8000 [cssom-view-1] Added definition of getBoxQuads() by jogibear9988 · Pull Request #10538 · w3c/csswg-drafts · GitHub
Skip to content

[cssom-view-1] Added definition of getBoxQuads()#10538

Open
jogibear9988 wants to merge 21 commits into
w3c:mainfrom
jogibear9988:patch-1
Open

[cssom-view-1] Added definition of getBoxQuads()#10538
jogibear9988 wants to merge 21 commits into
w3c:mainfrom
jogibear9988:patch-1

Conversation

@jogibear9988
Copy link
Copy Markdown

@jogibear9988 jogibear9988 commented Jul 8, 2024

Fixes #10537

A linked issue:
#10514

A firefox issue with a little bit of description:
https://bugzilla.mozilla.org/show_bug.cgi?id=1107559

A polyfill for the API
https://github.com/jogibear9988/getBoxQuadsPolyfill

@svgeesus svgeesus changed the title [css-spec-shortname-1] https://github.com/w3c/csswg-drafts/issues/10537 [cssom-view-1] https://github.com/w3c/csswg-drafts/issues/10537 Jul 8, 2024
@jogibear9988
Copy link
Copy Markdown
Author

One issues atm:
My polyfill only works for 2D transformations, 3D with perspective do not work (yet). Have to figure out how to do this. Cause of that, also my spec only works for 2D. I've found some spect for the 3D matrix, wich then also could maybe reused: https://drafts.csswg.org/css-transforms-2/#accumulated-3d-transformation-matrix-computation

@SebastianZ SebastianZ changed the title [cssom-view-1] https://github.com/w3c/csswg-drafts/issues/10537 [cssom-view-1] Added definition of getBoxQuads() May 12, 2025
@SebastianZ
Copy link
Copy Markdown
Contributor

I think it makes more sense to add another option to getBoxQuads() to consider the transformed coordinates instead of introducing a separate function getCompleteTransform() for that.

I imagine something like getBoxQuads({considerTransformations: true}).

Sebastian

@jogibear9988
Copy link
Copy Markdown
Author

One issues atm: My polyfill only works for 2D transformations, 3D with perspective do not work (yet). Have to figure out how to do this. Cause of that, also my spec only works for 2D. I've found some spect for the 3D matrix, wich then also could maybe reused: https://drafts.csswg.org/css-transforms-2/#accumulated-3d-transformation-matrix-computation

should be fixed in current polyfill

@jogibear9988
Copy link
Copy Markdown
Author

jogibear9988 commented May 12, 2025

I think it makes more sense to add another option to getBoxQuads() to consider the transformed coordinates instead of introducing a separate function getCompleteTransform() for that.

I imagine something like getBoxQuads({considerTransformations: true}).

Sebastian

it's in a extra method, cause it is used from other functions in the spec (like convertPointFromNode). And convertPointFromNode use it multiple times

@gsnedders gsnedders added Agenda+ and removed Agenda+ labels May 14, 2025
Copy link
Copy Markdown
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks like a good start. Please look at how other specs (specially recent ones) use bikeshed in order to get the formatting and references correct. Also this needs to work in terms of nodes and boxes, not elements.

Comment thread cssom-view-1/Overview.bs Outdated

The <dfn method for=GeometryUtils lt="getBoxQuads(options)|getBoxQuads()">getBoxQuads(<var>options</var>)</dfn> method must run the following steps:

The helper method getCompleteTransform(anchestor) must run the following steps:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to get the element as a parameter, and use <div algorithm> for this for example:

<div algorithm="get the complete transform">
  In order to <dfn export>get the complete transform</dfn> of an node <var>node</var> relative to a node <var>ancestor</ancestor> ...
</div>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added node to helper function

Comment thread cssom-view-1/Overview.bs Outdated

