Commit 472f4e64 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Don't report layout shift for visibility:hidden

BTW fixed a small invisible bug for anonymous LayoutObjects which just
affects performance a bit.

Bug: 1127474
Change-Id: I926bef2572a1d0099c2e106fdd4eb36756e99fb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410816Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807049}
parent fd97885a
...@@ -168,7 +168,10 @@ bool LayoutShiftTracker::NeedsToTrack(const LayoutObject& object) const { ...@@ -168,7 +168,10 @@ bool LayoutShiftTracker::NeedsToTrack(const LayoutObject& object) const {
// Don't report shift of anonymous objects. Will report the children because // Don't report shift of anonymous objects. Will report the children because
// we want report real DOM nodes. // we want report real DOM nodes.
if (object.IsAnonymous()) if (object.IsAnonymous())
return true; return false;
if (object.StyleRef().Visibility() != EVisibility::kVisible)
return false;
// Ignore layout objects that move (in the coordinate space of the paint // Ignore layout objects that move (in the coordinate space of the paint
// invalidation container) on scroll. // invalidation container) on scroll.
......
<!DOCTYPE html>
<title>Layout Instability: visibility:hidden</title>
<link rel="help" href="https://wicg.github.io/layout-instability/" />
<div id="target" style="position: absolute; top: 0; width: 400px; height: 400px; visibility: hidden"></div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/util.js"></script>
<script>
promise_test(async () => {
const watcher = new ScoreWatcher;
// Wait for the initial render to complete.
await waitForAnimationFrames(2);
// Shift target, for which no shift should be reported because it's hidden.
document.querySelector("#target").style.top = '200px';
await waitForAnimationFrames(2);
// No shift should be reported.
assert_equals(watcher.score, 0);
}, 'visibility:hidden');
</script>
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