OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 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 SVGLengthMode toSVGLengthMode(unsigned short mode) |
| 42 { |
| 43 ASSERT(mode >= LengthModeWidth && mode <= LengthModeOther); |
| 44 return static_cast<SVGLengthMode>(mode); |
| 45 } |
| 46 |
| 47 inline SVGLengthType toSVGLengthType(unsigned short type) |
| 48 { |
| 49 ASSERT(type >= LengthTypeUnknown && type <= LengthTypePC); |
| 50 return static_cast<SVGLengthType>(type); |
| 51 } |
| 52 |
| 53 } // namespace |
| 54 |
| 55 SVGLengthType SVGLengthTearOff::unitType() |
| 56 { |
| 57 return target()->unitType(); |
| 58 } |
| 59 |
| 60 SVGLengthMode SVGLengthTearOff::unitMode() |
| 61 { |
| 62 return target()->unitMode(); |
| 63 } |
| 64 |
| 65 float SVGLengthTearOff::value(ExceptionState& es) |
| 66 { |
| 67 SVGLengthContext lengthContext(contextElement()); |
| 68 return target()->value(lengthContext, es); |
| 69 } |
| 70 |
| 71 void SVGLengthTearOff::setValue(float value, ExceptionState& es) |
| 72 { |
| 73 if (isImmutable()) { |
| 74 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 75 return; |
| 76 } |
| 77 |
| 78 SVGLengthContext lengthContext(contextElement()); |
| 79 target()->setValue(value, lengthContext, es); |
| 80 commitChange(); |
| 81 } |
| 82 |
| 83 float SVGLengthTearOff::valueInSpecifiedUnits() |
| 84 { |
| 85 return target()->valueInSpecifiedUnits(); |
| 86 } |
| 87 |
| 88 void SVGLengthTearOff::setValueInSpecifiedUnits(float value, ExceptionState& es) |
| 89 { |
| 90 if (isImmutable()) { |
| 91 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 92 return; |
| 93 } |
| 94 target()->setValueInSpecifiedUnits(value); |
| 95 commitChange(); |
| 96 } |
| 97 |
| 98 String SVGLengthTearOff::valueAsString() |
| 99 { |
| 100 return target()->valueAsString(); |
| 101 } |
| 102 |
| 103 void SVGLengthTearOff::setValueAsString(const String& str, ExceptionState& es) |
| 104 { |
| 105 if (isImmutable()) { |
| 106 es.throwDOMException(NoModificationAllowedError, "The attribute is read-
only."); |
| 107 return; |
| 108 } |
| 109 |
| 110 target()->setValueAsString(str, es); |
| 111 commitChange(); |
| 112 } |
| 113 |
| 114 void SVGLengthTearOff::newValueSpecifiedUnits(unsigned short unitType, float val
ueInSpecifiedUnits, ExceptionState& exceptionState) |
| 115 { |
| 116 if (isImmutable()) { |
| 117 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 118 return; |
| 119 } |
| 120 |
| 121 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { |
| 122 exceptionState.throwDOMException(NotSupportedError, "Cannot set value wi
th unknown or invalid units (" + String::number(unitType) + ")."); |
| 123 return; |
| 124 } |
| 125 |
| 126 target()->newValueSpecifiedUnits(toSVGLengthType(unitType), valueInSpecified
Units); |
| 127 commitChange(); |
| 128 } |
| 129 |
| 130 void SVGLengthTearOff::convertToSpecifiedUnits(unsigned short unitType, Exceptio
nState& exceptionState) |
| 131 { |
| 132 if (isImmutable()) { |
| 133 exceptionState.throwDOMException(NoModificationAllowedError, "The object
is read-only."); |
| 134 return; |
| 135 } |
| 136 |
| 137 if (unitType == LengthTypeUnknown || unitType > LengthTypePC) { |
| 138 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to u
nknown or invalid units (" + String::number(unitType) + ")."); |
| 139 return; |
| 140 } |
| 141 |
| 142 SVGLengthContext lengthContext(contextElement()); |
| 143 target()->convertToSpecifiedUnits(toSVGLengthType(unitType), lengthContext,
exceptionState); |
| 144 commitChange(); |
| 145 } |
| 146 |
| 147 SVGLengthTearOff::SVGLengthTearOff(PassRefPtr<SVGLength> target, SVGElement* con
textElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attri
buteName) |
| 148 : NewSVGPropertyTearOff<SVGLength>(target, contextElement, propertyIsAnimVal
, attributeName) |
| 149 { |
| 150 ScriptWrappable::init(this); |
| 151 } |
| 152 |
| 153 } |
OLD | NEW |