Source/WebCore/ChangeLog

 12022-02-23 Antti Koivisto <antti@apple.com>
 2
 3 [CSS Container Queries] offsetWidth/Height and similar should update layout for container queries
 4 https://bugs.webkit.org/show_bug.cgi?id=237079
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Fix
 9
 10 css/css-contain/container-queries/inline-size-containment.html
 11 css/css-contain/container-queries/inline-size-containment-vertical-rl.html
 12
 13 * dom/Document.cpp:
 14 (WebCore::Document::updateLayout):
 15
 16 Make iterative instead of recursive.
 17
 18 (WebCore::Document::updateLayoutIfDimensionsOutOfDate):
 19
 20 Check for query containers.
 21 Call local updateLayout instead of the FrameViewLayoutContext one.
 22
 23 * page/FrameView.cpp:
 24 (WebCore::FrameView::updateLayoutAndStyleIfNeededRecursive):
 25 * style/StyleScope.cpp:
 26 (WebCore::Style::Scope::updateQueryContainerState):
 27
 28 Add protection against infinite layout/invalidation cycle with unstable layouts.
 29
 30 * style/StyleScope.h:
 31
1322022-02-23 Zan Dobersek <zdobersek@igalia.com>
233
334 [GStreamer] Add WebKitDMABufVideoSink

Source/WebCore/dom/Document.cpp

@@void Document::updateLayout()
22082208
22092209 frameView->layoutContext().layout();
22102210
2211  if (styleScope().updateQueryContainerState())
2212  updateLayout();
 2211 Style::Scope::QueryContainerUpdateContext queryContainerUpdateContext;
 2212 while (styleScope().updateQueryContainerState(queryContainerUpdateContext)) {
 2213 updateStyleIfNeeded();
 2214
 2215 if (!frameView->layoutContext().needsLayout())
 2216 break;
 2217
 2218 frameView->layoutContext().layout();
 2219 }
22132220}
22142221
22152222void Document::updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks runPostLayoutTasks)

@@bool Document::updateLayoutIfDimensionsOutOfDate(Element& element, DimensionsChe
23132320
23142321 previousBox = currentBox;
23152322 currentBox = downcast<RenderBox>(currRenderer);
2316 
 2323
 2324 if (currentBox->style().containerType() != ContainerType::None) {
 2325 requireFullLayout = true;
 2326 break;
 2327 }
 2328
23172329 // If a box needs layout for itself or if a box has changed children and sizes its width to
23182330 // its content, then require a full layout.
23192331 if (currentBox->selfNeedsLayout() ||

@@bool Document::updateLayoutIfDimensionsOutOfDate(Element& element, DimensionsChe
23482360
23492361 StackStats::LayoutCheckPoint layoutCheckPoint;
23502362
2351  // Only do a layout if changes have occurred that make it necessary.
2352  if (requireFullLayout && frameView && renderView() && (frameView->layoutContext().isLayoutPending() || renderView()->needsLayout()))
2353  frameView->layoutContext().layout();
 2363 // Only do a layout if changes have occurred that make it necessary.
 2364 if (requireFullLayout)
 2365 updateLayout();
23542366
23552367 return requireFullLayout;
23562368}

Source/WebCore/page/FrameView.cpp

@@void FrameView::updateLayoutAndStyleIfNeededRecursive()
45414541 return descendantsDeque.first().ptr();
45424542 };
45434543
 4544 Style::Scope::QueryContainerUpdateContext queryContainerUpdateContext;
 4545
45444546 for (unsigned i = 0; i < maxUpdatePasses; ++i) {
45454547 bool didWork = false;
45464548 DescendantsDeque deque;

@@void FrameView::updateLayoutAndStyleIfNeededRecursive()
45494551 didWork = true;
45504552 if (view->needsLayout()) {
45514553 view->layoutContext().layout();
4552  view->frame().document()->styleScope().updateQueryContainerState();
 4554 view->frame().document()->styleScope().updateQueryContainerState(queryContainerUpdateContext);
45534555 didWork = true;
45544556 }
45554557 }

Source/WebCore/style/StyleScope.cpp

@@bool Scope::isForUserAgentShadowTree() const
783783 return m_shadowRoot && m_shadowRoot->mode() == ShadowRootMode::UserAgent;
784784}
785785
786 bool Scope::updateQueryContainerState()
 786bool Scope::updateQueryContainerState(QueryContainerUpdateContext& context)
