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

Side by Side Diff: Source/core/animation/LengthBoxStyleInterpolation.cpp

Issue 995253002: Web Animations: Split image slice interpolation out of LengthBoxStyleInterpolation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: crbug.com/466536 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 | Annotate | Revision Log
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/LengthBoxStyleInterpolation.h" 6 #include "core/animation/LengthBoxStyleInterpolation.h"
7 7
8 #include "core/css/resolver/StyleBuilder.h" 8 #include "core/css/resolver/StyleBuilder.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 namespace { 12 namespace {
13 13
14 bool onlyInterpolateBetweenLengthAndCSSValueAuto(Rect& startRect, Rect& endRect) 14 bool onlyInterpolateBetweenLengthAndCSSValueAuto(Rect& startRect, Rect& endRect)
15 { 15 {
16 return startRect.left()->isLength() != endRect.left()->isLength() 16 return startRect.left()->isLength() != endRect.left()->isLength()
17 && startRect.right()->isLength() != endRect.right()->isLength() 17 && startRect.right()->isLength() != endRect.right()->isLength()
18 && startRect.top()->isLength() != endRect.top()->isLength() 18 && startRect.top()->isLength() != endRect.top()->isLength()
19 && startRect.bottom()->isLength() != endRect.bottom()->isLength(); 19 && startRect.bottom()->isLength() != endRect.bottom()->isLength();
20 } 20 }
21 21
22 } // namespace 22 } // namespace
23 23
24 PassRefPtrWillBeRawPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation: :maybeCreateFrom(CSSValue& start, CSSValue& end, CSSPropertyID id) 24 PassRefPtrWillBeRawPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation: :maybeCreateFrom(CSSValue& start, CSSValue& end, CSSPropertyID id)
25 { 25 {
26 bool startRect = start.isPrimitiveValue() && toCSSPrimitiveValue(start).isRe ct(); 26 bool startRect = start.isPrimitiveValue() && toCSSPrimitiveValue(start).isRe ct();
27 bool endRect = end.isPrimitiveValue() && toCSSPrimitiveValue(end).isRect(); 27 bool endRect = end.isPrimitiveValue() && toCSSPrimitiveValue(end).isRect();
28 28
29 if (startRect && endRect) { 29 if (startRect && endRect)
30 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(lengthBoxtoInt erpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true ), id, false, &start, &end)); 30 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(lengthBoxtoInt erpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true ), id, &start, &end));
31 }
32 if (start.isBorderImageSliceValue() && toCSSBorderImageSliceValue(start).sli ces()
33 && end.isBorderImageSliceValue() && toCSSBorderImageSliceValue(end).slic es()
34 && toCSSBorderImageSliceValue(start).m_fill == toCSSBorderImageSliceValu e(end).m_fill)
35 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(borderImageSli cetoInterpolableValue(start), borderImageSlicetoInterpolableValue(end), id, toCS SBorderImageSliceValue(start).m_fill, &start, &end));
36 return nullptr; 31 return nullptr;
37 } 32 }
38 33
39 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox toInterpolableValue(const CSSValue& lengthBox, const CSSValue& matchingValue, bo ol isEndInterpolation) 34 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox toInterpolableValue(const CSSValue& lengthBox, const CSSValue& matchingValue, bo ol isEndInterpolation)
40 { 35 {
41 const int numberOfSides = 4; 36 const int numberOfSides = 4;
42 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides); 37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides);
43 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue(); 38 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue();
44 Rect* matchingRect = toCSSPrimitiveValue(matchingValue).getRectValue(); 39 Rect* matchingRect = toCSSPrimitiveValue(matchingValue).getRectValue();
45 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect ->top(), rect->bottom() }; 40 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect ->top(), rect->bottom() };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 RefPtrWillBeRawPtr<Rect> result = Rect::create(); 87 RefPtrWillBeRawPtr<Rect> result = Rect::create();
93 88
94 result->setLeft(indexedValueToLength(*lengthBox, 0, startSides, endSides)); 89 result->setLeft(indexedValueToLength(*lengthBox, 0, startSides, endSides));
95 result->setRight(indexedValueToLength(*lengthBox, 1, startSides, endSides)); 90 result->setRight(indexedValueToLength(*lengthBox, 1, startSides, endSides));
96 result->setTop(indexedValueToLength(*lengthBox, 2, startSides, endSides)); 91 result->setTop(indexedValueToLength(*lengthBox, 2, startSides, endSides));
97 result->setBottom(indexedValueToLength(*lengthBox, 3, startSides, endSides)) ; 92 result->setBottom(indexedValueToLength(*lengthBox, 3, startSides, endSides)) ;
98 93
99 return CSSPrimitiveValue::create(result.release()); 94 return CSSPrimitiveValue::create(result.release());
100 } 95 }
101 96
102 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::borderIma geSlicetoInterpolableValue(const CSSValue& value)
103 {
104 const int numberOfSides = 4;
105 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides);
106 Quad* quad = toCSSBorderImageSliceValue(value).slices();
107 CSSPrimitiveValue* side[numberOfSides] = { quad->left(), quad->right(), quad ->top(), quad->bottom() };
108
109 for (size_t i = 0; i < numberOfSides; i++) {
110 result->set(i, LengthStyleInterpolation::toInterpolableValue(*side[i]));
111 }
112 return result.release();
113 }
114
115 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT oBorderImageSlice(InterpolableValue* value, bool fill)
116 {
117 InterpolableList* lengthBox = toInterpolableList(value);
118 RefPtrWillBeRawPtr<Quad> quad = Quad::create();
119
120 quad->setLeft(LengthStyleInterpolation::fromInterpolableValue(*lengthBox->ge t(0), RangeNonNegative));
121 quad->setRight(LengthStyleInterpolation::fromInterpolableValue(*lengthBox->g et(1), RangeNonNegative));
122 quad->setTop(LengthStyleInterpolation::fromInterpolableValue(*lengthBox->get (2), RangeNonNegative));
123 quad->setBottom(LengthStyleInterpolation::fromInterpolableValue(*lengthBox-> get(3), RangeNonNegative));
124
125 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.relea se()), fill);
126 }
127
128 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const 97 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const
129 { 98 {
130 if (m_id == CSSPropertyWebkitMaskBoxImageSlice || m_id == CSSPropertyBorderI mageSlice) { 99 if (m_cachedValue.get()->isBool())
131 StyleBuilder::applyProperty(m_id, state, interpolableValueToBorderImageS lice(m_cachedValue.get(), m_fill).get());
132 } else if (m_cachedValue.get()->isBool()) {
133 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue.get() : m_startCSSValue.get()); 100 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue.get() : m_startCSSValue.get());
134 } else { 101 else
135 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), *m_startCSSValue, *m_endCSSValue).get()); 102 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), *m_startCSSValue, *m_endCSSValue).get());
136 }
137 } 103 }
138 104
139 DEFINE_TRACE(LengthBoxStyleInterpolation) 105 DEFINE_TRACE(LengthBoxStyleInterpolation)
140 { 106 {
141 StyleInterpolation::trace(visitor); 107 StyleInterpolation::trace(visitor);
142 visitor->trace(m_startCSSValue); 108 visitor->trace(m_startCSSValue);
143 visitor->trace(m_endCSSValue); 109 visitor->trace(m_endCSSValue);
144 } 110 }
145 111
146 } 112 }
OLDNEW
« no previous file with comments | « Source/core/animation/LengthBoxStyleInterpolation.h ('k') | Source/core/animation/LengthBoxStyleInterpolationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698