OLD | NEW |
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/LengthBoxStyleInterpolation.h" | 6 #include "core/animation/LengthBoxStyleInterpolation.h" |
7 | 7 |
8 #include "core/css/Rect.h" | 8 #include "core/css/Rect.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 LengthBoxStyleInterpolation::canCreateFrom(const CSSValue& value) | 13 bool LengthBoxStyleInterpolation::canCreateFrom(const CSSValue& value) |
14 { | 14 { |
15 return value.isPrimitiveValue() && toCSSPrimitiveValue(value).isRect(); | 15 return value.isPrimitiveValue() && toCSSPrimitiveValue(value).isRect(); |
16 } | 16 } |
17 | 17 |
18 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox
toInterpolableValue(const CSSValue& lengthBox) | 18 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox
toInterpolableValue(const CSSValue& lengthBox) |
19 { | 19 { |
20 const int numberOfSides = 4; | 20 const int numberOfSides = 4; |
21 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe
rOfSides); | 21 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe
rOfSides); |
22 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue(); | 22 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue(); |
23 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect
->top(), rect->bottom() }; | 23 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect
->top(), rect->bottom() }; |
24 | 24 |
25 for (size_t i = 0; i < numberOfSides; i++) { | 25 for (size_t i = 0; i < numberOfSides; i++) { |
26 result->set(i, LengthStyleInterpolation::lengthToInterpolableValue(*side
[i])); | 26 result->set(i, LengthStyleInterpolation::toInterpolableValue(*side[i])); |
27 } | 27 } |
28 return result.release(); | 28 return result.release(); |
29 } | 29 } |
30 | 30 |
31 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT
oLengthBox(InterpolableValue* value, InterpolationRange range) | 31 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT
oLengthBox(InterpolableValue* value, InterpolationRange range) |
32 { | 32 { |
33 InterpolableList* lengthBox = toInterpolableList(value); | 33 InterpolableList* lengthBox = toInterpolableList(value); |
34 RefPtrWillBeRawPtr<Rect> result = Rect::create(); | 34 RefPtrWillBeRawPtr<Rect> result = Rect::create(); |
35 | 35 |
36 result->setLeft(LengthStyleInterpolation::interpolableValueToLength(lengthBo
x->get(0), RangeNonNegative)); | 36 result->setLeft(LengthStyleInterpolation::fromInterpolableValue(*lengthBox->
get(0), RangeNonNegative)); |
37 result->setRight(LengthStyleInterpolation::interpolableValueToLength(lengthB
ox->get(1), RangeNonNegative)); | 37 result->setRight(LengthStyleInterpolation::fromInterpolableValue(*lengthBox-
>get(1), RangeNonNegative)); |
38 result->setTop(LengthStyleInterpolation::interpolableValueToLength(lengthBox
->get(2), RangeNonNegative)); | 38 result->setTop(LengthStyleInterpolation::fromInterpolableValue(*lengthBox->g
et(2), RangeNonNegative)); |
39 result->setBottom(LengthStyleInterpolation::interpolableValueToLength(length
Box->get(3), RangeNonNegative)); | 39 result->setBottom(LengthStyleInterpolation::fromInterpolableValue(*lengthBox
->get(3), RangeNonNegative)); |
40 | 40 |
41 return CSSPrimitiveValue::create(result.release()); | 41 return CSSPrimitiveValue::create(result.release()); |
42 } | 42 } |
43 | 43 |
44 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const | 44 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const |
45 { | 45 { |
46 if (m_id == CSSPropertyWebkitMaskBoxImageSlice) | 46 if (m_id == CSSPropertyWebkitMaskBoxImageSlice) |
47 StyleBuilder::applyProperty(m_id, state, interpolableValueToBorderImageS
lice(m_cachedValue.get(), m_fill).get()); | 47 StyleBuilder::applyProperty(m_id, state, interpolableValueToBorderImageS
lice(m_cachedValue.get(), m_fill).get()); |
48 else | 48 else |
49 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_
cachedValue.get()).get()); | 49 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_
cachedValue.get()).get()); |
(...skipping 15 matching lines...) Expand all Loading... |
65 } | 65 } |
66 | 66 |
67 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::borderIma
geSlicetoInterpolableValue(CSSValue& value) | 67 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::borderIma
geSlicetoInterpolableValue(CSSValue& value) |
68 { | 68 { |
69 const int numberOfSides = 4; | 69 const int numberOfSides = 4; |
70 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe
rOfSides); | 70 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe
rOfSides); |
71 Quad* quad = toCSSBorderImageSliceValue(value).slices(); | 71 Quad* quad = toCSSBorderImageSliceValue(value).slices(); |
72 CSSPrimitiveValue* side[numberOfSides] = { quad->left(), quad->right(), quad
->top(), quad->bottom() }; | 72 CSSPrimitiveValue* side[numberOfSides] = { quad->left(), quad->right(), quad
->top(), quad->bottom() }; |
73 | 73 |
74 for (size_t i = 0; i < numberOfSides; i++) { | 74 for (size_t i = 0; i < numberOfSides; i++) { |
75 result->set(i, LengthStyleInterpolation::lengthToInterpolableValue(*side
[i])); | 75 result->set(i, LengthStyleInterpolation::toInterpolableValue(*side[i])); |
76 } | 76 } |
77 return result.release(); | 77 return result.release(); |
78 } | 78 } |
79 | 79 |
80 static inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toPrimitiveValue(PassRef
PtrWillBeRawPtr<CSSValue> value) | 80 static inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> toPrimitiveValue(PassRef
PtrWillBeRawPtr<CSSValue> value) |
81 { | 81 { |
82 return adoptRefWillBeNoop(toCSSPrimitiveValue(value.leakRef())); | 82 return adoptRefWillBeNoop(toCSSPrimitiveValue(value.leakRef())); |
83 } | 83 } |
84 | 84 |
85 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT
oBorderImageSlice(InterpolableValue* value, bool fill) | 85 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT
oBorderImageSlice(InterpolableValue* value, bool fill) |
86 { | 86 { |
87 InterpolableList* lengthBox = toInterpolableList(value); | 87 InterpolableList* lengthBox = toInterpolableList(value); |
88 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); | 88 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); |
89 | 89 |
90 quad->setLeft(toPrimitiveValue(LengthStyleInterpolation::interpolableValueTo
Length(lengthBox->get(0), RangeNonNegative))); | 90 quad->setLeft(toPrimitiveValue(LengthStyleInterpolation::fromInterpolableVal
ue(*lengthBox->get(0), RangeNonNegative))); |
91 quad->setRight(toPrimitiveValue(LengthStyleInterpolation::interpolableValueT
oLength(lengthBox->get(1), RangeNonNegative))); | 91 quad->setRight(toPrimitiveValue(LengthStyleInterpolation::fromInterpolableVa
lue(*lengthBox->get(1), RangeNonNegative))); |
92 quad->setTop(toPrimitiveValue(LengthStyleInterpolation::interpolableValueToL
ength(lengthBox->get(2), RangeNonNegative))); | 92 quad->setTop(toPrimitiveValue(LengthStyleInterpolation::fromInterpolableValu
e(*lengthBox->get(2), RangeNonNegative))); |
93 quad->setBottom(toPrimitiveValue(LengthStyleInterpolation::interpolableValue
ToLength(lengthBox->get(3), RangeNonNegative))); | 93 quad->setBottom(toPrimitiveValue(LengthStyleInterpolation::fromInterpolableV
alue(*lengthBox->get(3), RangeNonNegative))); |
94 | 94 |
95 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.relea
se()), fill); | 95 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.relea
se()), fill); |
96 } | 96 } |
97 | 97 |
98 } | 98 } |
OLD | NEW |