Commit a88d3cb5 authored by minch's avatar minch Committed by Commit bot

Disallow toggling of shelf auto-hide with touch when there are no windows open.

When there are no windows opened, do not change the auto_hide status when
swiping down (or swiping up and then releasing) on the shelf.

BUG=310322

Review-Url: https://codereview.chromium.org/2824233003
Cr-Commit-Position: refs/heads/master@{#468156}
parent 1465b8cd
...@@ -864,6 +864,22 @@ gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const { ...@@ -864,6 +864,22 @@ gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const {
return show_shelf_region_in_screen; return show_shelf_region_in_screen;
} }
bool ShelfLayoutManager::HasVisibleWindow() const {
WmWindow* root =
WmWindow::Get(shelf_widget_->GetNativeWindow())->GetRootWindow();
const std::vector<WmWindow*> windows =
Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal();
// Process the window list and check if there are any visible windows.
// Ignore app list windows that may be animating to hide after dismissal.
for (auto* window : windows) {
if (window->IsVisible() && !IsAppListWindow(window) &&
root->Contains(window)) {
return true;
}
}
return false;
}
ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
ShelfVisibilityState visibility_state) const { ShelfVisibilityState visibility_state) const {
if (visibility_state != SHELF_AUTO_HIDE || !wm_shelf_->IsShelfInitialized()) if (visibility_state != SHELF_AUTO_HIDE || !wm_shelf_->IsShelfInitialized())
...@@ -887,25 +903,8 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( ...@@ -887,25 +903,8 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
shelf_widget_->status_area_widget()->IsActive())) shelf_widget_->status_area_widget()->IsActive()))
return SHELF_AUTO_HIDE_SHOWN; return SHELF_AUTO_HIDE_SHOWN;
const int64_t shelf_display_id =
WmWindow::Get(shelf_widget_->GetNativeWindow())
->GetDisplayNearestWindow()
.id();
const std::vector<WmWindow*> windows =
Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal();
// Process the window list and check if there are any visible windows.
// Ignore app list windows that may be animating to hide after dismissal.
bool visible_window = false;
for (size_t i = 0; i < windows.size(); ++i) {
if (windows[i] && windows[i]->IsVisible() && !IsAppListWindow(windows[i]) &&
!windows[i]->GetWindowState()->IsMinimized() &&
windows[i]->GetDisplayNearestWindow().id() == shelf_display_id) {
visible_window = true;
break;
}
}
// If there are no visible windows do not hide the shelf. // If there are no visible windows do not hide the shelf.
if (!visible_window) if (!HasVisibleWindow())
return SHELF_AUTO_HIDE_SHOWN; return SHELF_AUTO_HIDE_SHOWN;
if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS)
...@@ -1128,12 +1127,15 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { ...@@ -1128,12 +1127,15 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
// When in fullscreen and the shelf is forced to be auto hidden, the auto hide // When in fullscreen and the shelf is forced to be auto hidden, the auto hide
// behavior affects neither the visibility state nor the auto hide state. Set // behavior affects neither the visibility state nor the auto hide state. Set
// |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
// hide state to |gesture_drag_auto_hide_state_|. // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide
// behavior if there is at least one window visible.
gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior) if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior &&
HasVisibleWindow()) {
wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior); wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior);
else } else {
UpdateVisibilityState(); UpdateVisibilityState();
}
gesture_drag_status_ = GESTURE_DRAG_NONE; gesture_drag_status_ = GESTURE_DRAG_NONE;
} }
......
...@@ -261,6 +261,9 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -261,6 +261,9 @@ class ASH_EXPORT ShelfLayoutManager
// two displays. // two displays.
gfx::Rect GetAutoHideShowShelfRegionInScreen() const; gfx::Rect GetAutoHideShowShelfRegionInScreen() const;
// Returns true if at least one window is visible.
bool HasVisibleWindow() const;
// Returns the AutoHideState. This value is determined from the shelf and // Returns the AutoHideState. This value is determined from the shelf and
// tray. // tray.
ShelfAutoHideState CalculateAutoHideState( ShelfAutoHideState CalculateAutoHideState(
......
...@@ -550,10 +550,11 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -550,10 +550,11 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString()); EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
// Close actually, otherwise further event may be affected since widget // Minimize actually, otherwise further event may be affected since widget
// is fullscreen status. // is fullscreen status.
widget->Close(); widget->Minimize();
RunAllPendingInMessageLoop(); RunAllPendingInMessageLoop();
EXPECT_FALSE(layout_manager->HasVisibleWindow());
// The shelf should be shown because there are no more visible windows. // The shelf should be shown because there are no more visible windows.
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
...@@ -570,6 +571,62 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { ...@@ -570,6 +571,62 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior()); EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe-down to hide. This should have no effect because there are no visible
// windows.
end = start + delta;
generator.GestureScrollSequenceWithCallback(
start, end, kTimeDelta, kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
widget->Restore();
RunAllPendingInMessageLoop();
EXPECT_TRUE(layout_manager->HasVisibleWindow());
// Swipe up on the shelf. This should show the shelf and disable auto-hide
// since there is one visible window.
end = below_start - delta;
generator.GestureScrollSequenceWithCallback(
below_start, end, kTimeDelta, kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
widget->Close();
RunAllPendingInMessageLoop();
EXPECT_FALSE(layout_manager->HasVisibleWindow());
// Swipe-up to hide. This should have no effect because there are no visible
// windows.
generator.GestureScrollSequenceWithCallback(
below_start, end, kTimeDelta, kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe-down to hide. This should have no effect because there are no visible
// windows.
end = start + delta;
generator.GestureScrollSequenceWithCallback(
start, end, kTimeDelta, kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,
base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
} }
// Makes sure SetVisible updates work area and widget appropriately. // Makes sure SetVisible updates work area and widget appropriately.
......
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