| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #ifndef SVGPropertyTearOff_h | 20 #ifndef SVGPropertyTearOff_h |
| 21 #define SVGPropertyTearOff_h | 21 #define SVGPropertyTearOff_h |
| 22 | 22 |
| 23 #include "core/svg/SVGElement.h" | 23 #include "core/svg/SVGElement.h" |
| 24 #include "core/svg/properties/SVGAnimatedProperty.h" | 24 #include "core/svg/properties/SVGAnimatedProperty.h" |
| 25 #include "core/svg/properties/SVGProperty.h" | 25 #include "core/svg/properties/SVGProperty.h" |
| 26 #include "wtf/WeakPtr.h" |
| 26 | 27 |
| 27 namespace WebCore { | 28 namespace WebCore { |
| 28 | 29 |
| 30 class SVGPropertyTearOffBase : public SVGProperty { |
| 31 public: |
| 32 virtual void detachWrapper() = 0; |
| 33 }; |
| 34 |
| 29 template<typename PropertyType> | 35 template<typename PropertyType> |
| 30 class SVGPropertyTearOff : public SVGProperty { | 36 class SVGPropertyTearOff : public SVGPropertyTearOffBase { |
| 31 public: | 37 public: |
| 32 typedef SVGPropertyTearOff<PropertyType> Self; | 38 typedef SVGPropertyTearOff<PropertyType> Self; |
| 33 | 39 |
| 34 // Used for child types (baseVal/animVal) of a SVGAnimated* property (for ex
ample: SVGAnimatedLength::baseVal()). | 40 // Used for child types (baseVal/animVal) of a SVGAnimated* property (for ex
ample: SVGAnimatedLength::baseVal()). |
| 35 // Also used for list tear offs (for example: text.x.baseVal.getItem(0)). | 41 // Also used for list tear offs (for example: text.x.baseVal.getItem(0)). |
| 36 static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPro
pertyRole role, PropertyType& value) | 42 static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPro
pertyRole role, PropertyType& value) |
| 37 { | 43 { |
| 38 ASSERT(animatedProperty); | 44 ASSERT(animatedProperty); |
| 39 return adoptRef(new Self(animatedProperty, role, value)); | 45 return adoptRef(new Self(animatedProperty, role, value)); |
| 40 } | 46 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 m_contextElement = m_animatedProperty->contextElement(); | 70 m_contextElement = m_animatedProperty->contextElement(); |
| 65 } | 71 } |
| 66 | 72 |
| 67 SVGElement* contextElement() const | 73 SVGElement* contextElement() const |
| 68 { | 74 { |
| 69 if (!m_animatedProperty || m_valueIsCopy) | 75 if (!m_animatedProperty || m_valueIsCopy) |
| 70 return 0; | 76 return 0; |
| 71 return m_contextElement.get(); | 77 return m_contextElement.get(); |
| 72 } | 78 } |
| 73 | 79 |
| 74 void detachWrapper() | 80 void addChild(WeakPtr<SVGPropertyTearOffBase> child) |
| 81 { |
| 82 m_childTearOffs.append(child); |
| 83 } |
| 84 |
| 85 virtual void detachWrapper() OVERRIDE |
| 75 { | 86 { |
| 76 if (m_valueIsCopy) | 87 if (m_valueIsCopy) |
| 77 return; | 88 return; |
| 78 | 89 |
| 90 detachChildren(); |
| 91 |
| 79 // Switch from a live value, to a non-live value. | 92 // Switch from a live value, to a non-live value. |
| 80 // For example: <text x="50"/> | 93 // For example: <text x="50"/> |
| 81 // var item = text.x.baseVal.getItem(0); | 94 // var item = text.x.baseVal.getItem(0); |
| 82 // text.setAttribute("x", "100"); | 95 // text.setAttribute("x", "100"); |
| 83 // item.value still has to report '50' and it has to be possible to modi
fy 'item' | 96 // item.value still has to report '50' and it has to be possible to modi
fy 'item' |
| 84 // w/o changing the "new item" (with x=100) in the text element. | 97 // w/o changing the "new item" (with x=100) in the text element. |
| 85 // Whenever the XML DOM modifies the "x" attribute, all existing wrapper
s are detached, using this function. | 98 // Whenever the XML DOM modifies the "x" attribute, all existing wrapper
s are detached, using this function. |
| 86 m_value = new PropertyType(*m_value); | 99 m_value = new PropertyType(*m_value); |
| 87 m_valueIsCopy = true; | 100 m_valueIsCopy = true; |
| 88 m_animatedProperty = 0; | 101 m_animatedProperty = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 , m_valueIsCopy(true) | 138 , m_valueIsCopy(true) |
| 126 { | 139 { |
| 127 } | 140 } |
| 128 | 141 |
| 129 virtual ~SVGPropertyTearOff() | 142 virtual ~SVGPropertyTearOff() |
| 130 { | 143 { |
| 131 if (m_valueIsCopy) | 144 if (m_valueIsCopy) |
| 132 delete m_value; | 145 delete m_value; |
| 133 } | 146 } |
| 134 | 147 |
| 148 void detachChildren() |
| 149 { |
| 150 for (Vector<WeakPtr<SVGPropertyTearOffBase> >::iterator iter = m_childTe
arOffs.begin(); iter != m_childTearOffs.end(); iter++) { |
| 151 if (iter->get()) |
| 152 iter->get()->detachWrapper(); |
| 153 } |
| 154 m_childTearOffs.clear(); |
| 155 } |
| 156 |
| 135 RefPtr<SVGElement> m_contextElement; | 157 RefPtr<SVGElement> m_contextElement; |
| 136 SVGAnimatedProperty* m_animatedProperty; | 158 SVGAnimatedProperty* m_animatedProperty; |
| 137 SVGPropertyRole m_role; | 159 SVGPropertyRole m_role; |
| 138 PropertyType* m_value; | 160 PropertyType* m_value; |
| 161 Vector<WeakPtr<SVGPropertyTearOffBase> > m_childTearOffs; |
| 139 bool m_valueIsCopy : 1; | 162 bool m_valueIsCopy : 1; |
| 140 }; | 163 }; |
| 141 | 164 |
| 142 } | 165 } |
| 143 | 166 |
| 144 #endif // SVGPropertyTearOff_h | 167 #endif // SVGPropertyTearOff_h |
| OLD | NEW |