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

Side by Side Diff: third_party/WebKit/Source/core/animation/BasicShapeInterpolationFunctions.cpp

Issue 2283783002: Move static methods out of CSSLengthInterpolationType to LengthInterpolationFunctions (Closed)
Patch Set: Fix compile Created 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/animation/BasicShapeInterpolationFunctions.h" 5 #include "core/animation/BasicShapeInterpolationFunctions.h"
6 6
7 #include "core/animation/CSSLengthInterpolationType.h"
8 #include "core/animation/CSSPositionAxisListInterpolationType.h" 7 #include "core/animation/CSSPositionAxisListInterpolationType.h"
8 #include "core/animation/LengthInterpolationFunctions.h"
9 #include "core/css/CSSBasicShapeValues.h" 9 #include "core/css/CSSBasicShapeValues.h"
10 #include "core/css/resolver/StyleResolverState.h" 10 #include "core/css/resolver/StyleResolverState.h"
11 #include "core/style/BasicShapes.h" 11 #include "core/style/BasicShapes.h"
12 #include <memory> 12 #include <memory>
13 13
14 namespace blink { 14 namespace blink {
15 15
16 class BasicShapeNonInterpolableValue : public NonInterpolableValue { 16 class BasicShapeNonInterpolableValue : public NonInterpolableValue {
17 public: 17 public:
18 static PassRefPtr<NonInterpolableValue> create(BasicShape::ShapeType type) 18 static PassRefPtr<NonInterpolableValue> create(BasicShape::ShapeType type)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 std::unique_ptr<InterpolableValue> unwrap(InterpolationValue&& value) 76 std::unique_ptr<InterpolableValue> unwrap(InterpolationValue&& value)
77 { 77 {
78 DCHECK(value.interpolableValue); 78 DCHECK(value.interpolableValue);
79 return std::move(value.interpolableValue); 79 return std::move(value.interpolableValue);
80 } 80 }
81 81
82 std::unique_ptr<InterpolableValue> convertCSSCoordinate(const CSSValue* coordina te) 82 std::unique_ptr<InterpolableValue> convertCSSCoordinate(const CSSValue* coordina te)
83 { 83 {
84 if (coordinate) 84 if (coordinate)
85 return unwrap(CSSPositionAxisListInterpolationType::convertPositionAxisC SSValue(*coordinate)); 85 return unwrap(CSSPositionAxisListInterpolationType::convertPositionAxisC SSValue(*coordinate));
86 return unwrap(CSSLengthInterpolationType::maybeConvertLength(Length(50, Perc ent), 1)); 86 return unwrap(LengthInterpolationFunctions::maybeConvertLength(Length(50, Pe rcent), 1));
87 } 87 }
88 88
89 std::unique_ptr<InterpolableValue> convertCoordinate(const BasicShapeCenterCoord inate& coordinate, double zoom) 89 std::unique_ptr<InterpolableValue> convertCoordinate(const BasicShapeCenterCoord inate& coordinate, double zoom)
90 { 90 {
91 return unwrap(CSSLengthInterpolationType::maybeConvertLength(coordinate.comp utedLength(), zoom)); 91 return unwrap(LengthInterpolationFunctions::maybeConvertLength(coordinate.co mputedLength(), zoom));
92 } 92 }
93 93
94 std::unique_ptr<InterpolableValue> createNeutralInterpolableCoordinate() 94 std::unique_ptr<InterpolableValue> createNeutralInterpolableCoordinate()
95 { 95 {
96 return CSSLengthInterpolationType::createNeutralInterpolableValue(); 96 return LengthInterpolationFunctions::createNeutralInterpolableValue();
97 } 97 }
98 98
99 BasicShapeCenterCoordinate createCoordinate(const InterpolableValue& interpolabl eValue, const CSSToLengthConversionData& conversionData) 99 BasicShapeCenterCoordinate createCoordinate(const InterpolableValue& interpolabl eValue, const CSSToLengthConversionData& conversionData)
100 { 100 {
101 return BasicShapeCenterCoordinate( 101 return BasicShapeCenterCoordinate(
102 BasicShapeCenterCoordinate::TopLeft, 102 BasicShapeCenterCoordinate::TopLeft,
103 CSSLengthInterpolationType::createLength(interpolableValue, nullptr, con versionData)); 103 LengthInterpolationFunctions::createLength(interpolableValue, nullptr, c onversionData, ValueRangeAll));
104 } 104 }
105 105
106 std::unique_ptr<InterpolableValue> convertCSSRadius(const CSSPrimitiveValue* rad ius) 106 std::unique_ptr<InterpolableValue> convertCSSRadius(const CSSPrimitiveValue* rad ius)
107 { 107 {
108 if (!radius || radius->isValueID()) 108 if (!radius || radius->isValueID())
109 return nullptr; 109 return nullptr;
110 return unwrap(CSSLengthInterpolationType::maybeConvertCSSValue(*radius)); 110 return unwrap(LengthInterpolationFunctions::maybeConvertCSSValue(*radius));
111 } 111 }
112 112
113 std::unique_ptr<InterpolableValue> convertRadius(const BasicShapeRadius& radius, double zoom) 113 std::unique_ptr<InterpolableValue> convertRadius(const BasicShapeRadius& radius, double zoom)
114 { 114 {
115 if (radius.type() != BasicShapeRadius::Value) 115 if (radius.type() != BasicShapeRadius::Value)
116 return nullptr; 116 return nullptr;
117 return unwrap(CSSLengthInterpolationType::maybeConvertLength(radius.value(), zoom)); 117 return unwrap(LengthInterpolationFunctions::maybeConvertLength(radius.value( ), zoom));
118 } 118 }
119 119
120 std::unique_ptr<InterpolableValue> createNeutralInterpolableRadius() 120 std::unique_ptr<InterpolableValue> createNeutralInterpolableRadius()
121 { 121 {
122 return CSSLengthInterpolationType::createNeutralInterpolableValue(); 122 return LengthInterpolationFunctions::createNeutralInterpolableValue();
123 } 123 }
124 124
125 BasicShapeRadius createRadius(const InterpolableValue& interpolableValue, const CSSToLengthConversionData& conversionData) 125 BasicShapeRadius createRadius(const InterpolableValue& interpolableValue, const CSSToLengthConversionData& conversionData)
126 { 126 {
127 return BasicShapeRadius(CSSLengthInterpolationType::createLength(interpolabl eValue, nullptr, conversionData, ValueRangeNonNegative)); 127 return BasicShapeRadius(LengthInterpolationFunctions::createLength(interpola bleValue, nullptr, conversionData, ValueRangeNonNegative));
128 } 128 }
129 129
130 std::unique_ptr<InterpolableValue> convertCSSLength(const CSSValue* length) 130 std::unique_ptr<InterpolableValue> convertCSSLength(const CSSValue* length)
131 { 131 {
132 if (!length) 132 if (!length)
133 return CSSLengthInterpolationType::createNeutralInterpolableValue(); 133 return LengthInterpolationFunctions::createNeutralInterpolableValue();
134 return unwrap(CSSLengthInterpolationType::maybeConvertCSSValue(*length)); 134 return unwrap(LengthInterpolationFunctions::maybeConvertCSSValue(*length));
135 } 135 }
136 136
137 std::unique_ptr<InterpolableValue> convertLength(const Length& length, double zo om) 137 std::unique_ptr<InterpolableValue> convertLength(const Length& length, double zo om)
138 { 138 {
139 return unwrap(CSSLengthInterpolationType::maybeConvertLength(length, zoom)); 139 return unwrap(LengthInterpolationFunctions::maybeConvertLength(length, zoom) );
140 } 140 }
141 141
142 std::unique_ptr<InterpolableValue> convertCSSBorderRadiusWidth(const CSSValuePai r* pair) 142 std::unique_ptr<InterpolableValue> convertCSSBorderRadiusWidth(const CSSValuePai r* pair)
143 { 143 {
144 return convertCSSLength(pair ? &pair->first() : nullptr); 144 return convertCSSLength(pair ? &pair->first() : nullptr);
145 } 145 }
146 146
147 std::unique_ptr<InterpolableValue> convertCSSBorderRadiusHeight(const CSSValuePa ir* pair) 147 std::unique_ptr<InterpolableValue> convertCSSBorderRadiusHeight(const CSSValuePa ir* pair)
148 { 148 {
149 return convertCSSLength(pair ? &pair->second() : nullptr); 149 return convertCSSLength(pair ? &pair->second() : nullptr);
150 } 150 }
151 151
152 LengthSize createBorderRadius(const InterpolableValue& width, const Interpolable Value& height, const CSSToLengthConversionData& conversionData) 152 LengthSize createBorderRadius(const InterpolableValue& width, const Interpolable Value& height, const CSSToLengthConversionData& conversionData)
153 { 153 {
154 return LengthSize( 154 return LengthSize(
155 CSSLengthInterpolationType::createLength(width, nullptr, conversionData, ValueRangeNonNegative), 155 LengthInterpolationFunctions::createLength(width, nullptr, conversionDat a, ValueRangeNonNegative),
156 CSSLengthInterpolationType::createLength(height, nullptr, conversionData , ValueRangeNonNegative)); 156 LengthInterpolationFunctions::createLength(height, nullptr, conversionDa ta, ValueRangeNonNegative));
157 } 157 }
158 158
159 namespace CircleFunctions { 159 namespace CircleFunctions {
160 160
161 enum CircleComponentIndex : unsigned { 161 enum CircleComponentIndex : unsigned {
162 CircleCenterXIndex, 162 CircleCenterXIndex,
163 CircleCenterYIndex, 163 CircleCenterYIndex,
164 CircleRadiusIndex, 164 CircleRadiusIndex,
165 CircleComponentIndexCount, 165 CircleComponentIndexCount,
166 }; 166 };
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 list->set(InsetBorderBottomRightWidthIndex, convertLength(inset.bottomRightR adius().width(), zoom)); 333 list->set(InsetBorderBottomRightWidthIndex, convertLength(inset.bottomRightR adius().width(), zoom));
334 list->set(InsetBorderBottomRightHeightIndex, convertLength(inset.bottomRight Radius().height(), zoom)); 334 list->set(InsetBorderBottomRightHeightIndex, convertLength(inset.bottomRight Radius().height(), zoom));
335 list->set(InsetBorderBottomLeftWidthIndex, convertLength(inset.bottomLeftRad ius().width(), zoom)); 335 list->set(InsetBorderBottomLeftWidthIndex, convertLength(inset.bottomLeftRad ius().width(), zoom));
336 list->set(InsetBorderBottomLeftHeightIndex, convertLength(inset.bottomLeftRa dius().height(), zoom)); 336 list->set(InsetBorderBottomLeftHeightIndex, convertLength(inset.bottomLeftRa dius().height(), zoom));
337 return InterpolationValue(std::move(list), BasicShapeNonInterpolableValue::c reate(BasicShape::BasicShapeInsetType)); 337 return InterpolationValue(std::move(list), BasicShapeNonInterpolableValue::c reate(BasicShape::BasicShapeInsetType));
338 } 338 }
339 339
340 std::unique_ptr<InterpolableValue> createNeutralValue() 340 std::unique_ptr<InterpolableValue> createNeutralValue()
341 { 341 {
342 std::unique_ptr<InterpolableList> list = InterpolableList::create(InsetCompo nentIndexCount); 342 std::unique_ptr<InterpolableList> list = InterpolableList::create(InsetCompo nentIndexCount);
343 list->set(InsetTopIndex, CSSLengthInterpolationType::createNeutralInterpolab leValue()); 343 list->set(InsetTopIndex, LengthInterpolationFunctions::createNeutralInterpol ableValue());
344 list->set(InsetRightIndex, CSSLengthInterpolationType::createNeutralInterpol ableValue()); 344 list->set(InsetRightIndex, LengthInterpolationFunctions::createNeutralInterp olableValue());
345 list->set(InsetBottomIndex, CSSLengthInterpolationType::createNeutralInterpo lableValue()); 345 list->set(InsetBottomIndex, LengthInterpolationFunctions::createNeutralInter polableValue());
346 list->set(InsetLeftIndex, CSSLengthInterpolationType::createNeutralInterpola bleValue()); 346 list->set(InsetLeftIndex, LengthInterpolationFunctions::createNeutralInterpo lableValue());
347 347
348 list->set(InsetBorderTopLeftWidthIndex, CSSLengthInterpolationType::createNe utralInterpolableValue()); 348 list->set(InsetBorderTopLeftWidthIndex, LengthInterpolationFunctions::create NeutralInterpolableValue());
349 list->set(InsetBorderTopLeftHeightIndex, CSSLengthInterpolationType::createN eutralInterpolableValue()); 349 list->set(InsetBorderTopLeftHeightIndex, LengthInterpolationFunctions::creat eNeutralInterpolableValue());
350 list->set(InsetBorderTopRightWidthIndex, CSSLengthInterpolationType::createN eutralInterpolableValue()); 350 list->set(InsetBorderTopRightWidthIndex, LengthInterpolationFunctions::creat eNeutralInterpolableValue());
351 list->set(InsetBorderTopRightHeightIndex, CSSLengthInterpolationType::create NeutralInterpolableValue()); 351 list->set(InsetBorderTopRightHeightIndex, LengthInterpolationFunctions::crea teNeutralInterpolableValue());
352 list->set(InsetBorderBottomRightWidthIndex, CSSLengthInterpolationType::crea teNeutralInterpolableValue()); 352 list->set(InsetBorderBottomRightWidthIndex, LengthInterpolationFunctions::cr eateNeutralInterpolableValue());
353 list->set(InsetBorderBottomRightHeightIndex, CSSLengthInterpolationType::cre ateNeutralInterpolableValue()); 353 list->set(InsetBorderBottomRightHeightIndex, LengthInterpolationFunctions::c reateNeutralInterpolableValue());
354 list->set(InsetBorderBottomLeftWidthIndex, CSSLengthInterpolationType::creat eNeutralInterpolableValue()); 354 list->set(InsetBorderBottomLeftWidthIndex, LengthInterpolationFunctions::cre ateNeutralInterpolableValue());
355 list->set(InsetBorderBottomLeftHeightIndex, CSSLengthInterpolationType::crea teNeutralInterpolableValue()); 355 list->set(InsetBorderBottomLeftHeightIndex, LengthInterpolationFunctions::cr eateNeutralInterpolableValue());
356 return std::move(list); 356 return std::move(list);
357 } 357 }
358 358
359 PassRefPtr<BasicShape> createBasicShape(const InterpolableValue& interpolableVal ue, const CSSToLengthConversionData& conversionData) 359 PassRefPtr<BasicShape> createBasicShape(const InterpolableValue& interpolableVal ue, const CSSToLengthConversionData& conversionData)
360 { 360 {
361 RefPtr<BasicShapeInset> inset = BasicShapeInset::create(); 361 RefPtr<BasicShapeInset> inset = BasicShapeInset::create();
362 const InterpolableList& list = toInterpolableList(interpolableValue); 362 const InterpolableList& list = toInterpolableList(interpolableValue);
363 inset->setTop(CSSLengthInterpolationType::createLength(*list.get(InsetTopInd ex), nullptr, conversionData)); 363 inset->setTop(LengthInterpolationFunctions::createLength(*list.get(InsetTopI ndex), nullptr, conversionData, ValueRangeAll));
364 inset->setRight(CSSLengthInterpolationType::createLength(*list.get(InsetRigh tIndex), nullptr, conversionData)); 364 inset->setRight(LengthInterpolationFunctions::createLength(*list.get(InsetRi ghtIndex), nullptr, conversionData, ValueRangeAll));
365 inset->setBottom(CSSLengthInterpolationType::createLength(*list.get(InsetBot tomIndex), nullptr, conversionData)); 365 inset->setBottom(LengthInterpolationFunctions::createLength(*list.get(InsetB ottomIndex), nullptr, conversionData, ValueRangeAll));
366 inset->setLeft(CSSLengthInterpolationType::createLength(*list.get(InsetLeftI ndex), nullptr, conversionData)); 366 inset->setLeft(LengthInterpolationFunctions::createLength(*list.get(InsetLef tIndex), nullptr, conversionData, ValueRangeAll));
367 367
368 inset->setTopLeftRadius(createBorderRadius(*list.get(InsetBorderTopLeftWidth Index), *list.get(InsetBorderTopLeftHeightIndex), conversionData)); 368 inset->setTopLeftRadius(createBorderRadius(*list.get(InsetBorderTopLeftWidth Index), *list.get(InsetBorderTopLeftHeightIndex), conversionData));
369 inset->setTopRightRadius(createBorderRadius(*list.get(InsetBorderTopRightWid thIndex), *list.get(InsetBorderTopRightHeightIndex), conversionData)); 369 inset->setTopRightRadius(createBorderRadius(*list.get(InsetBorderTopRightWid thIndex), *list.get(InsetBorderTopRightHeightIndex), conversionData));
370 inset->setBottomRightRadius(createBorderRadius(*list.get(InsetBorderBottomRi ghtWidthIndex), *list.get(InsetBorderBottomRightHeightIndex), conversionData)); 370 inset->setBottomRightRadius(createBorderRadius(*list.get(InsetBorderBottomRi ghtWidthIndex), *list.get(InsetBorderBottomRightHeightIndex), conversionData));
371 inset->setBottomLeftRadius(createBorderRadius(*list.get(InsetBorderBottomLef tWidthIndex), *list.get(InsetBorderBottomLeftHeightIndex), conversionData)); 371 inset->setBottomLeftRadius(createBorderRadius(*list.get(InsetBorderBottomLef tWidthIndex), *list.get(InsetBorderBottomLeftHeightIndex), conversionData));
372 return inset.release(); 372 return inset.release();
373 } 373 }
374 374
375 } // namespace InsetFunctions 375 } // namespace InsetFunctions
376 376
(...skipping 14 matching lines...) Expand all
391 std::unique_ptr<InterpolableList> list = InterpolableList::create(size); 391 std::unique_ptr<InterpolableList> list = InterpolableList::create(size);
392 for (size_t i = 0; i < size; i++) 392 for (size_t i = 0; i < size; i++)
393 list->set(i, convertLength(polygon.values()[i], zoom)); 393 list->set(i, convertLength(polygon.values()[i], zoom));
394 return InterpolationValue(std::move(list), BasicShapeNonInterpolableValue::c reatePolygon(polygon.getWindRule(), size)); 394 return InterpolationValue(std::move(list), BasicShapeNonInterpolableValue::c reatePolygon(polygon.getWindRule(), size));
395 } 395 }
396 396
397 std::unique_ptr<InterpolableValue> createNeutralValue(const BasicShapeNonInterpo lableValue& nonInterpolableValue) 397 std::unique_ptr<InterpolableValue> createNeutralValue(const BasicShapeNonInterpo lableValue& nonInterpolableValue)
398 { 398 {
399 std::unique_ptr<InterpolableList> list = InterpolableList::create(nonInterpo lableValue.size()); 399 std::unique_ptr<InterpolableList> list = InterpolableList::create(nonInterpo lableValue.size());
400 for (size_t i = 0; i < nonInterpolableValue.size(); i++) 400 for (size_t i = 0; i < nonInterpolableValue.size(); i++)
401 list->set(i, CSSLengthInterpolationType::createNeutralInterpolableValue( )); 401 list->set(i, LengthInterpolationFunctions::createNeutralInterpolableValu e());
402 return std::move(list); 402 return std::move(list);
403 } 403 }
404 404
405 PassRefPtr<BasicShape> createBasicShape(const InterpolableValue& interpolableVal ue, const BasicShapeNonInterpolableValue& nonInterpolableValue, const CSSToLengt hConversionData& conversionData) 405 PassRefPtr<BasicShape> createBasicShape(const InterpolableValue& interpolableVal ue, const BasicShapeNonInterpolableValue& nonInterpolableValue, const CSSToLengt hConversionData& conversionData)
406 { 406 {
407 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create(); 407 RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create();
408 polygon->setWindRule(nonInterpolableValue.windRule()); 408 polygon->setWindRule(nonInterpolableValue.windRule());
409 const InterpolableList& list = toInterpolableList(interpolableValue); 409 const InterpolableList& list = toInterpolableList(interpolableValue);
410 size_t size = nonInterpolableValue.size(); 410 size_t size = nonInterpolableValue.size();
411 DCHECK_EQ(list.length(), size); 411 DCHECK_EQ(list.length(), size);
412 DCHECK_EQ(size % 2, 0U); 412 DCHECK_EQ(size % 2, 0U);
413 for (size_t i = 0; i < size; i += 2) { 413 for (size_t i = 0; i < size; i += 2) {
414 polygon->appendPoint( 414 polygon->appendPoint(
415 CSSLengthInterpolationType::createLength(*list.get(i), nullptr, conv ersionData), 415 LengthInterpolationFunctions::createLength(*list.get(i), nullptr, co nversionData, ValueRangeAll),
416 CSSLengthInterpolationType::createLength(*list.get(i + 1), nullptr, conversionData)); 416 LengthInterpolationFunctions::createLength(*list.get(i + 1), nullptr , conversionData, ValueRangeAll));
417 } 417 }
418 return polygon.release(); 418 return polygon.release();
419 } 419 }
420 420
421 } // namespace PolygonFunctions 421 } // namespace PolygonFunctions
422 422
423 } // namespace 423 } // namespace
424 424
425 InterpolationValue BasicShapeInterpolationFunctions::maybeConvertCSSValue(const CSSValue& value) 425 InterpolationValue BasicShapeInterpolationFunctions::maybeConvertCSSValue(const CSSValue& value)
426 { 426 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 return InsetFunctions::createBasicShape(interpolableValue, conversionDat a); 489 return InsetFunctions::createBasicShape(interpolableValue, conversionDat a);
490 case BasicShape::BasicShapePolygonType: 490 case BasicShape::BasicShapePolygonType:
491 return PolygonFunctions::createBasicShape(interpolableValue, nonInterpol ableValue, conversionData); 491 return PolygonFunctions::createBasicShape(interpolableValue, nonInterpol ableValue, conversionData);
492 default: 492 default:
493 NOTREACHED(); 493 NOTREACHED();
494 return nullptr; 494 return nullptr;
495 } 495 }
496 } 496 }
497 497
498 } // namespace blink 498 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698