| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/language_switch_menu.h" | 5 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 menu_.reset(new views::Menu2(&menu_model_)); | 63 menu_.reset(new views::Menu2(&menu_model_)); |
| 64 } | 64 } |
| 65 | 65 |
| 66 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { | 66 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { |
| 67 DCHECK(g_browser_process); | 67 DCHECK(g_browser_process); |
| 68 const std::string locale = g_browser_process->GetApplicationLocale(); | 68 const std::string locale = g_browser_process->GetApplicationLocale(); |
| 69 return language_list_->GetLanguageNameAt( | 69 return language_list_->GetLanguageNameAt( |
| 70 language_list_->GetIndexFromLocale(locale)); | 70 language_list_->GetIndexFromLocale(locale)); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Currently, views::Menu is implemented directly with the Gtk | |
| 74 // widgets. So we use native gtk callbacks to get its future size. | |
| 75 int LanguageSwitchMenu::GetFirstLevelMenuWidth() const { | |
| 76 DCHECK(menu_ != NULL); | |
| 77 GtkRequisition box_size; | |
| 78 gtk_widget_size_request(menu_->GetNativeMenu(), &box_size); | |
| 79 return box_size.width; | |
| 80 } | |
| 81 | |
| 82 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { | 73 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { |
| 83 DCHECK(menu_ != NULL); | 74 DCHECK(menu_ != NULL); |
| 84 gtk_widget_set_size_request(menu_->GetNativeMenu(), width, -1); | 75 menu_->SetMinimumWidth(width); |
| 85 } | 76 } |
| 86 | 77 |
| 87 // static | 78 // static |
| 88 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { | 79 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { |
| 89 // Save new locale. | 80 // Save new locale. |
| 90 DCHECK(g_browser_process); | 81 DCHECK(g_browser_process); |
| 91 PrefService* prefs = g_browser_process->local_state(); | 82 PrefService* prefs = g_browser_process->local_state(); |
| 92 // TODO(markusheintz): If the preference is managed and can not be changed by | 83 // TODO(markusheintz): If the preference is managed and can not be changed by |
| 93 // the user, changing the language should be disabled in the UI. | 84 // the user, changing the language should be disabled in the UI. |
| 94 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() | 85 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void LanguageSwitchMenu::ExecuteCommand(int command_id) { | 132 void LanguageSwitchMenu::ExecuteCommand(int command_id) { |
| 142 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 133 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
| 143 SwitchLanguage(locale); | 134 SwitchLanguage(locale); |
| 144 InitLanguageMenu(); | 135 InitLanguageMenu(); |
| 145 | 136 |
| 146 // Update all view hierarchies that the locale has changed. | 137 // Update all view hierarchies that the locale has changed. |
| 147 views::Widget::NotifyLocaleChanged(); | 138 views::Widget::NotifyLocaleChanged(); |
| 148 } | 139 } |
| 149 | 140 |
| 150 } // namespace chromeos | 141 } // namespace chromeos |
| OLD | NEW |