Commit ffee3833 authored by Naina Raisinghani's avatar Naina Raisinghani Committed by Commit Bot

[css-typed-om] Allow mutations of CSSTransformValues.

This patch allows CSSTransformValues items to be mutated/appended.
Spec issue here: https://github.com/w3c/css-houdini-drafts/issues/690

Bug: 545318
Change-Id: I841704e1f2ec8db0f27ae254a0949d4f9b46c8f7
Reviewed-on: https://chromium-review.googlesource.com/925882Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: nainar <nainar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537710}
parent 97b4154f
......@@ -25,6 +25,39 @@ test(() => {
assert_style_value_array_equals(transform, values);
}, 'CSSTransformValue can be constructed with multiple transforms');
test(() => {
const values = [
new CSSScale(1, 1),
new CSSTranslate(CSS.px(1), CSS.px(1)),
new CSSRotate(CSS.deg(90))
];
const transform = new CSSTransformValue(values);
assert_style_value_array_equals(transform, values);
values.pop();
var new_value = new CSSRotate(CSS.deg(45));
values[2] = new_value;
transform[2] = new_value;
assert_style_value_array_equals(transform, values);
}, 'CSSTransformValue.set correctly sets the CSSTransformComponent at the given index');
test(() => {
const values = [
new CSSScale(1, 1),
new CSSTranslate(CSS.px(1), CSS.px(1)),
new CSSRotate(CSS.deg(90))
];
const transform = new CSSTransformValue(values);
assert_style_value_array_equals(transform, values);
var new_value = new CSSRotate(CSS.deg(45));
values[3] = new_value;
transform[3] = new_value;
assert_style_value_array_equals(transform, values);
}, 'Setting a component in CSSTransformValue correctly appends the CSSTransformComponent if index specified is greater than length');
test(() => {
const transform = new CSSTransformValue([
new CSSScale(1, 1),
......
......@@ -74,4 +74,25 @@ const CSSValue* CSSTransformValue::ToCSSValue() const {
return transform_css_value;
}
bool CSSTransformValue::AnonymousIndexedSetter(
unsigned index,
const Member<CSSTransformComponent> component,
ExceptionState& exception_state) {
if (index < transform_components_.size()) {
transform_components_[index] = component;
return true;
}
if (index == transform_components_.size()) {
transform_components_.push_back(component);
return true;
}
exception_state.ThrowRangeError(
ExceptionMessages::IndexOutsideRange<unsigned>(
"index", index, 0, ExceptionMessages::kInclusiveBound,
transform_components_.size(), ExceptionMessages::kInclusiveBound));
return false;
}
} // namespace blink
......@@ -38,9 +38,12 @@ class CORE_EXPORT CSSTransformValue final : public CSSStyleValue {
StyleValueType GetType() const override { return kTransformType; }
CSSTransformComponent* componentAtIndex(uint32_t index) {
CSSTransformComponent* AnonymousIndexedGetter(uint32_t index) {
return transform_components_.at(index);
}
bool AnonymousIndexedSetter(unsigned,
const Member<CSSTransformComponent>,
ExceptionState&);
size_t length() const { return transform_components_.size(); }
......
......@@ -10,7 +10,8 @@
] interface CSSTransformValue : CSSStyleValue {
// https://github.com/w3c/css-houdini-drafts/issues/358
readonly attribute unsigned long length;
[ImplementedAs=componentAtIndex] getter CSSTransformComponent (unsigned long index);
getter CSSTransformComponent (unsigned long index);
[RaisesException] setter CSSTransformComponent (unsigned long index, CSSTransformComponent val);
iterable<CSSTransformComponent>;
readonly attribute boolean is2D;
......
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