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 * Copyright (C) 2009, 2014 Apple Inc. All rights reserved.
5 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
26 #include "CSSPropertyNames.h"
27 #include "SVGAnimatedString.h"
28 #include "SVGLangSpace.h"
29 #include "SVGLocatable.h"
31 #include "SVGParsingError.h"
32 #include "SVGPropertyInfo.h"
33 #include "StyledElement.h"
35 #include <wtf/HashMap.h>
36 #include <wtf/HashSet.h>
37 #include <wtf/PassRefPtr.h>
41 class AffineTransform;
42 class CSSCursorImageValue;
43 class CSSStyleDeclaration;
46 class SVGAttributeToPropertyMap;
47 class SVGCursorElement;
48 class SVGDocumentExtensions;
49 class SVGElementInstance;
50 class SVGElementRareData;
53 void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName);
55 class SVGElement : public StyledElement, public SVGLangSpace {
57 bool isOutermostSVGSVGElement() const;
59 String xmlbase() const;
60 void setXmlbase(const String&, ExceptionCode&);
62 SVGSVGElement* ownerSVGElement() const;
63 SVGElement* viewportElement() const;
65 virtual String title() const override;
66 static bool isAnimatableCSSProperty(const QualifiedName&);
67 bool isPresentationAttributeWithSVGDOM(const QualifiedName&);
68 bool isKnownAttribute(const QualifiedName&);
69 PassRefPtr<CSSValue> getPresentationAttribute(const String& name);
70 virtual bool supportsMarkers() const { return false; }
71 bool hasRelativeLengths() const { return !m_elementsWithRelativeLengths.isEmpty(); }
72 virtual bool needsPendingResourceHandling() const { return true; }
73 bool instanceUpdatesBlocked() const;
74 void setInstanceUpdatesBlocked(bool);
75 virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const;
77 virtual bool isSVGGraphicsElement() const { return false; }
78 virtual bool isFilterEffect() const { return false; }
79 virtual bool isGradientStop() const { return false; }
80 virtual bool isTextContent() const { return false; }
81 virtual bool isSMILElement() const { return false; }
84 virtual bool isValid() const { return true; }
86 virtual void svgAttributeChanged(const QualifiedName&);
88 void animatedPropertyTypeForAttribute(const QualifiedName&, Vector<AnimatedPropertyType>&);
90 void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
91 void sendSVGLoadEventIfPossibleAsynchronously();
92 void svgLoadEventTimerFired(Timer<SVGElement>*);
93 virtual Timer<SVGElement>* svgLoadEventTimer();
95 virtual AffineTransform* supplementalTransform() { return 0; }
97 void invalidateSVGAttributes() { ensureUniqueElementData().setAnimatedSVGAttributesAreDirty(true); }
98 void invalidateSVGPresentationAttributeStyle()
100 ensureUniqueElementData().setPresentationAttributeStyleIsDirty(true);
101 // Trigger style recalculation for "elements as resource" (e.g. referenced by feImage).
102 setNeedsStyleRecalc(InlineStyleChange);
105 const HashSet<SVGElementInstance*>& instancesForElement() const;
107 bool getBoundingBox(FloatRect&, SVGLocatable::StyleUpdateStrategy = SVGLocatable::AllowStyleUpdate);
109 void setCursorElement(SVGCursorElement*);
110 void cursorElementRemoved();
111 void setCursorImageValue(CSSCursorImageValue*);
112 void cursorImageValueRemoved();
114 SVGElement* correspondingElement();
115 void setCorrespondingElement(SVGElement*);
117 void synchronizeAnimatedSVGAttribute(const QualifiedName&) const;
118 static void synchronizeAllAnimatedSVGAttribute(SVGElement*);
120 virtual PassRefPtr<RenderStyle> customStyleForRenderer(RenderStyle& parentStyle) override;
122 static void synchronizeRequiredFeatures(SVGElement* contextElement);
123 static void synchronizeRequiredExtensions(SVGElement* contextElement);
124 static void synchronizeSystemLanguage(SVGElement* contextElement);
126 virtual void synchronizeRequiredFeatures() { }
127 virtual void synchronizeRequiredExtensions() { }
128 virtual void synchronizeSystemLanguage() { }
130 static QualifiedName animatableAttributeForName(const AtomicString&);
132 bool isAnimatableAttribute(const QualifiedName&) const;
135 MutableStyleProperties* animatedSMILStyleProperties() const;
136 MutableStyleProperties& ensureAnimatedSMILStyleProperties();
137 void setUseOverrideComputedStyle(bool);
139 virtual bool haveLoadedRequiredResources();
141 virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) override;
142 virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) override;
143 bool hasFocusEventListeners() const;
145 #if ENABLE(CSS_REGIONS)
146 virtual bool shouldMoveToFlowThread(const RenderStyle&) const override;
149 bool hasTagName(const SVGQualifiedName& name) const { return hasLocalName(name.localName()); }
150 virtual short tabIndex() const override;
152 void callClearTarget() { clearTarget(); }
155 SVGElement(const QualifiedName&, Document&);
156 virtual ~SVGElement();
158 virtual bool isMouseFocusable() const override;
159 virtual bool supportsFocus() const override { return false; }
161 virtual bool rendererIsNeeded(const RenderStyle&) override;
162 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
164 virtual void finishParsingChildren() override;
165 virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) override;
166 virtual bool childShouldCreateRenderer(const Node&) const override;
168 SVGElementRareData& ensureSVGRareData();
170 void reportAttributeParsingError(SVGParsingError, const QualifiedName&, const AtomicString&);
171 static CSSPropertyID cssPropertyIdForSVGAttributeName(const QualifiedName&);
173 virtual bool isPresentationAttribute(const QualifiedName&) const override;
174 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
175 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
176 virtual void removedFrom(ContainerNode&) override;
177 virtual void childrenChanged(const ChildChange&) override;
178 virtual bool selfHasRelativeLengths() const { return false; }
179 void updateRelativeLengthsInformation() { updateRelativeLengthsInformation(selfHasRelativeLengths(), this); }
180 void updateRelativeLengthsInformation(bool hasRelativeLengths, SVGElement*);
183 friend class SVGElementInstance;
185 virtual RenderStyle* computedStyle(PseudoId = NOPSEUDO) override final;
186 virtual bool willRecalcStyle(Style::Change) override;
188 virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
190 virtual void clearTarget() { }
192 void mapInstanceToElement(SVGElementInstance*);
193 void removeInstanceMapping(SVGElementInstance*);
195 void buildPendingResourcesIfNeeded();
196 virtual void accessKeyAction(bool sendMouseEvents) override;
199 virtual bool filterOutAnimatableAttribute(const QualifiedName&) const;
202 std::unique_ptr<SVGElementRareData> m_svgRareData;
204 HashSet<SVGElement*> m_elementsWithRelativeLengths;
206 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGElement)
207 DECLARE_ANIMATED_STRING(ClassName, className)
208 END_DECLARE_ANIMATED_PROPERTIES
212 struct SVGAttributeHashTranslator {
213 static unsigned hash(const QualifiedName& key)
215 if (key.hasPrefix()) {
216 QualifiedNameComponents components = { nullAtom.impl(), key.localName().impl(), key.namespaceURI().impl() };
217 return hashComponents(components);
219 return DefaultHash<QualifiedName>::Hash::hash(key);
221 static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
224 void isSVGElement(const SVGElement&); // Catch unnecessary runtime check of type known at compile time.
225 inline bool isSVGElement(const Node& node) { return node.isSVGElement(); }
227 template <typename ArgType>
228 struct ElementTypeCastTraits<const SVGElement, ArgType> {
229 static bool is(ArgType& node) { return isSVGElement(node); }
232 NODE_TYPE_CASTS(SVGElement)
234 inline bool Node::hasTagName(const SVGQualifiedName& name) const
236 return isSVGElement() && downcast<SVGElement>(*this).hasTagName(name);
239 } // namespace WebCore
241 #include "SVGElementTypeHelpers.h"