Commit a87b7f44 authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

Add layout shift allowance to find-in-page

Bug: 1116592
Change-Id: I2fcd95f6310539bbb5f9bd4ec998a6cf0fd92aff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358650Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799138}
parent a744f40f
......@@ -59,6 +59,7 @@
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/layout/layout_shift_tracker.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/text_autosizer.h"
#include "third_party/blink/renderer/core/page/page.h"
......@@ -822,6 +823,13 @@ void TextFinder::FireBeforematchEvent(
// the beginning of the range. See
// https://github.com/WICG/display-locking/issues/125 for more details.
if (enclosing_block) {
// If the beforematch event handler causes layout shift, then we should
// give it layout shift allowance because it is responding to the user
// initiated find-in-page.
OwnerFrame()
.GetFrameView()
->GetLayoutShiftTracker()
.NotifyFindInPageInput();
enclosing_block->DispatchEvent(
*Event::CreateBubble(event_type_names::kBeforematch));
}
......
......@@ -595,6 +595,12 @@ void LayoutShiftTracker::NotifyViewportSizeChanged() {
UpdateInputTimestamp(base::TimeTicks::Now());
}
void LayoutShiftTracker::NotifyFindInPageInput() {
// This cancels any previously scheduled task from the same timer.
timer_.StartOneShot(kTimerDelay, FROM_HERE);
UpdateInputTimestamp(base::TimeTicks::Now());
}
std::unique_ptr<TracedValue> LayoutShiftTracker::PerFrameTraceData(
double score_delta,
bool input_detected) const {
......
......@@ -64,6 +64,7 @@ class CORE_EXPORT LayoutShiftTracker final
void NotifyInput(const WebInputEvent&);
void NotifyScroll(mojom::blink::ScrollType, ScrollOffset delta);
void NotifyViewportSizeChanged();
void NotifyFindInPageInput();
bool IsActive() const { return is_active_; }
double Score() const { return score_; }
double WeightedScore() const { return weighted_score_; }
......
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
.spacer {
height: 200px;
}
.hidden-matchable {
content-visibility: hidden-matchable;
}
</style>
<div id=hiddendiv class="hidden-matchable">
<div class="spacer"></div>
<div id=hiddentext>hiddentext</div>
</div>
<div>a bunch of</div>
<div>other stuff</div>
<script>
hiddendiv.addEventListener('beforematch', () => {
requestAnimationFrame(() => {
hiddendiv.classList.remove('hidden-matchable');
});
});
async_test(t => {
// PerformanceObserver won't work until we wait for two rAFs.
requestAnimationFrame(t.step_func(() => {
requestAnimationFrame(t.step_func(() => {
const observer = new PerformanceObserver(t.step_func_done(list => {
assert_true(list.getEntries().length === 1, 'There should be entries in the list.');
assert_true(list.getEntries()[0].hadRecentInput, 'find-in-page should mark hadRecentInput.');
}));
observer.observe({type: 'layout-shift', buffered: true});
testRunner.findString('hiddentext', ['Async']);
}));
}));
}, 'Verifies that find-in-page adds a layout shift allowance so that beforematch can cause layout shift.');
</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