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 #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/menu_delegate.h" | |
16 #include "views/controls/menu/view_menu_delegate.h" | 17 #include "views/controls/menu/view_menu_delegate.h" |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 class Canvas; | 20 class Canvas; |
20 } | 21 } |
21 | 22 |
22 namespace views { | 23 namespace views { |
23 class Menu2; | 24 class MenuItemView; |
24 } | 25 } |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 | 28 |
28 class NetworkMenu; | 29 class NetworkMenu; |
29 | 30 |
30 class NetworkMenuModel : public ui::MenuModel { | 31 class NetworkMenuModel : public views::MenuDelegate { |
stevenjb
2011/04/21 22:25:31
This should have come up in the CL where this was
rhashimoto
2011/04/21 22:49:58
Done.
| |
31 public: | 32 public: |
32 struct NetworkInfo { | 33 struct NetworkInfo { |
33 NetworkInfo() : | 34 NetworkInfo() : |
34 need_passphrase(false), remembered(true), auto_connect(true) {} | 35 need_passphrase(false), remembered(true), auto_connect(true) {} |
35 // "ethernet" | "wifi" | "cellular" | "other". | 36 // "ethernet" | "wifi" | "cellular" | "other". |
36 std::string network_type; | 37 std::string network_type; |
37 // "connected" | "connecting" | "disconnected" | "error". | 38 // "connected" | "connecting" | "disconnected" | "error". |
38 std::string status; | 39 std::string status; |
39 // status message or error message, empty if unknown status. | 40 // status message or error message, empty if unknown status. |
40 std::string message; | 41 std::string message; |
41 // IP address (if network is active, empty otherwise) | 42 // IP address (if network is active, empty otherwise) |
42 std::string ip_address; | 43 std::string ip_address; |
43 // Remembered passphrase. | 44 // Remembered passphrase. |
44 std::string passphrase; | 45 std::string passphrase; |
45 // true if the network requires a passphrase. | 46 // true if the network requires a passphrase. |
46 bool need_passphrase; | 47 bool need_passphrase; |
47 // true if the network is currently remembered. | 48 // true if the network is currently remembered. |
48 bool remembered; | 49 bool remembered; |
49 // true if the network is auto connect (meaningful for Wifi only). | 50 // true if the network is auto connect (meaningful for Wifi only). |
50 bool auto_connect; | 51 bool auto_connect; |
51 }; | 52 }; |
52 | 53 |
53 explicit NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} | 54 explicit NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} |
54 virtual ~NetworkMenuModel() {} | 55 virtual ~NetworkMenuModel() {} |
55 | 56 |
57 // views::MenuDelegate implementation ---------------------------------------- | |
58 | |
59 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | |
60 virtual bool IsItemChecked(int id) const OVERRIDE; | |
61 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
62 virtual void ExecuteCommand(int id) OVERRIDE; | |
63 | |
56 // Connect or reconnect to the network at |index|. | 64 // Connect or reconnect to the network at |index|. |
57 // If remember >= 0, set the favorite state of the network. | 65 // If remember >= 0, set the favorite state of the network. |
58 // Returns true if a connect occurred (e.g. menu should be closed). | 66 // Returns true if a connect occurred (e.g. menu should be closed). |
59 bool ConnectToNetworkAt(int index, | 67 bool ConnectToNetworkAt(int index, |
60 const std::string& passphrase, | 68 const std::string& passphrase, |
61 const std::string& ssid, | 69 const std::string& ssid, |
62 int remember) const; | 70 int remember) const; |
63 | 71 |
64 // Called by NetworkMenu::RunMenu to initialize list of menu items. | 72 // Called by NetworkMenu::RunMenu to initialize list of menu items. |
65 virtual void InitMenuItems(bool is_browser_mode, | 73 virtual void InitMenuItems(bool is_browser_mode, |
66 bool should_open_button_options) {} | 74 bool should_open_button_options) {} |
67 | 75 |
68 // ui::MenuModel implementation. | 76 // PopulateMenu() clears and reinstalls the menu items defined in this |
69 virtual bool HasIcons() const { return true; } | 77 // instance by calling PopulateMenuItem() on each one. Subclasses with |
70 virtual int GetItemCount() const; | 78 // submenus should override PopulateMenuItem(), deferring to the base |
71 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; | 79 // class implementation for non-submenu items and calling PopulateMenu() |
72 virtual int GetCommandIdAt(int index) const { return index; } | 80 // for the submenu after adding it. |
73 virtual string16 GetLabelAt(int index) const; | 81 virtual void PopulateMenu(views::MenuItemView* menu); |
74 virtual bool IsItemDynamicAt(int index) const { return true; } | 82 virtual void PopulateMenuItem( |
75 virtual const gfx::Font* GetLabelFontAt(int index) const; | 83 views::MenuItemView* menu, |
76 virtual bool GetAcceleratorAt(int index, | 84 int index, |
77 ui::Accelerator* accelerator) const { return false; } | 85 int command_id); |
78 virtual bool IsItemCheckedAt(int index) const; | |
79 virtual int GetGroupIdAt(int index) const { return 0; } | |
80 virtual bool GetIconAt(int index, SkBitmap* icon); | |
81 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { | |
82 return NULL; | |
83 } | |
84 virtual bool IsEnabledAt(int index) const; | |
85 virtual ui::MenuModel* GetSubmenuModelAt(int index) const; | |
86 virtual void HighlightChangedTo(int index) {} | |
87 virtual void ActivatedAt(int index); | |
88 virtual void MenuWillShow() {} | |
89 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
90 | 86 |
91 protected: | 87 protected: |
92 enum MenuItemFlags { | 88 enum MenuItemFlags { |
93 FLAG_DISABLED = 1 << 0, | 89 FLAG_DISABLED = 1 << 0, |
94 FLAG_TOGGLE_ETHERNET = 1 << 1, | 90 FLAG_TOGGLE_ETHERNET = 1 << 1, |
95 FLAG_TOGGLE_WIFI = 1 << 2, | 91 FLAG_TOGGLE_WIFI = 1 << 2, |
96 FLAG_TOGGLE_CELLULAR = 1 << 3, | 92 FLAG_TOGGLE_CELLULAR = 1 << 3, |
97 FLAG_TOGGLE_OFFLINE = 1 << 4, | 93 FLAG_TOGGLE_OFFLINE = 1 << 4, |
98 FLAG_ASSOCIATED = 1 << 5, | 94 FLAG_ASSOCIATED = 1 << 5, |
99 FLAG_ETHERNET = 1 << 6, | 95 FLAG_ETHERNET = 1 << 6, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 // |icon| must be non-NULL. | 242 // |icon| must be non-NULL. |
247 // If one of the |bottom_right_badge| or |top_left_badge| or | 243 // If one of the |bottom_right_badge| or |top_left_badge| or |
248 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the | 244 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the |
249 // icon. | 245 // icon. |
250 static SkBitmap IconForDisplay(const SkBitmap* icon, | 246 static SkBitmap IconForDisplay(const SkBitmap* icon, |
251 const SkBitmap* bottom_right_badge, | 247 const SkBitmap* bottom_right_badge, |
252 const SkBitmap* top_left_badge, | 248 const SkBitmap* top_left_badge, |
253 const SkBitmap* bottom_left_badge); | 249 const SkBitmap* bottom_left_badge); |
254 | 250 |
255 protected: | 251 protected: |
252 virtual views::MenuButton* GetMenuButton() = 0; | |
256 virtual gfx::NativeWindow GetNativeWindow() const = 0; | 253 virtual gfx::NativeWindow GetNativeWindow() const = 0; |
257 virtual void OpenButtonOptions() = 0; | 254 virtual void OpenButtonOptions() = 0; |
258 virtual bool ShouldOpenButtonOptions() const = 0; | 255 virtual bool ShouldOpenButtonOptions() const = 0; |
259 | 256 |
260 // Notify subclasses that connection to |network| was initiated. | 257 // Notify subclasses that connection to |network| was initiated. |
261 virtual void OnConnectNetwork(const Network* network, | 258 virtual void OnConnectNetwork(const Network* network, |
262 SkBitmap selected_icon_) {} | 259 SkBitmap selected_icon_) {} |
263 // Update the menu (e.g. when the network list or status has changed). | 260 // Update the menu (e.g. when the network list or status has changed). |
264 void UpdateMenu(); | 261 void UpdateMenu(); |
265 | 262 |
(...skipping 16 matching lines...) Expand all Loading... | |
282 // TODO(chocobo): Add this back when we decide to do colored bars again. | 279 // TODO(chocobo): Add this back when we decide to do colored bars again. |
283 // static const int kBarsImagesVLowData[]; | 280 // static const int kBarsImagesVLowData[]; |
284 | 281 |
285 // The number of animating images for network connecting. | 282 // The number of animating images for network connecting. |
286 static const int kNumAnimatingImages; | 283 static const int kNumAnimatingImages; |
287 // Animation images. These are created lazily. | 284 // Animation images. These are created lazily. |
288 static SkBitmap kAnimatingImages[]; | 285 static SkBitmap kAnimatingImages[]; |
289 static SkBitmap kAnimatingImagesBlack[]; | 286 static SkBitmap kAnimatingImagesBlack[]; |
290 | 287 |
291 // The network menu. | 288 // The network menu. |
292 scoped_ptr<views::Menu2> network_menu_; | 289 scoped_ptr<views::MenuItemView> network_menu_; |
293 | 290 |
294 scoped_ptr<NetworkMenuModel> main_menu_model_; | 291 scoped_ptr<NetworkMenuModel> main_menu_model_; |
295 | 292 |
296 // Holds minimum width or -1 if it wasn't set up. | 293 // Holds minimum width or -1 if it wasn't set up. |
297 int min_width_; | 294 int min_width_; |
298 | 295 |
299 // If true, call into the settings UI for network configuration dialogs. | 296 // If true, call into the settings UI for network configuration dialogs. |
300 bool use_settings_ui_; | 297 bool use_settings_ui_; |
301 | 298 |
302 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); | 299 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); |
303 }; | 300 }; |
304 | 301 |
305 } // namespace chromeos | 302 } // namespace chromeos |
306 | 303 |
307 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ | 304 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ |
OLD | NEW |