| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/LengthInterpolationType.h" | 6 #include "core/animation/LengthInterpolationType.h" |
| 7 | 7 |
| 8 #include "core/animation/LengthPropertyFunctions.h" | 8 #include "core/animation/LengthPropertyFunctions.h" |
| 9 #include "core/animation/LengthStyleInterpolation.h" | 9 #include "core/animation/LengthStyleInterpolation.h" |
| 10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 LengthInterpolationType::LengthInterpolationType(CSSPropertyID property) | 14 LengthInterpolationType::LengthInterpolationType(CSSPropertyID property) |
| 15 : InterpolationType(property) | 15 : InterpolationType(property) |
| 16 , m_valueRange(LengthPropertyFunctions::valueRange(property)) | 16 , m_valueRange(LengthPropertyFunctions::valueRange(property)) |
| 17 { } | 17 { } |
| 18 | 18 |
| 19 static PassOwnPtrWillBeRawPtr<InterpolableList> createNeutralValue() | 19 static InterpolableList* createNeutralValue() |
| 20 { | 20 { |
| 21 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList
::create(2); | 21 InterpolableList* listOfValuesAndTypes = InterpolableList::create(2); |
| 22 const size_t length = CSSPrimitiveValue::LengthUnitTypeCount; | 22 const size_t length = CSSPrimitiveValue::LengthUnitTypeCount; |
| 23 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create
(length); | 23 InterpolableList* listOfValues = InterpolableList::create(length); |
| 24 // TODO(alancutter): Use a NonInterpolableValue to represent the list of typ
es. | 24 // TODO(alancutter): Use a NonInterpolableValue to represent the list of typ
es. |
| 25 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create(
length); | 25 InterpolableList* listOfTypes = InterpolableList::create(length); |
| 26 for (size_t i = 0; i < length; i++) { | 26 for (size_t i = 0; i < length; i++) { |
| 27 listOfValues->set(i, InterpolableNumber::create(0)); | 27 listOfValues->set(i, InterpolableNumber::create(0)); |
| 28 listOfTypes->set(i, InterpolableNumber::create(0)); | 28 listOfTypes->set(i, InterpolableNumber::create(0)); |
| 29 } | 29 } |
| 30 listOfValuesAndTypes->set(0, listOfValues.release()); | 30 listOfValuesAndTypes->set(0, listOfValues); |
| 31 listOfValuesAndTypes->set(1, listOfTypes.release()); | 31 listOfValuesAndTypes->set(1, listOfTypes); |
| 32 return listOfValuesAndTypes.release(); | 32 return listOfValuesAndTypes; |
| 33 } | 33 } |
| 34 | 34 |
| 35 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
Length(const Length& length, float zoom) const | 35 InterpolationValue* LengthInterpolationType::maybeConvertLength(const Length& le
ngth, float zoom) const |
| 36 { | 36 { |
| 37 if (!length.isSpecified()) | 37 if (!length.isSpecified()) |
| 38 return nullptr; | 38 return nullptr; |
| 39 | 39 |
| 40 PixelsAndPercent pixelsAndPercent = length.pixelsAndPercent(); | 40 PixelsAndPercent pixelsAndPercent = length.pixelsAndPercent(); |
| 41 OwnPtrWillBeRawPtr<InterpolableList> valuesAndTypes = createNeutralValue(); | 41 InterpolableList* valuesAndTypes = createNeutralValue(); |
| 42 | 42 |
| 43 InterpolableList& values = toInterpolableList(*valuesAndTypes->get(0)); | 43 InterpolableList& values = toInterpolableList(*valuesAndTypes->get(0)); |
| 44 values.set(CSSPrimitiveValue::UnitTypePixels, InterpolableNumber::create(pix
elsAndPercent.pixels / zoom)); | 44 values.set(CSSPrimitiveValue::UnitTypePixels, InterpolableNumber::create(pix
elsAndPercent.pixels / zoom)); |
| 45 values.set(CSSPrimitiveValue::UnitTypePercentage, InterpolableNumber::create
(pixelsAndPercent.percent)); | 45 values.set(CSSPrimitiveValue::UnitTypePercentage, InterpolableNumber::create
(pixelsAndPercent.percent)); |
| 46 | 46 |
| 47 InterpolableList& types = toInterpolableList(*valuesAndTypes->get(1)); | 47 InterpolableList& types = toInterpolableList(*valuesAndTypes->get(1)); |
| 48 types.set(CSSPrimitiveValue::UnitTypePixels, InterpolableNumber::create(1)); | 48 types.set(CSSPrimitiveValue::UnitTypePixels, InterpolableNumber::create(1)); |
| 49 types.set(CSSPrimitiveValue::UnitTypePercentage, InterpolableNumber::create(
1)); | 49 types.set(CSSPrimitiveValue::UnitTypePercentage, InterpolableNumber::create(
1)); |
| 50 | 50 |
| 51 return InterpolationValue::create(*this, valuesAndTypes.release()); | 51 return InterpolationValue::create(*this, valuesAndTypes); |
| 52 } | 52 } |
| 53 | 53 |
| 54 class ParentLengthChecker : public InterpolationType::ConversionChecker { | 54 class ParentLengthChecker : public InterpolationType::ConversionChecker { |
| 55 public: | 55 public: |
| 56 static PassOwnPtrWillBeRawPtr<ParentLengthChecker> create(CSSPropertyID prop
erty, const Length& length) | 56 static ParentLengthChecker* create(CSSPropertyID property, const Length& len
gth) |
| 57 { | 57 { |
| 58 return adoptPtrWillBeNoop(new ParentLengthChecker(property, length)); | 58 return new ParentLengthChecker(property, length); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 ParentLengthChecker(CSSPropertyID property, const Length& length) | 62 ParentLengthChecker(CSSPropertyID property, const Length& length) |
| 63 : m_property(property) | 63 : m_property(property) |
| 64 , m_length(length) | 64 , m_length(length) |
| 65 { } | 65 { } |
| 66 | 66 |
| 67 bool isValid(const StyleResolverState& state) const final | 67 bool isValid(const StyleResolverState& state) const final |
| 68 { | 68 { |
| 69 Length parentLength; | 69 Length parentLength; |
| 70 if (!LengthPropertyFunctions::getLength(m_property, *state.parentStyle()
, parentLength)) | 70 if (!LengthPropertyFunctions::getLength(m_property, *state.parentStyle()
, parentLength)) |
| 71 return true; | 71 return true; |
| 72 return parentLength == m_length; | 72 return parentLength == m_length; |
| 73 } | 73 } |
| 74 | 74 |
| 75 DEFINE_INLINE_VIRTUAL_TRACE() | 75 DEFINE_INLINE_VIRTUAL_TRACE() |
| 76 { | 76 { |
| 77 ConversionChecker::trace(visitor); | 77 ConversionChecker::trace(visitor); |
| 78 } | 78 } |
| 79 | 79 |
| 80 const CSSPropertyID m_property; | 80 const CSSPropertyID m_property; |
| 81 const Length m_length; | 81 const Length m_length; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
Neutral() const | 84 InterpolationValue* LengthInterpolationType::maybeConvertNeutral() const |
| 85 { | 85 { |
| 86 return InterpolationValue::create(*this, createNeutralValue()); | 86 return InterpolationValue::create(*this, createNeutralValue()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
Initial() const | 89 InterpolationValue* LengthInterpolationType::maybeConvertInitial() const |
| 90 { | 90 { |
| 91 Length initialLength; | 91 Length initialLength; |
| 92 if (!LengthPropertyFunctions::getInitialLength(m_property, initialLength)) | 92 if (!LengthPropertyFunctions::getInitialLength(m_property, initialLength)) |
| 93 return nullptr; | 93 return nullptr; |
| 94 return maybeConvertLength(initialLength, 1); | 94 return maybeConvertLength(initialLength, 1); |
| 95 } | 95 } |
| 96 | 96 |
| 97 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
Inherit(const StyleResolverState* state, ConversionCheckers& conversionCheckers)
const | 97 InterpolationValue* LengthInterpolationType::maybeConvertInherit(const StyleReso
lverState* state, ConversionCheckers& conversionCheckers) const |
| 98 { | 98 { |
| 99 if (!state || !state->parentStyle()) | 99 if (!state || !state->parentStyle()) |
| 100 return nullptr; | 100 return nullptr; |
| 101 Length inheritedLength; | 101 Length inheritedLength; |
| 102 if (!LengthPropertyFunctions::getLength(m_property, *state->parentStyle(), i
nheritedLength)) | 102 if (!LengthPropertyFunctions::getLength(m_property, *state->parentStyle(), i
nheritedLength)) |
| 103 return nullptr; | 103 return nullptr; |
| 104 conversionCheckers.append(ParentLengthChecker::create(m_property, inheritedL
ength)); | 104 conversionCheckers.append(ParentLengthChecker::create(m_property, inheritedL
ength)); |
| 105 return maybeConvertLength(inheritedLength, state->parentStyle()->effectiveZo
om()); | 105 return maybeConvertLength(inheritedLength, state->parentStyle()->effectiveZo
om()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
Value(const CSSValue& value, const StyleResolverState* state, ConversionCheckers
& conversionCheckers) const | 108 InterpolationValue* LengthInterpolationType::maybeConvertValue(const CSSValue& v
alue, const StyleResolverState* state, ConversionCheckers& conversionCheckers) c
onst |
| 109 { | 109 { |
| 110 if (!value.isPrimitiveValue()) | 110 if (!value.isPrimitiveValue()) |
| 111 return nullptr; | 111 return nullptr; |
| 112 | 112 |
| 113 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | 113 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 114 | 114 |
| 115 OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList
::create(2); | 115 InterpolableList* listOfValuesAndTypes = InterpolableList::create(2); |
| 116 OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create
(CSSPrimitiveValue::LengthUnitTypeCount); | 116 InterpolableList* listOfValues = InterpolableList::create(CSSPrimitiveValue:
:LengthUnitTypeCount); |
| 117 OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create(
CSSPrimitiveValue::LengthUnitTypeCount); | 117 InterpolableList* listOfTypes = InterpolableList::create(CSSPrimitiveValue::
LengthUnitTypeCount); |
| 118 | 118 |
| 119 CSSLengthArray arrayOfValues; | 119 CSSLengthArray arrayOfValues; |
| 120 CSSLengthTypeArray arrayOfTypes; | 120 CSSLengthTypeArray arrayOfTypes; |
| 121 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) | 121 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) |
| 122 arrayOfValues.append(0); | 122 arrayOfValues.append(0); |
| 123 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); | 123 arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); |
| 124 | 124 |
| 125 if (primitiveValue.isValueID()) { | 125 if (primitiveValue.isValueID()) { |
| 126 CSSValueID valueID = primitiveValue.getValueID(); | 126 CSSValueID valueID = primitiveValue.getValueID(); |
| 127 double pixels; | 127 double pixels; |
| 128 if (!LengthPropertyFunctions::getPixelsForKeyword(m_property, valueID, p
ixels)) | 128 if (!LengthPropertyFunctions::getPixelsForKeyword(m_property, valueID, p
ixels)) |
| 129 return nullptr; | 129 return nullptr; |
| 130 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels); | 130 arrayOfTypes.set(CSSPrimitiveValue::UnitTypePixels); |
| 131 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels; | 131 arrayOfValues[CSSPrimitiveValue::UnitTypePixels] = pixels; |
| 132 } else { | 132 } else { |
| 133 if (!primitiveValue.isLength() && !primitiveValue.isPercentage() && !pri
mitiveValue.isCalculatedPercentageWithLength()) | 133 if (!primitiveValue.isLength() && !primitiveValue.isPercentage() && !pri
mitiveValue.isCalculatedPercentageWithLength()) |
| 134 return nullptr; | 134 return nullptr; |
| 135 primitiveValue.accumulateLengthArray(arrayOfValues, arrayOfTypes); | 135 primitiveValue.accumulateLengthArray(arrayOfValues, arrayOfTypes); |
| 136 } | 136 } |
| 137 | 137 |
| 138 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { | 138 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| 139 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); | 139 listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); |
| 140 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); | 140 listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); |
| 141 } | 141 } |
| 142 | 142 |
| 143 listOfValuesAndTypes->set(0, listOfValues.release()); | 143 listOfValuesAndTypes->set(0, listOfValues); |
| 144 listOfValuesAndTypes->set(1, listOfTypes.release()); | 144 listOfValuesAndTypes->set(1, listOfTypes); |
| 145 | 145 |
| 146 return InterpolationValue::create(*this, listOfValuesAndTypes.release()); | 146 return InterpolationValue::create(*this, listOfValuesAndTypes); |
| 147 } | 147 } |
| 148 | 148 |
| 149 PassOwnPtrWillBeRawPtr<InterpolationValue> LengthInterpolationType::maybeConvert
UnderlyingValue(const StyleResolverState& state) const | 149 InterpolationValue* LengthInterpolationType::maybeConvertUnderlyingValue(const S
tyleResolverState& state) const |
| 150 { | 150 { |
| 151 Length underlyingLength; | 151 Length underlyingLength; |
| 152 if (!LengthPropertyFunctions::getLength(m_property, *state.style(), underlyi
ngLength)) | 152 if (!LengthPropertyFunctions::getLength(m_property, *state.style(), underlyi
ngLength)) |
| 153 return nullptr; | 153 return nullptr; |
| 154 return maybeConvertLength(underlyingLength, state.style()->effectiveZoom()); | 154 return maybeConvertLength(underlyingLength, state.style()->effectiveZoom()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void LengthInterpolationType::apply(const InterpolableValue& interpolableValue,
const NonInterpolableValue*, StyleResolverState& state) const | 157 void LengthInterpolationType::apply(const InterpolableValue& interpolableValue,
const NonInterpolableValue*, StyleResolverState& state) const |
| 158 { | 158 { |
| 159 // TODO(alancutter): Make all length interpolation functions operate on Valu
eRanges instead of InterpolationRanges. | 159 // TODO(alancutter): Make all length interpolation functions operate on Valu
eRanges instead of InterpolationRanges. |
| 160 InterpolationRange range = m_valueRange == ValueRangeNonNegative ? RangeNonN
egative : RangeAll; | 160 InterpolationRange range = m_valueRange == ValueRangeNonNegative ? RangeNonN
egative : RangeAll; |
| 161 // TODO(alancutter): Set arbitrary property Lengths on ComputedStyle without
using cross compilation unit member function getters (Windows runtime doesn't l
ike it). | 161 // TODO(alancutter): Set arbitrary property Lengths on ComputedStyle without
using cross compilation unit member function getters (Windows runtime doesn't l
ike it). |
| 162 ASSERT(m_property == CSSPropertyLeft); | 162 ASSERT(m_property == CSSPropertyLeft); |
| 163 LengthStyleInterpolation::applyInterpolableValue(m_property, interpolableVal
ue, range, state, &ComputedStyle::setLeft); | 163 LengthStyleInterpolation::applyInterpolableValue(m_property, interpolableVal
ue, range, state, &ComputedStyle::setLeft); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |