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 #include "core/svg/SVGAngleTearOff.h" 33 34 #include "bindings/v8/ExceptionState.h" 35 #include "bindings/v8/ExceptionStatePlaceholder.h" 36 #include "core/dom/ExceptionCode.h" 37 38 namespace WebCore { 39 40 SVGAngleTearOff::SVGAngleTearOff(PassRefPtr<SVGAngle> targetProperty, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName) 41 : SVGPropertyTearOff<SVGAngle>(targetProperty, contextElement, propertyIsAnimVal, attributeName) 42 { 43 ScriptWrappable::init(this); 44 } 45 46 SVGAngleTearOff::~SVGAngleTearOff() 47 { 48 } 49 50 void SVGAngleTearOff::setValue(float value, ExceptionState& exceptionState) 51 { 52 if (isImmutable()) { 53 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); 54 return; 55 } 56 57 target()->setValue(value); 58 commitChange(); 59 } 60 61 void SVGAngleTearOff::setValueInSpecifiedUnits(float value, ExceptionState& exceptionState) 62 { 63 if (isImmutable()) { 64 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); 65 return; 66 } 67 68 target()->setValueInSpecifiedUnits(value); 69 commitChange(); 70 } 71 72 void SVGAngleTearOff::newValueSpecifiedUnits(unsigned short unitType, float valueInSpecifiedUnits, ExceptionState& exceptionState) 73 { 74 if (isImmutable()) { 75 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); 76 return; 77 } 78 79 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN || unitType > SVGAngle::SVG_ANGLETYPE_GRAD) { 80 exceptionState.throwDOMException(NotSupportedError, "Cannot set value with unknown or invalid units (" + String::number(unitType) + ")."); 81 return; 82 } 83 84 target()->newValueSpecifiedUnits(static_cast<SVGAngle::SVGAngleType>(unitType), valueInSpecifiedUnits); 85 commitChange(); 86 } 87 88 void SVGAngleTearOff::convertToSpecifiedUnits(unsigned short unitType, ExceptionState& exceptionState) 89 { 90 if (isImmutable()) { 91 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); 92 return; 93 } 94 95 if (unitType == SVGAngle::SVG_ANGLETYPE_UNKNOWN || unitType > SVGAngle::SVG_ANGLETYPE_GRAD) { 96 exceptionState.throwDOMException(NotSupportedError, "Cannot convert to unknown or invalid units (" + String::number(unitType) + ")."); 97 return; 98 } 99 100 target()->convertToSpecifiedUnits(static_cast<SVGAngle::SVGAngleType>(unitType), exceptionState); 101 if (!exceptionState.hadException()) 102 commitChange(); 103 } 104 105 void SVGAngleTearOff::setValueAsString(const String& value, ExceptionState& exceptionState) 106 { 107 if (isImmutable()) { 108 exceptionState.throwDOMException(NoModificationAllowedError, "The attribute is read-only."); 109 return; 110 } 111 112 String oldValue = target()->valueAsString(); 113 114 target()->setValueAsString(value, exceptionState); 115 116 if (!exceptionState.hadException() && !hasExposedAngleUnit()) { 117 target()->setValueAsString(oldValue, ASSERT_NO_EXCEPTION); // rollback to old value 118 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + value + "') is invalid."); 119 return; 120 } 121 122 commitChange(); 123 } 124 125 } 126