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

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

Issue 26247003: Web Animations CSS: Support animation of background-position and background-image (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review changes 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
« no previous file with comments | « Source/core/animation/AnimatableRepeatable.h ('k') | Source/core/animation/AnimatableValue.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/AnimatableRepeatable.h"
33
34 namespace {
35
36 size_t greatestCommonDivisor(size_t a, size_t b)
37 {
38 return b ? greatestCommonDivisor(b, a % b) : a;
39 }
40
41 size_t lowestCommonMultiple(size_t a, size_t b)
42 {
43 if (!a && !b)
Steve Block 2013/10/10 03:34:52 This could be an OR Or switch back to the assert,
alancutter (OOO until 2018) 2013/10/10 05:32:41 Done.
44 return 0;
45 return a / greatestCommonDivisor(a, b) * b;
46 }
47
48 } // namespace
49
50 namespace WebCore {
51
52 PassRefPtr<AnimatableValue> AnimatableRepeatable::interpolateTo(const Animatable Value* value, double fraction) const
53 {
54 // Interpolation behaviour spec: http://www.w3.org/TR/css3-transitions/#anim type-repeatable-list
55 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values;
56 ASSERT(lowestCommonMultiple(m_values.size(), otherValues.size()));
Steve Block 2013/10/10 03:34:52 I think we usually use a local variable, rather th
alancutter (OOO until 2018) 2013/10/10 05:32:41 Asserts are now at the top of the function and ins
57 Vector<RefPtr<AnimatableValue> > interpolatedValues(lowestCommonMultiple(m_v alues.size(), otherValues.size()));
58 for (size_t i = 0; i < interpolatedValues.size(); ++i) {
59 const AnimatableValue* from = m_values[i % m_values.size()].get();
Steve Block 2013/10/10 03:34:52 We should also assert that neither list has length
alancutter (OOO until 2018) 2013/10/10 05:32:41 Added assert to constructor and top of function.
60 const AnimatableValue* to = otherValues[i % otherValues.size()].get();
61 // Spec: If a pair of values cannot be interpolated, then the lists are not interpolable.
62 if (!from->isSameType(to))
63 return defaultInterpolateTo(this, value, fraction);
64 interpolatedValues[i] = interpolate(from, to, fraction);
65 }
66 return create(interpolatedValues);
67 }
68
69 PassRefPtr<AnimatableValue> AnimatableRepeatable::addWith(const AnimatableValue* value) const
70 {
71 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values;
72 Vector<RefPtr<AnimatableValue> > addedValues(lowestCommonMultiple(m_values.s ize(), otherValues.size()));
73 for (size_t i = 0; i < addedValues.size(); ++i) {
74 const AnimatableValue* left = m_values[i % m_values.size()].get();
75 const AnimatableValue* right = otherValues[i % otherValues.size()].get() ;
76 if (!left->isSameType(right))
77 return defaultAddWith(this, value);
78 addedValues[i] = add(left, right);
79 }
80 return create(addedValues);
81 }
82
83 bool AnimatableRepeatable::equalTo(const AnimatableValue* value) const
84 {
85 const Vector<RefPtr<AnimatableValue> >& otherValues = toAnimatableRepeatable (value)->m_values;
86 if (m_values.size() != otherValues.size())
87 return false;
88 for (size_t i = 0; i < m_values.size(); ++i) {
89 if (!m_values[i]->equals(otherValues[i].get()))
90 return false;
91 }
92 return true;
93 }
94
95 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/AnimatableRepeatable.h ('k') | Source/core/animation/AnimatableValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698