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

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

Issue 1249553002: CSSValue Immediates: Add move operators to CSSPrimitiveValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_3_tagged_ptrs_with_copy_ops_mv_operators_ref_primvalue
Patch Set: Rebase Created 5 years, 4 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
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(const CSSValue& start, const CSSValue& end, CSSPropertyID id) 24 PassRefPtrWillBeRawPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation: :maybeCreateFrom(const CSSValue& start, const 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, start, end)); 30 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(lengthBoxtoInt erpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true ), id, start, end));
31 return nullptr; 31 return nullptr;
32 } 32 }
33 33
34 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)
35 { 35 {
36 const int numberOfSides = 4; 36 const int numberOfSides = 4;
37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides); 37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides);
38 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue(); 38 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue();
39 Rect* matchingRect = toCSSPrimitiveValue(matchingValue).getRectValue(); 39 Rect* matchingRect = toCSSPrimitiveValue(matchingValue).getRectValue();
40 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect ->top(), rect->bottom() }; 40 CSSPrimitiveValue side[numberOfSides] = { rect->left(), rect->right(), rect- >top(), rect->bottom() };
41 CSSPrimitiveValue* matchingSide[numberOfSides] = { matchingRect->left(), mat chingRect->right(), matchingRect->top(), matchingRect->bottom() }; 41 CSSPrimitiveValue matchingSide[numberOfSides] = { matchingRect->left(), matc hingRect->right(), matchingRect->top(), matchingRect->bottom() };
42 42
43 for (size_t i = 0; i < numberOfSides; i++) { 43 for (size_t i = 0; i < numberOfSides; i++) {
44 if (side[i]->isValueID() || matchingSide[i]->isValueID()) { 44 if (side[i].isValueID() || matchingSide[i].isValueID()) {
45 result->set(i, InterpolableBool::create(isEndInterpolation)); 45 result->set(i, InterpolableBool::create(isEndInterpolation));
46 } else { 46 } else {
47 CSSValue sideCSSValue(*side[i]); 47 CSSValue sideCSSValue(side[i]);
48 ASSERT(LengthStyleInterpolation::canCreateFrom(sideCSSValue)); 48 ASSERT(LengthStyleInterpolation::canCreateFrom(sideCSSValue));
49 result->set(i, LengthStyleInterpolation::toInterpolableValue(sideCSS Value)); 49 result->set(i, LengthStyleInterpolation::toInterpolableValue(sideCSS Value));
50 } 50 }
51 } 51 }
52 return result.release(); 52 return result.release();
53 } 53 }
54 54
55 bool LengthBoxStyleInterpolation::usesDefaultInterpolation(const CSSValue& start , const CSSValue& end) 55 bool LengthBoxStyleInterpolation::usesDefaultInterpolation(const CSSValue& start , const CSSValue& end)
56 { 56 {
57 if (!start.isPrimitiveValue() || !end.isPrimitiveValue()) 57 if (!start.isPrimitiveValue() || !end.isPrimitiveValue())
58 return false; 58 return false;
59 const CSSPrimitiveValue& startValue = toCSSPrimitiveValue(start); 59 const CSSPrimitiveValue& startValue = toCSSPrimitiveValue(start);
60 const CSSPrimitiveValue& endValue = toCSSPrimitiveValue(end); 60 const CSSPrimitiveValue& endValue = toCSSPrimitiveValue(end);
61 if ((startValue.isValueID() && startValue.getValueID() == CSSValueAuto) 61 if ((startValue.isValueID() && startValue.getValueID() == CSSValueAuto)
62 || (endValue.isValueID() && endValue.getValueID() == CSSValueAuto)) 62 || (endValue.isValueID() && endValue.getValueID() == CSSValueAuto))
63 return true; 63 return true;
64 return onlyInterpolateBetweenLengthAndCSSValueAuto(*startValue.getRectValue( ), *endValue.getRectValue()); 64 return onlyInterpolateBetweenLengthAndCSSValueAuto(*startValue.getRectValue( ), *endValue.getRectValue());
65 } 65 }
66 66
67 namespace { 67 namespace {
68 68
69 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> indexedValueToLength(InterpolableList& lengthBox, size_t i, CSSPrimitiveValue* start[], CSSPrimitiveValue* end[]) 69 CSSPrimitiveValue indexedValueToLength(InterpolableList& lengthBox, size_t i, CS SPrimitiveValue start[], CSSPrimitiveValue end[])
70 { 70 {
71 if (lengthBox.get(i)->isBool()) { 71 if (lengthBox.get(i)->isBool()) {
72 if (toInterpolableBool(lengthBox.get(i))->value()) 72 if (toInterpolableBool(lengthBox.get(i))->value())
73 return end[i]; 73 return end[i];
74 return start[i]; 74 return start[i];
75 } 75 }
76 return LengthStyleInterpolation::fromInterpolableValue(*lengthBox.get(i), Ra ngeAll); 76 return LengthStyleInterpolation::fromInterpolableValue(*lengthBox.get(i), Ra ngeAll);
77 } 77 }
78 78
79 } 79 }
80 80
81 CSSValue LengthBoxStyleInterpolation::interpolableValueToLengthBox(InterpolableV alue* value, const CSSValue& originalStart, const CSSValue& originalEnd) 81 CSSValue LengthBoxStyleInterpolation::interpolableValueToLengthBox(InterpolableV alue* value, const CSSValue& originalStart, const CSSValue& originalEnd)
82 { 82 {
83 InterpolableList* lengthBox = toInterpolableList(value); 83 InterpolableList* lengthBox = toInterpolableList(value);
84 Rect* startRect = toCSSPrimitiveValue(originalStart).getRectValue(); 84 Rect* startRect = toCSSPrimitiveValue(originalStart).getRectValue();
85 Rect* endRect = toCSSPrimitiveValue(originalEnd).getRectValue(); 85 Rect* endRect = toCSSPrimitiveValue(originalEnd).getRectValue();
86 CSSPrimitiveValue* startSides[4] = { startRect->left(), startRect->right(), startRect->top(), startRect->bottom() }; 86 CSSPrimitiveValue startSides[4] = { startRect->left(), startRect->right(), s tartRect->top(), startRect->bottom() };
87 CSSPrimitiveValue* endSides[4] = { endRect->left(), endRect->right(), endRec t->top(), endRect->bottom() }; 87 CSSPrimitiveValue endSides[4] = { endRect->left(), endRect->right(), endRect ->top(), endRect->bottom() };
88 RefPtrWillBeRawPtr<Rect> result = Rect::create(); 88 RefPtrWillBeRawPtr<Rect> result = Rect::create();
89 89
90 result->setLeft(indexedValueToLength(*lengthBox, 0, startSides, endSides)); 90 result->setLeft(indexedValueToLength(*lengthBox, 0, startSides, endSides));
91 result->setRight(indexedValueToLength(*lengthBox, 1, startSides, endSides)); 91 result->setRight(indexedValueToLength(*lengthBox, 1, startSides, endSides));
92 result->setTop(indexedValueToLength(*lengthBox, 2, startSides, endSides)); 92 result->setTop(indexedValueToLength(*lengthBox, 2, startSides, endSides));
93 result->setBottom(indexedValueToLength(*lengthBox, 3, startSides, endSides)) ; 93 result->setBottom(indexedValueToLength(*lengthBox, 3, startSides, endSides)) ;
94 94
95 return CSSPrimitiveValue::create(result.release()); 95 return CSSPrimitiveValue::create(result.release());
96 } 96 }
97 97
98 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const 98 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const
99 { 99 {
100 if (m_cachedValue.get()->isBool()) 100 if (m_cachedValue.get()->isBool())
101 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue : m_startCSSValue); 101 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue : m_startCSSValue);
102 else 102 else
103 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), m_startCSSValue, m_endCSSValue)); 103 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), m_startCSSValue, m_endCSSValue));
104 } 104 }
105 105
106 DEFINE_TRACE(LengthBoxStyleInterpolation) 106 DEFINE_TRACE(LengthBoxStyleInterpolation)
107 { 107 {
108 StyleInterpolation::trace(visitor); 108 StyleInterpolation::trace(visitor);
109 visitor->trace(m_startCSSValue); 109 visitor->trace(m_startCSSValue);
110 visitor->trace(m_endCSSValue); 110 visitor->trace(m_endCSSValue);
111 } 111 }
112 112
113 } 113 }
OLDNEW
« no previous file with comments | « Source/core/animation/KeyframeEffectModelTest.cpp ('k') | Source/core/animation/LengthBoxStyleInterpolationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698