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

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

Issue 1304993002: Change Rect and Quad to be CSSValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@split_counter_out_attempt_3
Patch Set: Small change to generated style builder functions Created 5 years, 3 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/CSSQuadValue.h"
8 #include "core/css/resolver/StyleBuilder.h" 9 #include "core/css/resolver/StyleBuilder.h"
9 10
10 namespace blink { 11 namespace blink {
11 12
12 namespace { 13 namespace {
13 14
14 bool onlyInterpolateBetweenLengthAndCSSValueAuto(Rect& startRect, Rect& endRect) 15 bool onlyInterpolateBetweenLengthAndCSSValueAuto(const CSSQuadValue& startRect, const CSSQuadValue& endRect)
15 { 16 {
16 return startRect.left()->isLength() != endRect.left()->isLength() 17 return startRect.left()->isLength() != endRect.left()->isLength()
17 && startRect.right()->isLength() != endRect.right()->isLength() 18 && startRect.right()->isLength() != endRect.right()->isLength()
18 && startRect.top()->isLength() != endRect.top()->isLength() 19 && startRect.top()->isLength() != endRect.top()->isLength()
19 && startRect.bottom()->isLength() != endRect.bottom()->isLength(); 20 && startRect.bottom()->isLength() != endRect.bottom()->isLength();
20 } 21 }
21 22
22 } // namespace 23 } // namespace
23 24
24 PassRefPtrWillBeRawPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation: :maybeCreateFrom(CSSValue& start, CSSValue& end, CSSPropertyID id) 25 PassRefPtrWillBeRawPtr<LengthBoxStyleInterpolation> LengthBoxStyleInterpolation: :maybeCreateFrom(CSSValue& start, CSSValue& end, CSSPropertyID id)
25 { 26 {
26 bool startRect = start.isPrimitiveValue() && toCSSPrimitiveValue(start).isRe ct(); 27 bool startRect = start.isQuadValue() && toCSSQuadValue(start).serializationT ype() == CSSQuadValue::SerializationType::SerializeAsRect;
27 bool endRect = end.isPrimitiveValue() && toCSSPrimitiveValue(end).isRect(); 28 bool endRect = end.isQuadValue() && toCSSQuadValue(end).serializationType() == CSSQuadValue::SerializationType::SerializeAsRect;
28 29
29 if (startRect && endRect) 30 if (startRect && endRect)
30 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(lengthBoxtoInt erpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true ), id, &start, &end)); 31 return adoptRefWillBeNoop(new LengthBoxStyleInterpolation(lengthBoxtoInt erpolableValue(start, end, false), lengthBoxtoInterpolableValue(end, start, true ), id, &start, &end));
31 return nullptr; 32 return nullptr;
32 } 33 }
33 34
34 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox toInterpolableValue(const CSSValue& lengthBox, const CSSValue& matchingValue, bo ol isEndInterpolation) 35 PassOwnPtrWillBeRawPtr<InterpolableValue> LengthBoxStyleInterpolation::lengthBox toInterpolableValue(const CSSValue& lengthBox, const CSSValue& matchingValue, bo ol isEndInterpolation)
35 { 36 {
36 const int numberOfSides = 4; 37 const int numberOfSides = 4;
37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides); 38 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(numbe rOfSides);
38 Rect* rect = toCSSPrimitiveValue(lengthBox).getRectValue(); 39 const CSSQuadValue& rect = toCSSQuadValue(lengthBox);
39 Rect* matchingRect = toCSSPrimitiveValue(matchingValue).getRectValue(); 40 const CSSQuadValue& matchingRect = toCSSQuadValue(matchingValue);
40 CSSPrimitiveValue* side[numberOfSides] = { rect->left(), rect->right(), rect ->top(), rect->bottom() }; 41 CSSPrimitiveValue* side[numberOfSides] = { rect.left(), rect.right(), rect.t op(), rect.bottom() };
41 CSSPrimitiveValue* matchingSide[numberOfSides] = { matchingRect->left(), mat chingRect->right(), matchingRect->top(), matchingRect->bottom() }; 42 CSSPrimitiveValue* matchingSide[numberOfSides] = { matchingRect.left(), matc hingRect.right(), matchingRect.top(), matchingRect.bottom() };
42 43
43 for (size_t i = 0; i < numberOfSides; i++) { 44 for (size_t i = 0; i < numberOfSides; i++) {
44 if (side[i]->isValueID() || matchingSide[i]->isValueID()) { 45 if (side[i]->isValueID() || matchingSide[i]->isValueID()) {
45 result->set(i, InterpolableBool::create(isEndInterpolation)); 46 result->set(i, InterpolableBool::create(isEndInterpolation));
46 } else { 47 } else {
47 ASSERT(LengthStyleInterpolation::canCreateFrom(*side[i])); 48 ASSERT(LengthStyleInterpolation::canCreateFrom(*side[i]));
48 result->set(i, LengthStyleInterpolation::toInterpolableValue(*side[i ])); 49 result->set(i, LengthStyleInterpolation::toInterpolableValue(*side[i ]));
49 } 50 }
50 } 51 }
51 return result.release(); 52 return result.release();
52 } 53 }
53 54
54 bool LengthBoxStyleInterpolation::usesDefaultInterpolation(const CSSValue& start , const CSSValue& end) 55 bool LengthBoxStyleInterpolation::usesDefaultInterpolation(const CSSValue& start , const CSSValue& end)
55 { 56 {
56 if (!start.isPrimitiveValue() || !end.isPrimitiveValue()) 57 if (start.isPrimitiveValue() && end.isPrimitiveValue()) {
58 const CSSPrimitiveValue& startValue = toCSSPrimitiveValue(start);
59 const CSSPrimitiveValue& endValue = toCSSPrimitiveValue(end);
60 return (startValue.isValueID() && startValue.getValueID() == CSSValueAut o)
61 || (endValue.isValueID() && endValue.getValueID() == CSSValueAuto);
62 }
63
64 if (!start.isQuadValue() || !end.isQuadValue())
57 return false; 65 return false;
58 const CSSPrimitiveValue& startValue = toCSSPrimitiveValue(start); 66
59 const CSSPrimitiveValue& endValue = toCSSPrimitiveValue(end); 67 const CSSQuadValue& startValue = toCSSQuadValue(start);
60 if ((startValue.isValueID() && startValue.getValueID() == CSSValueAuto) 68 const CSSQuadValue& endValue = toCSSQuadValue(end);
61 || (endValue.isValueID() && endValue.getValueID() == CSSValueAuto)) 69 return onlyInterpolateBetweenLengthAndCSSValueAuto(startValue, endValue);
62 return true;
63 return onlyInterpolateBetweenLengthAndCSSValueAuto(*startValue.getRectValue( ), *endValue.getRectValue());
64 } 70 }
65 71
66 namespace { 72 namespace {
67 73
68 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> indexedValueToLength(InterpolableList& lengthBox, size_t i, CSSPrimitiveValue* start[], CSSPrimitiveValue* end[]) 74 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> indexedValueToLength(InterpolableList& lengthBox, size_t i, CSSPrimitiveValue* start[], CSSPrimitiveValue* end[])
69 { 75 {
70 if (lengthBox.get(i)->isBool()) { 76 if (lengthBox.get(i)->isBool()) {
71 if (toInterpolableBool(lengthBox.get(i))->value()) 77 if (toInterpolableBool(lengthBox.get(i))->value())
72 return end[i]; 78 return end[i];
73 return start[i]; 79 return start[i];
74 } 80 }
75 return LengthStyleInterpolation::fromInterpolableValue(*lengthBox.get(i), Ra ngeAll); 81 return LengthStyleInterpolation::fromInterpolableValue(*lengthBox.get(i), Ra ngeAll);
76 } 82 }
77 83
78 } 84 }
79 85
80 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT oLengthBox(InterpolableValue* value, const CSSValue& originalStart, const CSSVal ue& originalEnd) 86 PassRefPtrWillBeRawPtr<CSSValue> LengthBoxStyleInterpolation::interpolableValueT oLengthBox(InterpolableValue* value, const CSSValue& originalStart, const CSSVal ue& originalEnd)
81 { 87 {
82 InterpolableList* lengthBox = toInterpolableList(value); 88 InterpolableList* lengthBox = toInterpolableList(value);
83 Rect* startRect = toCSSPrimitiveValue(originalStart).getRectValue(); 89 const CSSQuadValue& startRect = toCSSQuadValue(originalStart);
84 Rect* endRect = toCSSPrimitiveValue(originalEnd).getRectValue(); 90 const CSSQuadValue& endRect = toCSSQuadValue(originalEnd);
85 CSSPrimitiveValue* startSides[4] = { startRect->left(), startRect->right(), startRect->top(), startRect->bottom() }; 91 CSSPrimitiveValue* startSides[4] = { startRect.left(), startRect.right(), st artRect.top(), startRect.bottom() };
86 CSSPrimitiveValue* endSides[4] = { endRect->left(), endRect->right(), endRec t->top(), endRect->bottom() }; 92 CSSPrimitiveValue* endSides[4] = { endRect.left(), endRect.right(), endRect. top(), endRect.bottom() };
87 RefPtrWillBeRawPtr<Rect> result = Rect::create();
88 93
89 result->setLeft(indexedValueToLength(*lengthBox, 0, startSides, endSides)); 94 RefPtrWillBeRawPtr<CSSPrimitiveValue> left = indexedValueToLength(*lengthBox , 0, startSides, endSides);
90 result->setRight(indexedValueToLength(*lengthBox, 1, startSides, endSides)); 95 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = indexedValueToLength(*lengthBo x, 1, startSides, endSides);
91 result->setTop(indexedValueToLength(*lengthBox, 2, startSides, endSides)); 96 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = indexedValueToLength(*lengthBox, 2, startSides, endSides);
92 result->setBottom(indexedValueToLength(*lengthBox, 3, startSides, endSides)) ; 97 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = indexedValueToLength(*lengthB ox, 3, startSides, endSides);
93 98
94 return CSSPrimitiveValue::create(result.release()); 99 return CSSQuadValue::create(top.release(), right.release(), bottom.release() , left.release(), CSSQuadValue::SerializeAsRect);
95 } 100 }
96 101
97 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const 102 void LengthBoxStyleInterpolation::apply(StyleResolverState& state) const
98 { 103 {
99 if (m_cachedValue.get()->isBool()) 104 if (m_cachedValue.get()->isBool())
100 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue.get() : m_startCSSValue.get()); 105 StyleBuilder::applyProperty(m_id, state, toInterpolableBool(m_cachedValu e.get())->value() ? m_endCSSValue.get() : m_startCSSValue.get());
101 else 106 else
102 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), *m_startCSSValue, *m_endCSSValue).get()); 107 StyleBuilder::applyProperty(m_id, state, interpolableValueToLengthBox(m_ cachedValue.get(), *m_startCSSValue, *m_endCSSValue).get());
103 } 108 }
104 109
105 DEFINE_TRACE(LengthBoxStyleInterpolation) 110 DEFINE_TRACE(LengthBoxStyleInterpolation)
106 { 111 {
107 StyleInterpolation::trace(visitor); 112 StyleInterpolation::trace(visitor);
108 visitor->trace(m_startCSSValue); 113 visitor->trace(m_startCSSValue);
109 visitor->trace(m_endCSSValue); 114 visitor->trace(m_endCSSValue);
110 } 115 }
111 116
112 } 117 }
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