Skip to content

Commit

Permalink
CrOS Shelf: Animate relayouts triggered from the status area
Browse files Browse the repository at this point in the history
Bug: 1035722,1035717
Change-Id: I450d71e5800b9f66689e735ee3e144b3dff52eab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1984671
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729055}
  • Loading branch information
Manu Cornet authored and Commit Bot committed Jan 7, 2020
1 parent 1bc4336 commit e3d9856
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
13 changes: 13 additions & 0 deletions ash/shelf/back_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ TEST_P(BackButtonTest, BackKeySequenceGenerated) {
if (GetParam())
std::unique_ptr<views::Widget> widget = CreateTestWidget();

// Wait for the navigation widget's animation.
test_api()->RunMessageLoopUntilAnimationsDone(
GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->get_bounds_animator_for_testing());

AcceleratorControllerImpl* controller =
Shell::Get()->accelerator_controller();

Expand Down Expand Up @@ -167,6 +174,12 @@ TEST_P(BackButtonTest, NoContextMenuOnBackButton) {
if (GetParam())
std::unique_ptr<views::Widget> widget = CreateTestWidget();

// We need to wait for the navigation widget's animation to be done.
test_api_->RunMessageLoopUntilAnimationsDone(
GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->get_bounds_animator_for_testing());
generator->MoveMouseTo(back_button()->GetBoundsInScreen().CenterPoint());
generator->PressRightButton();

Expand Down
17 changes: 17 additions & 0 deletions ash/shelf/home_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,32 @@ TEST_P(HomeButtonTest, ButtonPositionInTabletMode) {
// When hotseat is enabled, home button position changes between in-app shelf
// and home shelf, so test in-app when hotseat is enabled.
if (GetParam()) {
// Wait for the navigation widget's animation.
test_api.RunMessageLoopUntilAnimationsDone(
GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->get_bounds_animator_for_testing());
EXPECT_EQ(home_button()->bounds().x(), 0);

// Switch to in-app shelf.
std::unique_ptr<views::Widget> widget = CreateTestWidget();
}

// Wait for the navigation widget's animation.
test_api.RunMessageLoopUntilAnimationsDone(
GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->get_bounds_animator_for_testing());
EXPECT_GT(home_button()->bounds().x(), 0);

Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
test_api.RunMessageLoopUntilAnimationsDone(
GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->get_bounds_animator_for_testing());

// Visual space around the home button is set at the widget level.
EXPECT_EQ(0, home_button()->bounds().x());
Expand Down
10 changes: 4 additions & 6 deletions ash/system/status_area_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ StatusAreaLayoutManager::~StatusAreaLayoutManager() = default;
// StatusAreaLayoutManager, aura::LayoutManager implementation:

void StatusAreaLayoutManager::OnWindowResized() {
LayoutStatusArea();
LayoutStatusArea(/*animate=*/false);
}

void StatusAreaLayoutManager::SetChildBounds(
Expand All @@ -50,21 +50,19 @@ void StatusAreaLayoutManager::SetChildBounds(
return;

WmDefaultLayoutManager::SetChildBounds(child, requested_bounds);
LayoutStatusArea();
LayoutStatusArea(/*animate=*/true);
}

////////////////////////////////////////////////////////////////////////////////
// StatusAreaLayoutManager, private:

void StatusAreaLayoutManager::LayoutStatusArea() {
void StatusAreaLayoutManager::LayoutStatusArea(bool animate) {
// Shelf layout manager may be already doing layout.
if (shelf_widget_->shelf_layout_manager()->updating_bounds())
return;

base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
// TODO(manucornet): This should be animated, but that breaks
// |LoginCursorTest|.
shelf_widget_->shelf_layout_manager()->LayoutShelf();
shelf_widget_->shelf_layout_manager()->LayoutShelf(animate);
}

} // namespace ash
2 changes: 1 addition & 1 deletion ash/system/status_area_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StatusAreaLayoutManager : public WmDefaultLayoutManager {
private:
// Updates layout of the status area. Effectively calls ShelfLayoutManager
// to update layout of the shelf.
void LayoutStatusArea();
void LayoutStatusArea(bool animate);

// True when inside LayoutStatusArea method.
// Used to prevent calling itself again from SetChildBounds().
Expand Down
1 change: 1 addition & 0 deletions ash/system/status_area_widget_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void StatusAreaWidgetTestHelper::WaitForAnimationEnd(
StatusAreaWidget* status_area_widget) {
AnimationEndObserver observer(status_area_widget->GetLayer()->GetAnimator());
observer.WaitForAnimationEnd();
status_area_widget->GetLayer()->GetAnimator()->StopAnimating();
}

} // namespace ash
3 changes: 3 additions & 0 deletions chrome/browser/chromeos/login/login_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/unified/unified_system_tray.h"
#include "base/command_line.h"
#include "chrome/browser/chrome_notification_types.h"
Expand Down Expand Up @@ -108,6 +109,8 @@ void TestSystemTrayIsVisible(bool otr) {
<< "ShelfVisibilityState=" << shelf->GetVisibilityState()
<< " ShelfAutoHideBehavior="
<< static_cast<int>(shelf->auto_hide_behavior()));
ash::StatusAreaWidgetTestHelper::WaitForAnimationEnd(
shelf->GetStatusAreaWidget());
EXPECT_TRUE(tray->GetVisible());

// This check flakes for LoginGuestTest: https://crbug.com/693106.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ash/shelf/shelf_app_button.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -337,6 +338,8 @@ IN_PROC_BROWSER_TEST_F(ArcAppDeferredLauncherBrowserTest,
// during the bounds animation. So wait for the bounds animation to finish
// then get the final bounds of the shelf button.
test_api.RunMessageLoopUntilAnimationsDone();
ash::StatusAreaWidgetTestHelper::WaitForAnimationEnd(
ash::Shelf::ForWindow(root_window)->GetStatusAreaWidget());

const int item_index =
controller->shelf_model()->ItemIndexByID(ash::ShelfID(app_id));
Expand Down

0 comments on commit e3d9856

Please sign in to comment.