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

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

Issue 955863002: Support keywords in LengthStyleInterpolation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: pixels for keyword Created 5 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/animation/LengthStyleInterpolation.h" 6 #include "core/animation/LengthStyleInterpolation.h"
7 7
8 #include "core/css/CSSCalculationValue.h" 8 #include "core/css/CSSCalculationValue.h"
9 #include "core/css/resolver/StyleBuilder.h" 9 #include "core/css/resolver/StyleBuilder.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 bool LengthStyleInterpolation::canCreateFrom(const CSSValue& value) 13 namespace {
14
15 bool pixelsForKeyword(CSSPropertyID property, CSSValueID valueID, double& result )
16 {
17 switch (property) {
18 case CSSPropertyBorderBottomWidth:
19 case CSSPropertyBorderLeftWidth:
20 case CSSPropertyBorderRightWidth:
21 case CSSPropertyBorderTopWidth:
22 case CSSPropertyWebkitColumnRuleWidth:
23 case CSSPropertyOutlineWidth:
24 if (valueID == CSSValueThin) {
25 result = 1;
26 return true;
27 }
28 if (valueID == CSSValueMedium) {
29 result = 3;
30 return true;
31 }
32 if (valueID == CSSValueThick) {
33 result = 5;
34 return true;
35 }
36 return false;
37 case CSSPropertyLetterSpacing:
38 if (valueID == CSSValueNormal) {
39 result = 0;
40 return true;
41 }
42 return false;
43 case CSSPropertyPerspective:
44 if (valueID == CSSValueNone) {
45 result = 0;
alancutter (OOO until 2018) 2015/03/09 00:34:15 Actually we shouldn't be animating perspective: no
Eric Willigers 2015/03/09 02:04:55 Done.
46 return true;
47 }
48 return false;
49 default:
50 return false;
51 }
52 }
53
54 } // namespace
55
56 bool LengthStyleInterpolation::canCreateFrom(const CSSValue& value, CSSPropertyI D property)
14 { 57 {
15 if (value.isPrimitiveValue()) { 58 if (value.isPrimitiveValue()) {
16 const CSSPrimitiveValue& primitiveValue = blink::toCSSPrimitiveValue(val ue); 59 const CSSPrimitiveValue& primitiveValue = blink::toCSSPrimitiveValue(val ue);
17 if (primitiveValue.cssCalcValue()) 60 if (primitiveValue.cssCalcValue())
18 return true; 61 return true;
19 62
63 if (primitiveValue.isValueID()) {
64 CSSValueID valueID = primitiveValue.getValueID();
65 double pixels;
66 return pixelsForKeyword(property, valueID, pixels);
67 }
68
20 CSSPrimitiveValue::LengthUnitType type; 69 CSSPrimitiveValue::LengthUnitType type;
21 // Only returns true if the type is a primitive length unit. 70 // Only returns true if the type is a primitive length unit.
22 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit iveType(), type); 71 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit iveType(), type);
23 } 72 }
24 return value.isCalcValue(); 73 return value.isCalcValue();
25 } 74 }
26 75
27 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::toInterpolab leValue(const CSSValue& value) 76 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::toInterpolab leValue(const CSSValue& value, CSSPropertyID id)
28 { 77 {
29 ASSERT(canCreateFrom(value)); 78 ASSERT(canCreateFrom(value, id));
30 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList ::create(2); 79 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList ::create(2);
31 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create (CSSPrimitiveValue::LengthUnitTypeCount); 80 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create (CSSPrimitiveValue::LengthUnitTypeCount);
32 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create( CSSPrimitiveValue::LengthUnitTypeCount); 81 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create( CSSPrimitiveValue::LengthUnitTypeCount);
33 82
34 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); 83 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value);
35 84
36 CSSLengthArray arrayOfValues; 85 CSSLengthArray arrayOfValues;
37 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes; 86 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes;
38 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) 87 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++)
39 arrayOfValues.append(0); 88 arrayOfValues.append(0);
40 89
41 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); 90 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount);
42 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes); 91 if (primitive.isValueID()) {
92 CSSValueID valueID = primitive.getValueID();
93 double pixels;
94 pixelsForKeyword(id, valueID, pixels);
95 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels);
96 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels;
97 } else {
98 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes);
99 }
43 100
44 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { 101 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) {
45 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); 102 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i)));
46 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); 103 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i)));
47 } 104 }
48 105
49 listOfValuesAndTypes->set(0, listOfValues.release()); 106 listOfValuesAndTypes->set(0, listOfValues.release());
50 listOfValuesAndTypes->set(1, listOfTypes.release()); 107 listOfValuesAndTypes->set(1, listOfTypes.release());
51 108
52 return listOfValuesAndTypes.release(); 109 return listOfValuesAndTypes.release();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 { 176 {
120 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cachedValu e.get(), m_range).get()); 177 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cachedValu e.get(), m_range).get());
121 } 178 }
122 179
123 DEFINE_TRACE(LengthStyleInterpolation) 180 DEFINE_TRACE(LengthStyleInterpolation)
124 { 181 {
125 StyleInterpolation::trace(visitor); 182 StyleInterpolation::trace(visitor);
126 } 183 }
127 184
128 } 185 }
OLDNEW
« no previous file with comments | « Source/core/animation/LengthStyleInterpolation.h ('k') | Source/core/animation/StringKeyframe.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698