summaryrefslogtreecommitdiffstats
path: root/ash/shelf
diff options
context:
space:
mode:
authorrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-07 19:57:58 +0000
committerrharrison@chromium.org <rharrison@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-07 19:57:58 +0000
commit6c4ad7e59ff0b4ac594db809e1e5aabb25846b66 (patch)
tree1c57bdcf613b0fd478e6613b3dbe066486e76d7c /ash/shelf
parent913c45892aaf25289aefa245ac896ddcdc8f4f13 (diff)
downloadchromium_src-6c4ad7e59ff0b4ac594db809e1e5aabb25846b66.zip
chromium_src-6c4ad7e59ff0b4ac594db809e1e5aabb25846b66.tar.gz
chromium_src-6c4ad7e59ff0b4ac594db809e1e5aabb25846b66.tar.bz2
Move bezel event routing for the shelf into ShelfLayoutManager
Currently the only functional use of BorderGestureHandler is to funnel gestures that start on a bezel sensor to the shelf. This CL moves this functionality into ShelfLayoutManager via a filter class ShelfLayoutManager::BezelEventFilter and removes BorderGestureHandler. BUG=224371 TEST=Tested that bezel gestures for the shelf and immersive mode work as expected. Tested that when rotating the screen gestures on the bezeled sides were handled or not handled by the shelf when they should be. Added test cases and ran them. Review URL: https://chromiumcodereview.appspot.com/15931005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/shelf')
-rw-r--r--ash/shelf/shelf_bezel_event_filter.cc73
-rw-r--r--ash/shelf/shelf_bezel_event_filter.h39
-rw-r--r--ash/shelf/shelf_layout_manager.cc20
-rw-r--r--ash/shelf/shelf_layout_manager.h8
-rw-r--r--ash/shelf/shelf_layout_manager_unittest.cc41
5 files changed, 173 insertions, 8 deletions
diff --git a/ash/shelf/shelf_bezel_event_filter.cc b/ash/shelf/shelf_bezel_event_filter.cc
new file mode 100644
index 0000000..12ec940
--- /dev/null
+++ b/ash/shelf/shelf_bezel_event_filter.cc
@@ -0,0 +1,73 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/shelf/shelf_bezel_event_filter.h"
+
+#include "ash/shelf/shelf_layout_manager.h"
+#include "ash/shell.h"
+
+namespace ash {
+namespace internal {
+
+ShelfBezelEventFilter::ShelfBezelEventFilter(
+ ShelfLayoutManager* shelf)
+ : shelf_(shelf),
+ in_touch_drag_(false) {
+ Shell::GetInstance()->AddPreTargetHandler(this);
+}
+
+ShelfBezelEventFilter::~ShelfBezelEventFilter() {
+ Shell::GetInstance()->RemovePreTargetHandler(this);
+}
+
+void ShelfBezelEventFilter::OnGestureEvent(
+ ui::GestureEvent* event) {
+ gfx::Rect screen =
+ Shell::GetScreen()->GetDisplayNearestPoint(event->location()).bounds();
+ if ((!screen.Contains(event->location()) &&
+ IsShelfOnBezel(screen, event->location())) ||
+ in_touch_drag_) {
+ if (gesture_handler_.ProcessGestureEvent(*event)) {
+ switch (event->type()) {
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ in_touch_drag_ = true;
+ break;
+ case ui::ET_GESTURE_SCROLL_END:
+ case ui::ET_SCROLL_FLING_START:
+ in_touch_drag_ = false;
+ break;
+ default:
+ break;
+ }
+ event->StopPropagation();
+ }
+ }
+}
+
+bool ShelfBezelEventFilter::IsShelfOnBezel(
+ const gfx::Rect& screen,
+ const gfx::Point& point) const{
+ switch (shelf_->GetAlignment()) {
+ case SHELF_ALIGNMENT_BOTTOM:
+ if (point.y() >= screen.bottom())
+ return true;
+ break;
+ case SHELF_ALIGNMENT_LEFT:
+ if (point.x() <= screen.x())
+ return true;
+ break;
+ case SHELF_ALIGNMENT_TOP:
+ if (point.y() <= screen.y())
+ return true;
+ break;
+ case SHELF_ALIGNMENT_RIGHT:
+ if (point.x() >= screen.right())
+ return true;
+ break;
+ }
+ return false;
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/shelf/shelf_bezel_event_filter.h b/ash/shelf/shelf_bezel_event_filter.h
new file mode 100644
index 0000000..5390c4e
--- /dev/null
+++ b/ash/shelf/shelf_bezel_event_filter.h
@@ -0,0 +1,39 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SHELF_SHELF_BEZEL_EVENT_FILTER_H_
+#define ASH_SHELF_SHELF_BEZEL_EVENT_FILTER_H_
+
+#include "ash/wm/gestures/shelf_gesture_handler.h"
+#include "ui/base/events/event_handler.h"
+#include "ui/gfx/rect.h"
+
+namespace ash {
+namespace internal {
+class ShelfLayoutManager;
+
+// Detects and forwards touch gestures that occur on a bezel sensor to the
+// shelf.
+class ShelfBezelEventFilter : public ui::EventHandler {
+ public:
+ explicit ShelfBezelEventFilter(ShelfLayoutManager* shelf);
+ virtual ~ShelfBezelEventFilter();
+
+ // Overridden from ui::EventHandler:
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
+
+ private:
+ bool IsShelfOnBezel(const gfx::Rect& screen,
+ const gfx::Point& point) const;
+
+ ShelfLayoutManager* shelf_; // non-owned
+ bool in_touch_drag_;
+ ShelfGestureHandler gesture_handler_;
+ DISALLOW_COPY_AND_ASSIGN(ShelfBezelEventFilter);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SHELF_SHELF_BEZEL_EVENT_FILTER_H_
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index cf3e9b3..4481e44 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -6,6 +6,9 @@
#include <algorithm>
#include <cmath>
+#include <cstring>
+#include <string>
+#include <vector>
#include "ash/ash_switches.h"
#include "ash/launcher/launcher.h"
@@ -13,6 +16,7 @@
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/session_state_delegate.h"
+#include "ash/shelf/shelf_bezel_event_filter.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
@@ -23,15 +27,19 @@
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
-#include "ash/wm/workspace_controller.h"
#include "ash/wm/workspace/workspace_animations.h"
+#include "ash/wm/workspace_controller.h"
#include "base/auto_reset.h"
#include "base/command_line.h"
+#include "base/command_line.h"
#include "base/i18n/rtl.h"
+#include "base/string_number_conversions.h"
+#include "base/string_util.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/root_window.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_handler.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"
@@ -92,7 +100,6 @@ class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler {
ShelfLayoutManager* shelf_;
bool in_mouse_drag_;
ShelfGestureHandler gesture_handler_;
-
DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
};
@@ -172,6 +179,7 @@ ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf)
shelf_(shelf),
workspace_controller_(NULL),
window_overlaps_shelf_(false),
+ bezel_event_filter_(new ShelfBezelEventFilter(this)),
gesture_drag_status_(GESTURE_DRAG_NONE),
gesture_drag_amount_(0.f),
gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
@@ -567,10 +575,10 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
if (state.visibility_state == SHELF_AUTO_HIDE) {
// When state is SHELF_AUTO_HIDE we need to track when the mouse is over the
// launcher to unhide the shelf. AutoHideEventFilter does that for us.
- if (!event_filter_)
- event_filter_.reset(new AutoHideEventFilter(this));
+ if (!auto_hide_event_filter_)
+ auto_hide_event_filter_.reset(new AutoHideEventFilter(this));
} else {
- event_filter_.reset(NULL);
+ auto_hide_event_filter_.reset(NULL);
}
auto_hide_timer_.Stop();
@@ -874,7 +882,7 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
return SHELF_AUTO_HIDE_SHOWN;
// Don't show if the user is dragging the mouse.
- if (event_filter_.get() && event_filter_->in_mouse_drag())
+ if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag())
return SHELF_AUTO_HIDE_HIDDEN;
gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen();
diff --git a/ash/shelf/shelf_layout_manager.h b/ash/shelf/shelf_layout_manager.h
index e2018f8..b68206c 100644
--- a/ash/shelf/shelf_layout_manager.h
+++ b/ash/shelf/shelf_layout_manager.h
@@ -5,6 +5,8 @@
#ifndef ASH_SHELF_SHELF_LAYOUT_MANAGER_H_
#define ASH_SHELF_SHELF_LAYOUT_MANAGER_H_
+#include <vector>
+
#include "ash/ash_export.h"
#include "ash/launcher/launcher.h"
#include "ash/shelf/background_animator.h"
@@ -38,6 +40,7 @@ class ShelfWidget;
namespace internal {
class PanelLayoutManagerTest;
+class ShelfBezelEventFilter;
class ShelfLayoutManagerTest;
class StatusAreaWidget;
class WorkspaceController;
@@ -312,7 +315,10 @@ class ASH_EXPORT ShelfLayoutManager :
// EventFilter used to detect when user moves the mouse over the launcher to
// trigger showing the launcher.
- scoped_ptr<AutoHideEventFilter> event_filter_;
+ scoped_ptr<AutoHideEventFilter> auto_hide_event_filter_;
+
+ // EventFilter used to detect when user issues a gesture on a bezel sensor.
+ scoped_ptr<ShelfBezelEventFilter> bezel_event_filter_;
ObserverList<ShelfLayoutManagerObserver> observers_;
diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc
index 524ddf7..15bab64 100644
--- a/ash/shelf/shelf_layout_manager_unittest.cc
+++ b/ash/shelf/shelf_layout_manager_unittest.cc
@@ -470,7 +470,7 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
(GetShelfWidget()->GetWindowBoundsInScreen().x() +
GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
- end.set_y(outside_start.y() - 100);
+ end = outside_start + delta;
generator.GestureScrollSequence(outside_start,
end,
base::TimeDelta::FromMilliseconds(10),
@@ -481,14 +481,53 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
+ // Swipe up from below the shelf where a bezel would be, this should show the
+ // shelf.
+ gfx::Point below_start = start;
+ if (GetShelfLayoutManager()->IsHorizontalAlignment())
+ below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
+ else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
+ below_start.set_x(
+ GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
+ else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
+ below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
+ end = below_start - delta;
+ generator.GestureScrollSequence(below_start,
+ end,
+ base::TimeDelta::FromMilliseconds(10),
+ kNumScrollSteps);
+ EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
+ EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
+ EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
+ GetShelfWidget()->GetWindowBoundsInScreen());
+ EXPECT_EQ(shelf_shown.ToString(),
+ GetShelfWidget()->GetWindowBoundsInScreen().ToString());
+
+ // Swipe down again to hide.
+ end = start + delta;
+ generator.GestureScrollSequenceWithCallback(start, end,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
+ EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
+ EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
+ EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
+ EXPECT_EQ(shelf_hidden.ToString(),
+ GetShelfWidget()->GetWindowBoundsInScreen().ToString());
+
// Make the window fullscreen.
widget->SetFullscreen(true);
gfx::Rect bounds_fullscreen = window->bounds();
EXPECT_TRUE(widget->IsFullscreen());
EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString());
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
// Swipe-up. This should not change anything.
+ end = start - delta;
generator.GestureScrollSequenceWithCallback(end, start,
base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
base::Bind(&ShelfDragCallback::ProcessScroll,