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

[css-typed-om] Allow CSSSkew and CSSPerspective to accept CSSMathValues.

Currently CSSSkew and CSSPerspective do not accept calc values
(CSSMathValues) because it requires type checking the calc value to see
if they match the right type. Since type checking and matching are
now implemented, we have all the machinery to accept CSSMathValues too.

This patch uses CSSNumericValueType.Matches* functions to check if
the CSSNumericValues passed in resolve to the right type.

We also (re)moved some DCHECKs.

We also deelted redundant tests in inlinestyle/properties/transform.html

Spec:
https://drafts.css-houdini.org/css-typed-om-1/#dom-cssperspective-cssperspective
https://drafts.css-houdini.org/css-typed-om-1/#dom-cssskew-cssskew

Bug: 789370
Change-Id: Ice30511b022885004a3a13cca21c8316dd82a271
Reviewed-on: https://chromium-review.googlesource.com/828001Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524342}
parent be9eef8a
......@@ -114,25 +114,6 @@ runInlineStylePropertyMapTests( {
invalidObjects: [CSS.px(4)]
});
let crashTestStrings = {
'skew(calc(5deg + 0.1rad))': 'skew(calc(10.7296deg))',
'skew(calc(5deg + 0.1rad), 5deg)': 'skew(calc(10.7296deg), 5deg)',
'skew(5deg, calc(5deg + 0.1rad))': 'skew(5deg, calc(10.7296deg))',
'skewX(calc(5deg + 0.1rad))': 'skewX(calc(10.7296deg))',
'skewY(calc(5deg + 0.1rad))': 'skewY(calc(10.7296deg))',
'perspective(calc(10px + 5em))': 'perspective(calc(10px + 5em))',
};
for (let inputString in crashTestStrings) {
test(() => {
testElement.style.transform = inputString;
let result = testElement.attributeStyleMap.get('transform');
assert_equals(result.constructor, CSSStyleValue,
'result is a base CSSStyleValue');
assert_equals(result.toString(), crashTestStrings[inputString]);
}, "Getting transform when it is set to " + inputString + " does not crash");
}
// TODO(meade): Remove/update this test once translate is supported.
test(function() {
testElement.style.transform = 'translateY(50px)';
......
This is a testharness.js-based test.
PASS Constructing a CSSPerspective with a keyword throws a TypeError
PASS Constructing a CSSPerspective with a double throws a TypeError
PASS Constructing a CSSPerspective with a unitless zero throws a TypeError
PASS Constructing a CSSPerspective with a string length throws a TypeError
PASS Constructing a CSSPerspective with a number CSSUnitValue throws a TypeError
PASS Constructing a CSSPerspective with a time dimension CSSUnitValue throws a TypeError
PASS Constructing a CSSPerspective with a CSSMathValue of angle type throws a TypeError
PASS Updating CSSPerspective.length with a keyword throws a TypeError
PASS Updating CSSPerspective.length with a double throws a TypeError
PASS Updating CSSPerspective.length with a unitless zero throws a TypeError
PASS Updating CSSPerspective.length with a string length throws a TypeError
PASS Updating CSSPerspective.length with a number CSSUnitValue throws a TypeError
PASS Updating CSSPerspective.length with a time dimension CSSUnitValue throws a TypeError
PASS Updating CSSPerspective.length with a CSSMathValue of angle type throws a TypeError
PASS CSSPerspective can be constructed from a length CSSUnitValue
PASS CSSPerspective.length can be updated to a length CSSUnitValue
FAIL CSSPerspective can be constructed from a CSSMathValue of length type Failed to construct 'CSSPerspective': Must pass length to CSSPerspective
FAIL CSSPerspective.length can be updated to a CSSMathValue of length type Failed to set the 'length' property on 'CSSPerspective': Must pass length to CSSPerspective
PASS Modifying CSSPerspective.is2D is a no-op
Harness: the test ran to completion.
This is a testharness.js-based test.
PASS Constructing a CSSSkew with a keyword throws a TypeError
PASS Constructing a CSSSkew with a double throws a TypeError
PASS Constructing a CSSSkew with a unitless zero throws a TypeError
PASS Constructing a CSSSkew with a string angle throws a TypeError
PASS Constructing a CSSSkew with a number CSSUnitValue throws a TypeError
PASS Constructing a CSSSkew with a time dimension CSSUnitValue throws a TypeError
PASS Constructing a CSSSkew with a CSSMathValue of length type throws a TypeError
PASS Updating CSSSkew.ax with a keyword throws a TypeError
PASS Updating CSSSkew.ax with a double throws a TypeError
PASS Updating CSSSkew.ax with a unitless zero throws a TypeError
PASS Updating CSSSkew.ax with a string angle throws a TypeError
PASS Updating CSSSkew.ax with a number CSSUnitValue throws a TypeError
PASS Updating CSSSkew.ax with a time dimension CSSUnitValue throws a TypeError
PASS Updating CSSSkew.ax with a CSSMathValue of length type throws a TypeError
PASS Updating CSSSkew.ay with a keyword throws a TypeError
PASS Updating CSSSkew.ay with a double throws a TypeError
PASS Updating CSSSkew.ay with a unitless zero throws a TypeError
PASS Updating CSSSkew.ay with a string angle throws a TypeError
PASS Updating CSSSkew.ay with a number CSSUnitValue throws a TypeError
PASS Updating CSSSkew.ay with a time dimension CSSUnitValue throws a TypeError
PASS Updating CSSSkew.ay with a CSSMathValue of length type throws a TypeError
PASS CSSSkew can be constructed from an angle CSSUnitValue and an angle CSSUnitValue
FAIL CSSSkew can be constructed from an angle CSSUnitValue and a CSSMathValue of angle type Failed to construct 'CSSSkew': CSSSkew does not support non-angles
FAIL CSSSkew can be constructed from a CSSMathValue of angle type and an angle CSSUnitValue Failed to construct 'CSSSkew': CSSSkew does not support non-angles
FAIL CSSSkew can be constructed from a CSSMathValue of angle type and a CSSMathValue of angle type Failed to construct 'CSSSkew': CSSSkew does not support non-angles
PASS CSSSkew.ax can be updated to an angle CSSUnitValue
FAIL CSSSkew.ax can be updated to a CSSMathValue of angle type Failed to set the 'ax' property on 'CSSSkew': Must specify an angle unit
PASS CSSSkew.ay can be updated to an angle CSSUnitValue
FAIL CSSSkew.ay can be updated to a CSSMathValue of angle type Failed to set the 'ay' property on 'CSSSkew': Must specify an angle unit
PASS Modifying CSSSkew.is2D is a no-op
Harness: the test ran to completion.
......@@ -10,48 +10,38 @@
namespace blink {
namespace {
bool IsValidPerspectiveLength(CSSNumericValue* value) {
return value &&
value->Type().MatchesBaseType(CSSNumericValueType::BaseType::kLength);
}
} // namespace
CSSPerspective* CSSPerspective::Create(CSSNumericValue* length,
ExceptionState& exception_state) {
if (length->GetType() != CSSStyleValue::StyleValueType::kLengthType) {
if (!IsValidPerspectiveLength(length)) {
exception_state.ThrowTypeError("Must pass length to CSSPerspective");
return nullptr;
}
if (length->ContainsPercent()) {
exception_state.ThrowTypeError(
"CSSPerspective does not support CSSNumericValues with percent units");
return nullptr;
}
return new CSSPerspective(length);
}
void CSSPerspective::setLength(CSSNumericValue* length,
ExceptionState& exception_state) {
if (length->GetType() != CSSStyleValue::StyleValueType::kLengthType) {
if (!IsValidPerspectiveLength(length)) {
exception_state.ThrowTypeError("Must pass length to CSSPerspective");
return;
}
if (length->ContainsPercent()) {
exception_state.ThrowTypeError(
"CSSPerspective does not support CSSNumericValues with percent units");
return;
}
length_ = length;
}
CSSPerspective* CSSPerspective::FromCSSValue(const CSSFunctionValue& value) {
DCHECK_EQ(value.FunctionType(), CSSValuePerspective);
DCHECK_EQ(value.length(), 1U);
if (!value.Item(0).IsPrimitiveValue() ||
!ToCSSPrimitiveValue(value.Item(0)).IsLength() ||
ToCSSPrimitiveValue(value.Item(0)).IsCalculated())
return nullptr;
CSSNumericValue* length =
CSSNumericValue::FromCSSValue(ToCSSPrimitiveValue(value.Item(0)));
// TODO(meade): This shouldn't happen once CSSNumericValue is fully
// implemented, so once that happens this check can be removed.
if (!length)
return nullptr;
DCHECK(!length->ContainsPercent());
return new CSSPerspective(length);
}
......@@ -85,4 +75,9 @@ const CSSFunctionValue* CSSPerspective::ToCSSValue(
return result;
}
CSSPerspective::CSSPerspective(CSSNumericValue* length)
: CSSTransformComponent(false /* is2D */), length_(length) {
DCHECK(length);
}
} // namespace blink
......@@ -48,8 +48,7 @@ class CORE_EXPORT CSSPerspective final : public CSSTransformComponent {
}
private:
CSSPerspective(CSSNumericValue* length)
: CSSTransformComponent(false /* is2D */), length_(length) {}
CSSPerspective(CSSNumericValue* length);
Member<CSSNumericValue> length_;
DISALLOW_COPY_AND_ASSIGN(CSSPerspective);
......
......@@ -14,11 +14,19 @@
namespace blink {
namespace {
bool IsValidSkewAngle(CSSNumericValue* value) {
return value &&
value->Type().MatchesBaseType(CSSNumericValueType::BaseType::kAngle);
}
} // namespace
CSSSkew* CSSSkew::Create(CSSNumericValue* ax,
CSSNumericValue* ay,
ExceptionState& exception_state) {
if ((ax->GetType() != CSSStyleValue::StyleValueType::kAngleType) ||
(ay->GetType() != CSSStyleValue::StyleValueType::kAngleType)) {
if (!IsValidSkewAngle(ax) || !IsValidSkewAngle(ay)) {
exception_state.ThrowTypeError("CSSSkew does not support non-angles");
return nullptr;
}
......@@ -26,45 +34,28 @@ CSSSkew* CSSSkew::Create(CSSNumericValue* ax,
}
void CSSSkew::setAx(CSSNumericValue* value, ExceptionState& exception_state) {
if (value->GetType() != CSSStyleValue::StyleValueType::kAngleType) {
if (!IsValidSkewAngle(value)) {
exception_state.ThrowTypeError("Must specify an angle unit");
return;
}
if (!value->IsUnitValue()) {
exception_state.ThrowTypeError("Calculated angles are not supported yet");
return;
}
ax_ = value;
}
void CSSSkew::setAy(CSSNumericValue* value, ExceptionState& exception_state) {
if (value->GetType() != CSSStyleValue::StyleValueType::kAngleType) {
if (!IsValidSkewAngle(value)) {
exception_state.ThrowTypeError("Must specify an angle unit");
return;
}
if (!value->IsUnitValue()) {
exception_state.ThrowTypeError("Calculated angles are not supported yet");
return;
}
ay_ = value;
}
CSSSkew* CSSSkew::FromCSSValue(const CSSFunctionValue& value) {
DCHECK_GT(value.length(), 0U);
const CSSPrimitiveValue& x_value = ToCSSPrimitiveValue(value.Item(0));
if (x_value.IsCalculated()) {
// TODO(meade): Decide what we want to do with calc angles.
return nullptr;
}
DCHECK(x_value.IsAngle());
switch (value.FunctionType()) {
case CSSValueSkew:
if (value.length() == 2U) {
const CSSPrimitiveValue& y_value = ToCSSPrimitiveValue(value.Item(1));
if (y_value.IsCalculated()) {
// TODO(meade): Decide what we want to do with calc angles.
return nullptr;
}
DCHECK(y_value.IsAngle());
return CSSSkew::Create(CSSNumericValue::FromCSSValue(x_value),
CSSNumericValue::FromCSSValue(y_value));
}
......@@ -109,4 +100,10 @@ const CSSFunctionValue* CSSSkew::ToCSSValue(SecureContextMode) const {
return result;
}
CSSSkew::CSSSkew(CSSNumericValue* ax, CSSNumericValue* ay)
: CSSTransformComponent(true /* is2D */), ax_(ax), ay_(ay) {
DCHECK(ax);
DCHECK(ay);
}
} // namespace blink
......@@ -53,8 +53,7 @@ class CORE_EXPORT CSSSkew final : public CSSTransformComponent {
}
private:
CSSSkew(CSSNumericValue* ax, CSSNumericValue* ay)
: CSSTransformComponent(true /* is2D */), ax_(ax), ay_(ay) {}
CSSSkew(CSSNumericValue* ax, CSSNumericValue* ay);
Member<CSSNumericValue> ax_;
Member<CSSNumericValue> ay_;
......
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