2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef SVGElementRareData_h
21 #define SVGElementRareData_h
23 #include "core/css/StylePropertySet.h"
24 #include "core/css/resolver/StyleResolver.h"
25 #include "wtf/HashSet.h"
26 #include "wtf/Noncopyable.h"
27 #include "wtf/StdLibExtras.h"
31 class CSSCursorImageValue;
32 class SVGCursorElement;
35 class SVGElementRareData : public NoBaseWillBeGarbageCollectedFinalized<SVGElementRareData> {
36 WTF_MAKE_NONCOPYABLE(SVGElementRareData); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
38 SVGElementRareData(SVGElement* owner)
40 , m_cursorElement(nullptr)
41 , m_cursorImageValue(nullptr)
42 , m_correspondingElement(0)
43 , m_instancesUpdatesBlocked(false)
44 , m_useOverrideComputedStyle(false)
45 , m_needsOverrideComputedStyleUpdate(false)
49 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<const SVGElement>, RawPtrWillBeMember<SVGElementRareData> > SVGElementRareDataMap;
51 static SVGElementRareDataMap& rareDataMap()
54 DEFINE_STATIC_LOCAL(Persistent<SVGElementRareDataMap>, rareDataMap, (new SVGElementRareDataMap));
57 DEFINE_STATIC_LOCAL(SVGElementRareDataMap, rareDataMap, ());
62 static SVGElementRareData* rareDataFromMap(const SVGElement* element)
64 return rareDataMap().get(element);
67 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& elementInstances() { return m_elementInstances; }
68 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& elementInstances() const { return m_elementInstances; }
70 bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; }
71 void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; }
73 SVGCursorElement* cursorElement() const { return m_cursorElement; }
74 void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; }
76 SVGElement* correspondingElement() { return m_correspondingElement; }
77 void setCorrespondingElement(SVGElement* correspondingElement) { m_correspondingElement = correspondingElement; }
79 CSSCursorImageValue* cursorImageValue() const { return m_cursorImageValue; }
80 void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; }
82 MutableStylePropertySet* animatedSMILStyleProperties() const { return m_animatedSMILStyleProperties.get(); }
83 MutableStylePropertySet* ensureAnimatedSMILStyleProperties()
85 if (!m_animatedSMILStyleProperties)
86 m_animatedSMILStyleProperties = MutableStylePropertySet::create(SVGAttributeMode);
87 return m_animatedSMILStyleProperties.get();
90 RenderStyle* overrideComputedStyle(Element* element, RenderStyle* parentStyle)
93 if (!m_useOverrideComputedStyle)
95 if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
96 // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
97 m_overrideComputedStyle = element->document().ensureStyleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL);
98 m_needsOverrideComputedStyleUpdate = false;
100 ASSERT(m_overrideComputedStyle);
101 return m_overrideComputedStyle.get();
104 bool useOverrideComputedStyle() const { return m_useOverrideComputedStyle; }
105 void setUseOverrideComputedStyle(bool value) { m_useOverrideComputedStyle = value; }
106 void setNeedsOverrideComputedStyleUpdate() { m_needsOverrideComputedStyleUpdate = true; }
108 void trace(Visitor* visitor)
110 visitor->trace(m_animatedSMILStyleProperties);
111 visitor->trace(m_elementInstances);
112 visitor->registerWeakMembers<SVGElementRareData, &SVGElementRareData::processWeakMembers>(this);
115 void processWeakMembers(Visitor* visitor)
118 if (!visitor->isAlive(m_owner)) {
119 // If the owning SVGElement is dead this raraData element will be collected ASAP.
120 // The owning SVGElement will also be automatically removed from the SVGCursorElement's
121 // HashSet so no need to call out and clear anything.
122 // It should not be necessary, but just in case we clear the internal members to
123 // ensure we don't have a stale pointer.
125 m_cursorElement = nullptr;
126 m_cursorImageValue = nullptr;
130 if (!visitor->isAlive(m_cursorElement))
131 m_cursorElement = nullptr;
133 if (!visitor->isAlive(m_cursorImageValue)) {
134 // If the owning SVGElement is still alive and it is pointing to an SVGCursorElement
135 // we unregister it when the CSSCursorImageValue dies.
136 if (m_cursorElement) {
137 m_cursorElement->removeReferencedElement(m_owner);
138 m_cursorElement = nullptr;
140 m_cursorImageValue = nullptr;
142 ASSERT(!m_cursorElement || visitor->isAlive(m_cursorElement));
143 ASSERT(!m_cursorImageValue || visitor->isAlive(m_cursorImageValue));
148 RawPtrWillBeWeakMember<SVGElement> m_owner;
149 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> > m_elementInstances;
150 RawPtrWillBeWeakMember<SVGCursorElement> m_cursorElement;
151 RawPtrWillBeWeakMember<CSSCursorImageValue> m_cursorImageValue;
152 SVGElement* m_correspondingElement;
153 bool m_instancesUpdatesBlocked : 1;
154 bool m_useOverrideComputedStyle : 1;
155 bool m_needsOverrideComputedStyleUpdate : 1;
156 RefPtrWillBeMember<MutableStylePropertySet> m_animatedSMILStyleProperties;
157 RefPtr<RenderStyle> m_overrideComputedStyle;