Index: base/message_pump_win.cc |
diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc |
index 40118dab657c5d6675311ddf74b090a3ee4d19b7..57c602b131c1940082c49ada814e9b15130c684f 100644 |
--- a/base/message_pump_win.cc |
+++ b/base/message_pump_win.cc |
@@ -21,6 +21,25 @@ enum MessageLoopProblems { |
MESSAGE_LOOP_PROBLEM_MAX, |
}; |
+class SimpleMessageFilter : public base::MessagePumpForUI::MessageFilter { |
+ public: |
+ virtual ~SimpleMessageFilter() {} |
+ virtual bool Init() OVERRIDE { |
+ return true; |
+ } |
+ virtual BOOL DoPeekMessage(MSG* message, |
+ HWND window, |
+ UINT msg_filter_min, |
+ UINT msg_filter_max, |
+ UINT remove_msg) OVERRIDE { |
+ return PeekMessage(message, window, msg_filter_min, msg_filter_max, |
+ remove_msg); |
+ } |
+ virtual bool ProcessMessage(const MSG& message) OVERRIDE { |
+ return false; |
+ } |
+}; |
+ |
} // namespace |
namespace base { |
@@ -95,7 +114,11 @@ int MessagePumpWin::GetCurrentDelay() const { |
//----------------------------------------------------------------------------- |
// MessagePumpForUI public: |
-MessagePumpForUI::MessagePumpForUI() : instance_(NULL) { |
+MessagePumpForUI::MessagePumpForUI() |
+ : instance_(NULL), |
+ message_filter_(new SimpleMessageFilter) { |
+ DCHECK(message_filter_->Init()); |
+ |
InitMessageWnd(); |
} |
@@ -181,10 +204,11 @@ void MessagePumpForUI::PumpOutPendingPaintMessages() { |
const int kMaxPeekCount = 20; |
int peek_count; |
for (peek_count = 0; peek_count < kMaxPeekCount; ++peek_count) { |
- MSG msg; |
- if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_PAINT)) |
+ MSG message; |
+ if (!message_filter_->DoPeekMessage(&message, NULL, 0, 0, |
rvargas (doing something else)
2012/08/31 21:39:49
This is also a candidate for not using the filter.
yoichio
2012/09/03 04:45:08
Done.
|
+ PM_REMOVE | PM_QS_PAINT)) |
break; |
- ProcessMessageHelper(msg); |
+ ProcessMessageHelper(message); |
if (state_->should_quit) // Handle WM_QUIT. |
break; |
} |
@@ -295,16 +319,18 @@ void MessagePumpForUI::WaitForWork() { |
// If a parent child relationship exists between windows across threads |
// then their thread inputs are implicitly attached. |
// This causes the MsgWaitForMultipleObjectsEx API to return indicating |
- // that messages are ready for processing (specifically mouse messages |
- // intended for the child window. Occurs if the child window has capture) |
- // The subsequent PeekMessages call fails to return any messages thus |
+ // that messages are ready for processing (Specifically, mouse messages |
+ // intended for the child window may appear if the child window has |
+ // capture). |
+ // The subsequent PeekMessages call may fail to return any messages thus |
// causing us to enter a tight loop at times. |
// The WaitMessage call below is a workaround to give the child window |
- // sometime to process its input messages. |
+ // some time to process its input messages. |
MSG msg = {0}; |
DWORD queue_status = GetQueueStatus(QS_MOUSE); |
if (HIWORD(queue_status) & QS_MOUSE && |
- !PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE)) { |
+ !message_filter_->DoPeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, |
rvargas (doing something else)
2012/08/31 21:39:49
I assume that TSF can generate mouse events... and
yoichio
2012/09/03 04:45:08
Done.
|
+ PM_NOREMOVE)) { |
WaitMessage(); |
} |
return; |
@@ -361,41 +387,43 @@ bool MessagePumpForUI::ProcessNextWindowsMessage() { |
sent_messages_in_queue = true; |
MSG msg; |
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) |
+ if (message_filter_->DoPeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) |
return ProcessMessageHelper(msg); |
return sent_messages_in_queue; |
} |
-bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { |
+bool MessagePumpForUI::ProcessMessageHelper(const MSG& message) { |
TRACE_EVENT1("base", "MessagePumpForUI::ProcessMessageHelper", |
- "message", msg.message); |
- if (WM_QUIT == msg.message) { |
+ "message", message.message); |
+ if (WM_QUIT == message.message) { |
// Repost the QUIT message so that it will be retrieved by the primary |
// GetMessage() loop. |
state_->should_quit = true; |
- PostQuitMessage(static_cast<int>(msg.wParam)); |
+ PostQuitMessage(static_cast<int>(message.wParam)); |
return false; |
} |
// While running our main message pump, we discard kMsgHaveWork messages. |
- if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_) |
+ if (message.message == kMsgHaveWork && message.hwnd == message_hwnd_) |
return ProcessPumpReplacementMessage(); |
- if (CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode)) |
+ if (CallMsgFilter(const_cast<MSG*>(&message), kMessageFilterCode)) |
return true; |
- WillProcessMessage(msg); |
+ WillProcessMessage(message); |
- if (state_->dispatcher) { |
- if (!state_->dispatcher->Dispatch(msg)) |
- state_->should_quit = true; |
- } else { |
- TranslateMessage(&msg); |
- DispatchMessage(&msg); |
+ if (!message_filter_->ProcessMessage(message)) { |
+ if (state_->dispatcher) { |
+ if (!state_->dispatcher->Dispatch(message)) |
+ state_->should_quit = true; |
+ } else { |
+ TranslateMessage(&message); |
+ DispatchMessage(&message); |
+ } |
} |
- DidProcessMessage(msg); |
+ DidProcessMessage(message); |
return true; |
} |
@@ -410,20 +438,21 @@ bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
// that the re-post of kMsgHaveWork may be asynchronous to this thread!! |
bool have_message = false; |
- MSG msg; |
+ MSG message; |
// We should not process all window messages if we are in the context of an |
// OS modal loop, i.e. in the context of a windows API call like MessageBox. |
// This is to ensure that these messages are peeked out by the OS modal loop. |
if (MessageLoop::current()->os_modal_loop()) { |
// We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above. |
- have_message = PeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) || |
- PeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE); |
+ have_message = PeekMessage(&message, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) || |
+ PeekMessage(&message, NULL, WM_TIMER, WM_TIMER, PM_REMOVE); |
} else { |
- have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); |
+ have_message = !!message_filter_->DoPeekMessage(&message, NULL, 0, 0, |
+ PM_REMOVE); |
} |
- DCHECK(!have_message || kMsgHaveWork != msg.message || |
- msg.hwnd != message_hwnd_); |
+ DCHECK(!have_message || kMsgHaveWork != message.message || |
+ message.hwnd != message_hwnd_); |
// Since we discarded a kMsgHaveWork message, we must update the flag. |
int old_have_work = InterlockedExchange(&have_work_, 0); |
@@ -438,7 +467,11 @@ bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
// tasks appear very infrequently, but when the event queue is busy, the |
// kMsgHaveWork events get (percentage wise) rarer and rarer. |
ScheduleWork(); |
- return ProcessMessageHelper(msg); |
+ return ProcessMessageHelper(message); |
+} |
+ |
+void MessagePumpForUI::SetMessageFilter(MessageFilter *message_filter) { |
+ message_filter_.reset(message_filter); |
} |
//----------------------------------------------------------------------------- |