From bb35e6156ca121e7d1f6e0e1b682e88e2307dd47 Mon Sep 17 00:00:00 2001 From: Kent Tamura Date: Tue, 14 Nov 2023 02:22:44 +0000 Subject: [PATCH] SVG: Fix viewport-relative size invalidation We should call InvalidateSVGRootsWithRelativeLengthDescendents() on relayout due to scrollbars in NGBlockNode::Layout() Bug: 1500476 Change-Id: I34ba41e65104dadddbb6a791fc5a912e837ec84c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5020338 Reviewed-by: Morten Stenshorne Commit-Queue: Kent Tamura Auto-Submit: Kent Tamura Cr-Commit-Position: refs/heads/main@{#1224043} --- .../blink/renderer/core/layout/layout_view.cc | 18 +++++++-------- .../blink/renderer/core/layout/layout_view.h | 1 + .../renderer/core/layout/ng/ng_block_node.cc | 4 ++++ .../reftests/mask-percentage-ref.html | 10 ++++++++ .../painting/reftests/mask-percentage.html | 23 +++++++++++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage-ref.html create mode 100644 third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage.html diff --git a/third_party/blink/renderer/core/layout/layout_view.cc b/third_party/blink/renderer/core/layout/layout_view.cc index 5f3180b2e698e6..2d4f91a1aaefa4 100644 --- a/third_party/blink/renderer/core/layout/layout_view.cc +++ b/third_party/blink/renderer/core/layout/layout_view.cc @@ -801,6 +801,14 @@ const LayoutBox& LayoutView::RootBox() const { return To(*document_element->GetLayoutObject()); } +void LayoutView::InvalidateSvgRootsWithRelativeLengthDescendents() { + if (GetDocument().SvgExtensions() && !ShouldUsePrintingLayout()) { + GetDocument() + .AccessSVGExtensions() + .InvalidateSVGRootsWithRelativeLengthDescendents(); + } +} + void LayoutView::UpdateLayout() { NOT_DESTROYED(); if (ShouldUsePrintingLayout()) { @@ -830,17 +838,9 @@ void LayoutView::UpdateLayout() { bool is_resizing_initial_containing_block = LogicalWidth() != ViewLogicalWidthForBoxSizing() || LogicalHeight() != ViewLogicalHeightForBoxSizing(); - bool invalidate_svg_roots = - GetDocument().SvgExtensions() && !ShouldUsePrintingLayout() && - (!GetFrameView() || is_resizing_initial_containing_block); - if (invalidate_svg_roots) { - GetDocument() - .AccessSVGExtensions() - .InvalidateSVGRootsWithRelativeLengthDescendents(); - } - DCHECK(!initial_containing_block_resize_handled_list_); if (is_resizing_initial_containing_block) { + InvalidateSvgRootsWithRelativeLengthDescendents(); initial_containing_block_resize_handled_list_ = MakeGarbageCollected>>(); } diff --git a/third_party/blink/renderer/core/layout/layout_view.h b/third_party/blink/renderer/core/layout/layout_view.h index 4e0be05c8a0f48..a84b0655089e50 100644 --- a/third_party/blink/renderer/core/layout/layout_view.h +++ b/third_party/blink/renderer/core/layout/layout_view.h @@ -105,6 +105,7 @@ class CORE_EXPORT LayoutView : public LayoutNGBlockFlow { bool IsChildAllowed(LayoutObject*, const ComputedStyle&) const override; + void InvalidateSvgRootsWithRelativeLengthDescendents(); void UpdateLayout() final; LayoutUnit ComputeMinimumWidth(); diff --git a/third_party/blink/renderer/core/layout/ng/ng_block_node.cc b/third_party/blink/renderer/core/layout/ng/ng_block_node.cc index 461f59ee452bce..4b87e4f2912d97 100644 --- a/third_party/blink/renderer/core/layout/ng/ng_block_node.cc +++ b/third_party/blink/renderer/core/layout/ng/ng_block_node.cc @@ -29,6 +29,7 @@ #include "third_party/blink/renderer/core/layout/layout_multi_column_set.h" #include "third_party/blink/renderer/core/layout/layout_multi_column_spanner_placeholder.h" #include "third_party/blink/renderer/core/layout/layout_video.h" +#include "third_party/blink/renderer/core/layout/layout_view.h" #include "third_party/blink/renderer/core/layout/list/layout_list_item.h" #include "third_party/blink/renderer/core/layout/mathml/math_fraction_layout_algorithm.h" #include "third_party/blink/renderer/core/layout/mathml/math_layout_utils.h" @@ -534,6 +535,9 @@ const NGLayoutResult* NGBlockNode::Layout( box_->SetNeedsLayout(layout_invalidation_reason::kScrollbarChanged, kMarkOnlyThis); + if (auto* view = DynamicTo(GetLayoutBox())) { + view->InvalidateSvgRootsWithRelativeLengthDescendents(); + } fragment_geometry = CalculateInitialFragmentGeometry(constraint_space, *this, break_token); layout_result = LayoutWithAlgorithm(params); diff --git a/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage-ref.html b/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage-ref.html new file mode 100644 index 00000000000000..00c26e85ccfa03 --- /dev/null +++ b/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage-ref.html @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage.html b/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage.html new file mode 100644 index 00000000000000..e9cd0977413b5b --- /dev/null +++ b/third_party/blink/web_tests/external/wpt/svg/painting/reftests/mask-percentage.html @@ -0,0 +1,23 @@ + + +Percentages in a mask + + + + + + + + + + + + + + + + + +