Support transform-box to switch sizing box in SVG
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 19:19:24 +0000 (19:19 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 May 2017 19:19:24 +0000 (19:19 +0000)
commit0217bb40c0fe903c12e99460299bb36e84808751
tree1b1ea8ff313995b53f0e563a57f51ad7e2bb265b
parent321324d0ef6c4c8a398f534fe44e56ec1d46f658
Support transform-box to switch sizing box in SVG
https://bugs.webkit.org/show_bug.cgi?id=145783

Reviewed by Dean Jackson.

Source/WebCore:

Add support for the CSS "transform-box" property, as described at
<https://drafts.csswg.org/css-transforms/#transform-box>.

This changes the behavior of percentage values in transform-origin in SVG.
When these were added in r110532, percentage values in transform-origin were made
relative to the bounding box, but absolute values relative to the view box.
<https://github.com/w3c/csswg-drafts/issues/895> has concluded that this behavior
is confusing. The new behavior is that, for SVG elements, both absolute and
percentage values are relative to the reference box, which is specified by the
new transform-box property.

The initial value for transform-box is border-box, with the svg.css UA stylesheet
supplying a default of view-box for the relevant SVG elements per
<https://www.w3.org/TR/SVG2/styling.html#UAStyleSheet>.

For non-SVG elements, the used value is always border-box, so there is no change
in behavior.

Tests: fast/css/transform-box-parsing.html
       svg/transforms/svg-transform-box.html

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::operator TransformBox):
* css/CSSProperties.json:
* css/CSSValueKeywords.in:
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::parseSingleValue):
* css/svg.css:
(*:not(svg),):
(*): Deleted.
(html|* > svg): Deleted.
* page/animation/AnimationBase.cpp:
(WebCore::AnimationBase::computeTransformedExtentViaTransformList):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::applyTransform): The transformOriginX().isPercent() tests
were added to support the weird "% values are relative to bounding box" in SVG. Now
it's up to the caller to pass a non-zero origin when that matters, and
SVGGraphicsElement::animatedLocalTransform() is the only caller that does so.
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::hasTransform):
(WebCore::RenderStyle::transformBox):
(WebCore::RenderStyle::setTransformBox):
(WebCore::RenderStyle::initialTransformBox):
* rendering/style/RenderStyleConstants.h:
* rendering/style/StyleTransformData.cpp:
(WebCore::StyleTransformData::StyleTransformData):
(WebCore::StyleTransformData::operator==):
* rendering/style/StyleTransformData.h:
* svg/SVGGraphicsElement.cpp:
(WebCore::SVGGraphicsElement::animatedLocalTransform): Consult the transform-box
style to compute the reference box as the bounding box, or the view box.

Source/WebInspectorUI:

Add transform-box to the list of autocompletions.

* UserInterface/External/CodeMirror/css.js:

LayoutTests:

Modify tests that relied on the old "% values relative to the bounding box" behavior,
and new tests for parsing and rendering with transform-box.

* fast/css/transform-box-parsing.html: Added.
* svg/transforms/change-transform-origin-css.xhtml:
* svg/transforms/change-transform-origin-presentation-attribute.xhtml:
* svg/transforms/percent-transform-values.xhtml:
* svg/transforms/svg-transform-box-expected.html: Added.
* svg/transforms/svg-transform-box.html: Added.
* svg/transforms/transform-origin-css-property.xhtml:
* transforms/svg-vs-css.xhtml:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217236 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/transform-box-parsing-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/transform-box-parsing.html [new file with mode: 0644]
LayoutTests/svg/transforms/change-transform-origin-css.xhtml
LayoutTests/svg/transforms/change-transform-origin-presentation-attribute.xhtml
LayoutTests/svg/transforms/percent-transform-values.xhtml
LayoutTests/svg/transforms/svg-transform-box-expected.html [new file with mode: 0644]
LayoutTests/svg/transforms/svg-transform-box.html [new file with mode: 0644]
LayoutTests/svg/transforms/transform-origin-css-property.xhtml
LayoutTests/transforms/svg-vs-css.xhtml
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSPrimitiveValueMappings.h
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/CSSValueKeywords.in
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/css/svg.css
Source/WebCore/page/animation/AnimationBase.cpp
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/RenderStyleConstants.h
Source/WebCore/rendering/style/StyleTransformData.cpp
Source/WebCore/rendering/style/StyleTransformData.h
Source/WebCore/svg/SVGGraphicsElement.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/External/CodeMirror/css.js