Re: [csswg-drafts] [css-anchor-1] Issues with position fallback (#8059)

A new idea to make it work better with scrolling:

For each fallback position, we can calculate a **scroll-adjusted inset modified containing block**, defined as follows:
1. For each inset property, its **scroll-adjusted inset** is
    * `auto` if the property value is `auto`
    * Otherwise, the original property value offseted by the value of [snapshotted scroll offset](https://drafts4.csswg.org/css-anchor-position-1/#snapshotted-scroll-offset) in the same axis
2. The *scroll-adjusted inset modified containing block* is calculated using the same algorithm as [inset-modified containing block](https://drafts.csswg.org/css-position/#inset-modified-containing-block), but replacing the original inset  property values by the *scroll-adjusted insets*
3. The fallback position is valid if the margin box of the element, shifted by the snapshotted scroll offset (if any), falls in the *scroll-adjusted inset-modified containing block*

We can easily run this through [my previous test case](https://github.com/w3c/csswg-drafts/issues/8059#issuecomment-1314657467) and verify its correctness.

Intuitively, we are still folding scroll offset into inset value evaluation; however, we are not folding it deep into each `anchor()` function, but at a very shallow level at the end of the evaluation. In other words, any non-`auto` inset property value is shifted as a whole by the scroll offset.

This still won't cause layout invalidation in every scrolling, and hence still supports composited scrolling. When scrolled by an amount, both the margin box and certain edges of the scroll-adjusted inset-modified containing block will be shifted; Note that they are always shifted by the same amount. Therefore:
- If an inset property value is not `auto`, we just need to check if the margin box overflows this edge at the initial scroll position -- if it doesn't, it means the element will never overflow this edge regardless of how we scroll, and vice versa
- If an inset property value is `auto`, then this edge of the inset-modified cb is at a fixed location independent of scrolling; Then we can also work out the range of scroll offsets that doesn't overflow this edge
In the end, for each fallback position, we can still work out a range of scroll offsets, which forms a rectangle, in which the fallback position is valid

-- 
GitHub Notification of comment by xiaochengh
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8059#issuecomment-1433902031 using your GitHub account


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

Received on Thursday, 16 February 2023 23:58:44 UTC