Commit 7794f1cc authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

Keeps auto-hide shelf showing after opening the system tray

Due to the side effect from https://crrev.com/c/1988855, auto-hide shelf
is hidden after opening the system tray. Update on the shelf's
visibility state is triggered by the visibility change of system tray.
However, calculation on the auto-hide state depends on the state of
tray bubbles which are created/destructed after the visibility change.
This CL delays the update on the shelf's state when the visibility of
system tray changes. In addition, a test case is added for this
scenario.

Bug: 1046464
Change-Id: I72d48b5872ca9efc8160c9fd6bba6bd55addfa43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028766Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737437}
parent 00549647
...@@ -1268,6 +1268,8 @@ TEST_P(HotseatWidgetTest, ExitOverviewWithClickOnHotseat) { ...@@ -1268,6 +1268,8 @@ TEST_P(HotseatWidgetTest, ExitOverviewWithClickOnHotseat) {
// Hides the hotseat if the hotseat is in kExtendedMode and the system tray // Hides the hotseat if the hotseat is in kExtendedMode and the system tray
// is about to show (see https://crbug.com/1028321). // is about to show (see https://crbug.com/1028321).
TEST_P(HotseatWidgetTest, DismissHotseatWhenSystemTrayShows) { TEST_P(HotseatWidgetTest, DismissHotseatWhenSystemTrayShows) {
GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
TabletModeControllerTestApi().EnterTabletMode(); TabletModeControllerTestApi().EnterTabletMode();
std::unique_ptr<aura::Window> window = std::unique_ptr<aura::Window> window =
AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400)); AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
...@@ -1276,15 +1278,36 @@ TEST_P(HotseatWidgetTest, DismissHotseatWhenSystemTrayShows) { ...@@ -1276,15 +1278,36 @@ TEST_P(HotseatWidgetTest, DismissHotseatWhenSystemTrayShows) {
SwipeUpOnShelf(); SwipeUpOnShelf();
ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state()); ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
// Activates the system tray when hotseat is in kExtended mode. // Activates the system tray when hotseat is in kExtended mode and waits for
// the update in system tray to finish.
StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget(); StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
const gfx::Point status_area_widget_center = const gfx::Point status_area_widget_center =
status_area_widget->GetNativeView()->GetBoundsInScreen().CenterPoint(); status_area_widget->GetNativeView()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->GestureTapAt(status_area_widget_center); GetEventGenerator()->GestureTapAt(status_area_widget_center);
base::RunLoop().RunUntilIdle();
// Expects that the system tray shows and the hotseat is hidden. // Expects that the system tray shows and the hotseat is hidden.
EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state()); EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
EXPECT_TRUE(status_area_widget->unified_system_tray()->IsBubbleShown()); EXPECT_TRUE(status_area_widget->unified_system_tray()->IsBubbleShown());
// Early out since the remaining code is only meaningful for auto-hide shelf.
if (GetPrimaryShelf()->auto_hide_behavior() !=
ShelfAutoHideBehavior::kAlways) {
return;
}
// Auto-hide shelf should show when opening the system tray.
EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_SHOWN,
GetShelfLayoutManager()->auto_hide_state());
// Auto-hide shelf should hide when closing the system tray.
GetEventGenerator()->GestureTapAt(status_area_widget_center);
// Waits for the system tray to be closed.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_HIDDEN,
GetShelfLayoutManager()->auto_hide_state());
} }
// Tests that the work area updates once each when going to/from tablet mode // Tests that the work area updates once each when going to/from tablet mode
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ash/shelf/shelf_container_view.h" #include "ash/shelf/shelf_container_view.h"
#include "ash/shelf/shelf_tooltip_delegate.h" #include "ash/shelf/shelf_tooltip_delegate.h"
#include "ash/shelf/shelf_view.h" #include "ash/shelf/shelf_view.h"
#include "base/cancelable_callback.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_host_view.h"
#include "ui/views/context_menu_controller.h" #include "ui/views/context_menu_controller.h"
......
...@@ -1134,15 +1134,19 @@ void ShelfLayoutManager::OnCenterVisibilityChanged( ...@@ -1134,15 +1134,19 @@ void ShelfLayoutManager::OnCenterVisibilityChanged(
if (!chromeos::switches::ShouldShowShelfHotseat()) if (!chromeos::switches::ShouldShowShelfHotseat())
return; return;
if (visibility != message_center::VISIBILITY_MESSAGE_CENTER || // Uses base::CancelableClosure to handle two edge cases: (1)
hotseat_state() != HotseatState::kExtended) { // ShelfLayoutManager is destructed before the callback runs. (2) The previous
return; // callback is still pending.
} visibility_update_for_tray_callback_.Reset(base::BindOnce(
&ShelfLayoutManager::UpdateVisibilityStateForSystemTrayChange,
base::Unretained(this), visibility));
// Hides the hotseat when the hotseat is in kExtended mode and the system // OnCenterVisibilityChanged is called when the visibility of system tray
// tray shows. // is set, which is before the tray bubble is created/destructed. Meanwhile,
base::AutoReset<bool> reset(&should_hide_hotseat_, true); // we rely on the state of tray bubble to calculate the auto-hide state.
UpdateVisibilityState(); // Use ThreadTaskRunnerHandle to specify that the task runs on the UI thread.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, visibility_update_for_tray_callback_.callback());
} }
void ShelfLayoutManager::SuspendWorkAreaUpdate() { void ShelfLayoutManager::SuspendWorkAreaUpdate() {
...@@ -2825,4 +2829,18 @@ bool ShelfLayoutManager::IsWindowDragInProgress() const { ...@@ -2825,4 +2829,18 @@ bool ShelfLayoutManager::IsWindowDragInProgress() const {
return window_drag_controller_ && window_drag_controller_->drag_started(); return window_drag_controller_ && window_drag_controller_->drag_started();
} }
void ShelfLayoutManager::UpdateVisibilityStateForSystemTrayChange(
message_center::Visibility visibility) {
base::Optional<base::AutoReset<bool>> reset;
// Hides the hotseat when the hotseat is in kExtended mode and the system tray
// shows.
if (visibility == message_center::Visibility::VISIBILITY_MESSAGE_CENTER &&
hotseat_state() == HotseatState::kExtended) {
reset.emplace(&should_hide_hotseat_, true);
}
UpdateVisibilityState();
}
} // namespace ash } // namespace ash
...@@ -485,6 +485,10 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -485,6 +485,10 @@ class ASH_EXPORT ShelfLayoutManager
void MaybeCancelWindowDrag(); void MaybeCancelWindowDrag();
bool IsWindowDragInProgress() const; bool IsWindowDragInProgress() const;
// Updates the visibility state because of the change on the system tray.
void UpdateVisibilityStateForSystemTrayChange(
message_center::Visibility visibility);
// True when inside UpdateBoundsAndOpacity() method. Used to prevent calling // True when inside UpdateBoundsAndOpacity() method. Used to prevent calling
// UpdateBoundsAndOpacity() again from SetChildBounds(). // UpdateBoundsAndOpacity() again from SetChildBounds().
bool updating_bounds_ = false; bool updating_bounds_ = false;
...@@ -635,6 +639,10 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -635,6 +639,10 @@ class ASH_EXPORT ShelfLayoutManager
// Tracks whether the shelf is currently dimmed for inactivity. // Tracks whether the shelf is currently dimmed for inactivity.
bool dimmed_for_inactivity_ = false; bool dimmed_for_inactivity_ = false;
// Callback to update the shelf's state when the visibility of system tray
// changes.
base::CancelableOnceClosure visibility_update_for_tray_callback_;
// Records the presentation time for hotseat dragging. // Records the presentation time for hotseat dragging.
std::unique_ptr<PresentationTimeRecorder> hotseat_presentation_time_recorder_; std::unique_ptr<PresentationTimeRecorder> hotseat_presentation_time_recorder_;
......
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