OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ |
6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ | 6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "app/throb_animation.h" | 9 #include "app/throb_animation.h" |
13 #include "base/timer.h" | 10 #include "base/timer.h" |
14 #include "chrome/browser/chromeos/cros/network_library.h" | 11 #include "chrome/browser/chromeos/cros/network_library.h" |
15 #include "chrome/browser/chromeos/options/network_config_view.h" | 12 #include "chrome/browser/chromeos/status/network_menu.h" |
16 #include "chrome/browser/chromeos/status/status_area_button.h" | 13 #include "chrome/browser/chromeos/status/status_area_button.h" |
17 #include "views/controls/menu/menu_2.h" | |
18 #include "views/controls/menu/view_menu_delegate.h" | |
19 | |
20 class SkBitmap; | |
21 | 14 |
22 namespace gfx { | 15 namespace gfx { |
23 class Canvas; | 16 class Canvas; |
24 } | 17 } |
25 | 18 |
26 namespace chromeos { | 19 namespace chromeos { |
27 | 20 |
28 class StatusAreaHost; | 21 class StatusAreaHost; |
29 | 22 |
30 // The network menu button in the status area. | 23 // The network menu button in the status area. |
(...skipping 14 matching lines...) Expand all Loading... |
45 // -------------------------------- | 38 // -------------------------------- |
46 // Disable Wifi | 39 // Disable Wifi |
47 // Disable Celluar | 40 // Disable Celluar |
48 // -------------------------------- | 41 // -------------------------------- |
49 // <IP Address> | 42 // <IP Address> |
50 // Network settings... | 43 // Network settings... |
51 // | 44 // |
52 // <icon> will show the strength of the wifi/cellular networks. | 45 // <icon> will show the strength of the wifi/cellular networks. |
53 // The label will be BOLD if the network is currently connected. | 46 // The label will be BOLD if the network is currently connected. |
54 class NetworkMenuButton : public StatusAreaButton, | 47 class NetworkMenuButton : public StatusAreaButton, |
55 public views::ViewMenuDelegate, | 48 public NetworkMenu, |
56 public menus::MenuModel, | |
57 public NetworkLibrary::Observer { | 49 public NetworkLibrary::Observer { |
58 public: | 50 public: |
59 explicit NetworkMenuButton(StatusAreaHost* host); | 51 explicit NetworkMenuButton(StatusAreaHost* host); |
60 virtual ~NetworkMenuButton(); | 52 virtual ~NetworkMenuButton(); |
61 | 53 |
62 // menus::MenuModel implementation. | |
63 virtual bool HasIcons() const { return true; } | |
64 virtual int GetItemCount() const; | |
65 virtual menus::MenuModel::ItemType GetTypeAt(int index) const; | |
66 virtual int GetCommandIdAt(int index) const { return index; } | |
67 virtual string16 GetLabelAt(int index) const; | |
68 virtual bool IsLabelDynamicAt(int index) const { return true; } | |
69 virtual const gfx::Font* GetLabelFontAt(int index) const; | |
70 virtual bool GetAcceleratorAt(int index, | |
71 menus::Accelerator* accelerator) const { return false; } | |
72 virtual bool IsItemCheckedAt(int index) const; | |
73 virtual int GetGroupIdAt(int index) const { return 0; } | |
74 virtual bool GetIconAt(int index, SkBitmap* icon) const; | |
75 virtual menus::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const { | |
76 return NULL; | |
77 } | |
78 virtual bool IsEnabledAt(int index) const; | |
79 virtual menus::MenuModel* GetSubmenuModelAt(int index) const { return NULL; } | |
80 virtual void HighlightChangedTo(int index) {} | |
81 virtual void ActivatedAt(int index); | |
82 virtual void MenuWillShow() {} | |
83 | |
84 // AnimationDelegate implementation. | 54 // AnimationDelegate implementation. |
85 virtual void AnimationProgressed(const Animation* animation); | 55 virtual void AnimationProgressed(const Animation* animation); |
86 | 56 |
87 // NetworkLibrary::Observer implementation. | 57 // NetworkLibrary::Observer implementation. |
88 virtual void NetworkChanged(NetworkLibrary* obj); | 58 virtual void NetworkChanged(NetworkLibrary* obj); |
89 | 59 |
90 // Returns the Icon for a network strength between 0 and 100. | |
91 // |black| is used to specify whether to return a black icon for display | |
92 // on a light background or a white icon for display on a dark background. | |
93 static SkBitmap IconForNetworkStrength(int strength, bool black); | |
94 | |
95 // This method will convert the |icon| bitmap to the correct size for display. | |
96 // If the |badge| icon is not empty, it will draw that on top of the icon. | |
97 static SkBitmap IconForDisplay(SkBitmap icon, SkBitmap badge); | |
98 | |
99 // Sets the badge icon. | 60 // Sets the badge icon. |
100 void SetBadge(const SkBitmap& badge); | 61 void SetBadge(const SkBitmap& badge); |
101 SkBitmap badge() const { return badge_; } | 62 SkBitmap badge() const { return badge_; } |
102 | 63 |
103 protected: | 64 protected: |
104 // StatusAreaButton implementation. | 65 // StatusAreaButton implementation. |
105 virtual void DrawPressed(gfx::Canvas* canvas); | 66 virtual void DrawPressed(gfx::Canvas* canvas); |
106 virtual void DrawIcon(gfx::Canvas* canvas); | 67 virtual void DrawIcon(gfx::Canvas* canvas); |
107 | 68 |
| 69 // NetworkMenu implementation: |
| 70 virtual bool IsBrowserMode() const; |
| 71 virtual gfx::NativeWindow GetNativeWindow() const; |
| 72 virtual void OpenButtonOptions() const; |
| 73 virtual bool ShouldOpenButtonOptions() const; |
| 74 |
108 private: | 75 private: |
109 enum MenuItemFlags { | |
110 FLAG_DISABLED = 1 << 0, | |
111 FLAG_TOGGLE_ETHERNET = 1 << 1, | |
112 FLAG_TOGGLE_WIFI = 1 << 2, | |
113 FLAG_TOGGLE_CELLULAR = 1 << 3, | |
114 FLAG_TOGGLE_OFFLINE = 1 << 4, | |
115 FLAG_ASSOCIATED = 1 << 5, | |
116 FLAG_ETHERNET = 1 << 6, | |
117 FLAG_WIFI = 1 << 7, | |
118 FLAG_CELLULAR = 1 << 8, | |
119 FLAG_OPTIONS = 1 << 9, | |
120 FLAG_OTHER_NETWORK = 1 << 10, | |
121 }; | |
122 | |
123 struct MenuItem { | |
124 MenuItem() | |
125 : type(menus::MenuModel::TYPE_SEPARATOR), | |
126 flags(0) {} | |
127 MenuItem(menus::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
128 const std::string& wireless_path, int flags) | |
129 : type(type), | |
130 label(label), | |
131 icon(icon), | |
132 wireless_path(wireless_path), | |
133 flags(flags) {} | |
134 | |
135 menus::MenuModel::ItemType type; | |
136 string16 label; | |
137 SkBitmap icon; | |
138 std::string wireless_path; | |
139 int flags; | |
140 }; | |
141 typedef std::vector<MenuItem> MenuItemVector; | |
142 | |
143 // views::ViewMenuDelegate implementation. | |
144 virtual void RunMenu(views::View* source, const gfx::Point& pt); | |
145 | |
146 // Called by RunMenu to initialize our list of menu items. | |
147 void InitMenuItems(); | |
148 | |
149 // Set to true if we are currently refreshing the menu. | |
150 bool refreshing_menu_; | |
151 | |
152 // The number of wifi strength images. | |
153 static const int kNumWifiImages; | |
154 | |
155 // Our menu items. | |
156 MenuItemVector menu_items_; | |
157 | |
158 // The status area host, | 76 // The status area host, |
159 StatusAreaHost* host_; | 77 StatusAreaHost* host_; |
160 | 78 |
161 // The network menu. | |
162 views::Menu2 network_menu_; | |
163 | |
164 // A badge icon displayed on top of the icon. | 79 // A badge icon displayed on top of the icon. |
165 SkBitmap badge_; | 80 SkBitmap badge_; |
166 | 81 |
167 // The throb animation that does the wifi connecting animation. | 82 // The throb animation that does the wifi connecting animation. |
168 ThrobAnimation animation_connecting_; | 83 ThrobAnimation animation_connecting_; |
169 | 84 |
170 // The duration of the icon throbbing in milliseconds. | 85 // The duration of the icon throbbing in milliseconds. |
171 static const int kThrobDuration; | 86 static const int kThrobDuration; |
172 | 87 |
173 DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); | 88 DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); |
174 }; | 89 }; |
175 | 90 |
176 } // namespace chromeos | 91 } // namespace chromeos |
177 | 92 |
178 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ | 93 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ |
OLD | NEW |