| 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/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/input_method/input_method_manager.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 11 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 12 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 PrefService* GetPrefService() { | 22 PrefService* GetPrefService() { |
| 22 Profile* profile = ProfileManager::GetDefaultProfile(); | 23 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 23 if (profile) | 24 if (profile) |
| 24 return profile->GetPrefs(); | 25 return profile->GetPrefs(); |
| 25 return NULL; | 26 return NULL; |
| 26 } | 27 } |
| 27 | 28 |
| 28 // A class which implements interfaces of chromeos::InputMethodMenu. This class | 29 // A class which implements interfaces of chromeos::InputMethodMenu. This class |
| 29 // is just for avoiding multiple inheritance. | 30 // is just for avoiding multiple inheritance. |
| 30 class MenuImpl : public chromeos::InputMethodMenu { | 31 class MenuImpl : public chromeos::InputMethodMenu { |
| 31 public: | 32 public: |
| 32 MenuImpl(chromeos::InputMethodMenuButton* button, | 33 MenuImpl(chromeos::InputMethodMenuButton* button, |
| 33 PrefService* pref_service, | 34 PrefService* pref_service) |
| 34 chromeos::StatusAreaViewChromeos::ScreenMode screen_mode) | 35 : InputMethodMenu(pref_service, false), button_(button) {} |
| 35 : InputMethodMenu(pref_service, screen_mode, false), button_(button) {} | |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 // InputMethodMenu implementation. | 38 // InputMethodMenu implementation. |
| 39 virtual void UpdateUI(const std::string& input_method_id, | 39 virtual void UpdateUI(const std::string& input_method_id, |
| 40 const string16& name, | 40 const string16& name, |
| 41 const string16& tooltip, | 41 const string16& tooltip, |
| 42 size_t num_active_input_methods) { | 42 size_t num_active_input_methods) { |
| 43 button_->UpdateUI(input_method_id, name, tooltip, num_active_input_methods); | 43 button_->UpdateUI(input_method_id, name, tooltip, num_active_input_methods); |
| 44 } | 44 } |
| 45 virtual bool ShouldSupportConfigUI() { | 45 virtual bool ShouldSupportConfigUI() { |
| 46 return button_->ShouldSupportConfigUI(); | 46 return button_->ShouldSupportConfigUI(); |
| 47 } | 47 } |
| 48 virtual void OpenConfigUI() { | 48 virtual void OpenConfigUI() { |
| 49 button_->OpenConfigUI(); | 49 button_->OpenConfigUI(); |
| 50 } | 50 } |
| 51 // The UI (views button) to which this class delegates all requests. | 51 // The UI (views button) to which this class delegates all requests. |
| 52 chromeos::InputMethodMenuButton* button_; | 52 chromeos::InputMethodMenuButton* button_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(MenuImpl); | 54 DISALLOW_COPY_AND_ASSIGN(MenuImpl); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 namespace chromeos { | 59 namespace chromeos { |
| 60 | 60 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
| 62 // InputMethodMenuButton | 62 // InputMethodMenuButton |
| 63 | 63 |
| 64 InputMethodMenuButton::InputMethodMenuButton( | 64 InputMethodMenuButton::InputMethodMenuButton( |
| 65 StatusAreaButton::Delegate* delegate, | 65 StatusAreaButton::Delegate* delegate) |
| 66 StatusAreaViewChromeos::ScreenMode screen_mode) | |
| 67 : StatusAreaButton(delegate, this), | 66 : StatusAreaButton(delegate, this), |
| 68 menu_(new MenuImpl(this, GetPrefService(), screen_mode)), | 67 menu_(new MenuImpl(this, GetPrefService())) { |
| 69 screen_mode_(screen_mode) { | |
| 70 set_id(VIEW_ID_STATUS_BUTTON_INPUT_METHOD); | 68 set_id(VIEW_ID_STATUS_BUTTON_INPUT_METHOD); |
| 71 UpdateUIFromCurrentInputMethod(); | 69 UpdateUIFromCurrentInputMethod(); |
| 72 } | 70 } |
| 73 | 71 |
| 74 InputMethodMenuButton::~InputMethodMenuButton() {} | 72 InputMethodMenuButton::~InputMethodMenuButton() {} |
| 75 | 73 |
| 76 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
| 77 // views::View implementation: | 75 // views::View implementation: |
| 78 | 76 |
| 79 void InputMethodMenuButton::OnLocaleChanged() { | 77 void InputMethodMenuButton::OnLocaleChanged() { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const string16& name, | 110 const string16& name, |
| 113 const string16& tooltip, | 111 const string16& tooltip, |
| 114 size_t num_active_input_methods) { | 112 size_t num_active_input_methods) { |
| 115 // Hide the button only if there is only one input method, and the input | 113 // Hide the button only if there is only one input method, and the input |
| 116 // method is a XKB keyboard layout. We don't hide the button for other | 114 // method is a XKB keyboard layout. We don't hide the button for other |
| 117 // types of input methods as these might have intra input method modes, | 115 // types of input methods as these might have intra input method modes, |
| 118 // like Hiragana and Katakana modes in Japanese input methods. | 116 // like Hiragana and Katakana modes in Japanese input methods. |
| 119 const bool hide_button = | 117 const bool hide_button = |
| 120 num_active_input_methods == 1 && | 118 num_active_input_methods == 1 && |
| 121 input_method::InputMethodUtil::IsKeyboardLayout(input_method_id) && | 119 input_method::InputMethodUtil::IsKeyboardLayout(input_method_id) && |
| 122 screen_mode_ == StatusAreaViewChromeos::BROWSER_MODE; | 120 StatusAreaViewChromeos::IsBrowserMode(); |
| 123 SetVisible(!hide_button); | 121 SetVisible(!hide_button); |
| 124 SetText(name); | 122 SetText(name); |
| 125 SetTooltipText(tooltip); | 123 SetTooltipText(tooltip); |
| 126 SetAccessibleName(tooltip); | 124 SetAccessibleName(tooltip); |
| 127 | 125 |
| 128 if (WindowIsActive()) { | 126 if (WindowIsActive()) { |
| 129 // We don't call these functions if the |current_window| is not active since | 127 // We don't call these functions if the |current_window| is not active since |
| 130 // the calls are relatively expensive (crosbug.com/9206). Please note that | 128 // the calls are relatively expensive (crosbug.com/9206). Please note that |
| 131 // PrepareMenuModel() is necessary for fixing crosbug.com/7522 when the | 129 // PrepareMenuModel() is necessary for fixing crosbug.com/7522 when the |
| 132 // window is active. | 130 // window is active. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 156 const input_method::InputMethodDescriptor& input_method = | 154 const input_method::InputMethodDescriptor& input_method = |
| 157 input_method_manager->current_input_method(); | 155 input_method_manager->current_input_method(); |
| 158 const string16 name = InputMethodMenu::GetTextForIndicator(input_method); | 156 const string16 name = InputMethodMenu::GetTextForIndicator(input_method); |
| 159 const string16 tooltip = InputMethodMenu::GetTextForMenu(input_method); | 157 const string16 tooltip = InputMethodMenu::GetTextForMenu(input_method); |
| 160 const size_t num_active_input_methods = | 158 const size_t num_active_input_methods = |
| 161 input_method_manager->GetNumActiveInputMethods(); | 159 input_method_manager->GetNumActiveInputMethods(); |
| 162 UpdateUI(input_method.id(), name, tooltip, num_active_input_methods); | 160 UpdateUI(input_method.id(), name, tooltip, num_active_input_methods); |
| 163 } | 161 } |
| 164 | 162 |
| 165 } // namespace chromeos | 163 } // namespace chromeos |
| OLD | NEW |