test block in inline
1. let currentElement be the element getCompleteTransform() called on.
2. let transformationMatrix be the current transformation matrix of currentElement (https://www.w3.org/TR/css-transforms-2/#ctm)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use bikeshed references for this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should I use a bikeshed reference? (Is there an editor wich helps in editing bs files)

Comment thread cssom-view-1/Overview.bs Outdated

<ol>
<li><p class=issue>...
1. get the resulting matrix between the element and the document.defaultView via the algorithm defined in getCompleteTransform
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these algorithms need to be in terms of nodes, as GeometryUtils also applies to text nodes and such.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is node correct? Or should it be "GeometryNode"?
image

Comment thread cssom-view-1/Overview.bs Outdated
- 'border': no change
- 'margin': x - margin.left, y - margin.top
- 'padding': x + border.leftWidth, y + border.topWidth
- 'content': x + border.leftWidth + padding.left, y + border.topWidth + padding.top
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually based on the computed style but on the actual used padding box etc. Those boxes are defined already elsewhere and we should reuse the definitions.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really find where I should link to.
maybe: https://drafts.csswg.org/css2/#Computing_widths_and_margins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really find where I should link to. maybe: https://drafts.csswg.org/css2/#Computing_widths_and_margins

Pretty sure those boxes are defined here: https://drafts.csswg.org/css-box-4/#box-edges

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I need to link to the Algorythm how they are calculated, or is this enough?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I need to link to the Algorythm how they are calculated, or is this enough?

There is no algorithm like that for these. They are defined in English instead. Browsers have algorithms internally that match those descriptions and can call into those when a spec says to do something with one of these boxes, so linking to their definitions is enough to unambiguously tell an implementer what needs to happen.

More modern specs like to define their concepts in terms of algorithms to derive them, because that makes implementation easier and leaves less room for creative (mis-)interpretation of the definition.

TL;DR: You want to link to a concept's definition when using it. Whether that is an algorithm or not doesn't matter.

@whimboo
Copy link
Copy Markdown

whimboo commented Jul 8, 2025

Hi @jogibear9988, would you maybe have the time to follow-up on the review from Emilio? Thanks

@jogibear9988
Copy link
Copy Markdown
Author

@emilio
is it okay like now?

Copy link
Copy Markdown
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs a bit of work to get the spec into a reasonable shape, but looks in the right direction. Thanks!

Comment thread cssom-view-1/Overview.bs Outdated
points are flattened (3d transform), z=0. like getClientRect

test block in inline
1. let currentElement be node.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentNode, right? I think this should use <var>current</var> and other bikeshed markup to display properly.

Comment thread cssom-view-1/Overview.bs Outdated
1. let currentElement be node.
2. let transformationMatrix be the current transformation matrix of currentElement (https://www.w3.org/TR/css-transforms-2/#ctm)
3. while currentElement is not null do
<ol>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need the <ol>?

Comment thread cssom-view-1/Overview.bs Outdated

The <dfn method for=GeometryUtils lt="getBoxQuads(options)|getBoxQuads()">getBoxQuads(<var>options</var>)</dfn> method must run the following steps:

The helper method getCompleteTransform(node, anchestor) must run the following steps:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should probably add a <dfn> so that you can reference this properly elsewhere.

Comment thread cssom-view-1/Overview.bs Outdated

viewport boxes are all the same
<ol>
1. create an array as result container
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let |result| be an empty [=list=] of [=DOMQuad=] objects. etc, please look at existing bikeshed files to see how to make this work.

Comment thread cssom-view-1/Overview.bs Outdated
viewport boxes are all the same
<ol>
1. create an array as result container
2. for each css-fragment of the element run the following steps
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of what element? Probably of this? Also fragment should link to a definition.

Comment thread cssom-view-1/Overview.bs Outdated
- 'padding': https://drafts.csswg.org/css-box-4/#box-edges - use the padding-box
- 'content': https://drafts.csswg.org/css-box-4/#box-edges - use the content-box
3. create a DomQuad from the rect via DOMQuad.fromRect
4. Calculate the resulting transformation matrix between the element and options.realtiveTo (if relativeTo is unset use window.defaultView) via the algorithm defined in getCompleteTransform
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window.defaultView is not a thing, also s/realtiveTo/relativeTo.

This should be untransforming the rect to the layout viewport if there's no relativeTo.

Comment thread cssom-view-1/Overview.bs Outdated

<ol>
<li><p class=issue>...
1. transform each point of the DOMQuad via convertPointFromNode
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should link to convertPointFromNode, but also probably should have more precise details like:

 * Let <var>p1</var> be the result of calling [=convertFromFromNode=] with <var>quad</var>.p1, <var>from</var> and <var>options</var>.
 * ...
 * Return a new [=DOMQuad=] with <var>p1</var>...

Comment thread cssom-view-1/Overview.bs Outdated

<ol>
<li><p class=issue>...
1. get the resulting matrix between the node and the document.defaultView via the algorithm defined in getCompleteTransform
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give these meaningful names like:

 * Let <var>thisTransformToViewport</var> be the result of calling [=getCompleteTransform=] with <var>this</var> and <var>this</var>' [=associated document=].
 * Let <var>fromTransformToViewport</var> be the result of ...
 * Invert <var>fromTransformToViewport</var>.
 * ...

Then reference those.

Comment thread cssom-view-1/Overview.bs Outdated
- 'border': no change
- 'margin': x - margin.left, y - margin.top
- 'padding': x + border.leftWidth, y + border.topWidth
- 'content': x + border.leftWidth + padding.left, y + border.topWidth + padding.top
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, refer to standard terms. It seems ResizeObserver refers to the CSS2 border box area, etc.

Comment thread cssom-view-1/Overview.bs Outdated
1. get the resulting matrix between the node and the document.defaultView via the algorithm defined in getCompleteTransform
2. get the resulting matrix between the from and the document.defaultView via the algorithm defined in getCompleteTransform
3. inverse the matrix in 2.
4. Depending on the value of options.fromBox modify the point with the calculated style values of the element.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use <var>point</var> etc.

@whimboo
Copy link
Copy Markdown

whimboo commented Aug 27, 2025

Hi @jogibear9988. Would you maybe have the time to update this PR based on the review feedback from Emilio? Thanks a lot!

@jogibear9988
Copy link
Copy Markdown
Author

Sorry, I've read them, and hopefully fix in the next days

@whimboo
Copy link
Copy Markdown

whimboo commented Oct 30, 2025

Hi @jogibear9988. I wanted to check back with you about the status of this PR. Is it still something you can continue working on? Thanks!

@jogibear9988
Copy link
Copy Markdown
Author

@whimboo
sorry, had not much time to work on this.
at the moment I fix my polyfill (https://github.com/jogibear9988/getBoxQuadsPolyfill) to also respect offset-.... css properties. Didn't know they exist.
Also there is a small issue with webcomponents I try to fix.
Then I look to fix this spec.

@jogibear9988
Copy link
Copy Markdown
Author

Also I think the spec needs an upgrade to also include a function to calculate the complete transformation matrix between two elements.
My polyfill does this, and I need this also some time in my designer, and this is not possible only with the boxQuads result.
is this something I also should add here, or should this be an extra issue/pull req?

@bramus
Copy link
Copy Markdown
Contributor

bramus commented Nov 24, 2025

Also I think the spec needs an upgrade to also include a function to calculate the complete transformation matrix between two elements. My polyfill does this, and I need this also some time in my designer, and this is not possible only with the boxQuads result. is this something I also should add here, or should this be an extra issue/pull req?

This would need a separate PR – one that would need a CSS WG Resolution first to get the group’s consensus to adding it.

@whimboo
Copy link
Copy Markdown

whimboo commented Feb 10, 2026

Hello @jogibear9988. I want to check back with you if you may have some time that this PR could be moved forward? Or is it blocked based on the last comment? Thanks!

Copilot AI and others added 4 commits March 20, 2026 15:13
Rewrite getCompleteTransform, getBoxQuads, convertQuadFromNode,
convertRectFromNode, and convertPointFromNode algorithm definitions
using proper bikeshed markup:

- Use <div algorithm> block with <dfn> for getCompleteTransform
- Use <var> tags for all variables throughout
- Use {{}} bikeshed notation for DOM types (DOMQuad, DOMMatrix, etc.)
- Reference css-transforms-1 CTM definition properly
- Handle Document (layout viewport) vs Element/Text (box fragments)
- Use proper <a spec=css-break>box fragment</a> references
- Reference margin/padding/border/content edges correctly
- Fix relativeTo (not realtiveTo) and use layout viewport as fallback
- Give meaningful variable names (thisTransformToViewport, etc.)
- Link convertQuadFromNode to convertPointFromNode explicitly
- Reference used values of CSS properties for box adjustments

Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
…ible matrix note

- Spell out how margin/padding/content box adjustments work using
  specific CSS property used values
- Add note about non-invertible transformation matrices
- Add link-defaults for border-right-width and border-bottom-width

Co-authored-by: jogibear9988 <364896+jogibear9988@users.noreply.github.com>
jogibear9988 and others added 5 commits March 20, 2026 20:56
[cssom-view] Specify GeometryUtils algorithms (getBoxQuads, convertQuadFromNode, convertRectFromNode, convertPointFromNode)
…-from-pull-10538

# Conflicts:
#	cssom-view-1/Overview.bs
Resolve merge conflicts with updated patch-1 base branch
…10538

Copilot/fix issues from pull 10538
Comment thread cssom-view-1/Overview.bs Outdated
The main changes are:
- rewrote getBoxQuads() in terms of nodes and box fragments, with layout-viewport coordinates as the default when relativeTo is omitted
- added explicit Document and Text handling
- moved the box-space wording to helper algorithms and removed the margin/padding/content edge arithmetic based on used values
- reused convertQuadFromNode()/convertPointFromNode() for the actual coordinate conversion path

I also validated the edited file locally. A remote Bikeshed run still hits unrelated existing markdown errors later in cssom-view-1, but it did not report new fatal issues in the GeometryUtils block.
@jogibear9988
Copy link
Copy Markdown
Author

@jogibear9988
Copy link
Copy Markdown
Author

I also have a new library wich uses getBoxQuads API, to be able to create screenshots or vector exports of HTML pages: https://github.com/node-projects/layout2vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cssom-view] update description of getBoxQuads API

9 participants