OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
13 #include "chrome/browser/chromeos/language_preferences.h" | 13 #include "chrome/browser/chromeos/language_preferences.h" |
14 #include "chrome/browser/chromeos/login/language_list.h" | 14 #include "chrome/browser/chromeos/login/language_list.h" |
15 #include "chrome/browser/chromeos/login/ownership_service.h" | 15 #include "chrome/browser/chromeos/login/ownership_service.h" |
16 #include "chrome/browser/chromeos/login/screen_observer.h" | 16 #include "chrome/browser/chromeos/login/screen_observer.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/platform_locale_settings.h" | 20 #include "grit/platform_locale_settings.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/gfx/platform_font_gtk.h" | 23 #include "ui/gfx/platform_font_gtk.h" |
24 #include "views/controls/button/menu_button.h" | 24 #include "views/controls/button/menu_button.h" |
25 #include "views/controls/menu/menu_item_view.h" | 25 #include "views/controls/menu/menu_item_view.h" |
| 26 #include "views/controls/menu/menu_runner.h" |
26 #include "views/controls/menu/submenu_view.h" | 27 #include "views/controls/menu/submenu_view.h" |
27 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const int kLanguageMainMenuSize = 5; | 32 const int kLanguageMainMenuSize = 5; |
32 // TODO(glotov): need to specify the list as a part of the image customization. | 33 // TODO(glotov): need to specify the list as a part of the image customization. |
33 const char kLanguagesTopped[] = "es,it,de,fr,en-US"; | 34 const char kLanguagesTopped[] = "es,it,de,fr,en-US"; |
34 const int kMoreLanguagesSubMenu = 200; | 35 const int kMoreLanguagesSubMenu = 200; |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 namespace chromeos { | 39 namespace chromeos { |
39 | 40 |
40 LanguageSwitchMenu::LanguageSwitchMenu() | 41 LanguageSwitchMenu::LanguageSwitchMenu() |
41 : ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))) { | 42 : ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))), |
| 43 menu_runner_(new views::MenuRunner(menu_)) { |
42 } | 44 } |
43 | 45 |
44 LanguageSwitchMenu::~LanguageSwitchMenu() {} | 46 LanguageSwitchMenu::~LanguageSwitchMenu() {} |
45 | 47 |
46 void LanguageSwitchMenu::InitLanguageMenu() { | 48 void LanguageSwitchMenu::InitLanguageMenu() { |
47 // Update LanguageList to contain entries in current locale. | 49 // Update LanguageList to contain entries in current locale. |
48 language_list_.reset(new LanguageList); | 50 language_list_.reset(new LanguageList); |
49 language_list_->CopySpecifiedLanguagesUp(kLanguagesTopped); | 51 language_list_->CopySpecifiedLanguagesUp(kLanguagesTopped); |
50 | 52 |
51 // Clear older menu items. | 53 // Clear older menu items. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // We align on the left edge of the button for non RTL case. | 166 // We align on the left edge of the button for non RTL case. |
165 // MenuButton passes in pt the lower left corner for RTL and the | 167 // MenuButton passes in pt the lower left corner for RTL and the |
166 // lower right corner for non-RTL (with menu_offset applied). | 168 // lower right corner for non-RTL (with menu_offset applied). |
167 const int reverse_offset = button->width() + button->menu_offset().x() * 2; | 169 const int reverse_offset = button->width() + button->menu_offset().x() * 2; |
168 gfx::Point new_pt(pt); | 170 gfx::Point new_pt(pt); |
169 if (base::i18n::IsRTL()) | 171 if (base::i18n::IsRTL()) |
170 new_pt.set_x(pt.x() + reverse_offset); | 172 new_pt.set_x(pt.x() + reverse_offset); |
171 else | 173 else |
172 new_pt.set_x(pt.x() - reverse_offset); | 174 new_pt.set_x(pt.x() - reverse_offset); |
173 | 175 |
174 menu_->RunMenuAt(button->GetWidget(), button, | 176 if (menu_runner_->RunMenuAt(button->GetWidget(), button, |
175 gfx::Rect(new_pt, gfx::Size()), views::MenuItemView::TOPLEFT, true); | 177 gfx::Rect(new_pt, gfx::Size()), views::MenuItemView::TOPLEFT, |
| 178 views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED) |
| 179 return; |
176 } | 180 } |
177 | 181 |
178 //////////////////////////////////////////////////////////////////////////////// | 182 //////////////////////////////////////////////////////////////////////////////// |
179 // views::MenuDelegate implementation. | 183 // views::MenuDelegate implementation. |
180 | 184 |
181 void LanguageSwitchMenu::ExecuteCommand(int command_id) { | 185 void LanguageSwitchMenu::ExecuteCommand(int command_id) { |
182 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 186 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
183 // Here, we should enable keyboard layouts associated with the locale so | 187 // Here, we should enable keyboard layouts associated with the locale so |
184 // that users can use those keyboard layouts on the login screen. | 188 // that users can use those keyboard layouts on the login screen. |
185 SwitchLanguageAndEnableKeyboardLayouts(locale); | 189 SwitchLanguageAndEnableKeyboardLayouts(locale); |
186 g_browser_process->local_state()->SetString( | 190 g_browser_process->local_state()->SetString( |
187 prefs::kApplicationLocale, locale); | 191 prefs::kApplicationLocale, locale); |
188 g_browser_process->local_state()->ScheduleSavePersistentPrefs(); | 192 g_browser_process->local_state()->ScheduleSavePersistentPrefs(); |
189 InitLanguageMenu(); | 193 InitLanguageMenu(); |
190 | 194 |
191 // Update all view hierarchies that the locale has changed. | 195 // Update all view hierarchies that the locale has changed. |
192 views::Widget::NotifyLocaleChanged(); | 196 views::Widget::NotifyLocaleChanged(); |
193 } | 197 } |
194 | 198 |
195 } // namespace chromeos | 199 } // namespace chromeos |
OLD | NEW |