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

Support retrieval of content quads for elements with CSS transformations #787

Open
whimboo opened this issue Sep 23, 2024 · 7 comments
Open
Labels
blocked enhancement New feature or request module-browsingContext Browsing Context module

Comments

@whimboo
Copy link
Contributor

whimboo commented Sep 23, 2024

It would be beneficial to support the retrieval of content quads for elements with CSS transformations applied. Currently, this functionality lacks a uniform W3C specification, leading to inconsistent implementations across browsers, including differences in API naming. Both Chrome and Firefox, however, support content quad retrieval.

The content quad of an element should accurately reflect its current position and size, even during CSS transitions, and should be used instead of getBoundingClientRect() to get the actual position and size for performing precise actions on such elements.

Integrating this API directly into WebDriver BiDi would enable clients to use a dedicated command that works consistently across all browsers, eliminating the need for browser-specific implementations via script.evaluate or script.callFunction.

For Chrome, the DOM.getContentQuads() command is available in the Chrome DevTools Protocol, while Firefox implements this as Element.getBoxQuads().

@whimboo whimboo added enhancement New feature or request module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group labels Sep 23, 2024
@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed Support retrieval of content quads for elements with CSS transitions.

The full IRC log of that discussion <simonstewart> Topic: Support retrieval of content quads for elements with CSS transitions
<simonstewart> github: https://github.com//issues/787
<simonstewart> jgraham: some people want to retrieve content quads for elements. I don't know if that's different from calling getBoundingClientRect for an element, though it might have a nicer return value
<simonstewart> jgraham: isn't getBoundingClientRect affected by CSS Transform already?
<simonstewart> <quiet reading in the room>
<simonstewart> gsnedders: this does something with the document scale factor.
<simonstewart> gsnedders: It's not clear what the difference is.
<simonstewart> <people start reading browser source code to figure out what's happening>
<gsnedders> getClientRects, not getBoundingClientRect, because the Playwright API is returning all the rects.
<simonstewart> jgraham: No-one is clear what the difference is between getting content quads and getClientRects, so some clarification would be helpful.

@OrKoN
Copy link
Contributor

OrKoN commented Sep 27, 2024

I believe the difference is that quad returns 4 points whereas the rect returns only 2. So rect is always rectangular, while the quad can reflect the actual shape of the element after the transform. I think it can be still important for hit-testing.

@whimboo
Copy link
Contributor Author

whimboo commented Sep 27, 2024

Yes, this is actually for https://developer.mozilla.org/en-US/docs/Web/API/DOMQuad and is important (as I already mentioned) when elements are transformed via CSS.

Here an example: https://drafts.fxtf.org/geometry/#example-9bbe24bd

It looks like that we maybe should discuss it again today when we are all present?

@css-meeting-bot
Copy link
Member

The Browser Testing and Tools Working Group just discussed Support retrieval of content quads for elements with CSS transitions, and agreed to the following:

  • ACTION: jgraham to speak to Emilio and get advice on what we can do here
The full IRC log of that discussion <AutomatedTester> topic: Support retrieval of content quads for elements with CSS transitions
<AutomatedTester> github: https://github.com//issues/787
<simonstewart> https://test.csswg.org/harness/test/geometry-1_dev/
<whimboo> https://github.com/web-platform-tests/wpt/tree/fd25aeb946a8df94314cf6fb4fe63b46eee2cd8c/css/geometry
<gsnedders> https://wpt.fyi/results/css/geometry?run_id=5201124441456640&run_id=5179680340836352&run_id=5184785144348672 would be a better link for tests, rather than the old CSS WG Test Harness (which is the same tests)
<gsnedders> s/link for tests/link for test results/
<gsnedders> https://drafts.csswg.org/cssom-view/#dom-geometryutils-getboxquads seems like it should give a DOMQuad with what we want… if it were specified. Or implemented.
<gsnedders> c.f. https://wpt.fyi/results/css/cssom-view/idlharness.html?run_id=5201124441456640&run_id=5179680340836352&run_id=5184785144348672 for evidence of lack of implementation of getBoxQuads
<jgraham> jgraham: So the understanding I have is that getBoundingCLientRect returns a DOMRect, which is the bounds of a rectangle containing the element. For transformed elements that's different to the actual bounds of the element if those are non-rectangular. DOMQuads in https://drafts.fxtf.org/geometry/#DOMQuad represents the latter. This is what CDP
<jgraham> exposes via its API. There is a draft API for getting these values from content in CSSOM-view https://drafts.csswg.org/cssom-view/#dom-geometryutils-getboxquads however this is basically all TODO.
<jgraham> This is actually implemented in Firefox.
<jgraham> So the problem we have here is that in terms of a standard we don't have anything to point at to explain the behaviour of the requested API. We could implement it in Gecko and Chromium, but it would be nonstandard or implementation-defined. If we actually wrote a standard here we might as well finish CSSOM-view and then expose it to content
<jgraham> (assuming there's no compat issue), and then clients could use that via script. Having a BiDi only API here seems rather odd.
<davehunt> jgraham: we need someone from layout or from the CSS WG to help us out here. We should talk to Emilio
<AutomatedTester> ACTION: jgraham to speak to Emilio and get advice on what we can do here

@gsnedders
Copy link
Member

while Firefox implements this as Element.getBoxQuads()

Note this is effectively currently unspecified: https://drafts.csswg.org/cssom-view/#dom-geometryutils-getboxquads (though supported in Firefox behind a flag).

See w3c/csswg-drafts#10968.

@jgraham
Copy link
Member

jgraham commented Sep 27, 2024

w3c/csswg-drafts#10537 is an issue for defining getBoxQuads, which is a content API implementing this feature. I think this issue is blocked on having some usable definition of what getBoxQuads does, and if that definition is also tied to a DOM API I think it would make sense for clients to use that content API via script rather than having a special API in WebDriver that does the same thing.

@gsnedders
Copy link
Member

See also #769 / microsoft/playwright#32577:

Add support for getting content quads to ensure accurate clicking inside transformed elements. This is particularly relevant for tests involving transformed elements, as seen in tests/page/page-click.spec.ts.

@whimboo whimboo added blocked and removed needs-discussion Issues to be discussed by the working group labels Sep 27, 2024
@whimboo whimboo changed the title Support retrieval of content quads for elements with CSS transitions Support retrieval of content quads for elements with CSS transformations Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement New feature or request module-browsingContext Browsing Context module
Projects
None yet
Development

No branches or pull requests

5 participants