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

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: Tweak menu vertical spacing. 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
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 38
163 // Menu for network menu button in the status area/welcome screen. 39 // Menu for network menu button in the status area/welcome screen.
164 // This class will populating the menu with the list of networks. 40 // This class will populating the menu with the list of networks.
165 // It will also handle connecting to another wifi/cellular network. 41 // It will also handle connecting to another wifi/cellular network.
166 // 42 //
167 // The network menu looks like this: 43 // The network menu looks like this:
168 // 44 //
169 // <icon> Ethernet 45 // <icon> Ethernet
170 // <icon> Wifi Network A 46 // <icon> Wifi Network A
171 // <icon> Wifi Network B 47 // <icon> Wifi Network B
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // |icon| must be non-NULL. 125 // |icon| must be non-NULL.
250 // If one of the |bottom_right_badge| or |top_left_badge| or 126 // 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 127 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the
252 // icon. 128 // icon.
253 static SkBitmap IconForDisplay(const SkBitmap* icon, 129 static SkBitmap IconForDisplay(const SkBitmap* icon,
254 const SkBitmap* bottom_right_badge, 130 const SkBitmap* bottom_right_badge,
255 const SkBitmap* top_left_badge, 131 const SkBitmap* top_left_badge,
256 const SkBitmap* bottom_left_badge); 132 const SkBitmap* bottom_left_badge);
257 133
258 protected: 134 protected:
135 virtual views::MenuButton* GetMenuButton() = 0;
259 virtual gfx::NativeWindow GetNativeWindow() const = 0; 136 virtual gfx::NativeWindow GetNativeWindow() const = 0;
260 virtual void OpenButtonOptions() = 0; 137 virtual void OpenButtonOptions() = 0;
261 virtual bool ShouldOpenButtonOptions() const = 0; 138 virtual bool ShouldOpenButtonOptions() const = 0;
262 139
263 // Notify subclasses that connection to |network| was initiated. 140 // Notify subclasses that connection to |network| was initiated.
264 virtual void OnConnectNetwork(const Network* network, 141 virtual void OnConnectNetwork(const Network* network,
265 SkBitmap selected_icon_) {} 142 SkBitmap selected_icon_) {}
266 143
267 // Shows network details in Web UI options window. 144 // Shows network details in Web UI options window.
268 void ShowTabbedNetworkSettings(const Network* network) const; 145 void ShowTabbedNetworkSettings(const Network* network) const;
(...skipping 20 matching lines...) Expand all
289 // TODO(chocobo): Add this back when we decide to do colored bars again. 166 // TODO(chocobo): Add this back when we decide to do colored bars again.
290 // static const int kBarsImagesVLowData[]; 167 // static const int kBarsImagesVLowData[];
291 168
292 // The number of animating images for network connecting. 169 // The number of animating images for network connecting.
293 static const int kNumAnimatingImages; 170 static const int kNumAnimatingImages;
294 // Animation images. These are created lazily. 171 // Animation images. These are created lazily.
295 static SkBitmap kAnimatingImages[]; 172 static SkBitmap kAnimatingImages[];
296 static SkBitmap kAnimatingImagesBlack[]; 173 static SkBitmap kAnimatingImagesBlack[];
297 174
298 // The network menu. 175 // The network menu.
299 scoped_ptr<views::Menu2> network_menu_; 176 scoped_ptr<views::MenuItemView> network_menu_;
300 177
301 scoped_ptr<NetworkMenuModel> main_menu_model_; 178 scoped_ptr<NetworkMenuModel> main_menu_model_;
302 179
303 // Holds minimum width or -1 if it wasn't set up. 180 // Holds minimum width of the menu.
304 int min_width_; 181 int min_width_;
305 182
306 // If true, call into the settings UI for network configuration dialogs. 183 // If true, call into the settings UI for network configuration dialogs.
307 bool use_settings_ui_; 184 bool use_settings_ui_;
308 185
309 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); 186 DISALLOW_COPY_AND_ASSIGN(NetworkMenu);
310 }; 187 };
311 188
312 } // namespace chromeos 189 } // namespace chromeos
313 190
314 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ 191 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698