Chromium Code Reviews| Index: base/win/text_services_bridge.cc |
| diff --git a/base/win/text_services_bridge.cc b/base/win/text_services_bridge.cc |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..e5897b34266351a6723e99d43f76f89b1beb5b24 |
| --- /dev/null |
| +++ b/base/win/text_services_bridge.cc |
| @@ -0,0 +1,80 @@ |
| +// 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. |
| + |
| +#include "base/win/text_services_bridge.h" |
| + |
| +namespace base { |
| +namespace win { |
| + |
| +TextServicesBridge::TextServicesBridge() : client_id_(TF_CLIENTID_NULL) { |
| + is_initialized_ = scoped_com_initialiser_.succeeded(); |
|
cpu_(ooo_6.6-7.5)
2012/08/22 21:37:18
COM is initialized on this thread, don't do this.
rvargas (doing something else)
2012/08/23 01:20:19
However, this CL is introducing requirements that
|
| + if (!is_initialized_) { |
| + return; |
| + } |
| + |
| + is_initialized_ &= SUCCEEDED(thread_mgr_.CreateInstance(CLSID_TF_ThreadMgr)); |
| + if (!is_initialized_) |
| + return; |
| + |
| + is_initialized_ &= SUCCEEDED(message_pump_.QueryFrom(thread_mgr_)); |
| + is_initialized_ &= SUCCEEDED(keystroke_mgr_.QueryFrom(thread_mgr_)); |
| + // When activate succeeded, |client_id| is set valid value. |
| + is_initialized_ &= SUCCEEDED(thread_mgr_->Activate(&client_id_)); |
| +} |
| + |
| +TextServicesBridge::~TextServicesBridge() { |
| + if (is_initialized_) |
| + thread_mgr_->Deactivate(); |
| +} |
| + |
| +bool TextServicesBridge::Init() { |
| + return is_initialized_; |
|
cpu_(ooo_6.6-7.5)
2012/08/22 21:37:18
maybe we should do lines 16 to 23 here instead.
|
| +} |
| + |
| +// Wraps for ITfMessagePump::PeekMessage with win32 PeekMessage signature. |
| +// Obtains messages from application message queue. |
| +BOOL TextServicesBridge::DoPeekMessage(MSG* message, |
| + HWND hwnd, |
| + UINT msg_filter_min, |
| + UINT msg_filter_max, |
| + UINT remove_msg) { |
| + BOOL result = FALSE; |
| + if (FAILED(message_pump_->PeekMessage(message, hwnd, msg_filter_min, |
| + msg_filter_max, |
| + remove_msg, &result))) { |
| + result = FALSE; |
| + } |
| + |
| + return result; |
| +} |
| + |
| +// Sends msg to Text Service Manager. |
| +// The msg will be used to input composition text. |
| +// Returns true if|msg| was consumed by text service manager. |
| +bool TextServicesBridge::ProcessMessage(const MSG& msg) { |
| + if (msg.message == WM_KEYDOWN) { |
| + BOOL eaten = FALSE; |
| + HRESULT hr = keystroke_mgr_->TestKeyDown(msg.wParam, msg.lParam, &eaten); |
| + if (FAILED(hr) && !eaten) |
| + return false; |
| + eaten = FALSE; |
| + hr = keystroke_mgr_->KeyDown(msg.wParam, msg.lParam, &eaten); |
| + return (SUCCEEDED(hr) && eaten); |
| + } |
| + |
| + if (msg.message == WM_KEYUP) { |
| + BOOL eaten = FALSE; |
| + HRESULT hr = keystroke_mgr_->TestKeyUp(msg.wParam, msg.lParam, &eaten); |
| + if (FAILED(hr) && !eaten) |
| + return false; |
| + eaten = FALSE; |
| + hr = keystroke_mgr_->KeyUp(msg.wParam, msg.lParam, &eaten); |
| + return (SUCCEEDED(hr) && eaten); |
| + } |
| + |
| + return false; |
| +} |
| + |
| +} // namespace win |
| +} // namespace base |