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/Rect.h" | 10 #include "core/css/Rect.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 Member<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 InterpolableList* interpolableList = InterpolableList::create(kQuadSides
); |
43 const Quad& quad = *value.slices(); | 43 const Quad& 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; |
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<Quad> quad = Quad::create(); | 62 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); |
63 quad->setTop(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumber(
interpolableList.get(0))->value(), 0), type)); | 63 quad->setTop(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumber(
interpolableList.get(0))->value(), 0), type)); |
64 quad->setRight(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumbe
r(interpolableList.get(1))->value(), 0), type)); | 64 quad->setRight(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumbe
r(interpolableList.get(1))->value(), 0), type)); |
65 quad->setBottom(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumb
er(interpolableList.get(2))->value(), 0), type)); | 65 quad->setBottom(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumb
er(interpolableList.get(2))->value(), 0), type)); |
66 quad->setLeft(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumber
(interpolableList.get(3))->value(), 0), type)); | 66 quad->setLeft(CSSPrimitiveValue::create(clampTo<double>(toInterpolableNumber
(interpolableList.get(3))->value(), 0), type)); |
67 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.relea
se()), metadata.fill); | 67 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.relea
se()), metadata.fill); |
68 } | 68 } |
69 | 69 |
70 } // namespace | 70 } // namespace |
71 | 71 |
72 PassRefPtrWillBeRawPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolatio
n::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID propert
y) | 72 ImageSliceStyleInterpolation* ImageSliceStyleInterpolation::maybeCreate(const CS
SValue& start, const CSSValue& end, CSSPropertyID property) |
73 { | 73 { |
74 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) | 74 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) |
75 return nullptr; | 75 return nullptr; |
76 | 76 |
77 Decomposition startDecompose(toCSSBorderImageSliceValue(start)); | 77 Decomposition startDecompose(toCSSBorderImageSliceValue(start)); |
78 Decomposition endDecompose(toCSSBorderImageSliceValue(end)); | 78 Decomposition endDecompose(toCSSBorderImageSliceValue(end)); |
79 if (!(startDecompose.metadata == endDecompose.metadata)) | 79 if (!(startDecompose.metadata == endDecompose.metadata)) |
80 return nullptr; | 80 return nullptr; |
81 | 81 |
82 return adoptRefWillBeNoop(new ImageSliceStyleInterpolation( | 82 return new ImageSliceStyleInterpolation(startDecompose.interpolableValue.rel
ease(), endDecompose.interpolableValue.release(), property, startDecompose.metad
ata); |
83 startDecompose.interpolableValue.release(), | |
84 endDecompose.interpolableValue.release(), | |
85 property, | |
86 startDecompose.metadata | |
87 )); | |
88 } | 83 } |
89 | 84 |
90 void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const | 85 void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const |
91 { | 86 { |
92 StyleBuilder::applyProperty(m_id, state, compose(*m_cachedValue, m_metadata)
.get()); | 87 StyleBuilder::applyProperty(m_id, state, compose(*m_cachedValue, m_metadata)
.get()); |
93 } | 88 } |
94 | 89 |
95 DEFINE_TRACE(ImageSliceStyleInterpolation) | 90 DEFINE_TRACE(ImageSliceStyleInterpolation) |
96 { | 91 { |
97 StyleInterpolation::trace(visitor); | 92 StyleInterpolation::trace(visitor); |
98 } | 93 } |
99 | 94 |
100 } // namespace blink | 95 } // namespace blink |
OLD | NEW |