| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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_STATUS_INPUT_METHOD_MENU_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | |
| 13 #include "ui/base/models/menu_model.h" | |
| 14 #include "ui/views/controls/button/menu_button_listener.h" | |
| 15 #include "ui/views/controls/menu/menu_item_view.h" | |
| 16 | |
| 17 class PrefService; | |
| 18 class SkBitmap; | |
| 19 | |
| 20 namespace ui { | |
| 21 class SimpleMenuModel; | |
| 22 } // namespace ui | |
| 23 | |
| 24 namespace views { | |
| 25 class MenuItemView; | |
| 26 class MenuModelAdapter; | |
| 27 class MenuRunner; | |
| 28 } // namespace views | |
| 29 | |
| 30 namespace chromeos { | |
| 31 | |
| 32 // A class for the dropdown menu for switching input method and keyboard layout. | |
| 33 // Since the class provides the views::MenuButtonListener interface, it's easy | |
| 34 // to create a button widget (e.g. views::MenuButton, StatusAreaButton) which | |
| 35 // shows the dropdown menu on click. | |
| 36 class InputMethodMenu | |
| 37 : public views::MenuButtonListener, | |
| 38 public ui::MenuModel, | |
| 39 public input_method::InputMethodManager::Observer { | |
| 40 public: | |
| 41 InputMethodMenu(); | |
| 42 virtual ~InputMethodMenu(); | |
| 43 | |
| 44 // ui::MenuModel implementation. | |
| 45 virtual bool HasIcons() const OVERRIDE; | |
| 46 virtual int GetItemCount() const OVERRIDE; | |
| 47 virtual ui::MenuModel::ItemType GetTypeAt(int index) const OVERRIDE; | |
| 48 virtual int GetCommandIdAt(int index) const OVERRIDE; | |
| 49 virtual string16 GetLabelAt(int index) const OVERRIDE; | |
| 50 virtual bool IsItemDynamicAt(int index) const OVERRIDE; | |
| 51 virtual bool GetAcceleratorAt(int index, | |
| 52 ui::Accelerator* accelerator) const OVERRIDE; | |
| 53 virtual bool IsItemCheckedAt(int index) const OVERRIDE; | |
| 54 virtual int GetGroupIdAt(int index) const OVERRIDE; | |
| 55 virtual bool GetIconAt(int index, SkBitmap* icon) OVERRIDE; | |
| 56 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt( | |
| 57 int index) const OVERRIDE; | |
| 58 virtual bool IsEnabledAt(int index) const OVERRIDE; | |
| 59 virtual ui::MenuModel* GetSubmenuModelAt(int index) const OVERRIDE; | |
| 60 virtual void HighlightChangedTo(int index) OVERRIDE; | |
| 61 virtual void ActivatedAt(int index) OVERRIDE; | |
| 62 virtual void MenuWillShow() OVERRIDE; | |
| 63 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) OVERRIDE; | |
| 64 | |
| 65 // views::MenuButtonListener implementation. | |
| 66 virtual void OnMenuButtonClicked(views::View* source, | |
| 67 const gfx::Point& point) OVERRIDE; | |
| 68 | |
| 69 // InputMethodManager::Observer implementation. | |
| 70 virtual void InputMethodChanged( | |
| 71 input_method::InputMethodManager* manager, | |
| 72 const input_method::InputMethodDescriptor& current_input_method, | |
| 73 size_t num_active_input_methods) OVERRIDE; | |
| 74 virtual void ActiveInputMethodsChanged( | |
| 75 input_method::InputMethodManager* manager, | |
| 76 const input_method::InputMethodDescriptor& current_input_method, | |
| 77 size_t num_active_input_methods) OVERRIDE; | |
| 78 virtual void PropertyListChanged( | |
| 79 input_method::InputMethodManager* manager, | |
| 80 const input_method::InputMethodPropertyList& properties) OVERRIDE; | |
| 81 | |
| 82 // Specify menu alignment (default TOPRIGHT). | |
| 83 void set_menu_alignment(views::MenuItemView::AnchorPosition menu_alignment) { | |
| 84 menu_alignment_ = menu_alignment; | |
| 85 } | |
| 86 | |
| 87 // Sets the minimum width of the dropdown menu. | |
| 88 void SetMinimumWidth(int width); | |
| 89 | |
| 90 // Rebuilds menu model. | |
| 91 void PrepareMenuModel(); | |
| 92 | |
| 93 // Returns a string for the drop-down menu and the tooltip for the indicator. | |
| 94 // The method is public for unit tests. | |
| 95 static string16 GetTextForMenu( | |
| 96 const input_method::InputMethodDescriptor& input_method); | |
| 97 | |
| 98 protected: | |
| 99 // Prepares menu: saves user metrics and rebuilds. | |
| 100 void PrepareForMenuOpen(); | |
| 101 | |
| 102 private: | |
| 103 // Updates UI of a container of the menu (e.g. the "US" menu button in the | |
| 104 // status area). Sub classes have to implement the interface for their own UI. | |
| 105 virtual void UpdateUI(const std::string& input_method_id, // e.g. "mozc" | |
| 106 const string16& name, // e.g. "US", "INTL" | |
| 107 const string16& tooltip, | |
| 108 size_t num_active_input_methods) = 0; | |
| 109 | |
| 110 // Sub classes have to implement the interface. This interface should return | |
| 111 // true if the dropdown menu should show an item like "Customize languages | |
| 112 // and input..." WebUI. | |
| 113 virtual bool ShouldSupportConfigUI() = 0; | |
| 114 | |
| 115 // Sub classes have to implement the interface which opens an UI for | |
| 116 // customizing languages and input. | |
| 117 virtual void OpenConfigUI() = 0; | |
| 118 | |
| 119 // Parses |input_method| and then calls UpdateUI(). | |
| 120 void UpdateUIFromInputMethod( | |
| 121 const input_method::InputMethodDescriptor& input_method, | |
| 122 size_t num_active_input_methods); | |
| 123 | |
| 124 // Rebuilds |model_|. This function should be called whenever | |
| 125 // |input_method_descriptors_| is updated, or ImePropertiesChanged() is | |
| 126 // called. | |
| 127 void RebuildModel(); | |
| 128 | |
| 129 // Returns true if the zero-origin |index| points to one of the input methods. | |
| 130 bool IndexIsInInputMethodList(int index) const; | |
| 131 | |
| 132 // Returns true if the zero-origin |index| points to one of the IME | |
| 133 // properties. When returning true, |property_index| is updated so that | |
| 134 // property_list.at(property_index) points to the menu item. | |
| 135 bool GetPropertyIndex(int index, int* property_index) const; | |
| 136 | |
| 137 // Returns true if the zero-origin |index| points to the "Configure IME" menu | |
| 138 // item. | |
| 139 bool IndexPointsToConfigureImeMenuItem(int index) const; | |
| 140 | |
| 141 // Add / Remove InputMethodManager observer. | |
| 142 void AddObserver(); | |
| 143 void RemoveObserver(); | |
| 144 | |
| 145 // The current input method list. | |
| 146 scoped_ptr<input_method::InputMethodDescriptors> input_method_descriptors_; | |
| 147 | |
| 148 // We borrow ui::SimpleMenuModel implementation to maintain the current | |
| 149 // content of the pop-up menu. The ui::MenuModel is implemented using this | |
| 150 // |model_|. The MenuModelAdapter wraps the model with the | |
| 151 // views::MenuDelegate interface required for MenuItemView. | |
| 152 scoped_ptr<ui::SimpleMenuModel> model_; | |
| 153 scoped_ptr<views::MenuModelAdapter> input_method_menu_delegate_; | |
| 154 views::MenuItemView* input_method_menu_; | |
| 155 scoped_ptr<views::MenuRunner> input_method_menu_runner_; | |
| 156 | |
| 157 int minimum_input_method_menu_width_; | |
| 158 | |
| 159 // Menu alignment (default TOPRIGHT). | |
| 160 views::MenuItemView::AnchorPosition menu_alignment_; | |
| 161 | |
| 162 DISALLOW_COPY_AND_ASSIGN(InputMethodMenu); | |
| 163 }; | |
| 164 | |
| 165 } // namespace chromeos | |
| 166 | |
| 167 #endif // CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_ | |
| OLD | NEW |