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/ImageSliceStyleInterpolation.h" | 6 #include "core/animation/ImageSliceStyleInterpolation.h" |
7 | 7 |
8 #include "core/css/CSSBorderImageSliceValue.h" | 8 #include "core/css/CSSBorderImageSliceValue.h" |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
10 #include "core/css/CSSQuadValue.h" | 10 #include "core/css/CSSQuadValue.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace { | 25 namespace { |
26 | 26 |
27 class Decomposition { | 27 class Decomposition { |
28 STACK_ALLOCATED(); | 28 STACK_ALLOCATED(); |
29 public: | 29 public: |
30 Decomposition(const CSSBorderImageSliceValue& value) | 30 Decomposition(const CSSBorderImageSliceValue& value) |
31 { | 31 { |
32 decompose(value); | 32 decompose(value); |
33 } | 33 } |
34 | 34 |
35 OwnPtrWillBeMember<InterpolableValue> interpolableValue; | 35 OwnPtr<InterpolableValue> interpolableValue; |
36 ImageSliceStyleInterpolation::Metadata metadata; | 36 ImageSliceStyleInterpolation::Metadata metadata; |
37 | 37 |
38 private: | 38 private: |
39 void decompose(const CSSBorderImageSliceValue& value) | 39 void decompose(const CSSBorderImageSliceValue& value) |
40 { | 40 { |
41 const size_t kQuadSides = 4; | 41 const size_t kQuadSides = 4; |
42 OwnPtrWillBeRawPtr<InterpolableList> interpolableList = InterpolableList
::create(kQuadSides); | 42 OwnPtr<InterpolableList> interpolableList = InterpolableList::create(kQu
adSides); |
43 const CSSQuadValue& quad = *value.slices(); | 43 const CSSQuadValue& quad = *value.slices(); |
44 interpolableList->set(0, InterpolableNumber::create(quad.top()->getDoubl
eValue())); | 44 interpolableList->set(0, InterpolableNumber::create(quad.top()->getDoubl
eValue())); |
45 interpolableList->set(1, InterpolableNumber::create(quad.right()->getDou
bleValue())); | 45 interpolableList->set(1, InterpolableNumber::create(quad.right()->getDou
bleValue())); |
46 interpolableList->set(2, InterpolableNumber::create(quad.bottom()->getDo
ubleValue())); | 46 interpolableList->set(2, InterpolableNumber::create(quad.bottom()->getDo
ubleValue())); |
47 interpolableList->set(3, InterpolableNumber::create(quad.left()->getDoub
leValue())); | 47 interpolableList->set(3, InterpolableNumber::create(quad.left()->getDoub
leValue())); |
48 bool isPercentage = quad.top()->isPercentage(); | 48 bool isPercentage = quad.top()->isPercentage(); |
49 ASSERT(quad.bottom()->isPercentage() == isPercentage | 49 ASSERT(quad.bottom()->isPercentage() == isPercentage |
50 && quad.left()->isPercentage() == isPercentage | 50 && quad.left()->isPercentage() == isPercentage |
51 && quad.right()->isPercentage() == isPercentage); | 51 && quad.right()->isPercentage() == isPercentage); |
52 | 52 |
53 interpolableValue = interpolableList.release(); | 53 interpolableValue = interpolableList.release(); |
54 metadata = ImageSliceStyleInterpolation::Metadata {isPercentage, value.m
_fill}; | 54 metadata = ImageSliceStyleInterpolation::Metadata {isPercentage, value.m
_fill}; |
55 } | 55 } |
56 }; | 56 }; |
57 | 57 |
58 PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> compose(const InterpolableValue
& value, const ImageSliceStyleInterpolation::Metadata& metadata) | 58 PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> compose(const InterpolableValue
& value, const ImageSliceStyleInterpolation::Metadata& metadata) |
59 { | 59 { |
60 const InterpolableList& interpolableList = toInterpolableList(value); | 60 const InterpolableList& interpolableList = toInterpolableList(value); |
61 CSSPrimitiveValue::UnitType type = metadata.isPercentage ? CSSPrimitiveValue
::UnitType::Percentage : CSSPrimitiveValue::UnitType::Number; | 61 CSSPrimitiveValue::UnitType type = metadata.isPercentage ? CSSPrimitiveValue
::UnitType::Percentage : CSSPrimitiveValue::UnitType::Number; |
62 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = CSSPrimitiveValue::create(clampT
o<double>(toInterpolableNumber(interpolableList.get(0))->value(), 0), type); | 62 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = CSSPrimitiveValue::create(clampT
o<double>(toInterpolableNumber(interpolableList.get(0))->value(), 0), type); |
63 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = CSSPrimitiveValue::create(clam
pTo<double>(toInterpolableNumber(interpolableList.get(1))->value(), 0), type); | 63 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = CSSPrimitiveValue::create(clam
pTo<double>(toInterpolableNumber(interpolableList.get(1))->value(), 0), type); |
64 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = CSSPrimitiveValue::create(cla
mpTo<double>(toInterpolableNumber(interpolableList.get(2))->value(), 0), type); | 64 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = CSSPrimitiveValue::create(cla
mpTo<double>(toInterpolableNumber(interpolableList.get(2))->value(), 0), type); |
65 RefPtrWillBeRawPtr<CSSPrimitiveValue> left = CSSPrimitiveValue::create(clamp
To<double>(toInterpolableNumber(interpolableList.get(3))->value(), 0), type); | 65 RefPtrWillBeRawPtr<CSSPrimitiveValue> left = CSSPrimitiveValue::create(clamp
To<double>(toInterpolableNumber(interpolableList.get(3))->value(), 0), type); |
66 return CSSBorderImageSliceValue::create(CSSQuadValue::create(top.release(),
right.release(), bottom.release(), left.release(), CSSQuadValue::SerializeAsQuad
), metadata.fill); | 66 return CSSBorderImageSliceValue::create(CSSQuadValue::create(top.release(),
right.release(), bottom.release(), left.release(), CSSQuadValue::SerializeAsQuad
), metadata.fill); |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 PassRefPtrWillBeRawPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolatio
n::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID propert
y) | 71 PassRefPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolation::maybeCrea
te(const CSSValue& start, const CSSValue& end, CSSPropertyID property) |
72 { | 72 { |
73 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) | 73 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) |
74 return nullptr; | 74 return nullptr; |
75 | 75 |
76 Decomposition startDecompose(toCSSBorderImageSliceValue(start)); | 76 Decomposition startDecompose(toCSSBorderImageSliceValue(start)); |
77 Decomposition endDecompose(toCSSBorderImageSliceValue(end)); | 77 Decomposition endDecompose(toCSSBorderImageSliceValue(end)); |
78 if (!(startDecompose.metadata == endDecompose.metadata)) | 78 if (!(startDecompose.metadata == endDecompose.metadata)) |
79 return nullptr; | 79 return nullptr; |
80 | 80 |
81 return adoptRefWillBeNoop(new ImageSliceStyleInterpolation( | 81 return adoptRef(new ImageSliceStyleInterpolation( |
82 startDecompose.interpolableValue.release(), | 82 startDecompose.interpolableValue.release(), |
83 endDecompose.interpolableValue.release(), | 83 endDecompose.interpolableValue.release(), |
84 property, | 84 property, |
85 startDecompose.metadata | 85 startDecompose.metadata |
86 )); | 86 )); |
87 } | 87 } |
88 | 88 |
89 void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const | 89 void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const |
90 { | 90 { |
91 StyleBuilder::applyProperty(m_id, state, compose(*m_cachedValue, m_metadata)
.get()); | 91 StyleBuilder::applyProperty(m_id, state, compose(*m_cachedValue, m_metadata)
.get()); |
92 } | 92 } |
93 | 93 |
94 DEFINE_TRACE(ImageSliceStyleInterpolation) | |
95 { | |
96 StyleInterpolation::trace(visitor); | |
97 } | |
98 | |
99 } // namespace blink | 94 } // namespace blink |
OLD | NEW |