~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/svg/SVGCursorElement.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
 
3
 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public License
 
16
 * along with this library; see the file COPYING.LIB.  If not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#if ENABLE(SVG)
 
24
#include "SVGCursorElement.h"
 
25
 
 
26
#include "Attr.h"
 
27
#include "Document.h"
 
28
#include "SVGElementInstance.h"
 
29
#include "SVGNames.h"
 
30
 
 
31
namespace WebCore {
 
32
 
 
33
// Animated property definitions
 
34
DEFINE_ANIMATED_LENGTH(SVGCursorElement, SVGNames::xAttr, X, x)
 
35
DEFINE_ANIMATED_LENGTH(SVGCursorElement, SVGNames::yAttr, Y, y)
 
36
DEFINE_ANIMATED_STRING(SVGCursorElement, XLinkNames::hrefAttr, Href, href)
 
37
DEFINE_ANIMATED_BOOLEAN(SVGCursorElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
 
38
 
 
39
BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGCursorElement)
 
40
    REGISTER_LOCAL_ANIMATED_PROPERTY(x)
 
41
    REGISTER_LOCAL_ANIMATED_PROPERTY(y)
 
42
    REGISTER_LOCAL_ANIMATED_PROPERTY(href)
 
43
    REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
 
44
    REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
 
45
END_REGISTER_ANIMATED_PROPERTIES
 
46
 
 
47
inline SVGCursorElement::SVGCursorElement(const QualifiedName& tagName, Document* document)
 
48
    : SVGElement(tagName, document)
 
49
    , m_x(LengthModeWidth)
 
50
    , m_y(LengthModeHeight)
 
51
{
 
52
    ASSERT(hasTagName(SVGNames::cursorTag));
 
53
    registerAnimatedPropertiesForSVGCursorElement();
 
54
}
 
55
 
 
56
PassRefPtr<SVGCursorElement> SVGCursorElement::create(const QualifiedName& tagName, Document* document)
 
57
{
 
58
    return adoptRef(new SVGCursorElement(tagName, document));
 
59
}
 
60
 
 
61
SVGCursorElement::~SVGCursorElement()
 
62
{
 
63
    HashSet<SVGElement*>::iterator end = m_clients.end();
 
64
    for (HashSet<SVGElement*>::iterator it = m_clients.begin(); it != end; ++it)
 
65
        (*it)->cursorElementRemoved();
 
66
}
 
67
 
 
68
bool SVGCursorElement::isSupportedAttribute(const QualifiedName& attrName)
 
69
{
 
70
    DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
 
71
    if (supportedAttributes.isEmpty()) {
 
72
        SVGTests::addSupportedAttributes(supportedAttributes);
 
73
        SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
 
74
        SVGURIReference::addSupportedAttributes(supportedAttributes);
 
75
        supportedAttributes.add(SVGNames::xAttr);
 
76
        supportedAttributes.add(SVGNames::yAttr);
 
77
    }
 
78
    return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
 
79
}
 
80
 
 
81
void SVGCursorElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 
82
{
 
83
    SVGParsingError parseError = NoError;
 
84
 
 
85
    if (!isSupportedAttribute(name))
 
86
        SVGElement::parseAttribute(name, value);
 
87
    else if (name == SVGNames::xAttr)
 
88
        setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
 
89
    else if (name == SVGNames::yAttr)
 
90
        setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
 
91
    else if (SVGTests::parseAttribute(name, value)
 
92
             || SVGExternalResourcesRequired::parseAttribute(name, value)
 
93
             || SVGURIReference::parseAttribute(name, value)) {
 
94
    } else
 
95
        ASSERT_NOT_REACHED();
 
96
    
 
97
    reportAttributeParsingError(parseError, name, value);
 
98
}
 
99
 
 
100
void SVGCursorElement::addClient(SVGElement* element)
 
101
{
 
102
    m_clients.add(element);
 
103
    element->setCursorElement(this);
 
104
}
 
105
 
 
106
void SVGCursorElement::removeClient(SVGElement* element)
 
107
{
 
108
    HashSet<SVGElement*>::iterator it = m_clients.find(element);
 
109
    if (it != m_clients.end()) {
 
110
        m_clients.remove(it);
 
111
        element->cursorElementRemoved();
 
112
    }
 
113
}
 
114
 
 
115
void SVGCursorElement::removeReferencedElement(SVGElement* element)
 
116
{
 
117
    m_clients.remove(element);
 
118
}
 
119
 
 
120
void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName)
 
121
{
 
122
    if (!isSupportedAttribute(attrName)) {
 
123
        SVGElement::svgAttributeChanged(attrName);
 
124
        return;
 
125
    }
 
126
 
 
127
    SVGElementInstance::InvalidationGuard invalidationGuard(this);
 
128
 
 
129
    // Any change of a cursor specific attribute triggers this recalc.
 
130
    HashSet<SVGElement*>::const_iterator it = m_clients.begin();
 
131
    HashSet<SVGElement*>::const_iterator end = m_clients.end();
 
132
 
 
133
    for (; it != end; ++it)
 
134
        (*it)->setNeedsStyleRecalc();
 
135
}
 
136
 
 
137
void SVGCursorElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 
138
{
 
139
    SVGElement::addSubresourceAttributeURLs(urls);
 
140
 
 
141
    addSubresourceURL(urls, document()->completeURL(href()));
 
142
}
 
143
 
 
144
}
 
145
 
 
146
#endif // ENABLE(SVG)