summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/accelerators/accelerator_dispatcher_linux.cc3
-rw-r--r--ash/accelerators/accelerator_dispatcher_win.cc3
-rw-r--r--ash/accelerators/nested_dispatcher_controller_unittest.cc126
-rw-r--r--ash/ash.gyp2
-rw-r--r--ui/base/cocoa/events_mac.mm4
-rw-r--r--ui/base/events.h3
-rw-r--r--ui/base/win/events_win.cc6
-rw-r--r--ui/base/x/events_x.cc18
8 files changed, 159 insertions, 6 deletions
diff --git a/ash/accelerators/accelerator_dispatcher_linux.cc b/ash/accelerators/accelerator_dispatcher_linux.cc
index 4743e94..8403480 100644
--- a/ash/accelerators/accelerator_dispatcher_linux.cc
+++ b/ash/accelerators/accelerator_dispatcher_linux.cc
@@ -17,6 +17,7 @@
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/base/accelerators/accelerator.h"
+#include "ui/base/events.h"
namespace ash {
@@ -31,7 +32,7 @@ base::MessagePumpDispatcher::DispatchStatus AcceleratorDispatcher::Dispatch(
XEvent* xev) {
if (!associated_window_)
return EVENT_QUIT;
- if (!associated_window_->CanReceiveEvents())
+ if (!ui::IsNoopEvent(xev) && !associated_window_->CanReceiveEvents())
return aura::Env::GetInstance()->GetDispatcher()->Dispatch(xev);
if (xev->type == KeyPress) {
diff --git a/ash/accelerators/accelerator_dispatcher_win.cc b/ash/accelerators/accelerator_dispatcher_win.cc
index 2aeceda..0383b3b 100644
--- a/ash/accelerators/accelerator_dispatcher_win.cc
+++ b/ash/accelerators/accelerator_dispatcher_win.cc
@@ -10,6 +10,7 @@
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/base/accelerators/accelerator.h"
+#include "ui/base/events.h"
namespace ash {
@@ -23,7 +24,7 @@ const int kModifierMask = (ui::EF_SHIFT_DOWN |
bool AcceleratorDispatcher::Dispatch(const MSG& msg) {
if (!associated_window_)
return false;
- if (!associated_window_->CanReceiveEvents())
+ if (!ui::IsNoopEvent(msg) && !associated_window_->CanReceiveEvents())
return aura::Env::GetInstance()->GetDispatcher()->Dispatch(msg);
if(msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) {
diff --git a/ash/accelerators/nested_dispatcher_controller_unittest.cc b/ash/accelerators/nested_dispatcher_controller_unittest.cc
new file mode 100644
index 0000000..47cac99
--- /dev/null
+++ b/ash/accelerators/nested_dispatcher_controller_unittest.cc
@@ -0,0 +1,126 @@
+// 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/shell.h"
+#include "ash/shell_window_ids.h"
+#include "ash/test/ash_test_base.h"
+#include "base/bind.h"
+#include "base/event_types.h"
+#include "base/message_loop.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "ui/aura/client/dispatcher_client.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/test/test_windows.h"
+#include "ui/aura/window.h"
+
+#if defined(USE_X11)
+#include <X11/Xlib.h>
+#include "ui/base/x/x11_util.h"
+#endif // USE_X11
+
+namespace ash {
+namespace test {
+
+namespace {
+
+class MockDispatcher : public MessageLoop::Dispatcher {
+ public:
+ MockDispatcher() : num_key_events_dispatched_(0) {
+ }
+
+ int num_key_events_dispatched() { return num_key_events_dispatched_; }
+
+#if defined(OS_WIN)
+ virtual bool Dispatch(MSG msg) OVERRIDE {
+ if (msg.message == WM_KEYUP)
+ num_key_events_dispatched_++;
+ return !ui::IsNoopEvent(msg);
+ }
+#elif defined(USE_X11)
+ virtual base::MessagePumpDispatcher::DispatchStatus Dispatch(
+ XEvent* xev) OVERRIDE {
+ if (xev->type == KeyRelease)
+ num_key_events_dispatched_++;
+ return ui::IsNoopEvent(xev) ? MessagePumpDispatcher::EVENT_QUIT :
+ MessagePumpDispatcher::EVENT_IGNORED;
+ }
+#endif
+
+ private:
+ int num_key_events_dispatched_;
+};
+
+void DispatchKeyEvent() {
+#if defined(OS_WIN)
+ MSG native_event = { NULL, WM_KEYUP, ui::VKEY_A, 0 };
+ ash::Shell::GetRootWindow()->PostNativeEvent(native_event);
+#elif defined(USE_X11)
+ XEvent native_event;
+ ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED,
+ ui::VKEY_A,
+ 0,
+ &native_event);
+ ash::Shell::GetRootWindow()->PostNativeEvent(&native_event);
+#endif
+
+ // Send noop event to signal dispatcher to exit.
+ ash::Shell::GetRootWindow()->PostNativeEvent(ui::CreateNoopEvent());
+}
+
+} // namespace
+
+typedef AshTestBase NestedDispatcherTest;
+
+// Aura window below lock screen in z order.
+TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) {
+ MockDispatcher inner_dispatcher;
+ aura::Window* default_container = Shell::GetInstance()->GetContainer(
+ ash::internal::kShellWindowId_DefaultContainer);
+ scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId(
+ 0, default_container));
+ scoped_ptr<aura::Window>mock_lock_container(
+ aura::test::CreateTestWindowWithId(0, default_container));
+ mock_lock_container->set_stops_event_propagation(true);
+ aura::test::CreateTestWindowWithId(0, mock_lock_container.get());
+ EXPECT_TRUE(aura::test::WindowIsAbove(mock_lock_container.get(),
+ associated_window.get()));
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&DispatchKeyEvent),
+ base::TimeDelta::FromMilliseconds(100));
+ aura::client::GetDispatcherClient()->RunWithDispatcher(
+ &inner_dispatcher,
+ associated_window.get(),
+ true /* nestable_tasks_allowed */);
+ EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched());
+}
+
+// Aura window above lock screen in z order.
+TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) {
+ MockDispatcher inner_dispatcher;
+
+ aura::Window* default_container = Shell::GetInstance()->GetContainer(
+ ash::internal::kShellWindowId_DefaultContainer);
+ scoped_ptr<aura::Window>mock_lock_container(
+ aura::test::CreateTestWindowWithId(0, default_container));
+ mock_lock_container->set_stops_event_propagation(true);
+ aura::test::CreateTestWindowWithId(0, mock_lock_container.get());
+ scoped_ptr<aura::Window>associated_window(aura::test::CreateTestWindowWithId(
+ 0, default_container));
+ EXPECT_TRUE(aura::test::WindowIsAbove(associated_window.get(),
+ mock_lock_container.get()));
+
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&DispatchKeyEvent),
+ base::TimeDelta::FromMilliseconds(100));
+ aura::client::GetDispatcherClient()->RunWithDispatcher(
+ &inner_dispatcher,
+ associated_window.get(),
+ true /* nestable_tasks_allowed */);
+ EXPECT_EQ(1, inner_dispatcher.num_key_events_dispatched());
+}
+
+} // namespace test
+} // namespace ash
diff --git a/ash/ash.gyp b/ash/ash.gyp
index ce530c7..a794547 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -246,6 +246,7 @@
'../ui/views/test/test_views_delegate.h',
'accelerators/accelerator_controller_unittest.cc',
'accelerators/accelerator_filter_unittest.cc',
+ 'accelerators/nested_dispatcher_controller_unittest.cc',
'drag_drop/drag_drop_controller_unittest.cc',
'ime/input_method_event_filter_unittest.cc',
'launcher/launcher_model_unittest.cc',
@@ -298,6 +299,7 @@
'sources/': [
['exclude', 'accelerators/accelerator_controller_unittest.cc'],
['exclude', 'accelerators/accelerator_filter_unittest.cc'],
+ ['exclude', 'accelerators/nested_dispatcher_controller_unittest.cc'],
['exclude', 'drag_drop/drag_drop_controller_unittest.cc'],
['exclude', 'tooltips/tooltip_controller_unittest.cc'],
],
diff --git a/ui/base/cocoa/events_mac.mm b/ui/base/cocoa/events_mac.mm
index f40d755..a3ae73b 100644
--- a/ui/base/cocoa/events_mac.mm
+++ b/ui/base/cocoa/events_mac.mm
@@ -179,6 +179,10 @@ bool GetScrollOffsets(const base::NativeEvent& native_event,
return false;
}
+bool IsNoopEvent(base::NativeEvent event) {
+ return ([event type] == NSApplicationDefined && [event subtype] == 0);
+}
+
base::NativeEvent CreateNoopEvent() {
return [NSEvent otherEventWithType:NSApplicationDefined
location:NSZeroPoint
diff --git a/ui/base/events.h b/ui/base/events.h
index 354c186..0334d10 100644
--- a/ui/base/events.h
+++ b/ui/base/events.h
@@ -169,6 +169,9 @@ UI_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
double* start_time,
double* end_time);
+// Returns true if event is noop.
+UI_EXPORT bool IsNoopEvent(base::NativeEvent event);
+
// Creates and returns no-op event.
UI_EXPORT base::NativeEvent CreateNoopEvent();
diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc
index d3557f2..0207e31 100644
--- a/ui/base/win/events_win.cc
+++ b/ui/base/win/events_win.cc
@@ -266,9 +266,13 @@ void UpdateDeviceList() {
NOTIMPLEMENTED();
}
+bool IsNoopEvent(base::NativeEvent event) {
+ return event.message == WM_USER + 310;
+}
+
base::NativeEvent CreateNoopEvent() {
MSG event = { NULL };
- event.message = WM_USER;
+ event.message = WM_USER + 310;
return event;
}
diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc
index 56da7b9..3be94b4 100644
--- a/ui/base/x/events_x.cc
+++ b/ui/base/x/events_x.cc
@@ -399,6 +399,15 @@ float GetTouchParamFromXEvent(XEvent* xev,
return default_value;
}
+#if !defined(TOOLKIT_USES_GTK)
+Atom GetNoopEventAtom() {
+ NOTREACHED();
+ return XInternAtom(
+ base::MessagePumpX::GetDefaultXDisplay(),
+ "noop", False);
+}
+#endif
+
} // namespace
namespace ui {
@@ -712,6 +721,11 @@ void UpdateDeviceList() {
TouchFactory::GetInstance()->UpdateDeviceList(display);
}
+bool IsNoopEvent(base::NativeEvent event) {
+ return (event->type == ClientMessage &&
+ event->xclient.message_type == GetNoopEventAtom());
+}
+
base::NativeEvent CreateNoopEvent() {
static XEvent* noop = NULL;
if (!noop) {
@@ -728,9 +742,7 @@ base::NativeEvent CreateNoopEvent() {
#else
// Make sure we use atom from current xdisplay, which may
// change during the test.
- noop->xclient.message_type = XInternAtom(
- base::MessagePumpX::GetDefaultXDisplay(),
- "noop", False);
+ noop->xclient.message_type = GetNoopEventAtom();
#endif
return noop;
}