Commit 9fb80d25 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Create LayoutShiftTracker::ContainingBlockScope for the first fragment only

Currently PaintInvalidator iterates all block fragments with one context
for each LayoutObject, so we should create ContainingBlockScope only once
for the first fragment only. Previously creating multiple
ContainingBlockScopes for one multi-block-fragment object broke stacking
of the scopes, causing memory corruption.

Add check in ~ContainingBlockScope for stacking error in the scopes.

This limitation will be removed with LayoutNGFragmentTraversal which
traverses block fragments in depth-first order.

Bug: 1113710
Change-Id: I07aa3626f1a1d34714459e256880a96897585d4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339449Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796093}
parent f05116f4
......@@ -84,6 +84,9 @@ class CORE_EXPORT LayoutShiftTracker final
explicit ReattachHookScope(const Node&);
~ReattachHookScope();
ReattachHookScope(const ReattachHookScope&) = delete;
ReattachHookScope& operator=(const ReattachHookScope&) = delete;
static void NotifyDetach(const Node&);
static void NotifyAttach(const Node&);
......@@ -117,7 +120,13 @@ class CORE_EXPORT LayoutShiftTracker final
new_rect_(new_rect) {
top_ = this;
}
~ContainingBlockScope() { top_ = outer_; }
~ContainingBlockScope() {
DCHECK_EQ(top_, this);
top_ = outer_;
}
ContainingBlockScope(const ContainingBlockScope&) = delete;
ContainingBlockScope& operator=(const ContainingBlockScope&) = delete;
private:
friend class LayoutShiftTracker;
......
......@@ -237,6 +237,9 @@ void PaintInvalidator::UpdateLayoutShiftTracking(
}();
bool should_create_containing_block_scope =
// TODO(crbug.com/1104064): Support multiple-fragments when switching to
// LayoutNGFragmentTraversal.
context.fragment_data == &box.FirstFragment() &&
box.IsLayoutBlockFlow() && box.ChildrenInline() && box.SlowFirstChild();
if (!should_report_layout_shift && !should_create_containing_block_scope)
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment