1 /* 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * 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. 8 * 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. 13 * 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. 18 */ 19 20 #ifndef SVGElementRareData_h 21 #define SVGElementRareData_h 22 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" 28 29 namespace WebCore { 30 31 class CSSCursorImageValue; 32 class SVGCursorElement; 33 class SVGElement; 34 35 class SVGElementRareData : public NoBaseWillBeGarbageCollectedFinalized<SVGElementRareData> { 36 WTF_MAKE_NONCOPYABLE(SVGElementRareData); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 37 public: SVGElementRareData(SVGElement * owner)38 SVGElementRareData(SVGElement* owner) 39 #if ENABLE(OILPAN) 40 : m_owner(owner) 41 , m_cursorElement(nullptr) 42 #else 43 : m_cursorElement(nullptr) 44 #endif 45 , m_cursorImageValue(nullptr) 46 , m_correspondingElement(nullptr) 47 , m_instancesUpdatesBlocked(false) 48 , m_useOverrideComputedStyle(false) 49 , m_needsOverrideComputedStyleUpdate(false) 50 { 51 } 52 elementInstances()53 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& elementInstances() { return m_elementInstances; } elementInstances()54 const WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >& elementInstances() const { return m_elementInstances; } 55 instanceUpdatesBlocked()56 bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; } setInstanceUpdatesBlocked(bool value)57 void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; } 58 cursorElement()59 SVGCursorElement* cursorElement() const { return m_cursorElement; } setCursorElement(SVGCursorElement * cursorElement)60 void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; } 61 correspondingElement()62 SVGElement* correspondingElement() { return m_correspondingElement.get(); } setCorrespondingElement(SVGElement * correspondingElement)63 void setCorrespondingElement(SVGElement* correspondingElement) { m_correspondingElement = correspondingElement; } 64 cursorImageValue()65 CSSCursorImageValue* cursorImageValue() const { return m_cursorImageValue; } setCursorImageValue(CSSCursorImageValue * cursorImageValue)66 void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; } 67 animatedSMILStyleProperties()68 MutableStylePropertySet* animatedSMILStyleProperties() const { return m_animatedSMILStyleProperties.get(); } ensureAnimatedSMILStyleProperties()69 MutableStylePropertySet* ensureAnimatedSMILStyleProperties() 70 { 71 if (!m_animatedSMILStyleProperties) 72 m_animatedSMILStyleProperties = MutableStylePropertySet::create(SVGAttributeMode); 73 return m_animatedSMILStyleProperties.get(); 74 } 75 overrideComputedStyle(Element * element,RenderStyle * parentStyle)76 RenderStyle* overrideComputedStyle(Element* element, RenderStyle* parentStyle) 77 { 78 ASSERT(element); 79 if (!m_useOverrideComputedStyle) 80 return 0; 81 if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) { 82 // 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. 83 m_overrideComputedStyle = element->document().ensureStyleResolver().styleForElement(element, parentStyle, DisallowStyleSharing, MatchAllRulesExcludingSMIL); 84 m_needsOverrideComputedStyleUpdate = false; 85 } 86 ASSERT(m_overrideComputedStyle); 87 return m_overrideComputedStyle.get(); 88 } 89 useOverrideComputedStyle()90 bool useOverrideComputedStyle() const { return m_useOverrideComputedStyle; } setUseOverrideComputedStyle(bool value)91 void setUseOverrideComputedStyle(bool value) { m_useOverrideComputedStyle = value; } setNeedsOverrideComputedStyleUpdate()92 void setNeedsOverrideComputedStyleUpdate() { m_needsOverrideComputedStyleUpdate = true; } 93 trace(Visitor * visitor)94 void trace(Visitor* visitor) 95 { 96 #if ENABLE(OILPAN) 97 visitor->trace(m_animatedSMILStyleProperties); 98 visitor->trace(m_elementInstances); 99 visitor->trace(m_correspondingElement); 100 visitor->trace(m_owner); 101 visitor->registerWeakMembers<SVGElementRareData, &SVGElementRareData::processWeakMembers>(this); 102 #endif 103 } 104 processWeakMembers(Visitor * visitor)105 void processWeakMembers(Visitor* visitor) 106 { 107 #if ENABLE(OILPAN) 108 ASSERT(m_owner); 109 if (!visitor->isAlive(m_cursorElement)) 110 m_cursorElement = nullptr; 111 112 if (!visitor->isAlive(m_cursorImageValue)) { 113 // The owning SVGElement is still alive and if it is pointing to an SVGCursorElement 114 // we unregister it when the CSSCursorImageValue dies. 115 if (m_cursorElement) { 116 m_cursorElement->removeReferencedElement(m_owner); 117 m_cursorElement = nullptr; 118 } 119 m_cursorImageValue = nullptr; 120 } 121 ASSERT(!m_cursorElement || visitor->isAlive(m_cursorElement)); 122 ASSERT(!m_cursorImageValue || visitor->isAlive(m_cursorImageValue)); 123 #endif 124 } 125 126 private: 127 #if ENABLE(OILPAN) 128 Member<SVGElement> m_owner; 129 #endif 130 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> > m_elementInstances; 131 RawPtrWillBeWeakMember<SVGCursorElement> m_cursorElement; 132 RawPtrWillBeWeakMember<CSSCursorImageValue> m_cursorImageValue; 133 RefPtrWillBeMember<SVGElement> m_correspondingElement; 134 bool m_instancesUpdatesBlocked : 1; 135 bool m_useOverrideComputedStyle : 1; 136 bool m_needsOverrideComputedStyleUpdate : 1; 137 RefPtrWillBeMember<MutableStylePropertySet> m_animatedSMILStyleProperties; 138 RefPtr<RenderStyle> m_overrideComputedStyle; 139 }; 140 141 } 142 143 #endif 144