| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/svg/SVGInteger.h" | 32 #include "core/svg/SVGInteger.h" |
| 33 | 33 |
| 34 #include "core/svg/SVGAnimationElement.h" | 34 #include "core/svg/SVGAnimationElement.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 SVGInteger::SVGInteger(int value) | 38 SVGInteger::SVGInteger(int value) |
| 39 : NewSVGPropertyBase(classType()) | 39 : SVGPropertyBase(classType()) |
| 40 , m_value(value) | 40 , m_value(value) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 PassRefPtr<SVGInteger> SVGInteger::clone() const | 44 PassRefPtr<SVGInteger> SVGInteger::clone() const |
| 45 { | 45 { |
| 46 return create(m_value); | 46 return create(m_value); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PassRefPtr<NewSVGPropertyBase> SVGInteger::cloneForAnimation(const String& value
) const | 49 PassRefPtr<SVGPropertyBase> SVGInteger::cloneForAnimation(const String& value) c
onst |
| 50 { | 50 { |
| 51 RefPtr<SVGInteger> svgInteger = create(); | 51 RefPtr<SVGInteger> svgInteger = create(); |
| 52 svgInteger->setValueAsString(value, IGNORE_EXCEPTION); | 52 svgInteger->setValueAsString(value, IGNORE_EXCEPTION); |
| 53 return svgInteger.release(); | 53 return svgInteger.release(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 String SVGInteger::valueAsString() const | 56 String SVGInteger::valueAsString() const |
| 57 { | 57 { |
| 58 return String::number(m_value); | 58 return String::number(m_value); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SVGInteger::setValueAsString(const String& string, ExceptionState& exceptio
nState) | 61 void SVGInteger::setValueAsString(const String& string, ExceptionState& exceptio
nState) |
| 62 { | 62 { |
| 63 if (string.isEmpty()) { | 63 if (string.isEmpty()) { |
| 64 m_value = 0; | 64 m_value = 0; |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool valid = true; | 68 bool valid = true; |
| 69 m_value = string.toIntStrict(&valid); | 69 m_value = string.toIntStrict(&valid); |
| 70 | 70 |
| 71 if (!valid) { | 71 if (!valid) { |
| 72 exceptionState.throwDOMException(SyntaxError, "The value provided ('" +
string + "') is invalid."); | 72 exceptionState.throwDOMException(SyntaxError, "The value provided ('" +
string + "') is invalid."); |
| 73 m_value = 0; | 73 m_value = 0; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void SVGInteger::add(PassRefPtr<NewSVGPropertyBase> other, SVGElement*) | 77 void SVGInteger::add(PassRefPtr<SVGPropertyBase> other, SVGElement*) |
| 78 { | 78 { |
| 79 setValue(m_value + toSVGInteger(other)->value()); | 79 setValue(m_value + toSVGInteger(other)->value()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SVGInteger::calculateAnimatedValue(SVGAnimationElement* animationElement, f
loat percentage, unsigned repeatCount, PassRefPtr<NewSVGPropertyBase> from, Pass
RefPtr<NewSVGPropertyBase> to, PassRefPtr<NewSVGPropertyBase> toAtEndOfDuration,
SVGElement*) | 82 void SVGInteger::calculateAnimatedValue(SVGAnimationElement* animationElement, f
loat percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRef
Ptr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDuration, SVGEleme
nt*) |
| 83 { | 83 { |
| 84 ASSERT(animationElement); | 84 ASSERT(animationElement); |
| 85 | 85 |
| 86 RefPtr<SVGInteger> fromInteger = toSVGInteger(from); | 86 RefPtr<SVGInteger> fromInteger = toSVGInteger(from); |
| 87 RefPtr<SVGInteger> toInteger = toSVGInteger(to); | 87 RefPtr<SVGInteger> toInteger = toSVGInteger(to); |
| 88 RefPtr<SVGInteger> toAtEndOfDurationInteger = toSVGInteger(toAtEndOfDuration
); | 88 RefPtr<SVGInteger> toAtEndOfDurationInteger = toSVGInteger(toAtEndOfDuration
); |
| 89 | 89 |
| 90 float animatedFloat = m_value; | 90 float animatedFloat = m_value; |
| 91 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger
->value(), toInteger->value(), toAtEndOfDurationInteger->value(), animatedFloat)
; | 91 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger
->value(), toInteger->value(), toAtEndOfDurationInteger->value(), animatedFloat)
; |
| 92 m_value = static_cast<int>(roundf(animatedFloat)); | 92 m_value = static_cast<int>(roundf(animatedFloat)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 float SVGInteger::calculateDistance(PassRefPtr<NewSVGPropertyBase> other, SVGEle
ment*) | 95 float SVGInteger::calculateDistance(PassRefPtr<SVGPropertyBase> other, SVGElemen
t*) |
| 96 { | 96 { |
| 97 return abs(m_value - toSVGInteger(other)->value()); | 97 return abs(m_value - toSVGInteger(other)->value()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } | 100 } |
| OLD | NEW |