Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: ui/base/ime/win/imm32_manager.cc

Issue 2298123003: Using input language instead of the application locale to determine the Omnibox's text input type o… (Closed)
Patch Set: ..... Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ime/win/imm32_manager.h" 5 #include "ui/base/ime/win/imm32_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 input_language_id_(LANG_USER_DEFAULT), 117 input_language_id_(LANG_USER_DEFAULT),
118 system_caret_(false), 118 system_caret_(false),
119 caret_rect_(-1, -1, 0, 0), 119 caret_rect_(-1, -1, 0, 0),
120 use_composition_window_(false) { 120 use_composition_window_(false) {
121 } 121 }
122 122
123 IMM32Manager::~IMM32Manager() { 123 IMM32Manager::~IMM32Manager() {
124 } 124 }
125 125
126 void IMM32Manager::SetInputLanguage() { 126 void IMM32Manager::SetInputLanguage() {
127 // Retrieve the current keyboard layout from Windows and determine whether 127 // Retrieve the current input language from the system's keyboard layout.
128 // or not the current input context has IMEs. 128 // Using GetKeyboardLayoutName instead of GetKeyboardLayout, because
129 // Also save its input language for language-specific operations required 129 // the language from GetKeyboardLayout is the language under where the
130 // while composing a text. 130 // keyboard layout is installed. And the language from GetKeyboardLayoutName
131 HKL keyboard_layout = ::GetKeyboardLayout(0); 131 // indicates the language of the keyboard layout itself.
132 // See crbug.com/344834.
133 WCHAR keyboard_layout[KL_NAMELENGTH];
134 ::GetKeyboardLayoutNameW(keyboard_layout);
yukawa 2016/09/01 20:15:03 Let's check the return value. If |GetKeyboardLayo
Shu Chen 2016/09/07 03:13:34 Done.
132 input_language_id_ = 135 input_language_id_ =
133 static_cast<LANGID>(reinterpret_cast<uintptr_t>(keyboard_layout)); 136 static_cast<LANGID>(_wtoi(&keyboard_layout[KL_NAMELENGTH >> 1]));
134 } 137 }
135 138
136 void IMM32Manager::CreateImeWindow(HWND window_handle) { 139 void IMM32Manager::CreateImeWindow(HWND window_handle) {
137 // When a user disables TSF (Text Service Framework) and CUAS (Cicero 140 // When a user disables TSF (Text Service Framework) and CUAS (Cicero
138 // Unaware Application Support), Chinese IMEs somehow ignore function calls 141 // Unaware Application Support), Chinese IMEs somehow ignore function calls
139 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate 142 // to ::ImmSetCandidateWindow(), i.e. they do not move their candidate
140 // window to the position given as its parameters, and use the position 143 // window to the position given as its parameters, and use the position
141 // of the current system caret instead, i.e. it uses ::GetCaretPos() to 144 // of the current system caret instead, i.e. it uses ::GetCaretPos() to
142 // retrieve the position of their IME candidate window. 145 // retrieve the position of their IME candidate window.
143 // Therefore, we create a temporary system caret for Chinese IMEs and use 146 // Therefore, we create a temporary system caret for Chinese IMEs and use
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 MoveImeWindow(window_handle, imm_context); 453 MoveImeWindow(window_handle, imm_context);
451 ::ImmReleaseContext(window_handle, imm_context); 454 ::ImmReleaseContext(window_handle, imm_context);
452 } 455 }
453 } 456 }
454 } 457 }
455 458
456 void IMM32Manager::SetUseCompositionWindow(bool use_composition_window) { 459 void IMM32Manager::SetUseCompositionWindow(bool use_composition_window) {
457 use_composition_window_ = use_composition_window; 460 use_composition_window_ = use_composition_window;
458 } 461 }
459 462
460 std::string IMM32Manager::GetInputLanguageName() const { 463 bool IMM32Manager::IsInputLanguageCJK() const {
461 const LCID locale_id = MAKELCID(input_language_id_, SORT_DEFAULT); 464 LANGID lang = PRIMARYLANGID(input_language_id_);
462 // max size for LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME is 9. 465 return lang == LANG_CHINESE || lang == LANG_JAPANESE ||
463 wchar_t buffer[9]; 466 lang == LANG_KOREAN;
464
465 // Get language id.
466 int length = ::GetLocaleInfo(locale_id, LOCALE_SISO639LANGNAME, &buffer[0],
467 arraysize(buffer));
468 if (length <= 1)
469 return std::string();
470
471 std::string language;
472 base::WideToUTF8(buffer, length - 1, &language);
473 if (SUBLANGID(input_language_id_) == SUBLANG_NEUTRAL)
474 return language;
475
476 // Get region id.
477 length = ::GetLocaleInfo(locale_id, LOCALE_SISO3166CTRYNAME, &buffer[0],
478 arraysize(buffer));
479 if (length <= 1)
480 return language;
481
482 std::string region;
483 base::WideToUTF8(buffer, length - 1, &region);
484 return language.append(1, '-').append(region);
485 } 467 }
486 468
487 void IMM32Manager::SetTextInputMode(HWND window_handle, 469 void IMM32Manager::SetTextInputMode(HWND window_handle,
488 TextInputMode input_mode) { 470 TextInputMode input_mode) {
489 if (input_mode == ui::TEXT_INPUT_MODE_DEFAULT) 471 if (input_mode == ui::TEXT_INPUT_MODE_DEFAULT)
490 return; 472 return;
491 473
492 const HIMC imm_context = ::ImmGetContext(window_handle); 474 const HIMC imm_context = ::ImmGetContext(window_handle);
493 if (!imm_context) 475 if (!imm_context)
494 return; 476 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 | IME_CMODE_KATAKANA 598 | IME_CMODE_KATAKANA
617 | IME_CMODE_FULLSHAPE); 599 | IME_CMODE_FULLSHAPE);
618 break; 600 break;
619 default: 601 default:
620 *open = FALSE; 602 *open = FALSE;
621 break; 603 break;
622 } 604 }
623 } 605 }
624 606
625 } // namespace ui 607 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698