Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp |
| diff --git a/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp |
| index 0c930d29eb22acbf5d4e0eb2ff7b648a6380b46b..fe3036c67cd2444cba7ebbfb76931cb8f56f8a7c 100644 |
| --- a/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp |
| +++ b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp |
| @@ -6,6 +6,8 @@ |
| #include "core/css/CSSImageValue.h" |
| #include "core/css/CSSValue.h" |
| +#include "core/css/cssom/CSSCalcLength.h" |
| +#include "core/css/cssom/CSSKeywordValue.h" |
| #include "core/css/cssom/CSSNumberValue.h" |
| #include "core/css/cssom/CSSSimpleLength.h" |
| #include "core/css/cssom/CSSStyleValue.h" |
| @@ -49,6 +51,57 @@ CSSStyleValue* styleValueForProperty(CSSPropertyID propertyID, const CSSValue& v |
| return nullptr; |
| } |
| +const Length* getLengthFromStyle(CSSPropertyID propertyID, const ComputedStyle* style) |
| +{ |
| + switch (propertyID) { |
| + case CSSPropertyLeft: |
| + return &(style->left()); |
| + case CSSPropertyRight: |
| + return &(style->right()); |
| + case CSSPropertyTop: |
| + return &(style->top()); |
| + case CSSPropertyBottom: |
| + return &(style->bottom()); |
| + case CSSPropertyHeight: |
| + return &(style->height()); |
| + case CSSPropertyWidth: |
| + return &(style->width()); |
| + default: |
| + break; |
| + } |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| +CSSStyleValue* styleValueForProperty(CSSPropertyID propertyID, const ComputedStyle* style) |
|
meade_UTC10
2016/09/09 01:56:27
Would it make more sense for this to be a series o
|
| +{ |
| + switch (propertyID) { |
| + case CSSPropertyLeft: |
| + case CSSPropertyRight: |
| + case CSSPropertyTop: |
| + case CSSPropertyBottom: |
| + case CSSPropertyHeight: |
| + case CSSPropertyWidth: { |
| + const Length* length = getLengthFromStyle(propertyID, style); |
| + if (length->isAuto()) { |
| + return new CSSKeywordValue("auto"); |
| + } |
| + if (length->isFixed()) { |
| + return CSSSimpleLength::create(length->pixels(), CSSPrimitiveValue::UnitType::Pixels); |
| + } |
| + if (length->isPercent()) { |
| + return CSSSimpleLength::create(length->percent(), CSSPrimitiveValue::UnitType::Percentage); |
| + } |
| + if (length->isCalculated()) { |
| + return CSSCalcLength::fromLength(length); |
| + } |
| + NOTREACHED(); |
| + } |
| + default: |
| + return nullptr; |
| + } |
| +} |
| + |
| CSSStyleValueVector unsupportedCSSValue(const CSSValue& value) |
| { |
| CSSStyleValueVector styleValueVector; |
| @@ -83,4 +136,13 @@ CSSStyleValueVector StyleValueFactory::cssValueToStyleValueVector(CSSPropertyID |
| return styleValueVector; |
| } |
| +// TODO: Renee: Add checks as in cssValueToStyleValueVector. |
| +CSSStyleValueVector StyleValueFactory::computedStyleToStyleValueVector(CSSPropertyID propertyID, const ComputedStyle* style) |
| +{ |
| + CSSStyleValueVector styleValueVector; |
| + CSSStyleValue* styleValue = styleValueForProperty(propertyID, style); |
| + styleValueVector.append(styleValue); |
| + return styleValueVector; |
| +} |
| + |
| } // namespace blink |