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

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

Issue 3166028: Replace network combobox with network dropdown button (Closed)
Patch Set: Removed trailing spaces Created 10 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
11
12 #include "chrome/browser/chromeos/options/network_config_view.h"
13 #include "gfx/native_widget_types.h"
14 #include "views/controls/menu/menu_2.h"
15 #include "views/controls/menu/view_menu_delegate.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
17
18 namespace gfx {
19 class Canvas;
20 }
21
22 namespace chromeos {
23
24 // Menu for network menu button in the status area/welcome screen.
25 // This class will populating the menu with the list of networks.
26 // It will also handle connecting to another wifi/cellular network.
27 //
28 // The network menu looks like this:
29 //
30 // <icon> Ethernet
31 // <icon> Wifi Network A
32 // <icon> Wifi Network B
33 // <icon> Wifi Network C
34 // <icon> Cellular Network A
35 // <icon> Cellular Network B
36 // <icon> Cellular Network C
37 // <icon> Other...
38 // --------------------------------
39 // Disable Wifi
40 // Disable Celluar
41 // --------------------------------
42 // <IP Address>
43 // Network settings...
44 //
45 // <icon> will show the strength of the wifi/cellular networks.
46 // The label will be BOLD if the network is currently connected.
47 class NetworkMenu : public views::ViewMenuDelegate,
48 public menus::MenuModel {
49 public:
50 NetworkMenu();
51 virtual ~NetworkMenu();
52
53 // menus::MenuModel implementation.
54 virtual bool HasIcons() const { return true; }
55 virtual int GetItemCount() const;
56 virtual menus::MenuModel::ItemType GetTypeAt(int index) const;
57 virtual int GetCommandIdAt(int index) const { return index; }
58 virtual string16 GetLabelAt(int index) const;
59 virtual bool IsLabelDynamicAt(int index) const { return true; }
60 virtual const gfx::Font* GetLabelFontAt(int index) const;
61 virtual bool GetAcceleratorAt(int index,
62 menus::Accelerator* accelerator) const { return false; }
63 virtual bool IsItemCheckedAt(int index) const;
64 virtual int GetGroupIdAt(int index) const { return 0; }
65 virtual bool GetIconAt(int index, SkBitmap* icon) const;
66 virtual menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const {
67 return NULL;
68 }
69 virtual bool IsEnabledAt(int index) const;
70 virtual menus::MenuModel* GetSubmenuModelAt(int index) const { return NULL; }
71 virtual void HighlightChangedTo(int index) {}
72 virtual void ActivatedAt(int index);
73 virtual void MenuWillShow() {}
74
75 void SetFirstLevelMenuWidth(int width);
76
77 void set_menu_offset(int delta_x, int delta_y) {
78 delta_x_ = delta_x;
79 delta_y_ = delta_y;
80 }
81
82 // Cancels the active menu.
83 void CancelMenu();
84
85 // Returns the Icon for a network strength between 0 and 100.
86 // |black| is used to specify whether to return a black icon for display
87 // on a light background or a white icon for display on a dark background.
88 static SkBitmap IconForNetworkStrength(int strength, bool black);
89
90 // This method will convert the |icon| bitmap to the correct size for display.
91 // If the |badge| icon is not empty, it will draw that on top of the icon.
92 static SkBitmap IconForDisplay(SkBitmap icon, SkBitmap badge);
93
94 protected:
95 virtual bool IsBrowserMode() const = 0;
96 virtual gfx::NativeWindow GetNativeWindow() const = 0;
97 virtual void OpenButtonOptions() const = 0;
98 virtual bool ShouldOpenButtonOptions() const = 0;
99
100 // Notify subclasses that connection to |network| was initiated.
101 virtual void OnConnectNetwork(const Network& network,
102 SkBitmap selected_icon_) {}
103
104 private:
105 enum MenuItemFlags {
106 FLAG_DISABLED = 1 << 0,
107 FLAG_TOGGLE_ETHERNET = 1 << 1,
108 FLAG_TOGGLE_WIFI = 1 << 2,
109 FLAG_TOGGLE_CELLULAR = 1 << 3,
110 FLAG_TOGGLE_OFFLINE = 1 << 4,
111 FLAG_ASSOCIATED = 1 << 5,
112 FLAG_ETHERNET = 1 << 6,
113 FLAG_WIFI = 1 << 7,
114 FLAG_CELLULAR = 1 << 8,
115 FLAG_OPTIONS = 1 << 9,
116 FLAG_OTHER_NETWORK = 1 << 10,
117 };
118
119 struct MenuItem {
120 MenuItem()
121 : type(menus::MenuModel::TYPE_SEPARATOR),
122 flags(0) {}
123 MenuItem(menus::MenuModel::ItemType type, string16 label, SkBitmap icon,
124 const std::string& wireless_path, int flags)
125 : type(type),
126 label(label),
127 icon(icon),
128 wireless_path(wireless_path),
129 flags(flags) {}
130
131 menus::MenuModel::ItemType type;
132 string16 label;
133 SkBitmap icon;
134 std::string wireless_path;
135 int flags;
136 };
137 typedef std::vector<MenuItem> MenuItemVector;
138
139 // views::ViewMenuDelegate implementation.
140 virtual void RunMenu(views::View* source, const gfx::Point& pt);
141
142 // Called by RunMenu to initialize our list of menu items.
143 void InitMenuItems();
144
145 // Set to true if we are currently refreshing the menu.
146 bool refreshing_menu_;
147
148 // The number of wifi strength images.
149 static const int kNumWifiImages;
150
151 // Our menu items.
152 MenuItemVector menu_items_;
153
154 // The network menu.
155 views::Menu2 network_menu_;
156
157 int delta_x_, delta_y_;
158
159 DISALLOW_COPY_AND_ASSIGN(NetworkMenu);
160 };
161
162 } // namespace chromeos
163
164 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_dropdown_button.cc ('k') | chrome/browser/chromeos/status/network_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698