OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 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 |
| 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. |
| 17 * |
| 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. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 |
| 33 #include "core/svg/SVGLengthTearOff.h" |
| 34 |
| 35 #include "bindings/v8/ExceptionState.h" |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 namespace { |
| 40 |
| 41 inline SVGLengthType toSVGLengthType(unsigned short type) |
| 42 { |
| 43 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); |
| 44 return static_cast<SVGLengthType>(type); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 SVGLengthType SVGLengthTearOff::unitType() |
| 50 { |
| 51 return target()->unitType(); |
| 52 } |
| 53 |
| 54 SVGLengthMode SVGLengthTearOff::unitMode() |
| 55 { |
| 56 return target()->unitMode(); |
| 57 } |
| 58 |
| 59 float SVGLengthTearOff::value(ExceptionState& es) |
| 60 { |
| 61 SVGLengthContext lengthContext(contextElement()); |
| 62 return target()->value(lengthContext, es); |
| 63 } |
| 64 |
| 65 void SVGLengthTearOff::setValue(float value, ExceptionState& es) |
| 66 { |
| 67 if (isImmutable()) { |
| 68 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 69 return; |
| 70 } |
| 71 |
| 72 SVGLengthContext lengthContext(contextElement()); |
| 73 target()->setValue(value, lengthContext, es); |
| 74 commitChange(); |
| 75 } |
| 76 |
| 77 float SVGLengthTearOff::valueInSpecifiedUnits() |
| 78 { |
| 79 return target()->valueInSpecifiedUnits(); |
| 80 } |
| 81 |
| 82 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& es) |
| 83 { |
| 84 if (isImmutable()) { |
| 85 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 86 return; |
| 87 } |
| 88 target()->setValueInSpecifiedUnits(value); |
| 89 commitChange(); |
| 90 } |
| 91 |
| 92 String SVGLengthTearOff::valueAsString() |
| 93 { |
| 94 return target()->valueAsString(); |
| 95 } |
| 96 |
| 97 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) |
| 98 { |
| 99 if (isImmutable()) { |
| 100 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 101 return; |
| 102 } |
| 103 |
| 104 target()->setValueAsString(str, es); |
| 105 commitChange(); |
| 106 } |
| 107 |
| 108 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) |
| 109 { |
| 110 if (isImmutable()) { |
| 111 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 112 return; |
| 113 } |
| 114 |
| 115 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { |
| 116 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); |
| 117 return; |
| 118 } |
| 119 |
| 120 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified
Units); |
| 121 commitChange(); |
| 122 } |
| 123 |
| 124 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) |
| 125 { |
| 126 if (isImmutable()) { |
| 127 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 128 return; |
| 129 } |
| 130 |
| 131 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { |
| 132 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); |
| 133 return; |
| 134 } |
| 135 |
| 136 SVGLengthContext lengthContext(contextElement()); |
| 137 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext,
exceptionState); |
| 138 commitChange(); |
| 139 } |
| 140 |
| 141 SVGLengthTearOff::SVGLengthTearOff(PassRefPtr<SVGLength> target, SVGElement* con
textElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attri
buteName) |
| 142 : NewSVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal
, attributeName) |
| 143 { |
| 144 ScriptWrappable::init(this); |
| 145 } |
| 146 |
| 147 } |
OLD | NEW |