diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-09 19:50:06 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-09 19:50:06 +0000 |
commit | 046460d54e5397286cba1b3ce9462b4129b2aaab (patch) | |
tree | 79b0e31f0a28b01ae9b1dfd12dad5be6fa3368b4 /base | |
parent | c90ec6552b57ec596c35a4c44082ad518857a393 (diff) | |
download | chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.zip chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.tar.gz chromium_src-046460d54e5397286cba1b3ce9462b4129b2aaab.tar.bz2 |
Consolidate win/x dispatchers
BUG=116282
TEST=no functional change. All tests should pass.
Review URL: http://codereview.chromium.org/9958152
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131412 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/message_loop.h | 6 | ||||
-rw-r--r-- | base/message_loop_unittest.cc | 2 | ||||
-rw-r--r-- | base/message_pump_dispatcher.h | 34 | ||||
-rw-r--r-- | base/message_pump_win.cc | 4 | ||||
-rw-r--r-- | base/message_pump_win.h | 24 | ||||
-rw-r--r-- | base/message_pump_x.cc | 7 | ||||
-rw-r--r-- | base/message_pump_x.h | 21 |
7 files changed, 45 insertions, 53 deletions
diff --git a/base/message_loop.h b/base/message_loop.h index 4527c5b..c1ffc89 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -77,10 +77,8 @@ class Histogram; // class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate { public: -#if defined(OS_WIN) - typedef base::MessagePumpWin::Dispatcher Dispatcher; - typedef base::MessagePumpObserver Observer; -#elif !defined(OS_MACOSX) && !defined(OS_ANDROID) + +#if !defined(OS_MACOSX) && !defined(OS_ANDROID) typedef base::MessagePumpDispatcher Dispatcher; typedef base::MessagePumpObserver Observer; #endif diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc index 883a805..d1e921c 100644 --- a/base/message_loop_unittest.cc +++ b/base/message_loop_unittest.cc @@ -1080,7 +1080,7 @@ class DispatcherImpl : public MessageLoopForUI::Dispatcher { public: DispatcherImpl() : dispatch_count_(0) {} - virtual bool Dispatch(const MSG& msg) { + virtual bool Dispatch(const base::NativeEvent& msg) OVERRIDE { ::TranslateMessage(&msg); ::DispatchMessage(&msg); // Do not count WM_TIMER since it is not what we post and it will cause diff --git a/base/message_pump_dispatcher.h b/base/message_pump_dispatcher.h new file mode 100644 index 0000000..685e92b --- /dev/null +++ b/base/message_pump_dispatcher.h @@ -0,0 +1,34 @@ +// 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 BASE_MESSAGE_PUMP_DISPATCHER_H +#define BASE_MESSAGE_PUMP_DISPATCHER_H +#pragma once + +#include "base/base_export.h" +#include "base/event_types.h" + +namespace base { + +// Dispatcher is used during a nested invocation of Run to dispatch +// events when |MessageLoop::RunWithDispatcher| is invoked. If +// |MessageLoop::Run| is invoked, MessageLoop does not dispatch events +// (or invoke TranslateMessage), rather every message is passed to +// Dispatcher's Dispatch method for dispatch. It is up to the +// Dispatcher whether or not to dispatch the event. +// +// The nested loop is exited by either posting a quit, or returning false +// from Dispatch. +class BASE_EXPORT MessagePumpDispatcher { + public: + virtual ~MessagePumpDispatcher() {} + + // Dispatches the event. If true is returned processing continues as + // normal. If false is returned, the nested loop exits immediately. + virtual bool Dispatch(const NativeEvent& event) = 0; +}; + +} // namespace base + +#endif // BASE_MESSAGE_PUMP_DISPATCHER_H diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc index 740ddd9..9484b29 100644 --- a/base/message_pump_win.cc +++ b/base/message_pump_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -38,7 +38,7 @@ void MessagePumpWin::DidProcessMessage(const MSG& msg) { } void MessagePumpWin::RunWithDispatcher( - Delegate* delegate, Dispatcher* dispatcher) { + Delegate* delegate, MessagePumpDispatcher* dispatcher) { RunState s; s.delegate = delegate; s.dispatcher = dispatcher; diff --git a/base/message_pump_win.h b/base/message_pump_win.h index d0d32f6..f5a00f3 100644 --- a/base/message_pump_win.h +++ b/base/message_pump_win.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -13,6 +13,7 @@ #include "base/base_export.h" #include "base/basictypes.h" #include "base/message_pump.h" +#include "base/message_pump_dispatcher.h" #include "base/message_pump_observer.h" #include "base/observer_list.h" #include "base/time.h" @@ -25,23 +26,6 @@ namespace base { // controlling the lifetime of the message pump. class BASE_EXPORT MessagePumpWin : public MessagePump { public: - - // Dispatcher is used during a nested invocation of Run to dispatch events. - // If Run is invoked with a non-NULL Dispatcher, MessageLoop does not - // dispatch events (or invoke TranslateMessage), rather every message is - // passed to Dispatcher's Dispatch method for dispatch. It is up to the - // Dispatcher to dispatch, or not, the event. - // - // The nested loop is exited by either posting a quit, or returning false - // from Dispatch. - class BASE_EXPORT Dispatcher { - public: - virtual ~Dispatcher() {} - // Dispatches the event. If true is returned processing continues as - // normal. If false is returned, the nested loop exits immediately. - virtual bool Dispatch(const MSG& msg) = 0; - }; - MessagePumpWin() : have_work_(0), state_(NULL) {} virtual ~MessagePumpWin() {} @@ -58,7 +42,7 @@ class BASE_EXPORT MessagePumpWin : public MessagePump { void DidProcessMessage(const MSG& msg); // Like MessagePump::Run, but MSG objects are routed through dispatcher. - void RunWithDispatcher(Delegate* delegate, Dispatcher* dispatcher); + void RunWithDispatcher(Delegate* delegate, MessagePumpDispatcher* dispatcher); // MessagePump methods: virtual void Run(Delegate* delegate) { RunWithDispatcher(delegate, NULL); } @@ -67,7 +51,7 @@ class BASE_EXPORT MessagePumpWin : public MessagePump { protected: struct RunState { Delegate* delegate; - Dispatcher* dispatcher; + MessagePumpDispatcher* dispatcher; // Used to flag that the current Run() invocation should return ASAP. bool should_quit; diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc index 171d5bd..e7deff0 100644 --- a/base/message_pump_x.cc +++ b/base/message_pump_x.cc @@ -144,14 +144,9 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher, } if (!WillProcessXEvent(xev)) { - MessagePumpDispatcher::DispatchStatus status = - dispatcher->Dispatch(xev); - - if (status == MessagePumpDispatcher::EVENT_QUIT) { + if (!dispatcher->Dispatch(xev)) { should_quit = true; Quit(); - } else if (status == MessagePumpDispatcher::EVENT_IGNORED) { - DVLOG(1) << "Event (" << xev->type << ") not handled."; } DidProcessXEvent(xev); } diff --git a/base/message_pump_x.h b/base/message_pump_x.h index a9c5cdb..85f7c8d 100644 --- a/base/message_pump_x.h +++ b/base/message_pump_x.h @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_pump.h" #include "base/message_pump_glib.h" +#include "base/message_pump_dispatcher.h" #include "base/message_pump_observer.h" #include <bitset> @@ -18,26 +19,6 @@ typedef struct _XDisplay Display; namespace base { -// The documentation for this class is in message_pump_glib.h -// -// The nested loop is exited by either posting a quit, or returning EVENT_QUIT -// from Dispatch. -class MessagePumpDispatcher { - public: - enum DispatchStatus { - EVENT_IGNORED, // The event was not processed. - EVENT_PROCESSED, // The event has been processed. - EVENT_QUIT // The event was processed and the message-loop should - // terminate. - }; - virtual ~MessagePumpDispatcher() {} - - // Dispatches the event. EVENT_IGNORED is returned if the event was ignored - // (i.e. not processed). EVENT_PROCESSED is returned if the event was - // processed. The nested loop exits immediately if EVENT_QUIT is returned. - virtual DispatchStatus Dispatch(XEvent* xevent) = 0; -}; - // This class implements a message-pump for dispatching X events. class BASE_EXPORT MessagePumpX : public MessagePumpGlib { public: |