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(PassRefPtrWillBeRawPtr
<SVGInteger
> firstInteger
, PassRefPtrWillBeRawPtr
<SVGInteger
> secondInteger
)
40 : SVGPropertyBase(classType())
41 , m_firstInteger(firstInteger
)
42 , m_secondInteger(secondInteger
)
46 DEFINE_TRACE(SVGIntegerOptionalInteger
)
48 visitor
->trace(m_firstInteger
);
49 visitor
->trace(m_secondInteger
);
50 SVGPropertyBase::trace(visitor
);
53 PassRefPtrWillBeRawPtr
<SVGIntegerOptionalInteger
> SVGIntegerOptionalInteger::clone() const
55 return SVGIntegerOptionalInteger::create(m_firstInteger
->clone(), m_secondInteger
->clone());
58 PassRefPtrWillBeRawPtr
<SVGPropertyBase
> SVGIntegerOptionalInteger::cloneForAnimation(const String
& value
) const
61 if (!parseNumberOptionalNumber(value
, floatX
, floatY
)) {
62 return SVGIntegerOptionalInteger::create(SVGInteger::create(0), SVGInteger::create(0));
65 int x
= static_cast<int>(roundf(floatX
));
66 int y
= static_cast<int>(roundf(floatY
));
68 return SVGIntegerOptionalInteger::create(SVGInteger::create(x
), SVGInteger::create(y
));
71 String
SVGIntegerOptionalInteger::valueAsString() const
73 if (m_firstInteger
->value() == m_secondInteger
->value()) {
74 return String::number(m_firstInteger
->value());
77 return String::number(m_firstInteger
->value()) + " " + String::number(m_secondInteger
->value());
80 void SVGIntegerOptionalInteger::setValueAsString(const String
& value
, ExceptionState
& exceptionState
)
83 if (!parseNumberOptionalNumber(value
, x
, y
)) {
84 exceptionState
.throwDOMException(SyntaxError
, "The value provided ('" + value
+ "') is invalid.");
88 m_firstInteger
->setValue(x
);
89 m_secondInteger
->setValue(y
);
92 void SVGIntegerOptionalInteger::add(PassRefPtrWillBeRawPtr
<SVGPropertyBase
> other
, SVGElement
*)
94 RefPtrWillBeRawPtr
<SVGIntegerOptionalInteger
> otherIntegerOptionalInteger
= toSVGIntegerOptionalInteger(other
);
96 m_firstInteger
->setValue(m_firstInteger
->value() + otherIntegerOptionalInteger
->m_firstInteger
->value());
97 m_secondInteger
->setValue(m_secondInteger
->value() + otherIntegerOptionalInteger
->m_secondInteger
->value());
100 void SVGIntegerOptionalInteger::calculateAnimatedValue(SVGAnimationElement
* animationElement
, float percentage
, unsigned repeatCount
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> from
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> to
, PassRefPtrWillBeRawPtr
<SVGPropertyBase
> toAtEndOfDuration
, SVGElement
*)
102 ASSERT(animationElement
);
104 RefPtrWillBeRawPtr
<SVGIntegerOptionalInteger
> fromInteger
= toSVGIntegerOptionalInteger(from
);
105 RefPtrWillBeRawPtr
<SVGIntegerOptionalInteger
> toInteger
= toSVGIntegerOptionalInteger(to
);
106 RefPtrWillBeRawPtr
<SVGIntegerOptionalInteger
> toAtEndOfDurationInteger
= toSVGIntegerOptionalInteger(toAtEndOfDuration
);
108 float x
= m_firstInteger
->value();
109 float y
= m_secondInteger
->value();
110 animationElement
->animateAdditiveNumber(percentage
, repeatCount
, fromInteger
->firstInteger()->value(), toInteger
->firstInteger()->value(), toAtEndOfDurationInteger
->firstInteger()->value(), x
);
111 animationElement
->animateAdditiveNumber(percentage
, repeatCount
, fromInteger
->secondInteger()->value(), toInteger
->secondInteger()->value(), toAtEndOfDurationInteger
->secondInteger()->value(), y
);
112 m_firstInteger
->setValue(static_cast<int>(roundf(x
)));
113 m_secondInteger
->setValue(static_cast<int>(roundf(y
)));
116 float SVGIntegerOptionalInteger::calculateDistance(PassRefPtrWillBeRawPtr
<SVGPropertyBase
> other
, SVGElement
*)
118 // FIXME: Distance calculation is not possible for SVGIntegerOptionalInteger right now. We need the distance for every single value.