Commit 06201cb6 authored by David Black's avatar David Black Committed by Commit Bot

Fix stuttering issue.

Caused by rounding. Because we previously were using host width in the
calculation (which varied across layout passes, especially during
animation) we could calculate a different center x position with each
layout pass.

Now, the child view center x position is based on its own width (which
is constant) and screen center x position (which is constant) so there
is no more stuttering issue.

Bug: b:113346276
Change-Id: Id3a95235bd15a716df51313a33e11d4d7e4006be
Reviewed-on: https://chromium-review.googlesource.com/1194970Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#587000}
parent 9bc66a10
...@@ -115,7 +115,7 @@ class AssistantContainerLayout : public views::LayoutManager { ...@@ -115,7 +115,7 @@ class AssistantContainerLayout : public views::LayoutManager {
} }
void Layout(views::View* host) override { void Layout(views::View* host) override {
const int host_width = host->width(); const int host_center_x = host->GetBoundsInScreen().CenterPoint().x();
const int host_height = host->height(); const int host_height = host->height();
for (int i = 0; i < host->child_count(); ++i) { for (int i = 0; i < host->child_count(); ++i) {
...@@ -123,8 +123,16 @@ class AssistantContainerLayout : public views::LayoutManager { ...@@ -123,8 +123,16 @@ class AssistantContainerLayout : public views::LayoutManager {
const gfx::Size child_size = child->GetPreferredSize(); const gfx::Size child_size = child->GetPreferredSize();
// Children are horizontally centered and bottom aligned. // Children are horizontally centered. This means that both the |host|
int child_left = (host_width - child_size.width()) / 2; // and child views share the same center x-coordinate relative to the
// screen. We use this center value when placing our children because
// deriving center from the host width causes rounding inconsistencies
// that are especially noticeable during animation.
gfx::Point child_center(host_center_x, /*y=*/0);
views::View::ConvertPointFromScreen(host, &child_center);
int child_left = child_center.x() - child_size.width() / 2;
// Children are bottom aligned.
int child_top = host_height - child_size.height(); int child_top = host_height - child_size.height();
child->SetBounds(child_left, child_top, child_size.width(), child->SetBounds(child_left, child_top, child_size.width(),
......
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