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/status/input_method_menu_button.h" | 5 #include "chrome/browser/chromeos/status/input_method_menu_button.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 return NULL; | 26 return NULL; |
27 } | 27 } |
28 | 28 |
29 #if defined(CROS_FONTS_USING_BCI) | 29 #if defined(CROS_FONTS_USING_BCI) |
30 const int kFontSizeDelta = 0; | 30 const int kFontSizeDelta = 0; |
31 #else | 31 #else |
32 const int kFontSizeDelta = 1; | 32 const int kFontSizeDelta = 1; |
33 #endif | 33 #endif |
34 | 34 |
| 35 // A class which implements interfaces of chromeos::InputMethodMenu. This class |
| 36 // is just for avoiding multiple inheritance. |
| 37 class MenuImpl : public chromeos::InputMethodMenu { |
| 38 public: |
| 39 MenuImpl(chromeos::InputMethodMenuButton* button, |
| 40 PrefService* pref_service, |
| 41 chromeos::StatusAreaHost::ScreenMode screen_mode) |
| 42 : InputMethodMenu(pref_service, screen_mode, false), button_(button) {} |
| 43 |
| 44 private: |
| 45 // InputMethodMenu implementation. |
| 46 virtual void UpdateUI(const std::string& input_method_id, |
| 47 const std::wstring& name, |
| 48 const std::wstring& tooltip, |
| 49 size_t num_active_input_methods) { |
| 50 button_->UpdateUI(input_method_id, name, tooltip, num_active_input_methods); |
| 51 } |
| 52 virtual bool ShouldSupportConfigUI() { |
| 53 return button_->ShouldSupportConfigUI(); |
| 54 } |
| 55 virtual void OpenConfigUI() { |
| 56 button_->OpenConfigUI(); |
| 57 } |
| 58 // The UI (views button) to which this class delegates all requests. |
| 59 chromeos::InputMethodMenuButton* button_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(MenuImpl); |
| 62 }; |
| 63 |
35 } // namespace | 64 } // namespace |
36 | 65 |
37 namespace chromeos { | 66 namespace chromeos { |
38 | 67 |
39 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
40 // InputMethodMenuButton | 69 // InputMethodMenuButton |
41 | 70 |
42 InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host) | 71 InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host) |
43 : StatusAreaButton(this), | 72 : StatusAreaButton(this), |
44 InputMethodMenu(GetPrefService(host), | 73 menu_(new MenuImpl(this, GetPrefService(host), host->GetScreenMode())), |
45 host->GetScreenMode(), | |
46 false /* for_out_of_box_experience_dialog */), | |
47 host_(host) { | 74 host_(host) { |
48 set_border(NULL); | 75 set_border(NULL); |
49 set_use_menu_button_paint(true); | 76 set_use_menu_button_paint(true); |
50 SetFont(ResourceBundle::GetSharedInstance().GetFont( | 77 SetFont(ResourceBundle::GetSharedInstance().GetFont( |
51 ResourceBundle::BaseFont).DeriveFont(kFontSizeDelta)); | 78 ResourceBundle::BaseFont).DeriveFont(kFontSizeDelta)); |
52 SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha | 79 SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha |
53 SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible) | 80 SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible) |
54 SetShowMultipleIconStates(false); | 81 SetShowMultipleIconStates(false); |
55 set_alignment(TextButton::ALIGN_CENTER); | 82 set_alignment(TextButton::ALIGN_CENTER); |
56 | 83 |
57 chromeos::KeyboardLibrary* keyboard_library = | 84 chromeos::KeyboardLibrary* keyboard_library = |
58 chromeos::CrosLibrary::Get()->GetKeyboardLibrary(); | 85 chromeos::CrosLibrary::Get()->GetKeyboardLibrary(); |
59 const std::string hardware_keyboard_id = // e.g. "xkb:us::eng" | 86 const std::string hardware_keyboard_id = // e.g. "xkb:us::eng" |
60 keyboard_library->GetHardwareKeyboardLayoutName(); | 87 keyboard_library->GetHardwareKeyboardLayoutName(); |
61 | 88 |
62 // Draw the default indicator "US". The default indicator "US" is used when | 89 // Draw the default indicator "US". The default indicator "US" is used when |
63 // |pref_service| is not available (for example, unit tests) or |pref_service| | 90 // |pref_service| is not available (for example, unit tests) or |pref_service| |
64 // is available, but Chrome preferences are not available (for example, | 91 // is available, but Chrome preferences are not available (for example, |
65 // initial OS boot). | 92 // initial OS boot). |
66 InputMethodMenuButton::UpdateUI(hardware_keyboard_id, L"US", L"", 1); | 93 UpdateUI(hardware_keyboard_id, L"US", L"", 1); |
67 } | 94 } |
68 | 95 |
69 //////////////////////////////////////////////////////////////////////////////// | 96 //////////////////////////////////////////////////////////////////////////////// |
70 // views::View implementation: | 97 // views::View implementation: |
71 | 98 |
72 gfx::Size InputMethodMenuButton::GetPreferredSize() { | 99 gfx::Size InputMethodMenuButton::GetPreferredSize() { |
73 // If not enabled, then hide this button. | 100 // If not enabled, then hide this button. |
74 if (!IsEnabled()) { | 101 if (!IsEnabled()) { |
75 return gfx::Size(0, 0); | 102 return gfx::Size(0, 0); |
76 } | 103 } |
77 return StatusAreaButton::GetPreferredSize(); | 104 return StatusAreaButton::GetPreferredSize(); |
78 } | 105 } |
79 | 106 |
80 void InputMethodMenuButton::OnLocaleChanged() { | 107 void InputMethodMenuButton::OnLocaleChanged() { |
81 input_method::OnLocaleChanged(); | 108 input_method::OnLocaleChanged(); |
82 | 109 |
83 chromeos::InputMethodLibrary* input_method_library = | 110 chromeos::InputMethodLibrary* input_method_library = |
84 chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); | 111 chromeos::CrosLibrary::Get()->GetInputMethodLibrary(); |
85 const InputMethodDescriptor& input_method = | 112 const InputMethodDescriptor& input_method = |
86 input_method_library->current_input_method(); | 113 input_method_library->current_input_method(); |
| 114 const std::wstring name = InputMethodMenu::GetTextForIndicator(input_method); |
| 115 const std::wstring tooltip = InputMethodMenu::GetTextForMenu(input_method); |
87 | 116 |
88 // In general, we should not call an input method API in the input method | 117 // In general, we should not call an input method API in the input method |
89 // button classes (status/input_menu_button*.cc) for performance reasons (see | 118 // button classes (status/input_menu_button*.cc) for performance reasons (see |
90 // http://crosbug.com/8284). However, since OnLocaleChanged is called only in | 119 // http://crosbug.com/8284). However, since OnLocaleChanged is called only in |
91 // OOBE/Login screen which does not have two or more Chrome windows, it's okay | 120 // OOBE/Login screen which does not have two or more Chrome windows, it's okay |
92 // to call GetNumActiveInputMethods here. | 121 // to call GetNumActiveInputMethods here. |
93 const size_t num_active_input_methods = | 122 const size_t num_active_input_methods = |
94 input_method_library->GetNumActiveInputMethods(); | 123 input_method_library->GetNumActiveInputMethods(); |
| 124 UpdateUI(input_method.id, name, tooltip, num_active_input_methods); |
95 | 125 |
96 UpdateUIFromInputMethod(input_method, num_active_input_methods); | |
97 Layout(); | 126 Layout(); |
98 SchedulePaint(); | 127 SchedulePaint(); |
99 } | 128 } |
100 | 129 |
101 //////////////////////////////////////////////////////////////////////////////// | 130 //////////////////////////////////////////////////////////////////////////////// |
102 // InputMethodMenu::InputMethodMenuHost implementation: | 131 // views::ViewMenuDelegate implementation: |
| 132 |
| 133 void InputMethodMenuButton::RunMenu(views::View* unused_source, |
| 134 const gfx::Point& pt) { |
| 135 menu_->RunMenu(unused_source, pt); |
| 136 } |
103 | 137 |
104 void InputMethodMenuButton::UpdateUI(const std::string& input_method_id, | 138 void InputMethodMenuButton::UpdateUI(const std::string& input_method_id, |
105 const std::wstring& name, | 139 const std::wstring& name, |
106 const std::wstring& tooltip, | 140 const std::wstring& tooltip, |
107 size_t num_active_input_methods) { | 141 size_t num_active_input_methods) { |
108 // Hide the button only if there is only one input method, and the input | 142 // Hide the button only if there is only one input method, and the input |
109 // method is a XKB keyboard layout. We don't hide the button for other | 143 // method is a XKB keyboard layout. We don't hide the button for other |
110 // types of input methods as these might have intra input method modes, | 144 // types of input methods as these might have intra input method modes, |
111 // like Hiragana and Katakana modes in Japanese input methods. | 145 // like Hiragana and Katakana modes in Japanese input methods. |
112 if (num_active_input_methods == 1 && | 146 if (num_active_input_methods == 1 && |
(...skipping 13 matching lines...) Expand all Loading... |
126 | 160 |
127 void InputMethodMenuButton::OpenConfigUI() { | 161 void InputMethodMenuButton::OpenConfigUI() { |
128 host_->OpenButtonOptions(this); // ask browser to open the DOMUI page. | 162 host_->OpenButtonOptions(this); // ask browser to open the DOMUI page. |
129 } | 163 } |
130 | 164 |
131 bool InputMethodMenuButton::ShouldSupportConfigUI() { | 165 bool InputMethodMenuButton::ShouldSupportConfigUI() { |
132 return host_->ShouldOpenButtonOptions(this); | 166 return host_->ShouldOpenButtonOptions(this); |
133 } | 167 } |
134 | 168 |
135 } // namespace chromeos | 169 } // namespace chromeos |
OLD | NEW |