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