summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/language_switch_menu.h
blob: d13d974854fe96dabf1cea2ff8adf3ffa1dee51e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_
#pragma once

#include <string>

#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "ui/views/controls/button/menu_button_listener.h"
#include "ui/views/controls/menu/menu_delegate.h"
#include "ui/views/view.h"

class WizardControllerTest_SwitchLanguage_Test;

namespace views {
class MenuItemView;
class MenuRunner;
}  // namespace views

namespace chromeos {

class LanguageList;

class LanguageSwitchMenu : public views::MenuButtonListener,
                           public views::MenuDelegate {
 public:
  LanguageSwitchMenu();
  virtual ~LanguageSwitchMenu();

  // Initializes language selection menu contents.
  void InitLanguageMenu();

  // Returns current locale name to be placed on the language menu-button.
  string16 GetCurrentLocaleName() const;

  // Sets the minimum width of the first level menu to be shown.
  void SetFirstLevelMenuWidth(int width);

  // Switches the current locale, saves the new locale in preferences.
  // Returns true if it has switched the current locale.
  static bool SwitchLanguage(const std::string& locale);

  // Switches the current locale, saves the new locale in preferences.
  // Enables the keyboard layouts associated with the new locale.
  static void SwitchLanguageAndEnableKeyboardLayouts(
      const std::string& locale);

 private:
  static void LoadFontsForCurrentLocale();

  // Overridden from views::MenuButtonListener:
  virtual void OnMenuButtonClicked(views::View* source,
                                   const gfx::Point& point) OVERRIDE;

  // Overridden from views::MenuDelegate:
  virtual void ExecuteCommand(int command_id) OVERRIDE;

  // The menu.
  views::MenuItemView* menu_;

  // Runs and owns |menu_|.
  scoped_ptr<views::MenuRunner> menu_runner_;

  // Language locale name storage.
  scoped_ptr<LanguageList> language_list_;

  FRIEND_TEST(::WizardControllerTest, SwitchLanguage);
  DISALLOW_COPY_AND_ASSIGN(LanguageSwitchMenu);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_SWITCH_MENU_H_