| Index: Source/core/animation/AnimatableSVGLengthVector.cpp
|
| diff --git a/Source/core/animation/AnimatableSVGLengthVector.cpp b/Source/core/animation/AnimatableSVGLengthVector.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1ce2ad2ffa074b895aeacd2d9c3cdc045ede49e0
|
| --- /dev/null
|
| +++ b/Source/core/animation/AnimatableSVGLengthVector.cpp
|
| @@ -0,0 +1,120 @@
|
| +/*
|
| + * Copyright (C) 2013 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "core/animation/AnimatableSVGLengthVector.h"
|
| +
|
| +#include "bindings/v8/ExceptionStatePlaceholder.h"
|
| +#include "platform/FloatConversion.h"
|
| +#include <algorithm>
|
| +
|
| +namespace WebCore {
|
| +
|
| +namespace {
|
| +
|
| +int lowestCommonMultiple(int a, int b)
|
| +{
|
| + ASSERT(a > 0);
|
| + ASSERT(b > 0);
|
| + int maxCandidate = std::max(a, b);
|
| + int result = 1;
|
| + for (int i = 2; i <= maxCandidate; ++i) {
|
| + bool isFactorOfA = !(a % i);
|
| + bool isFactorOfB = !(b % i);
|
| + while (isFactorOfA || isFactorOfB) {
|
| + bool hit = false;
|
| + if (isFactorOfA) {
|
| + a /= i;
|
| + hit = true;
|
| + isFactorOfA = !(a % i);
|
| + }
|
| + if (isFactorOfB) {
|
| + b /= i;
|
| + hit = true;
|
| + isFactorOfB = !(b % i);
|
| + }
|
| + if (hit)
|
| + result *= i;
|
| + }
|
| + }
|
| + ASSERT(!(result % a) && !(result % b));
|
| + return result;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +PassRefPtr<AnimatableValue> AnimatableSVGLengthVector::interpolateTo(const AnimatableValue* value, double fraction) const
|
| +{
|
| + Vector<SVGLength> from = m_lengths;
|
| + Vector<SVGLength> to = toAnimatableSVGLengthVector(value)->toSVGLengthVector();
|
| +
|
| + // The spec states that if the sum of all values is zero, this should be
|
| + // treated like a value of 'none', which means that a solid line is drawn.
|
| + // Since we animate to and from values of zero, treat a value of 'none' the
|
| + // same.
|
| + static SVGLength* zeroPixels = 0;
|
| + if (!zeroPixels) {
|
| + zeroPixels = new SVGLength;
|
| + zeroPixels->newValueSpecifiedUnits(LengthTypePX, 0, IGNORE_EXCEPTION);
|
| + }
|
| + if (from.isEmpty()) {
|
| + from.append(*zeroPixels);
|
| + from.append(*zeroPixels);
|
| + }
|
| + if (to.isEmpty()) {
|
| + to.append(*zeroPixels);
|
| + to.append(*zeroPixels);
|
| + }
|
| +
|
| + const size_t fromLength = from.size();
|
| + const size_t toLength = to.size();
|
| +
|
| + size_t resultLength = lowestCommonMultiple(fromLength, toLength);
|
| + Vector<SVGLength> result(resultLength);
|
| + for (size_t i = 0; i < resultLength; ++i) {
|
| + result[i] = to[i % toLength].blend(from[i % fromLength], narrowPrecisionToFloat(fraction));
|
| + if (result[i].valueInSpecifiedUnits() < 0)
|
| + result[i].setValueInSpecifiedUnits(0);
|
| + }
|
| + return create(result);
|
| +}
|
| +
|
| +PassRefPtr<AnimatableValue> AnimatableSVGLengthVector::addWith(const AnimatableValue* value) const
|
| +{
|
| + RELEASE_ASSERT_WITH_MESSAGE(false, "Web Animations not yet implemented: AnimatableSVGLengthVector::addWith()");
|
| + return 0;
|
| +}
|
| +
|
| +bool AnimatableSVGLengthVector::equalTo(const AnimatableValue* value) const
|
| +{
|
| + return m_lengths == toAnimatableSVGLengthVector(value)->toSVGLengthVector();
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|