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

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: transitions test with interpolated perspective 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 default:
44 return false;
45 }
46 }
47
48 } // namespace
49
50 bool LengthStyleInterpolation::canCreateFrom(const CSSValue& value, CSSPropertyI D property)
14 { 51 {
15 if (value.isPrimitiveValue()) { 52 if (value.isPrimitiveValue()) {
16 const CSSPrimitiveValue& primitiveValue = blink::toCSSPrimitiveValue(val ue); 53 const CSSPrimitiveValue& primitiveValue = blink::toCSSPrimitiveValue(val ue);
17 if (primitiveValue.cssCalcValue()) 54 if (primitiveValue.cssCalcValue())
18 return true; 55 return true;
19 56
57 if (primitiveValue.isValueID()) {
58 CSSValueID valueID = primitiveValue.getValueID();
59 double pixels;
60 return pixelsForKeyword(property, valueID, pixels);
61 }
62
20 CSSPrimitiveValue::LengthUnitType type; 63 CSSPrimitiveValue::LengthUnitType type;
21 // Only returns true if the type is a primitive length unit. 64 // Only returns true if the type is a primitive length unit.
22 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit iveType(), type); 65 return CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue.primit iveType(), type);
23 } 66 }
24 return value.isCalcValue(); 67 return value.isCalcValue();
25 } 68 }
26 69
27 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::toInterpolab leValue(const CSSValue& value) 70 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::toInterpolab leValue(const CSSValue& value, CSSPropertyID id)
28 { 71 {
29 ASSERT(canCreateFrom(value)); 72 ASSERT(canCreateFrom(value, id));
30 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList ::create(2); 73 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList ::create(2);
31 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create (CSSPrimitiveValue::LengthUnitTypeCount); 74 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create (CSSPrimitiveValue::LengthUnitTypeCount);
32 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create( CSSPrimitiveValue::LengthUnitTypeCount); 75 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create( CSSPrimitiveValue::LengthUnitTypeCount);
33 76
34 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); 77 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value);
35 78
36 CSSLengthArray arrayOfValues; 79 CSSLengthArray arrayOfValues;
37 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes; 80 CSSPrimitiveValue::CSSLengthTypeArray arrayOfTypes;
38 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) 81 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++)
39 arrayOfValues.append(0); 82 arrayOfValues.append(0);
40 83
41 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); 84 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount);
42 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes); 85 if (primitive.isValueID()) {
86 CSSValueID valueID = primitive.getValueID();
87 double pixels;
88 pixelsForKeyword(id, valueID, pixels);
89 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels);
90 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels;
91 } else {
92 primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes);
93 }
43 94
44 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { 95 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) {
45 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); 96 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i)));
46 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); 97 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i)));
47 } 98 }
48 99
49 listOfValuesAndTypes->set(0, listOfValues.release()); 100 listOfValuesAndTypes->set(0, listOfValues.release());
50 listOfValuesAndTypes->set(1, listOfTypes.release()); 101 listOfValuesAndTypes->set(1, listOfTypes.release());
51 102
52 return listOfValuesAndTypes.release(); 103 return listOfValuesAndTypes.release();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 { 170 {
120 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cachedValu e.get(), m_range).get()); 171 StyleBuilder::applyProperty(m_id, state, fromInterpolableValue(*m_cachedValu e.get(), m_range).get());
121 } 172 }
122 173
123 DEFINE_TRACE(LengthStyleInterpolation) 174 DEFINE_TRACE(LengthStyleInterpolation)
124 { 175 {
125 StyleInterpolation::trace(visitor); 176 StyleInterpolation::trace(visitor);
126 } 177 }
127 178
128 } 179 }
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