Commit fe125c15 authored by Bryan McQuade's avatar Bryan McQuade Committed by Commit Bot

Ignore layout shift due to viewport size change.

I tested this manually, both by resizing a Chrome window, and by
simulating mobile device rotation in devtools.

Change-Id: I69297b2501827070de4255b152d3099cb91ab11e
Bug: 958832
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1653609
Commit-Queue: Bryan McQuade <bmcquade@chromium.org>
Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669830}
parent 0dd19e33
......@@ -1221,6 +1221,9 @@ void LocalFrameView::ViewportSizeChanged(bool width_changed,
frame_->GetDocument()->Lifecycle().LifecyclePostponed())
return;
if (frame_->IsMainFrame())
jank_tracker_->NotifyViewportSizeChanged();
auto* layout_view = GetLayoutView();
if (layout_view) {
// If this is the main frame, we might have got here by hiding/showing the
......
......@@ -389,6 +389,11 @@ void JankTracker::NotifyScroll(ScrollType scroll_type) {
observed_input_or_scroll_ = true;
}
void JankTracker::NotifyViewportSizeChanged() {
// This cancels any previously scheduled task from the same timer.
timer_.StartOneShot(kTimerDelay, FROM_HERE);
}
bool JankTracker::IsActive() {
// This eliminates noise from the private Page object created by
// SVGImage::DataChanged.
......
......@@ -39,6 +39,7 @@ class CORE_EXPORT JankTracker {
void NotifyPrePaintFinished();
void NotifyInput(const WebInputEvent&);
void NotifyScroll(ScrollType);
void NotifyViewportSizeChanged();
bool IsActive();
double Score() const { return score_; }
double ScoreWithMoveDistance() const { return score_with_move_distance_; }
......
......@@ -447,6 +447,41 @@ TEST_F(JankTrackerSimTest, SubframeWeighting) {
EXPECT_FLOAT_EQ(0.15, jank_tracker.WeightedScore());
}
TEST_F(JankTrackerSimTest, ViewportSizeChange) {
WebView().MainFrameWidget()->Resize(WebSize(800, 600));
SimRequest main_resource("https://example.com/", "text/html");
LoadURL("https://example.com/");
main_resource.Complete(R"HTML(
<style>
body { margin: 0; }
.square {
display: inline-block;
position: relative;
width: 300px;
height: 300px;
background:yellow;
}
</style>
<div class='square'></div>
<div class='square'></div>
)HTML");
Compositor().BeginFrame();
test::RunPendingTasks();
// Resize the viewport, making it 400px wide. This should cause the second div
// to change position during block layout flow. Since it was the result of a
// viewport size change, this position change should not affect the score.
WebView().MainFrameWidget()->Resize(WebSize(400, 600));
Compositor().BeginFrame();
test::RunPendingTasks();
JankTracker& jank_tracker = MainFrame().GetFrameView()->GetJankTracker();
EXPECT_FLOAT_EQ(0.0, jank_tracker.Score());
}
TEST_F(JankTrackerTest, StableCompositingChanges) {
SetBodyInnerHTML(R"HTML(
<style>
......
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