Skip to content

[cssom] Don't use "applies to" to define getComputedStyle behavior #3678

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

Open
AmeliaBR opened this issue Feb 26, 2019 · 17 comments
Open

[cssom] Don't use "applies to" to define getComputedStyle behavior #3678

AmeliaBR opened this issue Feb 26, 2019 · 17 comments
Assignees
Labels
cssom-1 Current Work

Comments

@AmeliaBR
Copy link
Contributor

The definition of resolved values in CSSOM — which are used in getComputedStyle results — currently includes sets of properties where the resolved value switches between the used value and the computed value depending on whether "the property applies to the element or pseudo-element".

As discussed in #3414 (comment), this is problematic because "applies to" isn't strictly defined for many properties in a way that can be used in normative tests. And the conclusion of the group in that discussion is that it would be better to fix the resolved value definition than to make "applies to" in property definition boxes as strict as would be required.

Since the used vs computed behavior is about legacy compat, the first step could be to review current implementations more carefully. Then maybe we can find a better definition for when the result switches from one to the other.

@AmeliaBR AmeliaBR added the cssom-1 Current Work label Feb 26, 2019
@emilio
Copy link
Collaborator

emilio commented May 11, 2019

Some interop bugs:

That's from a quick skim. I'll try to get engines to align here.

@emilio
Copy link
Collaborator

emilio commented May 11, 2019

@emilio
Copy link
Collaborator

emilio commented May 11, 2019

@emilio
Copy link
Collaborator

emilio commented May 11, 2019

So for https://drafts.csswg.org/cssom/#resolved-value-special-case-property-like-height with that case the only thing left is to define when they're resolved and how.

In Gecko, the check is "The element has a CSS layout box, and either the computed value of display is not inline, or the element is a replaced element".

In WebKit / Blink the check is "The element has a layout box, and IsBox() returns true for that". I'm not sure what that means exactly, would need to dig. But I suspect there's more behavior differences for e.g., SVG elements with display different than inline or such. The Gecko behavior is very easy to spec of course, but I think the Blink behavior also makes sense, so want to understand it better.

@kojiishi or @mstensho, do you know what would be a good-ish definition of what LayoutObject::IsBox() means in Blink? I get it means everything that inherits from LayoutBox, but that's not something that I could conceivably put into a spec.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue May 12, 2019
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

--HG--
extra : moz-landing-system : lando
mykmelez pushed a commit to mykmelez/gecko that referenced this issue May 12, 2019
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780
@kojiishi
Copy link
Contributor

In WebKit / Blink the check is "The element has a layout box, and IsBox() returns true for that".

It means, for non-SVG, the element is not text nor an inline box (e.g., span). Atomic inlines (replaced elements and inline block) are IsBox() true, so that might be one difference.

For SVG, I'm not an expert, but generally using IsBox() for SVG objects is not recommended because it often returns unexpected values. For instance, it is false for SVGContainer but true for SVGText.

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 16, 2019
The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1527392
gecko-commit: d51f3432e142ef24333b125087f5fccc2fbc366a
gecko-integration-branch: central
gecko-reviewers: mats
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 16, 2019
The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1527392
gecko-commit: d51f3432e142ef24333b125087f5fccc2fbc366a
gecko-integration-branch: central
gecko-reviewers: mats
@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

w3c/svgwg#349 is another issue, seems like Blink returns used values for <rect>, <foreignObject> and <image>...

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

https://chromium.googlesource.com/chromium/src/+/269ecd52bd4e0ec15a70924b089589f9bfe26ee0 is the commit that introduced that, for my own reference. cc @fsoder

@fsoder
Copy link

fsoder commented Jun 24, 2019

For SVG elements Blink essentially follows "applies to".

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

@fsoder Seems like other than Blink every engine uses "CSS layout box which isn't a replaced inline element", would you be open to revert that patch? What <svg> elements does width apply to?

@fsoder
Copy link

fsoder commented Jun 24, 2019

I suggested returning computed values in w3c/svgwg#349 - an issue that I filed in response to a bug report - which would indicate level of author interest.
<image>, <rect> and <foreignObject> are the relevant elements IIRC.

@AmeliaBR
Copy link
Contributor Author

width and height are extended to certain SVG elements (without CSS boxes) in https://svgwg.org/svg2-draft/geometry.html#Sizing

If you're implementing support for those properties within an SVG layout context, then the properties apply to the element as far as computed/resolved styles are concerned. But maybe we should be stating that explicitly?

Can we modify an "applies to" line in a partial property definition box? (ping @tabatkins)

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

Sure but do we really want them to return the used value? I always thought of the resolved value thing as a whole as a compatibility issue, rather than a feature.

@AmeliaBR
Copy link
Contributor Author

@emilio, see the discussion in w3c/svgwg#349. The general consensus was consistency of author expectations (as in https://crbug.com/772707). Most properties that accept a length convert it to px when retrieved from getComputedStyle().

But, the current behavior in Blink results in an inconsistency between width/height (resolved value is used value, AKA always px) and the other SVG geometry properties (resolved value is computed value).

For this issue, the question is: How can we define the legacy requirements for resolved value in a way that is independent of "applies to"? Only then can we talk about whether there are contexts where a property applies to an element, but there is no legacy requirement for returning used values in getComputedStyle.

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

Would people be fine if I updated the spec to say that the width and height used value are returned when:

  • The element has a CSS layout box (thus no SVG layout), and...
  • The element is not a non-replaced inline element.

I think that matches all of WebKit / Blink / Gecko, per all the comments here, modulo blink resolving these for these three svg elements.

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

Most properties that accept a length convert it to px when retrieved from getComputedStyle().

(Also this is not true, these properties are the exception, not the rule)

@emilio
Copy link
Collaborator

emilio commented Jun 24, 2019

Oh, though according to that Chromium issue, safari does return used value here as well? :(

@emilio
Copy link
Collaborator

emilio commented Jun 25, 2019

Ok, so safari doesn't return the used value (per testing in https://phabricator.services.mozilla.com/D35651). Firefox does return something similar to the used value if display is different than inline (and I consider this a bug).

So we probably still can decide what to do. I'd prefer to change the spec to say "The element has a CSS layout box (thus no SVG layout), and isn't a replaced inline box.", but we could also go for the Blink behavior and add the whitelist of svg elements for which we return the used value...

marcoscaceres pushed a commit to web-platform-tests/wpt that referenced this issue Jul 23, 2019
The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1527392
gecko-commit: d51f3432e142ef24333b125087f5fccc2fbc366a
gecko-integration-branch: central
gecko-reviewers: mats
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 4, 2019
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

UltraBlame original commit: d51f3432e142ef24333b125087f5fccc2fbc366a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 4, 2019
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

UltraBlame original commit: d51f3432e142ef24333b125087f5fccc2fbc366a
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 4, 2019
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780

UltraBlame original commit: d51f3432e142ef24333b125087f5fccc2fbc366a
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this issue May 1, 2025
…ues. r=mats

The spec says that when there's no box or the property doesn't apply, the
computed value should be returned.

That's not what we're doing right now, we're clamping by min-/max- values, which
is wrong.

This patch makes us match other engines and the spec, and it's an attempt to get
interop on resolved values in:

  w3c/csswg-drafts#3678

WebKit fails the WPT test, but due to a different reason:

  https://bugs.webkit.org/show_bug.cgi?id=197814

Differential Revision: https://phabricator.services.mozilla.com/D30780
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cssom-1 Current Work
Projects
None yet
Development

No branches or pull requests

4 participants