OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/win/ime_input.h" | 5 #include "ui/base/win/ime_input.h" |
6 | 6 |
| 7 #include <atlbase.h> |
| 8 #include <atlcom.h> |
| 9 #include <msctf.h> |
| 10 |
7 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
9 #include "base/string16.h" | 13 #include "base/string16.h" |
10 #include "base/string_util.h" | 14 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/win/scoped_comptr.h" |
12 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
13 #include "ui/base/ime/composition_text.h" | 18 #include "ui/base/ime/composition_text.h" |
14 | 19 |
15 // "imm32.lib" is required by IMM32 APIs used in this file. | 20 // "imm32.lib" is required by IMM32 APIs used in this file. |
16 // NOTE(hbono): To comply with a comment from Darin, I have added | 21 // NOTE(hbono): To comply with a comment from Darin, I have added |
17 // this #pragma directive instead of adding "imm32.lib" to a project file. | 22 // this #pragma directive instead of adding "imm32.lib" to a project file. |
18 #pragma comment(lib, "imm32.lib") | 23 #pragma comment(lib, "imm32.lib") |
19 | 24 |
20 // Following code requires wchar_t to be same as char16. It should always be | 25 // Following code requires wchar_t to be same as char16. It should always be |
21 // true on Windows. | 26 // true on Windows. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ImeInput::~ImeInput() { | 128 ImeInput::~ImeInput() { |
124 } | 129 } |
125 | 130 |
126 bool ImeInput::SetInputLanguage() { | 131 bool ImeInput::SetInputLanguage() { |
127 // Retrieve the current keyboard layout from Windows and determine whether | 132 // Retrieve the current keyboard layout from Windows and determine whether |
128 // or not the current input context has IMEs. | 133 // or not the current input context has IMEs. |
129 // Also save its input language for language-specific operations required | 134 // Also save its input language for language-specific operations required |
130 // while composing a text. | 135 // while composing a text. |
131 HKL keyboard_layout = ::GetKeyboardLayout(0); | 136 HKL keyboard_layout = ::GetKeyboardLayout(0); |
132 input_language_id_ = reinterpret_cast<LANGID>(keyboard_layout); | 137 input_language_id_ = reinterpret_cast<LANGID>(keyboard_layout); |
133 ime_status_ = (::ImmIsIME(keyboard_layout) == TRUE); | 138 |
| 139 // Check TSF Input Processor first. |
| 140 // If the active profile is TSF INPUTPROCESSOR, this is IME. |
| 141 base::win::ScopedComPtr<ITfInputProcessorProfileMgr> prof_mgr; |
| 142 TF_INPUTPROCESSORPROFILE prof; |
| 143 if (SUCCEEDED(prof_mgr.CreateInstance(CLSID_TF_InputProcessorProfiles)) && |
| 144 SUCCEEDED(prof_mgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &prof)) && |
| 145 prof.hkl == NULL && |
| 146 prof.dwProfileType == TF_PROFILETYPE_INPUTPROCESSOR) { |
| 147 ime_status_ = true; |
| 148 } else { |
| 149 // If the curent language is not using TSF, check IMM32 based IMEs. |
| 150 // As ImmIsIME always returns non-0 value on Vista+, use ImmGetIMEFileName |
| 151 // instead to check if this HKL has any associated IME file. |
| 152 ime_status_ = (ImmGetIMEFileName(keyboard_layout, NULL, 0) != 0); |
| 153 } |
| 154 |
134 return ime_status_; | 155 return ime_status_; |
135 } | 156 } |
136 | 157 |
137 void ImeInput::CreateImeWindow(HWND window_handle) { | 158 void ImeInput::CreateImeWindow(HWND window_handle) { |
138 // When a user disables TSF (Text Service Framework) and CUAS (Cicero | 159 // When a user disables TSF (Text Service Framework) and CUAS (Cicero |
139 // Unaware Application Support), Chinese IMEs somehow ignore function calls | 160 // Unaware Application Support), Chinese IMEs somehow ignore function calls |
140 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate | 161 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate |
141 // window to the position given as its parameters, and use the position | 162 // window to the position given as its parameters, and use the position |
142 // of the current system caret instead, i.e. it uses ::GetCaretPos() to | 163 // of the current system caret instead, i.e. it uses ::GetCaretPos() to |
143 // retrieve the position of their IME candidate window. | 164 // retrieve the position of their IME candidate window. |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 keystate[VK_RCONTROL] = 0; | 571 keystate[VK_RCONTROL] = 0; |
551 keystate[VK_LCONTROL] = 0; | 572 keystate[VK_LCONTROL] = 0; |
552 for (int i = 0; i <= VK_PACKET; ++i) { | 573 for (int i = 0; i <= VK_PACKET; ++i) { |
553 if (keystate[i] & kKeyDownMask) | 574 if (keystate[i] & kKeyDownMask) |
554 return false; | 575 return false; |
555 } | 576 } |
556 return true; | 577 return true; |
557 } | 578 } |
558 | 579 |
559 } // namespace ui | 580 } // namespace ui |
OLD | NEW |