OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/win/text_services_bridge.h" |
| 6 |
| 7 namespace base { |
| 8 namespace win { |
| 9 |
| 10 TextServicesBridge::TextServicesBridge() : client_id_(TF_CLIENTID_NULL) { |
| 11 is_initialized_ = scoped_com_initialiser_.succeeded(); |
| 12 if (!is_initialized_) { |
| 13 return; |
| 14 } |
| 15 |
| 16 is_initialized_ &= SUCCEEDED(thread_mgr_.CreateInstance(CLSID_TF_ThreadMgr)); |
| 17 if (!is_initialized_) |
| 18 return; |
| 19 |
| 20 is_initialized_ &= SUCCEEDED(message_pump_.QueryFrom(thread_mgr_)); |
| 21 is_initialized_ &= SUCCEEDED(keystroke_mgr_.QueryFrom(thread_mgr_)); |
| 22 // When activate succeeded, |client_id| is set valid value. |
| 23 is_initialized_ &= SUCCEEDED(thread_mgr_->Activate(&client_id_)); |
| 24 } |
| 25 |
| 26 TextServicesBridge::~TextServicesBridge() { |
| 27 if (is_initialized_) |
| 28 thread_mgr_->Deactivate(); |
| 29 } |
| 30 |
| 31 bool TextServicesBridge::Init() { |
| 32 return is_initialized_; |
| 33 } |
| 34 |
| 35 BOOL TextServicesBridge::DoPeekMessage(MSG* msg, |
| 36 HWND hwnd, |
| 37 UINT msg_filter_min, |
| 38 UINT msg_filter_max, |
| 39 UINT remove_msg) { |
| 40 BOOL result = FALSE; |
| 41 if (FAILED(message_pump_->PeekMessage(msg, hwnd, msg_filter_min, |
| 42 msg_filter_max, |
| 43 remove_msg, &result))) { |
| 44 result = FALSE; |
| 45 } |
| 46 |
| 47 return result; |
| 48 } |
| 49 |
| 50 bool TextServicesBridge::ProcessMessage(const MSG& msg) { |
| 51 if (msg.message == WM_KEYDOWN) { |
| 52 BOOL eaten = FALSE; |
| 53 HRESULT hr = keystroke_mgr_->TestKeyDown(msg.wParam, msg.lParam, &eaten); |
| 54 if (FAILED(hr) && !eaten) |
| 55 return false; |
| 56 eaten = FALSE; |
| 57 hr = keystroke_mgr_->KeyDown(msg.wParam, msg.lParam, &eaten); |
| 58 return (SUCCEEDED(hr) && eaten); |
| 59 } |
| 60 |
| 61 if (msg.message == WM_KEYUP) { |
| 62 BOOL eaten = FALSE; |
| 63 HRESULT hr = keystroke_mgr_->TestKeyUp(msg.wParam, msg.lParam, &eaten); |
| 64 if (FAILED(hr) && !eaten) |
| 65 return false; |
| 66 eaten = FALSE; |
| 67 hr = keystroke_mgr_->KeyUp(msg.wParam, msg.lParam, &eaten); |
| 68 return (SUCCEEDED(hr) && eaten); |
| 69 } |
| 70 |
| 71 return false; |
| 72 } |
| 73 |
| 74 } // namespace win |
| 75 } // namespace base |
OLD | NEW |