Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/browser/chromeos/status/input_method_menu.h

Issue 6962012: Convert ChromiumOS input method menu to views::MenuItemView implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_
6 #define CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_ 6 #define CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "chrome/browser/chromeos/cros/input_method_library.h" 11 #include "chrome/browser/chromeos/cros/input_method_library.h"
12 #include "chrome/browser/chromeos/status/status_area_host.h" 12 #include "chrome/browser/chromeos/status/status_area_host.h"
13 #include "chrome/browser/prefs/pref_member.h" 13 #include "chrome/browser/prefs/pref_member.h"
14 #include "content/common/notification_observer.h" 14 #include "content/common/notification_observer.h"
15 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
16 #include "content/common/notification_type.h" 16 #include "content/common/notification_type.h"
17 #include "ui/base/models/simple_menu_model.h" 17 #include "ui/base/models/menu_model.h"
18 #include "views/controls/menu/menu_2.h" 18 #include "views/controls/menu/menu_item_view.h"
19 #include "views/controls/menu/view_menu_delegate.h" 19 #include "views/controls/menu/view_menu_delegate.h"
20 20
21 class PrefService; 21 class PrefService;
22 class SkBitmap; 22 class SkBitmap;
23 23
24 namespace ui {
25 class SimpleMenuModel;
26 } // namespace ui
27
28 namespace views {
29 class MenuModelAdapter;
30 } // namespace views
31
24 namespace chromeos { 32 namespace chromeos {
25 33
26 // A class for the dropdown menu for switching input method and keyboard layout. 34 // A class for the dropdown menu for switching input method and keyboard layout.
27 // Since the class provides the views::ViewMenuDelegate interface, it's easy to 35 // Since the class provides the views::ViewMenuDelegate interface, it's easy to
28 // create a button widget (e.g. views::MenuButton, chromeos::StatusAreaButton) 36 // create a button widget (e.g. views::MenuButton, chromeos::StatusAreaButton)
29 // which shows the dropdown menu on click. 37 // which shows the dropdown menu on click.
30 class InputMethodMenu : public views::ViewMenuDelegate, 38 class InputMethodMenu : public views::ViewMenuDelegate,
31 public ui::MenuModel, 39 public ui::MenuModel,
32 public InputMethodLibrary::Observer, 40 public InputMethodLibrary::Observer,
33 public NotificationObserver { 41 public NotificationObserver {
(...skipping 18 matching lines...) Expand all
52 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; 60 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const;
53 virtual bool IsEnabledAt(int index) const; 61 virtual bool IsEnabledAt(int index) const;
54 virtual ui::MenuModel* GetSubmenuModelAt(int index) const; 62 virtual ui::MenuModel* GetSubmenuModelAt(int index) const;
55 virtual void HighlightChangedTo(int index); 63 virtual void HighlightChangedTo(int index);
56 virtual void ActivatedAt(int index); 64 virtual void ActivatedAt(int index);
57 virtual void MenuWillShow(); 65 virtual void MenuWillShow();
58 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate); 66 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate);
59 67
60 // views::ViewMenuDelegate implementation. Sub classes can override the method 68 // views::ViewMenuDelegate implementation. Sub classes can override the method
61 // to adjust the position of the menu. 69 // to adjust the position of the menu.
62 virtual void RunMenu(views::View* unused_source, 70 virtual void RunMenu(views::View* source, const gfx::Point& pt);
63 const gfx::Point& pt);
64 71
65 // InputMethodLibrary::Observer implementation. 72 // InputMethodLibrary::Observer implementation.
66 virtual void InputMethodChanged( 73 virtual void InputMethodChanged(
67 InputMethodLibrary* obj, 74 InputMethodLibrary* obj,
68 const InputMethodDescriptor& current_input_method, 75 const InputMethodDescriptor& current_input_method,
69 size_t num_active_input_methods); 76 size_t num_active_input_methods);
70 virtual void ActiveInputMethodsChanged( 77 virtual void ActiveInputMethodsChanged(
71 InputMethodLibrary* obj, 78 InputMethodLibrary* obj,
72 const InputMethodDescriptor& current_input_method, 79 const InputMethodDescriptor& current_input_method,
73 size_t num_active_input_methods); 80 size_t num_active_input_methods);
74 virtual void PreferenceUpdateNeeded( 81 virtual void PreferenceUpdateNeeded(
75 InputMethodLibrary* obj, 82 InputMethodLibrary* obj,
76 const InputMethodDescriptor& previous_input_method, 83 const InputMethodDescriptor& previous_input_method,
77 const InputMethodDescriptor& current_input_method); 84 const InputMethodDescriptor& current_input_method);
78 virtual void PropertyListChanged( 85 virtual void PropertyListChanged(
79 InputMethodLibrary* obj, 86 InputMethodLibrary* obj,
80 const ImePropertyList& current_ime_properties); 87 const ImePropertyList& current_ime_properties);
81 virtual void FirstObserverIsAdded(InputMethodLibrary* obj); 88 virtual void FirstObserverIsAdded(InputMethodLibrary* obj);
82 89
83 // NotificationObserver implementation. 90 // NotificationObserver implementation.
84 virtual void Observe(NotificationType type, 91 virtual void Observe(NotificationType type,
85 const NotificationSource& source, 92 const NotificationSource& source,
86 const NotificationDetails& details); 93 const NotificationDetails& details);
87 94
95 // Specify menu alignment (default TOPRIGHT).
96 void set_menu_alignment(views::MenuItemView::AnchorPosition menu_alignment) {
97 menu_alignment_ = menu_alignment;
98 }
99
88 // Sets the minimum width of the dropdown menu. 100 // Sets the minimum width of the dropdown menu.
89 void SetMinimumWidth(int width); 101 void SetMinimumWidth(int width);
90 102
91 // Rebuilds model and menu2 objects. 103 // Rebuilds menu model.
92 void PrepareMenu(); 104 void PrepareMenuModel();
93 105
94 // Registers input method preferences for the login screen. 106 // Registers input method preferences for the login screen.
95 static void RegisterPrefs(PrefService* local_state); 107 static void RegisterPrefs(PrefService* local_state);
96 108
97 // Returns a string for the indicator on top right corner of the Chrome 109 // Returns a string for the indicator on top right corner of the Chrome
98 // window. The method is public for unit tests. 110 // window. The method is public for unit tests.
99 static std::wstring GetTextForIndicator( 111 static std::wstring GetTextForIndicator(
100 const InputMethodDescriptor& input_method); 112 const InputMethodDescriptor& input_method);
101 113
102 // Returns a string for the drop-down menu and the tooltip for the indicator. 114 // Returns a string for the drop-down menu and the tooltip for the indicator.
103 // The method is public for unit tests. 115 // The method is public for unit tests.
104 static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method); 116 static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method);
105 117
106 protected: 118 protected:
107 // Prepares menu: saves user metrics and rebuilds. 119 // Prepares menu: saves user metrics and rebuilds.
108 void PrepareForMenuOpen(); 120 void PrepareForMenuOpen();
109 121
110 // Returns menu2 object for language menu.
111 views::Menu2& input_method_menu() {
112 return input_method_menu_;
113 }
114
115 private: 122 private:
116 // Updates UI of a container of the menu (e.g. the "US" menu button in the 123 // Updates UI of a container of the menu (e.g. the "US" menu button in the
117 // status area). Sub classes have to implement the interface for their own UI. 124 // status area). Sub classes have to implement the interface for their own UI.
118 virtual void UpdateUI(const std::string& input_method_id, // e.g. "mozc" 125 virtual void UpdateUI(const std::string& input_method_id, // e.g. "mozc"
119 const std::wstring& name, // e.g. "US", "INTL" 126 const std::wstring& name, // e.g. "US", "INTL"
120 const std::wstring& tooltip, 127 const std::wstring& tooltip,
121 size_t num_active_input_methods) = 0; 128 size_t num_active_input_methods) = 0;
122 129
123 // Sub classes have to implement the interface. This interface should return 130 // Sub classes have to implement the interface. This interface should return
124 // true if the dropdown menu should show an item like "Customize languages 131 // true if the dropdown menu should show an item like "Customize languages
(...skipping 27 matching lines...) Expand all
152 159
153 // The current input method list. 160 // The current input method list.
154 scoped_ptr<InputMethodDescriptors> input_method_descriptors_; 161 scoped_ptr<InputMethodDescriptors> input_method_descriptors_;
155 162
156 // Objects for reading/writing the Chrome prefs. 163 // Objects for reading/writing the Chrome prefs.
157 StringPrefMember previous_input_method_pref_; 164 StringPrefMember previous_input_method_pref_;
158 StringPrefMember current_input_method_pref_; 165 StringPrefMember current_input_method_pref_;
159 166
160 // We borrow ui::SimpleMenuModel implementation to maintain the current 167 // We borrow ui::SimpleMenuModel implementation to maintain the current
161 // content of the pop-up menu. The ui::MenuModel is implemented using this 168 // content of the pop-up menu. The ui::MenuModel is implemented using this
162 // |model_|. 169 // |model_|. The MenuModelAdapter wraps the model with the
170 // views::MenuDelegate interface required for MenuItemView.
163 scoped_ptr<ui::SimpleMenuModel> model_; 171 scoped_ptr<ui::SimpleMenuModel> model_;
172 scoped_ptr<views::MenuModelAdapter> input_method_menu_delegate_;
164 173
165 // The language menu which pops up when the button in status area is clicked.
166 views::Menu2 input_method_menu_;
167 int minimum_input_method_menu_width_; 174 int minimum_input_method_menu_width_;
168 175
176 // Menu alignment (default TOPRIGHT).
177 views::MenuItemView::AnchorPosition menu_alignment_;
178
169 PrefService* pref_service_; 179 PrefService* pref_service_;
170 NotificationRegistrar registrar_; 180 NotificationRegistrar registrar_;
171 181
172 // The mode of the host screen (e.g. browser, screen locker, login screen.) 182 // The mode of the host screen (e.g. browser, screen locker, login screen.)
173 const StatusAreaHost::ScreenMode screen_mode_; 183 const StatusAreaHost::ScreenMode screen_mode_;
174 // true if the menu is for a dialog in OOBE screen. In the dialog, we don't 184 // true if the menu is for a dialog in OOBE screen. In the dialog, we don't
175 // use radio buttons. 185 // use radio buttons.
176 const bool for_out_of_box_experience_dialog_; 186 const bool for_out_of_box_experience_dialog_;
177 187
178 DISALLOW_COPY_AND_ASSIGN(InputMethodMenu); 188 DISALLOW_COPY_AND_ASSIGN(InputMethodMenu);
179 }; 189 };
180 190
181 } // namespace chromeos 191 } // namespace chromeos
182 192
183 #endif // CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_ 193 #endif // CHROME_BROWSER_CHROMEOS_STATUS_INPUT_METHOD_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/keyboard_switch_menu.cc ('k') | chrome/browser/chromeos/status/input_method_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698