summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 19:43:37 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 19:43:37 +0000
commit435b212e562f37e94926df26d564efadaca81f78 (patch)
tree8f8684e0b20d50f45ff7cf40100e3ebd24eaca17 /ash
parent77a3bbbbc746fdad0ba0206e7661e4fed8a4090e (diff)
downloadchromium_src-435b212e562f37e94926df26d564efadaca81f78.zip
chromium_src-435b212e562f37e94926df26d564efadaca81f78.tar.gz
chromium_src-435b212e562f37e94926df26d564efadaca81f78.tar.bz2
Touches outside the Root Window contribute to system level gestures.
A new event filter has been added, SystemGestureEventFilter, which will handle system level gesture events. It currently consumes system level gesture events, but does nothing with them. Touches outside the root window are targeted at the root window, and touches targeted at the root window are consumed by the SystemGestureEventFilter. BUG=119498 TEST=SystemGestureEventFilterTest.*, GestureRecognizerTest.GestureEventOutsideRootWindowTap Review URL: https://chromiumcodereview.appspot.com/9837015 Patch from Tim Dresser <tdresser@chromium.org>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp3
-rw-r--r--ash/shell.cc10
-rw-r--r--ash/shell.h5
-rw-r--r--ash/wm/root_window_event_filter.cc12
-rw-r--r--ash/wm/system_gesture_event_filter.cc47
-rw-r--r--ash/wm/system_gesture_event_filter.h45
-rw-r--r--ash/wm/system_gesture_event_filter_unittest.cc48
7 files changed, 168 insertions, 2 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index c27dcb9..9313197 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -208,6 +208,8 @@
'wm/partial_screenshot_view.cc',
'wm/partial_screenshot_view.h',
'wm/shelf_auto_hide_behavior.h',
+ 'wm/system_gesture_event_filter.cc',
+ 'wm/system_gesture_event_filter.h',
'wm/system_modal_container_layout_manager.cc',
'wm/system_modal_container_layout_manager.h',
'wm/system_modal_container_event_filter.cc',
@@ -365,6 +367,7 @@
'wm/root_window_event_filter_unittest.cc',
'wm/shadow_controller_unittest.cc',
'wm/shelf_layout_manager_unittest.cc',
+ 'wm/system_gesture_event_filter_unittest.cc',
'wm/system_modal_container_layout_manager_unittest.cc',
'wm/toplevel_window_event_filter_unittest.cc',
'wm/video_detector_unittest.cc',
diff --git a/ash/shell.cc b/ash/shell.cc
index cfa9baa..955f012 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -56,6 +56,7 @@
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/stacking_controller.h"
#include "ash/wm/status_area_layout_manager.h"
+#include "ash/wm/system_gesture_event_filter.h"
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/wm/toplevel_window_event_filter.h"
#include "ash/wm/video_detector.h"
@@ -510,6 +511,11 @@ internal::InputMethodEventFilter* Shell::TestApi::input_method_event_filter() {
return shell_->input_method_filter_.get();
}
+internal::SystemGestureEventFilter*
+ Shell::TestApi::system_gesture_event_filter() {
+ return shell_->system_gesture_filter_.get();
+}
+
internal::WorkspaceController* Shell::TestApi::workspace_controller() {
return shell_->workspace_controller_.get();
}
@@ -534,6 +540,7 @@ Shell::~Shell() {
RemoveRootWindowEventFilter(partial_screenshot_filter_.get());
RemoveRootWindowEventFilter(input_method_filter_.get());
RemoveRootWindowEventFilter(window_modality_controller_.get());
+ RemoveRootWindowEventFilter(system_gesture_filter_.get());
#if !defined(OS_MACOSX)
RemoveRootWindowEventFilter(accelerator_filter_.get());
#endif
@@ -650,6 +657,9 @@ void Shell::Init() {
input_method_filter_.reset(new internal::InputMethodEventFilter);
AddRootWindowEventFilter(input_method_filter_.get());
+ system_gesture_filter_.reset(new internal::SystemGestureEventFilter);
+ AddRootWindowEventFilter(system_gesture_filter_.get());
+
root_window->SetCursor(ui::kCursorPointer);
if (initially_hide_cursor_)
root_window->ShowCursor(false);
diff --git a/ash/shell.h b/ash/shell.h
index fbf81b6..a03ede5 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -72,6 +72,7 @@ class RootWindowEventFilter;
class RootWindowLayoutManager;
class ShadowController;
class ShelfLayoutManager;
+class SystemGestureEventFilter;
class StackingController;
class TooltipController;
class VisibilityController;
@@ -98,6 +99,7 @@ class ASH_EXPORT Shell {
internal::RootWindowLayoutManager* root_window_layout();
internal::InputMethodEventFilter* input_method_event_filter();
+ internal::SystemGestureEventFilter* system_gesture_event_filter();
internal::WorkspaceController* workspace_controller();
private:
@@ -310,6 +312,9 @@ class ASH_EXPORT Shell {
// screenshot UI is active.
scoped_ptr<internal::PartialScreenshotEventFilter> partial_screenshot_filter_;
+ // An event filter which handles system level gestures
+ scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
+
#if !defined(OS_MACOSX)
// An event filter that pre-handles global accelerators.
scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
diff --git a/ash/wm/root_window_event_filter.cc b/ash/wm/root_window_event_filter.cc
index 822dfe6..1fb086b 100644
--- a/ash/wm/root_window_event_filter.cc
+++ b/ash/wm/root_window_event_filter.cc
@@ -149,8 +149,16 @@ ui::TouchStatus RootWindowEventFilter::PreHandleTouchEvent(
ui::GestureStatus RootWindowEventFilter::PreHandleGestureEvent(
aura::Window* target,
aura::GestureEvent* event) {
- // TODO(sad):
- return ui::GESTURE_STATUS_UNKNOWN;
+ ui::GestureStatus status = ui::GESTURE_STATUS_UNKNOWN;
+ if (filters_.might_have_observers()) {
+ ObserverListBase<aura::EventFilter>::Iterator it(filters_);
+ aura::EventFilter* filter;
+ while (status == ui::GESTURE_STATUS_UNKNOWN &&
+ (filter = it.GetNext()) != NULL) {
+ status = filter->PreHandleGestureEvent(target, event);
+ }
+ }
+ return status;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/ash/wm/system_gesture_event_filter.cc b/ash/wm/system_gesture_event_filter.cc
new file mode 100644
index 0000000..46f2ea17
--- /dev/null
+++ b/ash/wm/system_gesture_event_filter.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2012 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/wm/system_gesture_event_filter.h"
+
+#include "ash/shell.h"
+#include "ui/aura/event.h"
+#include "ui/aura/root_window.h"
+
+namespace ash {
+namespace internal {
+
+SystemGestureEventFilter::SystemGestureEventFilter()
+ : aura::EventFilter() {
+}
+
+SystemGestureEventFilter::~SystemGestureEventFilter() {
+}
+
+bool SystemGestureEventFilter::PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) {
+ return false;
+}
+
+bool SystemGestureEventFilter::PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) {
+ return false;
+}
+
+ui::TouchStatus SystemGestureEventFilter::PreHandleTouchEvent(
+ aura::Window* target,
+ aura::TouchEvent* event) {
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus SystemGestureEventFilter::PreHandleGestureEvent(
+ aura::Window* target, aura::GestureEvent* event) {
+ // TODO(tdresser) handle system level gesture events
+ if (target == Shell::GetRootWindow())
+ return ui::GESTURE_STATUS_CONSUMED;
+ return ui::GESTURE_STATUS_UNKNOWN;
+}
+
+} // namespace internal
+} // namespace ash
+
diff --git a/ash/wm/system_gesture_event_filter.h b/ash/wm/system_gesture_event_filter.h
new file mode 100644
index 0000000..fe58711
--- /dev/null
+++ b/ash/wm/system_gesture_event_filter.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 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_WM_SYSTEM_GESTURE_EVENT_FILTER_H_
+#define ASH_WM_SYSTEM_GESTURE_EVENT_FILTER_H_
+#pragma once
+
+#include "ash/shell.h"
+#include "ui/aura/event_filter.h"
+
+namespace aura {
+class MouseEvent;
+class KeyEvent;
+class Window;
+}
+
+namespace ash {
+namespace internal {
+
+// An event filter which handles system level gesture events.
+class SystemGestureEventFilter : public aura::EventFilter {
+ public:
+ SystemGestureEventFilter();
+ virtual ~SystemGestureEventFilter();
+
+ // Overriden from aura::EventFilter:
+ virtual bool PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) OVERRIDE;
+ virtual bool PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
+ aura::TouchEvent* event) OVERRIDE;
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemGestureEventFilter);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_WM_SYSTEM_GESTURE_EVENT_FILTER_H_
diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc
new file mode 100644
index 0000000..2a8febf
--- /dev/null
+++ b/ash/wm/system_gesture_event_filter_unittest.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2012 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/wm/system_gesture_event_filter.h"
+
+#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ui/aura/event.h"
+#include "ui/aura/root_window.h"
+
+namespace ash {
+
+typedef test::AshTestBase SystemGestureEventFilterTest;
+
+// Ensure that events targeted at the root window are consumed by the
+// system event handler.
+TEST_F(SystemGestureEventFilterTest, TapOutsideRootWindow) {
+ aura::RootWindow* root_window = Shell::GetRootWindow();
+
+ Shell::TestApi shell_test(Shell::GetInstance());
+
+ const int kTouchId = 5;
+
+ // A touch outside the root window will be associated with the root window
+ aura::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(-10, -10), kTouchId);
+ root_window->DispatchTouchEvent(&press);
+
+ aura::GestureEvent* event = new aura::GestureEvent(
+ ui::ET_GESTURE_TAP, 0, 0, 0, base::Time::Now(), 0, 0, 1 << kTouchId);
+ bool consumed = root_window->DispatchGestureEvent(event);
+
+ EXPECT_TRUE(consumed);
+
+ // Without the event filter, the touch shouldn't be consumed by the
+ // system event handler.
+ Shell::GetInstance()->RemoveRootWindowEventFilter(
+ shell_test.system_gesture_event_filter());
+
+ aura::GestureEvent* event2 = new aura::GestureEvent(
+ ui::ET_GESTURE_TAP, 0, 0, 0, base::Time::Now(), 0, 0, 1 << kTouchId);
+ consumed = root_window->DispatchGestureEvent(event2);
+
+ // The event filter doesn't exist, so the touch won't be consumed.
+ EXPECT_FALSE(consumed);
+}
+
+} // namespace ash