2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
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.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
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.
33 #include "core/svg/SVGLengthTearOff.h"
35 #include "bindings/core/v8/ExceptionState.h"
36 #include "core/dom/ExceptionCode.h"
42 inline SVGLengthType toSVGLengthType(unsigned short type)
44 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC);
45 return static_cast<SVGLengthType>(type);
50 SVGLengthType SVGLengthTearOff::unitType()
52 return target()->unitType();
55 SVGLengthMode SVGLengthTearOff::unitMode()
57 return target()->unitMode();
60 float SVGLengthTearOff::value(ExceptionState& es)
62 SVGLengthContext lengthContext(contextElement());
63 return target()->value(lengthContext, es);
66 void SVGLengthTearOff::setValue(float value, ExceptionState& es)
69 es.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
73 SVGLengthContext lengthContext(contextElement());
74 target()->setValue(value, lengthContext, es);
78 float SVGLengthTearOff::valueInSpecifiedUnits()
80 return target()->valueInSpecifiedUnits();
83 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& es)
86 es.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
89 target()->setValueInSpecifiedUnits(value);
93 String SVGLengthTearOff::valueAsString()
95 return target()->valueAsString();
98 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es)
101 es.throwDOMException(NoModificationAllowedError, "The attribute is read-only.");
105 target()->setValueAsString(str, es);
109 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState)
112 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
116 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) {
117 exceptionState.throwDOMException(NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ").");
121 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecifiedUnits);
125 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState)
128 exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
132 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) {
133 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ").");
137 SVGLengthContext lengthContext(contextElement());
138 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext, exceptionState);
142 SVGLengthTearOff::SVGLengthTearOff(PassRefPtr<SVGLength> target, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName)
143 : SVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal, attributeName)