- Revision
- 295200
- Author
- [email protected]
- Date
- 2022-06-03 02:54:36 -0700 (Fri, 03 Jun 2022)
Log Message
Re-evaluate queries after subframe size changes
https://bugs.webkit.org/show_bug.cgi?id=241225
Reviewed by Alan Bujtas.
Container queries in frames don't react to frame size changes.
* LayoutTests/TestExpectations:
Mark imported/w3c/web-platform-tests/css/css-contain/container-queries/inline-size-bfc-floats.html as failure, it has ever
been passing by fluke (there are some containment issues with floats).
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-in-container-invalidation-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-invalidation-expected.txt:
* Source/WebCore/css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
Ensure we update layout when there are container queries in a subframe, similar to media queries.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::resolveStyle):
(WebCore::Document::updateLayout):
* Source/WebCore/page/FrameView.cpp:
(WebCore::FrameView::updateContentsSize):
(WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive):
* Source/WebCore/page/FrameViewLayoutContext.cpp:
(WebCore::FrameViewLayoutContext::layout):
Move the container query invalidation loop to the main layout function so all paths are covered.
(WebCore::FrameViewLayoutContext::performLayout):
* Source/WebCore/page/FrameViewLayoutContext.h:
* Source/WebCore/style/StyleScopeRuleSets.cpp:
(WebCore::Style::ScopeRuleSets::hasContainerQueries const):
* Source/WebCore/style/StyleScopeRuleSets.h:
Canonical link: https://commits.webkit.org/251257@main
Modified Paths
Diff
Modified: trunk/LayoutTests/TestExpectations (295199 => 295200)
--- trunk/LayoutTests/TestExpectations 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/LayoutTests/TestExpectations 2022-06-03 09:54:36 UTC (rev 295200)
@@ -4778,6 +4778,7 @@
# Container queries
webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/custom-layout-container-001.https.html [ ImageOnlyFailure ]
+webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/inline-size-bfc-floats.html [ ImageOnlyFailure ]
webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/svg-foreignobject-no-size-container.html [ Skip ]
webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/container-units-gradient-invalidation.html [ ImageOnlyFailure ]
webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/container-units-gradient.html [ ImageOnlyFailure ]
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-in-container-invalidation-expected.txt (295199 => 295200)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-in-container-invalidation-expected.txt 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-in-container-invalidation-expected.txt 2022-06-03 09:54:36 UTC (rev 295200)
@@ -1,4 +1,4 @@
-FAIL @container-dependent elements respond to size changes of an @container-dependent iframe assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
+PASS @container-dependent elements respond to size changes of an @container-dependent iframe
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-invalidation-expected.txt (295199 => 295200)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-invalidation-expected.txt 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/iframe-invalidation-expected.txt 2022-06-03 09:54:36 UTC (rev 295200)
@@ -1,4 +1,4 @@
-FAIL @container-dependent elements respond to iframe size changes assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
+PASS @container-dependent elements respond to iframe size changes
Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (295199 => 295200)
--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp 2022-06-03 09:54:36 UTC (rev 295200)
@@ -2895,10 +2895,20 @@
style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle, styledRenderer());
- // FIXME: Some of these cases could be narrowed down or optimized better.
- forceFullLayout = isLayoutDependent(propertyID, style, styledRenderer())
- || styledElement->isInShadowTree()
- || (document.styleScope().resolverIfExists() && document.styleScope().resolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
+ forceFullLayout = [&] {
+ // FIXME: Some of these cases could be narrowed down or optimized better.
+ if (isLayoutDependent(propertyID, style, styledRenderer()))
+ return true;
+ // FIXME: Why?
+ if (styledElement->isInShadowTree())
+ return true;
+ if (!document.ownerElement())
+ return false;
+ if (!document.styleScope().resolverIfExists())
+ return false;
+ auto& ruleSets = document.styleScope().resolverIfExists()->ruleSets();
+ return ruleSets.hasViewportDependentMediaQueries() || ruleSets.hasContainerQueries();
+ }();
if (forceFullLayout)
document.updateLayoutIgnorePendingStylesheets();
Modified: trunk/Source/WebCore/dom/Document.cpp (295199 => 295200)
--- trunk/Source/WebCore/dom/Document.cpp 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/dom/Document.cpp 2022-06-03 09:54:36 UTC (rev 295200)
@@ -2207,8 +2207,9 @@
bool Document::updateStyleIfNeeded()
{
- if (topDocument().isResolvingContainerQueries())
+ if (isResolvingContainerQueries())
return false;
+
RefPtr<FrameView> frameView = view();
{
ScriptDisallowedScope::InMainThread scriptDisallowedScope;
@@ -2260,16 +2261,6 @@
return;
frameView->layoutContext().layout();
-
- Style::Scope::QueryContainerUpdateContext queryContainerUpdateContext;
- while (styleScope().updateQueryContainerState(queryContainerUpdateContext)) {
- updateStyleIfNeeded();
-
- if (!frameView->layoutContext().needsLayout())
- break;
-
- frameView->layoutContext().layout();
- }
}
void Document::updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks runPostLayoutTasks)
Modified: trunk/Source/WebCore/page/FrameView.cpp (295199 => 295200)
--- trunk/Source/WebCore/page/FrameView.cpp 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/page/FrameView.cpp 2022-06-03 09:54:36 UTC (rev 295200)
@@ -4553,8 +4553,6 @@
return descendantsDeque.first().ptr();
};
- Style::Scope::QueryContainerUpdateContext queryContainerUpdateContext;
-
for (unsigned i = 0; i < maxUpdatePasses; ++i) {
bool didWork = false;
DescendantsDeque deque;
@@ -4563,7 +4561,6 @@
didWork = true;
if (view->needsLayout()) {
view->layoutContext().layout();
- view->frame().document()->styleScope().updateQueryContainerState(queryContainerUpdateContext);
didWork = true;
}
}
Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.cpp (295199 => 295200)
--- trunk/Source/WebCore/page/FrameViewLayoutContext.cpp 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.cpp 2022-06-03 09:54:36 UTC (rev 295200)
@@ -169,6 +169,21 @@
{
LOG_WITH_STREAM(Layout, stream << "FrameView " << &view() << " FrameViewLayoutContext::layout() with size " << view().layoutSize());
+ performLayout();
+
+ Style::Scope::QueryContainerUpdateContext queryContainerUpdateContext;
+ while (document()->styleScope().updateQueryContainerState(queryContainerUpdateContext)) {
+ document()->updateStyleIfNeeded();
+
+ if (!needsLayout())
+ break;
+
+ performLayout();
+ }
+}
+
+void FrameViewLayoutContext::performLayout()
+{
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!frame().document()->inRenderTreeUpdate());
ASSERT(LayoutDisallowedScope::isLayoutAllowed());
ASSERT(!view().isPainting());
Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.h (295199 => 295200)
--- trunk/Source/WebCore/page/FrameViewLayoutContext.h 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.h 2022-06-03 09:54:36 UTC (rev 295200)
@@ -127,6 +127,7 @@
friend class SubtreeLayoutStateMaintainer;
friend class PaginatedLayoutStateMaintainer;
+ void performLayout();
bool canPerformLayout() const;
bool layoutDisallowed() const { return m_layoutDisallowedCount; }
bool isLayoutSchedulingEnabled() const { return m_layoutSchedulingIsEnabled; }
Modified: trunk/Source/WebCore/style/StyleScopeRuleSets.cpp (295199 => 295200)
--- trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/style/StyleScopeRuleSets.cpp 2022-06-03 09:54:36 UTC (rev 295200)
@@ -163,6 +163,18 @@
return false;
}
+bool ScopeRuleSets::hasContainerQueries() const
+{
+ if (m_authorStyle->hasContainerQueries())
+ return true;
+ if (m_userStyle && m_userStyle->hasContainerQueries())
+ return true;
+ if (m_userAgentMediaQueryStyle && m_userAgentMediaQueryStyle->hasContainerQueries())
+ return true;
+
+ return false;
+}
+
std::optional<DynamicMediaQueryEvaluationChanges> ScopeRuleSets::evaluateDynamicMediaQueryRules(const MediaQueryEvaluator& evaluator)
{
std::optional<DynamicMediaQueryEvaluationChanges> evaluationChanges;
Modified: trunk/Source/WebCore/style/StyleScopeRuleSets.h (295199 => 295200)
--- trunk/Source/WebCore/style/StyleScopeRuleSets.h 2022-06-03 08:29:27 UTC (rev 295199)
+++ trunk/Source/WebCore/style/StyleScopeRuleSets.h 2022-06-03 09:54:36 UTC (rev 295200)
@@ -79,6 +79,7 @@
void resetUserAgentMediaQueryStyle();
bool hasViewportDependentMediaQueries() const;
+ bool hasContainerQueries() const;
std::optional<DynamicMediaQueryEvaluationChanges> evaluateDynamicMediaQueryRules(const MediaQueryEvaluator&);