Commit c0e1f715 authored by George Steel's avatar George Steel Committed by Commit Bot

Add case to serialize kRotateAroundOrigin transform

Fix DCHECK failure which occurred when attempting to serialize such an
operation, which can occur due to the SVG transform presentation
attribute and is unreperesentable in CSS. As there is currently no
consensus on how to handle this case and there are no relatice lengths
in such operations, I am computing them as matrix() values.

See the CSSWG issue at https://github.com/w3c/csswg-drafts/issues/5011
to determine the correct way to handle this. I have proposed the
approach used here.

Add regression test (crashes without patch).

Change-Id: Ia116ead6c451cafc6fb222be3bb52362123bae3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2163758Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarKevin Ellis <kevers@chromium.org>
Commit-Queue: George Steel <gtsteel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763427}
parent 4a9ff3f1
......@@ -1844,6 +1844,14 @@ CSSValue* ComputedStyleUtils::ValueForTransformOperation(
rotate.Angle(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kRotateAroundOrigin: {
// TODO(https://github.com/w3c/csswg-drafts/issues/5011):
// Update this once there is consensus.
TransformationMatrix matrix;
operation.Apply(matrix, FloatSize(0, 0));
return ValueForTransformationMatrix(matrix, zoom,
/*force_matrix3d=*/false);
}
case TransformOperation::kSkewX: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewX);
......@@ -1891,10 +1899,6 @@ CSSValue* ComputedStyleUtils::ValueForTransformOperation(
// TODO(816803): The computed value in this case is not fully spec'd
// See https://github.com/w3c/css-houdini-drafts/issues/425
return CSSIdentifierValue::Create(CSSValueID::kNone);
default:
// The remaining operations are unsupported.
NOTREACHED();
return CSSIdentifierValue::Create(CSSValueID::kNone);
}
}
......
......@@ -11,9 +11,15 @@
<body>
<div id='testElement'></div>
<svg>
<g id='testSvgGroup'>
</g>
</svg>
<script>
var testElement = document.getElementById('testElement');
var testSvgGroup = document.getElementById('testSvgGroup');
var computedStyleMap = testElement.computedStyleMap();
test(function() {
......@@ -95,6 +101,17 @@ test(function() {
assert_equals(getComputedStyle(testElement).transform, 'matrix(2, 0, 0, 3, 4, 5)', 'Resolves as 2D');
}, 'transform preserved a matrix3d value which reperesents a 2d transform')
test(function() {
// Chosen for floating-point stability as 90deg was returning episilon
// for coefficients which should have been zero.
testSvgGroup.setAttribute('transform', 'rotate(45, 10, 0)');
var result = testSvgGroup.computedStyleMap().get('transform');
// TODO(https://github.com/w3c/csswg-drafts/issues/5011):
// Update this once there is consensus.
assert_equals(result.toString(), "matrix(0.707107, 0.707107, -0.707107, 0.707107, 2.92893, -7.07107)");
}, 'transform serializes a three-valued rotate from an svg presentation attribute value as a matrix.')
</script>
</body>
</html>
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