summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 16:57:21 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-30 16:57:21 +0000
commit4168ad750ebe1bf59b29fd82dc9425c016a404e6 (patch)
treeb2fafca54811b5206c182202cb4eb8148e147566 /ui
parent9002fe205e37e1cd08480e83987e36482945958a (diff)
downloadchromium_src-4168ad750ebe1bf59b29fd82dc9425c016a404e6.zip
chromium_src-4168ad750ebe1bf59b29fd82dc9425c016a404e6.tar.gz
chromium_src-4168ad750ebe1bf59b29fd82dc9425c016a404e6.tar.bz2
Merge aura::DispatcherLinux into base::MessagePumpAuraX11.
The majority of incoming XEvents are related to specific XWindows and need to be sent to a specific MessagePumpDispatcher. MessagePumpAuraX11 would pass the XEvent to aura::DispatcherLinux, which would pass it to the next dispatcher. Because of the chromeos unit tests, which spin up a new XDisplay on each test, these two objects need to have equivalent lifetimes. Due to the incoming clipboard support (which this patch was split off from), DispatcherLinux can't live in aura:: anymore. The solution is to merge the two objects that have to have equivalent lifetimes together. The one ui:: specific check was split off into an MessagePumpObserver. This also got rid of those hacks where we would static downcast to DispatcherLinux from MessagePumpDispatcher. BUG=130805 Review URL: https://chromiumcodereview.appspot.com/10895020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp4
-rw-r--r--ui/aura/device_list_updater_aurax11.cc32
-rw-r--r--ui/aura/device_list_updater_aurax11.h32
-rw-r--r--ui/aura/dispatcher_linux.cc106
-rw-r--r--ui/aura/dispatcher_linux.h61
-rw-r--r--ui/aura/display_change_observer_x11.cc7
-rw-r--r--ui/aura/env.cc17
-rw-r--r--ui/aura/env.h7
-rw-r--r--ui/aura/root_window_host_linux.cc7
-rw-r--r--ui/views/widget/x11_desktop_handler.cc9
10 files changed, 94 insertions, 188 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index cd41c3b4..ae72753 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -69,8 +69,8 @@
'desktop/desktop_screen_x11.cc',
'desktop/desktop_stacking_client.cc',
'desktop/desktop_stacking_client.h',
- 'dispatcher_linux.cc',
- 'dispatcher_linux.h',
+ 'device_list_updater_aurax11.cc',
+ 'device_list_updater_aurax11.h',
'dispatcher_win.cc',
'display_observer.cc',
'display_observer.h',
diff --git a/ui/aura/device_list_updater_aurax11.cc b/ui/aura/device_list_updater_aurax11.cc
new file mode 100644
index 0000000..7d0b9471
--- /dev/null
+++ b/ui/aura/device_list_updater_aurax11.cc
@@ -0,0 +1,32 @@
+// 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/device_list_updater_aurax11.h"
+
+#include <X11/extensions/XInput2.h>
+
+#include "ui/base/events.h"
+
+namespace aura {
+
+DeviceListUpdaterAuraX11::DeviceListUpdaterAuraX11() {}
+
+DeviceListUpdaterAuraX11::~DeviceListUpdaterAuraX11() {}
+
+base::EventStatus DeviceListUpdaterAuraX11::WillProcessEvent(
+ const base::NativeEvent& event) {
+ // XI_HierarchyChanged events are special. There is no window associated with
+ // these events. So process them directly from here.
+ if (event->type == GenericEvent &&
+ event->xgeneric.evtype == XI_HierarchyChanged) {
+ ui::UpdateDeviceList();
+ }
+
+ return base::EVENT_CONTINUE;
+}
+
+void DeviceListUpdaterAuraX11::DidProcessEvent(const base::NativeEvent& event) {
+}
+
+} // namespace aura
diff --git a/ui/aura/device_list_updater_aurax11.h b/ui/aura/device_list_updater_aurax11.h
new file mode 100644
index 0000000..2837039
--- /dev/null
+++ b/ui/aura/device_list_updater_aurax11.h
@@ -0,0 +1,32 @@
+// 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_DEVICE_LIST_UPDATER_AURAX11_H_
+#define UI_AURA_DEVICE_LIST_UPDATER_AURAX11_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/message_pump_observer.h"
+
+namespace aura {
+
+// Filters out global XInput notifications and updates the DeviceList.
+class DeviceListUpdaterAuraX11 : public base::MessagePumpObserver {
+ public:
+ DeviceListUpdaterAuraX11();
+ virtual ~DeviceListUpdaterAuraX11();
+
+ // Overridden from base::MessagePumpObserver:
+ virtual base::EventStatus WillProcessEvent(
+ const base::NativeEvent& event) OVERRIDE;
+ virtual void DidProcessEvent(
+ const base::NativeEvent& event) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DeviceListUpdaterAuraX11);
+};
+
+} // namespace aura
+
+#endif // UI_AURA_DEVICE_LIST_UPDATER_AURAX11_H_
diff --git a/ui/aura/dispatcher_linux.cc b/ui/aura/dispatcher_linux.cc
deleted file mode 100644
index 7d13665..0000000
--- a/ui/aura/dispatcher_linux.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-// 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/base/events.h"
-
-namespace aura {
-
-DispatcherLinux::DispatcherLinux()
- : x_root_window_(
- DefaultRootWindow(base::MessagePumpAuraX11::GetDefaultXDisplay())) {
- base::MessagePumpAuraX11::SetDefaultDispatcher(this);
- MessageLoopForUI::current()->AddObserver(this);
-}
-
-DispatcherLinux::~DispatcherLinux() {
- MessageLoopForUI::current()->RemoveObserver(this);
- base::MessagePumpAuraX11::SetDefaultDispatcher(NULL);
-}
-
-void DispatcherLinux::AddDispatcherForWindow(
- MessageLoop::Dispatcher* dispatcher,
- ::Window x_window) {
- dispatchers_.insert(std::make_pair(x_window, dispatcher));
-}
-
-void DispatcherLinux::RemoveDispatcherForWindow(::Window x_window) {
- dispatchers_.erase(x_window);
-}
-
-void DispatcherLinux::AddDispatcherForRootWindow(
- MessageLoop::Dispatcher* dispatcher) {
- DCHECK(std::find(root_window_dispatchers_.begin(),
- root_window_dispatchers_.end(),
- dispatcher) ==
- root_window_dispatchers_.end());
- root_window_dispatchers_.push_back(dispatcher);
-}
-
-void DispatcherLinux::RemoveDispatcherForRootWindow(
- MessageLoop::Dispatcher* dispatcher) {
- root_window_dispatchers_.erase(
- std::remove(root_window_dispatchers_.begin(),
- root_window_dispatchers_.end(),
- dispatcher));
-}
-
-bool DispatcherLinux::Dispatch(const base::NativeEvent& xev) {
- // XI_HierarchyChanged events are special. There is no window associated with
- // these events. So process them directly from here.
- if (xev->type == GenericEvent &&
- xev->xgeneric.evtype == XI_HierarchyChanged) {
- ui::UpdateDeviceList();
- return true;
- }
-
- // MappingNotify events (meaning that the keyboard or pointer buttons have
- // been remapped) aren't associated with a window; send them to all
- // dispatchers.
- if (xev->type == MappingNotify) {
- for (DispatchersMap::const_iterator it = dispatchers_.begin();
- it != dispatchers_.end(); ++it) {
- it->second->Dispatch(xev);
- }
- return true;
- }
- if (xev->xany.window == x_root_window_) {
- for (Dispatchers::const_iterator it = root_window_dispatchers_.begin();
- it != root_window_dispatchers_.end();
- ++it) {
- (*it)->Dispatch(xev);
- }
- return true;
- }
- MessageLoop::Dispatcher* dispatcher = GetDispatcherForXEvent(xev);
- return dispatcher ? dispatcher->Dispatch(xev) : true;
-}
-
-base::EventStatus DispatcherLinux::WillProcessEvent(
- const base::NativeEvent& event) {
- return base::EVENT_CONTINUE;
-}
-
-void DispatcherLinux::DidProcessEvent(const base::NativeEvent& event) {
-}
-
-MessageLoop::Dispatcher* DispatcherLinux::GetDispatcherForXEvent(
- XEvent* xev) const {
- ::Window x_window = xev->xany.window;
- if (xev->type == GenericEvent) {
- XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
- x_window = xievent->event;
- }
- DispatchersMap::const_iterator it = dispatchers_.find(x_window);
- return it != dispatchers_.end() ? it->second : NULL;
-}
-
-MessageLoop::Dispatcher* CreateDispatcher() {
- return new DispatcherLinux;
-}
-
-} // namespace aura
diff --git a/ui/aura/dispatcher_linux.h b/ui/aura/dispatcher_linux.h
deleted file mode 100644
index 57d98b8..0000000
--- a/ui/aura/dispatcher_linux.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// 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_
-
-#include <map>
-#include <vector>
-#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/aura_export.h"
-
-namespace aura {
-
-class AURA_EXPORT DispatcherLinux : public MessageLoop::Dispatcher,
- public base::MessagePumpObserver {
- public:
- DispatcherLinux();
- virtual ~DispatcherLinux();
-
- // Adds/Removes |dispatcher| for the |x_window|.
- void AddDispatcherForWindow(MessageLoop::Dispatcher* dispatcher,
- ::Window x_window);
- void RemoveDispatcherForWindow(::Window x_window);
-
- // Adds/Removes |dispatcher| to receive all events sent to the X
- // root window.
- void AddDispatcherForRootWindow(MessageLoop::Dispatcher* dispatcher);
- void RemoveDispatcherForRootWindow(MessageLoop::Dispatcher* dispatcher);
-
- // Overridden from MessageLoop::Dispatcher:
- virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
-
- // Overridden from base::MessagePumpObserver:
- virtual base::EventStatus WillProcessEvent(
- const base::NativeEvent& event) OVERRIDE;
- virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE;
-
- private:
- typedef std::map< ::Window, MessageLoop::Dispatcher* > DispatchersMap;
- typedef std::vector<MessageLoop::Dispatcher*> Dispatchers;
-
- MessageLoop::Dispatcher* GetDispatcherForXEvent(XEvent* xev) const;
-
- DispatchersMap dispatchers_;
- Dispatchers root_window_dispatchers_;
-
- ::Window x_root_window_;
-
- DISALLOW_COPY_AND_ASSIGN(DispatcherLinux);
-};
-
-} // namespace aura
-
-#endif // UI_AURA_DISPATCHER_LINUX_H_
diff --git a/ui/aura/display_change_observer_x11.cc b/ui/aura/display_change_observer_x11.cc
index b5ffb52..af13460 100644
--- a/ui/aura/display_change_observer_x11.cc
+++ b/ui/aura/display_change_observer_x11.cc
@@ -12,7 +12,6 @@
#include <X11/extensions/Xrandr.h>
#include "base/message_pump_aurax11.h"
-#include "ui/aura/dispatcher_linux.h"
#include "ui/aura/env.h"
#include "ui/aura/display_manager.h"
#include "ui/base/x/x11_util.h"
@@ -85,13 +84,11 @@ DisplayChangeObserverX11::DisplayChangeObserverX11()
xrandr_event_base_(0) {
int error_base_ignored;
XRRQueryExtension(xdisplay_, &xrandr_event_base_, &error_base_ignored);
- static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
- AddDispatcherForRootWindow(this);
+ base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(this);
}
DisplayChangeObserverX11::~DisplayChangeObserverX11() {
- static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
- RemoveDispatcherForRootWindow(this);
+ base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(this);
}
bool DisplayChangeObserverX11::Dispatch(const base::NativeEvent& event) {
diff --git a/ui/aura/env.cc b/ui/aura/env.cc
index 90f3fbf..6c40697 100644
--- a/ui/aura/env.cc
+++ b/ui/aura/env.cc
@@ -15,6 +15,7 @@
#include "ui/compositor/compositor_switches.h"
#if defined(USE_X11)
+#include "base/message_pump_aurax11.h"
#include "ui/aura/display_change_observer_x11.h"
#endif
@@ -35,6 +36,11 @@ Env::Env()
}
Env::~Env() {
+#if defined(USE_X11)
+ base::MessagePumpAuraX11::Current()->RemoveObserver(
+ &device_list_updater_aurax11_);
+#endif
+
ui::Compositor::Terminate();
}
@@ -97,7 +103,11 @@ void Env::SetEventFilter(EventFilter* event_filter) {
#if !defined(OS_MACOSX)
MessageLoop::Dispatcher* Env::GetDispatcher() {
+#if defined(USE_X11)
+ return base::MessagePumpAuraX11::Current();
+#else
return dispatcher_.get();
+#endif
}
#endif
@@ -105,11 +115,16 @@ MessageLoop::Dispatcher* Env::GetDispatcher() {
// Env, private:
void Env::Init() {
-#if !defined(OS_MACOSX)
+#if defined(OS_WIN)
dispatcher_.reset(CreateDispatcher());
#endif
#if defined(USE_X11)
display_change_observer_.reset(new internal::DisplayChangeObserverX11);
+
+ // We can't do this with a root window listener because XI_HierarchyChanged
+ // messages don't have a target window.
+ base::MessagePumpAuraX11::Current()->AddObserver(
+ &device_list_updater_aurax11_);
#endif
ui::Compositor::Initialize(
CommandLine::ForCurrentProcess()->HasSwitch(
diff --git a/ui/aura/env.h b/ui/aura/env.h
index ffec69b..0c25b6a 100644
--- a/ui/aura/env.h
+++ b/ui/aura/env.h
@@ -12,6 +12,10 @@
#include "ui/aura/client/stacking_client.h"
#include "ui/gfx/point.h"
+#if defined(USE_X11)
+#include "ui/aura/device_list_updater_aurax11.h"
+#endif
+
namespace aura {
class EnvObserver;
class EventFilter;
@@ -96,7 +100,7 @@ class AURA_EXPORT Env {
void NotifyWindowInitialized(Window* window);
ObserverList<EnvObserver> observers_;
-#if !defined(OS_MACOSX)
+#if defined(OS_WIN)
scoped_ptr<MessageLoop::Dispatcher> dispatcher_;
#endif
@@ -115,6 +119,7 @@ class AURA_EXPORT Env {
#if defined(USE_X11)
scoped_ptr<internal::DisplayChangeObserverX11> display_change_observer_;
+ DeviceListUpdaterAuraX11 device_list_updater_aurax11_;
#endif
DISALLOW_COPY_AND_ASSIGN(Env);
diff --git a/ui/aura/root_window_host_linux.cc b/ui/aura/root_window_host_linux.cc
index e39a7f0..1821ce9 100644
--- a/ui/aura/root_window_host_linux.cc
+++ b/ui/aura/root_window_host_linux.cc
@@ -20,7 +20,6 @@
#include "grit/ui_resources.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/user_action_client.h"
-#include "ui/aura/dispatcher_linux.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/base/cursor/cursor.h"
@@ -505,8 +504,7 @@ RootWindowHostLinux::RootWindowHostLinux(RootWindowHostDelegate* delegate,
CopyFromParent, // visual
CWBackPixmap,
&swa);
- static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
- AddDispatcherForWindow(this, xwindow_);
+ base::MessagePumpAuraX11::Current()->AddDispatcherForWindow(this, xwindow_);
prop_.reset(new ui::ViewProp(xwindow_, kRootWindowHostLinuxKey, this));
@@ -569,8 +567,7 @@ RootWindowHostLinux::RootWindowHostLinux(RootWindowHostDelegate* delegate,
}
RootWindowHostLinux::~RootWindowHostLinux() {
- static_cast<DispatcherLinux*>(Env::GetInstance()->GetDispatcher())->
- RemoveDispatcherForWindow(xwindow_);
+ base::MessagePumpAuraX11::Current()->RemoveDispatcherForWindow(xwindow_);
UnConfineCursor();
diff --git a/ui/views/widget/x11_desktop_handler.cc b/ui/views/widget/x11_desktop_handler.cc
index c39fb43..98e9ff5 100644
--- a/ui/views/widget/x11_desktop_handler.cc
+++ b/ui/views/widget/x11_desktop_handler.cc
@@ -6,7 +6,6 @@
#include "base/message_loop.h"
#include "ui/aura/desktop/desktop_activation_client.h"
-#include "ui/aura/dispatcher_linux.h"
#include "ui/aura/env.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
@@ -42,9 +41,7 @@ X11DesktopHandler::X11DesktopHandler()
focus_manager_(new aura::FocusManager),
desktop_activation_client_(
new aura::DesktopActivationClient(focus_manager_.get())) {
- static_cast<aura::DispatcherLinux*>(
- aura::Env::GetInstance()->GetDispatcher())->
- AddDispatcherForRootWindow(this);
+ base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(this);
aura::Env::GetInstance()->AddObserver(this);
XWindowAttributes attr;
@@ -56,9 +53,7 @@ X11DesktopHandler::X11DesktopHandler()
X11DesktopHandler::~X11DesktopHandler() {
aura::Env::GetInstance()->RemoveObserver(this);
- static_cast<aura::DispatcherLinux*>(
- aura::Env::GetInstance()->GetDispatcher())->
- RemoveDispatcherForRootWindow(this);
+ base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(this);
}
bool X11DesktopHandler::Dispatch(const base::NativeEvent& event) {