Commit 6c9ae5a9 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Update IDL and implementation for StylePropertyMap.

The spec has changed StylePropertyMap's IDL. StylePropertyMap.append
and set now take a variadic number of (CSSStyleValue or Strings). This
patch changes the IDL and updates the implementation.

Bug: 785132
Change-Id: I502abbd369bea20853e68f434f3c96dc6437a892
Reviewed-on: https://chromium-review.googlesource.com/768330
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarnainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#518425}
parent 2d129306
This is a testharness.js-based test.
PASS Setting animation-direction to normal
PASS Setting animation-direction to reverse
PASS Setting animation-direction to alternate
PASS Setting animation-direction to alternate-reverse
PASS Setting animation-direction to initial
PASS Setting animation-direction to inherit
PASS Setting animation-direction to unset
PASS Setting animation-direction to invalid value CSSUnitValue "4px" throws
PASS Setting animation-direction to invalid value null throws
PASS Setting animation-direction to invalid value undefined throws
PASS Setting animation-direction to invalid value true throws
PASS Setting animation-direction to invalid value false throws
PASS Setting animation-direction to invalid value 1 throws
PASS Setting animation-direction to invalid value hello throws
PASS Setting animation-direction to invalid value [object Object] throws
PASS Setting animation-direction to invalid value CSSKeywordValue "notAKeyword" throws
PASS Getting animation-direction when it is set to normal
PASS Getting animation-direction when it is set to reverse
PASS Getting animation-direction when it is set to alternate
PASS Getting animation-direction when it is set to alternate-reverse
PASS Getting animation-direction when it is set to initial
PASS Getting animation-direction when it is set to inherit
PASS Getting animation-direction when it is set to unset
PASS getAll for single-valued animation-direction
FAIL getAll for list-valued animation-direction Failed to execute 'set' on 'StylePropertyMap': Not implemented yet
PASS Delete animation-direction removes the value from the styleMap
PASS animation-direction shows up in getProperties
FAIL Set animation-direction to a sequence Failed to execute 'set' on 'StylePropertyMap': Not implemented yet
PASS Set animation-direction to a sequence containing an invalid type
PASS Appending a CSSKeywordValue to animation-direction
FAIL Append a sequence to animation-direction Failed to execute 'append' on 'StylePropertyMap': Not implemented yet
PASS Appending an invalid value to animation-direction
PASS Append a sequence containing an invalid value to animation-direction
Harness: the test ran to completion.
...@@ -23,8 +23,8 @@ bindings_core_generated_union_type_files = [ ...@@ -23,8 +23,8 @@ bindings_core_generated_union_type_files = [
"$bindings_core_v8_output_dir/boolean_or_byte_string_byte_string_record.h", "$bindings_core_v8_output_dir/boolean_or_byte_string_byte_string_record.h",
"$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence.cc", "$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence.cc",
"$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence.h", "$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence.h",
"$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence_or_string.cc", "$bindings_core_v8_output_dir/css_style_value_or_string.cc",
"$bindings_core_v8_output_dir/css_style_value_or_css_style_value_sequence_or_string.h", "$bindings_core_v8_output_dir/css_style_value_or_string.h",
"$bindings_core_v8_output_dir/dictionary_sequence_or_dictionary.cc", "$bindings_core_v8_output_dir/dictionary_sequence_or_dictionary.cc",
"$bindings_core_v8_output_dir/dictionary_sequence_or_dictionary.h", "$bindings_core_v8_output_dir/dictionary_sequence_or_dictionary.h",
"$bindings_core_v8_output_dir/double_or_auto_keyword.cc", "$bindings_core_v8_output_dir/double_or_auto_keyword.cc",
......
...@@ -61,22 +61,6 @@ const CSSValue* SingleStyleValueAsCSSValue( ...@@ -61,22 +61,6 @@ const CSSValue* SingleStyleValueAsCSSValue(
return value_list; return value_list;
} }
const CSSValueList* AsCSSValueList(
CSSPropertyID property_id,
const CSSStyleValueVector& style_value_vector,
SecureContextMode secure_context_mode) {
CSSValueList* value_list = CssValueListForPropertyID(property_id);
for (const CSSStyleValue* value : style_value_vector) {
const CSSValue* css_value =
StyleValueToCSSValue(property_id, *value, secure_context_mode);
if (!css_value) {
return nullptr;
}
value_list->Append(*css_value);
}
return value_list;
}
} // namespace } // namespace
CSSStyleValueVector InlineStylePropertyMap::GetAllInternal( CSSStyleValueVector InlineStylePropertyMap::GetAllInternal(
...@@ -121,24 +105,20 @@ Vector<String> InlineStylePropertyMap::getProperties() { ...@@ -121,24 +105,20 @@ Vector<String> InlineStylePropertyMap::getProperties() {
return result; return result;
} }
void InlineStylePropertyMap::set( void InlineStylePropertyMap::set(const ExecutionContext* execution_context,
const ExecutionContext* execution_context,
CSSPropertyID property_id, CSSPropertyID property_id,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (values.IsEmpty())
return;
// TODO(545318): Implement correctly for both list and non-list properties
const auto& item = values[0];
const CSSValue* css_value = nullptr; const CSSValue* css_value = nullptr;
if (item.IsCSSStyleValue()) { if (item.IsCSSStyleValue()) {
css_value = css_value =
SingleStyleValueAsCSSValue(property_id, *item.GetAsCSSStyleValue(), SingleStyleValueAsCSSValue(property_id, *item.GetAsCSSStyleValue(),
execution_context->SecureContextMode()); execution_context->SecureContextMode());
} else if (item.IsCSSStyleValueSequence()) {
if (!CSSProperty::Get(property_id).IsRepeated()) {
exception_state.ThrowTypeError(
"Property does not support multiple values");
return;
}
css_value = AsCSSValueList(property_id, item.GetAsCSSStyleValueSequence(),
execution_context->SecureContextMode());
} else { } else {
// Parse it. // Parse it.
DCHECK(item.IsString()); DCHECK(item.IsString());
...@@ -153,10 +133,9 @@ void InlineStylePropertyMap::set( ...@@ -153,10 +133,9 @@ void InlineStylePropertyMap::set(
owner_element_->SetInlineStyleProperty(property_id, css_value); owner_element_->SetInlineStyleProperty(property_id, css_value);
} }
void InlineStylePropertyMap::append( void InlineStylePropertyMap::append(const ExecutionContext* execution_context,
const ExecutionContext* execution_context,
CSSPropertyID property_id, CSSPropertyID property_id,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!CSSProperty::Get(property_id).IsRepeated()) { if (!CSSProperty::Get(property_id).IsRepeated()) {
exception_state.ThrowTypeError("Property does not support multiple values"); exception_state.ThrowTypeError("Property does not support multiple values");
...@@ -177,6 +156,7 @@ void InlineStylePropertyMap::append( ...@@ -177,6 +156,7 @@ void InlineStylePropertyMap::append(
return; return;
} }
for (auto& item : values) {
if (item.IsCSSStyleValue()) { if (item.IsCSSStyleValue()) {
const CSSValue* css_value = const CSSValue* css_value =
StyleValueToCSSValue(property_id, *item.GetAsCSSStyleValue(), StyleValueToCSSValue(property_id, *item.GetAsCSSStyleValue(),
...@@ -186,16 +166,6 @@ void InlineStylePropertyMap::append( ...@@ -186,16 +166,6 @@ void InlineStylePropertyMap::append(
return; return;
} }
css_value_list->Append(*css_value); css_value_list->Append(*css_value);
} else if (item.IsCSSStyleValueSequence()) {
for (CSSStyleValue* style_value : item.GetAsCSSStyleValueSequence()) {
const CSSValue* css_value = StyleValueToCSSValue(
property_id, *style_value, execution_context->SecureContextMode());
if (!css_value) {
exception_state.ThrowTypeError("Invalid type for property");
return;
}
css_value_list->Append(*css_value);
}
} else { } else {
// Parse it. // Parse it.
DCHECK(item.IsString()); DCHECK(item.IsString());
...@@ -203,6 +173,7 @@ void InlineStylePropertyMap::append( ...@@ -203,6 +173,7 @@ void InlineStylePropertyMap::append(
exception_state.ThrowTypeError("Not implemented yet"); exception_state.ThrowTypeError("Not implemented yet");
return; return;
} }
}
owner_element_->SetInlineStyleProperty(property_id, css_value_list); owner_element_->SetInlineStyleProperty(property_id, css_value_list);
} }
......
...@@ -20,11 +20,11 @@ class CORE_EXPORT InlineStylePropertyMap final : public StylePropertyMap { ...@@ -20,11 +20,11 @@ class CORE_EXPORT InlineStylePropertyMap final : public StylePropertyMap {
void set(const ExecutionContext*, void set(const ExecutionContext*,
CSSPropertyID, CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&, HeapVector<CSSStyleValueOrString>&,
ExceptionState&) override; ExceptionState&) override;
void append(const ExecutionContext*, void append(const ExecutionContext*,
CSSPropertyID, CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&, HeapVector<CSSStyleValueOrString>&,
ExceptionState&) override; ExceptionState&) override;
void remove(CSSPropertyID, ExceptionState&) override; void remove(CSSPropertyID, ExceptionState&) override;
......
...@@ -13,7 +13,7 @@ namespace blink { ...@@ -13,7 +13,7 @@ namespace blink {
void StylePropertyMap::set(const ExecutionContext* execution_context, void StylePropertyMap::set(const ExecutionContext* execution_context,
const String& property_name, const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& item,
ExceptionState& exception_state) { ExceptionState& exception_state) {
CSSPropertyID property_id = cssPropertyID(property_name); CSSPropertyID property_id = cssPropertyID(property_name);
if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) { if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) {
...@@ -24,10 +24,9 @@ void StylePropertyMap::set(const ExecutionContext* execution_context, ...@@ -24,10 +24,9 @@ void StylePropertyMap::set(const ExecutionContext* execution_context,
exception_state.ThrowTypeError("Invalid propertyName: " + property_name); exception_state.ThrowTypeError("Invalid propertyName: " + property_name);
} }
void StylePropertyMap::append( void StylePropertyMap::append(const ExecutionContext* execution_context,
const ExecutionContext* execution_context,
const String& property_name, const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& item,
ExceptionState& exception_state) { ExceptionState& exception_state) {
CSSPropertyID property_id = cssPropertyID(property_name); CSSPropertyID property_id = cssPropertyID(property_name);
if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) { if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define StylePropertyMap_h #define StylePropertyMap_h
#include "base/macros.h" #include "base/macros.h"
#include "bindings/core/v8/css_style_value_or_string.h"
#include "bindings/core/v8/v8_update_function.h" #include "bindings/core/v8/v8_update_function.h"
#include "core/css/cssom/StylePropertyMapReadonly.h" #include "core/css/cssom/StylePropertyMapReadonly.h"
...@@ -20,22 +21,22 @@ class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadonly { ...@@ -20,22 +21,22 @@ class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadonly {
public: public:
void set(const ExecutionContext*, void set(const ExecutionContext*,
const String& property_name, const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState&); ExceptionState&);
void append(const ExecutionContext*, void append(const ExecutionContext*,
const String& property_name, const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState&); ExceptionState&);
void remove(const String& property_name, ExceptionState&); void remove(const String& property_name, ExceptionState&);
void update(const String&, const V8UpdateFunction*) {} void update(const String&, const V8UpdateFunction*) {}
virtual void set(const ExecutionContext*, virtual void set(const ExecutionContext*,
CSSPropertyID, CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState&) = 0; ExceptionState&) = 0;
virtual void append(const ExecutionContext*, virtual void append(const ExecutionContext*,
CSSPropertyID, CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString& item, HeapVector<CSSStyleValueOrString>& values,
ExceptionState&) = 0; ExceptionState&) = 0;
virtual void remove(CSSPropertyID, ExceptionState&) = 0; virtual void remove(CSSPropertyID, ExceptionState&) = 0;
......
...@@ -10,8 +10,8 @@ callback UpdateFunction = CSSStyleValue (CSSStyleValue oldValue); ...@@ -10,8 +10,8 @@ callback UpdateFunction = CSSStyleValue (CSSStyleValue oldValue);
Exposed=(Window,PaintWorklet), Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM RuntimeEnabled=CSSTypedOM
] interface StylePropertyMap : StylePropertyMapReadonly { ] interface StylePropertyMap : StylePropertyMapReadonly {
[RaisesException, CallWith=ExecutionContext] void append(DOMString property, (CSSStyleValue or sequence<CSSStyleValue> or DOMString) value); [RaisesException, CallWith=ExecutionContext] void append(DOMString property, (CSSStyleValue or DOMString)... values);
[RaisesException, ImplementedAs=remove] void delete(DOMString property); [RaisesException, ImplementedAs=remove] void delete(DOMString property);
[RaisesException, CallWith=ExecutionContext] void set(DOMString property, (CSSStyleValue or sequence<CSSStyleValue> or DOMString) value); [RaisesException, CallWith=ExecutionContext] void set(DOMString property, (CSSStyleValue or DOMString)... values);
void update(DOMString property, UpdateFunction updateFunction); void update(DOMString property, UpdateFunction updateFunction);
}; };
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "bindings/core/v8/Iterable.h" #include "bindings/core/v8/Iterable.h"
#include "bindings/core/v8/css_style_value_or_css_style_value_sequence.h" #include "bindings/core/v8/css_style_value_or_css_style_value_sequence.h"
#include "bindings/core/v8/css_style_value_or_css_style_value_sequence_or_string.h"
#include "core/CSSPropertyNames.h" #include "core/CSSPropertyNames.h"
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "core/css/cssom/CSSStyleValue.h" #include "core/css/cssom/CSSStyleValue.h"
......
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