Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGElement.h
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4  * Copyright (C) 2009 Apple Inc. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef SVGElement_h
23 #define SVGElement_h
24
25 #include "core/dom/Element.h"
26 #include "core/svg/SVGAnimatedString.h"
27 #include "core/svg/SVGParsingError.h"
28 #include "core/svg/properties/SVGAnimatedPropertyMacros.h"
29 #include "core/svg/properties/SVGPropertyInfo.h"
30 #include "platform/Timer.h"
31 #include "wtf/HashMap.h"
32 #include "wtf/OwnPtr.h"
33
34 namespace WebCore {
35
36 class AffineTransform;
37 class CSSCursorImageValue;
38 class Document;
39 class NewSVGAnimatedPropertyBase;
40 class SubtreeLayoutScope;
41 class SVGAttributeToPropertyMap;
42 class SVGCursorElement;
43 class SVGDocumentExtensions;
44 class SVGElementInstance;
45 class SVGElementRareData;
46 class SVGFitToViewBox;
47 class SVGSVGElement;
48
49 void mapAttributeToCSSProperty(HashMap<StringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName);
50
51 class SVGElement : public Element {
52 public:
53     virtual ~SVGElement();
54
55     bool isOutermostSVGSVGElement() const;
56
57     virtual String title() const OVERRIDE;
58     bool hasRelativeLengths() const { return !m_elementsWithRelativeLengths.isEmpty(); }
59     virtual bool supportsMarkers() const { return false; }
60     PassRefPtr<CSSValue> getPresentationAttribute(const AtomicString& name);
61     static bool isAnimatableCSSProperty(const QualifiedName&);
62     enum CTMScope {
63         NearestViewportScope, // Used by SVGGraphicsElement::getCTM()
64         ScreenScope // Used by SVGGraphicsElement::getScreenCTM()
65     };
66     virtual AffineTransform localCoordinateSpaceTransform(CTMScope) const;
67     virtual bool needsPendingResourceHandling() const { return true; }
68
69     bool instanceUpdatesBlocked() const;
70     void setInstanceUpdatesBlocked(bool);
71
72     const AtomicString& xmlbase() const;
73     void setXMLbase(const AtomicString&);
74
75     const AtomicString& xmllang() const;
76     void setXMLlang(const AtomicString&);
77
78     const AtomicString& xmlspace() const;
79     void setXMLspace(const AtomicString&);
80
81     SVGSVGElement* ownerSVGElement() const;
82     SVGElement* viewportElement() const;
83
84     SVGDocumentExtensions* accessDocumentSVGExtensions();
85
86     virtual bool isSVGGraphicsElement() const { return false; }
87     virtual bool isSVGSVGElement() const { return false; }
88     virtual bool isFilterEffect() const { return false; }
89     virtual bool isGradientStop() const { return false; }
90     virtual bool isTextContent() const { return false; }
91     virtual bool isTextPositioning() const { return false; }
92     virtual bool isStructurallyExternal() const { return false; }
93
94     // For SVGTests
95     virtual bool isValid() const { return true; }
96
97     virtual void svgAttributeChanged(const QualifiedName&);
98
99     void animatedPropertyTypeForAttribute(const QualifiedName&, Vector<AnimatedPropertyType>&);
100     PassRefPtr<NewSVGAnimatedPropertyBase> propertyFromAttribute(const QualifiedName& attributeName);
101
102     void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
103     void sendSVGLoadEventIfPossibleAsynchronously();
104     void svgLoadEventTimerFired(Timer<SVGElement>*);
105     virtual Timer<SVGElement>* svgLoadEventTimer();
106
107     virtual AffineTransform* supplementalTransform() { return 0; }
108
109     void invalidateSVGAttributes() { ensureUniqueElementData()->m_animatedSVGAttributesAreDirty = true; }
110
111     const HashSet<SVGElementInstance*>& instancesForElement() const;
112
113     bool getBoundingBox(FloatRect&);
114
115     void setCursorElement(SVGCursorElement*);
116     void cursorElementRemoved();
117     void setCursorImageValue(CSSCursorImageValue*);
118     void cursorImageValueRemoved();
119
120     SVGElement* correspondingElement();
121     void setCorrespondingElement(SVGElement*);
122
123     void synchronizeAnimatedSVGAttribute(const QualifiedName&) const;
124
125     virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE FINAL;
126
127     static void synchronizeRequiredFeatures(SVGElement* contextElement);
128     static void synchronizeRequiredExtensions(SVGElement* contextElement);
129     static void synchronizeSystemLanguage(SVGElement* contextElement);
130
131     virtual void synchronizeRequiredFeatures() { }
132     virtual void synchronizeRequiredExtensions() { }
133     virtual void synchronizeSystemLanguage() { }
134
135 #ifndef NDEBUG
136     virtual bool isAnimatableAttribute(const QualifiedName&) const;
137 #endif
138
139     MutableStylePropertySet* animatedSMILStyleProperties() const;
140     MutableStylePropertySet* ensureAnimatedSMILStyleProperties();
141     void setUseOverrideComputedStyle(bool);
142
143     virtual bool haveLoadedRequiredResources();
144
145     virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) OVERRIDE FINAL;
146     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) OVERRIDE FINAL;
147
148     void invalidateRelativeLengthClients(SubtreeLayoutScope* = 0);
149
150     bool isContextElement() const { return m_isContextElement; }
151     void setContextElement() { m_isContextElement = true; }
152
153     void addToPropertyMap(PassRefPtr<NewSVGAnimatedPropertyBase>);
154
155     SVGAnimatedString* className() { return m_className.get(); }
156
157 protected:
158     SVGElement(const QualifiedName&, Document&, ConstructionType = CreateSVGElement);
159
160     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
161
162     virtual void finishParsingChildren() OVERRIDE;
163     virtual void attributeChanged(const QualifiedName&, const AtomicString&, AttributeModificationReason = ModifiedDirectly) OVERRIDE;
164
165     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
166     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
167     virtual bool rendererIsNeeded(const RenderStyle&) OVERRIDE;
168
169     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
170     virtual void removedFrom(ContainerNode*) OVERRIDE;
171     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
172
173     static CSSPropertyID cssPropertyIdForSVGAttributeName(const QualifiedName&);
174     void updateRelativeLengthsInformation() { updateRelativeLengthsInformation(selfHasRelativeLengths(), this); }
175     void updateRelativeLengthsInformation(bool hasRelativeLengths, SVGElement*);
176
177     virtual bool selfHasRelativeLengths() const { return false; }
178
179     SVGElementRareData* svgRareData() const;
180     SVGElementRareData* ensureSVGRareData();
181
182     bool hasSVGRareData() const { return m_hasSVGRareData; }
183     void setHasSVGRareData() { m_hasSVGRareData = true; }
184     void clearHasSVGRareData() { m_hasSVGRareData = false; }
185
186     // SVGFitToViewBox::parseAttribute uses reportAttributeParsingError.
187     friend class SVGFitToViewBox;
188     void reportAttributeParsingError(SVGParsingError, const QualifiedName&, const AtomicString&);
189     bool hasFocusEventListeners() const;
190
191     class CleanUpAnimatedPropertiesCaller {
192     public:
193         CleanUpAnimatedPropertiesCaller()
194         :   m_owner(0)
195         {
196         }
197
198         ~CleanUpAnimatedPropertiesCaller()
199         {
200             ASSERT(m_owner);
201             m_owner->cleanupAnimatedProperties();
202         }
203
204         void setOwner(SVGElement* owner) { m_owner = owner; }
205
206     private:
207         SVGElement* m_owner;
208     };
209
210 private:
211     friend class SVGElementInstance;
212
213     // FIXME: Author shadows should be allowed
214     // https://bugs.webkit.org/show_bug.cgi?id=77938
215     virtual bool areAuthorShadowsAllowed() const OVERRIDE FINAL { return false; }
216
217     RenderStyle* computedStyle(PseudoId = NOPSEUDO);
218     virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) OVERRIDE FINAL { return computedStyle(pseudoElementSpecifier); }
219     virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE;
220     virtual bool isKeyboardFocusable() const OVERRIDE;
221
222     void buildPendingResourcesIfNeeded();
223
224     void mapInstanceToElement(SVGElementInstance*);
225     void removeInstanceMapping(SVGElementInstance*);
226
227     void cleanupAnimatedProperties();
228     friend class CleanUpAnimatedPropertiesCaller;
229
230     HashSet<SVGElement*> m_elementsWithRelativeLengths;
231
232     typedef HashMap<QualifiedName, RefPtr<NewSVGAnimatedPropertyBase> > AttributeToPropertyMap;
233     AttributeToPropertyMap m_newAttributeToPropertyMap;
234
235 #if !ASSERT_DISABLED
236     bool m_inRelativeLengthClientsInvalidation;
237 #endif
238     unsigned m_animatedPropertiesDestructed : 1;
239     unsigned m_isContextElement : 1;
240     unsigned m_hasSVGRareData : 1;
241
242     RefPtr<SVGAnimatedString> m_className;
243     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGElement)
244     END_DECLARE_ANIMATED_PROPERTIES
245 };
246
247 struct SVGAttributeHashTranslator {
248     static unsigned hash(const QualifiedName& key)
249     {
250         if (key.hasPrefix()) {
251             QualifiedNameComponents components = { nullAtom.impl(), key.localName().impl(), key.namespaceURI().impl() };
252             return hashComponents(components);
253         }
254         return DefaultHash<QualifiedName>::Hash::hash(key);
255     }
256     static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
257 };
258
259 DEFINE_NODE_TYPE_CASTS(SVGElement, isSVGElement());
260
261 }
262
263 #endif