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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "chrome/browser/language_combobox_model.h" 13 #include "testing/gtest/include/gtest/gtest_prod.h" 14 #include "ui/base/models/simple_menu_model.h" 15 #include "views/controls/menu/menu_2.h" 16 #include "views/controls/menu/view_menu_delegate.h" 17 #include "views/view.h" 18 19 class WizardControllerTest_SwitchLanguage_Test; 20 21 namespace chromeos { 22 23 class ScreenObserver; 24 25 class LanguageSwitchMenu : public views::ViewMenuDelegate, 26 public ui::SimpleMenuModel::Delegate { 27 public: 28 LanguageSwitchMenu(); 29 30 // Initializes language selection menu contents. 31 void InitLanguageMenu(); 32 33 // Sets menu's alignment. 34 void set_menu_alignment(views::Menu2::Alignment alignment) { 35 menu_alignment_ = alignment; 36 } 37 38 // Returns current locale name to be placed on the language menu-button. 39 string16 GetCurrentLocaleName() const; 40 41 // Sets the minimum width of the first level menu to be shown. 42 void SetFirstLevelMenuWidth(int width); 43 44 // Switches the current locale, saves the new locale in preferences. 45 // Returns true if it has switched the current locale. 46 static bool SwitchLanguage(const std::string& locale); 47 48 // Switches the current locale, saves the new locale in preferences. 49 // Enables the keyboard layouts associated with the new locale. 50 static void SwitchLanguageAndEnableKeyboardLayouts( 51 const std::string& locale); 52 53 private: 54 static void LoadFontsForCurrentLocale(); 55 56 // views::ViewMenuDelegate implementation. 57 virtual void RunMenu(views::View* source, const gfx::Point& pt); 58 59 // ui::SimpleMenuModel::Delegate implementation. 60 virtual bool IsCommandIdChecked(int command_id) const; 61 virtual bool IsCommandIdEnabled(int command_id) const; 62 virtual bool GetAcceleratorForCommandId(int command_id, 63 ui::Accelerator* accelerator); 64 virtual void ExecuteCommand(int command_id); 65 66 // Dialog controls that we own ourselves. 67 ui::SimpleMenuModel menu_model_; 68 ui::SimpleMenuModel menu_model_submenu_; 69 scoped_ptr<views::Menu2> menu_; 70 71 // Language locale name storage. 72 scoped_ptr<LanguageList> language_list_; 73 74 // Menu alignment. 75 views::Menu2::Alignment menu_alignment_; 76 77 FRIEND_TEST(::WizardControllerTest, SwitchLanguage); 78 DISALLOW_COPY_AND_ASSIGN(LanguageSwitchMenu); 79 }; 80 81 } // namespace chromeos 82 83 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_ 84