Commit 950384ff authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Implement StylePropertyMap.clear.

This patch adds the clear() method to inline & declared StylePropertyMap
Spec: https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-clear

Bug: 813653
Change-Id: Ib56f60fa59dc8d241e7fb1a7695fce2bea094026
Reviewed-on: https://chromium-review.googlesource.com/925761
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarnainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537717}
parent 19ad180b
This is a testharness.js-based test. This is a testharness.js-based test.
Found 236 tests; 225 PASS, 11 FAIL, 0 TIMEOUT, 0 NOTRUN. Found 237 tests; 226 PASS, 11 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS CSS Typed OM IDL test PASS CSS Typed OM IDL test
PASS CSSStyleValue interface: existence and properties of interface object PASS CSSStyleValue interface: existence and properties of interface object
PASS CSSStyleValue interface object length PASS CSSStyleValue interface object length
...@@ -26,6 +26,7 @@ PASS StylePropertyMap interface: existence and properties of interface prototype ...@@ -26,6 +26,7 @@ PASS StylePropertyMap interface: existence and properties of interface prototype
PASS StylePropertyMap interface: operation append(DOMString, [object Object],[object Object]) PASS StylePropertyMap interface: operation append(DOMString, [object Object],[object Object])
PASS StylePropertyMap interface: operation delete(DOMString) PASS StylePropertyMap interface: operation delete(DOMString)
PASS StylePropertyMap interface: operation set(DOMString, [object Object],[object Object]) PASS StylePropertyMap interface: operation set(DOMString, [object Object],[object Object])
PASS StylePropertyMap interface: operation clear()
PASS CSSUnparsedValue interface: existence and properties of interface object PASS CSSUnparsedValue interface: existence and properties of interface object
PASS CSSUnparsedValue interface object length PASS CSSUnparsedValue interface object length
PASS CSSUnparsedValue interface object name PASS CSSUnparsedValue interface object name
......
<!doctype html>
<meta charset="utf-8">
<title>Declared StylePropertyMap.clear</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-clear">
<meta name="assert" content="Test declared StylePropertyMap.clear" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
test(t => {
let styleMap = createInlineStyleMap(t, '');
styleMap.clear();
assert_array_equals([...styleMap], []);
}, 'Clearing an empty CSS rule is a no-op');
test(t => {
let styleMap = createInlineStyleMap(t, '--foo: auto; width: 10px; transition-duration: 1s, 2s');
styleMap.clear();
assert_equals(styleMap.get('--foo'), null,
'Custom properties should be cleared');
assert_equals(styleMap.get('width'), null,
'CSS properties should be cleared');
assert_equals(styleMap.get('transition-duration'), null,
'List-valued properties should be cleared');
assert_array_equals([...styleMap], []);
}, 'Can clear a CSS rule containing properties');
test(t => {
let [rule, styleMap] = createRuleWithDeclaredStyleMap(t, 'width: 10px;');
styleMap.clear();
assert_equals(rule.style.width, '', 'CSS rule style should be cleared');
}, 'Declared StylePropertyMap.clear updates the CSS rule');
</script>
<!doctype html>
<meta charset="utf-8">
<title>Inline StylePropertyMap.clear</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-clear">
<meta name="assert" content="Test inline StylePropertyMap.clear" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
test(t => {
let styleMap = createInlineStyleMap(t, '');
styleMap.clear();
assert_array_equals([...styleMap], []);
}, 'Clearing an empty inline style is a no-op');
test(t => {
let styleMap = createInlineStyleMap(t, '--foo: auto; width: 10px; transition-duration: 1s, 2s');
styleMap.clear();
assert_equals(styleMap.get('--foo'), null,
'Custom properties should be cleared');
assert_equals(styleMap.get('width'), null,
'CSS properties should be cleared');
assert_equals(styleMap.get('transition-duration'), null,
'List-valued properties should be cleared');
assert_array_equals([...styleMap], []);
}, 'Can clear an inline style containing properties');
test(t => {
let [elem, styleMap] = createElementWithInlineStyleMap(t, 'width: 10px;');
styleMap.clear();
assert_equals(elem.style.width, '', 'Element inline style should be cleared');
}, 'Inline StylePropertyMap.clear updates the element inline style');
</script>
...@@ -24,6 +24,7 @@ interface StylePropertyMap : StylePropertyMapReadOnly { ...@@ -24,6 +24,7 @@ interface StylePropertyMap : StylePropertyMapReadOnly {
void append(DOMString property, (CSSStyleValue or DOMString)... values); void append(DOMString property, (CSSStyleValue or DOMString)... values);
void delete(DOMString property); void delete(DOMString property);
void set(DOMString property, (CSSStyleValue or DOMString)... values); void set(DOMString property, (CSSStyleValue or DOMString)... values);
void clear();
}; };
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)] [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
......
...@@ -6879,6 +6879,7 @@ interface StorageManager ...@@ -6879,6 +6879,7 @@ interface StorageManager
interface StylePropertyMap : StylePropertyMapReadOnly interface StylePropertyMap : StylePropertyMapReadOnly
attribute @@toStringTag attribute @@toStringTag
method append method append
method clear
method constructor method constructor
method delete method delete
method set method set
......
...@@ -68,6 +68,13 @@ void DeclaredStylePropertyMap::RemoveCustomProperty( ...@@ -68,6 +68,13 @@ void DeclaredStylePropertyMap::RemoveCustomProperty(
GetStyleRule()->MutableProperties().RemoveProperty(property_name); GetStyleRule()->MutableProperties().RemoveProperty(property_name);
} }
void DeclaredStylePropertyMap::RemoveAllProperties() {
if (!GetStyleRule())
return;
CSSStyleSheet::RuleMutationScope mutation_scope(owner_rule_);
GetStyleRule()->MutableProperties().Clear();
}
void DeclaredStylePropertyMap::ForEachProperty( void DeclaredStylePropertyMap::ForEachProperty(
const IterationCallback& callback) { const IterationCallback& callback) {
if (!GetStyleRule()) if (!GetStyleRule())
......
...@@ -39,6 +39,7 @@ class CORE_EXPORT DeclaredStylePropertyMap final : public StylePropertyMap { ...@@ -39,6 +39,7 @@ class CORE_EXPORT DeclaredStylePropertyMap final : public StylePropertyMap {
void SetCustomProperty(const AtomicString&, const CSSValue&) override; void SetCustomProperty(const AtomicString&, const CSSValue&) override;
void RemoveProperty(CSSPropertyID) override; void RemoveProperty(CSSPropertyID) override;
void RemoveCustomProperty(const AtomicString&) override; void RemoveCustomProperty(const AtomicString&) override;
void RemoveAllProperties() final;
private: private:
StyleRule* GetStyleRule() const; StyleRule* GetStyleRule() const;
......
...@@ -48,6 +48,10 @@ void InlineStylePropertyMap::RemoveCustomProperty( ...@@ -48,6 +48,10 @@ void InlineStylePropertyMap::RemoveCustomProperty(
owner_element_->RemoveInlineStyleProperty(property_name); owner_element_->RemoveInlineStyleProperty(property_name);
} }
void InlineStylePropertyMap::RemoveAllProperties() {
owner_element_->RemoveAllInlineStyleProperties();
}
void InlineStylePropertyMap::ForEachProperty( void InlineStylePropertyMap::ForEachProperty(
const IterationCallback& callback) { const IterationCallback& callback) {
CSSPropertyValueSet& inline_style_set = CSSPropertyValueSet& inline_style_set =
......
...@@ -29,6 +29,7 @@ class CORE_EXPORT InlineStylePropertyMap final : public StylePropertyMap { ...@@ -29,6 +29,7 @@ class CORE_EXPORT InlineStylePropertyMap final : public StylePropertyMap {
void SetCustomProperty(const AtomicString&, const CSSValue&) override; void SetCustomProperty(const AtomicString&, const CSSValue&) override;
void RemoveProperty(CSSPropertyID) override; void RemoveProperty(CSSPropertyID) override;
void RemoveCustomProperty(const AtomicString&); void RemoveCustomProperty(const AtomicString&);
void RemoveAllProperties() final;
private: private:
Member<Element> owner_element_; Member<Element> owner_element_;
......
...@@ -207,4 +207,8 @@ void StylePropertyMap::remove(const String& property_name, ...@@ -207,4 +207,8 @@ void StylePropertyMap::remove(const String& property_name,
} }
} }
void StylePropertyMap::clear() {
RemoveAllProperties();
}
} // namespace blink } // namespace blink
...@@ -28,12 +28,14 @@ class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadOnly { ...@@ -28,12 +28,14 @@ class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadOnly {
const HeapVector<CSSStyleValueOrString>& values, const HeapVector<CSSStyleValueOrString>& values,
ExceptionState&); ExceptionState&);
void remove(const String& property_name, ExceptionState&); void remove(const String& property_name, ExceptionState&);
void clear();
protected: protected:
virtual void SetProperty(CSSPropertyID, const CSSValue&) = 0; virtual void SetProperty(CSSPropertyID, const CSSValue&) = 0;
virtual void SetCustomProperty(const AtomicString&, const CSSValue&) = 0; virtual void SetCustomProperty(const AtomicString&, const CSSValue&) = 0;
virtual void RemoveProperty(CSSPropertyID) = 0; virtual void RemoveProperty(CSSPropertyID) = 0;
virtual void RemoveCustomProperty(const AtomicString&) = 0; virtual void RemoveCustomProperty(const AtomicString&) = 0;
virtual void RemoveAllProperties() = 0;
StylePropertyMap() = default; StylePropertyMap() = default;
......
...@@ -14,4 +14,5 @@ callback UpdateFunction = CSSStyleValue (CSSStyleValue oldValue); ...@@ -14,4 +14,5 @@ callback UpdateFunction = CSSStyleValue (CSSStyleValue oldValue);
[RaisesException, ImplementedAs=remove] void delete(DOMString property); [RaisesException, ImplementedAs=remove] void delete(DOMString property);
// Putting Exposed=Window in the next line makes |set| not exposed to PaintWorklet. // Putting Exposed=Window in the next line makes |set| not exposed to PaintWorklet.
[RaisesException, CallWith=ExecutionContext, Exposed=Window] void set(DOMString property, (CSSStyleValue or DOMString)... values); [RaisesException, CallWith=ExecutionContext, Exposed=Window] void set(DOMString property, (CSSStyleValue or DOMString)... values);
void clear();
}; };
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