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 class SVGElementInstance; 35 36 class SVGElementRareData { 37 WTF_MAKE_NONCOPYABLE(SVGElementRareData); WTF_MAKE_FAST_ALLOCATED; 38 public: SVGElementRareData()39 SVGElementRareData() 40 : m_cursorElement(0) 41 , m_cursorImageValue(0) 42 , m_correspondingElement(0) 43 , m_instancesUpdatesBlocked(false) 44 , m_useOverrideComputedStyle(false) 45 , m_needsOverrideComputedStyleUpdate(false) 46 { 47 } 48 49 typedef HashMap<const SVGElement*, SVGElementRareData*> SVGElementRareDataMap; 50 rareDataMap()51 static SVGElementRareDataMap& rareDataMap() 52 { 53 DEFINE_STATIC_LOCAL(SVGElementRareDataMap, rareDataMap, ()); 54 return rareDataMap; 55 } 56 rareDataFromMap(const SVGElement * element)57 static SVGElementRareData* rareDataFromMap(const SVGElement* element) 58 { 59 return rareDataMap().get(element); 60 } 61 elementInstances()62 HashSet<SVGElementInstance*>& elementInstances() { return m_elementInstances; } elementInstances()63 const HashSet<SVGElementInstance*>& elementInstances() const { return m_elementInstances; } 64 instanceUpdatesBlocked()65 bool instanceUpdatesBlocked() const { return m_instancesUpdatesBlocked; } setInstanceUpdatesBlocked(bool value)66 void setInstanceUpdatesBlocked(bool value) { m_instancesUpdatesBlocked = value; } 67 cursorElement()68 SVGCursorElement* cursorElement() const { return m_cursorElement; } setCursorElement(SVGCursorElement * cursorElement)69 void setCursorElement(SVGCursorElement* cursorElement) { m_cursorElement = cursorElement; } 70 correspondingElement()71 SVGElement* correspondingElement() { return m_correspondingElement; } setCorrespondingElement(SVGElement * correspondingElement)72 void setCorrespondingElement(SVGElement* correspondingElement) { m_correspondingElement = correspondingElement; } 73 cursorImageValue()74 CSSCursorImageValue* cursorImageValue() const { return m_cursorImageValue; } setCursorImageValue(CSSCursorImageValue * cursorImageValue)75 void setCursorImageValue(CSSCursorImageValue* cursorImageValue) { m_cursorImageValue = cursorImageValue; } 76 animatedSMILStyleProperties()77 MutableStylePropertySet* animatedSMILStyleProperties() const { return m_animatedSMILStyleProperties.get(); } ensureAnimatedSMILStyleProperties()78 MutableStylePropertySet* ensureAnimatedSMILStyleProperties() 79 { 80 if (!m_animatedSMILStyleProperties) 81 m_animatedSMILStyleProperties = MutableStylePropertySet::create(SVGAttributeMode); 82 return m_animatedSMILStyleProperties.get(); 83 } 84 destroyAnimatedSMILStyleProperties()85 void destroyAnimatedSMILStyleProperties() 86 { 87 m_animatedSMILStyleProperties.clear(); 88 } 89 overrideComputedStyle(Element * element,RenderStyle * parentStyle)90 RenderStyle* overrideComputedStyle(Element* element, RenderStyle* parentStyle) 91 { 92 ASSERT(element); 93 if (!m_useOverrideComputedStyle) 94 return 0; 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; 99 } 100 ASSERT(m_overrideComputedStyle); 101 return m_overrideComputedStyle.get(); 102 } 103 useOverrideComputedStyle()104 bool useOverrideComputedStyle() const { return m_useOverrideComputedStyle; } setUseOverrideComputedStyle(bool value)105 void setUseOverrideComputedStyle(bool value) { m_useOverrideComputedStyle = value; } setNeedsOverrideComputedStyleUpdate()106 void setNeedsOverrideComputedStyleUpdate() { m_needsOverrideComputedStyleUpdate = true; } 107 108 private: 109 HashSet<SVGElementInstance*> m_elementInstances; 110 SVGCursorElement* m_cursorElement; 111 CSSCursorImageValue* m_cursorImageValue; 112 SVGElement* m_correspondingElement; 113 bool m_instancesUpdatesBlocked : 1; 114 bool m_useOverrideComputedStyle : 1; 115 bool m_needsOverrideComputedStyleUpdate : 1; 116 RefPtr<MutableStylePropertySet> m_animatedSMILStyleProperties; 117 RefPtr<RenderStyle> m_overrideComputedStyle; 118 }; 119 120 } 121 122 #endif 123