OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/ime_input.h" | 5 #include "chrome/browser/ime_input.h" |
6 | 6 |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 | 9 |
10 // "imm32.lib" is required by IMM32 APIs used in this file. | 10 // "imm32.lib" is required by IMM32 APIs used in this file. |
11 // NOTE(hbono): To comply with a comment from Darin, I have added | 11 // NOTE(hbono): To comply with a comment from Darin, I have added |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void ImeInput::DisableIME(HWND window_handle) { | 297 void ImeInput::DisableIME(HWND window_handle) { |
298 // A renderer process have moved its input focus to a password input | 298 // A renderer process have moved its input focus to a password input |
299 // when there is an ongoing composition, e.g. a user has clicked a | 299 // when there is an ongoing composition, e.g. a user has clicked a |
300 // mouse button and selected a password input while composing a text. | 300 // mouse button and selected a password input while composing a text. |
301 // For this case, we have to complete the ongoing composition and | 301 // For this case, we have to complete the ongoing composition and |
302 // clean up the resources attached to this object BEFORE DISABLING THE IME. | 302 // clean up the resources attached to this object BEFORE DISABLING THE IME. |
303 CleanupComposition(window_handle); | 303 CleanupComposition(window_handle); |
304 ::ImmAssociateContextEx(window_handle, NULL, 0); | 304 ::ImmAssociateContextEx(window_handle, NULL, 0); |
305 } | 305 } |
306 | 306 |
| 307 void ImeInput::CancelIME(HWND window_handle) { |
| 308 if (is_composing_) { |
| 309 HIMC imm_context = ::ImmGetContext(window_handle); |
| 310 if (imm_context) { |
| 311 ::ImmNotifyIME(imm_context, NI_COMPOSITIONSTR, CPS_CANCEL, 0); |
| 312 ::ImmReleaseContext(window_handle, imm_context); |
| 313 } |
| 314 ResetComposition(window_handle); |
| 315 } |
| 316 } |
| 317 |
307 void ImeInput::EnableIME(HWND window_handle, | 318 void ImeInput::EnableIME(HWND window_handle, |
308 const gfx::Rect& caret_rect, | 319 const gfx::Rect& caret_rect, |
309 bool complete) { | 320 bool complete) { |
310 // Load the default IME context. | 321 // Load the default IME context. |
311 // NOTE(hbono) | 322 // NOTE(hbono) |
312 // IMM ignores this call if the IME context is loaded. Therefore, we do | 323 // IMM ignores this call if the IME context is loaded. Therefore, we do |
313 // not have to check whether or not the IME context is loaded. | 324 // not have to check whether or not the IME context is loaded. |
314 ::ImmAssociateContextEx(window_handle, NULL, IACE_DEFAULT); | 325 ::ImmAssociateContextEx(window_handle, NULL, IACE_DEFAULT); |
315 // Complete the ongoing composition and move the IME windows. | 326 // Complete the ongoing composition and move the IME windows. |
316 HIMC imm_context = ::ImmGetContext(window_handle); | 327 HIMC imm_context = ::ImmGetContext(window_handle); |
(...skipping 11 matching lines...) Expand all Loading... |
328 // This update is used for moving an IME window when a renderer process | 339 // This update is used for moving an IME window when a renderer process |
329 // resize/moves the input caret. | 340 // resize/moves the input caret. |
330 if (caret_rect.x() >= 0 && caret_rect.y() >= 0) { | 341 if (caret_rect.x() >= 0 && caret_rect.y() >= 0) { |
331 caret_rect_.SetRect(caret_rect.x(), caret_rect.y(), caret_rect.width(), | 342 caret_rect_.SetRect(caret_rect.x(), caret_rect.y(), caret_rect.width(), |
332 caret_rect.height()); | 343 caret_rect.height()); |
333 MoveImeWindow(window_handle, imm_context); | 344 MoveImeWindow(window_handle, imm_context); |
334 } | 345 } |
335 ::ImmReleaseContext(window_handle, imm_context); | 346 ::ImmReleaseContext(window_handle, imm_context); |
336 } | 347 } |
337 } | 348 } |
OLD | NEW |