summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 00:09:23 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 00:09:23 +0000
commitbca7497622b009bca0597c48f8c43ec0a7121fbd (patch)
tree5c6ef8df8f8010a12a2c60a84d2ec8b2a96a7662 /ui
parent1ec8ebdcc88980cc4fd819fd020159c2bdb1f098 (diff)
downloadchromium_src-bca7497622b009bca0597c48f8c43ec0a7121fbd.zip
chromium_src-bca7497622b009bca0597c48f8c43ec0a7121fbd.tar.gz
chromium_src-bca7497622b009bca0597c48f8c43ec0a7121fbd.tar.bz2
Moves the Linux dispatcher into its own object.
Like DispatcherWin, DispatcherLinux is owned by the Env singleton. http://crbug.com/112131 TEST=compiles, tests pass Review URL: https://chromiumcodereview.appspot.com/9447048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/dispatcher_linux.cc51
-rw-r--r--ui/aura/dispatcher_linux.h47
-rw-r--r--ui/aura/dispatcher_win.cc5
-rw-r--r--ui/aura/env.cc12
-rw-r--r--ui/aura/env.h12
-rw-r--r--ui/aura/root_window.h2
-rw-r--r--ui/aura/root_window_host.h9
-rw-r--r--ui/aura/root_window_host_linux.cc15
-rw-r--r--ui/aura/root_window_host_linux.h7
10 files changed, 123 insertions, 39 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 15067cc..d70dabf 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -48,6 +48,8 @@
'client/window_move_client.h',
'client/window_types.h',
'cursor.h',
+ 'dispatcher_linux.cc',
+ 'dispatcher_linux.h',
'dispatcher_win.cc',
'env.cc',
'env.h',
diff --git a/ui/aura/dispatcher_linux.cc b/ui/aura/dispatcher_linux.cc
new file mode 100644
index 0000000..dc84bd99
--- /dev/null
+++ b/ui/aura/dispatcher_linux.cc
@@ -0,0 +1,51 @@
+// 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 "ui/aura/dispatcher_linux.h"
+
+#include <X11/extensions/XInput2.h>
+
+#include "ui/aura/root_window_host_linux.h"
+
+namespace aura {
+
+DispatcherLinux::DispatcherLinux() {
+ base::MessagePumpX::SetDefaultDispatcher(this);
+}
+
+DispatcherLinux::~DispatcherLinux() {
+ base::MessagePumpX::SetDefaultDispatcher(NULL);
+}
+
+void DispatcherLinux::RootWindowHostCreated(::Window window,
+ RootWindowHostLinux* host) {
+ hosts_.insert(std::make_pair(window, host));
+}
+
+void DispatcherLinux::RootWindowHostDestroying(::Window window) {
+ hosts_.erase(window);
+}
+
+base::MessagePumpDispatcher::DispatchStatus DispatcherLinux::Dispatch(
+ XEvent* xev) {
+ RootWindowHostLinux* host = GetRootWindowHostForXEvent(xev);
+ return host ? host->Dispatch(xev) : EVENT_IGNORED;
+}
+
+RootWindowHostLinux* DispatcherLinux::GetRootWindowHostForXEvent(
+ XEvent* xev) const {
+ ::Window window = xev->xany.window;
+ if (xev->type == GenericEvent) {
+ XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
+ window = xievent->event;
+ }
+ HostsMap::const_iterator it = hosts_.find(window);
+ return it != hosts_.end() ? it->second : NULL;
+}
+
+Dispatcher* CreateDispatcher() {
+ return new DispatcherLinux;
+}
+
+} // namespace aura
diff --git a/ui/aura/dispatcher_linux.h b/ui/aura/dispatcher_linux.h
new file mode 100644
index 0000000..11c9084
--- /dev/null
+++ b/ui/aura/dispatcher_linux.h
@@ -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.
+
+#ifndef UI_AURA_DISPATCHER_LINUX_H_
+#define UI_AURA_DISPATCHER_LINUX_H_
+#pragma once
+
+#include <map>
+#include <X11/Xlib.h>
+// Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
+#undef RootWindow
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/message_loop.h"
+#include "ui/aura/env.h"
+
+namespace aura {
+
+class RootWindowHostLinux;
+
+class DispatcherLinux : public Dispatcher {
+ public:
+ DispatcherLinux();
+ virtual ~DispatcherLinux();
+
+ void RootWindowHostCreated(::Window window, RootWindowHostLinux* host);
+ void RootWindowHostDestroying(::Window window);
+
+ // Overridden from MessageLoop::Dispatcher:
+ virtual base::MessagePumpDispatcher::DispatchStatus Dispatch(
+ XEvent* xev) OVERRIDE;
+
+ private:
+ typedef std::map< ::Window, RootWindowHostLinux* > HostsMap;
+
+ RootWindowHostLinux* GetRootWindowHostForXEvent(XEvent* xev) const;
+
+ HostsMap hosts_;
+
+ DISALLOW_COPY_AND_ASSIGN(DispatcherLinux);
+};
+
+} // namespace aura
+
+#endif // UI_AURA_DISPATCHER_LINUX_H_
diff --git a/ui/aura/dispatcher_win.cc b/ui/aura/dispatcher_win.cc
index f8a4232..eaada06 100644
--- a/ui/aura/dispatcher_win.cc
+++ b/ui/aura/dispatcher_win.cc
@@ -5,11 +5,12 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
+#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
namespace aura {
-class DispatcherWin : public MessageLoop::Dispatcher {
+class DispatcherWin : public Dispatcher {
public:
DispatcherWin() {}
virtual ~DispatcherWin() {}
@@ -27,7 +28,7 @@ bool DispatcherWin::Dispatch(const MSG& msg) {
return true;
}
-MessageLoop::Dispatcher* CreateDispatcher() {
+Dispatcher* CreateDispatcher() {
return new DispatcherWin;
}
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index 5052e32..5299f1f 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -7,10 +7,6 @@
#include "ui/aura/root_window_host.h"
#include "ui/aura/window.h"
-#if !defined(OS_MACOSX) && !defined(OS_WIN)
-#include "ui/aura/root_window.h"
-#endif
-
namespace aura {
// static
@@ -20,7 +16,7 @@ Env* Env::instance_ = NULL;
// Env, public:
Env::Env() {
-#if defined(OS_WIN)
+#if !defined(OS_MACOSX)
dispatcher_.reset(CreateDispatcher());
#endif
}
@@ -50,13 +46,7 @@ void Env::RemoveObserver(EnvObserver* observer) {
#if !defined(OS_MACOSX)
MessageLoop::Dispatcher* Env::GetDispatcher() {
-#if defined(OS_WIN)
return dispatcher_.get();
-#else
- // TODO(beng): Consolidate in the previous branch of this macro once the linux
- // dispatcher is complete.
- return RootWindow::GetInstance()->host_->GetDispatcher();
-#endif
}
#endif
diff --git a/ui/aura/env.h b/ui/aura/env.h
index feba8ed..738433c 100644
--- a/ui/aura/env.h
+++ b/ui/aura/env.h
@@ -16,9 +16,14 @@ namespace aura {
class EnvObserver;
class Window;
+class Dispatcher : public MessageLoop::Dispatcher {
+ public:
+ virtual ~Dispatcher() {}
+};
+
#if !defined(OS_MACOSX)
// Creates a platform-specific native event dispatcher.
-MessageLoop::Dispatcher* CreateDispatcher();
+Dispatcher* CreateDispatcher();
#endif
// A singleton object that tracks general state within Aura.
@@ -49,9 +54,8 @@ class AURA_EXPORT Env {
void NotifyWindowInitialized(Window* window);
ObserverList<EnvObserver> observers_;
-#if defined(OS_WIN)
- // TODO(beng): remove the ifdef once the linux dispatcher is complete.
- scoped_ptr<MessageLoop::Dispatcher> dispatcher_;
+#if !defined(OS_MACOSX)
+ scoped_ptr<Dispatcher> dispatcher_;
#endif
static Env* instance_;
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 1f999aa..dd6c716 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -201,8 +201,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
virtual void OnCompositingEnded(ui::Compositor*) OVERRIDE;
private:
- // TODO(beng): remove this friendship once the linux dispatcher is moved.
- friend class Env;
friend class Window;
RootWindow();
diff --git a/ui/aura/root_window_host.h b/ui/aura/root_window_host.h
index 4af42ac..e41e8fd 100644
--- a/ui/aura/root_window_host.h
+++ b/ui/aura/root_window_host.h
@@ -23,11 +23,7 @@ class RootWindow;
// RootWindowHost bridges between a native window and the embedded RootWindow.
// It provides the accelerated widget and maps events from the native os to
// aura.
-#if defined(OS_MACOSX) || defined(OS_WIN)
class RootWindowHost {
-#else
-class RootWindowHost : public MessageLoop::Dispatcher {
-#endif // defined(OS_MACOSX)
public:
virtual ~RootWindowHost() {}
@@ -86,11 +82,6 @@ class RootWindowHost : public MessageLoop::Dispatcher {
// Posts |native_event| to the platform's event queue.
#if !defined(OS_MACOSX)
virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0;
-
-#if !defined(OS_WIN)
- // See documentation for RootWindow::GetDispatcher().
- virtual MessageLoop::Dispatcher* GetDispatcher() = 0;
-#endif
#endif
};
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index 57f6394..b3b32c5 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -10,6 +10,8 @@
#include "base/message_pump_x.h"
#include "ui/aura/cursor.h"
+#include "ui/aura/dispatcher_linux.h"
+#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/base/keycodes/keyboard_codes.h"
@@ -287,6 +289,8 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
CopyFromParent, // visual
CWBackPixmap,
&swa);
+ static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
+ RootWindowHostCreated(xwindow_, this);
long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask |
KeyPressMask | KeyReleaseMask |
@@ -301,7 +305,6 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
if (base::MessagePumpForUI::HasXInput2())
ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_);
- base::MessagePumpX::SetDefaultDispatcher(this);
MessageLoopForUI::current()->AddDestructionObserver(this);
// Initialize invisible cursor.
@@ -317,6 +320,8 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
}
RootWindowHostLinux::~RootWindowHostLinux() {
+ static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
+ RootWindowHostDestroying(xwindow_);
XDestroyWindow(xdisplay_, xwindow_);
// Clears XCursorCache.
@@ -325,7 +330,6 @@ RootWindowHostLinux::~RootWindowHostLinux() {
XFreeCursor(xdisplay_, invisible_cursor_);
MessageLoopForUI::current()->RemoveDestructionObserver(this);
- base::MessagePumpX::SetDefaultDispatcher(NULL);
}
base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch(
@@ -489,7 +493,8 @@ base::MessagePumpDispatcher::DispatchStatus RootWindowHostLinux::Dispatch(
break;
}
}
- return handled ? EVENT_PROCESSED : EVENT_IGNORED;
+ return handled ? base::MessagePumpDispatcher::EVENT_PROCESSED :
+ base::MessagePumpDispatcher::EVENT_IGNORED;
}
void RootWindowHostLinux::SetRootWindow(RootWindow* root_window) {
@@ -626,10 +631,6 @@ void RootWindowHostLinux::PostNativeEvent(
XSendEvent(xdisplay_, xwindow_, False, 0, &xevent);
}
-MessageLoop::Dispatcher* RootWindowHostLinux::GetDispatcher() {
- return this;
-}
-
void RootWindowHostLinux::WillDestroyCurrentMessageLoop() {
aura::RootWindow::DeleteInstance();
}
diff --git a/ui/aura/root_window_host_linux.h b/ui/aura/root_window_host_linux.h
index 8fc4fa9..0d05b7b 100644
--- a/ui/aura/root_window_host_linux.h
+++ b/ui/aura/root_window_host_linux.h
@@ -23,10 +23,10 @@ class RootWindowHostLinux : public RootWindowHost,
explicit RootWindowHostLinux(const gfx::Rect& bounds);
virtual ~RootWindowHostLinux();
- private:
- // MessageLoop::Dispatcher Override.
- virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE;
+ // Handles an event targeted at this host's window.
+ base::MessagePumpDispatcher::DispatchStatus Dispatch(XEvent* xev);
+ private:
// RootWindowHost Overrides.
virtual void SetRootWindow(RootWindow* root_window) OVERRIDE;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
@@ -44,7 +44,6 @@ class RootWindowHostLinux : public RootWindowHost,
virtual void UnConfineCursor() OVERRIDE;
virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
- virtual MessageLoop::Dispatcher* GetDispatcher() OVERRIDE;
// MessageLoop::DestructionObserver Overrides.
virtual void WillDestroyCurrentMessageLoop() OVERRIDE;