From fee5771921b6f93f36a3b102c30b3711db8b7b5b Mon Sep 17 00:00:00 2001 From: meade Date: Wed, 2 Mar 2016 20:52:20 -0800 Subject: Add a StyleValueFactory that converts CSSValues to StyleValues. BUG=545318 Review URL: https://codereview.chromium.org/1752173002 Cr-Commit-Position: refs/heads/master@{#378958} --- third_party/WebKit/Source/core/core.gypi | 2 ++ .../WebKit/Source/core/css/cssom/StyleValue.cpp | 7 +----- .../WebKit/Source/core/css/cssom/StyleValue.h | 1 - .../Source/core/css/cssom/StyleValueFactory.cpp | 25 ++++++++++++++++++++++ .../Source/core/css/cssom/StyleValueFactory.h | 25 ++++++++++++++++++++++ 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp create mode 100644 third_party/WebKit/Source/core/css/cssom/StyleValueFactory.h diff --git a/third_party/WebKit/Source/core/core.gypi b/third_party/WebKit/Source/core/core.gypi index 4b1018d..27c2390 100644 --- a/third_party/WebKit/Source/core/core.gypi +++ b/third_party/WebKit/Source/core/core.gypi @@ -1320,6 +1320,8 @@ 'css/cssom/StylePropertyMap.h', 'css/cssom/StyleValue.cpp', 'css/cssom/StyleValue.h', + 'css/cssom/StyleValueFactory.cpp', + 'css/cssom/StyleValueFactory.h', 'css/cssom/TransformComponent.h', 'css/cssom/TransformValue.cpp', 'css/cssom/TransformValue.h', diff --git a/third_party/WebKit/Source/core/css/cssom/StyleValue.cpp b/third_party/WebKit/Source/core/css/cssom/StyleValue.cpp index e91a459..4b168d6 100644 --- a/third_party/WebKit/Source/core/css/cssom/StyleValue.cpp +++ b/third_party/WebKit/Source/core/css/cssom/StyleValue.cpp @@ -5,15 +5,10 @@ #include "core/css/cssom/StyleValue.h" #include "bindings/core/v8/ScriptValue.h" +#include "core/css/cssom/SimpleLength.h" namespace blink { -StyleValue* StyleValue::create(const CSSValue& val) -{ - // TODO: implement. - return nullptr; -} - ScriptValue StyleValue::parse(ScriptState* state, const String& property, const String& cssText) { // TODO: implement. diff --git a/third_party/WebKit/Source/core/css/cssom/StyleValue.h b/third_party/WebKit/Source/core/css/cssom/StyleValue.h index 9f90924..726518b 100644 --- a/third_party/WebKit/Source/core/css/cssom/StyleValue.h +++ b/third_party/WebKit/Source/core/css/cssom/StyleValue.h @@ -27,7 +27,6 @@ public: virtual StyleValueType type() const = 0; - static StyleValue* create(const CSSValue&); static ScriptValue parse(ScriptState*, const String& property, const String& cssText); virtual PassRefPtrWillBeRawPtr toCSSValue() const = 0; diff --git a/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp new file mode 100644 index 0000000..2a0a0a7 --- /dev/null +++ b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp @@ -0,0 +1,25 @@ +// 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/css/cssom/StyleValueFactory.h" + +#include "core/css/CSSValue.h" +#include "core/css/cssom/SimpleLength.h" +#include "core/css/cssom/StyleValue.h" + +namespace blink { + +StyleValue* StyleValueFactory::create(CSSPropertyID propertyID, const CSSValue& value) +{ + if (value.isPrimitiveValue()) { + const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); + if (primitiveValue.isLength() && !primitiveValue.isCalculated()) { + return SimpleLength::create(primitiveValue.getDoubleValue(), primitiveValue.typeWithCalcResolved()); + } + } + // TODO(meade): Implement the rest. + return nullptr; +} + +} // namespace blink diff --git a/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.h b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.h new file mode 100644 index 0000000..36a4437 --- /dev/null +++ b/third_party/WebKit/Source/core/css/cssom/StyleValueFactory.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef StyleValueFactory_h +#define StyleValueFactory_h + +#include "core/CSSPropertyNames.h" +#include "wtf/Allocator.h" + +namespace blink { + +class CSSValue; +class StyleValue; + +class StyleValueFactory { + STATIC_ONLY(StyleValueFactory); + +public: + static StyleValue* create(CSSPropertyID, const CSSValue&); +}; + +} // namespace blink + +#endif -- cgit v1.1