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/SVGIntegerOptionalInteger.h"
34 #include "core/svg/SVGAnimationElement.h"
35 #include "core/svg/SVGParserUtilities.h"
39 SVGIntegerOptionalInteger::SVGIntegerOptionalInteger(PassRefPtr<SVGInteger> firstInteger, PassRefPtr<SVGInteger> secondInteger)
40 : SVGPropertyBase(classType())
41 , m_firstInteger(firstInteger)
42 , m_secondInteger(secondInteger)
46 PassRefPtr<SVGIntegerOptionalInteger> SVGIntegerOptionalInteger::clone() const
48 return SVGIntegerOptionalInteger::create(m_firstInteger->clone(), m_secondInteger->clone());
51 PassRefPtr<SVGPropertyBase> SVGIntegerOptionalInteger::cloneForAnimation(const String& value) const
54 if (!parseNumberOptionalNumber(value, floatX, floatY)) {
55 return SVGIntegerOptionalInteger::create(SVGInteger::create(0), SVGInteger::create(0));
58 int x = static_cast<int>(roundf(floatX));
59 int y = static_cast<int>(roundf(floatY));
61 return SVGIntegerOptionalInteger::create(SVGInteger::create(x), SVGInteger::create(y));
64 String SVGIntegerOptionalInteger::valueAsString() const
66 if (m_firstInteger->value() == m_secondInteger->value()) {
67 return String::number(m_firstInteger->value());
70 return String::number(m_firstInteger->value()) + " " + String::number(m_secondInteger->value());
73 void SVGIntegerOptionalInteger::setValueAsString(const String& value, ExceptionState& exceptionState)
76 if (!parseNumberOptionalNumber(value, x, y)) {
77 exceptionState.throwDOMException(SyntaxError, "The value provided ('" + value + "') is invalid.");
81 m_firstInteger->setValue(x);
82 m_secondInteger->setValue(y);
85 void SVGIntegerOptionalInteger::add(PassRefPtrWillBeRawPtr<SVGPropertyBase> other, SVGElement*)
87 RefPtr<SVGIntegerOptionalInteger> otherIntegerOptionalInteger = toSVGIntegerOptionalInteger(other);
89 m_firstInteger->setValue(m_firstInteger->value() + otherIntegerOptionalInteger->m_firstInteger->value());
90 m_secondInteger->setValue(m_secondInteger->value() + otherIntegerOptionalInteger->m_secondInteger->value());
93 void SVGIntegerOptionalInteger::calculateAnimatedValue(SVGAnimationElement* animationElement, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> from, PassRefPtr<SVGPropertyBase> to, PassRefPtr<SVGPropertyBase> toAtEndOfDuration, SVGElement*)
95 ASSERT(animationElement);
97 RefPtr<SVGIntegerOptionalInteger> fromInteger = toSVGIntegerOptionalInteger(from);
98 RefPtr<SVGIntegerOptionalInteger> toInteger = toSVGIntegerOptionalInteger(to);
99 RefPtr<SVGIntegerOptionalInteger> toAtEndOfDurationInteger = toSVGIntegerOptionalInteger(toAtEndOfDuration);
101 float x = m_firstInteger->value();
102 float y = m_secondInteger->value();
103 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger->firstInteger()->value(), toInteger->firstInteger()->value(), toAtEndOfDurationInteger->firstInteger()->value(), x);
104 animationElement->animateAdditiveNumber(percentage, repeatCount, fromInteger->secondInteger()->value(), toInteger->secondInteger()->value(), toAtEndOfDurationInteger->secondInteger()->value(), y);
105 m_firstInteger->setValue(static_cast<int>(roundf(x)));
106 m_secondInteger->setValue(static_cast<int>(roundf(y)));
109 float SVGIntegerOptionalInteger::calculateDistance(PassRefPtr<SVGPropertyBase> other, SVGElement*)
111 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger right now. We need the distance for every single value.