Skip to content
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

[cssom] getComputedStyle only supports ::before/::after #2149

Closed
gsnedders opened this issue Dec 30, 2017 · 3 comments
Closed

[cssom] getComputedStyle only supports ::before/::after #2149

gsnedders opened this issue Dec 30, 2017 · 3 comments
Labels
cssom-1 Current Work

Comments

@gsnedders
Copy link
Contributor

gsnedders commented Dec 30, 2017

https://drafts.csswg.org/cssom/#extensions-to-the-window-interface

Roughly, from what I've tested:

  • Chrome, Firefox, and Safari all support gCS ::first-letter and ::first-line.
  • Firefox throws NS_ERROR_NOT_AVAILABLE for ::marker (and doesn't support ::marker AFAIK), Chrome doesn't support it so returns the element, and Safari does support ::marker and does support it for gCS
  • Firefox supports gCS ::placeholder, Chrome and Safari does not (despite supporting the feature)

Is there any reason not to allow all pseudo-elements for gCS?

@gsnedders gsnedders added the cssom-1 Current Work label Dec 30, 2017
gsnedders added a commit to gsnedders/web-platform-tests that referenced this issue Dec 30, 2017
@upsuper
Copy link
Member

upsuper commented Dec 30, 2017

I think it makes sense to support all pseudo-elements which the user-agent supports, and it probably should also be specified that what should happen when the pseudo-element is not supported.

Personally I think throwing an exception (maybe TypeError) is better than returning the style of the element, but I can accept argument on that.

Note that, Firefox currently throws NS_ERROR_NOT_AVAILABLE when getting property value from the object returned from gCS in that case, and gCS itself doesn't throw, which, I would think, is a bug. I think gCS should throw, or everything should work smoothly.

FWIW, there could be tricky cases for supporting returning all properties on all pseudo-elements, for example, since many pseudo-elements have only limited properties applied, user-agents may want to avoid computing the rest if possible, and may optimize their storage, which can lead to observable difference on returned value.

Also some properties which use used value rather than computed value as resolve value might be tricky in some cases, although it isn't clear to me what the cases would be.

@FremyCompany
Copy link
Contributor

Edge supports a broad range of them, and like Chrome we fallback to returning the style of the element if we are not able to return the pseudo element style. We are supposed to support -webkit-input-placeholder but I am not sure it's actually working in the end, this could be just a bug.

I believe the advantage of returning a functioning style object when asked about a pseudo-element you don't support is that you don't crash, with a bit of chance the script will do just fine with slighly wrong values.

@css-meeting-bot
Copy link
Member

The Working Group just discussed getComputedStyle only supports ::before/::after, and agreed to the following resolutions:

  • RESOLVED: getComputedStyle for pseudo elements that are not slotted is supported.
  • RESOLVED: Throw in this case
The full IRC log of that discussion <dael> Topic: getComputedStyle only supports ::before/::after
<dael> github:
<dael> github: https://github.com//issues/2149
<dael> gsnedders: getComputedStyle takes a second arg we could pass a pseudo element. Spec desn't agree with impl. It only allows some pseudo and impl allow any.
<dael> gsnedders: What do we do when it's invalid?
<dael> TabAtkins: Seems that we should support first-letter and first-line, but I don't see why not all.
<dael> emilio: Except slotted
<dael> TabAtkins: Yeah. We do still want some sort of magic thing.
<dael> TabAtkins: Slotted is first case of a pseudo being an alias for 1 or more elements. Aliases wouldn't work from this sort of example.
<dael> TabAtkins: We should prob make a term for things like slotted and things not like slotted and say it works for all things in that category.
<dael> Rossen: Currently it should work for non-slotted pseudo elements.
<dael> TabAtkins: Yes.
<dael> TabAtkins: I need to make it into 2 categories where slotted is only one in the second currently.
<dael> Rossen: Reasonable. Other optinos or objections?
<dael> RESOLVED: getComputedStyle for pseudo elements that are not slotted is supported.
<dael> gsnedders: What to do given an invalid pseudo element? All browsers return a css style declaration. FF throws if you trya nd access a property, everyone else returns the element style declaration and ignores the pseudo element.
<dael> TabAtkins: Returning element styles is...there's no reason to do that. Throwing would be best.
<dael> gsnedders: Nothing does that. So can it be web compat?
<dael> TabAtkins: FF doesn't let you touch it. Unless there's code to getgCS and not do anything I suspect we can throw.
<dael> fremy: Empty strings?
<dael> gsnedders: Reasonable. I'd prefer try throwing.
<dael> TabAtkins: At gCS call time.
<dael> ???: incl slotted?
<dael> TabAtkins: Yeah.
<TabAtkins> s/???/ewilligers/
<dael> Rossen: Do we throw for non-elements?
<dael> emilio: Yes.
<dael> Rossen: So this is not different.
<dael> TabAtkins: We're trying to say do the same.
<dael> Rossen: I'm trying to align whatever we do in that situation we should do it for this situation
<dael> fremy: If people call getComputedStyle with a placeholder we'll throw.
<dael> emilio: blink claims to support all eleemnts at parse time which is weird.
<dael> fremy: [missed]
<dael> emilio: Does gCS webkit get a result now? I guess not.
<dael> fremy: They work in Edge and Chrome they return.
<dael> emilio: gCS in ::webkit-foo
<dael> fremy: I think that's why we returnt he element style. People do random things we don't support and since Chrome does something we do something.
<dael> fremy: I'm fine saying we should throw but I won't be first to impl.
<dael> Rossen: In terms of defining behavior the most sensible thing is throw.
<dael> Rossen: Objections to that proposal?
<dael> RESOLVED: Throw in this case

emilio added a commit to emilio/csswg-drafts that referenced this issue Apr 11, 2018
emilio added a commit to emilio/csswg-drafts that referenced this issue Apr 11, 2018
emilio added a commit to emilio/csswg-drafts that referenced this issue Apr 11, 2018
emilio added a commit to emilio/web-platform-tests that referenced this issue Apr 11, 2018
@emilio emilio closed this as completed in 4020029 Apr 11, 2018
emilio added a commit to emilio/web-platform-tests that referenced this issue Apr 13, 2018
fergald pushed a commit to fergald/csswg-drafts that referenced this issue May 7, 2018
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