Skip to content

Commit

Permalink
SVG: Fix viewport-relative size invalidation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Kent Tamura <[email protected]>
Auto-Submit: Kent Tamura <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1224043}
  • Loading branch information
tkent-google authored and Chromium LUCI CQ committed Nov 14, 2023
1 parent a50d8f6 commit bb35e61
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
18 changes: 9 additions & 9 deletions third_party/blink/renderer/core/layout/layout_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,14 @@ const LayoutBox& LayoutView::RootBox() const {
return To<LayoutBox>(*document_element->GetLayoutObject());
}

void LayoutView::InvalidateSvgRootsWithRelativeLengthDescendents() {
if (GetDocument().SvgExtensions() && !ShouldUsePrintingLayout()) {
GetDocument()
.AccessSVGExtensions()
.InvalidateSVGRootsWithRelativeLengthDescendents();
}
}

void LayoutView::UpdateLayout() {
NOT_DESTROYED();
if (ShouldUsePrintingLayout()) {
Expand Down Expand Up @@ -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<HeapHashSet<Member<const LayoutObject>>>();
}
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/layout/layout_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class CORE_EXPORT LayoutView : public LayoutNGBlockFlow {

bool IsChildAllowed(LayoutObject*, const ComputedStyle&) const override;

void InvalidateSvgRootsWithRelativeLengthDescendents();
void UpdateLayout() final;
LayoutUnit ComputeMinimumWidth();

Expand Down
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/layout/ng/ng_block_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -534,6 +535,9 @@ const NGLayoutResult* NGBlockNode::Layout(
box_->SetNeedsLayout(layout_invalidation_reason::kScrollbarChanged,
kMarkOnlyThis);

if (auto* view = DynamicTo<LayoutView>(GetLayoutBox())) {
view->InvalidateSvgRootsWithRelativeLengthDescendents();
}
fragment_geometry = CalculateInitialFragmentGeometry(constraint_space,
*this, break_token);
layout_result = LayoutWithAlgorithm(params);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<body>
<svg
width="100%" height="100%"
xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="100%" height="100%" fill='lime'></rect>
</svg>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<title>Percentages in a mask</title>
<link rel="help" href="https://crbug.com/1500476" />
<link rel="match" href="mask-percentage-ref.html" />
<body>
<svg
width="100%" height="100%"
xmlns="http://www.w3.org/2000/svg">

<defs>
<mask id='corner'>
<g><rect x="0" y="0" height="100%" width="100%" fill="white" /></g>
</mask>
</defs>

<rect x="0" y="0" width="100%" height="100%" fill="red"></rect>
<g mask='url(#corner)'>
<rect x="0" y="0" width="100%" height="100%" fill='lime'></rect>
</g>
</svg>
</body>
</html>

0 comments on commit bb35e61

Please sign in to comment.