Chromium Code Reviews| Index: base/message_pump_win.cc |
| diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc |
| index 40118dab657c5d6675311ddf74b090a3ee4d19b7..f553d0a86ae0f18990c9363f62e1a789137a9380 100644 |
| --- a/base/message_pump_win.cc |
| +++ b/base/message_pump_win.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/message_loop.h" |
| #include "base/metrics/histogram.h" |
| #include "base/process_util.h" |
| +#include "base/win/text_services_bridge.h" |
| #include "base/win/wrapped_window_proc.h" |
| namespace { |
| @@ -21,6 +22,24 @@ 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* msg, |
| + HWND hwnd, |
|
rvargas (doing something else)
2012/08/21 19:45:37
Indent under the first arg
yoichio
2012/08/22 08:06:50
Done.
|
| + UINT msg_filter_min, |
| + UINT msg_filter_max, |
| + UINT remove_msg) OVERRIDE { |
| + return PeekMessage(msg, hwnd, msg_filter_min, msg_filter_max, remove_msg); |
| + } |
| + virtual bool ProcessMessage(const MSG& message) OVERRIDE { |
| + return false; |
| + } |
| +}; |
| + |
| } // namespace |
| namespace base { |
| @@ -97,6 +116,12 @@ int MessagePumpWin::GetCurrentDelay() const { |
| MessagePumpForUI::MessagePumpForUI() : instance_(NULL) { |
| InitMessageWnd(); |
| + |
| + if (base::win::IsTsfAwareRequired()) |
| + message_filter_.reset(new win::TextServicesBridge); |
| + |
| + if (!message_filter_.get() || !message_filter_->Init()) |
| + message_filter_.reset(new SimpleMessageFilter); |
|
rvargas (doing something else)
2012/08/21 19:45:37
+ DCHECK Init()
yoichio
2012/08/22 08:06:50
Done.
|
| } |
| MessagePumpForUI::~MessagePumpForUI() { |
| @@ -182,7 +207,8 @@ void MessagePumpForUI::PumpOutPendingPaintMessages() { |
| 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)) |
| + if (!message_filter_->DoPeekMessage(&msg, NULL, 0, 0, |
| + PM_REMOVE | PM_QS_PAINT)) |
| break; |
| ProcessMessageHelper(msg); |
| if (state_->should_quit) // Handle WM_QUIT. |
| @@ -295,16 +321,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, |
| + PM_NOREMOVE)) { |
| WaitMessage(); |
| } |
| return; |
| @@ -361,7 +389,7 @@ 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; |
| @@ -387,12 +415,14 @@ bool MessagePumpForUI::ProcessMessageHelper(const MSG& msg) { |
| WillProcessMessage(msg); |
| - if (state_->dispatcher) { |
| - if (!state_->dispatcher->Dispatch(msg)) |
| - state_->should_quit = true; |
| - } else { |
| - TranslateMessage(&msg); |
| - DispatchMessage(&msg); |
| + if (!message_filter_->ProcessMessage(msg)) { |
| + if (state_->dispatcher) { |
|
rvargas (doing something else)
2012/08/21 19:45:37
Are you sure this is the correct behavior when the
yoichio
2012/08/22 08:06:50
Yes it is prospected about ITfKeystrokeMgr::KeyDow
|
| + if (!state_->dispatcher->Dispatch(msg)) |
| + state_->should_quit = true; |
| + } else { |
| + TranslateMessage(&msg); |
| + DispatchMessage(&msg); |
| + } |
| } |
| DidProcessMessage(msg); |
| @@ -416,10 +446,14 @@ bool MessagePumpForUI::ProcessPumpReplacementMessage() { |
| // 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 = |
| + message_filter_->DoPeekMessage(&msg, NULL, WM_PAINT, WM_PAINT, |
| + PM_REMOVE) || |
| + message_filter_->DoPeekMessage(&msg, NULL, WM_TIMER, WM_TIMER, |
| + PM_REMOVE); |
| } else { |
| - have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); |
| + have_message = (0 != message_filter_->DoPeekMessage(&msg, NULL, 0, 0, |
| + PM_REMOVE)); |
| } |
| DCHECK(!have_message || kMsgHaveWork != msg.message || |