Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/ime/input_method_win.h" | 5 #include "views/ime/input_method_win.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 break; | 108 break; |
| 109 case WM_IME_STARTCOMPOSITION: | 109 case WM_IME_STARTCOMPOSITION: |
| 110 result = OnImeStartComposition(message, w_param, l_param, handled); | 110 result = OnImeStartComposition(message, w_param, l_param, handled); |
| 111 break; | 111 break; |
| 112 case WM_IME_COMPOSITION: | 112 case WM_IME_COMPOSITION: |
| 113 result = OnImeComposition(message, w_param, l_param, handled); | 113 result = OnImeComposition(message, w_param, l_param, handled); |
| 114 break; | 114 break; |
| 115 case WM_IME_ENDCOMPOSITION: | 115 case WM_IME_ENDCOMPOSITION: |
| 116 result = OnImeEndComposition(message, w_param, l_param, handled); | 116 result = OnImeEndComposition(message, w_param, l_param, handled); |
| 117 break; | 117 break; |
| 118 case WM_IME_REQUEST: | |
| 119 result = OnImeRequest(message, w_param, l_param, handled); | |
| 120 break; | |
| 118 case WM_CHAR: | 121 case WM_CHAR: |
| 119 case WM_SYSCHAR: | 122 case WM_SYSCHAR: |
| 120 result = OnChar(message, w_param, l_param, handled); | 123 result = OnChar(message, w_param, l_param, handled); |
| 121 break; | 124 break; |
| 122 case WM_DEADCHAR: | 125 case WM_DEADCHAR: |
| 123 case WM_SYSDEADCHAR: | 126 case WM_SYSDEADCHAR: |
| 124 result = OnDeadChar(message, w_param, l_param, handled); | 127 result = OnDeadChar(message, w_param, l_param, handled); |
| 125 break; | 128 break; |
| 126 default: | 129 default: |
| 127 NOTREACHED() << "Unknown IME message:" << message; | 130 NOTREACHED() << "Unknown IME message:" << message; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 return 0; | 215 return 0; |
| 213 | 216 |
| 214 if (GetTextInputClient()->HasCompositionText()) | 217 if (GetTextInputClient()->HasCompositionText()) |
| 215 GetTextInputClient()->ClearCompositionText(); | 218 GetTextInputClient()->ClearCompositionText(); |
| 216 | 219 |
| 217 ime_input_.ResetComposition(hwnd()); | 220 ime_input_.ResetComposition(hwnd()); |
| 218 ime_input_.DestroyImeWindow(hwnd()); | 221 ime_input_.DestroyImeWindow(hwnd()); |
| 219 return 0; | 222 return 0; |
| 220 } | 223 } |
| 221 | 224 |
| 225 LRESULT InputMethodWin::OnImeRequest( | |
| 226 UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { | |
| 227 *handled = FALSE; | |
| 228 | |
| 229 // Should not receive WM_IME_REQUEST message, if IME is disabled. | |
| 230 const ui::TextInputType type = GetTextInputType(); | |
| 231 if (type == ui::TEXT_INPUT_TYPE_NONE || | |
| 232 type == ui::TEXT_INPUT_TYPE_PASSWORD) { | |
| 233 return 0; | |
| 234 } | |
| 235 | |
| 236 switch (wparam) { | |
| 237 case IMR_RECONVERTSTRING: | |
| 238 *handled = TRUE; | |
| 239 return OnReconvertString(reinterpret_cast<RECONVERTSTRING*>(lparam)); | |
| 240 case IMR_DOCUMENTFEED: | |
| 241 *handled = TRUE; | |
| 242 return OnDocumentFeed(reinterpret_cast<RECONVERTSTRING*>(lparam)); | |
| 243 default: | |
| 244 return 0; | |
| 245 } | |
| 246 } | |
| 247 | |
| 222 LRESULT InputMethodWin::OnChar( | 248 LRESULT InputMethodWin::OnChar( |
| 223 UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { | 249 UINT message, WPARAM wparam, LPARAM lparam, BOOL* handled) { |
| 224 *handled = TRUE; | 250 *handled = TRUE; |
| 225 | 251 |
| 226 // We need to send character events to the focused text input client event if | 252 // We need to send character events to the focused text input client event if |
| 227 // its text input type is ui::TEXT_INPUT_TYPE_NONE. | 253 // its text input type is ui::TEXT_INPUT_TYPE_NONE. |
| 228 if (!GetTextInputClient()) | 254 if (!GetTextInputClient()) |
| 229 return 0; | 255 return 0; |
| 230 | 256 |
| 231 int flags = 0; | 257 int flags = 0; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 247 // what dead key was pressed. | 273 // what dead key was pressed. |
| 248 ui::CompositionText composition; | 274 ui::CompositionText composition; |
| 249 composition.text.assign(1, static_cast<char16>(wparam)); | 275 composition.text.assign(1, static_cast<char16>(wparam)); |
| 250 composition.selection = ui::Range(0, 1); | 276 composition.selection = ui::Range(0, 1); |
| 251 composition.underlines.push_back( | 277 composition.underlines.push_back( |
| 252 ui::CompositionUnderline(0, 1, SK_ColorBLACK, false)); | 278 ui::CompositionUnderline(0, 1, SK_ColorBLACK, false)); |
| 253 GetTextInputClient()->SetCompositionText(composition); | 279 GetTextInputClient()->SetCompositionText(composition); |
| 254 return 0; | 280 return 0; |
| 255 } | 281 } |
| 256 | 282 |
| 283 LRESULT InputMethodWin::OnDocumentFeed(RECONVERTSTRING *reconv) { | |
| 284 TextInputClient* client = GetTextInputClient(); | |
| 285 if (!client) | |
| 286 return 0; | |
| 287 | |
| 288 ui::Range text_range; | |
| 289 if (!client->GetTextRange(&text_range) || text_range.is_empty()) | |
| 290 return 0; | |
| 291 | |
| 292 bool result = false; | |
| 293 ui::Range target_range; | |
| 294 if (client->HasCompositionText()) | |
| 295 result = client->GetCompositionTextRange(&target_range); | |
| 296 | |
| 297 if (!result || target_range.is_empty()) { | |
| 298 if (!client->GetSelectionRange(&target_range) || | |
| 299 !target_range.IsValid()) { | |
| 300 return 0; | |
| 301 } | |
| 302 } | |
| 303 | |
| 304 if (!text_range.Contains(target_range)) | |
| 305 return 0; | |
| 306 | |
| 307 size_t len = text_range.length(); | |
| 308 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); | |
| 309 | |
| 310 if (!reconv) | |
| 311 return need_size; | |
| 312 | |
| 313 if (reconv->dwSize < need_size) | |
| 314 return 0; | |
| 315 | |
| 316 string16 text; | |
| 317 if (!GetTextInputClient()->GetTextFromRange(text_range, &text)) | |
| 318 return 0; | |
| 319 | |
| 320 reconv->dwVersion = 0; | |
| 321 reconv->dwStrLen = len; | |
| 322 reconv->dwStrOffset = sizeof(RECONVERTSTRING); | |
| 323 reconv->dwCompStrLen = | |
| 324 client->HasCompositionText() ? target_range.length() : 0; | |
| 325 reconv->dwCompStrOffset = | |
| 326 (target_range.GetMin() - text_range.start()) * sizeof(WCHAR); | |
| 327 reconv->dwTargetStrLen = target_range.length(); | |
| 328 reconv->dwTargetStrOffset = reconv->dwCompStrOffset; | |
| 329 | |
| 330 memcpy((char*)reconv + sizeof(RECONVERTSTRING), | |
| 331 text.c_str(), len * sizeof(WCHAR)); | |
| 332 | |
| 333 return reinterpret_cast<LRESULT>(reconv); | |
| 334 } | |
| 335 | |
| 336 LRESULT InputMethodWin::OnReconvertString(RECONVERTSTRING *reconv) { | |
| 337 TextInputClient* client = GetTextInputClient(); | |
| 338 if (!client) | |
| 339 return 0; | |
| 340 | |
| 341 // If there is a composition string already, we don't allow reconversion. | |
| 342 if (client->HasCompositionText()) | |
| 343 return 0; | |
| 344 | |
| 345 ui::Range text_range; | |
| 346 if (!client->GetTextRange(&text_range) || text_range.is_empty()) | |
| 347 return 0; | |
| 348 | |
| 349 ui::Range selection_range; | |
| 350 if (!client->GetSelectionRange(&selection_range) || | |
| 351 selection_range.is_empty()) { | |
| 352 return 0; | |
| 353 } | |
| 354 | |
| 355 DCHECK(text_range.Contains(selection_range)); | |
| 356 | |
| 357 size_t len = selection_range.length(); | |
| 358 size_t need_size = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR); | |
|
Peng
2011/10/27 00:28:00
I checked document of IMR_RECONVERTSTRING & IMR_DO
James Su
2011/10/27 04:56:39
When doing reconversion, the IME can use the surro
Peng
2011/10/27 16:12:24
Because we do not implement the logic to allow IME
James Su
2011/10/27 18:39:49
You still don't get the point.
1) This method has
| |
| 359 | |
| 360 if (!reconv) | |
| 361 return need_size; | |
| 362 | |
| 363 if (reconv->dwSize < need_size) | |
| 364 return 0; | |
| 365 | |
| 366 string16 text; | |
| 367 if (!GetTextInputClient()->GetTextFromRange(selection_range, &text)) | |
| 368 return 0; | |
| 369 | |
| 370 reconv->dwVersion = 0; | |
| 371 reconv->dwStrLen = len; | |
| 372 reconv->dwStrOffset = sizeof(RECONVERTSTRING); | |
| 373 reconv->dwCompStrLen = len; | |
| 374 reconv->dwCompStrOffset = 0; | |
| 375 reconv->dwTargetStrLen = len; | |
| 376 reconv->dwTargetStrOffset = 0; | |
| 377 | |
| 378 memcpy(reinterpret_cast<char*>(reconv) + sizeof(RECONVERTSTRING), | |
| 379 text.c_str(), len * sizeof(WCHAR)); | |
| 380 | |
| 381 return reinterpret_cast<LRESULT>(reconv); | |
| 382 } | |
| 383 | |
| 257 void InputMethodWin::ConfirmCompositionText() { | 384 void InputMethodWin::ConfirmCompositionText() { |
| 258 if (!IsTextInputTypeNone()) { | 385 if (!IsTextInputTypeNone()) { |
| 259 ime_input_.CleanupComposition(hwnd()); | 386 ime_input_.CleanupComposition(hwnd()); |
| 260 // Though above line should confirm the client's composition text by sending | 387 // Though above line should confirm the client's composition text by sending |
| 261 // a result text to us, in case the input method and the client are in | 388 // a result text to us, in case the input method and the client are in |
| 262 // inconsistent states, we check the client's composition state again. | 389 // inconsistent states, we check the client's composition state again. |
| 263 if (GetTextInputClient()->HasCompositionText()) | 390 if (GetTextInputClient()->HasCompositionText()) |
| 264 GetTextInputClient()->ConfirmCompositionText(); | 391 GetTextInputClient()->ConfirmCompositionText(); |
| 265 } | 392 } |
| 266 } | 393 } |
| 267 | 394 |
| 268 void InputMethodWin::UpdateIMEState() { | 395 void InputMethodWin::UpdateIMEState() { |
| 269 // Use switch here in case we are going to add more text input types. | 396 // Use switch here in case we are going to add more text input types. |
| 270 // We disable input method in password field. | 397 // We disable input method in password field. |
| 271 switch (GetTextInputType()) { | 398 switch (GetTextInputType()) { |
| 272 case ui::TEXT_INPUT_TYPE_NONE: | 399 case ui::TEXT_INPUT_TYPE_NONE: |
| 273 case ui::TEXT_INPUT_TYPE_PASSWORD: | 400 case ui::TEXT_INPUT_TYPE_PASSWORD: |
| 274 ime_input_.DisableIME(hwnd()); | 401 ime_input_.DisableIME(hwnd()); |
| 275 break; | 402 break; |
| 276 default: | 403 default: |
| 277 ime_input_.EnableIME(hwnd()); | 404 ime_input_.EnableIME(hwnd()); |
| 278 break; | 405 break; |
| 279 } | 406 } |
| 280 } | 407 } |
| 281 | 408 |
| 282 } // namespace views | 409 } // namespace views |
| OLD | NEW |