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

Side by Side Diff: sky/engine/core/animation/LengthStyleInterpolation.cpp

Issue 1229273004: Remove Animations and Transitions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sky/engine/core/animation/LengthStyleInterpolation.h"
6
7 #include "sky/engine/core/css/CSSCalculationValue.h"
8 #include "sky/engine/core/css/resolver/StyleBuilder.h"
9
10 namespace blink {
11
12 bool LengthStyleInterpolation::canCreateFrom(const CSSValue& value)
13 {
14 if (value.isPrimitiveValue()) {
15 const CSSPrimitiveValue& primitiveValue = blink::toCSSPrimitiveValue(val ue);
16 if (primitiveValue.cssCalcValue())
17 return true;
18
19 CSSPrimitiveValue::LengthUnitType type;
20 // Only returns true if the type is a primitive length unit.
21 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit iveType(), type);
22 }
23 return value.isCalcValue();
24 }
25
26 PassOwnPtr<InterpolableValue> LengthStyleInterpolation::lengthToInterpolableValu e(CSSValue* value)
27 {
28 OwnPtr<InterpolableList> result = InterpolableList::create(CSSPrimitiveValue ::LengthUnitTypeCount);
29 CSSPrimitiveValue* primitive = toCSSPrimitiveValue(value);
30
31 CSSLengthArray array;
32 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++)
33 array.append(0);
34 primitive->accumulateLengthArray(array);
35
36 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++)
37 result->set(i, InterpolableNumber::create(array.at(i)));
38
39 return result.release();
40 }
41
42 namespace {
43
44 static CSSPrimitiveValue::UnitType toUnitType(int lengthUnitType)
45 {
46 return static_cast<CSSPrimitiveValue::UnitType>(CSSPrimitiveValue::lengthUni tTypeToUnitType(static_cast<CSSPrimitiveValue::LengthUnitType>(lengthUnitType))) ;
47 }
48
49 static PassRefPtr<CSSCalcExpressionNode> constructCalcExpression(PassRefPtr<CSSC alcExpressionNode> previous, InterpolableList* list, size_t position)
50 {
51 while (position != CSSPrimitiveValue::LengthUnitTypeCount) {
52 const InterpolableNumber *subValue = toInterpolableNumber(list->get(posi tion));
53 if (subValue->value()) {
54 RefPtr<CSSCalcExpressionNode> next;
55 if (previous)
56 next = CSSCalcValue::createExpressionNode(previous, CSSCalcValue ::createExpressionNode(CSSPrimitiveValue::create(subValue->value(), toUnitType(p osition))), CalcAdd);
57 else
58 next = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::cre ate(subValue->value(), toUnitType(position)));
59 return constructCalcExpression(next, list, position + 1);
60 }
61 position++;
62 }
63 return previous;
64 }
65
66 }
67
68 PassRefPtr<CSSValue> LengthStyleInterpolation::interpolableValueToLength(Interpo lableValue* value, ValueRange range)
69 {
70 InterpolableList* listValue = toInterpolableList(value);
71 unsigned unitCount = 0;
72 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) {
73 const InterpolableNumber* subValue = toInterpolableNumber(listValue->get (i));
74 if (subValue->value()) {
75 unitCount++;
76 }
77 }
78
79 switch (unitCount) {
80 case 0:
81 return CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX);
82 case 1:
83 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) {
84 const InterpolableNumber* subValue = toInterpolableNumber(listValue- >get(i));
85 double value = subValue->value();
86 if (value) {
87 if (range == ValueRangeNonNegative && value < 0)
88 value = 0;
89 return CSSPrimitiveValue::create(value, toUnitType(i));
90 }
91 }
92 ASSERT_NOT_REACHED();
93 default:
94 return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpre ssion(nullptr, listValue, 0), range));
95 }
96 }
97
98 void LengthStyleInterpolation::apply(StyleResolverState& state) const
99 {
100 StyleBuilder::applyProperty(m_id, state, interpolableValueToLength(m_cachedV alue.get(), m_range).get());
101 }
102
103 }
OLDNEW
« no previous file with comments | « sky/engine/core/animation/LengthStyleInterpolation.h ('k') | sky/engine/core/animation/LengthStyleInterpolationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698