Chromium Code Reviews| 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/simple_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/button/menu_button.h" | |
| 17 #include "views/controls/menu/menu_delegate.h" | |
| 16 #include "views/controls/menu/view_menu_delegate.h" | 18 #include "views/controls/menu/view_menu_delegate.h" |
| 17 | 19 |
| 18 namespace gfx { | 20 namespace gfx { |
| 19 class Canvas; | 21 class Canvas; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace views { | |
| 23 class Menu2; | |
| 24 } | |
| 25 | |
| 26 namespace chromeos { | 24 namespace chromeos { |
| 27 | 25 |
| 28 // Menu for network menu button in the status area/welcome screen. | 26 // Menu for network menu button in the status area/welcome screen. |
| 29 // This class will populating the menu with the list of networks. | 27 // This class will populating the menu with the list of networks. |
| 30 // It will also handle connecting to another wifi/cellular network. | 28 // It will also handle connecting to another wifi/cellular network. |
| 31 // | 29 // |
| 32 // The network menu looks like this: | 30 // The network menu looks like this: |
| 33 // | 31 // |
| 34 // <icon> Ethernet | 32 // <icon> Ethernet |
| 35 // <icon> Wifi Network A | 33 // <icon> Wifi Network A |
| 36 // <icon> Wifi Network B | 34 // <icon> Wifi Network B |
| 37 // <icon> Wifi Network C | 35 // <icon> Wifi Network C |
| 38 // <icon> Cellular Network A | 36 // <icon> Cellular Network A |
| 39 // <icon> Cellular Network B | 37 // <icon> Cellular Network B |
| 40 // <icon> Cellular Network C | 38 // <icon> Cellular Network C |
| 41 // <icon> Other... | 39 // <icon> Other... |
| 42 // -------------------------------- | 40 // -------------------------------- |
| 43 // Disable Wifi | 41 // Disable Wifi |
| 44 // Disable Celluar | 42 // Disable Celluar |
| 45 // -------------------------------- | 43 // -------------------------------- |
| 46 // <IP Address> | 44 // <IP Address> |
| 47 // Network settings... | 45 // Network settings... |
| 48 // | 46 // |
| 49 // <icon> will show the strength of the wifi/cellular networks. | 47 // <icon> will show the strength of the wifi/cellular networks. |
| 50 // The label will be BOLD if the network is currently connected. | 48 // The label will be BOLD if the network is currently connected. |
| 51 class NetworkMenu : public views::ViewMenuDelegate, | 49 class NetworkMenu : public views::MenuDelegate, |
| 52 public ui::MenuModel { | 50 public views::ViewMenuDelegate { |
| 53 public: | 51 public: |
| 54 struct NetworkInfo { | 52 struct NetworkInfo { |
| 55 NetworkInfo() : | 53 NetworkInfo() : |
| 56 need_passphrase(false), remembered(true), auto_connect(true) {} | 54 need_passphrase(false), remembered(true), auto_connect(true) {} |
| 57 // "ethernet" | "wifi" | "cellular" | "other". | 55 // "ethernet" | "wifi" | "cellular" | "other". |
| 58 std::string network_type; | 56 std::string network_type; |
| 59 // "connected" | "connecting" | "disconnected" | "error". | 57 // "connected" | "connecting" | "disconnected" | "error". |
| 60 std::string status; | 58 std::string status; |
| 61 // status message or error message, empty if unknown status. | 59 // status message or error message, empty if unknown status. |
| 62 std::string message; | 60 std::string message; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 80 bool GetNetworkAt(int index, NetworkInfo* info) const; | 78 bool GetNetworkAt(int index, NetworkInfo* info) const; |
| 81 | 79 |
| 82 // Connect or reconnect to the network at |index|. | 80 // Connect or reconnect to the network at |index|. |
| 83 // If remember >= 0, set the favorite state of the network. | 81 // If remember >= 0, set the favorite state of the network. |
| 84 // Returns true if a connect occurred (e.g. menu should be closed). | 82 // Returns true if a connect occurred (e.g. menu should be closed). |
| 85 bool ConnectToNetworkAt(int index, | 83 bool ConnectToNetworkAt(int index, |
| 86 const std::string& passphrase, | 84 const std::string& passphrase, |
| 87 const std::string& ssid, | 85 const std::string& ssid, |
| 88 int remember) const; | 86 int remember) const; |
| 89 | 87 |
| 90 // ui::MenuModel implementation. | 88 // views::MenuDelegate implementation |
| 91 virtual bool HasIcons() const { return true; } | 89 virtual std::wstring GetLabel(int id) const; |
|
oshima
2011/04/14 17:27:31
OVERRIDE
rhashimoto
2011/04/14 18:27:04
Done.
| |
| 92 virtual int GetItemCount() const; | 90 virtual const gfx::Font* GetLabelFont(int id) const; |
| 93 virtual ui::MenuModel::ItemType GetTypeAt(int index) const; | 91 virtual bool IsItemChecked(int id) const; |
| 94 virtual int GetCommandIdAt(int index) const { return index; } | 92 virtual bool IsCommandEnabled(int id) const; |
| 95 virtual string16 GetLabelAt(int index) const; | 93 virtual void ExecuteCommand(int id); |
| 96 virtual bool IsItemDynamicAt(int index) const { return true; } | |
| 97 virtual const gfx::Font* GetLabelFontAt(int index) const; | |
| 98 virtual bool GetAcceleratorAt(int index, | |
| 99 ui::Accelerator* accelerator) const { return false; } | |
| 100 virtual bool IsItemCheckedAt(int index) const; | |
| 101 virtual int GetGroupIdAt(int index) const { return 0; } | |
| 102 virtual bool GetIconAt(int index, SkBitmap* icon); | |
| 103 virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { | |
| 104 return NULL; | |
| 105 } | |
| 106 virtual bool IsEnabledAt(int index) const; | |
| 107 virtual ui::MenuModel* GetSubmenuModelAt(int index) const { return NULL; } | |
| 108 virtual void HighlightChangedTo(int index) {} | |
| 109 virtual void ActivatedAt(int index); | |
| 110 virtual void MenuWillShow() {} | |
| 111 virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
| 112 | 94 |
| 113 void SetFirstLevelMenuWidth(int width); | 95 void SetFirstLevelMenuWidth(int width); |
| 114 | 96 |
| 115 // Cancels the active menu. | 97 // Cancels the active menu. |
| 116 void CancelMenu(); | 98 void CancelMenu(); |
| 117 | 99 |
| 118 // The following methods returns pointer to a shared instance of the SkBitmap. | 100 // The following methods returns pointer to a shared instance of the SkBitmap. |
| 119 // This shared bitmap is owned by the resource bundle and should not be freed. | 101 // This shared bitmap is owned by the resource bundle and should not be freed. |
| 120 | 102 |
| 121 // Returns the Icon for a network strength for a WifiNetwork |wifi|. | 103 // Returns the Icon for a network strength for a WifiNetwork |wifi|. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 // This method will convert the |icon| bitmap to the correct size for display. | 136 // This method will convert the |icon| bitmap to the correct size for display. |
| 155 // |icon| must be non-NULL. | 137 // |icon| must be non-NULL. |
| 156 // If one of the |bottom_right_badge| or |top_left_badge| icons are not NULL, | 138 // If one of the |bottom_right_badge| or |top_left_badge| icons are not NULL, |
| 157 // they will be drawn on top of the icon. | 139 // they will be drawn on top of the icon. |
| 158 static SkBitmap IconForDisplay(const SkBitmap* icon, | 140 static SkBitmap IconForDisplay(const SkBitmap* icon, |
| 159 const SkBitmap* bottom_right_badge, | 141 const SkBitmap* bottom_right_badge, |
| 160 const SkBitmap* top_left_badge); | 142 const SkBitmap* top_left_badge); |
| 161 | 143 |
| 162 protected: | 144 protected: |
| 163 virtual bool IsBrowserMode() const = 0; | 145 virtual bool IsBrowserMode() const = 0; |
| 146 virtual views::MenuButton* GetMenuButton() = 0; | |
| 164 virtual gfx::NativeWindow GetNativeWindow() const = 0; | 147 virtual gfx::NativeWindow GetNativeWindow() const = 0; |
| 165 virtual void OpenButtonOptions() = 0; | 148 virtual void OpenButtonOptions() = 0; |
| 166 virtual bool ShouldOpenButtonOptions() const = 0; | 149 virtual bool ShouldOpenButtonOptions() const = 0; |
| 167 | 150 |
| 168 // Notify subclasses that connection to |network| was initiated. | 151 // Notify subclasses that connection to |network| was initiated. |
| 169 virtual void OnConnectNetwork(const Network* network, | 152 virtual void OnConnectNetwork(const Network* network, |
| 170 SkBitmap selected_icon_) {} | 153 SkBitmap selected_icon_) {} |
| 171 // Update the menu (e.g. when the network list or status has changed). | 154 // Update the menu (e.g. when the network list or status has changed). |
| 172 void UpdateMenu(); | 155 void UpdateMenu(); |
| 173 | 156 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 // The number of animating images for network connecting. | 221 // The number of animating images for network connecting. |
| 239 static const int kNumAnimatingImages; | 222 static const int kNumAnimatingImages; |
| 240 // Animation images. These are created lazily. | 223 // Animation images. These are created lazily. |
| 241 static SkBitmap kAnimatingImages[]; | 224 static SkBitmap kAnimatingImages[]; |
| 242 static SkBitmap kAnimatingImagesBlack[]; | 225 static SkBitmap kAnimatingImagesBlack[]; |
| 243 | 226 |
| 244 // Our menu items. | 227 // Our menu items. |
| 245 MenuItemVector menu_items_; | 228 MenuItemVector menu_items_; |
| 246 | 229 |
| 247 // The network menu. | 230 // The network menu. |
| 248 scoped_ptr<views::Menu2> network_menu_; | 231 scoped_ptr<views::MenuItemView> network_menu_; |
| 249 | 232 |
| 250 // Holds minimum width or -1 if it wasn't set up. | 233 // Holds minimum width or -1 if it wasn't set up. |
| 251 int min_width_; | 234 int min_width_; |
| 252 | 235 |
| 253 // If true, call into the settings UI for network configuration dialogs. | 236 // If true, call into the settings UI for network configuration dialogs. |
| 254 bool use_settings_ui_; | 237 bool use_settings_ui_; |
| 255 | 238 |
| 256 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); | 239 DISALLOW_COPY_AND_ASSIGN(NetworkMenu); |
| 257 }; | 240 }; |
| 258 | 241 |
| 259 } // namespace chromeos | 242 } // namespace chromeos |
| 260 | 243 |
| 261 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ | 244 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_ |
| OLD | NEW |