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

Side by Side Diff: chrome/browser/chromeos/network_menu_button.h

Issue 251099: Refactor cros library code into central location and have the UI elements obs... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
OLDNEW
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_NETWORK_MENU_BUTTON_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
6 #define CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_ 6 #define CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
10 9
11 #include "base/timer.h" 10 #include "base/timer.h"
11 #include "chrome/browser/chromeos/cros_network_library.h"
12 #include "chrome/browser/chromeos/password_dialog_view.h" 12 #include "chrome/browser/chromeos/password_dialog_view.h"
13 #include "third_party/cros/chromeos_network.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "views/controls/button/menu_button.h" 13 #include "views/controls/button/menu_button.h"
16 #include "views/controls/menu/menu_2.h" 14 #include "views/controls/menu/menu_2.h"
17 #include "views/controls/menu/view_menu_delegate.h" 15 #include "views/controls/menu/view_menu_delegate.h"
18 16
19 class Browser; 17 class Browser;
20 18 class SkBitmap;
21 struct WifiNetwork {
22 WifiNetwork() : encrypted(false), strength(0) { }
23 WifiNetwork(const std::string& ssid, bool encrypted,
24 chromeos::EncryptionType encryption, int strength)
25 : ssid(ssid),
26 encrypted(encrypted),
27 encryption(encryption),
28 strength(strength) { }
29
30 // WifiNetworks are sorted by ssids.
31 bool operator< (const WifiNetwork& other) const {
32 return ssid < other.ssid;
33 }
34
35 std::string ssid;
36 bool encrypted;
37 chromeos::EncryptionType encryption;
38 int strength;
39 };
40 typedef std::vector<WifiNetwork> WifiNetworkVector;
41 19
42 // The network menu button in the status area. 20 // The network menu button in the status area.
43 // This class will handle getting the wifi networks and populating the menu. 21 // This class will handle getting the wifi networks and populating the menu.
44 // It will also handle the status icon changing and connecting to another 22 // It will also handle the status icon changing and connecting to another
45 // wifi network. 23 // wifi network.
46 class NetworkMenuButton : public views::MenuButton, 24 class NetworkMenuButton : public views::MenuButton,
47 public views::ViewMenuDelegate, 25 public views::ViewMenuDelegate,
48 public views::Menu2Model, 26 public views::Menu2Model,
49 public PasswordDialogDelegate { 27 public PasswordDialogDelegate,
28 public CrosNetworkLibrary::Observer {
50 public: 29 public:
51 NetworkMenuButton(Browser* browser, bool cros_library_loaded); 30 explicit NetworkMenuButton(Browser* browser);
52 virtual ~NetworkMenuButton() {} 31 virtual ~NetworkMenuButton();
53 32
54 // views::Menu2Model implementation. 33 // views::Menu2Model implementation.
55 virtual bool HasIcons() const { return false; } 34 virtual bool HasIcons() const { return false; }
56 virtual int GetItemCount() const; 35 virtual int GetItemCount() const;
57 virtual views::Menu2Model::ItemType GetTypeAt(int index) const; 36 virtual views::Menu2Model::ItemType GetTypeAt(int index) const;
58 virtual int GetCommandIdAt(int index) const { return index; } 37 virtual int GetCommandIdAt(int index) const { return index; }
59 virtual string16 GetLabelAt(int index) const; 38 virtual string16 GetLabelAt(int index) const;
60 virtual bool IsLabelDynamicAt(int index) const { return true; } 39 virtual bool IsLabelDynamicAt(int index) const { return true; }
61 virtual bool GetAcceleratorAt(int index, 40 virtual bool GetAcceleratorAt(int index,
62 views::Accelerator* accelerator) const { return false; } 41 views::Accelerator* accelerator) const { return false; }
63 virtual bool IsItemCheckedAt(int index) const; 42 virtual bool IsItemCheckedAt(int index) const;
64 virtual int GetGroupIdAt(int index) const { return 0; } 43 virtual int GetGroupIdAt(int index) const { return 0; }
65 virtual bool GetIconAt(int index, SkBitmap* icon) const { return false; } 44 virtual bool GetIconAt(int index, SkBitmap* icon) const { return false; }
66 virtual bool IsEnabledAt(int index) const; 45 virtual bool IsEnabledAt(int index) const;
67 virtual Menu2Model* GetSubmenuModelAt(int index) const { return NULL; } 46 virtual Menu2Model* GetSubmenuModelAt(int index) const { return NULL; }
68 virtual void HighlightChangedTo(int index) {} 47 virtual void HighlightChangedTo(int index) {}
69 virtual void ActivatedAt(int index); 48 virtual void ActivatedAt(int index);
70 virtual void MenuWillShow() {} 49 virtual void MenuWillShow() {}
71 50
72 // PasswordDialogDelegate implementation. 51 // PasswordDialogDelegate implementation.
73 virtual bool OnPasswordDialogCancel() { return true; } 52 virtual bool OnPasswordDialogCancel() { return true; }
74 virtual bool OnPasswordDialogAccept(const std::string& ssid, 53 virtual bool OnPasswordDialogAccept(const std::string& ssid,
75 const string16& password); 54 const string16& password);
76 55
56 // CrosNetworkLibrary::Observer implementation.
57 virtual void NetworkChanged(CrosNetworkLibrary* obj);
58
77 private: 59 private:
78 // views::ViewMenuDelegate implementation. 60 // views::ViewMenuDelegate implementation.
79 virtual void RunMenu(views::View* source, const gfx::Point& pt, 61 virtual void RunMenu(views::View* source, const gfx::Point& pt,
80 gfx::NativeView hwnd); 62 gfx::NativeView hwnd);
81 63
82 // Gets the WifiNetwork for the given ssid in the list of wifi networks.
83 // Returns whether or not WifiNetwork was found.
84 bool GetWifiNetwork(const WifiNetworkVector& networks,
85 const std::string& ssid,
86 WifiNetwork* network);
87
88 // Helper method to add a wifi network to the model.
89 void AddWifiNetwork(const std::string& ssid, bool encrypted,
90 chromeos::EncryptionType encryption, int strength);
91
92 // Refreshes the networks model using real data.
93 void RefreshNetworks();
94
95 // Connect to the specified wireless network with password.
96 // Returns whether or not connection was successful.
97 bool ConnectToWifiNetwork(const std::string& ssid, const string16& password);
98
99 // Start animating the icon to show that we are connecting to a network. 64 // Start animating the icon to show that we are connecting to a network.
100 void StartConnectingAnimation(); 65 void StartConnectingAnimation();
101 66
102 // Stop animating the icon and set the appropriate icon. 67 // Stop animating the icon and set the appropriate icon.
103 void StopConnectingAnimation(); 68 void StopConnectingAnimation();
104 69
105 // Update the icon to either the connecting, connected, or disconnected icon. 70 // Update the icon to either the connecting, connected, or disconnected icon.
106 void UpdateIcon(); 71 void UpdateIcon();
107 72
108 // Whether or not the cros shared library loaded successfully or not.
109 bool cros_library_loaded_;
110
111 // Set to true if we are currently refreshing the menu. 73 // Set to true if we are currently refreshing the menu.
112 bool refreshing_menu_; 74 bool refreshing_menu_;
113 75
114 // The number of wifi strength images. 76 // The number of wifi strength images.
115 static const int kNumWifiImages; 77 static const int kNumWifiImages;
116 78
117 // Wifi strength images.
118 static SkBitmap* wifi_images_[];
119
120 // Wired image.
121 static SkBitmap* wired_image_;
122
123 // Disconnected image.
124 static SkBitmap* disconnected_image_;
125
126 // Whether or not ethernet is connected.
127 bool ethernet_connected_;
128
129 // The currently connected wifi network ssid.
130 std::string current_ssid_;
131
132 // The wifi netowrk ssid we are attempting to connect to.
133 std::string connecting_ssid_;
134
135 // A list of wifi networks. 79 // A list of wifi networks.
136 WifiNetworkVector wifi_networks_; 80 WifiNetworkVector wifi_networks_;
137 81
138 // A list of wifi networks that we are currently showing in the menu. 82 // The activated wifi network.
139 WifiNetworkVector wifi_networks_in_menu_; 83 WifiNetwork activated_wifi_network_;
140 84
141 // The network menu. 85 // The network menu.
142 views::Menu2 network_menu_; 86 views::Menu2 network_menu_;
143 87
144 // The browser window that owns us. 88 // The browser window that owns us.
145 Browser* browser_; 89 Browser* browser_;
146 90
147 // TODO(chocobo): Look into replacing our own animation with throb_animation. 91 // TODO(chocobo): Look into replacing our own animation with throb_animation.
148 // A timer for animating the icon when we are connecting. 92 // A timer for animating the icon when we are connecting.
149 base::RepeatingTimer<NetworkMenuButton> timer_; 93 base::RepeatingTimer<NetworkMenuButton> timer_;
150 94
151 // Current frame of the animated connecting icon. 95 // Current frame of the animated connecting icon.
152 int icon_animation_index_; 96 int icon_animation_index_;
153 97
154 // Whether the next frame for the animated connecting icon is increasing. 98 // Whether the next frame for the animated connecting icon is increasing.
155 bool icon_animation_increasing_; 99 bool icon_animation_increasing_;
156 100
157 // The number of milliseconds between frames of animated connecting icon.. 101 // The number of milliseconds between frames of animated connecting icon..
158 static const int kAnimationDelayMillis; 102 static const int kAnimationDelayMillis;
159 103
160 DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); 104 DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
161 }; 105 };
162 106
163 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_ 107 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros_power_library.cc ('k') | chrome/browser/chromeos/network_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698