OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
pdr.
2014/01/07 06:42:53
Can you check that we're able to change this copyr
kouhei (in TOK)
2014/01/07 09:22:28
I'll revert these copyright changes. These were ac
| |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | |
4 * | 3 * |
5 * This library is free software; you can redistribute it and/or | 4 * Redistribution and use in source and binary forms, with or without |
6 * modify it under the terms of the GNU Library General Public | 5 * modification, are permitted provided that the following conditions are |
7 * License as published by the Free Software Foundation; either | 6 * met: |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | 7 * |
10 * This library is distributed in the hope that it will be useful, | 8 * * Redistributions of source code must retain the above copyright |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 * notice, this list of conditions and the following disclaimer. |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 * * Redistributions in binary form must reproduce the above |
13 * Library General Public License for more details. | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
14 * | 17 * |
15 * You should have received a copy of the GNU Library General Public License | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
16 * along with this library; see the file COPYING.LIB. If not, write to | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
18 * Boston, MA 02110-1301, USA. | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
19 */ | 29 */ |
20 | 30 |
21 #ifndef SVGLength_h | 31 #ifndef SVGLength_h |
22 #define SVGLength_h | 32 #define SVGLength_h |
23 | 33 |
24 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionMessages.h" |
35 #include "bindings/v8/ExceptionStatePlaceholder.h" | |
36 #include "bindings/v8/ScriptWrappable.h" | |
37 #include "core/dom/ExceptionCode.h" | |
25 #include "core/svg/SVGLengthContext.h" | 38 #include "core/svg/SVGLengthContext.h" |
26 #include "core/svg/SVGParsingError.h" | 39 #include "core/svg/SVGParsingError.h" |
27 #include "core/svg/properties/SVGPropertyTraits.h" | 40 #include "core/svg/properties/NewSVGProperty.h" |
28 #include "platform/animation/AnimationUtilities.h" | 41 #include "core/svg/properties/NewSVGPropertyTearOff.h" |
29 | 42 |
30 namespace WebCore { | 43 namespace WebCore { |
31 | 44 |
45 /* use SVGLength.h decls */ | |
32 class CSSPrimitiveValue; | 46 class CSSPrimitiveValue; |
33 class ExceptionState; | 47 class ExceptionState; |
34 class QualifiedName; | 48 class QualifiedName; |
35 | 49 |
36 enum SVGLengthNegativeValuesMode { | 50 enum SVGLengthNegativeValuesMode { |
37 AllowNegativeLengths, | 51 AllowNegativeLengths, |
38 ForbidNegativeLengths | 52 ForbidNegativeLengths |
39 }; | 53 }; |
40 | 54 |
41 class SVGLength { | 55 class SVGLengthTearOff; |
42 WTF_MAKE_FAST_ALLOCATED; | 56 |
57 class SVGLength : public NewSVGPropertyBase { | |
43 public: | 58 public: |
44 // Forward declare these enums in the w3c naming scheme, for IDL generation | 59 typedef SVGLengthTearOff TearOffType; |
45 enum { | |
46 SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown, | |
47 SVG_LENGTHTYPE_NUMBER = LengthTypeNumber, | |
48 SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage, | |
49 SVG_LENGTHTYPE_EMS = LengthTypeEMS, | |
50 SVG_LENGTHTYPE_EXS = LengthTypeEXS, | |
51 SVG_LENGTHTYPE_PX = LengthTypePX, | |
52 SVG_LENGTHTYPE_CM = LengthTypeCM, | |
53 SVG_LENGTHTYPE_MM = LengthTypeMM, | |
54 SVG_LENGTHTYPE_IN = LengthTypeIN, | |
55 SVG_LENGTHTYPE_PT = LengthTypePT, | |
56 SVG_LENGTHTYPE_PC = LengthTypePC | |
57 }; | |
58 | 60 |
59 SVGLength(SVGLengthMode = LengthModeOther, const String& valueAsString = Str ing()); | 61 static PassRefPtr<SVGLength> create(SVGLengthMode mode = LengthModeOther) |
60 SVGLength(const SVGLengthContext&, float, SVGLengthMode = LengthModeOther, S VGLengthType = LengthTypeNumber); | 62 { |
61 SVGLength(const SVGLength&); | 63 return adoptRef(new SVGLength(mode)); |
64 } | |
62 | 65 |
63 SVGLengthType unitType() const; | 66 PassRefPtr<SVGLength> clone() const; |
64 SVGLengthMode unitMode() const; | 67 virtual PassRefPtr<NewSVGPropertyBase> cloneForAnimation(const String&) cons t; |
68 | |
69 SVGLengthType unitType() const { return static_cast<SVGLengthType>(m_unitTyp e); } | |
70 void setUnitType(SVGLengthType); | |
71 SVGLengthMode unitMode() const { return static_cast<SVGLengthMode>(m_unitMod e); } | |
65 | 72 |
66 bool operator==(const SVGLength&) const; | 73 bool operator==(const SVGLength&) const; |
67 bool operator!=(const SVGLength&) const; | 74 bool operator!=(const SVGLength& other) const { return !operator==(other); } |
68 | 75 |
69 static SVGLength construct(SVGLengthMode, const String&, SVGParsingError&, S VGLengthNegativeValuesMode = AllowNegativeLengths); | 76 float value(const SVGLengthContext& context) const |
70 | 77 { |
71 float value(const SVGLengthContext&) const; | 78 return value(context, IGNORE_EXCEPTION); |
79 } | |
72 float value(const SVGLengthContext&, ExceptionState&) const; | 80 float value(const SVGLengthContext&, ExceptionState&) const; |
73 void setValue(float, const SVGLengthContext&, ExceptionState&); | 81 void setValue(float, const SVGLengthContext&, ExceptionState&); |
74 void setValue(const SVGLengthContext&, float, SVGLengthMode, SVGLengthType, ExceptionState&); | |
75 | 82 |
76 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } | 83 float valueInSpecifiedUnits() const { return m_valueInSpecifiedUnits; } |
77 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } | 84 void setValueInSpecifiedUnits(float value) { m_valueInSpecifiedUnits = value ; } |
78 | 85 |
79 float valueAsPercentage() const; | 86 float valueAsPercentage() const; |
80 | 87 |
81 String valueAsString() const; | 88 virtual String valueAsString() const; |
pdr.
2014/01/07 06:42:53
Please add OVERRIDE (here, and elsewhere)
virtual
kouhei (in TOK)
2014/01/07 09:22:28
Done.
| |
82 void setValueAsString(const String&, ExceptionState&); | 89 void setValueAsString(const String&, ExceptionState&); |
83 void setValueAsString(const String&, SVGLengthMode, ExceptionState&); | |
84 | 90 |
85 void newValueSpecifiedUnits(unsigned short, float valueInSpecifiedUnits, Exc eptionState&); | 91 void newValueSpecifiedUnits(SVGLengthType, float valueInSpecifiedUnits); |
86 void convertToSpecifiedUnits(unsigned short, const SVGLengthContext&, Except ionState&); | 92 void convertToSpecifiedUnits(SVGLengthType, const SVGLengthContext&, Excepti onState&); |
87 | 93 |
88 // Helper functions | 94 // Helper functions |
89 inline bool isRelative() const | 95 inline bool isRelative() const |
90 { | 96 { |
91 SVGLengthType type = unitType(); | 97 return m_unitType == LengthTypePercentage |
92 return type == LengthTypePercentage || type == LengthTypeEMS || type == LengthTypeEXS; | 98 || m_unitType == LengthTypeEMS |
99 || m_unitType == LengthTypeEXS; | |
93 } | 100 } |
94 | 101 |
95 bool isZero() const | 102 bool isZero() const |
96 { | 103 { |
97 return !m_valueInSpecifiedUnits; | 104 return !m_valueInSpecifiedUnits; |
98 } | 105 } |
99 | 106 |
100 static SVGLength fromCSSPrimitiveValue(CSSPrimitiveValue*); | 107 static PassRefPtr<SVGLength> fromCSSPrimitiveValue(CSSPrimitiveValue*); |
101 static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(const SVGLength&); | 108 static PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue(PassRefPtr<SVGLengt h>); |
102 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); | 109 static SVGLengthMode lengthModeForAnimatedLengthAttribute(const QualifiedNam e&); |
103 | 110 |
104 SVGLength blend(const SVGLength& from, float progress) const | 111 PassRefPtr<SVGLength> blend(const SVGLength* from, float progress) const; |
112 | |
113 virtual void add(PassRefPtr<NewSVGPropertyBase>, SVGElement*); | |
114 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> from, PassRefPtr<NewSVGProp ertyBase> to, PassRefPtr<NewSVGPropertyBase> toAtEndOfDurationValue, SVGElement* contextElement); | |
115 virtual float calculateDistance(PassRefPtr<NewSVGPropertyBase> to, SVGElemen t* contextElement); | |
116 | |
117 private: | |
118 SVGLength(SVGLengthMode); | |
119 | |
120 float m_valueInSpecifiedUnits; | |
121 unsigned m_unitMode : 2; | |
122 unsigned m_unitType : 4; | |
123 }; | |
124 | |
125 inline SVGLength* toSVGLength(NewSVGPropertyBase* base) | |
126 { | |
127 // FIXME: add type checking | |
pdr.
2014/01/07 06:42:53
(here, and elsewhere in this patch)
Can you implem
kouhei (in TOK)
2014/01/07 09:22:28
Done.
| |
128 return static_cast<SVGLength*>(base); | |
129 } | |
130 | |
131 class SVGLengthTearOff : public NewSVGPropertyTearOff<SVGLength>, public ScriptW rappable { | |
132 public: | |
133 // Forward declare these enums in the w3c naming scheme, for IDL generation | |
134 enum { | |
135 SVG_LENGTHTYPE_UNKNOWN = LengthTypeUnknown, | |
136 SVG_LENGTHTYPE_NUMBER = LengthTypeNumber, | |
137 SVG_LENGTHTYPE_PERCENTAGE = LengthTypePercentage, | |
138 SVG_LENGTHTYPE_EMS = LengthTypeEMS, | |
139 SVG_LENGTHTYPE_EXS = LengthTypeEXS, | |
140 SVG_LENGTHTYPE_PX = LengthTypePX, | |
141 SVG_LENGTHTYPE_CM = LengthTypeCM, | |
142 SVG_LENGTHTYPE_MM = LengthTypeMM, | |
143 SVG_LENGTHTYPE_IN = LengthTypeIN, | |
144 SVG_LENGTHTYPE_PT = LengthTypePT, | |
145 SVG_LENGTHTYPE_PC = LengthTypePC | |
146 }; | |
147 | |
148 static PassRefPtr<SVGLengthTearOff> create(PassRefPtr<SVGLength> target, SVG Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie dName& attributeName = nullQName()) | |
105 { | 149 { |
106 SVGLengthType toType = unitType(); | 150 return adoptRef(new SVGLengthTearOff(target, contextElement, propertyIsA nimVal, attributeName)); |
107 SVGLengthType fromType = from.unitType(); | |
108 if ((from.isZero() && isZero()) | |
109 || fromType == LengthTypeUnknown | |
110 || toType == LengthTypeUnknown | |
111 || (!from.isZero() && fromType != LengthTypePercentage && toType == LengthTypePercentage) | |
112 || (!isZero() && fromType == LengthTypePercentage && toType != Lengt hTypePercentage) | |
113 || (!from.isZero() && !isZero() && (fromType == LengthTypeEMS || fro mType == LengthTypeEXS) && fromType != toType)) | |
114 return *this; | |
115 | |
116 SVGLength length; | |
117 TrackExceptionState exceptionState; | |
118 | |
119 if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { | |
120 float fromPercent = from.valueAsPercentage() * 100; | |
121 float toPercent = valueAsPercentage() * 100; | |
122 length.newValueSpecifiedUnits(LengthTypePercentage, WebCore::blend(f romPercent, toPercent, progress), exceptionState); | |
123 if (exceptionState.hadException()) | |
124 return SVGLength(); | |
125 return length; | |
126 } | |
127 | |
128 if (fromType == toType || from.isZero() || isZero() || fromType == Lengt hTypeEMS || fromType == LengthTypeEXS) { | |
129 float fromValue = from.valueInSpecifiedUnits(); | |
130 float toValue = valueInSpecifiedUnits(); | |
131 if (isZero()) | |
132 length.newValueSpecifiedUnits(fromType, WebCore::blend(fromValue , toValue, progress), exceptionState); | |
133 else | |
134 length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState); | |
135 if (exceptionState.hadException()) | |
136 return SVGLength(); | |
137 return length; | |
138 } | |
139 | |
140 ASSERT(!isRelative()); | |
141 ASSERT(!from.isRelative()); | |
142 | |
143 SVGLengthContext nonRelativeLengthContext(0); | |
144 float fromValueInUserUnits = nonRelativeLengthContext.convertValueToUser Units(from.valueInSpecifiedUnits(), from.unitMode(), fromType, exceptionState); | |
145 if (exceptionState.hadException()) | |
146 return SVGLength(); | |
147 | |
148 float fromValue = nonRelativeLengthContext.convertValueFromUserUnits(fro mValueInUserUnits, unitMode(), toType, exceptionState); | |
149 if (exceptionState.hadException()) | |
150 return SVGLength(); | |
151 | |
152 float toValue = valueInSpecifiedUnits(); | |
153 length.newValueSpecifiedUnits(toType, WebCore::blend(fromValue, toValue, progress), exceptionState); | |
154 | |
155 if (exceptionState.hadException()) | |
156 return SVGLength(); | |
157 return length; | |
158 } | 151 } |
159 | 152 |
153 SVGLengthType unitType(); | |
154 SVGLengthMode unitMode(); | |
155 float value(ExceptionState&); | |
156 void setValue(float value, ExceptionState&); | |
157 float valueInSpecifiedUnits(); | |
158 void setValueInSpecifiedUnits(float value, ExceptionState&); | |
159 String valueAsString(); | |
160 void setValueAsString(const String&, ExceptionState&); | |
161 void newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedU nits, ExceptionState&); | |
162 void convertToSpecifiedUnits(unsigned short unitType, ExceptionState&); | |
163 | |
160 private: | 164 private: |
161 float m_valueInSpecifiedUnits; | 165 SVGLengthTearOff(PassRefPtr<SVGLength>, SVGElement* contextElement, Property IsAnimValType, const QualifiedName& attributeName = nullQName()); |
pdr.
2014/01/07 06:42:53
Can you check whether this should be anyQName() or
kouhei (in TOK)
2014/01/08 08:12:07
I think nullQName is appropriate here, as we want
| |
162 unsigned int m_unit; | |
163 }; | 166 }; |
164 | 167 |
165 template<> | |
166 struct SVGPropertyTraits<SVGLength> { | |
167 static SVGLength initialValue() { return SVGLength(); } | |
168 static String toString(const SVGLength& type) { return type.valueAsString(); } | |
169 }; | |
170 | |
171 | |
172 } // namespace WebCore | 168 } // namespace WebCore |
173 | 169 |
174 #endif // SVGLength_h | 170 #endif // SVGLength_h |
OLD | NEW |