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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 2298123003: Using input language instead of the application locale to determine the Omnibox's text input type o… (Closed)
Patch Set: fix compiling errors in mus. 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/base/ime/dummy_input_method.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const gfx::Range& selection, 94 const gfx::Range& selection,
95 const gfx::Range& saved_selection_for_focus_change) 95 const gfx::Range& saved_selection_for_focus_change)
96 : model_state(model_state), 96 : model_state(model_state),
97 selection(selection), 97 selection(selection),
98 saved_selection_for_focus_change(saved_selection_for_focus_change) { 98 saved_selection_for_focus_change(saved_selection_for_focus_change) {
99 } 99 }
100 100
101 OmniboxState::~OmniboxState() { 101 OmniboxState::~OmniboxState() {
102 } 102 }
103 103
104
105 // Helpers --------------------------------------------------------------------
106
107 // We'd like to set the text input type to TEXT_INPUT_TYPE_URL, because this
108 // triggers URL-specific layout in software keyboards, e.g. adding top-level "/"
109 // and ".com" keys for English. However, this also causes IMEs to default to
110 // Latin character mode, which makes entering search queries difficult for IME
111 // users. Therefore, we try to guess whether an IME will be used based on the
112 // application language, and set the input type accordingly.
113 ui::TextInputType DetermineTextInputType() {
114 #if defined(OS_WIN)
115 DCHECK(g_browser_process);
116 const std::string& locale = g_browser_process->GetApplicationLocale();
117 const std::string& language = locale.substr(0, 2);
118 // Assume CJK + Thai users are using an IME.
119 if (language == "ja" ||
120 language == "ko" ||
121 language == "th" ||
122 language == "zh")
123 return ui::TEXT_INPUT_TYPE_SEARCH;
124 #endif
125 return ui::TEXT_INPUT_TYPE_URL;
126 }
127
128 } // namespace 104 } // namespace
129 105
130 106
131 // OmniboxViewViews ----------------------------------------------------------- 107 // OmniboxViewViews -----------------------------------------------------------
132 108
133 // static 109 // static
134 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; 110 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews";
135 111
136 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, 112 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller,
137 Profile* profile, 113 Profile* profile,
(...skipping 26 matching lines...) Expand all
164 RemoveCandidateWindowObserver(this); 140 RemoveCandidateWindowObserver(this);
165 #endif 141 #endif
166 142
167 // Explicitly teardown members which have a reference to us. Just to be safe 143 // Explicitly teardown members which have a reference to us. Just to be safe
168 // we want them to be destroyed before destroying any other internal state. 144 // we want them to be destroyed before destroying any other internal state.
169 popup_view_.reset(); 145 popup_view_.reset();
170 } 146 }
171 147
172 void OmniboxViewViews::Init() { 148 void OmniboxViewViews::Init() {
173 set_controller(this); 149 set_controller(this);
174 SetTextInputType(DetermineTextInputType()); 150 SetTextInputType(ui::TEXT_INPUT_TYPE_URL);
175 151
176 if (popup_window_mode_) 152 if (popup_window_mode_)
177 SetReadOnly(true); 153 SetReadOnly(true);
178 154
179 if (location_bar_view_) { 155 if (location_bar_view_) {
180 // Initialize the popup view using the same font. 156 // Initialize the popup view using the same font.
181 popup_view_.reset(OmniboxPopupContentsView::Create( 157 popup_view_.reset(OmniboxPopupContentsView::Create(
182 GetFontList(), this, model(), location_bar_view_)); 158 GetFontList(), this, model(), location_bar_view_));
183 } 159 }
184 160
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Textfield::ExecuteCommand(command_id, event_flags); 348 Textfield::ExecuteCommand(command_id, event_flags);
373 return; 349 return;
374 } 350 }
375 OnBeforePossibleChange(); 351 OnBeforePossibleChange();
376 location_bar_view_->command_updater()->ExecuteCommand(command_id); 352 location_bar_view_->command_updater()->ExecuteCommand(command_id);
377 OnAfterPossibleChange(true); 353 OnAfterPossibleChange(true);
378 return; 354 return;
379 } 355 }
380 } 356 }
381 357
358 ui::TextInputType OmniboxViewViews::GetTextInputType() const {
359 ui::TextInputType input_type = views::Textfield::GetTextInputType();
360 // We'd like to set the text input type to TEXT_INPUT_TYPE_URL, because this
361 // triggers URL-specific layout in software keyboards, e.g. adding top-level
362 // "/" and ".com" keys for English. However, this also causes IMEs to default
363 // to Latin character mode, which makes entering search queries difficult for
364 // IME users. Therefore, we try to guess whether an IME will be used based on
365 // the input language, and set the input type accordingly.
366 #if defined(OS_WIN)
367 if (input_type != ui::TEXT_INPUT_TYPE_NONE && location_bar_view_) {
368 ui::InputMethod* input_method =
369 location_bar_view_->GetWidget()->GetInputMethod();
370 if (input_method && input_method->IsInputLocaleCJK())
371 return ui::TEXT_INPUT_TYPE_SEARCH;
372 }
373 #endif
374 return input_type;
375 }
376
377
382 void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text, 378 void OmniboxViewViews::SetTextAndSelectedRange(const base::string16& text,
383 const gfx::Range& range) { 379 const gfx::Range& range) {
384 SetText(text); 380 SetText(text);
385 SelectRange(range); 381 SelectRange(range);
386 } 382 }
387 383
388 base::string16 OmniboxViewViews::GetSelectedText() const { 384 base::string16 OmniboxViewViews::GetSelectedText() const {
389 // TODO(oshima): Support IME. 385 // TODO(oshima): Support IME.
390 return views::Textfield::GetSelectedText(); 386 return views::Textfield::GetSelectedText();
391 } 387 }
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); 1082 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO);
1087 1083
1088 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); 1084 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR);
1089 1085
1090 // Minor note: We use IDC_ for command id here while the underlying textfield 1086 // Minor note: We use IDC_ for command id here while the underlying textfield
1091 // is using IDS_ for all its command ids. This is because views cannot depend 1087 // is using IDS_ for all its command ids. This is because views cannot depend
1092 // on IDC_ for now. 1088 // on IDC_ for now.
1093 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, 1089 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES,
1094 IDS_EDIT_SEARCH_ENGINES); 1090 IDS_EDIT_SEARCH_ENGINES);
1095 } 1091 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | ui/base/ime/dummy_input_method.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698