Commit 41116935 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Add a 'values' attribute to all variadic CSSMathValues.

This patch adds the 'values' attribute to CSSMathSum/Product/Min/Max.
'values' is a CSSNumericArray, which is an array of CSSNumericValues
representing the arguments to the CSSMathValue. We make the variadic
CSSMathValues inherit from a new class CSSMathVariadic so that all the
boilerplate with working with multiple arguments are in one place.

Note that CSSNumericArray is not spec'd, but we based the implementation
off https://github.com/w3c/css-houdini-drafts/issues/486

Spec: https://drafts.css-houdini.org/css-typed-om-1/#complex-numeric

Bug: 776173
Change-Id: I1079b31993ecb02f31c2fe93ebf31c548fa6025c
Reviewed-on: https://chromium-review.googlesource.com/762887Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarRenée Wright <rjwright@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516223}
parent ecc9a74e
......@@ -16,17 +16,25 @@ CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathMax : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathNegate : CSSMathValue
CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathProduct : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathValue : CSSNumericValue
CONSOLE MESSAGE: line 147: getter operator
CONSOLE MESSAGE: line 147: method constructor
......@@ -34,6 +42,9 @@ CONSOLE MESSAGE: line 147: interface CSSMatrixComponent : CSSTransformComponent
CONSOLE MESSAGE: line 147: getter matrix
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter matrix
CONSOLE MESSAGE: line 147: interface CSSNumericArray
CONSOLE MESSAGE: line 147: getter length
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSNumericValue : CSSStyleValue
CONSOLE MESSAGE: line 147: method add
CONSOLE MESSAGE: line 147: method constructor
......@@ -295,17 +306,25 @@ CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathMax : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathNegate : CSSMathValue
CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathProduct : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue
CONSOLE MESSAGE: line 147: getter values
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter values
CONSOLE MESSAGE: line 147: interface CSSMathValue : CSSNumericValue
CONSOLE MESSAGE: line 147: getter operator
CONSOLE MESSAGE: line 147: method constructor
......@@ -313,6 +332,9 @@ CONSOLE MESSAGE: line 147: interface CSSMatrixComponent : CSSTransformComponent
CONSOLE MESSAGE: line 147: getter matrix
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter matrix
CONSOLE MESSAGE: line 147: interface CSSNumericArray
CONSOLE MESSAGE: line 147: getter length
CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSNumericValue : CSSStyleValue
CONSOLE MESSAGE: line 147: method add
CONSOLE MESSAGE: line 147: method constructor
......
......@@ -23,11 +23,14 @@ for (const {subclass, operator} of gVariadicMathValueSubclasses) {
test(() => {
const result = new subclass(CSS.number(0));
assert_equals(result.operator, operator);
assert_style_value_array_equals(result.values, [CSS.number(0)]);
}, subclass.name + ' can be constructed from a single number CSSUnitValue');
test(() => {
const result = new subclass(CSS.number(1), CSS.number(2), CSS.number(3), CSS.number(4), CSS.number(5));
const args = [CSS.number(1), CSS.number(2), CSS.number(3), CSS.number(4), CSS.number(5)]
const result = new subclass(...args);
assert_equals(result.operator, operator);
assert_style_value_array_equals(result.values, args);
}, subclass.name + ' can be constructed from more than one number CSSUnitValue');
test(() => {
......
......@@ -646,10 +646,14 @@ interface CSSMathInvert : CSSMathValue
setter value
interface CSSMathMax : CSSMathValue
attribute @@toStringTag
getter values
method constructor
setter values
interface CSSMathMin : CSSMathValue
attribute @@toStringTag
getter values
method constructor
setter values
interface CSSMathNegate : CSSMathValue
attribute @@toStringTag
getter value
......@@ -657,10 +661,14 @@ interface CSSMathNegate : CSSMathValue
setter value
interface CSSMathProduct : CSSMathValue
attribute @@toStringTag
getter values
method constructor
setter values
interface CSSMathSum : CSSMathValue
attribute @@toStringTag
getter values
method constructor
setter values
interface CSSMathValue : CSSNumericValue
attribute @@toStringTag
getter operator
......@@ -679,6 +687,11 @@ interface CSSNamespaceRule : CSSRule
getter namespaceURI
getter prefix
method constructor
interface CSSNumericArray
attribute @@toStringTag
getter length
method @@iterator
method constructor
interface CSSNumericValue : CSSStyleValue
attribute @@toStringTag
method add
......
......@@ -81,6 +81,7 @@ core_idl_files =
"css/cssom/CSSMathSum.idl",
"css/cssom/CSSMathProduct.idl",
"css/cssom/CSSMathValue.idl",
"css/cssom/CSSNumericArray.idl",
"css/cssom/CSSNumericValue.idl",
"css/cssom/CSSPerspective.idl",
"css/cssom/CSSPositionValue.idl",
......
......@@ -5,13 +5,13 @@
#ifndef CSSMathMax_h
#define CSSMathMax_h
#include "core/css/cssom/CSSMathValue.h"
#include "core/css/cssom/CSSMathVariadic.h"
namespace blink {
// Represents the maximum of one or more CSSNumericValues.
// See CSSMathMax.idl for more information about this class.
class CORE_EXPORT CSSMathMax : public CSSMathValue {
class CORE_EXPORT CSSMathMax final : public CSSMathVariadic {
WTF_MAKE_NONCOPYABLE(CSSMathMax);
DEFINE_WRAPPERTYPEINFO();
......@@ -27,7 +27,7 @@ class CORE_EXPORT CSSMathMax : public CSSMathValue {
// TODO(crbug.com/776173): Implement add typing.
CSSNumericValueType type(CSSPrimitiveValue::UnitType::kNumber);
return new CSSMathMax(args, type);
return new CSSMathMax(CSSNumericArray::FromNumberishes(args), type);
}
String getOperator() const final { return "max"; }
......@@ -36,8 +36,8 @@ class CORE_EXPORT CSSMathMax : public CSSMathValue {
StyleValueType GetType() const final { return CSSStyleValue::kMaxType; }
private:
CSSMathMax(const HeapVector<CSSNumberish>&, const CSSNumericValueType& type)
: CSSMathValue(type) {}
CSSMathMax(CSSNumericArray* values, const CSSNumericValueType& type)
: CSSMathVariadic(values, type) {}
};
} // namespace blink
......
......@@ -10,4 +10,5 @@
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSMathMax : CSSMathValue {
attribute CSSNumericArray values;
};
......@@ -5,13 +5,13 @@
#ifndef CSSMathMin_h
#define CSSMathMin_h
#include "core/css/cssom/CSSMathValue.h"
#include "core/css/cssom/CSSMathVariadic.h"
namespace blink {
// Represents the minimum of one or more CSSNumericValues.
// See CSSMathMin.idl for more information about this class.
class CORE_EXPORT CSSMathMin : public CSSMathValue {
class CORE_EXPORT CSSMathMin final : public CSSMathVariadic {
WTF_MAKE_NONCOPYABLE(CSSMathMin);
DEFINE_WRAPPERTYPEINFO();
......@@ -27,7 +27,7 @@ class CORE_EXPORT CSSMathMin : public CSSMathValue {
// TODO(crbug.com/776173): Implement add typing.
CSSNumericValueType type(CSSPrimitiveValue::UnitType::kNumber);
return new CSSMathMin(args, type);
return new CSSMathMin(CSSNumericArray::FromNumberishes(args), type);
}
String getOperator() const final { return "min"; }
......@@ -36,8 +36,8 @@ class CORE_EXPORT CSSMathMin : public CSSMathValue {
StyleValueType GetType() const final { return CSSStyleValue::kMinType; }
private:
CSSMathMin(const HeapVector<CSSNumberish>&, const CSSNumericValueType& type)
: CSSMathValue(type) {}
CSSMathMin(CSSNumericArray* values, const CSSNumericValueType& type)
: CSSMathVariadic(values, type) {}
};
} // namespace blink
......
......@@ -10,4 +10,5 @@
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSMathMin : CSSMathValue {
attribute CSSNumericArray values;
};
......@@ -5,13 +5,13 @@
#ifndef CSSMathProduct_h
#define CSSMathProduct_h
#include "core/css/cssom/CSSMathValue.h"
#include "core/css/cssom/CSSMathVariadic.h"
namespace blink {
// Represents the product of one or more CSSNumericValues.
// See CSSMathProduct.idl for more information about this class.
class CORE_EXPORT CSSMathProduct : public CSSMathValue {
class CORE_EXPORT CSSMathProduct final : public CSSMathVariadic {
WTF_MAKE_NONCOPYABLE(CSSMathProduct);
DEFINE_WRAPPERTYPEINFO();
......@@ -27,7 +27,7 @@ class CORE_EXPORT CSSMathProduct : public CSSMathValue {
// TODO(crbug.com/776173): Implement multiply typing.
CSSNumericValueType type(CSSPrimitiveValue::UnitType::kNumber);
return new CSSMathProduct(args, type);
return new CSSMathProduct(CSSNumericArray::FromNumberishes(args), type);
}
String getOperator() const final { return "product"; }
......@@ -36,9 +36,8 @@ class CORE_EXPORT CSSMathProduct : public CSSMathValue {
StyleValueType GetType() const final { return CSSStyleValue::kProductType; }
private:
CSSMathProduct(const HeapVector<CSSNumberish>&,
const CSSNumericValueType& type)
: CSSMathValue(type) {}
CSSMathProduct(CSSNumericArray* values, const CSSNumericValueType& type)
: CSSMathVariadic(values, type) {}
};
} // namespace blink
......
......@@ -10,4 +10,5 @@
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSMathProduct : CSSMathValue {
attribute CSSNumericArray values;
};
......@@ -5,13 +5,13 @@
#ifndef CSSMathSum_h
#define CSSMathSum_h
#include "core/css/cssom/CSSMathValue.h"
#include "core/css/cssom/CSSMathVariadic.h"
namespace blink {
// Represents the sum of one or more CSSNumericValues.
// See CSSMathSum.idl for more information about this class.
class CORE_EXPORT CSSMathSum final : public CSSMathValue {
class CORE_EXPORT CSSMathSum final : public CSSMathVariadic {
WTF_MAKE_NONCOPYABLE(CSSMathSum);
DEFINE_WRAPPERTYPEINFO();
......@@ -27,7 +27,7 @@ class CORE_EXPORT CSSMathSum final : public CSSMathValue {
// TODO(crbug.com/776173): Implement add typing.
CSSNumericValueType type(CSSPrimitiveValue::UnitType::kNumber);
return new CSSMathSum(args, type);
return new CSSMathSum(CSSNumericArray::FromNumberishes(args), type);
}
String getOperator() const final { return "sum"; }
......@@ -36,8 +36,8 @@ class CORE_EXPORT CSSMathSum final : public CSSMathValue {
StyleValueType GetType() const final { return CSSStyleValue::kSumType; }
private:
CSSMathSum(const HeapVector<CSSNumberish>&, const CSSNumericValueType& type)
: CSSMathValue(type) {}
CSSMathSum(CSSNumericArray* values, const CSSNumericValueType& type)
: CSSMathVariadic(values, type) {}
};
} // namespace blink
......
......@@ -10,4 +10,5 @@
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSMathSum : CSSMathValue {
attribute CSSNumericArray values;
};
// 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.
#ifndef CSSMathVariadic_h
#define CSSMathVariadic_h
#include "core/css/cssom/CSSMathValue.h"
#include "core/css/cssom/CSSNumericArray.h"
namespace blink {
// Represents an arithmetic operation with one or more CSSNumericValues.
class CORE_EXPORT CSSMathVariadic : public CSSMathValue {
WTF_MAKE_NONCOPYABLE(CSSMathVariadic);
public:
CSSNumericArray* values() { return values_.Get(); }
void setValues(CSSNumericArray* values) { values_ = values; }
void Trace(Visitor* visitor) override {
visitor->Trace(values_);
CSSMathValue::Trace(visitor);
}
protected:
CSSMathVariadic(CSSNumericArray* values, const CSSNumericValueType& type)
: CSSMathValue(type), values_(values) {}
private:
Member<CSSNumericArray> values_;
};
} // namespace blink
#endif // CSSMathVariadic_h
// 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.
#ifndef CSSNumericArray_h
#define CSSNumericArray_h
#include "core/css/cssom/CSSNumericValue.h"
namespace blink {
// See CSSNumericArray.idl for more information about this class.
class CORE_EXPORT CSSNumericArray final : public ScriptWrappable {
WTF_MAKE_NONCOPYABLE(CSSNumericArray);
DEFINE_WRAPPERTYPEINFO();
public:
// blink internal
static CSSNumericArray* Create(CSSNumericValueVector values) {
return new CSSNumericArray(std::move(values));
}
static CSSNumericArray* FromNumberishes(
const HeapVector<CSSNumberish>& values) {
CSSNumericValueVector result;
for (const CSSNumberish& value : values) {
result.push_back(CSSNumericValue::FromNumberish(value));
}
return new CSSNumericArray(result);
}
void Trace(Visitor* visitor) {
visitor->Trace(values_);
ScriptWrappable::Trace(visitor);
}
unsigned length() const { return values_.size(); }
CSSNumericValue* AnonymousIndexedGetter(unsigned index) {
if (index < values_.size())
return values_[index].Get();
return nullptr;
}
private:
explicit CSSNumericArray(CSSNumericValueVector values)
: values_(std::move(values)) {}
CSSNumericValueVector values_;
};
} // namespace blink
#endif // CSSNumericArray_h
// 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.
// Represents the sum of one or more CSSNumericValues.
// https://drafts.css-houdini.org/css-typed-om-1/#cssmathsum
[
Exposed=(Window,PaintWorklet),
RaisesException=Constructor,
RuntimeEnabled=CSSTypedOM
] interface CSSNumericArray {
readonly attribute unsigned long length;
getter CSSNumericValue(unsigned long index);
};
......@@ -67,6 +67,8 @@ class CORE_EXPORT CSSNumericValue : public CSSStyleValue {
CSSNumericValueType type_;
};
using CSSNumericValueVector = HeapVector<Member<CSSNumericValue>>;
} // namespace blink
#endif // CSSNumericValue_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