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

Clip replaced elements to their content rect #26390

Open
SimonSapin opened this issue May 1, 2020 · 4 comments
Open

Clip replaced elements to their content rect #26390

SimonSapin opened this issue May 1, 2020 · 4 comments

Comments

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented May 1, 2020

layout_2020::replaced::ReplacedContent::make_fragment is called in three places for inline-level, block-level, and absolutely-positioned replaced boxes. It returns an arbitrary Vec of fragments for the replaced content which is wrapped into a BoxFragment for the box itself. The latter is responsible the box’s borders, backgrounds, etc. Hopefully, this nesting in the fragment tree will also make it easier to implement object-fit and object-position.

Layout 2020 does not yet implement this bit of spec: https://drafts.csswg.org/css-backgrounds/#corner-clipping

The content of replaced elements is always trimmed to the content edge curve.

(The content edge curve is the content rect, with corners possibly rounded by border-radius.) Note that this is different from the clipping/trimming by the overflow property, which uses the padding rect/edge.

In the current fragment tree however there is no way to tell whether a BoxFragment was generated for a replaced element. We may want to add a boolean field or equivalent, so that display list construction can know which fragments to clip at their content edge.

@mrobinson, I see that clipping for the overflow property is handled by StackingContext rather than BoxFragment. Should we make replaced elements generate a (pseudo?) stacking context?

@mrobinson
Copy link
Member

@mrobinson mrobinson commented May 4, 2020

I think what we want to do here is just establish a rounded rectangle clip when building the display list for the BoxFragment and apply it to all children. WebRender supports creating arbitrary chains of clips (things don't have to be defined hierarchically), so perhaps we could simply append a series of clips for the hierarchy of the rounded rectangles onto the clip provided by the stacking context.

@SimonSapin
Copy link
Member Author

@SimonSapin SimonSapin commented May 4, 2020

Background painting is another case where we have WebRender clips for rounded corners, but those clips apply only to specific display items. My question was around how to make sure that everything in a sub-tree uses that clip.

By the way, per spec replaced elements are clipped even if the corner radius happens to be zero. This is not observable for raster images, but it might be eventually for SVG depending on how we end up integrating Pathfinder to WebRender.

@mrobinson
Copy link
Member

@mrobinson mrobinson commented May 5, 2020

For the subtree case, I think we can keep a stack of item-derived clips in the display list builder and use it to create ClipChains either during display list construction or stacking context tree construction.

@SimonSapin
Copy link
Member Author

@SimonSapin SimonSapin commented May 7, 2020

We presumably already do something similar for nested elements with the overflow property.

That said dealing with the general case may not worth worrying about yet since we have no plan to implement SVG soon, and so far the Vec returned by ReplacedContent::make_fragments is always either empty or has exactly one fragment which is a (raster) image fragment (and therefore does not have child fragments of its own).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Layout 2020
  
Architecture
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.