Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: base/message_pump_x.cc

Issue 8635014: DefaultDispatcher for MessagePumpX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DeleteInstanceForTesting->DeleteInstance Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_pump_x.h ('k') | ui/aura/desktop.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_pump_x.cc
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc
index 06dea11119fc2500f8b8ad861d151f2f23118a6b..3b1ed3da1f58dab6517656fe06fc9ed8eb0fe1f8 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;
}
« no previous file with comments | « base/message_pump_x.h ('k') | ui/aura/desktop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698