OLD | NEW |
---|---|
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 Loading... | |
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, | |
Nikita (slow)
2014/04/07 04:54:27
nit: Add comment.
Alexander Alekseev
2014/04/07 16:56:28
Done.
| |
76 const std::string& loaded_locale) { | |
77 const size_t dash_pos_requested = requested_locale.find_first_of('-'); | |
78 | |
79 // Requested language doesn't have specific country. | |
Nikita (slow)
2014/04/07 04:54:27
nit: It's better to use "region" instead of "count
Alexander Alekseev
2014/04/07 16:56:28
Done.
| |
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 | |
Nikita (slow)
2014/04/07 04:54:27
nit: Capitalize comment.
Alexander Alekseev
2014/04/07 16:56:28
Done.
| |
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 258 |
233 base::WeakPtr<NetworkScreenHandler> handler_; | 259 base::WeakPtr<NetworkScreenHandler> handler_; |
234 | 260 |
235 // Block UI while resource bundle is being reloaded. | 261 // Block UI while resource bundle is being reloaded. |
236 chromeos::InputEventsBlocker input_events_blocker; | 262 chromeos::InputEventsBlocker input_events_blocker; |
237 }; | 263 }; |
238 | 264 |
239 // static | 265 // static |
240 void NetworkScreenHandler::OnLanguageChangedCallback( | 266 void NetworkScreenHandler::OnLanguageChangedCallback( |
241 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, | 267 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context, |
242 const std::string& /*requested locale*/, | 268 const std::string& requested_locale, |
243 const std::string& /*loaded_locale*/, | 269 const std::string& loaded_locale, |
244 const bool /*success*/) { | 270 const bool success) { |
245 if (!context or !context->handler_) | 271 if (!context or !context->handler_) |
246 return; | 272 return; |
247 | 273 |
248 NetworkScreenHandler* const self = context->handler_.get(); | 274 NetworkScreenHandler* const self = context->handler_.get(); |
275 | |
276 if (success) { | |
277 if (requested_locale == loaded_locale) { | |
278 self->selected_language_code_ = requested_locale; | |
279 } else { | |
280 self->selected_language_code_ = | |
281 CalculateSelectedLanguage(requested_locale, loaded_locale); | |
282 } | |
283 } else { | |
284 self->selected_language_code_ = loaded_locale; | |
285 } | |
286 | |
249 self->ReloadLocalizedContent(); | 287 self->ReloadLocalizedContent(); |
250 | 288 |
251 AccessibilityManager::Get()->OnLocaleChanged(); | 289 AccessibilityManager::Get()->OnLocaleChanged(); |
252 } | 290 } |
253 | 291 |
254 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { | 292 void NetworkScreenHandler::HandleOnLanguageChanged(const std::string& locale) { |
255 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 293 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
256 if (app_locale == locale) | 294 if (app_locale == locale) |
257 return; | 295 return; |
258 | 296 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 oobe_timer_update_interval_ = | 405 oobe_timer_update_interval_ = |
368 std::max(std::min(oobe_timer_update_interval_, | 406 std::max(std::min(oobe_timer_update_interval_, |
369 derelict_detection_timeout_ - time_on_oobe_), | 407 derelict_detection_timeout_ - time_on_oobe_), |
370 base::TimeDelta::FromSeconds(0)); | 408 base::TimeDelta::FromSeconds(0)); |
371 } | 409 } |
372 | 410 |
373 bool NetworkScreenHandler::IsDerelict() { | 411 bool NetworkScreenHandler::IsDerelict() { |
374 return time_on_oobe_ >= derelict_detection_timeout_; | 412 return time_on_oobe_ >= derelict_detection_timeout_; |
375 } | 413 } |
376 | 414 |
377 // static | |
378 base::ListValue* NetworkScreenHandler::GetLanguageList() { | 415 base::ListValue* NetworkScreenHandler::GetLanguageList() { |
379 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 416 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
380 input_method::InputMethodManager* manager = | 417 input_method::InputMethodManager* manager = |
381 input_method::InputMethodManager::Get(); | 418 input_method::InputMethodManager::Get(); |
382 ComponentExtensionIMEManager* comp_manager = | 419 ComponentExtensionIMEManager* comp_manager = |
383 manager->GetComponentExtensionIMEManager(); | 420 manager->GetComponentExtensionIMEManager(); |
384 input_method::InputMethodDescriptors descriptors; | 421 input_method::InputMethodDescriptors descriptors; |
385 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { | 422 if (extension_ime_util::UseWrappedExtensionKeyboardLayouts()) { |
386 if (comp_manager->IsInitialized()) | 423 if (comp_manager->IsInitialized()) |
387 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); | 424 descriptors = comp_manager->GetXkbIMEAsInputMethodDescriptor(); |
(...skipping 21 matching lines...) Expand all Loading... | |
409 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); | 446 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_LANGUAGES)); |
410 } | 447 } |
411 if (display_name != native_name) { | 448 if (display_name != native_name) { |
412 display_name = base::StringPrintf("%s - %s", | 449 display_name = base::StringPrintf("%s - %s", |
413 display_name.c_str(), | 450 display_name.c_str(), |
414 native_name.c_str()); | 451 native_name.c_str()); |
415 } | 452 } |
416 | 453 |
417 language_info->SetString("value", value); | 454 language_info->SetString("value", value); |
418 language_info->SetString("title", display_name); | 455 language_info->SetString("title", display_name); |
419 language_info->SetBoolean("selected", value == app_locale); | 456 if (selected_language_code_.empty()) { |
457 if (value == app_locale) | |
458 language_info->SetBoolean("selected", true); | |
459 } else { | |
460 if (value == selected_language_code_) | |
461 language_info->SetBoolean("selected", true); | |
462 } | |
420 } | 463 } |
421 return languages_list; | 464 return languages_list; |
422 } | 465 } |
423 | 466 |
424 base::DictionaryValue* CreateInputMethodsEntry( | 467 base::DictionaryValue* CreateInputMethodsEntry( |
425 const input_method::InputMethodDescriptor& method, | 468 const input_method::InputMethodDescriptor& method, |
426 const std::string current_input_method_id) { | 469 const std::string current_input_method_id) { |
427 input_method::InputMethodUtil* util = | 470 input_method::InputMethodUtil* util = |
428 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 471 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
429 const std::string& ime_id = method.id(); | 472 const std::string& ime_id = method.id(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 timezone_option->SetString("value", timezone_id); | 592 timezone_option->SetString("value", timezone_id); |
550 timezone_option->SetString("title", timezone_name); | 593 timezone_option->SetString("title", timezone_name); |
551 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); | 594 timezone_option->SetBoolean("selected", timezone_id == current_timezone_id); |
552 timezone_list->Append(timezone_option.release()); | 595 timezone_list->Append(timezone_option.release()); |
553 } | 596 } |
554 | 597 |
555 return timezone_list.release(); | 598 return timezone_list.release(); |
556 } | 599 } |
557 | 600 |
558 } // namespace chromeos | 601 } // namespace chromeos |
OLD | NEW |