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 = [
"$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.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_css_style_value_sequence_or_string.h",
"$bindings_core_v8_output_dir/css_style_value_or_string.cc",
"$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.h",
"$bindings_core_v8_output_dir/double_or_auto_keyword.cc",
......
......@@ -61,22 +61,6 @@ const CSSValue* SingleStyleValueAsCSSValue(
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
CSSStyleValueVector InlineStylePropertyMap::GetAllInternal(
......@@ -121,24 +105,20 @@ Vector<String> InlineStylePropertyMap::getProperties() {
return result;
}
void InlineStylePropertyMap::set(
const ExecutionContext* execution_context,
CSSPropertyID property_id,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
ExceptionState& exception_state) {
void InlineStylePropertyMap::set(const ExecutionContext* execution_context,
CSSPropertyID property_id,
HeapVector<CSSStyleValueOrString>& values,
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;
if (item.IsCSSStyleValue()) {
css_value =
SingleStyleValueAsCSSValue(property_id, *item.GetAsCSSStyleValue(),
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 {
// Parse it.
DCHECK(item.IsString());
......@@ -153,11 +133,10 @@ void InlineStylePropertyMap::set(
owner_element_->SetInlineStyleProperty(property_id, css_value);
}
void InlineStylePropertyMap::append(
const ExecutionContext* execution_context,
CSSPropertyID property_id,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
ExceptionState& exception_state) {
void InlineStylePropertyMap::append(const ExecutionContext* execution_context,
CSSPropertyID property_id,
HeapVector<CSSStyleValueOrString>& values,
ExceptionState& exception_state) {
if (!CSSProperty::Get(property_id).IsRepeated()) {
exception_state.ThrowTypeError("Property does not support multiple values");
return;
......@@ -177,31 +156,23 @@ void InlineStylePropertyMap::append(
return;
}
if (item.IsCSSStyleValue()) {
const CSSValue* css_value =
StyleValueToCSSValue(property_id, *item.GetAsCSSStyleValue(),
execution_context->SecureContextMode());
if (!css_value) {
exception_state.ThrowTypeError("Invalid type for property");
return;
}
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());
for (auto& item : values) {
if (item.IsCSSStyleValue()) {
const CSSValue* css_value =
StyleValueToCSSValue(property_id, *item.GetAsCSSStyleValue(),
execution_context->SecureContextMode());
if (!css_value) {
exception_state.ThrowTypeError("Invalid type for property");
return;
}
css_value_list->Append(*css_value);
} else {
// Parse it.
DCHECK(item.IsString());
// TODO(meade): Implement this.
exception_state.ThrowTypeError("Not implemented yet");
return;
}
} else {
// Parse it.
DCHECK(item.IsString());
// TODO(meade): Implement this.
exception_state.ThrowTypeError("Not implemented yet");
return;
}
owner_element_->SetInlineStyleProperty(property_id, css_value_list);
......
......@@ -20,11 +20,11 @@ class CORE_EXPORT InlineStylePropertyMap final : public StylePropertyMap {
void set(const ExecutionContext*,
CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&,
HeapVector<CSSStyleValueOrString>&,
ExceptionState&) override;
void append(const ExecutionContext*,
CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString&,
HeapVector<CSSStyleValueOrString>&,
ExceptionState&) override;
void remove(CSSPropertyID, ExceptionState&) override;
......
......@@ -13,7 +13,7 @@ namespace blink {
void StylePropertyMap::set(const ExecutionContext* execution_context,
const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
HeapVector<CSSStyleValueOrString>& item,
ExceptionState& exception_state) {
CSSPropertyID property_id = cssPropertyID(property_name);
if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) {
......@@ -24,11 +24,10 @@ void StylePropertyMap::set(const ExecutionContext* execution_context,
exception_state.ThrowTypeError("Invalid propertyName: " + property_name);
}
void StylePropertyMap::append(
const ExecutionContext* execution_context,
const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
ExceptionState& exception_state) {
void StylePropertyMap::append(const ExecutionContext* execution_context,
const String& property_name,
HeapVector<CSSStyleValueOrString>& item,
ExceptionState& exception_state) {
CSSPropertyID property_id = cssPropertyID(property_name);
if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) {
append(execution_context, property_id, item, exception_state);
......
......@@ -6,6 +6,7 @@
#define StylePropertyMap_h
#include "base/macros.h"
#include "bindings/core/v8/css_style_value_or_string.h"
#include "bindings/core/v8/v8_update_function.h"
#include "core/css/cssom/StylePropertyMapReadonly.h"
......@@ -20,22 +21,22 @@ class CORE_EXPORT StylePropertyMap : public StylePropertyMapReadonly {
public:
void set(const ExecutionContext*,
const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
HeapVector<CSSStyleValueOrString>& values,
ExceptionState&);
void append(const ExecutionContext*,
const String& property_name,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
HeapVector<CSSStyleValueOrString>& values,
ExceptionState&);
void remove(const String& property_name, ExceptionState&);
void update(const String&, const V8UpdateFunction*) {}
virtual void set(const ExecutionContext*,
CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
HeapVector<CSSStyleValueOrString>& values,
ExceptionState&) = 0;
virtual void append(const ExecutionContext*,
CSSPropertyID,
CSSStyleValueOrCSSStyleValueSequenceOrString& item,
HeapVector<CSSStyleValueOrString>& values,
ExceptionState&) = 0;
virtual void remove(CSSPropertyID, ExceptionState&) = 0;
......
......@@ -10,8 +10,8 @@ callback UpdateFunction = CSSStyleValue (CSSStyleValue oldValue);
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM
] 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, 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);
};
......@@ -8,7 +8,6 @@
#include "base/macros.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_or_string.h"
#include "core/CSSPropertyNames.h"
#include "core/CoreExport.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