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

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

Issue 7016042: Convert NetworkMenu from Menu2 to MenuItemView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace fix. Created 9 years, 7 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_NETWORK_MENU_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ 6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "chrome/browser/chromeos/options/network_config_view.h" 12 #include "chrome/browser/chromeos/options/network_config_view.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/base/models/menu_model.h" 14 #include "ui/base/models/menu_model.h"
15 #include "ui/gfx/native_widget_types.h" 15 #include "ui/gfx/native_widget_types.h"
16 #include "views/controls/menu/view_menu_delegate.h" 16 #include "views/controls/menu/view_menu_delegate.h"
17 17
18 namespace {
19
20 const int kMainCommandIndexOffset = 1000;
21 const int kVPNCommandIndexOffset = 2000;
22 const int kMoreCommandIndexOffset = 3000;
23
24 } // namespace
25
18 namespace gfx { 26 namespace gfx {
19 class Canvas; 27 class Canvas;
20 } 28 }
21 29
22 namespace views { 30 namespace views {
23 class Menu2; 31 class MenuItemView;
32 class MenuButton;
24 } 33 }
25 34
26 namespace chromeos { 35 namespace chromeos {
27 36
28 class NetworkMenu; 37 class NetworkMenuModel;
29 38 class NetworkMenuTaskProxy;
30 class NetworkMenuModel : public ui::MenuModel {
31 public:
32 struct NetworkInfo {
33 NetworkInfo();
34 ~NetworkInfo();
35
36 // "ethernet" | "wifi" | "cellular" | "other".
37 std::string network_type;
38 // "connected" | "connecting" | "disconnected" | "error".
39 std::string status;
40 // status message or error message, empty if unknown status.
41 std::string message;
42 // IP address (if network is active, empty otherwise)
43 std::string ip_address;
44 // Remembered passphrase.
45 std::string passphrase;
46 // true if the network requires a passphrase.
47 bool need_passphrase;
48 // true if the network is currently remembered.
49 bool remembered;
50 // true if the network is auto connect (meaningful for Wifi only).
51 bool auto_connect;
52 };
53
54 explicit NetworkMenuModel(NetworkMenu* owner);
55 virtual ~NetworkMenuModel();
56
57 // Connect or reconnect to the network at |index|.
58 // If remember >= 0, set the favorite state of the network.
59 // Returns true if a connect occurred (e.g. menu should be closed).
60 bool ConnectToNetworkAt(int index,
61 const std::string& passphrase,
62 const std::string& ssid,
63 int remember) const;
64
65 // Called by NetworkMenu::RunMenu to initialize list of menu items.
66 virtual void InitMenuItems(bool is_browser_mode,
67 bool should_open_button_options) = 0;
68
69 // ui::MenuModel implementation.
70 virtual bool HasIcons() const;
71 virtual int GetItemCount() const;
72 virtual ui::MenuModel::ItemType GetTypeAt(int index) const;
73 virtual int GetCommandIdAt(int index) const;
74 virtual string16 GetLabelAt(int index) const;
75 virtual bool IsItemDynamicAt(int index) const;
76 virtual const gfx::Font* GetLabelFontAt(int index) const;
77 virtual bool GetAcceleratorAt(int index, ui::Accelerator* accelerator) const;
78 virtual bool IsItemCheckedAt(int index) const;
79 virtual int GetGroupIdAt(int index) const;
80 virtual bool GetIconAt(int index, SkBitmap* icon);
81 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const;
82 virtual bool IsEnabledAt(int index) const;
83 virtual ui::MenuModel* GetSubmenuModelAt(int index) const;
84 virtual void HighlightChangedTo(int index);
85 virtual void ActivatedAt(int index);
86 virtual void MenuWillShow();
87 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate);
88
89 protected:
90 enum MenuItemFlags {
91 FLAG_NONE = 0,
92 FLAG_DISABLED = 1 << 0,
93 FLAG_TOGGLE_ETHERNET = 1 << 1,
94 FLAG_TOGGLE_WIFI = 1 << 2,
95 FLAG_TOGGLE_CELLULAR = 1 << 3,
96 FLAG_TOGGLE_OFFLINE = 1 << 4,
97 FLAG_ASSOCIATED = 1 << 5,
98 FLAG_ETHERNET = 1 << 6,
99 FLAG_WIFI = 1 << 7,
100 FLAG_CELLULAR = 1 << 8,
101 FLAG_OPTIONS = 1 << 9,
102 FLAG_ADD_WIFI = 1 << 10,
103 FLAG_ADD_CELLULAR = 1 << 11,
104 FLAG_VPN = 1 << 12,
105 FLAG_ADD_VPN = 1 << 13,
106 FLAG_DISCONNECT_VPN = 1 << 14,
107 FLAG_VIEW_ACCOUNT = 1 << 15,
108 };
109
110 struct MenuItem {
111 MenuItem()
112 : type(ui::MenuModel::TYPE_SEPARATOR),
113 sub_menu_model(NULL),
114 flags(0) {}
115 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon,
116 const std::string& service_path, int flags)
117 : type(type),
118 label(label),
119 icon(icon),
120 service_path(service_path),
121 sub_menu_model(NULL),
122 flags(flags) {}
123 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon,
124 NetworkMenuModel* sub_menu_model, int flags)
125 : type(type),
126 label(label),
127 icon(icon),
128 sub_menu_model(sub_menu_model),
129 flags(flags) {}
130
131 ui::MenuModel::ItemType type;
132 string16 label;
133 SkBitmap icon;
134 std::string service_path;
135 NetworkMenuModel* sub_menu_model; // Weak.
136 int flags;
137 };
138 typedef std::vector<MenuItem> MenuItemVector;
139
140 // Our menu items.
141 MenuItemVector menu_items_;
142
143 NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel.
144
145 // Top up URL of the current carrier on empty string if there's none.
146 std::string top_up_url_;
147
148 // Carrier ID which top up URL is initialized for.
149 // Used to update top up URL only when cellular carrier has changed.
150 std::string carrier_id_;
151
152 private:
153 // Show a NetworkConfigView modal dialog instance.
154 void ShowNetworkConfigView(NetworkConfigView* view) const;
155
156 void ActivateCellular(const CellularNetwork* cellular) const;
157 void ShowOther(ConnectionType type) const;
158 void ShowOtherCellular() const;
159
160 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel);
161 };
162 39
163 // Menu for network menu button in the status area/welcome screen. 40 // Menu for network menu button in the status area/welcome screen.
164 // This class will populating the menu with the list of networks. 41 // This class will populating the menu with the list of networks.
165 // It will also handle connecting to another wifi/cellular network. 42 // It will also handle connecting to another wifi/cellular network.
166 // 43 //
167 // The network menu looks like this: 44 // The network menu looks like this:
168 // 45 //
169 // <icon> Ethernet 46 // <icon> Ethernet
170 // <icon> Wifi Network A 47 // <icon> Wifi Network A
171 // <icon> Wifi Network B 48 // <icon> Wifi Network B
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // |icon| must be non-NULL. 126 // |icon| must be non-NULL.
250 // If one of the |bottom_right_badge| or |top_left_badge| or 127 // If one of the |bottom_right_badge| or |top_left_badge| or
251 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the 128 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the
252 // icon. 129 // icon.
253 static SkBitmap IconForDisplay(const SkBitmap* icon, 130 static SkBitmap IconForDisplay(const SkBitmap* icon,
254 const SkBitmap* bottom_right_badge, 131 const SkBitmap* bottom_right_badge,
255 const SkBitmap* top_left_badge, 132 const SkBitmap* top_left_badge,
256 const SkBitmap* bottom_left_badge); 133 const SkBitmap* bottom_left_badge);
257 134
258 protected: 135 protected:
136 virtual views::MenuButton* GetMenuButton() = 0;
259 virtual gfx::NativeWindow GetNativeWindow() const = 0; 137 virtual gfx::NativeWindow GetNativeWindow() const = 0;
260 virtual void OpenButtonOptions() = 0; 138 virtual void OpenButtonOptions() = 0;
261 virtual bool ShouldOpenButtonOptions() const = 0; 139 virtual bool ShouldOpenButtonOptions() const = 0;
262 140
263 // Notify subclasses that connection to |network| was initiated. 141 // Notify subclasses that connection to |network| was initiated.
264 virtual void OnConnectNetwork(const Network* network, 142 virtual void OnConnectNetwork(const Network* network,
265 SkBitmap selected_icon_) {} 143 SkBitmap selected_icon_) {}
266 144
267 // Shows network details in Web UI options window. 145 // Shows network details in Web UI options window.
268 void ShowTabbedNetworkSettings(const Network* network) const; 146 void ShowTabbedNetworkSettings(const Network* network) const;
269 147
270 // Update the menu (e.g. when the network list or status has changed). 148 // Update the menu (e.g. when the network list or status has changed).
271 void UpdateMenu(); 149 void UpdateMenu();
272 150
273 private: 151 private:
274 friend class NetworkMenuModel; 152 friend class NetworkMenuModel;
153 friend class NetworkMenuTaskProxy;
154
155 // Performs the actual work of UpdateMenu().
156 void UpdateMenuImpl();
275 157
276 // views::ViewMenuDelegate implementation. 158 // views::ViewMenuDelegate implementation.
277 virtual void RunMenu(views::View* source, const gfx::Point& pt); 159 virtual void RunMenu(views::View* source, const gfx::Point& pt);
278 160
279 // Set to true if we are currently refreshing the menu. 161 // Set to true if we are currently refreshing the menu.
280 bool refreshing_menu_; 162 bool refreshing_menu_;
281 163
282 // The number of bars images for representing network strength. 164 // The number of bars images for representing network strength.
283 static const int kNumBarsImages; 165 static const int kNumBarsImages;
284 166
285 // Bars image resources. 167 // Bars image resources.
286 static const int kBarsImages[]; 168 static const int kBarsImages[];
287 static const int kBarsImagesBlack[]; 169 static const int kBarsImagesBlack[];
288 static const int kBarsImagesOrange[]; 170 static const int kBarsImagesOrange[];
289 // TODO(chocobo): Add this back when we decide to do colored bars again. 171 // TODO(chocobo): Add this back when we decide to do colored bars again.
290 // static const int kBarsImagesVLowData[]; 172 // static const int kBarsImagesVLowData[];
291 173
292 // The number of animating images for network connecting. 174 // The number of animating images for network connecting.
293 static const int kNumAnimatingImages; 175 static const int kNumAnimatingImages;
294 // Animation images. These are created lazily. 176 // Animation images. These are created lazily.
295 static SkBitmap kAnimatingImages[]; 177 static SkBitmap kAnimatingImages[];
296 static SkBitmap kAnimatingImagesBlack[]; 178 static SkBitmap kAnimatingImagesBlack[];
297 179
298 // The network menu. 180 // The network menu.
299 scoped_ptr<views::Menu2> network_menu_; 181 scoped_ptr<views::MenuItemView> network_menu_;
300
301 scoped_ptr<NetworkMenuModel> main_menu_model_; 182 scoped_ptr<NetworkMenuModel> main_menu_model_;
302 183
303 // Holds minimum width or -1 if it wasn't set up. 184 // Reference-counted proxy object for passing to PostTask.
185 scoped_refptr<NetworkMenuTaskProxy> network_menu_task_proxy_;
186
187 // Holds minimum width of the menu.
304 int min_width_; 188 int min_width_;
305 189
306 // If true, call into the settings UI for network configuration dialogs. 190 // If true, call into the settings UI for network configuration dialogs.
307 bool use_settings_ui_; 191 bool use_settings_ui_;
308 192
309 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); 193 DISALLOW_COPY_AND_ASSIGN(NetworkMenu);
310 }; 194 };
311 195
312 } // namespace chromeos 196 } // namespace chromeos
313 197
314 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ 198 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698