Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Side by Side Diff: Source/core/animation/AnimatableSVGLengthVector.cpp

Issue 26292004: Web Animations CSS: Support animation of stroke-dasharray property (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31 #include "config.h"
32 #include "core/animation/AnimatableSVGLengthVector.h"
33
34 #include "bindings/v8/ExceptionStatePlaceholder.h"
35 #include "platform/FloatConversion.h"
36 #include <algorithm>
37
38 namespace WebCore {
39
40 namespace {
41
42 int lowestCommonMultiple(int a, int b)
43 {
44 ASSERT(a > 0);
45 ASSERT(b > 0);
46 int maxCandidate = std::max(a, b);
47 int result = 1;
48 for (int i = 2; i <= maxCandidate; ++i) {
49 bool isFactorOfA = !(a % i);
50 bool isFactorOfB = !(b % i);
51 while (isFactorOfA || isFactorOfB) {
52 bool hit = false;
53 if (isFactorOfA) {
54 a /= i;
55 hit = true;
56 isFactorOfA = !(a % i);
57 }
58 if (isFactorOfB) {
59 b /= i;
60 hit = true;
61 isFactorOfB = !(b % i);
62 }
63 if (hit)
64 result *= i;
65 }
66 }
67 ASSERT(!(result % a) && !(result % b));
68 return result;
69 }
70
71 } // namespace
72
73 PassRefPtr<AnimatableValue> AnimatableSVGLengthVector::interpolateTo(const Anima tableValue* value, double fraction) const
74 {
75 Vector<SVGLength> from = m_lengths;
76 Vector<SVGLength> to = toAnimatableSVGLengthVector(value)->toSVGLengthVector ();
77
78 // The spec states that if the sum of all values is zero, this should be
79 // treated like a value of 'none', which means that a solid line is drawn.
80 // Since we animate to and from values of zero, treat a value of 'none' the
81 // same.
82 static SVGLength* zeroPixels = 0;
83 if (!zeroPixels) {
84 zeroPixels = new SVGLength;
85 zeroPixels->newValueSpecifiedUnits(LengthTypePX, 0, IGNORE_EXCEPTION);
86 }
87 if (from.isEmpty()) {
88 from.append(*zeroPixels);
89 from.append(*zeroPixels);
90 }
91 if (to.isEmpty()) {
92 to.append(*zeroPixels);
93 to.append(*zeroPixels);
94 }
95
96 const size_t fromLength = from.size();
97 const size_t toLength = to.size();
98
99 size_t resultLength = lowestCommonMultiple(fromLength, toLength);
100 Vector<SVGLength> result(resultLength);
101 for (size_t i = 0; i < resultLength; ++i) {
102 result[i] = to[i % toLength].blend(from[i % fromLength], narrowPrecision ToFloat(fraction));
103 if (result[i].valueInSpecifiedUnits() < 0)
104 result[i].setValueInSpecifiedUnits(0);
105 }
106 return create(result);
107 }
108
109 PassRefPtr<AnimatableValue> AnimatableSVGLengthVector::addWith(const AnimatableV alue* value) const
110 {
111 RELEASE_ASSERT_WITH_MESSAGE(false, "Web Animations not yet implemented: Anim atableSVGLengthVector::addWith()");
112 return 0;
113 }
114
115 bool AnimatableSVGLengthVector::equalTo(const AnimatableValue* value) const
116 {
117 return m_lengths == toAnimatableSVGLengthVector(value)->toSVGLengthVector();
118 }
119
120 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/AnimatableSVGLengthVector.h ('k') | Source/core/animation/AnimatableValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698