2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "core/svg/SVGNumber.h"
34 #include "core/svg/SVGAnimationElement.h"
35 #include "core/svg/SVGParserUtilities.h"
39 SVGNumber::SVGNumber(float value
)
44 PassRefPtrWillBeRawPtr
<SVGNumber
> SVGNumber::clone() const
46 return create(m_value
);
49 String
SVGNumber::valueAsString() const
51 return String::number(m_value
);
54 template<typename CharType
>
55 bool SVGNumber::parse(const CharType
*& ptr
, const CharType
* end
)
57 if (!parseNumber(ptr
, end
, m_value
, AllowLeadingAndTrailingWhitespace
)) {
70 void SVGNumber::setValueAsString(const String
& string
, ExceptionState
& exceptionState
)
72 if (string
.isEmpty()) {
78 if (string
.is8Bit()) {
79 const LChar
* ptr
= string
.characters8();
80 const LChar
* end
= ptr
+ string
.length();
81 valid
= parse(ptr
, end
);
83 const UChar
* ptr
= string
.characters16();
84 const UChar
* end
= ptr
+ string
.length();
85 valid
= parse(ptr
, end
);
89 exceptionState
.throwDOMException(SyntaxError
, "The value provided ('" + string
+ "') is invalid.");
94 void SVGNumber::add(PassRefPtrWillBeRawPtr
<SVGPropertyBase
> other
, SVGElement
*)
96 setValue(m_value
+ toSVGNumber(other
)->value());
99 void SVGNumber::calculateAnimatedValue(SVGAnimationElement
* animationElement
, float percentage
, unsigned repeatCount
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> from
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> to
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> toAtEndOfDuration
, SVGElement
*)
101 ASSERT(animationElement
);
103 RefPtrWillBeRawPtr
<SVGNumber
> fromNumber
= toSVGNumber(from
);
104 RefPtrWillBeRawPtr
<SVGNumber
> toNumber
= toSVGNumber(to
);
105 RefPtrWillBeRawPtr
<SVGNumber
> toAtEndOfDurationNumber
= toSVGNumber(toAtEndOfDuration
);
107 animationElement
->animateAdditiveNumber(percentage
, repeatCount
, fromNumber
->value(), toNumber
->value(), toAtEndOfDurationNumber
->value(), m_value
);
110 float SVGNumber::calculateDistance(PassRefPtrWillBeRawPtr
<SVGPropertyBase
> other
, SVGElement
*)
112 return fabsf(m_value
- toSVGNumber(other
)->value());
115 PassRefPtrWillBeRawPtr
<SVGNumber
> SVGNumberAcceptPercentage::clone() const
117 return create(m_value
);
120 void SVGNumberAcceptPercentage::setValueAsString(const String
& string
, ExceptionState
& exceptionState
)
122 bool valid
= parseNumberOrPercentage(string
, m_value
);
125 exceptionState
.throwDOMException(SyntaxError
, "The value provided ('" + string
+ "') is invalid.");
130 SVGNumberAcceptPercentage::SVGNumberAcceptPercentage(float value
)