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/SVGNumberOptionalNumber.h"
34 #include "core/svg/SVGAnimationElement.h"
35 #include "core/svg/SVGParserUtilities.h"
39 SVGNumberOptionalNumber::SVGNumberOptionalNumber(PassRefPtr<SVGNumber> firstNumber, PassRefPtr<SVGNumber> secondNumber)
40 : SVGPropertyBase(classType())
41 , m_firstNumber(firstNumber)
42 , m_secondNumber(secondNumber)
46 PassRefPtr<SVGNumberOptionalNumber> SVGNumberOptionalNumber::clone() const
48 return SVGNumberOptionalNumber::create(m_firstNumber->clone(), m_secondNumber->clone());
51 PassRefPtr<SVGPropertyBase> SVGNumberOptionalNumber::cloneForAnimation(const String& value) const
54 if (!parseNumberOptionalNumber(value, x, y)) {
58 return SVGNumberOptionalNumber::create(SVGNumber::create(x), SVGNumber::create(y));
61 String SVGNumberOptionalNumber::valueAsString() const
63 if (m_firstNumber->value() == m_secondNumber->value()) {
64 return String::number(m_firstNumber->value());
67 return String::number(m_firstNumber->value()) + " " + String::number(m_secondNumber->value());
70 void SVGNumberOptionalNumber::setValueAsString(const String& value, ExceptionState& exceptionState)
73 if (!parseNumberOptionalNumber(value, x, y)) {
74 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + value + "') is invalid.");
78 m_firstNumber->setValue(x);
79 m_secondNumber->setValue(y);
82 void SVGNumberOptionalNumber::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*)
84 RefPtr<SVGNumberOptionalNumber> otherNumberOptionalNumber = toSVGNumberOptionalNumber(other);
86 m_firstNumber->setValue(m_firstNumber->value() + otherNumberOptionalNumber->m_firstNumber->value());
87 m_secondNumber->setValue(m_secondNumber->value() + otherNumberOptionalNumber->m_secondNumber->value());
90 void SVGNumberOptionalNumber::calculateAnimatedValue(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDuration, SVGElement*)
92 ASSERT(animationElement);
94 RefPtr<SVGNumberOptionalNumber> fromNumber = toSVGNumberOptionalNumber(from);
95 RefPtr<SVGNumberOptionalNumber> toNumber = toSVGNumberOptionalNumber(to);
96 RefPtr<SVGNumberOptionalNumber> toAtEndOfDurationNumber = toSVGNumberOptionalNumber(toAtEndOfDuration);
98 float x = m_firstNumber->value();
99 float y = m_secondNumber->value();
100 animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber->firstNumber()->value(), toNumber->firstNumber()->value(), toAtEndOfDurationNumber->firstNumber()->value(), x);
101 animationElement->animateAdditiveNumber(percentage, repeatCount, fromNumber->secondNumber()->value(), toNumber->secondNumber()->value(), toAtEndOfDurationNumber->secondNumber()->value(), y);
102 m_firstNumber->setValue(x);
103 m_secondNumber->setValue(y);
106 float SVGNumberOptionalNumber::calculateDistance(PassRefPtr<SVGPropertyBase> other, SVGElement*)
108 // FIXME: Distance calculation is not possible for SVGNumberOptionalNumber right now. We need the distance for every single value.