OLD | NEW |
| (Empty) |
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 SVGMatrixTearOff_h | |
21 #define SVGMatrixTearOff_h | |
22 | |
23 #include "core/svg/SVGTransform.h" | |
24 #include "core/svg/properties/SVGPropertyTearOff.h" | |
25 | |
26 namespace WebCore { | |
27 | |
28 class SVGMatrixTearOff FINAL : public SVGPropertyTearOff<SVGMatrix> { | |
29 public: | |
30 // Used for child types (baseVal/animVal) of a SVGAnimated* property (for ex
ample: SVGAnimatedLength::baseVal()). | |
31 // Also used for list tear offs (for example: text.x.baseVal.getItem(0)). | |
32 static PassRefPtr<SVGMatrixTearOff> create(SVGAnimatedProperty* animatedProp
erty, SVGPropertyRole role, SVGMatrix& value) | |
33 { | |
34 ASSERT(animatedProperty); | |
35 return adoptRef(new SVGMatrixTearOff(animatedProperty, role, value)); | |
36 } | |
37 | |
38 // Used for non-animated POD types (for example: SVGSVGElement::createSVGLen
gth()). | |
39 static PassRefPtr<SVGMatrixTearOff> create(const SVGMatrix& initialValue) | |
40 { | |
41 return adoptRef(new SVGMatrixTearOff(initialValue)); | |
42 } | |
43 | |
44 // Used for non-animated POD types that are not associated with a SVGAnimate
dProperty object, nor with a XML DOM attribute | |
45 // and that contain a parent type that's exposed to the bindings via a SVGSt
aticPropertyTearOff object | |
46 // (for example: SVGTransform::matrix). | |
47 static PassRefPtr<SVGMatrixTearOff> create(SVGPropertyTearOff<SVGTransform>*
parent, SVGMatrix& value) | |
48 { | |
49 ASSERT(parent); | |
50 RefPtr<SVGMatrixTearOff> result = adoptRef(new SVGMatrixTearOff(parent,
value)); | |
51 parent->addChild(result->m_weakFactory.createWeakPtr()); | |
52 return result.release(); | |
53 } | |
54 | |
55 virtual void commitChange() OVERRIDE | |
56 { | |
57 if (m_parent) { | |
58 // This is a tear-off from a SVGPropertyTearOff<SVGTransform>. | |
59 m_parent->propertyReference().updateSVGMatrix(); | |
60 m_parent->commitChange(); | |
61 } else { | |
62 // This is either a detached tear-off or a reference tear-off from a
AnimatedProperty. | |
63 SVGPropertyTearOff<SVGMatrix>::commitChange(); | |
64 } | |
65 } | |
66 | |
67 // SVGMatrixTearOff can be a child tear-off of a SVGTransform tear-off, | |
68 // which means that |m_value| may be pointing inside |m_value| of the other
tear-off. | |
69 // This method is called from the parent SVGTransform tear-off when |m_paren
t->m_value| is updated, | |
70 // so that |this->m_value| would point to valid location. | |
71 virtual void setValueForMatrixIfNeeded(SVGTransform* transform) OVERRIDE | |
72 { | |
73 setValue(transform->svgMatrix()); | |
74 } | |
75 | |
76 SVGPropertyTearOff<SVGTransform>* parent() { return m_parent; } | |
77 | |
78 private: | |
79 SVGMatrixTearOff(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role
, SVGMatrix& value) | |
80 : SVGPropertyTearOff<SVGMatrix>(animatedProperty, role, value) | |
81 , m_parent(0) | |
82 , m_weakFactory(this) | |
83 { | |
84 } | |
85 | |
86 SVGMatrixTearOff(const SVGMatrix& initialValue) | |
87 : SVGPropertyTearOff<SVGMatrix>(initialValue) | |
88 , m_parent(0) | |
89 , m_weakFactory(this) | |
90 { | |
91 } | |
92 | |
93 SVGMatrixTearOff(SVGPropertyTearOff<SVGTransform>* parent, SVGMatrix& value) | |
94 : SVGPropertyTearOff<SVGMatrix>(0, UndefinedRole, value) | |
95 , m_parent(parent) | |
96 , m_weakFactory(this) | |
97 { | |
98 } | |
99 | |
100 // m_parent is kept alive from V8 wrapper. | |
101 SVGPropertyTearOff<SVGTransform>* m_parent; | |
102 | |
103 WeakPtrFactory<SVGPropertyTearOffBase > m_weakFactory; | |
104 }; | |
105 | |
106 } | |
107 | |
108 #endif // SVGMatrixTearOff_h | |
OLD | NEW |