Commit 774c7751 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[css-typed-om] Add IDLs CSSMathNegate and CSSMathInvert.

This patch adds the new CSSMathValue subclasses CSSMathNegate and
CSSMathInvert. Note that we only implement the constructor and
attributes. More complicated things like typing or arithmetic will
be done in a later patch.

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

Bug: 776173
Change-Id: I7183df9c269db6eb799f93d39c0d8b1e541f7991
Reviewed-on: https://chromium-review.googlesource.com/743201
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512448}
parent 181b297d
...@@ -11,10 +11,18 @@ CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue ...@@ -11,10 +11,18 @@ CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue
CONSOLE MESSAGE: line 147: getter value CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathInvert : CSSMathValue
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: interface CSSMathMax : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
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: interface CSSMathProduct : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue
...@@ -278,10 +286,18 @@ CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue ...@@ -278,10 +286,18 @@ CONSOLE MESSAGE: line 147: interface CSSKeywordValue : CSSStyleValue
CONSOLE MESSAGE: line 147: getter value CONSOLE MESSAGE: line 147: getter value
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: setter value CONSOLE MESSAGE: line 147: setter value
CONSOLE MESSAGE: line 147: interface CSSMathInvert : CSSMathValue
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: interface CSSMathMax : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue CONSOLE MESSAGE: line 147: interface CSSMathMin : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
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: interface CSSMathProduct : CSSMathValue
CONSOLE MESSAGE: line 147: method constructor CONSOLE MESSAGE: line 147: method constructor
CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue CONSOLE MESSAGE: line 147: interface CSSMathSum : CSSMathValue
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
<script> <script>
'use strict'; 'use strict';
const gMathValueSubclasses = [ const gVariadicMathValueSubclasses = [
{ subclass: CSSMathSum, operator: 'sum' }, { subclass: CSSMathSum, operator: 'sum' },
{ subclass: CSSMathProduct, operator: 'product' }, { subclass: CSSMathProduct, operator: 'product' },
{ subclass: CSSMathMin, operator: 'min' }, { subclass: CSSMathMin, operator: 'min' },
{ subclass: CSSMathMax, operator: 'max' }, { subclass: CSSMathMax, operator: 'max' },
]; ];
for (const {subclass, operator} of gMathValueSubclasses) { for (const {subclass, operator} of gVariadicMathValueSubclasses) {
test(() => { test(() => {
assert_throws(new SyntaxError(), () => new subclass()); assert_throws(new SyntaxError(), () => new subclass());
}, 'Constructing a ' + subclass.name + ' with no arguments throws a SyntaxError'); }, 'Constructing a ' + subclass.name + ' with no arguments throws a SyntaxError');
...@@ -36,4 +36,35 @@ for (const {subclass, operator} of gMathValueSubclasses) { ...@@ -36,4 +36,35 @@ for (const {subclass, operator} of gMathValueSubclasses) {
}, subclass.name + '.operator is readonly'); }, subclass.name + '.operator is readonly');
} }
const gUnaryMathValueSubclasses = [
{ subclass: CSSMathNegate, operator: 'negate' },
{ subclass: CSSMathInvert, operator: 'invert' },
]
for (const {subclass, operator} of gUnaryMathValueSubclasses) {
test(() => {
const result1 = new subclass(CSS.number(0));
assert_equals(result1.operator, operator);
assert_style_value_equals(result1.value, CSS.number(0));
const result2 = new subclass(0);
assert_equals(result2.operator, operator);
assert_style_value_equals(result2.value, CSS.number(0));
}, subclass.name + ' can be constructed from a single numberish value');
test(() => {
let result = new subclass(CSS.number(1));
assert_throws(new TypeError(), () => result.operator = 'foo');
}, subclass.name + '.operator is readonly');
test(() => {
let result = new subclass(0);
result.value = CSS.number(1);
assert_style_value_equals(result.value, CSS.number(1));
result.value = 2;
assert_style_value_equals(result.value, CSS.number(2));
}, subclass.name + '.value can be updated with a numberish value');
}
</script> </script>
...@@ -638,12 +638,22 @@ interface CSSKeywordValue : CSSStyleValue ...@@ -638,12 +638,22 @@ interface CSSKeywordValue : CSSStyleValue
getter value getter value
method constructor method constructor
setter value setter value
interface CSSMathInvert : CSSMathValue
attribute @@toStringTag
getter value
method constructor
setter value
interface CSSMathMax : CSSMathValue interface CSSMathMax : CSSMathValue
attribute @@toStringTag attribute @@toStringTag
method constructor method constructor
interface CSSMathMin : CSSMathValue interface CSSMathMin : CSSMathValue
attribute @@toStringTag attribute @@toStringTag
method constructor method constructor
interface CSSMathNegate : CSSMathValue
attribute @@toStringTag
getter value
method constructor
setter value
interface CSSMathProduct : CSSMathValue interface CSSMathProduct : CSSMathValue
attribute @@toStringTag attribute @@toStringTag
method constructor method constructor
......
...@@ -74,8 +74,10 @@ core_idl_files = ...@@ -74,8 +74,10 @@ core_idl_files =
"css/cssom/CSSImageValue.idl", "css/cssom/CSSImageValue.idl",
"css/cssom/CSSKeywordValue.idl", "css/cssom/CSSKeywordValue.idl",
"css/cssom/CSSMatrixComponent.idl", "css/cssom/CSSMatrixComponent.idl",
"css/cssom/CSSMathInvert.idl",
"css/cssom/CSSMathMax.idl", "css/cssom/CSSMathMax.idl",
"css/cssom/CSSMathMin.idl", "css/cssom/CSSMathMin.idl",
"css/cssom/CSSMathNegate.idl",
"css/cssom/CSSMathSum.idl", "css/cssom/CSSMathSum.idl",
"css/cssom/CSSMathProduct.idl", "css/cssom/CSSMathProduct.idl",
"css/cssom/CSSMathValue.idl", "css/cssom/CSSMathValue.idl",
......
// 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 CSSMathInvert_h
#define CSSMathInvert_h
#include "core/css/cssom/CSSMathValue.h"
namespace blink {
// Represents the inverse of a CSSNumericValue.
// See CSSMathInvert.idl for more information about this class.
class CORE_EXPORT CSSMathInvert : public CSSMathValue {
WTF_MAKE_NONCOPYABLE(CSSMathInvert);
DEFINE_WRAPPERTYPEINFO();
public:
// The constructor defined in the IDL.
static CSSMathInvert* Create(const CSSNumberish& arg) {
return new CSSMathInvert(CSSNumericValue::FromNumberish(arg));
}
String getOperator() const final { return "invert"; }
void value(CSSNumberish& value) { value.SetCSSNumericValue(value_); }
void setValue(const CSSNumberish& value) {
value_ = CSSNumericValue::FromNumberish(value);
}
// From CSSStyleValue.
StyleValueType GetType() const final { return CSSStyleValue::kInvertType; }
void Trace(Visitor* visitor) override {
visitor->Trace(value_);
CSSMathValue::Trace(visitor);
}
private:
explicit CSSMathInvert(CSSNumericValue* value)
: CSSMathValue(), value_(value) {}
Member<CSSNumericValue> value_;
};
} // namespace blink
#endif // CSSMathInvert_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 inverse a CSSNumericValue.
// https://drafts.css-houdini.org/css-typed-om-1/#cssmathinvert
[
Constructor(CSSNumberish arg),
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM
] interface CSSMathInvert : CSSMathValue {
attribute CSSNumberish value;
};
// 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 CSSMathNegate_h
#define CSSMathNegate_h
#include "core/css/cssom/CSSMathValue.h"
namespace blink {
// Represents the negation of a CSSNumericValue.
// See CSSMathNegate.idl for more information about this class.
class CORE_EXPORT CSSMathNegate : public CSSMathValue {
WTF_MAKE_NONCOPYABLE(CSSMathNegate);
DEFINE_WRAPPERTYPEINFO();
public:
// The constructor defined in the IDL.
static CSSMathNegate* Create(const CSSNumberish& arg) {
return new CSSMathNegate(CSSNumericValue::FromNumberish(arg));
}
String getOperator() const final { return "negate"; }
void value(CSSNumberish& value) { value.SetCSSNumericValue(value_); }
void setValue(const CSSNumberish& value) {
value_ = CSSNumericValue::FromNumberish(value);
}
// From CSSStyleValue.
StyleValueType GetType() const final { return CSSStyleValue::kNegateType; }
void Trace(Visitor* visitor) override {
visitor->Trace(value_);
CSSMathValue::Trace(visitor);
}
private:
explicit CSSMathNegate(CSSNumericValue* value)
: CSSMathValue(), value_(value) {}
Member<CSSNumericValue> value_;
};
} // namespace blink
#endif // CSSMathNegate_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 negation of a CSSNumericValue.
// https://drafts.css-houdini.org/css-typed-om-1/#cssmathnegate
[
Constructor(CSSNumberish arg),
Exposed=(Window,PaintWorklet),
RuntimeEnabled=CSSTypedOM
] interface CSSMathNegate : CSSMathValue {
attribute CSSNumberish value;
};
...@@ -45,6 +45,15 @@ CSSNumericValue* CSSNumericValue::FromCSSValue(const CSSPrimitiveValue& value) { ...@@ -45,6 +45,15 @@ CSSNumericValue* CSSNumericValue::FromCSSValue(const CSSPrimitiveValue& value) {
return CSSUnitValue::FromCSSValue(value); return CSSUnitValue::FromCSSValue(value);
} }
/* static */
CSSNumericValue* CSSNumericValue::FromNumberish(const CSSNumberish& value) {
if (value.IsDouble()) {
return CSSUnitValue::Create(value.GetAsDouble(),
CSSPrimitiveValue::UnitType::kNumber);
}
return value.GetAsCSSNumericValue();
}
CSSNumericValue* CSSNumericValue::to(const String& unit_string, CSSNumericValue* CSSNumericValue::to(const String& unit_string,
ExceptionState& exception_state) { ExceptionState& exception_state) {
CSSPrimitiveValue::UnitType unit = UnitFromName(unit_string); CSSPrimitiveValue::UnitType unit = UnitFromName(unit_string);
......
...@@ -27,6 +27,8 @@ class CORE_EXPORT CSSNumericValue : public CSSStyleValue { ...@@ -27,6 +27,8 @@ class CORE_EXPORT CSSNumericValue : public CSSStyleValue {
// Blink-internal ways of creating CSSNumericValues. // Blink-internal ways of creating CSSNumericValues.
static CSSNumericValue* parse(const String& css_text, ExceptionState&); static CSSNumericValue* parse(const String& css_text, ExceptionState&);
static CSSNumericValue* FromCSSValue(const CSSPrimitiveValue&); static CSSNumericValue* FromCSSValue(const CSSPrimitiveValue&);
// https://drafts.css-houdini.org/css-typed-om-1/#rectify-a-numberish-value
static CSSNumericValue* FromNumberish(const CSSNumberish& value);
// Methods defined in the IDL. // Methods defined in the IDL.
virtual CSSNumericValue* add(const CSSNumericValue*, ExceptionState&) { virtual CSSNumericValue* add(const CSSNumericValue*, ExceptionState&) {
......
...@@ -29,10 +29,12 @@ class CORE_EXPORT CSSStyleValue : public ScriptWrappable { ...@@ -29,10 +29,12 @@ class CORE_EXPORT CSSStyleValue : public ScriptWrappable {
kAngleType, kAngleType,
kFlexType, kFlexType,
kFrequencyType, kFrequencyType,
kInvertType,
kKeywordType, kKeywordType,
kLengthType, kLengthType,
kMaxType, kMaxType,
kMinType, kMinType,
kNegateType,
kNumberType, kNumberType,
kPercentType, kPercentType,
kPositionType, kPositionType,
......
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