Commit 46232054 authored by Adam Raine's avatar Adam Raine Committed by Commit Bot

Add Color specific CSSStyleValue

To composite color values cross thread, we must have a specific
CrossThreadColorValue, and the only way to know if a CSSStyleValue holds
a color value is to create a new color specific style value.  This patch
adds a new class CSSColorStyleValue for this purpose.

Bug: 883721
Change-Id: I83472ffd26bf2eba3312b8578e81222f61bd17c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717189
Commit-Queue: Adam Raine <asraine@google.com>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681317}
parent e625a57d
......@@ -274,6 +274,8 @@ blink_core_sources("css") {
"cssom/css_unit_values.h",
"cssom/css_unparsed_value.cc",
"cssom/css_unparsed_value.h",
"cssom/css_unsupported_color_value.cc",
"cssom/css_unsupported_color_value.h",
"cssom/css_unsupported_style_value.cc",
"cssom/css_unsupported_style_value.h",
"cssom/css_url_image_value.cc",
......@@ -605,6 +607,7 @@ blink_core_tests("unit_tests") {
"cssom/css_style_image_value_test.cc",
"cssom/css_unit_value_test.cc",
"cssom/css_unparsed_value_test.cc",
"cssom/css_unsupported_color_value_test.cc",
"cssom/paint_worklet_style_property_map_test.cc",
"cssom/prepopulated_computed_style_property_map_test.cc",
"drag_update_test.cc",
......
......@@ -17,7 +17,7 @@ class CSSValuePool;
namespace cssvalue {
// Represents the non-keyword subset of <color>.
class CSSColorValue : public CSSValue {
class CORE_EXPORT CSSColorValue : public CSSValue {
public:
// TODO(sashab): Make this create() method take a Color instead.
static CSSColorValue* Create(RGBA32 color);
......
......@@ -45,6 +45,7 @@ class CORE_EXPORT CSSStyleValue : public ScriptWrappable {
kTransformType,
kPositionType,
kURLImageType,
kUnsupportedColorType,
};
static CSSStyleValue* parse(const ExecutionContext*,
......
// Copyright 2019 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 "third_party/blink/renderer/core/css/cssom/css_unsupported_color_value.h"
#include "third_party/blink/renderer/core/css/css_color_value.h"
#include "third_party/blink/renderer/core/css/css_custom_ident_value.h"
#include "third_party/blink/renderer/core/css/css_identifier_value.h"
#include "third_party/blink/renderer/core/css/css_inherited_value.h"
#include "third_party/blink/renderer/core/css/css_initial_value.h"
#include "third_party/blink/renderer/core/css/css_unset_value.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
namespace blink {
CSSUnsupportedColorValue* CSSUnsupportedColorValue::Create(Color color) {
return MakeGarbageCollected<CSSUnsupportedColorValue>(color);
}
CSSUnsupportedColorValue* CSSUnsupportedColorValue::Create(
const CSSPropertyName& name,
Color color) {
return MakeGarbageCollected<CSSUnsupportedColorValue>(name, color);
}
CSSUnsupportedColorValue* CSSUnsupportedColorValue::FromCSSValue(
const cssvalue::CSSColorValue& color_value) {
return MakeGarbageCollected<CSSUnsupportedColorValue>(color_value.Value());
}
Color CSSUnsupportedColorValue::Value() const {
return color_value_;
}
const CSSValue* CSSUnsupportedColorValue::ToCSSValue() const {
return cssvalue::CSSColorValue::Create(
MakeRGBA(color_value_.Red(), color_value_.Green(), color_value_.Blue(),
color_value_.Alpha()));
}
} // namespace blink
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_COLOR_VALUE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_COLOR_VALUE_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_color_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unsupported_style_value.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
// CSSUnsupportedColorValue represents all color values that are normally
// treated as CSSUnsupportedValue. When compositing color values cross thread,
// this class can be used to differentiate between color values and other types
// that use CSSUnsupportedStyleValue.
class CORE_EXPORT CSSUnsupportedColorValue final
: public CSSUnsupportedStyleValue {
public:
static CSSUnsupportedColorValue* Create(Color color);
static CSSUnsupportedColorValue* Create(const CSSPropertyName& name,
Color color);
static CSSUnsupportedColorValue* FromCSSValue(const cssvalue::CSSColorValue&);
explicit CSSUnsupportedColorValue(Color color)
: CSSUnsupportedStyleValue(
cssvalue::CSSColorValue::SerializeAsCSSComponentValue(color)),
color_value_(color) {}
explicit CSSUnsupportedColorValue(const CSSPropertyName& name, Color color)
: CSSUnsupportedStyleValue(
name,
cssvalue::CSSColorValue::SerializeAsCSSComponentValue(color)),
color_value_(color) {}
StyleValueType GetType() const override { return kUnsupportedColorType; }
Color Value() const;
const CSSValue* ToCSSValue() const override;
private:
Color color_value_;
DISALLOW_COPY_AND_ASSIGN(CSSUnsupportedColorValue);
};
template <>
struct DowncastTraits<CSSUnsupportedColorValue> {
static bool AllowFrom(const CSSStyleValue& value) {
return value.GetType() ==
CSSStyleValue::StyleValueType::kUnsupportedColorType;
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_COLOR_VALUE_H_
// Copyright 2019 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 "third_party/blink/renderer/core/css/cssom/css_unsupported_color_value.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
TEST(CSSUnsupportedColorValueTest, CreateColorStyleValue) {
CSSStyleValue* style_value =
CSSUnsupportedColorValue::Create(Color(0, 255, 0));
EXPECT_EQ(style_value->GetType(),
CSSStyleValue::StyleValueType::kUnsupportedColorType);
EXPECT_TRUE(DynamicTo<CSSUnsupportedStyleValue>(style_value));
CSSUnsupportedColorValue* color_value =
DynamicTo<CSSUnsupportedColorValue>(style_value);
EXPECT_TRUE(color_value);
EXPECT_EQ(color_value->Value(), Color(0, 255, 0));
}
TEST(CSSUnsupportedColorValueTest, ColorStyleValueToString) {
CSSUnsupportedColorValue* style_value =
CSSUnsupportedColorValue::Create(Color(0, 255, 0));
EXPECT_TRUE(style_value);
EXPECT_EQ(
style_value->toString(),
cssvalue::CSSColorValue::SerializeAsCSSComponentValue(Color(0, 255, 0)));
}
} // namespace blink
......@@ -24,7 +24,7 @@ namespace blink {
// * Tied to no CSS property at all, in which case it's not valid for any
// property.
class CORE_EXPORT CSSUnsupportedStyleValue final : public CSSStyleValue {
class CORE_EXPORT CSSUnsupportedStyleValue : public CSSStyleValue {
public:
static CSSUnsupportedStyleValue* Create(const CSSValue& value) {
return MakeGarbageCollected<CSSUnsupportedStyleValue>(value.CssText());
......@@ -70,7 +70,9 @@ class CORE_EXPORT CSSUnsupportedStyleValue final : public CSSStyleValue {
template <>
struct DowncastTraits<CSSUnsupportedStyleValue> {
static bool AllowFrom(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::StyleValueType::kUnknownType;
return value.GetType() == CSSStyleValue::StyleValueType::kUnknownType ||
value.GetType() ==
CSSStyleValue::StyleValueType::kUnsupportedColorType;
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment