[@container] Make UpdateStyleAndLayoutTreeForNode understand CQ #32904
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We currently have pretty serious bugs in getComputedStyle (and similar
APIs that force style), since NeedsLayoutTreeUpdateForNodeIncluding-
DisplayLocked is completely unaware of container queries: if nothing
is style dirty in the ancestor chain, we will early-out from
UpdateStyleAndLayoutTreeForNode, and never actually update anything.
However, for container queries, we have to also check for layout-
dirtiness, since doing that layout can affect container-query-
dependent elements.
This CL tries to formalize the concept of a "layout upgrade", which
is a name for when UpdateStyleAndLayoutTree needs to also call
UpdateStyleAndLayout due layout dependencies.
true whenever we may need to upgrade. Otherwise we'll early-out,
and never even get the chance to upgrade. Hence, we look at the
target node and the ancestor chain, and try to figure out if a
layout upgrade will be needed. We can not know this for sure
at this time, because the subsequent call to update style may
(for example) remove all container-query containers, i.e.
remove layout dependencies.
decides how or if an upgrade should take place. NodeLayoutUpgrade
being the most interesting of these objects.
ancestor chain to understand if an upgrade is needed. It is not
possible to answer this question in the first traversal
definitively, since style (first pass) has not been updated yet
at that time.
For forced updates which target nodes in display:none (or elements
without ComputedStyle in general), we can not tell ahead-of-time
whether or not something may require an upgrade, since the
DependsOnContainerQueries exists on ComputedStyle. Hence, for those
situations we defensively assume that we require an upgrade if we're
inside an interleaving root [1].
Pseudo-elements also needed adjustment in this CL (the change in
ElementRuleCollector). getComputedStyle will call NeedsLayoutTree-
UpdateForNodeIncludingDisplayLocked with the originating element,
so it is not enough to mark the pseudo-style with as
DependsOnContainerQueries, since we never actually observe that style
in NeedsLayoutTreeUpdateForNode(etc). Hence we mark the originating
element as well, although this will cause some over-invalidation in
some cases. (It's possible to iterate on this if needed).
[1] Interleaving root = basically a container-for-container-queries
that is not display:none.
Fixed: 1295717
Change-Id: I2c7d3a82dd513b618ad5245df9b3b6cd7e306d9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3472067
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#980529}