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 28 matching lines...) Expand all Loading... |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 inline SVGLengthType toSVGLengthType(unsigned short type) | 43 inline SVGLengthType toSVGLengthType(unsigned short type) |
44 { | 44 { |
45 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); | 45 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); |
46 return static_cast<SVGLengthType>(type); | 46 return static_cast<SVGLengthType>(type); |
47 } | 47 } |
48 | 48 |
| 49 inline bool canResolveRelativeUnits(const SVGElement* contextElement) |
| 50 { |
| 51 return contextElement && contextElement->inDocument(); |
| 52 } |
| 53 |
49 } // namespace | 54 } // namespace |
50 | 55 |
51 SVGLengthType SVGLengthTearOff::unitType() | 56 SVGLengthType SVGLengthTearOff::unitType() |
52 { | 57 { |
53 return target()->unitType(); | 58 return target()->unitType(); |
54 } | 59 } |
55 | 60 |
56 SVGLengthMode SVGLengthTearOff::unitMode() | 61 SVGLengthMode SVGLengthTearOff::unitMode() |
57 { | 62 { |
58 return target()->unitMode(); | 63 return target()->unitMode(); |
59 } | 64 } |
60 | 65 |
61 float SVGLengthTearOff::value(ExceptionState& es) | 66 float SVGLengthTearOff::value(ExceptionState& exceptionState) |
62 { | 67 { |
| 68 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| 69 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); |
| 70 return 0; |
| 71 } |
| 72 |
63 SVGLengthContext lengthContext(contextElement()); | 73 SVGLengthContext lengthContext(contextElement()); |
64 return target()->value(lengthContext, es); | 74 return target()->value(lengthContext); |
65 } | 75 } |
66 | 76 |
67 void SVGLengthTearOff::setValue(float value, ExceptionState& es) | 77 void SVGLengthTearOff::setValue(float value, ExceptionState& exceptionState) |
68 { | 78 { |
69 if (isImmutable()) { | 79 if (isImmutable()) { |
70 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); | 80 exceptionState.throwDOMException(NoModificationAllowedError, "The attrib
ute is read-only."); |
| 81 return; |
| 82 } |
| 83 |
| 84 if (target()->isRelative() && !canResolveRelativeUnits(contextElement())) { |
| 85 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); |
71 return; | 86 return; |
72 } | 87 } |
73 | 88 |
74 SVGLengthContext lengthContext(contextElement()); | 89 SVGLengthContext lengthContext(contextElement()); |
75 target()->setValue(value, lengthContext, es); | 90 target()->setValue(value, lengthContext); |
76 commitChange(); | 91 commitChange(); |
77 } | 92 } |
78 | 93 |
79 float SVGLengthTearOff::valueInSpecifiedUnits() | 94 float SVGLengthTearOff::valueInSpecifiedUnits() |
80 { | 95 { |
81 return target()->valueInSpecifiedUnits(); | 96 return target()->valueInSpecifiedUnits(); |
82 } | 97 } |
83 | 98 |
84 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& es) | 99 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& es) |
85 { | 100 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 if (isImmutable()) { | 143 if (isImmutable()) { |
129 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); | 144 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
130 return; | 145 return; |
131 } | 146 } |
132 | 147 |
133 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { | 148 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { |
134 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); | 149 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); |
135 return; | 150 return; |
136 } | 151 } |
137 | 152 |
| 153 if ((target()->isRelative() || SVGLength::isRelativeUnit(toSVGLengthType(uni
tType))) |
| 154 && !canResolveRelativeUnits(contextElement())) { |
| 155 exceptionState.throwDOMException(NotSupportedError, "Could not resolve r
elative length."); |
| 156 return; |
| 157 } |
| 158 |
138 SVGLengthContext lengthContext(contextElement()); | 159 SVGLengthContext lengthContext(contextElement()); |
139 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext,
exceptionState); | 160 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext); |
140 commitChange(); | 161 commitChange(); |
141 } | 162 } |
142 | 163 |
143 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) | 164 SVGLengthTearOff::SVGLengthTearOff(PassRefPtrWillBeRawPtr<SVGLength> target, SVG
Element* contextElement, PropertyIsAnimValType propertyIsAnimVal, const Qualifie
dName& attributeName) |
144 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) | 165 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, a
ttributeName) |
145 { | 166 { |
146 } | 167 } |
147 | 168 |
148 } | 169 } |
OLD | NEW |