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

Side by Side Diff: Source/core/svg/properties/SVGMatrixTearOff.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 SVGStaticPropertyWithParentTearOff_h 20 #ifndef SVGMatrixTearOff_h
21 #define SVGStaticPropertyWithParentTearOff_h 21 #define SVGMatrixTearOff_h
22 22
23 #include "core/svg/SVGTransform.h"
23 #include "core/svg/properties/SVGPropertyTearOff.h" 24 #include "core/svg/properties/SVGPropertyTearOff.h"
24 25
25 namespace WebCore { 26 namespace WebCore {
26 27
27 #if COMPILER(MSVC) 28 class SVGMatrixTearOff : public SVGPropertyTearOff<SVGMatrix> {
28 // UpdateMethod is 12 bytes. We have to pack to a size greater than or equal to that to avoid an
29 // alignment warning (C4121). 16 is the next-largest size allowed for packing, s o we use that.
30 #pragma pack(push, 16)
31 #endif
32 template<typename ParentType, typename PropertyType>
33 class SVGStaticPropertyWithParentTearOff : public SVGPropertyTearOff<PropertyTyp e> {
34 public: 29 public:
35 typedef SVGStaticPropertyWithParentTearOff<ParentType, PropertyType> Self;
36 typedef void (ParentType::*UpdateMethod)();
37
38 // Used for non-animated POD types that are not associated with a SVGAnimate dProperty object, nor with a XML DOM attribute 30 // Used for non-animated POD types that are not associated with a SVGAnimate dProperty object, nor with a XML DOM attribute
39 // and that contain a parent type that's exposed to the bindings via a SVGSt aticPropertyTearOff object 31 // and that contain a parent type that's exposed to the bindings via a SVGSt aticPropertyTearOff object
40 // (for example: SVGTransform::matrix). 32 // (for example: SVGTransform::matrix).
41 static PassRefPtr<Self> create(SVGProperty* parent, PropertyType& value, Upd ateMethod update) 33 static PassRefPtr<SVGMatrixTearOff> create(SVGPropertyTearOff<SVGTransform>* parent, SVGMatrix& value)
42 { 34 {
43 ASSERT(parent); 35 ASSERT(parent);
44 return adoptRef(new Self(parent, value, update)); 36 RefPtr<SVGMatrixTearOff> result = adoptRef(new SVGMatrixTearOff(parent, value));
37 parent->addChild(result.get());
38 return result.release();
45 } 39 }
46 40
47 virtual void commitChange() 41 virtual void commitChange()
48 { 42 {
49 (static_cast<SVGPropertyTearOff<ParentType>*>(m_parent.get())->propertyR eference().*m_update)(); 43 if (!m_parent)
44 return;
45
46 m_parent->propertyReference().updateSVGMatrix();
50 m_parent->commitChange(); 47 m_parent->commitChange();
51 } 48 }
52 49
50 virtual void detachWrapper() OVERRIDE
51 {
52 SVGPropertyTearOff<SVGMatrix>::detachWrapper();
53 m_parent = 0;
54 }
55
53 private: 56 private:
54 SVGStaticPropertyWithParentTearOff(SVGProperty* parent, PropertyType& value, UpdateMethod update) 57 SVGMatrixTearOff(SVGPropertyTearOff<SVGTransform>* parent, SVGMatrix& value)
55 : SVGPropertyTearOff<PropertyType>(0, UndefinedRole, value) 58 : SVGPropertyTearOff<SVGMatrix>(0, UndefinedRole, value)
56 , m_update(update)
57 , m_parent(parent) 59 , m_parent(parent)
58 { 60 {
59 } 61 }
60 62
61 UpdateMethod m_update; 63 SVGPropertyTearOff<SVGTransform>* m_parent;
62 RefPtr<SVGProperty> m_parent;
63 }; 64 };
64 #if COMPILER(MSVC)
65 #pragma pack(pop)
66 #endif
67 65
68 } 66 }
69 67
70 #endif // SVGStaticPropertyWithParentTearOff_h 68 #endif // SVGMatrixTearOff_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698