Commit 0a7ee900 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

Make StylePropertyMapReadOnly a pure interface

This CL is implementing the Phase 1 described in this doc:
https://docs.google.com/document/d/1v-k8Ck7x_2kpBfgaVmqg2NvQRvD1PqyOt50rdO141Wc/edit#

Basically, it redefines the StylePropertyMapReadOnly to be a pure
interface. Then it renames the existing StylePropertyMapReadOnly to
StylePropertyMapReadOnlyMainThread. Then it makes all subclasses of
StylePropertyMapReadOnly to be subclasses of
StylePropertyMapReadOnlyMainThread.

This CL should not introduce any behavior change.

Bug: 895579
Change-Id: I400981d1745ab3ee80b9ba9b77c3e3406cd0c1e7
Reviewed-on: https://chromium-review.googlesource.com/c/1354118
Commit-Queue: Xida Chen <xidachen@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612216}
parent 5096e619
......@@ -264,8 +264,9 @@ blink_core_sources("css") {
"cssom/prepopulated_computed_style_property_map.h",
"cssom/style_property_map.cc",
"cssom/style_property_map.h",
"cssom/style_property_map_read_only.cc",
"cssom/style_property_map_read_only.h",
"cssom/style_property_map_read_only_main_thread.cc",
"cssom/style_property_map_read_only_main_thread.h",
"cssom/style_value_factory.cc",
"cssom/style_value_factory.h",
"document_style_environment_variables.cc",
......
......@@ -8,7 +8,7 @@
#include "base/macros.h"
#include "third_party/blink/renderer/core/css/css_computed_style_declaration.h"
#include "third_party/blink/renderer/core/css/css_selector.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only_main_thread.h"
#include "third_party/blink/renderer/core/dom/node.h"
namespace blink {
......@@ -17,11 +17,13 @@ namespace blink {
// API. The specification is here:
// https://drafts.css-houdini.org/css-typed-om/#computed-StylePropertyMapReadOnly-objects
//
// The computed StylePropertyMapReadOnly retrieves computed styles and returns
// them as CSSStyleValues. The IDL for this class is in StylePropertyMap.idl.
// The computed StylePropertyMapReadOnly for an element is accessed via
// element.computedStyleMap() (see ElementComputedStyleMap.idl/h)
class CORE_EXPORT ComputedStylePropertyMap : public StylePropertyMapReadOnly {
// The computed StylePropertyMapReadOnlyMainThread retrieves computed styles and
// returns them as CSSStyleValues. The IDL for this class is in
// StylePropertyMap.idl. The computed StylePropertyMapReadOnlyMainThread for an
// element is accessed via element.computedStyleMap() (see
// ElementComputedStyleMap.idl/h)
class CORE_EXPORT ComputedStylePropertyMap
: public StylePropertyMapReadOnlyMainThread {
public:
static ComputedStylePropertyMap* Create(Node* node) {
return new ComputedStylePropertyMap(node);
......@@ -29,7 +31,7 @@ class CORE_EXPORT ComputedStylePropertyMap : public StylePropertyMapReadOnly {
void Trace(blink::Visitor* visitor) override {
visitor->Trace(node_);
StylePropertyMapReadOnly::Trace(visitor);
StylePropertyMapReadOnlyMainThread::Trace(visitor);
}
unsigned int size() override;
......@@ -41,7 +43,7 @@ class CORE_EXPORT ComputedStylePropertyMap : public StylePropertyMapReadOnly {
protected:
ComputedStylePropertyMap(Node* node, const String& pseudo_element = String())
: StylePropertyMapReadOnly(),
: StylePropertyMapReadOnlyMainThread(),
pseudo_id_(CSSSelector::ParsePseudoId(pseudo_element)),
node_(node) {}
......
......@@ -21,7 +21,7 @@ PrepopulatedComputedStylePropertyMap::PrepopulatedComputedStylePropertyMap(
Node* styled_node,
const Vector<CSSPropertyID>& native_properties,
const Vector<AtomicString>& custom_properties)
: StylePropertyMapReadOnly(), styled_node_(styled_node) {
: StylePropertyMapReadOnlyMainThread(), styled_node_(styled_node) {
// NOTE: This may over-reserve as shorthand properties will get dropped from
// being in the map.
native_values_.ReserveCapacityForSize(native_properties.size());
......@@ -128,7 +128,7 @@ void PrepopulatedComputedStylePropertyMap::Trace(blink::Visitor* visitor) {
visitor->Trace(styled_node_);
visitor->Trace(native_values_);
visitor->Trace(custom_values_);
StylePropertyMapReadOnly::Trace(visitor);
StylePropertyMapReadOnlyMainThread::Trace(visitor);
}
} // namespace blink
......@@ -7,7 +7,7 @@
#include "base/macros.h"
#include "third_party/blink/renderer/core/css/css_property_id_templates.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only_main_thread.h"
namespace blink {
......@@ -24,7 +24,7 @@ class ComputedStyle;
// result when the ComputedStyle changes UpdateStyle needs to be called to
// re-populate the internal maps.
class CORE_EXPORT PrepopulatedComputedStylePropertyMap
: public StylePropertyMapReadOnly {
: public StylePropertyMapReadOnlyMainThread {
public:
// NOTE: styled_node may be null, in the case where this map is for an
// anonymous box.
......
......@@ -7,7 +7,7 @@
#include "base/macros.h"
#include "third_party/blink/renderer/bindings/core/v8/css_style_value_or_string.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only_main_thread.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
namespace blink {
......@@ -15,7 +15,7 @@ namespace blink {
class ExceptionState;
class ExecutionContext;
class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadOnly {
class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadOnlyMainThread {
DEFINE_WRAPPERTYPEINFO();
public:
......
......@@ -14,52 +14,23 @@
namespace blink {
class CSSProperty;
class CORE_EXPORT StylePropertyMapReadOnly
: public ScriptWrappable,
public PairIterable<String, CSSStyleValueVector> {
DEFINE_WRAPPERTYPEINFO();
public:
using StylePropertyMapEntry = std::pair<String, CSSStyleValueVector>;
~StylePropertyMapReadOnly() override = default;
CSSStyleValue* get(const ExecutionContext*,
const String& property_name,
ExceptionState&);
CSSStyleValueVector getAll(const ExecutionContext*,
virtual CSSStyleValue* get(const ExecutionContext*,
const String& property_name,
ExceptionState&);
bool has(const ExecutionContext*,
const String& property_name,
ExceptionState&);
ExceptionState&) = 0;
virtual CSSStyleValueVector getAll(const ExecutionContext*,
const String& property_name,
ExceptionState&) = 0;
virtual bool has(const ExecutionContext*,
const String& property_name,
ExceptionState&) = 0;
virtual unsigned int size() = 0;
protected:
StylePropertyMapReadOnly() = default;
virtual const CSSValue* GetProperty(CSSPropertyID) = 0;
virtual const CSSValue* GetCustomProperty(AtomicString) = 0;
using IterationCallback =
std::function<void(const AtomicString&, const CSSValue&)>;
virtual void ForEachProperty(const IterationCallback&) = 0;
virtual String SerializationForShorthand(const CSSProperty&) = 0;
const CSSValue* GetCustomProperty(const ExecutionContext&,
const AtomicString&);
private:
IterationSource* StartIteration(ScriptState*, ExceptionState&) override;
CSSStyleValue* GetShorthandProperty(const CSSProperty&);
private:
DISALLOW_COPY_AND_ASSIGN(StylePropertyMapReadOnly);
};
} // namespace blink
......
// Copyright 2016 the chromium authors. All rights reserved.
// Copyright 2018 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/style_property_map_read_only.h"
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only_main_thread.h"
#include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
......@@ -26,7 +26,8 @@ class StylePropertyMapIterationSource final
: public PairIterable<String, CSSStyleValueVector>::IterationSource {
public:
explicit StylePropertyMapIterationSource(
HeapVector<StylePropertyMapReadOnly::StylePropertyMapEntry> values)
HeapVector<StylePropertyMapReadOnlyMainThread::StylePropertyMapEntry>
values)
: index_(0), values_(values) {}
bool Next(ScriptState*,
......@@ -36,7 +37,7 @@ class StylePropertyMapIterationSource final
if (index_ >= values_.size())
return false;
const StylePropertyMapReadOnly::StylePropertyMapEntry& pair =
const StylePropertyMapReadOnlyMainThread::StylePropertyMapEntry& pair =
values_.at(index_++);
key = pair.first;
value = pair.second;
......@@ -50,12 +51,13 @@ class StylePropertyMapIterationSource final
private:
wtf_size_t index_;
const HeapVector<StylePropertyMapReadOnly::StylePropertyMapEntry> values_;
const HeapVector<StylePropertyMapReadOnlyMainThread::StylePropertyMapEntry>
values_;
};
} // namespace
CSSStyleValue* StylePropertyMapReadOnly::get(
CSSStyleValue* StylePropertyMapReadOnlyMainThread::get(
const ExecutionContext* execution_context,
const String& property_name,
ExceptionState& exception_state) {
......@@ -93,7 +95,7 @@ CSSStyleValue* StylePropertyMapReadOnly::get(
custom_property_name, *value);
}
CSSStyleValueVector StylePropertyMapReadOnly::getAll(
CSSStyleValueVector StylePropertyMapReadOnlyMainThread::getAll(
const ExecutionContext* execution_context,
const String& property_name,
ExceptionState& exception_state) {
......@@ -127,13 +129,14 @@ CSSStyleValueVector StylePropertyMapReadOnly::getAll(
property_id, custom_property_name, *value);
}
bool StylePropertyMapReadOnly::has(const ExecutionContext* execution_context,
const String& property_name,
ExceptionState& exception_state) {
bool StylePropertyMapReadOnlyMainThread::has(
const ExecutionContext* execution_context,
const String& property_name,
ExceptionState& exception_state) {
return !getAll(execution_context, property_name, exception_state).IsEmpty();
}
const CSSValue* StylePropertyMapReadOnly::GetCustomProperty(
const CSSValue* StylePropertyMapReadOnlyMainThread::GetCustomProperty(
const ExecutionContext& execution_context,
const AtomicString& property_name) {
const CSSValue* value = GetCustomProperty(property_name);
......@@ -145,10 +148,10 @@ const CSSValue* StylePropertyMapReadOnly::GetCustomProperty(
return PropertyRegistry::ParseIfRegistered(*document, property_name, value);
}
StylePropertyMapReadOnly::IterationSource*
StylePropertyMapReadOnly::StartIteration(ScriptState* script_state,
ExceptionState&) {
HeapVector<StylePropertyMapReadOnly::StylePropertyMapEntry> result;
StylePropertyMapReadOnlyMainThread::IterationSource*
StylePropertyMapReadOnlyMainThread::StartIteration(ScriptState* script_state,
ExceptionState&) {
HeapVector<StylePropertyMapReadOnlyMainThread::StylePropertyMapEntry> result;
const ExecutionContext& execution_context =
*ExecutionContext::From(script_state);
......@@ -178,7 +181,7 @@ StylePropertyMapReadOnly::StartIteration(ScriptState* script_state,
return new StylePropertyMapIterationSource(result);
}
CSSStyleValue* StylePropertyMapReadOnly::GetShorthandProperty(
CSSStyleValue* StylePropertyMapReadOnlyMainThread::GetShorthandProperty(
const CSSProperty& property) {
DCHECK(property.IsShorthand());
const auto serialization = SerializationForShorthand(property);
......
// Copyright 2018 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_STYLE_PROPERTY_MAP_READ_ONLY_MAIN_THREAD_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_STYLE_PROPERTY_MAP_READ_ONLY_MAIN_THREAD_H_
#include "third_party/blink/renderer/core/css/cssom/style_property_map_read_only.h"
namespace blink {
class CSSProperty;
class CORE_EXPORT StylePropertyMapReadOnlyMainThread
: public StylePropertyMapReadOnly {
public:
using StylePropertyMapEntry = std::pair<String, CSSStyleValueVector>;
~StylePropertyMapReadOnlyMainThread() override = default;
CSSStyleValue* get(const ExecutionContext*,
const String& property_name,
ExceptionState&) override;
CSSStyleValueVector getAll(const ExecutionContext*,
const String& property_name,
ExceptionState&) override;
bool has(const ExecutionContext*,
const String& property_name,
ExceptionState&) override;
unsigned int size() override = 0;
protected:
StylePropertyMapReadOnlyMainThread() = default;
virtual const CSSValue* GetProperty(CSSPropertyID) = 0;
virtual const CSSValue* GetCustomProperty(AtomicString) = 0;
using IterationCallback =
std::function<void(const AtomicString&, const CSSValue&)>;
virtual void ForEachProperty(const IterationCallback&) = 0;
virtual String SerializationForShorthand(const CSSProperty&) = 0;
const CSSValue* GetCustomProperty(const ExecutionContext&,
const AtomicString&);
private:
IterationSource* StartIteration(ScriptState*, ExceptionState&) override;
CSSStyleValue* GetShorthandProperty(const CSSProperty&);
private:
DISALLOW_COPY_AND_ASSIGN(StylePropertyMapReadOnlyMainThread);
};
} // namespace blink
#endif
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