Commit c06186d9 authored by oshima@chromium.org's avatar oshima@chromium.org

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
parent 1219d90f
...@@ -45,6 +45,10 @@ int xiopcode = -1; ...@@ -45,6 +45,10 @@ int xiopcode = -1;
// The message-pump opens a connection to the display and owns it. // The message-pump opens a connection to the display and owns it.
Display* g_xdisplay = NULL; 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) { void InitializeXInput2(void) {
Display* display = base::MessagePumpX::GetDefaultXDisplay(); Display* display = base::MessagePumpX::GetDefaultXDisplay();
if (!display) if (!display)
...@@ -108,6 +112,12 @@ bool MessagePumpX::HasXInput2() { ...@@ -108,6 +112,12 @@ bool MessagePumpX::HasXInput2() {
return xiopcode != -1; return xiopcode != -1;
} }
// static
void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) {
DCHECK(!g_default_dispatcher || !dispatcher);
g_default_dispatcher = dispatcher;
}
void MessagePumpX::InitXSource() { void MessagePumpX::InitXSource() {
DCHECK(!x_source_); DCHECK(!x_source_);
GPollFD* x_poll = new GPollFD(); GPollFD* x_poll = new GPollFD();
...@@ -122,7 +132,8 @@ void MessagePumpX::InitXSource() { ...@@ -122,7 +132,8 @@ void MessagePumpX::InitXSource() {
g_source_attach(x_source_, g_main_context_default()); 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 should_quit = false;
bool have_cookie = false; bool have_cookie = false;
...@@ -133,7 +144,7 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) { ...@@ -133,7 +144,7 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) {
if (WillProcessXEvent(xev) == EVENT_CONTINUE) { if (WillProcessXEvent(xev) == EVENT_CONTINUE) {
MessagePumpDispatcher::DispatchStatus status = MessagePumpDispatcher::DispatchStatus status =
GetDispatcher()->Dispatch(xev); dispatcher->Dispatch(xev);
if (status == MessagePumpDispatcher::EVENT_QUIT) { if (status == MessagePumpDispatcher::EVENT_QUIT) {
should_quit = true; should_quit = true;
...@@ -153,7 +164,10 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) { ...@@ -153,7 +164,10 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) {
bool MessagePumpX::RunOnce(GMainContext* context, bool block) { bool MessagePumpX::RunOnce(GMainContext* context, bool block) {
Display* display = GetDefaultXDisplay(); Display* display = GetDefaultXDisplay();
if (!display || !GetDispatcher()) MessagePumpDispatcher* dispatcher =
GetDispatcher() ? GetDispatcher() : g_default_dispatcher;
if (!display || !dispatcher)
return g_main_context_iteration(context, block); return g_main_context_iteration(context, block);
// In the general case, we want to handle all pending events before running // In the general case, we want to handle all pending events before running
...@@ -161,7 +175,7 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) { ...@@ -161,7 +175,7 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) {
while (XPending(display)) { while (XPending(display)) {
XEvent xev; XEvent xev;
XNextEvent(display, &xev); XNextEvent(display, &xev);
if (ProcessXEvent(&xev)) if (ProcessXEvent(dispatcher, &xev))
return true; return true;
} }
......
...@@ -54,13 +54,16 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib { ...@@ -54,13 +54,16 @@ class BASE_EXPORT MessagePumpX : public MessagePumpGlib {
// Returns true if the system supports XINPUT2. // Returns true if the system supports XINPUT2.
static bool HasXInput2(); static bool HasXInput2();
// Sets the default dispatcher to process native events.
static void SetDefaultDispatcher(MessagePumpDispatcher* dispatcher);
private: private:
// Initializes the glib event source for X. // Initializes the glib event source for X.
void InitXSource(); void InitXSource();
// Dispatches the XEvent and returns true if we should exit the current loop // Dispatches the XEvent and returns true if we should exit the current loop
// of message processing. // 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 // 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 // not send the event to any other observers and returns true. Returns false
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
#include "ui/gfx/compositor/compositor_cc.h" #include "ui/gfx/compositor/compositor_cc.h"
#endif #endif
#if defined(USE_X11)
#include "base/message_pump_x.h"
#endif
using std::string; using std::string;
using std::vector; using std::vector;
...@@ -101,48 +105,8 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) { ...@@ -101,48 +105,8 @@ void GetEventFiltersToNotify(Window* target, EventFilters* filters) {
Desktop* Desktop::instance_ = NULL; Desktop* Desktop::instance_ = NULL;
bool Desktop::use_fullscreen_host_window_ = false; bool Desktop::use_fullscreen_host_window_ = false;
Desktop::Desktop() ////////////////////////////////////////////////////////////////////////////////
: Window(NULL), // Desktop, public:
host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())),
ALLOW_THIS_IN_INITIALIZER_LIST(
stacking_client_(new DefaultStackingClient(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
active_window_(NULL),
mouse_button_flags_(0),
last_cursor_(kCursorNull),
in_destructor_(false),
screen_(new ScreenAura),
capture_window_(NULL),
mouse_pressed_handler_(NULL),
mouse_moved_handler_(NULL),
focused_window_(NULL),
touch_event_handler_(NULL) {
set_name("RootWindow");
gfx::Screen::SetInstance(screen_);
host_->SetDesktop(this);
last_mouse_location_ = host_->QueryMouseLocation();
if (ui::Compositor::compositor_factory()) {
compositor_ = (*ui::Compositor::compositor_factory())(this);
} else {
#ifdef USE_WEBKIT_COMPOSITOR
ui::CompositorCC::Initialize(false);
#endif
compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
host_->GetSize());
}
DCHECK(compositor_.get());
}
Desktop::~Desktop() {
in_destructor_ = true;
#ifdef USE_WEBKIT_COMPOSITOR
if (!ui::Compositor::compositor_factory())
ui::CompositorCC::Terminate();
#endif
if (instance_ == this)
instance_ = NULL;
}
// static // static
Desktop* Desktop::GetInstance() { Desktop* Desktop::GetInstance() {
...@@ -154,7 +118,7 @@ Desktop* Desktop::GetInstance() { ...@@ -154,7 +118,7 @@ Desktop* Desktop::GetInstance() {
} }
// static // static
void Desktop::DeleteInstanceForTesting() { void Desktop::DeleteInstance() {
delete instance_; delete instance_;
instance_ = NULL; instance_ = NULL;
} }
...@@ -188,7 +152,7 @@ void Desktop::SetCursor(gfx::NativeCursor cursor) { ...@@ -188,7 +152,7 @@ void Desktop::SetCursor(gfx::NativeCursor cursor) {
void Desktop::Run() { void Desktop::Run() {
ShowDesktop(); ShowDesktop();
MessageLoopForUI::current()->RunWithDispatcher(host_.get()); MessageLoopForUI::current()->Run();
} }
void Desktop::Draw() { void Desktop::Draw() {
...@@ -426,6 +390,59 @@ void Desktop::ToggleFullScreen() { ...@@ -426,6 +390,59 @@ void Desktop::ToggleFullScreen() {
} }
#endif #endif
////////////////////////////////////////////////////////////////////////////////
// Desktop, private:
Desktop::Desktop()
: Window(NULL),
host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())),
ALLOW_THIS_IN_INITIALIZER_LIST(
stacking_client_(new DefaultStackingClient(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
active_window_(NULL),
mouse_button_flags_(0),
last_cursor_(kCursorNull),
in_destructor_(false),
screen_(new ScreenAura),
capture_window_(NULL),
mouse_pressed_handler_(NULL),
mouse_moved_handler_(NULL),
focused_window_(NULL),
touch_event_handler_(NULL) {
set_name("RootWindow");
gfx::Screen::SetInstance(screen_);
host_->SetDesktop(this);
last_mouse_location_ = host_->QueryMouseLocation();
if (ui::Compositor::compositor_factory()) {
compositor_ = (*ui::Compositor::compositor_factory())(this);
} else {
#ifdef USE_WEBKIT_COMPOSITOR
ui::CompositorCC::Initialize(false);
#endif
compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
host_->GetSize());
}
DCHECK(compositor_.get());
#if defined(USE_X11)
base::MessagePumpX::SetDefaultDispatcher(host_.get());
#endif
}
Desktop::~Desktop() {
#if defined(USE_X11)
base::MessagePumpX::SetDefaultDispatcher(NULL);
#endif
in_destructor_ = true;
#ifdef USE_WEBKIT_COMPOSITOR
if (!ui::Compositor::compositor_factory())
ui::CompositorCC::Terminate();
#endif
if (instance_ == this)
instance_ = NULL;
}
void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) {
if (target == mouse_moved_handler_) if (target == mouse_moved_handler_)
return; return;
......
...@@ -46,11 +46,8 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, ...@@ -46,11 +46,8 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
public internal::FocusManager, public internal::FocusManager,
public ui::LayerAnimationObserver { public ui::LayerAnimationObserver {
public: public:
Desktop();
virtual ~Desktop();
static Desktop* GetInstance(); static Desktop* GetInstance();
static void DeleteInstanceForTesting(); static void DeleteInstance();
static void set_use_fullscreen_host_window(bool use_fullscreen) { static void set_use_fullscreen_host_window(bool use_fullscreen) {
use_fullscreen_host_window_ = use_fullscreen; use_fullscreen_host_window_ = use_fullscreen;
...@@ -151,6 +148,9 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, ...@@ -151,6 +148,9 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate,
#endif #endif
private: private:
Desktop();
virtual ~Desktop();
// Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|,
// sending exited and entered events as its value changes. // sending exited and entered events as its value changes.
void HandleMouseMoved(const MouseEvent& event, Window* target); void HandleMouseMoved(const MouseEvent& event, Window* target);
......
...@@ -42,7 +42,7 @@ AuraTestBase::~AuraTestBase() { ...@@ -42,7 +42,7 @@ AuraTestBase::~AuraTestBase() {
// Ensure that we don't use the previously-allocated static Desktop object // Ensure that we don't use the previously-allocated static Desktop object
// later -- on Linux, it holds a reference to our message loop's X connection. // later -- on Linux, it holds a reference to our message loop's X connection.
aura::Desktop::DeleteInstanceForTesting(); aura::Desktop::DeleteInstance();
} }
TestStackingClient* AuraTestBase::GetTestStackingClient() { TestStackingClient* AuraTestBase::GetTestStackingClient() {
......
...@@ -121,7 +121,7 @@ int main(int argc, char** argv) { ...@@ -121,7 +121,7 @@ int main(int argc, char** argv) {
aura::Desktop::GetInstance()->Run(); aura::Desktop::GetInstance()->Run();
delete aura::Desktop::GetInstance(); aura::Desktop::DeleteInstance();
ui::CompositorTestSupport::Terminate(); ui::CompositorTestSupport::Terminate();
......
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