Chromium Code Reviews| Index: third_party/WebKit/Source/core/animation/SizeListPropertyFunctions.cpp |
| diff --git a/third_party/WebKit/Source/core/animation/SizeListPropertyFunctions.cpp b/third_party/WebKit/Source/core/animation/SizeListPropertyFunctions.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1308cc4d4e994a02a4059a454f1d41de48b49d6f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/animation/SizeListPropertyFunctions.cpp |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/animation/SizeListPropertyFunctions.h" |
| + |
| +#include "core/style/ComputedStyle.h" |
| + |
| +namespace blink { |
| + |
| +static const FillLayer* getFillLayer(CSSPropertyID property, const ComputedStyle& style) |
| +{ |
| + switch (property) { |
| + case CSSPropertyBackgroundSize: |
| + return &style.backgroundLayers(); |
| + case CSSPropertyWebkitMaskSize: |
| + return &style.maskLayers(); |
| + default: |
| + NOTREACHED(); |
| + return nullptr; |
| + } |
| +} |
| + |
| +static FillLayer* accessFillLayer(CSSPropertyID property, ComputedStyle& style) |
| +{ |
| + switch (property) { |
| + case CSSPropertyBackgroundSize: |
| + return &style.accessBackgroundLayers(); |
| + case CSSPropertyWebkitMaskSize: |
| + return &style.accessMaskLayers(); |
| + default: |
| + NOTREACHED(); |
| + return nullptr; |
| + } |
| +} |
| + |
| +SizeList SizeListPropertyFunctions::getInitialSizeList(CSSPropertyID property) |
| +{ |
| + return getSizeList(property, ComputedStyle::initialStyle()); |
| +} |
| + |
| +SizeList SizeListPropertyFunctions::getSizeList(CSSPropertyID property, const ComputedStyle& style) |
| +{ |
| + SizeList result; |
| + for (const FillLayer* fillLayer = getFillLayer(property, style); fillLayer && fillLayer->isSizeSet(); fillLayer = fillLayer->next()) |
|
Eric Willigers
2016/08/31 01:47:06
We stop when we hit a fillLayer with size not set,
alancutter (OOO until 2018)
2016/09/05 07:44:27
Yes. Unset/nullptr indicates the end of the list.
|
| + result.append(fillLayer->size()); |
| + return result; |
| +} |
| + |
| +void SizeListPropertyFunctions::setSizeList(CSSPropertyID property, ComputedStyle& style, SizeList& sizeList) |
| +{ |
| + FillLayer* fillLayer = accessFillLayer(property, style); |
| + FillLayer* prev = nullptr; |
| + for (const FillSize& size : sizeList) { |
| + if (!fillLayer) |
| + fillLayer = prev->ensureNext(); |
| + fillLayer->setSize(size); |
| + prev = fillLayer; |
| + fillLayer = fillLayer->next(); |
| + } |
| + while (fillLayer) { |
| + fillLayer->clearSize(); |
| + fillLayer = fillLayer->next(); |
| + } |
| +} |
| + |
| +} // namespace blink |