Skip to content

[css-transforms-1] transform-origin: 0% not equivalent to 0px is confusing #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smfr opened this issue Jan 12, 2017 · 2 comments
Closed
Labels

Comments

@smfr
Copy link
Contributor

smfr commented Jan 12, 2017

https://www.w3.org/mid/525F2287.8050002@mcc.id.au

I think the behaviour of transform-origin, where lengths mean different
things depending on whether the element is an SVG element or not, isn't
great. It leads to questions like:

  • Why shouldn't 'transform-origin: 0px 0px' and 'transform-origin: 0%
    0%' mean the same thing? Surely 0% of anything is 0, and so that should
    be equivalent to 0px.

  • How do we treat 'transform-origin: calc(0% + 0px) calc(0% + 0px)'?

What about having something in the property value that explicitly opts
in to having values be relative to the SVG viewport rather than the
bounding box? For example:

transform-origin: viewport 50% 50%; /* middle of the viewport /
transform-origin: 50% 50%; /
middle of the bbox /
transform-origin: viewport 4px 4px; /
relative to viewport origin /
transform-origin: 4px 4px; /
relative to the bbox origin */

And then the UA style sheet could set

transform-origin: viewport 0 0;

on SVG elements.

Alternatively, since setting the transform origin to be anything
viewport relative except for the origin isn't that useful -- and could
be handled by translations in the 'transform' property -- we could just
add a single new value which means the viewport origin for SVG elements,
and the bbox origin for other elements:

transform-origin: auto;

This would then be the initial value, no need for a UA style sheet rule.
Percentages and lengths would always be relative to the bbox.

Even if we don't do either of these, and leave the "percentages are
interpreted differently" behaviour, we should define what happens with
calc()s that contain percentages.

@smfr smfr added the css-transforms-1 Current Work label Jan 12, 2017
@smfr smfr changed the title transform-origin: 0% not equivalent to 0px is confusing [css-transforms-1] transform-origin: 0% not equivalent to 0px is confusing Jan 13, 2017
@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed transform-origin: 0% != 0px, and agreed to the following resolutions:

RESOLUTION: no need to change anything for this issue. implementations just need to support transform-box
The full IRC log of that discussion
<dino> Topic: transform-origin: 0% != 0px
<dino> Github Topic: https://github.com/w3c/csswg-drafts/issues/895
<dino> dbaron: it's only different for SVG?
<dino> smfr: yes
<dino> ChrisL: it's not that crazy to have the UA stylesheet do different things for SVG and CSS
<dino> Github Issue: https://github.com/w3c/csswg-drafts/issues/895
<dino> dbaron: it's only different for SVG?
<dino> smfr: yes
<dino> ChrisL: it's not that crazy to have the UA stylesheet do different things for SVG and CSS
<dino> smfr: auto is one proposal. or a keyword 'viewport'
<dino> Rossen: i'd prefer 'auto' as a magic keyword. And this might be our only option.
<dino> Rossen: other comments?
<dino> TabAtkins: I like 'auto'
<dino> TabAtkins: proposal is that the current 0% becomes 'auto', and then we change 0% to be the same as 0px
<dino> smfr: so 'auto' would be different for CSS and SVG?
<dino> TabAtkins: I don't care about that as much as having 0% and 0px using the same base.
<dino> transform-origin will now accept an 'auto' value which will be the initial value. For CSS, that is equivalent to 50% 50%. For SVG, it's equivalent to 0px 0px. And, from now on, in SVG, % are in the same base as px, so relative to the element.
<dino> <discussion of what % means for CSS properties in SVG>
<dino> ChrisL: I want to make sure that we're not clipped to 0-100% for CSS in SVG stuff.
<dino> dino: definitely not for transform-origin
<dino> smfr: there is also a proposal for transform-box, which would affect what % are resolved against
<dino> smfr: this is in level 1, but i'm not sure there are implementations
<dino> birtles: we implemented it
<Rossen> dino: if we all implement the box values there is no need have the percentages change
<birtles> Gecko intent to ship has some background: https://groups.google.com/forum/#!topic/mozilla.dev.platform/ssV6H4_3WGU
<dino> s/box/transform-box/
<dino> birtles: Blink has it implemented behind a flag
<birtles> Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=595829
<dino> proposed resolution: no need to change anything for this issue. implementations just need to add transform-box, or behave as if you do implement it
<dino> RESOLUTION: no need to change anything for this issue. implementations just need to support transform-box
<BogdanBrinza> Edge doesn't have plans for (at least) next release or two since we don't support CSS transforms on SVG boxes yet, so the problem doesn't exist for us
<dino> smfr: so we think that heycam's comments are all addressed by transform-box
<dino> dbaron: yes
<TabAtkins> ScribeNick: TabAtkins

hubot pushed a commit to WebKit/WebKit-http that referenced this issue May 22, 2017
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.
<w3c/csswg-drafts#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: http://svn.webkit.org/repository/webkit/trunk@217236 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@smfr
Copy link
Contributor Author

smfr commented Nov 6, 2017

I don't think this issue covers anything that's not covered by issue 857.

@smfr smfr closed this as completed Nov 6, 2017
ryanhaddad pushed a commit to WebKit/WebKit that referenced this issue Dec 22, 2020
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.
<w3c/csswg-drafts#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:


Canonical link: https://commits.webkit.org/189361@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217236 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants