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.
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.
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.
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.
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"
36 class AffineTransform;
37 class CSSCursorImageValue;
39 class NewSVGAnimatedPropertyBase;
40 class SubtreeLayoutScope;
41 class SVGAttributeToPropertyMap;
42 class SVGCursorElement;
43 class SVGDocumentExtensions;
44 class SVGElementInstance;
45 class SVGElementRareData;
46 class SVGFitToViewBox;
49 void mapAttributeToCSSProperty(HashMap<StringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName);
51 class SVGElement : public Element {
53 virtual ~SVGElement();
55 bool isOutermostSVGSVGElement() const;
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&);
63 NearestViewportScope, // Used by SVGGraphicsElement::getCTM()
64 ScreenScope // Used by SVGGraphicsElement::getScreenCTM()
66 virtual AffineTransform localCoordinateSpaceTransform(CTMScope) const;
67 virtual bool needsPendingResourceHandling() const { return true; }
69 bool instanceUpdatesBlocked() const;
70 void setInstanceUpdatesBlocked(bool);
72 const AtomicString& xmlbase() const;
73 void setXMLbase(const AtomicString&);
75 const AtomicString& xmllang() const;
76 void setXMLlang(const AtomicString&);
78 const AtomicString& xmlspace() const;
79 void setXMLspace(const AtomicString&);
81 SVGSVGElement* ownerSVGElement() const;
82 SVGElement* viewportElement() const;
84 SVGDocumentExtensions* accessDocumentSVGExtensions();
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; }
95 virtual bool isValid() const { return true; }
97 virtual void svgAttributeChanged(const QualifiedName&);
99 void animatedPropertyTypeForAttribute(const QualifiedName&, Vector<AnimatedPropertyType>&);
100 PassRefPtr<NewSVGAnimatedPropertyBase> propertyFromAttribute(const QualifiedName& attributeName);
102 void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
103 void sendSVGLoadEventIfPossibleAsynchronously();
104 void svgLoadEventTimerFired(Timer<SVGElement>*);
105 virtual Timer<SVGElement>* svgLoadEventTimer();
107 virtual AffineTransform* supplementalTransform() { return 0; }
109 void invalidateSVGAttributes() { ensureUniqueElementData()->m_animatedSVGAttributesAreDirty = true; }
111 const HashSet<SVGElementInstance*>& instancesForElement() const;
113 bool getBoundingBox(FloatRect&);
115 void setCursorElement(SVGCursorElement*);
116 void cursorElementRemoved();
117 void setCursorImageValue(CSSCursorImageValue*);
118 void cursorImageValueRemoved();
120 SVGElement* correspondingElement();
121 void setCorrespondingElement(SVGElement*);
123 void synchronizeAnimatedSVGAttribute(const QualifiedName&) const;
125 virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE FINAL;
127 static void synchronizeRequiredFeatures(SVGElement* contextElement);
128 static void synchronizeRequiredExtensions(SVGElement* contextElement);
129 static void synchronizeSystemLanguage(SVGElement* contextElement);
131 virtual void synchronizeRequiredFeatures() { }
132 virtual void synchronizeRequiredExtensions() { }
133 virtual void synchronizeSystemLanguage() { }
136 virtual bool isAnimatableAttribute(const QualifiedName&) const;
139 MutableStylePropertySet* animatedSMILStyleProperties() const;
140 MutableStylePropertySet* ensureAnimatedSMILStyleProperties();
141 void setUseOverrideComputedStyle(bool);
143 virtual bool haveLoadedRequiredResources();
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;
148 void invalidateRelativeLengthClients(SubtreeLayoutScope* = 0);
150 bool isContextElement() const { return m_isContextElement; }
151 void setContextElement() { m_isContextElement = true; }
153 void addToPropertyMap(PassRefPtr<NewSVGAnimatedPropertyBase>);
155 SVGAnimatedString* className() { return m_className.get(); }
158 SVGElement(const QualifiedName&, Document&, ConstructionType = CreateSVGElement);
160 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
162 virtual void finishParsingChildren() OVERRIDE;
163 virtual void attributeChanged(const QualifiedName&, const AtomicString&, AttributeModificationReason = ModifiedDirectly) OVERRIDE;
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;
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;
173 static CSSPropertyID cssPropertyIdForSVGAttributeName(const QualifiedName&);
174 void updateRelativeLengthsInformation() { updateRelativeLengthsInformation(selfHasRelativeLengths(), this); }
175 void updateRelativeLengthsInformation(bool hasRelativeLengths, SVGElement*);
177 virtual bool selfHasRelativeLengths() const { return false; }
179 SVGElementRareData* svgRareData() const;
180 SVGElementRareData* ensureSVGRareData();
182 bool hasSVGRareData() const { return m_hasSVGRareData; }
183 void setHasSVGRareData() { m_hasSVGRareData = true; }
184 void clearHasSVGRareData() { m_hasSVGRareData = false; }
186 // SVGFitToViewBox::parseAttribute uses reportAttributeParsingError.
187 friend class SVGFitToViewBox;
188 void reportAttributeParsingError(SVGParsingError, const QualifiedName&, const AtomicString&);
189 bool hasFocusEventListeners() const;
191 class CleanUpAnimatedPropertiesCaller {
193 CleanUpAnimatedPropertiesCaller()
198 ~CleanUpAnimatedPropertiesCaller()
201 m_owner->cleanupAnimatedProperties();
204 void setOwner(SVGElement* owner) { m_owner = owner; }
211 friend class SVGElementInstance;
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; }
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;
222 void buildPendingResourcesIfNeeded();
224 void mapInstanceToElement(SVGElementInstance*);
225 void removeInstanceMapping(SVGElementInstance*);
227 void cleanupAnimatedProperties();
228 friend class CleanUpAnimatedPropertiesCaller;
230 HashSet<SVGElement*> m_elementsWithRelativeLengths;
232 typedef HashMap<QualifiedName, RefPtr<NewSVGAnimatedPropertyBase> > AttributeToPropertyMap;
233 AttributeToPropertyMap m_newAttributeToPropertyMap;
236 bool m_inRelativeLengthClientsInvalidation;
238 unsigned m_animatedPropertiesDestructed : 1;
239 unsigned m_isContextElement : 1;
240 unsigned m_hasSVGRareData : 1;
242 RefPtr<SVGAnimatedString> m_className;
243 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGElement)
244 END_DECLARE_ANIMATED_PROPERTIES
247 struct SVGAttributeHashTranslator {
248 static unsigned hash(const QualifiedName& key)
250 if (key.hasPrefix()) {
251 QualifiedNameComponents components = { nullAtom.impl(), key.localName().impl(), key.namespaceURI().impl() };
252 return hashComponents(components);
254 return DefaultHash<QualifiedName>::Hash::hash(key);
256 static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
259 DEFINE_NODE_TYPE_CASTS(SVGElement, isSVGElement());