Commit 83749ddd authored by meade's avatar meade Committed by Commit bot

[CSS Typed OM] Rearrange StylePropertyMap classes to match the new spec.

The edited spec is here:
https://drafts.css-houdini.org/css-typed-om/#the-stylepropertymap

Broadly, the changes are:

- Rename ImmutableStylePropertyMap -> StylePropertyMapReadonly
- Switch StylePropertyMap to inherit from StylePropertyMapReadonly
instead of the other way around
- Update all references appropriately

BUG=545318

Review-Url: https://codereview.chromium.org/2730633004
Cr-Commit-Position: refs/heads/master@{#456025}
parent 5cba00e0
......@@ -247,10 +247,13 @@ CONSOLE MESSAGE: line 138: method getReader
CONSOLE MESSAGE: line 138: method pipeThrough
CONSOLE MESSAGE: line 138: method pipeTo
CONSOLE MESSAGE: line 138: method tee
CONSOLE MESSAGE: line 138: interface StylePropertyMap
CONSOLE MESSAGE: line 138: interface StylePropertyMap : StylePropertyMapReadonly
CONSOLE MESSAGE: line 138: method append
CONSOLE MESSAGE: line 138: method constructor
CONSOLE MESSAGE: line 138: method delete
CONSOLE MESSAGE: line 138: method set
CONSOLE MESSAGE: line 138: interface StylePropertyMapReadonly
CONSOLE MESSAGE: line 138: method constructor
CONSOLE MESSAGE: line 138: method entries
CONSOLE MESSAGE: line 138: method forEach
CONSOLE MESSAGE: line 138: method get
......@@ -258,7 +261,6 @@ CONSOLE MESSAGE: line 138: method getAll
CONSOLE MESSAGE: line 138: method getProperties
CONSOLE MESSAGE: line 138: method has
CONSOLE MESSAGE: line 138: method keys
CONSOLE MESSAGE: line 138: method set
CONSOLE MESSAGE: line 138: method values
CONSOLE MESSAGE: line 138: interface WorkletGlobalScope
CONSOLE MESSAGE: line 138: method constructor
......
......@@ -6554,12 +6554,16 @@ interface StorageManager
method estimate
method persist
method persisted
interface StylePropertyMap
interface StylePropertyMap : StylePropertyMapReadonly
attribute @@toStringTag
method @@iterator
method append
method constructor
method delete
method set
interface StylePropertyMapReadonly
attribute @@toStringTag
method @@iterator
method constructor
method entries
method forEach
method get
......@@ -6567,7 +6571,6 @@ interface StylePropertyMap
method getProperties
method has
method keys
method set
method values
interface StyleSheet
attribute @@toStringTag
......
......@@ -85,6 +85,7 @@ core_idl_files = get_path_info([
"css/cssom/CSSUnparsedValue.idl",
"css/cssom/CSSVariableReferenceValue.idl",
"css/cssom/StylePropertyMap.idl",
"css/cssom/StylePropertyMapReadonly.idl",
"dom/ArrayBuffer.idl",
"dom/ArrayBufferView.idl",
"dom/Attr.idl",
......
......@@ -293,12 +293,13 @@ blink_core_sources("css") {
"cssom/ComputedStylePropertyMap.h",
"cssom/FilteredComputedStylePropertyMap.cpp",
"cssom/FilteredComputedStylePropertyMap.h",
"cssom/ImmutableStylePropertyMap.h",
"cssom/InlineStylePropertyMap.cpp",
"cssom/InlineStylePropertyMap.h",
"cssom/MutableStylePropertyMap.h",
"cssom/StylePropertyMap.cpp",
"cssom/StylePropertyMap.h",
"cssom/StylePropertyMapReadonly.cpp",
"cssom/StylePropertyMapReadonly.h",
"cssom/StyleValueFactory.cpp",
"cssom/StyleValueFactory.h",
"cssom/WindowGetComputedStyle.h",
......
......@@ -6,7 +6,7 @@
#define ComputedStylePropertyMap_h
#include "core/css/CSSComputedStyleDeclaration.h"
#include "core/css/cssom/ImmutableStylePropertyMap.h"
#include "core/css/cssom/StylePropertyMapReadonly.h"
#include "core/dom/Node.h"
#include "core/layout/LayoutObject.h"
......@@ -20,7 +20,7 @@ namespace blink {
// them as CSSStyleValues. The IDL for this class is in StylePropertyMap.idl.
// The computed StylePropertyMapReadOnly for an element is accessed via
// window.getComputedStyleMap(element) (see WindowGetComputedStyle.idl/h)
class CORE_EXPORT ComputedStylePropertyMap : public ImmutableStylePropertyMap {
class CORE_EXPORT ComputedStylePropertyMap : public StylePropertyMapReadonly {
WTF_MAKE_NONCOPYABLE(ComputedStylePropertyMap);
public:
......@@ -34,7 +34,7 @@ class CORE_EXPORT ComputedStylePropertyMap : public ImmutableStylePropertyMap {
DEFINE_INLINE_VIRTUAL_TRACE() {
visitor->trace(m_computedStyleDeclaration);
visitor->trace(m_node);
ImmutableStylePropertyMap::trace(visitor);
StylePropertyMapReadonly::trace(visitor);
}
private:
......@@ -42,7 +42,7 @@ class CORE_EXPORT ComputedStylePropertyMap : public ImmutableStylePropertyMap {
protected:
ComputedStylePropertyMap(Node* node, const String& pseudoElement = String())
: ImmutableStylePropertyMap(),
: StylePropertyMapReadonly(),
m_computedStyleDeclaration(
CSSComputedStyleDeclaration::create(node, false, pseudoElement)),
m_pseudoId(CSSSelector::parsePseudoId(pseudoElement)),
......
// 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 ImmutableStylePropertyMap_h
#define ImmutableStylePropertyMap_h
#include "core/css/cssom/StylePropertyMap.h"
namespace blink {
class CORE_EXPORT ImmutableStylePropertyMap : public StylePropertyMap {
WTF_MAKE_NONCOPYABLE(ImmutableStylePropertyMap);
public:
void set(CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&,
ExceptionState& exceptionState) override {
exceptionState.throwTypeError("This StylePropertyMap is immutable.");
}
void append(CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&,
ExceptionState& exceptionState) override {
exceptionState.throwTypeError("This StylePropertyMap is immutable.");
}
void remove(CSSPropertyID, ExceptionState& exceptionState) override {
exceptionState.throwTypeError("This StylePropertyMap is immutable.");
}
protected:
ImmutableStylePropertyMap() = default;
};
} // namespace blink
#endif
......@@ -12,81 +12,6 @@
namespace blink {
namespace {
class StylePropertyMapIterationSource final
: public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
IterationSource {
public:
explicit StylePropertyMapIterationSource(
HeapVector<StylePropertyMap::StylePropertyMapEntry> values)
: m_index(0), m_values(values) {}
bool next(ScriptState*,
String& key,
CSSStyleValueOrCSSStyleValueSequence& value,
ExceptionState&) override {
if (m_index >= m_values.size())
return false;
const StylePropertyMap::StylePropertyMapEntry& pair =
m_values.at(m_index++);
key = pair.first;
value = pair.second;
return true;
}
DEFINE_INLINE_VIRTUAL_TRACE() {
visitor->trace(m_values);
PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
IterationSource::trace(visitor);
}
private:
size_t m_index;
const HeapVector<StylePropertyMap::StylePropertyMapEntry> m_values;
};
} // namespace
CSSStyleValue* StylePropertyMap::get(const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) {
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return nullptr;
}
CSSStyleValueVector styleVector = getAllInternal(propertyID);
if (styleVector.isEmpty())
return nullptr;
return styleVector[0];
}
CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
return getAllInternal(propertyID);
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return CSSStyleValueVector();
}
bool StylePropertyMap::has(const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
return !getAllInternal(propertyID).isEmpty();
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return false;
}
void StylePropertyMap::set(const String& propertyName,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
ExceptionState& exceptionState) {
......@@ -123,10 +48,4 @@ void StylePropertyMap::remove(const String& propertyName,
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
}
StylePropertyMap::IterationSource* StylePropertyMap::startIteration(
ScriptState*,
ExceptionState&) {
return new StylePropertyMapIterationSource(getIterationEntries());
}
} // namespace blink
......@@ -5,40 +5,17 @@
#ifndef StylePropertyMap_h
#define StylePropertyMap_h
#include "bindings/core/v8/CSSStyleValueOrCSSStyleValueSequence.h"
#include "bindings/core/v8/CSSStyleValueOrCSSStyleValueSequenceOrString.h"
#include "bindings/core/v8/Iterable.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CSSPropertyNames.h"
#include "core/CoreExport.h"
#include "core/css/cssom/CSSStyleValue.h"
#include "core/css/cssom/StylePropertyMapReadonly.h"
namespace blink {
class ExceptionState;
class CORE_EXPORT StylePropertyMap
: public GarbageCollectedFinalized<StylePropertyMap>,
public ScriptWrappable,
public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence> {
WTF_MAKE_NONCOPYABLE(StylePropertyMap);
class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadonly {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(StylePropertyMap);
public:
typedef std::pair<String, CSSStyleValueOrCSSStyleValueSequence>
StylePropertyMapEntry;
virtual ~StylePropertyMap() {}
// Accessors.
virtual CSSStyleValue* get(const String& propertyName, ExceptionState&);
virtual CSSStyleValueVector getAll(const String& propertyName,
ExceptionState&);
virtual bool has(const String& propertyName, ExceptionState&);
virtual Vector<String> getProperties() = 0;
// Modifiers.
void set(const String& propertyName,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
ExceptionState&);
......@@ -55,17 +32,9 @@ class CORE_EXPORT StylePropertyMap
ExceptionState&) = 0;
virtual void remove(CSSPropertyID, ExceptionState&) = 0;
DEFINE_INLINE_VIRTUAL_TRACE() {}
protected:
StylePropertyMap() {}
virtual CSSStyleValueVector getAllInternal(CSSPropertyID) = 0;
virtual CSSStyleValueVector getAllInternal(
AtomicString customPropertyName) = 0;
virtual HeapVector<StylePropertyMapEntry> getIterationEntries() = 0;
IterationSource* startIteration(ScriptState*, ExceptionState&) override;
};
} // namespace blink
......
......@@ -5,13 +5,8 @@
[
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM,
] interface StylePropertyMap {
] interface StylePropertyMap : StylePropertyMapReadonly {
[RaisesException] void append(DOMString property, (CSSStyleValue or sequence<CSSStyleValue> or DOMString) value);
[RaisesException, ImplementedAs=remove] void delete(DOMString property);
[RaisesException] CSSStyleValue? get(DOMString property);
[RaisesException] sequence<CSSStyleValue> getAll(DOMString property);
[RaisesException] boolean has(DOMString property);
[RaisesException] void set(DOMString property, (CSSStyleValue or sequence<CSSStyleValue> or DOMString) value);
iterable<DOMString, (CSSStyleValue or sequence<CSSStyleValue>)>;
sequence<DOMString> getProperties();
};
// 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/StylePropertyMapReadonly.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/css/CSSValueList.h"
#include "core/css/cssom/CSSSimpleLength.h"
#include "core/css/cssom/CSSStyleValue.h"
#include "core/css/cssom/StyleValueFactory.h"
namespace blink {
namespace {
class StylePropertyMapIterationSource final
: public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
IterationSource {
public:
explicit StylePropertyMapIterationSource(
HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> values)
: m_index(0), m_values(values) {}
bool next(ScriptState*,
String& key,
CSSStyleValueOrCSSStyleValueSequence& value,
ExceptionState&) override {
if (m_index >= m_values.size())
return false;
const StylePropertyMapReadonly::StylePropertyMapEntry& pair =
m_values.at(m_index++);
key = pair.first;
value = pair.second;
return true;
}
DEFINE_INLINE_VIRTUAL_TRACE() {
visitor->trace(m_values);
PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
IterationSource::trace(visitor);
}
private:
size_t m_index;
const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> m_values;
};
} // namespace
CSSStyleValue* StylePropertyMapReadonly::get(const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) {
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return nullptr;
}
CSSStyleValueVector styleVector = getAllInternal(propertyID);
if (styleVector.isEmpty())
return nullptr;
return styleVector[0];
}
CSSStyleValueVector StylePropertyMapReadonly::getAll(
const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
return getAllInternal(propertyID);
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return CSSStyleValueVector();
}
bool StylePropertyMapReadonly::has(const String& propertyName,
ExceptionState& exceptionState) {
CSSPropertyID propertyID = cssPropertyID(propertyName);
if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
return !getAllInternal(propertyID).isEmpty();
// TODO(meade): Handle custom properties here.
exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
return false;
}
StylePropertyMapReadonly::IterationSource*
StylePropertyMapReadonly::startIteration(ScriptState*, ExceptionState&) {
return new StylePropertyMapIterationSource(getIterationEntries());
}
} // namespace blink
// 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 StylePropertyMapReadonly_h
#define StylePropertyMapReadonly_h
#include "bindings/core/v8/CSSStyleValueOrCSSStyleValueSequence.h"
#include "bindings/core/v8/CSSStyleValueOrCSSStyleValueSequenceOrString.h"
#include "bindings/core/v8/Iterable.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CSSPropertyNames.h"
#include "core/CoreExport.h"
#include "core/css/cssom/CSSStyleValue.h"
namespace blink {
class CORE_EXPORT StylePropertyMapReadonly
: public GarbageCollectedFinalized<StylePropertyMapReadonly>,
public ScriptWrappable,
public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence> {
DEFINE_WRAPPERTYPEINFO();
WTF_MAKE_NONCOPYABLE(StylePropertyMapReadonly);
public:
typedef std::pair<String, CSSStyleValueOrCSSStyleValueSequence>
StylePropertyMapEntry;
virtual ~StylePropertyMapReadonly() {}
virtual CSSStyleValue* get(const String& propertyName, ExceptionState&);
virtual CSSStyleValueVector getAll(const String& propertyName,
ExceptionState&);
virtual bool has(const String& propertyName, ExceptionState&);
virtual Vector<String> getProperties() = 0;
DEFINE_INLINE_VIRTUAL_TRACE() {}
protected:
StylePropertyMapReadonly() = default;
virtual CSSStyleValueVector getAllInternal(CSSPropertyID) = 0;
virtual CSSStyleValueVector getAllInternal(
AtomicString customPropertyName) = 0;
virtual HeapVector<StylePropertyMapEntry> getIterationEntries() = 0;
IterationSource* startIteration(ScriptState*, ExceptionState&) override;
};
} // namespace blink
#endif
// Copyright 2017 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.
[
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM,
] interface StylePropertyMapReadonly {
[RaisesException] CSSStyleValue? get(DOMString property);
[RaisesException] sequence<CSSStyleValue> getAll(DOMString property);
[RaisesException] boolean has(DOMString property);
iterable<DOMString, (CSSStyleValue or sequence<CSSStyleValue>)>;
sequence<DOMString> getProperties();
};
......@@ -14,9 +14,10 @@ class WindowGetComputedStyle {
STATIC_ONLY(WindowGetComputedStyle);
public:
static StylePropertyMap* getComputedStyleMap(const LocalDOMWindow&,
Element* element,
const String& pseudoElement) {
static StylePropertyMapReadonly* getComputedStyleMap(
const LocalDOMWindow&,
Element* element,
const String& pseudoElement) {
DCHECK(element);
return ComputedStylePropertyMap::create(element, pseudoElement);
}
......
......@@ -7,5 +7,5 @@
[
RuntimeEnabled=CSSTypedOM,
] partial interface Window {
[NewObject] StylePropertyMap getComputedStyleMap(Element element, optional DOMString? pseudoElement = null);
[NewObject] StylePropertyMapReadonly getComputedStyleMap(Element element, optional DOMString? pseudoElement = null);
};
......@@ -95,7 +95,7 @@ PassRefPtr<Image> CSSPaintDefinition::paint(
m_hasAlpha ? NonOpaque : Opaque))),
m_hasAlpha, zoom);
PaintSize* paintSize = PaintSize::create(specifiedSize);
StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create(
StylePropertyMapReadonly* styleMap = FilteredComputedStylePropertyMap::create(
CSSComputedStyleDeclaration::create(layoutObject.node()),
m_nativeInvalidationProperties, m_customInvalidationProperties,
layoutObject.node());
......
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