Commit b5d22b70 authored by Min Chen's avatar Min Chen Committed by Commit Bot

Tap to hide the AUTO_HIDE_SHOWN shelf.

Currently we can see AUTO_HIDE_SHOWN shelf can be hidden when tap inside
some of the apps, e.g, chrome browser. That is because of the window
hierarchy, stacking changes or set bounds for the child windows. Tap
inside of some the apps like "Files" or Wallpaper can't hide the
AUTO_HIDE_SHOWN shelf since we don't have the related logic for TAP
event. This cl adds the logic that tap outside of the AUTO_HIDE_SHOWN
shelf to hide it.


Bug: 882059, b/119322652
Change-Id: I8fc5b6d06a885a7b77280cbf86de4d830c04a296
Reviewed-on: https://chromium-review.googlesource.com/c/1343511
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609885}
parent 50761482
...@@ -45,7 +45,7 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler { ...@@ -45,7 +45,7 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler {
event, static_cast<aura::Window*>(event->target())); event, static_cast<aura::Window*>(event->target()));
} }
void OnGestureEvent(ui::GestureEvent* event) override { void OnGestureEvent(ui::GestureEvent* event) override {
shelf_layout_manager_->ProcessGestureEventOnWindow( shelf_layout_manager_->ProcessGestureEventOfAutoHideShelf(
event, static_cast<aura::Window*>(event->target())); event, static_cast<aura::Window*>(event->target()));
} }
......
...@@ -349,14 +349,23 @@ void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event, ...@@ -349,14 +349,23 @@ void ShelfLayoutManager::UpdateAutoHideForMouseEvent(ui::MouseEvent* event,
} }
} }
void ShelfLayoutManager::ProcessGestureEventOnWindow(ui::GestureEvent* event, void ShelfLayoutManager::ProcessGestureEventOfAutoHideShelf(
aura::Window* target) { ui::GestureEvent* event,
aura::Window* target) {
const bool is_shelf_window = IsShelfWindow(target);
// Skip event processing if shelf widget is fully visible to let the default // Skip event processing if shelf widget is fully visible to let the default
// event dispatching do its work. // event dispatching do its work.
if (IsVisible() || in_shutdown_) if (IsVisible() || in_shutdown_) {
// Tap outside of the AUTO_HIDE_SHOWN shelf should hide it.
if (!IsShelfWindow(target) && visibility_state() == SHELF_AUTO_HIDE &&
state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN &&
event->type() == ui::ET_GESTURE_TAP) {
UpdateAutoHideState();
}
return; return;
}
if (IsShelfWindow(target)) { if (is_shelf_window) {
ui::GestureEvent event_in_screen(*event); ui::GestureEvent event_in_screen(*event);
gfx::Point location_in_screen(event->location()); gfx::Point location_in_screen(event->location());
::wm::ConvertPointToScreen(target, &location_in_screen); ::wm::ConvertPointToScreen(target, &location_in_screen);
......
...@@ -113,9 +113,10 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -113,9 +113,10 @@ class ASH_EXPORT ShelfLayoutManager
// Updates the auto-hide state for mouse events. // Updates the auto-hide state for mouse events.
void UpdateAutoHideForMouseEvent(ui::MouseEvent* event, aura::Window* target); void UpdateAutoHideForMouseEvent(ui::MouseEvent* event, aura::Window* target);
// Process the gesture events on |target|. // Called by AutoHideEventHandler to process the gesture events when shelf is
void ProcessGestureEventOnWindow(ui::GestureEvent* event, // auto hide.
aura::Window* target); void ProcessGestureEventOfAutoHideShelf(ui::GestureEvent* event,
aura::Window* target);
ShelfVisibilityState visibility_state() const { ShelfVisibilityState visibility_state() const {
return state_.visibility_state; return state_.visibility_state;
......
...@@ -2547,6 +2547,52 @@ TEST_F(ShelfLayoutManagerTest, HomeLauncherGestureHandler) { ...@@ -2547,6 +2547,52 @@ TEST_F(ShelfLayoutManagerTest, HomeLauncherGestureHandler) {
EXPECT_FALSE(gesture_handler->window()); EXPECT_FALSE(gesture_handler->window());
} }
// Tests that tap outside of the AUTO_HIDE_SHOWN shelf should hide it.
TEST_F(ShelfLayoutManagerTest, TapOutsideOfAutoHideShownShelf) {
views::Widget* widget = CreateTestWidget();
Shelf* shelf = GetPrimaryShelf();
ui::test::EventGenerator* generator = GetEventGenerator();
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
layout_manager->LayoutShelf();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
aura::Window* window = widget->GetNativeWindow();
gfx::Rect window_bounds = window->GetBoundsInScreen();
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point end(start + gfx::Vector2d(0, -80));
const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(100);
const int kNumScrollSteps = 4;
// Swipe up to show the auto-hide shelf.
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap outside the window and AUTO_HIDE_SHOWN shelf should hide the shelf.
gfx::Point tap_location =
window_bounds.bottom_right() + gfx::Vector2d(10, 10);
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Swipe up to show the auto-hide shelf again.
generator->GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap inside the AUTO_HIDE_SHOWN shelf should not hide the shelf.
gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
tap_location = gfx::Point(shelf_bounds.CenterPoint());
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Tap inside the window should still hide the shelf.
tap_location = window_bounds.origin() + gfx::Vector2d(10, 10);
generator->GestureTapAt(tap_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
class ShelfLayoutManagerKeyboardTest : public AshTestBase { class ShelfLayoutManagerKeyboardTest : public AshTestBase {
public: public:
ShelfLayoutManagerKeyboardTest() = default; ShelfLayoutManagerKeyboardTest() = default;
......
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