OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/svg/SVGPoint.h" | 31 #include "core/svg/SVGPoint.h" |
32 | 32 |
33 #include "bindings/core/v8/ExceptionState.h" | |
34 #include "core/dom/ExceptionCode.h" | |
35 #include "core/svg/SVGAnimationElement.h" | 33 #include "core/svg/SVGAnimationElement.h" |
36 #include "core/svg/SVGParserUtilities.h" | 34 #include "core/svg/SVGParserUtilities.h" |
37 #include "platform/transforms/AffineTransform.h" | 35 #include "platform/transforms/AffineTransform.h" |
38 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
39 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
40 | 38 |
41 namespace blink { | 39 namespace blink { |
42 | 40 |
43 SVGPoint::SVGPoint() | 41 SVGPoint::SVGPoint() |
44 { | 42 { |
45 } | 43 } |
46 | 44 |
47 SVGPoint::SVGPoint(const FloatPoint& point) | 45 SVGPoint::SVGPoint(const FloatPoint& point) |
48 : m_value(point) | 46 : m_value(point) |
49 { | 47 { |
50 } | 48 } |
51 | 49 |
52 PassRefPtrWillBeRawPtr<SVGPoint> SVGPoint::clone() const | 50 PassRefPtrWillBeRawPtr<SVGPoint> SVGPoint::clone() const |
53 { | 51 { |
54 return SVGPoint::create(m_value); | 52 return SVGPoint::create(m_value); |
55 } | 53 } |
56 | 54 |
57 template<typename CharType> | 55 template<typename CharType> |
58 void SVGPoint::parse(const CharType*& ptr, const CharType* end, ExceptionState&
exceptionState) | 56 bool SVGPoint::parse(const CharType*& ptr, const CharType* end) |
59 { | 57 { |
60 const CharType* start = ptr; | |
61 | |
62 skipOptionalSVGSpaces(ptr, end); | 58 skipOptionalSVGSpaces(ptr, end); |
63 | 59 |
64 float x = 0.0f; | 60 float x = 0.0f; |
65 float y = 0.0f; | 61 float y = 0.0f; |
66 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, DisallowWh
itespace); | 62 bool valid = parseNumber(ptr, end, x) && parseNumber(ptr, end, y, DisallowWh
itespace); |
67 | 63 |
68 if (!valid) { | 64 if (!valid) |
69 exceptionState.throwDOMException(SyntaxError, "Problem parsing point \""
+ String(start, end - start) + "\""); | 65 return false; |
70 return; | |
71 } | |
72 | 66 |
73 skipOptionalSVGSpaces(ptr, end); | 67 if (skipOptionalSVGSpaces(ptr, end)) { |
74 if (ptr < end) { // nothing should come after the last, fourth number | 68 // Nothing should come after the second number. |
75 exceptionState.throwDOMException(SyntaxError, "Problem parsing point \""
+ String(start, end - start) + "\""); | 69 return false; |
76 return; | |
77 } | 70 } |
78 | 71 |
79 m_value = FloatPoint(x, y); | 72 m_value = FloatPoint(x, y); |
| 73 return true; |
80 } | 74 } |
81 | 75 |
82 FloatPoint SVGPoint::matrixTransform(const AffineTransform& transform) const | 76 FloatPoint SVGPoint::matrixTransform(const AffineTransform& transform) const |
83 { | 77 { |
84 double newX, newY; | 78 double newX, newY; |
85 transform.map(static_cast<double>(x()), static_cast<double>(y()), newX, newY
); | 79 transform.map(static_cast<double>(x()), static_cast<double>(y()), newX, newY
); |
86 return FloatPoint::narrowPrecision(newX, newY); | 80 return FloatPoint::narrowPrecision(newX, newY); |
87 } | 81 } |
88 | 82 |
89 void SVGPoint::setValueAsString(const String& string, ExceptionState& exceptionS
tate) | 83 SVGParsingError SVGPoint::setValueAsString(const String& string) |
90 { | 84 { |
91 if (string.isEmpty()) { | 85 if (string.isEmpty()) { |
92 m_value = FloatPoint(0.0f, 0.0f); | 86 m_value = FloatPoint(0.0f, 0.0f); |
93 return; | 87 return NoError; |
94 } | 88 } |
95 | 89 |
| 90 bool valid; |
96 if (string.is8Bit()) { | 91 if (string.is8Bit()) { |
97 const LChar* ptr = string.characters8(); | 92 const LChar* ptr = string.characters8(); |
98 const LChar* end = ptr + string.length(); | 93 const LChar* end = ptr + string.length(); |
99 parse(ptr, end, exceptionState); | 94 valid = parse(ptr, end); |
100 return; | 95 } else { |
| 96 const UChar* ptr = string.characters16(); |
| 97 const UChar* end = ptr + string.length(); |
| 98 valid = parse(ptr, end); |
101 } | 99 } |
102 | 100 return valid ? NoError : ParsingAttributeFailedError; |
103 const UChar* ptr = string.characters16(); | |
104 const UChar* end = ptr + string.length(); | |
105 parse(ptr, end, exceptionState); | |
106 } | 101 } |
107 | 102 |
108 String SVGPoint::valueAsString() const | 103 String SVGPoint::valueAsString() const |
109 { | 104 { |
110 StringBuilder builder; | 105 StringBuilder builder; |
111 builder.appendNumber(x()); | 106 builder.appendNumber(x()); |
112 builder.append(' '); | 107 builder.append(' '); |
113 builder.appendNumber(y()); | 108 builder.appendNumber(y()); |
114 return builder.toString(); | 109 return builder.toString(); |
115 } | 110 } |
(...skipping 11 matching lines...) Expand all Loading... |
127 } | 122 } |
128 | 123 |
129 float SVGPoint::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SV
GElement* contextElement) | 124 float SVGPoint::calculateDistance(PassRefPtrWillBeRawPtr<SVGPropertyBase> to, SV
GElement* contextElement) |
130 { | 125 { |
131 // SVGPoint is not animated by itself | 126 // SVGPoint is not animated by itself |
132 ASSERT_NOT_REACHED(); | 127 ASSERT_NOT_REACHED(); |
133 return 0.0f; | 128 return 0.0f; |
134 } | 129 } |
135 | 130 |
136 } | 131 } |
OLD | NEW |