| 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 NetworkMenuModel; |
| 29 | |
| 30 class NetworkMenuModel : public ui::MenuModel { | |
| 31 public: | |
| 32 struct NetworkInfo { | |
| 33 NetworkInfo() : | |
| 34 need_passphrase(false), remembered(true), auto_connect(true) {} | |
| 35 // "ethernet" | "wifi" | "cellular" | "other". | |
| 36 std::string network_type; | |
| 37 // "connected" | "connecting" | "disconnected" | "error". | |
| 38 std::string status; | |
| 39 // status message or error message, empty if unknown status. | |
| 40 std::string message; | |
| 41 // IP address (if network is active, empty otherwise) | |
| 42 std::string ip_address; | |
| 43 // Remembered passphrase. | |
| 44 std::string passphrase; | |
| 45 // true if the network requires a passphrase. | |
| 46 bool need_passphrase; | |
| 47 // true if the network is currently remembered. | |
| 48 bool remembered; | |
| 49 // true if the network is auto connect (meaningful for Wifi only). | |
| 50 bool auto_connect; | |
| 51 }; | |
| 52 | |
| 53 explicit NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} | |
| 54 virtual ~NetworkMenuModel() {} | |
| 55 | |
| 56 // Connect or reconnect to the network at |index|. | |
| 57 // If remember >= 0, set the favorite state of the network. | |
| 58 // Returns true if a connect occurred (e.g. menu should be closed). | |
| 59 bool ConnectToNetworkAt(int index, | |
| 60 const std::string& passphrase, | |
| 61 const std::string& ssid, | |
| 62 int remember) const; | |
| 63 | |
| 64 // Called by NetworkMenu::RunMenu to initialize list of menu items. | |
| 65 virtual void InitMenuItems(bool is_browser_mode, | |
| 66 bool should_open_button_options) {} | |
| 67 | |
| 68 // ui::MenuModel implementation. | |
| 69 virtual bool HasIcons() const { return true; } | |
| 70 virtual int GetItemCount() const; | |
| 71 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; | |
| 72 virtual int GetCommandIdAt(int index) const { return index; } | |
| 73 virtual string16 GetLabelAt(int index) const; | |
| 74 virtual bool IsItemDynamicAt(int index) const { return true; } | |
| 75 virtual const gfx::Font* GetLabelFontAt(int index) const; | |
| 76 virtual bool GetAcceleratorAt(int index, | |
| 77 ui::Accelerator* accelerator) const { return false; } | |
| 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 | |
| 91 protected: | |
| 92 enum MenuItemFlags { | |
| 93 FLAG_DISABLED = 1 << 0, | |
| 94 FLAG_TOGGLE_ETHERNET = 1 << 1, | |
| 95 FLAG_TOGGLE_WIFI = 1 << 2, | |
| 96 FLAG_TOGGLE_CELLULAR = 1 << 3, | |
| 97 FLAG_TOGGLE_OFFLINE = 1 << 4, | |
| 98 FLAG_ASSOCIATED = 1 << 5, | |
| 99 FLAG_ETHERNET = 1 << 6, | |
| 100 FLAG_WIFI = 1 << 7, | |
| 101 FLAG_CELLULAR = 1 << 8, | |
| 102 FLAG_PRIVATE_NETWORKS = 1 << 9, | |
| 103 FLAG_OPTIONS = 1 << 10, | |
| 104 FLAG_ADD_WIFI = 1 << 11, | |
| 105 FLAG_ADD_CELLULAR = 1 << 12, | |
| 106 FLAG_VPN = 1 << 13, | |
| 107 FLAG_ADD_VPN = 1 << 14, | |
| 108 FLAG_DISCONNECT_VPN = 1 << 15, | |
| 109 }; | |
| 110 | |
| 111 struct MenuItem { | |
| 112 MenuItem() | |
| 113 : type(ui::MenuModel::TYPE_SEPARATOR), | |
| 114 sub_menu_model(NULL), | |
| 115 flags(0) {} | |
| 116 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 117 const std::string& service_path, int flags) | |
| 118 : type(type), | |
| 119 label(label), | |
| 120 icon(icon), | |
| 121 service_path(service_path), | |
| 122 sub_menu_model(NULL), | |
| 123 flags(flags) {} | |
| 124 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 125 NetworkMenuModel* sub_menu_model, int flags) | |
| 126 : type(type), | |
| 127 label(label), | |
| 128 icon(icon), | |
| 129 sub_menu_model(sub_menu_model), | |
| 130 flags(flags) {} | |
| 131 | |
| 132 ui::MenuModel::ItemType type; | |
| 133 string16 label; | |
| 134 SkBitmap icon; | |
| 135 std::string service_path; | |
| 136 NetworkMenuModel* sub_menu_model; // Weak. | |
| 137 int flags; | |
| 138 }; | |
| 139 typedef std::vector<MenuItem> MenuItemVector; | |
| 140 | |
| 141 // Our menu items. | |
| 142 MenuItemVector menu_items_; | |
| 143 | |
| 144 NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel. | |
| 145 | |
| 146 private: | |
| 147 // Shows network details in Web UI options window. | |
| 148 void ShowTabbedNetworkSettings(const Network* network) const; | |
| 149 | |
| 150 // Show a NetworkConfigView modal dialog instance. | |
| 151 void ShowNetworkConfigView(NetworkConfigView* view) const; | |
| 152 | |
| 153 void ActivateCellular(const CellularNetwork* cellular) const; | |
| 154 void ShowOther(ConnectionType type) const; | |
| 155 void ShowOtherCellular() const; | |
| 156 | |
| 157 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); | |
| 158 }; | |
| 159 | 30 |
| 160 // Menu for network menu button in the status area/welcome screen. | 31 // Menu for network menu button in the status area/welcome screen. |
| 161 // This class will populating the menu with the list of networks. | 32 // This class will populating the menu with the list of networks. |
| 162 // It will also handle connecting to another wifi/cellular network. | 33 // It will also handle connecting to another wifi/cellular network. |
| 163 // | 34 // |
| 164 // The network menu looks like this: | 35 // The network menu looks like this: |
| 165 // | 36 // |
| 166 // <icon> Ethernet | 37 // <icon> Ethernet |
| 167 // <icon> Wifi Network A | 38 // <icon> Wifi Network A |
| 168 // <icon> Wifi Network B | 39 // <icon> Wifi Network B |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // |icon| must be non-NULL. | 117 // |icon| must be non-NULL. |
| 247 // If one of the |bottom_right_badge| or |top_left_badge| or | 118 // 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 | 119 // |bottom_left_badge| icons are not NULL, they will be drawn on top of the |
| 249 // icon. | 120 // icon. |
| 250 static SkBitmap IconForDisplay(const SkBitmap* icon, | 121 static SkBitmap IconForDisplay(const SkBitmap* icon, |
| 251 const SkBitmap* bottom_right_badge, | 122 const SkBitmap* bottom_right_badge, |
| 252 const SkBitmap* top_left_badge, | 123 const SkBitmap* top_left_badge, |
| 253 const SkBitmap* bottom_left_badge); | 124 const SkBitmap* bottom_left_badge); |
| 254 | 125 |
| 255 protected: | 126 protected: |
| 127 virtual views::MenuButton* GetMenuButton() = 0; |
| 256 virtual gfx::NativeWindow GetNativeWindow() const = 0; | 128 virtual gfx::NativeWindow GetNativeWindow() const = 0; |
| 257 virtual void OpenButtonOptions() = 0; | 129 virtual void OpenButtonOptions() = 0; |
| 258 virtual bool ShouldOpenButtonOptions() const = 0; | 130 virtual bool ShouldOpenButtonOptions() const = 0; |
| 259 | 131 |
| 260 // Notify subclasses that connection to |network| was initiated. | 132 // Notify subclasses that connection to |network| was initiated. |
| 261 virtual void OnConnectNetwork(const Network* network, | 133 virtual void OnConnectNetwork(const Network* network, |
| 262 SkBitmap selected_icon_) {} | 134 SkBitmap selected_icon_) {} |
| 263 // Update the menu (e.g. when the network list or status has changed). | 135 // Update the menu (e.g. when the network list or status has changed). |
| 264 void UpdateMenu(); | 136 void UpdateMenu(); |
| 265 | 137 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 282 // TODO(chocobo): Add this back when we decide to do colored bars again. | 154 // TODO(chocobo): Add this back when we decide to do colored bars again. |
| 283 // static const int kBarsImagesVLowData[]; | 155 // static const int kBarsImagesVLowData[]; |
| 284 | 156 |
| 285 // The number of animating images for network connecting. | 157 // The number of animating images for network connecting. |
| 286 static const int kNumAnimatingImages; | 158 static const int kNumAnimatingImages; |
| 287 // Animation images. These are created lazily. | 159 // Animation images. These are created lazily. |
| 288 static SkBitmap kAnimatingImages[]; | 160 static SkBitmap kAnimatingImages[]; |
| 289 static SkBitmap kAnimatingImagesBlack[]; | 161 static SkBitmap kAnimatingImagesBlack[]; |
| 290 | 162 |
| 291 // The network menu. | 163 // The network menu. |
| 292 scoped_ptr<views::Menu2> network_menu_; | 164 scoped_ptr<views::MenuItemView> network_menu_; |
| 293 | 165 |
| 294 scoped_ptr<NetworkMenuModel> main_menu_model_; | 166 scoped_ptr<NetworkMenuModel> main_menu_model_; |
| 295 | 167 |
| 296 // Holds minimum width or -1 if it wasn't set up. | 168 // Holds minimum width or -1 if it wasn't set up. |
| 297 int min_width_; | 169 int min_width_; |
| 298 | 170 |
| 299 // If true, call into the settings UI for network configuration dialogs. | 171 // If true, call into the settings UI for network configuration dialogs. |
| 300 bool use_settings_ui_; | 172 bool use_settings_ui_; |
| 301 | 173 |
| 302 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); | 174 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); |
| 303 }; | 175 }; |
| 304 | 176 |
| 305 } // namespace chromeos | 177 } // namespace chromeos |
| 306 | 178 |
| 307 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ | 179 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ |
| OLD | NEW |