Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: Source/core/svg/properties/SVGPropertyTearOff.h

Issue 23995018: Fix lifetime handling of SVGPropertyTearOffs. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 26
27 namespace WebCore { 27 namespace WebCore {
28 28
29 class SVGPropertyTearOffBase : public SVGProperty {
30 public:
31 virtual void detachWrapper() = 0;
32 };
33
29 template<typename PropertyType> 34 template<typename PropertyType>
30 class SVGPropertyTearOff : public SVGProperty { 35 class SVGPropertyTearOff : public SVGPropertyTearOffBase {
31 public: 36 public:
32 typedef SVGPropertyTearOff<PropertyType> Self; 37 typedef SVGPropertyTearOff<PropertyType> Self;
33 38
34 // Used for child types (baseVal/animVal) of a SVGAnimated* property (for ex ample: SVGAnimatedLength::baseVal()). 39 // 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)). 40 // 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) 41 static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPro pertyRole role, PropertyType& value)
37 { 42 {
38 ASSERT(animatedProperty); 43 ASSERT(animatedProperty);
39 return adoptRef(new Self(animatedProperty, role, value)); 44 return adoptRef(new Self(animatedProperty, role, value));
40 } 45 }
(...skipping 23 matching lines...) Expand all
64 m_contextElement = m_animatedProperty->contextElement(); 69 m_contextElement = m_animatedProperty->contextElement();
65 } 70 }
66 71
67 SVGElement* contextElement() const 72 SVGElement* contextElement() const
68 { 73 {
69 if (!m_animatedProperty || m_valueIsCopy) 74 if (!m_animatedProperty || m_valueIsCopy)
70 return 0; 75 return 0;
71 return m_contextElement.get(); 76 return m_contextElement.get();
72 } 77 }
73 78
74 void detachWrapper() 79 void addChild(SVGPropertyTearOffBase* child)
80 {
81 m_childTearOffs.append(child);
82 }
83
84 virtual void detachWrapper() OVERRIDE
75 { 85 {
76 if (m_valueIsCopy) 86 if (m_valueIsCopy)
77 return; 87 return;
78 88
89 detachChildren();
90
79 // Switch from a live value, to a non-live value. 91 // Switch from a live value, to a non-live value.
80 // For example: <text x="50"/> 92 // For example: <text x="50"/>
81 // var item = text.x.baseVal.getItem(0); 93 // var item = text.x.baseVal.getItem(0);
82 // text.setAttribute("x", "100"); 94 // text.setAttribute("x", "100");
83 // item.value still has to report '50' and it has to be possible to modi fy 'item' 95 // 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. 96 // 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. 97 // Whenever the XML DOM modifies the "x" attribute, all existing wrapper s are detached, using this function.
86 m_value = new PropertyType(*m_value); 98 m_value = new PropertyType(*m_value);
87 m_valueIsCopy = true; 99 m_valueIsCopy = true;
88 m_animatedProperty = 0; 100 m_animatedProperty = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 SVGPropertyTearOff(const PropertyType& initialValue) 133 SVGPropertyTearOff(const PropertyType& initialValue)
122 : m_animatedProperty(0) 134 : m_animatedProperty(0)
123 , m_role(UndefinedRole) 135 , m_role(UndefinedRole)
124 , m_value(new PropertyType(initialValue)) 136 , m_value(new PropertyType(initialValue))
125 , m_valueIsCopy(true) 137 , m_valueIsCopy(true)
126 { 138 {
127 } 139 }
128 140
129 virtual ~SVGPropertyTearOff() 141 virtual ~SVGPropertyTearOff()
130 { 142 {
143 detachChildren();
144
131 if (m_valueIsCopy) 145 if (m_valueIsCopy)
132 delete m_value; 146 delete m_value;
133 } 147 }
134 148
149 void detachChildren()
150 {
151 for (Vector<RefPtr<SVGPropertyTearOffBase> >::iterator iter = m_childTea rOffs.begin(); iter != m_childTearOffs.end(); iter++)
pdr. 2013/09/13 22:01:15 This pattern can lead to badness if detachWrapper(
ojan 2013/09/13 22:12:04 This definitely cannot change the list.
152 (*iter)->detachWrapper();
153 m_childTearOffs.clear();
154 }
155
135 RefPtr<SVGElement> m_contextElement; 156 RefPtr<SVGElement> m_contextElement;
136 SVGAnimatedProperty* m_animatedProperty; 157 SVGAnimatedProperty* m_animatedProperty;
137 SVGPropertyRole m_role; 158 SVGPropertyRole m_role;
138 PropertyType* m_value; 159 PropertyType* m_value;
160 Vector<RefPtr<SVGPropertyTearOffBase> > m_childTearOffs;
139 bool m_valueIsCopy : 1; 161 bool m_valueIsCopy : 1;
140 }; 162 };
141 163
142 } 164 }
143 165
144 #endif // SVGPropertyTearOff_h 166 #endif // SVGPropertyTearOff_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698