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.
5 #include "base/win/text_services_message_filter.h"
10 TextServicesMessageFilter::TextServicesMessageFilter()
11 : client_id_(TF_CLIENTID_NULL),
12 is_initialized_(false) {
15 TextServicesMessageFilter::~TextServicesMessageFilter() {
17 thread_mgr_->Deactivate();
20 bool TextServicesMessageFilter::Init() {
21 if (FAILED(thread_mgr_.CreateInstance(CLSID_TF_ThreadMgr)))
24 if (FAILED(message_pump_.QueryFrom(thread_mgr_)))
27 if (FAILED(keystroke_mgr_.QueryFrom(thread_mgr_)))
30 if (FAILED(thread_mgr_->Activate(&client_id_)))
33 is_initialized_ = true;
34 return is_initialized_;
37 // Wraps for ITfMessagePump::PeekMessage with win32 PeekMessage signature.
38 // Obtains messages from application message queue.
39 BOOL TextServicesMessageFilter::DoPeekMessage(MSG* msg,
45 if (FAILED(message_pump_->PeekMessage(msg, window_handle,
46 msg_filter_min, msg_filter_max,
47 remove_msg, &result))) {
54 // Sends message to Text Service Manager.
55 // The message will be used to input composition text.
56 // Returns true if |message| was consumed by text service manager.
57 bool TextServicesMessageFilter::ProcessMessage(const MSG& msg) {
58 if (msg.message == WM_KEYDOWN) {
60 HRESULT hr = keystroke_mgr_->TestKeyDown(msg.wParam, msg.lParam, &eaten);
61 if (FAILED(hr) && !eaten)
64 hr = keystroke_mgr_->KeyDown(msg.wParam, msg.lParam, &eaten);
65 return (SUCCEEDED(hr) && !!eaten);
68 if (msg.message == WM_KEYUP) {
70 HRESULT hr = keystroke_mgr_->TestKeyUp(msg.wParam, msg.lParam, &eaten);
71 if (FAILED(hr) && !eaten)
74 hr = keystroke_mgr_->KeyUp(msg.wParam, msg.lParam, &eaten);
75 return (SUCCEEDED(hr) && !!eaten);