summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGElement.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/svg/SVGElement.h')
-rw-r--r--Source/WebCore/svg/SVGElement.h173
1 files changed, 108 insertions, 65 deletions
diff --git a/Source/WebCore/svg/SVGElement.h b/Source/WebCore/svg/SVGElement.h
index 14321e846..283e6c896 100644
--- a/Source/WebCore/svg/SVGElement.h
+++ b/Source/WebCore/svg/SVGElement.h
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2016 Apple Inc. All rights reserved.
* Copyright (C) 2013 Samsung Electronics. All rights reserved.
*
* This library is free software; you can redistribute it and/or
@@ -20,36 +20,29 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef SVGElement_h
-#define SVGElement_h
+#pragma once
-#if ENABLE(SVG)
-#include "CSSPropertyNames.h"
#include "SVGAnimatedString.h"
-#include "SVGElementTypeHelpers.h"
#include "SVGLangSpace.h"
#include "SVGLocatable.h"
+#include "SVGNames.h"
#include "SVGParsingError.h"
#include "SVGPropertyInfo.h"
#include "StyledElement.h"
-#include "Timer.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
-#include <wtf/PassRefPtr.h>
namespace WebCore {
class AffineTransform;
-class CSSCursorImageValue;
class CSSStyleDeclaration;
-class CSSValue;
+class DeprecatedCSSOMValue;
class Document;
class SVGAttributeToPropertyMap;
-class SVGCursorElement;
class SVGDocumentExtensions;
-class SVGElementInstance;
class SVGElementRareData;
class SVGSVGElement;
+class SVGUseElement;
void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, CSSPropertyID>* propertyNameToIdMap, const QualifiedName& attrName);
@@ -57,16 +50,14 @@ class SVGElement : public StyledElement, public SVGLangSpace {
public:
bool isOutermostSVGSVGElement() const;
- String xmlbase() const;
- void setXmlbase(const String&, ExceptionCode&);
-
SVGSVGElement* ownerSVGElement() const;
SVGElement* viewportElement() const;
- virtual String title() const override;
+ String title() const override;
static bool isAnimatableCSSProperty(const QualifiedName&);
+ bool isPresentationAttributeWithSVGDOM(const QualifiedName&);
bool isKnownAttribute(const QualifiedName&);
- PassRefPtr<CSSValue> getPresentationAttribute(const String& name);
+ RefPtr<DeprecatedCSSOMValue> getPresentationAttribute(const String& name);
virtual bool supportsMarkers() const { return false; }
bool hasRelativeLengths() const { return !m_elementsWithRelativeLengths.isEmpty(); }
virtual bool needsPendingResourceHandling() const { return true; }
@@ -74,8 +65,6 @@ public:
void setInstanceUpdatesBlocked(bool);
virtual AffineTransform localCoordinateSpaceTransform(SVGLocatable::CTMScope) const;
- SVGDocumentExtensions* accessDocumentSVGExtensions();
-
virtual bool isSVGGraphicsElement() const { return false; }
virtual bool isFilterEffect() const { return false; }
virtual bool isGradientStop() const { return false; }
@@ -87,32 +76,37 @@ public:
virtual void svgAttributeChanged(const QualifiedName&);
- virtual void animatedPropertyTypeForAttribute(const QualifiedName&, Vector<AnimatedPropertyType>&);
+ Vector<AnimatedPropertyType> animatedPropertyTypesForAttribute(const QualifiedName&);
void sendSVGLoadEventIfPossible(bool sendParentLoadEvents = false);
void sendSVGLoadEventIfPossibleAsynchronously();
- void svgLoadEventTimerFired(Timer<SVGElement>*);
- virtual Timer<SVGElement>* svgLoadEventTimer();
+ void svgLoadEventTimerFired();
+ virtual Timer* svgLoadEventTimer();
- virtual AffineTransform* supplementalTransform() { return 0; }
+ virtual AffineTransform* supplementalTransform() { return nullptr; }
void invalidateSVGAttributes() { ensureUniqueElementData().setAnimatedSVGAttributesAreDirty(true); }
+ void invalidateSVGPresentationAttributeStyle()
+ {
+ ensureUniqueElementData().setPresentationAttributeStyleIsDirty(true);
+ // Trigger style recalculation for "elements as resource" (e.g. referenced by feImage).
+ invalidateStyle();
+ }
- const HashSet<SVGElementInstance*>& instancesForElement() const;
+ // The instances of an element are clones made in shadow trees to implement <use>.
+ const HashSet<SVGElement*>& instances() const;
bool getBoundingBox(FloatRect&, SVGLocatable::StyleUpdateStrategy = SVGLocatable::AllowStyleUpdate);
- void setCursorElement(SVGCursorElement*);
- void cursorElementRemoved();
- void setCursorImageValue(CSSCursorImageValue*);
- void cursorImageValueRemoved();
+ SVGElement* correspondingElement() const;
+ SVGUseElement* correspondingUseElement() const;
- SVGElement* correspondingElement();
void setCorrespondingElement(SVGElement*);
void synchronizeAnimatedSVGAttribute(const QualifiedName&) const;
+ static void synchronizeAllAnimatedSVGAttribute(SVGElement*);
- virtual PassRefPtr<RenderStyle> customStyleForRenderer() override;
+ std::optional<ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
static void synchronizeRequiredFeatures(SVGElement* contextElement);
static void synchronizeRequiredExtensions(SVGElement* contextElement);
@@ -122,8 +116,9 @@ public:
virtual void synchronizeRequiredExtensions() { }
virtual void synchronizeSystemLanguage() { }
+ static QualifiedName animatableAttributeForName(const AtomicString&);
#ifndef NDEBUG
- virtual bool isAnimatableAttribute(const QualifiedName&) const;
+ bool isAnimatableAttribute(const QualifiedName&) const;
#endif
MutableStyleProperties* animatedSMILStyleProperties() const;
@@ -132,68 +127,93 @@ public:
virtual bool haveLoadedRequiredResources();
- virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) override;
- virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) override;
+ bool addEventListener(const AtomicString& eventType, Ref<EventListener>&&, const AddEventListenerOptions&) override;
+ bool removeEventListener(const AtomicString& eventType, EventListener&, const ListenerOptions&) override;
+ bool hasFocusEventListeners() const;
#if ENABLE(CSS_REGIONS)
- virtual bool shouldMoveToFlowThread(const RenderStyle&) const override;
+ bool shouldMoveToFlowThread(const RenderStyle&) const override;
#endif
+ bool hasTagName(const SVGQualifiedName& name) const { return hasLocalName(name.localName()); }
+ int tabIndex() const override;
+
+ void callClearTarget() { clearTarget(); }
+
+ class InstanceUpdateBlocker;
+
protected:
SVGElement(const QualifiedName&, Document&);
virtual ~SVGElement();
- virtual bool rendererIsNeeded(const RenderStyle&) override;
- virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
+ bool isMouseFocusable() const override;
+ bool supportsFocus() const override { return false; }
+
+ bool rendererIsNeeded(const RenderStyle&) override;
+ void parseAttribute(const QualifiedName&, const AtomicString&) override;
- virtual void finishParsingChildren() override;
- virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) override;
- virtual bool childShouldCreateRenderer(const Node&) const override;
+ void finishParsingChildren() override;
+ void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly) override;
+ bool childShouldCreateRenderer(const Node&) const override;
SVGElementRareData& ensureSVGRareData();
void reportAttributeParsingError(SVGParsingError, const QualifiedName&, const AtomicString&);
static CSSPropertyID cssPropertyIdForSVGAttributeName(const QualifiedName&);
- virtual bool isPresentationAttribute(const QualifiedName&) const override;
- virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
- virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
- virtual void removedFrom(ContainerNode&) override;
- virtual void childrenChanged(const ChildChange&) override;
+ bool isPresentationAttribute(const QualifiedName&) const override;
+ void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) override;
+ InsertionNotificationRequest insertedInto(ContainerNode&) override;
+ void removedFrom(ContainerNode&) override;
+ void childrenChanged(const ChildChange&) override;
virtual bool selfHasRelativeLengths() const { return false; }
void updateRelativeLengthsInformation() { updateRelativeLengthsInformation(selfHasRelativeLengths(), this); }
void updateRelativeLengthsInformation(bool hasRelativeLengths, SVGElement*);
-private:
- friend class SVGElementInstance;
-
- // FIXME: Author shadows should be allowed
- // https://bugs.webkit.org/show_bug.cgi?id=77938
- virtual bool areAuthorShadowsAllowed() const override { return false; }
+ void willRecalcStyle(Style::Change) override;
- virtual RenderStyle* computedStyle(PseudoId = NOPSEUDO) override final;
- virtual bool willRecalcStyle(Style::Change) override;
+ class InstanceInvalidationGuard;
- virtual bool isSupported(StringImpl* feature, StringImpl* version) const;
+private:
+ const RenderStyle* computedStyle(PseudoId = NOPSEUDO) final;
- void mapInstanceToElement(SVGElementInstance*);
- void removeInstanceMapping(SVGElementInstance*);
+ virtual void clearTarget() { }
void buildPendingResourcesIfNeeded();
- virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
- virtual bool isMouseFocusable() const override;
- virtual void accessKeyAction(bool sendMouseEvents) override;
+ void accessKeyAction(bool sendMouseEvents) override;
+
+#ifndef NDEBUG
+ virtual bool filterOutAnimatableAttribute(const QualifiedName&) const;
+#endif
+
+ void invalidateInstances();
std::unique_ptr<SVGElementRareData> m_svgRareData;
HashSet<SVGElement*> m_elementsWithRelativeLengths;
- BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGElement)
+ BEGIN_DECLARE_ANIMATED_PROPERTIES_BASE(SVGElement)
DECLARE_ANIMATED_STRING(ClassName, className)
END_DECLARE_ANIMATED_PROPERTIES
};
+class SVGElement::InstanceInvalidationGuard {
+public:
+ InstanceInvalidationGuard(SVGElement&);
+ ~InstanceInvalidationGuard();
+private:
+ SVGElement& m_element;
+};
+
+class SVGElement::InstanceUpdateBlocker {
+public:
+ InstanceUpdateBlocker(SVGElement&);
+ ~InstanceUpdateBlocker();
+private:
+ SVGElement& m_element;
+};
+
struct SVGAttributeHashTranslator {
static unsigned hash(const QualifiedName& key)
{
@@ -206,13 +226,36 @@ struct SVGAttributeHashTranslator {
static bool equal(const QualifiedName& a, const QualifiedName& b) { return a.matches(b); }
};
-void isSVGElement(const SVGElement&); // Catch unnecessary runtime check of type known at compile time.
-inline bool isSVGElement(const Node& node) { return node.isSVGElement(); }
-template <> inline bool isElementOfType<const SVGElement>(const Element& element) { return element.isSVGElement(); }
+inline SVGElement::InstanceInvalidationGuard::InstanceInvalidationGuard(SVGElement& element)
+ : m_element(element)
+{
+}
-NODE_TYPE_CASTS(SVGElement)
+inline SVGElement::InstanceInvalidationGuard::~InstanceInvalidationGuard()
+{
+ m_element.invalidateInstances();
+}
+inline SVGElement::InstanceUpdateBlocker::InstanceUpdateBlocker(SVGElement& element)
+ : m_element(element)
+{
+ m_element.setInstanceUpdatesBlocked(true);
}
-#endif
-#endif
+inline SVGElement::InstanceUpdateBlocker::~InstanceUpdateBlocker()
+{
+ m_element.setInstanceUpdatesBlocked(false);
+}
+
+inline bool Node::hasTagName(const SVGQualifiedName& name) const
+{
+ return isSVGElement() && downcast<SVGElement>(*this).hasTagName(name);
+}
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGElement)
+ static bool isType(const WebCore::Node& node) { return node.isSVGElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
+#include "SVGElementTypeHelpers.h"