[csswg-drafts] [cssom] The way CSSStyleDeclaration exposes properties is not ideal. (#5649)

emilio has just created a new issue for https://github.com/w3c/csswg-drafts:

== [cssom] The way CSSStyleDeclaration exposes properties is not ideal. ==
Right now we only have a single interface that exposes the CSS property names as attributes ([`CSSStyleDeclaration`](https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface)), but no browser does it right, and the spec behavior is also not great.

In particular, the spec behavior means that you expose stuff like `fontFaceRule.style.color`, which doesn't quite make sense.

WebKit and Blink (though WebKit may have changed recently) historically use named getters for this (which is also not great, see https://github.com/w3c/csswg-drafts/issues/1089).

Note also that:

 * Per recent discussion with @gsnedders WebKit trunk may have changed behavior?
 * Per spec there's no exposure of descriptors for the rules that have them (but Blink / WebKit expose them as part of the named getters).

Gecko does something which IMO is better. Gecko exposes them as attributes as the spec describes, but on an interface that derives from `CSSStyleDeclaration` called [`CSS2Properties`](https://searchfox.org/mozilla-central/rev/25d5a4443a7e13cfa58eff38f1faa5e69f0b170f/dom/webidl/CSS2Properties.webidl.in#2) which we use for all the "style" declarations (so, inline style declarations, `CSSStyleRule.style`, `getComputedStyle`, `CSSPageRule.style`, and individual keyframe declarations). ([link](https://searchfox.org/mozilla-central/rev/25d5a4443a7e13cfa58eff38f1faa5e69f0b170f/layout/style/nsDOMCSSDeclaration.cpp#31), [link](https://searchfox.org/mozilla-central/search?q=public+nsDOMCSSDec&path=&case=false&regexp=false)). I think something like what Gecko does, but with similar interfaces for the declaration blocks that should have descriptors, like `@font-face` and `@counter-style`, would generally be much saner.

Since there's movement around here, and the interop story here is quite sad, I think there's quite a fair amount of room for improvement, and if we can align in a model that is both consistent and useful for developers it'd be great.

Does the thing I described above seem reasonable? Other ideas?

cc @gsnedders @foolip @andruud @xiaochengh @heycam 

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/5649 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 22 October 2020 18:03:51 UTC