diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 06:58:59 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 06:58:59 +0000 |
commit | c06186d9e84ef974d5784414b983b0bb9a343903 (patch) | |
tree | 181759e9169abaa99a55890e4e34e2ac76da736c /base | |
parent | 1219d90f11ee6196c9b9b94f140c86437dad8d88 (diff) | |
download | chromium_src-c06186d9e84ef974d5784414b983b0bb9a343903.zip chromium_src-c06186d9e84ef974d5784414b983b0bb9a343903.tar.gz chromium_src-c06186d9e84ef974d5784414b983b0bb9a343903.tar.bz2 |
DefaultDispatcher for MessagePumpX
MPX itself doesn't know how to handle events and we've been converting MessageLoop::Run() -> Desktop::Run() or RunAllPending to use ui_test_utils::RunAllPendingInMessageLoop(). It's no longer necessary with this CL.
Windows's message pump can dispatch events without dispatcher.
BUG=none
TEST=none, but I believe some of browser_tests on aura is flaky because of this, and this CL should make them less/non flaky.
Review URL: http://codereview.chromium.org/8635014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111324 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/message_pump_x.cc | 22 | ||||
-rw-r--r-- | base/message_pump_x.h | 5 |
2 files changed, 22 insertions, 5 deletions
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc index 06dea11..3b1ed3d 100644 --- a/base/message_pump_x.cc +++ b/base/message_pump_x.cc @@ -45,6 +45,10 @@ int xiopcode = -1; // The message-pump opens a connection to the display and owns it. Display* g_xdisplay = NULL; +// The default dispatcher to process native events when no dispatcher +// is specified. +base::MessagePumpDispatcher* g_default_dispatcher = NULL; + void InitializeXInput2(void) { Display* display = base::MessagePumpX::GetDefaultXDisplay(); if (!display) @@ -108,6 +112,12 @@ bool MessagePumpX::HasXInput2() { return xiopcode != -1; } +// static +void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) { + DCHECK(!g_default_dispatcher || !dispatcher); + g_default_dispatcher = dispatcher; +} + void MessagePumpX::InitXSource() { DCHECK(!x_source_); GPollFD* x_poll = new GPollFD(); @@ -122,7 +132,8 @@ void MessagePumpX::InitXSource() { g_source_attach(x_source_, g_main_context_default()); } -bool MessagePumpX::ProcessXEvent(XEvent* xev) { +bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher, + XEvent* xev) { bool should_quit = false; bool have_cookie = false; @@ -133,7 +144,7 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) { if (WillProcessXEvent(xev) == EVENT_CONTINUE) { MessagePumpDispatcher::DispatchStatus status = - GetDispatcher()->Dispatch(xev); + dispatcher->Dispatch(xev); if (status == MessagePumpDispatcher::EVENT_QUIT) { should_quit = true; @@ -153,7 +164,10 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) { bool MessagePumpX::RunOnce(GMainContext* context, bool block) { Display* display = GetDefaultXDisplay(); - if (!display || !GetDispatcher()) + MessagePumpDispatcher* dispatcher = + GetDispatcher() ? GetDispatcher() : g_default_dispatcher; + + if (!display || !dispatcher) return g_main_context_iteration(context, block); // In the general case, we want to handle all pending events before running @@ -161,7 +175,7 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) { while (XPending(display)) { XEvent xev; XNextEvent(display, &xev); - if (ProcessXEvent(&xev)) + if (ProcessXEvent(dispatcher, &xev)) return true; } diff --git a/base/message_pump_x.h b/base/message_pump_x.h index 342050f..e6bb71c 100644 --- a/base/message_pump_x.h +++ b/base/message_pump_x.h @@ -54,13 +54,16 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { // Returns true if the system supports XINPUT2. static bool HasXInput2(); + // Sets the default dispatcher to process native events. + static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher); + private: // Initializes the glib event source for X. void InitXSource(); // Dispatches the XEvent and returns true if we should exit the current loop // of message processing. - bool ProcessXEvent(XEvent* event); + bool ProcessXEvent(MessagePumpDispatcher* dispatcher, XEvent* event); // Sends the event to the observers. If an observer returns true, then it does // not send the event to any other observers and returns true. Returns false |