787787{
788788 ASSERT(!m_shadowRoot);
789789 ASSERT(m_document.renderView());

@@bool Scope::updateQueryContainerState()
791791 auto previousStates = WTFMove(m_queryContainerStates);
792792 m_queryContainerStates.clear();
793793
794  Vector<Element*> changedContainers;
 794 Vector<Element*> containersToInvalidate;
795795
796796 for (auto& containerRenderer : m_document.renderView()->containerQueryBoxes()) {
797797 auto* containerElement = containerRenderer.element();

@@bool Scope::updateQueryContainerState()
814814
815815 auto it = previousStates.find(*containerElement);
816816 bool changed = it == previousStates.end() || sizeChanged(it->value);
817  if (changed)
818  changedContainers.append(containerElement);
 817 // Protect against unstable layout by invalidating only once per container.
 818 if (changed && context.invalidatedContainers.add(containerElement).isNewEntry)
 819 containersToInvalidate.append(containerElement);
819820 m_queryContainerStates.add(*containerElement, size);
820821 }
821822
822  for (auto* toInvalidate : changedContainers)
 823 for (auto* toInvalidate : containersToInvalidate)
823824 toInvalidate->invalidateForQueryContainerChange();
824825
825  return !changedContainers.isEmpty();
 826 return !containersToInvalidate.isEmpty();
826827}
827828
828829HTMLSlotElement* assignedSlotForScopeOrdinal(const Element& element, ScopeOrdinal scopeOrdinal)

Source/WebCore/style/StyleScope.h

@@public:
129129 static Scope& forNode(Node&);
130130 static Scope* forOrdinal(Element&, ScopeOrdinal);
131131
132  bool updateQueryContainerState();
 132 struct QueryContainerUpdateContext {
 133 HashSet<Element*> invalidatedContainers;
 134 };
 135 bool updateQueryContainerState(QueryContainerUpdateContext&);
133136
134137private:
135138 Scope& documentScope();

LayoutTests/imported/w3c/ChangeLog

 12022-02-23 Antti Koivisto <antti@apple.com>
 2
 3 [CSS Container Queries] offsetWidth/Height and similar should update layout for container queries
 4 https://bugs.webkit.org/show_bug.cgi?id=237079
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * web-platform-tests/css/css-contain/container-queries/auto-scrollbars-expected.txt:
 9 * web-platform-tests/css/css-contain/container-queries/inline-size-containment-expected.txt:
 10 * web-platform-tests/css/css-contain/container-queries/inline-size-containment-vertical-rl-expected.txt:
 11 * web-platform-tests/css/css-contain/container-queries/transition-scrollbars-expected.txt:
 12
1132022-02-22 Antti Koivisto <antti@apple.com>
214
315 [CSS container Queries] getComputedStyle should update style for invalid query containers

LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/auto-scrollbars-expected.txt

11
2 FAIL Initial layout - expecting a scrollbar without overflowing content instead of overflowing content without a scrollbar assert_equals: Layout with a scrollbar means the container query applies expected "50px" but got "100px"
 2FAIL Initial layout - expecting a scrollbar without overflowing content instead of overflowing content without a scrollbar assert_less_than: Expects a vertical scrollbar expected a number less than 100 but got 100
33FAIL Same result after a reflow assert_less_than: Expects a vertical scrollbar expected a number less than 100 but got 100
44

LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/inline-size-containment-expected.txt

11
2 FAIL inline-size containment only assert_equals: expected 400 but got 20
 2PASS inline-size containment only
33

LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/inline-size-containment-vertical-rl-expected.txt

11
2 FAIL inline-size containment only assert_equals: expected 50 but got 400
 2PASS inline-size containment only
33

LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/transition-scrollbars-expected.txt

11Foo bar foo bar foo Foo bar foo bar foo Foo bar foo bar foo Foo bar foo bar foo Foo bar foo bar foo
22
3 FAIL Scrollbars do not cause a transition of background-color assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 255)"
 3FAIL Scrollbars do not cause a transition of background-color assert_equals: expected "rgb(0, 0, 255)" but got "rgb(0, 64, 128)"
44