Commit e10f5fe1 authored by sadrul@chromium.org's avatar sadrul@chromium.org

x11: Remove MessagePumpObserver.

Convert the last ramining instances of MessagePumpObservers into
PlatformEventObservers, and remove support for MessagePumpObservers
from non-Windows platforms.

BUG=354062
R=sky@chromium.org
TBR=darin@chromium.org

Review URL: https://codereview.chromium.org/233653002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263158 0039d316-1c4b-4281-b951-d872f2087c98
parent d18575d0
......@@ -669,8 +669,7 @@ void MessageLoopForUI::Attach() {
}
#endif
#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || \
defined(OS_WIN) || defined(USE_X11))
#if !defined(OS_NACL) && defined(OS_WIN)
void MessageLoopForUI::AddObserver(Observer* observer) {
pump_ui()->AddObserver(observer);
}
......@@ -678,7 +677,7 @@ void MessageLoopForUI::AddObserver(Observer* observer) {
void MessageLoopForUI::RemoveObserver(Observer* observer) {
pump_ui()->RemoveObserver(observer);
}
#endif // !defined(OS_MACOSX) && !defined(OS_NACL) && !defined(OS_ANDROID)
#endif // !defined(OS_NACL) && defined(OS_WIN)
#if defined(USE_OZONE) && !defined(OS_NACL)
bool MessageLoopForUI::WatchFileDescriptor(
......
......@@ -93,8 +93,7 @@ class WaitableEvent;
//
class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
public:
#if defined(USE_AURA)
#if defined(OS_WIN)
typedef MessagePumpObserver Observer;
#elif defined(USE_GTK_MESSAGE_PUMP)
typedef MessagePumpGdkObserver Observer;
......@@ -577,10 +576,8 @@ class BASE_EXPORT MessageLoopForUI : public MessageLoop {
void Start();
#endif
#if !defined(OS_NACL) && (defined(TOOLKIT_GTK) || \
defined(OS_WIN) || defined(USE_X11))
// Please see message_pump_win/message_pump_glib for definitions of these
// methods.
#if !defined(OS_NACL) && defined(OS_WIN)
// Please see message_pump_win for definitions of these methods.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
#endif
......
......@@ -8,16 +8,16 @@
#include "base/base_export.h"
#include "base/event_types.h"
#if !defined(OS_WIN)
#error Should not be here.
#endif
namespace base {
// A MessagePumpObserver is an object that receives global
// notifications from the UI MessageLoop with MessagePumpWin or
// MessagePumpX11.
// notifications from the UI MessageLoop with MessagePumpWin.
//
// NOTE: An Observer implementation should be extremely fast!
//
// For use with MessagePumpX11, please see message_pump_glib.h for more
// info about how this is invoked in this environment.
class BASE_EXPORT MessagePumpObserver {
public:
// This method is called before processing a NativeEvent.
......
......@@ -60,20 +60,4 @@ MessagePumpX11* MessagePumpX11::Current() {
}
#endif
void MessagePumpX11::AddObserver(MessagePumpObserver* observer) {
observers_.AddObserver(observer);
}
void MessagePumpX11::RemoveObserver(MessagePumpObserver* observer) {
observers_.RemoveObserver(observer);
}
void MessagePumpX11::WillProcessXEvent(XEvent* xevent) {
FOR_EACH_OBSERVER(MessagePumpObserver, observers_, WillProcessEvent(xevent));
}
void MessagePumpX11::DidProcessXEvent(XEvent* xevent) {
FOR_EACH_OBSERVER(MessagePumpObserver, observers_, DidProcessEvent(xevent));
}
} // namespace base
......@@ -10,27 +10,14 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_pump.h"
#include "base/message_loop/message_pump_dispatcher.h"
#include "base/message_loop/message_pump_glib.h"
#include "base/message_loop/message_pump_observer.h"
#include "base/observer_list.h"
// It would be nice to include the X11 headers here so that we use Window
// instead of its typedef of unsigned long, but we can't because everything in
// chrome includes us through base/message_loop/message_loop.h, and X11's crappy
// #define heavy headers muck up half of chrome.
typedef struct _GPollFD GPollFD;
typedef struct _GSource GSource;
typedef struct _XDisplay Display;
namespace base {
// This class implements a message-pump for dispatching X events.
//
// If there's a current dispatcher given through RunWithDispatcher(), that
// dispatcher receives events. Otherwise, we route to messages to dispatchers
// who have subscribed to messages from a specific X11 window.
class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib {
public:
MessagePumpX11();
......@@ -42,21 +29,7 @@ class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib {
// Returns the UI or GPU message pump.
static MessagePumpX11* Current();
// Adds an Observer, which will start receiving notifications immediately.
void AddObserver(MessagePumpObserver* observer);
// Removes an Observer. It is safe to call this method while an Observer is
// receiving a notification callback.
void RemoveObserver(MessagePumpObserver* observer);
// Sends the event to the observers.
void WillProcessXEvent(XEvent* xevent);
void DidProcessXEvent(XEvent* xevent);
private:
// List of observers.
ObserverList<MessagePumpObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpX11);
};
......
......@@ -20,7 +20,6 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/message_loop/message_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
......@@ -41,6 +40,7 @@
#include "ui/events/event_switches.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/platform/platform_event_observer.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/events/x/device_data_manager.h"
#include "ui/events/x/device_list_cache_x.h"
......@@ -116,14 +116,15 @@ namespace internal {
// where they can be calibrated later.
// 2. Has the Calibrate method that does the actual bezel calibration,
// when invoked from X root window's event dispatcher.
class TouchEventCalibrate : public base::MessagePumpObserver {
class TouchEventCalibrate : public ui::PlatformEventObserver {
public:
TouchEventCalibrate()
: left_(0),
right_(0),
top_(0),
bottom_(0) {
base::MessageLoopForUI::current()->AddObserver(this);
if (ui::PlatformEventSource::GetInstance())
ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
#if defined(USE_XI2_MT)
std::vector<std::string> parts;
if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
......@@ -141,7 +142,8 @@ class TouchEventCalibrate : public base::MessagePumpObserver {
}
virtual ~TouchEventCalibrate() {
base::MessageLoopForUI::current()->RemoveObserver(this);
if (ui::PlatformEventSource::GetInstance())
ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
}
// Modify the location of the |event|,
......@@ -207,8 +209,8 @@ class TouchEventCalibrate : public base::MessagePumpObserver {
}
private:
// Overridden from base::MessagePumpObserver:
virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE {
// ui::PlatformEventObserver:
virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE {
#if defined(USE_XI2_MT)
if (event->type == GenericEvent &&
(event->xgeneric.evtype == XI_TouchBegin ||
......@@ -222,8 +224,7 @@ class TouchEventCalibrate : public base::MessagePumpObserver {
#endif // defined(USE_XI2_MT)
}
virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE {
}
virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {}
// The difference in screen's native resolution pixels between
// the border of the touchscreen and the border of the screen,
......
......@@ -15,8 +15,6 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "base/message_loop/message_pump_observer.h"
#include "base/message_loop/message_pump_x11.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -26,7 +24,8 @@
#include "ui/base/x/selection_utils.h"
#include "ui/base/x/x11_util.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/events/platform/platform_event_observer.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/size.h"
#include "ui/gfx/x/x11_atom_cache.h"
......@@ -57,7 +56,7 @@ const char* kAtomsToCache[] = {
///////////////////////////////////////////////////////////////////////////////
// Uses the XFixes API to provide sequence numbers for GetSequenceNumber().
class SelectionChangeObserver : public base::MessagePumpObserver {
class SelectionChangeObserver : public ui::PlatformEventObserver {
public:
static SelectionChangeObserver* GetInstance();
......@@ -72,10 +71,9 @@ class SelectionChangeObserver : public base::MessagePumpObserver {
SelectionChangeObserver();
virtual ~SelectionChangeObserver();
// Overridden from base::MessagePumpObserver:
virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE;
virtual void DidProcessEvent(
const base::NativeEvent& event) OVERRIDE {}
// ui::PlatformEventObserver:
virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {}
int event_base_;
Atom clipboard_atom_;
......@@ -107,19 +105,19 @@ SelectionChangeObserver::SelectionChangeObserver()
XFixesSelectionWindowDestroyNotifyMask |
XFixesSelectionClientCloseNotifyMask);
base::MessagePumpX11::Current()->AddObserver(this);
ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
}
}
SelectionChangeObserver::~SelectionChangeObserver() {
// We are a singleton; we will outlive our message pump.
// We are a singleton; we will outlive the event source.
}
SelectionChangeObserver* SelectionChangeObserver::GetInstance() {
return Singleton<SelectionChangeObserver>::get();
}
void SelectionChangeObserver::WillProcessEvent(const base::NativeEvent& event) {
void SelectionChangeObserver::WillProcessEvent(const ui::PlatformEvent& event) {
if (event->type == event_base_ + XFixesSelectionNotify) {
XFixesSelectionNotifyEvent* ev =
reinterpret_cast<XFixesSelectionNotifyEvent*>(event);
......
......@@ -13,8 +13,6 @@
#include <utility>
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_pump_x11.h"
#include "base/stl_util.h"
#include "ui/display/chromeos/native_display_observer.h"
#include "ui/display/chromeos/x11/display_mode_x11.h"
......@@ -22,8 +20,10 @@
#include "ui/display/chromeos/x11/display_util_x11.h"
#include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h"
#include "ui/display/x11/edid_parser_x11.h"
#include "ui/events/platform/platform_event_observer.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_error_tracker.h"
#include "ui/gfx/x/x11_types.h"
namespace ui {
......@@ -102,32 +102,33 @@ class NativeDisplayDelegateX11::HelperDelegateX11
};
////////////////////////////////////////////////////////////////////////////////
// NativeDisplayDelegateX11::MessagePumpObserverX11
// NativeDisplayDelegateX11::PlatformEventObserverX11
class NativeDisplayDelegateX11::MessagePumpObserverX11
: public base::MessagePumpObserver {
class NativeDisplayDelegateX11::PlatformEventObserverX11
: public PlatformEventObserver {
public:
MessagePumpObserverX11(HelperDelegate* delegate);
virtual ~MessagePumpObserverX11();
PlatformEventObserverX11(HelperDelegate* delegate);
virtual ~PlatformEventObserverX11();
// base::MessagePumpObserver overrides:
virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE;
virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE;
// PlatformEventObserverX11:
virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
private:
HelperDelegate* delegate_; // Not owned.
DISALLOW_COPY_AND_ASSIGN(MessagePumpObserverX11);
DISALLOW_COPY_AND_ASSIGN(PlatformEventObserverX11);
};
NativeDisplayDelegateX11::MessagePumpObserverX11::MessagePumpObserverX11(
NativeDisplayDelegateX11::PlatformEventObserverX11::PlatformEventObserverX11(
HelperDelegate* delegate)
: delegate_(delegate) {}
NativeDisplayDelegateX11::MessagePumpObserverX11::~MessagePumpObserverX11() {}
NativeDisplayDelegateX11::PlatformEventObserverX11::
~PlatformEventObserverX11() {}
void NativeDisplayDelegateX11::MessagePumpObserverX11::WillProcessEvent(
const base::NativeEvent& event) {
void NativeDisplayDelegateX11::PlatformEventObserverX11::WillProcessEvent(
const ui::PlatformEvent& event) {
// XI_HierarchyChanged events are special. There is no window associated with
// these events. So process them directly from here.
if (event->type == GenericEvent &&
......@@ -139,14 +140,14 @@ void NativeDisplayDelegateX11::MessagePumpObserverX11::WillProcessEvent(
}
}
void NativeDisplayDelegateX11::MessagePumpObserverX11::DidProcessEvent(
const base::NativeEvent& event) {}
void NativeDisplayDelegateX11::PlatformEventObserverX11::DidProcessEvent(
const ui::PlatformEvent& event) {}
////////////////////////////////////////////////////////////////////////////////
// NativeDisplayDelegateX11 implementation:
NativeDisplayDelegateX11::NativeDisplayDelegateX11()
: display_(base::MessagePumpX11::GetDefaultXDisplay()),
: display_(gfx::GetXDisplay()),
window_(DefaultRootWindow(display_)),
screen_(NULL) {}
......@@ -154,8 +155,9 @@ NativeDisplayDelegateX11::~NativeDisplayDelegateX11() {
if (ui::PlatformEventSource::GetInstance()) {
ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(
platform_event_dispatcher_.get());
ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(
platform_event_observer_.get());
}
base::MessagePumpX11::Current()->RemoveObserver(message_pump_observer_.get());
STLDeleteContainerPairSecondPointers(modes_.begin(), modes_.end());
}
......@@ -168,16 +170,18 @@ void NativeDisplayDelegateX11::Initialize() {
helper_delegate_.reset(new HelperDelegateX11(this));
platform_event_dispatcher_.reset(new NativeDisplayEventDispatcherX11(
helper_delegate_.get(), xrandr_event_base));
message_pump_observer_.reset(
new MessagePumpObserverX11(helper_delegate_.get()));
platform_event_observer_.reset(
new PlatformEventObserverX11(helper_delegate_.get()));
if (ui::PlatformEventSource::GetInstance()) {
ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(
platform_event_dispatcher_.get());
}
// We can't do this with a root window listener because XI_HierarchyChanged
// messages don't have a target window.
base::MessagePumpX11::Current()->AddObserver(message_pump_observer_.get());
ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(
platform_event_observer_.get());
}
}
void NativeDisplayDelegateX11::GrabServer() {
......
......@@ -45,7 +45,7 @@ class NativeDisplayEventDispatcherX11;
class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
public:
// Helper class that allows NativeDisplayEventDispatcherX11 and
// NativeDisplayDelegateX11::MessagePumpObserverX11 to interact with this
// NativeDisplayDelegateX11::PlatformEventObserverX11 to interact with this
// class or with mocks in tests.
class HelperDelegate {
public:
......@@ -95,7 +95,7 @@ class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
private:
class HelperDelegateX11;
class MessagePumpObserverX11;
class PlatformEventObserverX11;
// Parses all the modes made available by |screen_|.
void InitModes();
......@@ -143,7 +143,7 @@ class DISPLAY_EXPORT NativeDisplayDelegateX11 : public NativeDisplayDelegate {
scoped_ptr<NativeDisplayEventDispatcherX11> platform_event_dispatcher_;
// Processes X11 display events that have no X11 window associated with it.
scoped_ptr<MessagePumpObserverX11> message_pump_observer_;
scoped_ptr<PlatformEventObserverX11> platform_event_observer_;
// List of observers waiting for display configuration change events.
ObserverList<NativeDisplayObserver> observers_;
......
......@@ -11,7 +11,6 @@
#include <X11/XKBlib.h>
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "ui/events/event_utils.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/gfx/x/x11_types.h"
......@@ -195,12 +194,7 @@ uint32_t X11EventSource::DispatchEvent(XEvent* xevent) {
have_cookie = true;
}
// TODO(sad): Remove this once all MessagePumpObservers are turned into
// PlatformEventObservers.
base::MessagePumpX11::Current()->WillProcessXEvent(xevent);
uint32_t action = PlatformEventSource::DispatchEvent(xevent);
base::MessagePumpX11::Current()->DidProcessXEvent(xevent);
if (xevent->type == GenericEvent &&
xevent->xgeneric.evtype == XI_HierarchyChanged) {
ui::UpdateDeviceList();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment