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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc

Issue 224093013: Allow country-specific languages in UI list at OOBE. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include. Created 6 years, 8 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 (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/webui/chromeos/login/network_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { 67 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) {
68 base::DictionaryValue* optgroup = new base::DictionaryValue; 68 base::DictionaryValue* optgroup = new base::DictionaryValue;
69 optgroup->SetString( 69 optgroup->SetString(
70 "optionGroupName", 70 "optionGroupName",
71 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); 71 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS));
72 input_methods_list->Append(optgroup); 72 input_methods_list->Append(optgroup);
73 } 73 }
74 74
75 std::string CalculateSelectedLanguage(const std::string& requested_locale,
76 const std::string& loaded_locale) {
jungshik at Google 2014/04/04 08:37:22 JFYI: It's also possible to ICU's Locale class (ge
77 const size_t dash_pos_requested = requested_locale.find_first_of('-');
78
79 // Requested language doesn't have specific country.
80 if (dash_pos_requested == std::string::npos || dash_pos_requested == 0)
81 return loaded_locale;
82
83 const size_t dash_pos_loaded = loaded_locale.find_first_of('-');
84
85 // loaded_locale doesn't have 'country' name and requested_locale
86 // is a country-specific language of loaded_locale.
87 if (dash_pos_loaded == std::string::npos || dash_pos_loaded == 0) {
88 if (requested_locale.substr(0, dash_pos_requested) == loaded_locale)
89 return requested_locale;
90 // languages differ
91 return loaded_locale;
92 }
93 // Both locales are country-specific. Check that languages are the same.
94 if (requested_locale.substr(0, dash_pos_requested) ==
95 loaded_locale.substr(0, dash_pos_loaded))
96 return requested_locale;
97
98 return loaded_locale;
99 }
100
75 } // namespace 101 } // namespace
76 102
77 namespace chromeos { 103 namespace chromeos {
78 104
79 // NetworkScreenHandler, public: ----------------------------------------------- 105 // NetworkScreenHandler, public: -----------------------------------------------
80 106
81 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor) 107 NetworkScreenHandler::NetworkScreenHandler(CoreOobeActor* core_oobe_actor)
82 : BaseScreenHandler(kJsScreenPath), 108 : BaseScreenHandler(kJsScreenPath),
83 screen_(NULL), 109 screen_(NULL),
84 core_oobe_actor_(core_oobe_actor), 110 core_oobe_actor_(core_oobe_actor),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 260
235 base::WeakPtr<NetworkScreenHandler> handler_; 261 base::WeakPtr<NetworkScreenHandler> handler_;
236 262
237 // Block UI while resource bundle is being reloaded. 263 // Block UI while resource bundle is being reloaded.
238 chromeos::InputEventsBlocker input_events_blocker; 264 chromeos::InputEventsBlocker input_events_blocker;
239 }; 265 };
240 266
241 // static 267 // static
242 void NetworkScreenHandler::OnLanguageChangedCallback( 268 void NetworkScreenHandler::OnLanguageChangedCallback(
243 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, 269 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context,
244 const std::string& /*requested locale*/, 270 const std::string& requested_locale,
245 const std::string& /*loaded_locale*/, 271 const std::string& loaded_locale,
246 const bool /*success*/) { 272 const bool success) {
247 if (!context or !context->handler_) 273 if (!context or !context->handler_)
248 return; 274 return;
249 275
250 NetworkScreenHandler* const self = context->handler_.get(); 276 NetworkScreenHandler* const self = context->handler_.get();
251 277
278 if (success) {
279 if (requested_locale == loaded_locale) {
280 self->selected_language_code_ = requested_locale;
281 } else {
282 self->selected_language_code_ =
283 CalculateSelectedLanguage(requested_locale, loaded_locale);
284 }
285 } else {
286 self->selected_language_code_ = loaded_locale;
287 }
288
252 base::DictionaryValue localized_strings; 289 base::DictionaryValue localized_strings;
253 static_cast<OobeUI*>(self->web_ui()->GetController()) 290 static_cast<OobeUI*>(self->web_ui()->GetController())
254 ->GetLocalizedStrings(&localized_strings); 291 ->GetLocalizedStrings(&localized_strings);
255 self->core_oobe_actor_->ReloadContent(localized_strings); 292 self->core_oobe_actor_->ReloadContent(localized_strings);
256 293
257 // Buttons are recreated, updated "Continue" button state. 294 // Buttons are recreated, updated "Continue" button state.
258 self->EnableContinue(self->is_continue_enabled_); 295 self->EnableContinue(self->is_continue_enabled_);
259 296
260 AccessibilityManager::Get()->OnLocaleChanged(); 297 AccessibilityManager::Get()->OnLocaleChanged();
261 } 298 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 oobe_timer_update_interval_ = 413 oobe_timer_update_interval_ =
377 std::max(std::min(oobe_timer_update_interval_, 414 std::max(std::min(oobe_timer_update_interval_,
378 derelict_detection_timeout_ - time_on_oobe_), 415 derelict_detection_timeout_ - time_on_oobe_),
379 base::TimeDelta::FromSeconds(0)); 416 base::TimeDelta::FromSeconds(0));
380 } 417 }
381 418
382 bool NetworkScreenHandler::IsDerelict() { 419 bool NetworkScreenHandler::IsDerelict() {
383 return time_on_oobe_ >= derelict_detection_timeout_; 420 return time_on_oobe_ >= derelict_detection_timeout_;
384 } 421 }
385 422
386 // static
387 base::ListValue* NetworkScreenHandler::GetLanguageList() { 423 base::ListValue* NetworkScreenHandler::GetLanguageList() {
388 const std::string app_locale = g_browser_process->GetApplicationLocale(); 424 const std::string app_locale = g_browser_process->GetApplicationLocale();
389 input_method::InputMethodManager* manager = 425 input_method::InputMethodManager* manager =
390 input_method::InputMethodManager::Get(); 426 input_method::InputMethodManager::Get();
391 ComponentExtensionIMEManager* comp_manager = 427 ComponentExtensionIMEManager* comp_manager =
392 manager->GetComponentExtensionIMEManager(); 428 manager->GetComponentExtensionIMEManager();
393 input_method::InputMethodDescriptors descriptors; 429 input_method::InputMethodDescriptors descriptors;
394 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { 430 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) {
395 if (comp_manager->IsInitialized()) 431 if (comp_manager->IsInitialized())
396 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); 432 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor();
(...skipping 21 matching lines...) Expand all
418 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); 454 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES));
419 } 455 }
420 if (display_name != native_name) { 456 if (display_name != native_name) {
421 display_name = base::StringPrintf("%s - %s", 457 display_name = base::StringPrintf("%s - %s",
422 display_name.c_str(), 458 display_name.c_str(),
423 native_name.c_str()); 459 native_name.c_str());
424 } 460 }
425 461
426 language_info->SetString("value", value); 462 language_info->SetString("value", value);
427 language_info->SetString("title", display_name); 463 language_info->SetString("title", display_name);
428 language_info->SetBoolean("selected", value == app_locale); 464 if (selected_language_code_.empty()) {
465 if (value == app_locale)
466 language_info->SetBoolean("selected", true);
467 } else {
468 if (value == selected_language_code_)
469 language_info->SetBoolean("selected", true);
470 }
429 } 471 }
430 return languages_list; 472 return languages_list;
431 } 473 }
432 474
433 base::DictionaryValue* CreateInputMethodsEntry( 475 base::DictionaryValue* CreateInputMethodsEntry(
434 const input_method::InputMethodDescriptor& method, 476 const input_method::InputMethodDescriptor& method,
435 const std::string current_input_method_id) { 477 const std::string current_input_method_id) {
436 input_method::InputMethodUtil* util = 478 input_method::InputMethodUtil* util =
437 input_method::InputMethodManager::Get()->GetInputMethodUtil(); 479 input_method::InputMethodManager::Get()->GetInputMethodUtil();
438 const std::string& ime_id = method.id(); 480 const std::string& ime_id = method.id();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 timezone_option->SetString("value", timezone_id); 590 timezone_option->SetString("value", timezone_id);
549 timezone_option->SetString("title", timezone_name); 591 timezone_option->SetString("title", timezone_name);
550 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); 592 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id);
551 timezone_list->Append(timezone_option.release()); 593 timezone_list->Append(timezone_option.release());
552 } 594 }
553 595
554 return timezone_list.release(); 596 return timezone_list.release();
555 } 597 }
556 598
557 } // namespace chromeos 599 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698