Chromium Code Reviews

Side by Side Diff: chrome/browser/chromeos/status/network_menu_button.cc

Issue 1142005: Mocks for all libcros elements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "chrome/browser/chromeos/status/network_menu_button.h" 5 #include "chrome/browser/chromeos/status/network_menu_button.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/browser/chromeos/cros/cros_library.h"
12 #include "chrome/browser/chromeos/options/network_config_view.h" 13 #include "chrome/browser/chromeos/options/network_config_view.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/status/status_area_host.h" 14 #include "chrome/browser/chromeos/status/status_area_host.h"
15 #include "gfx/canvas.h" 15 #include "gfx/canvas.h"
16 #include "gfx/skbitmap_operations.h" 16 #include "gfx/skbitmap_operations.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
19 #include "views/widget/widget.h" 19 #include "views/widget/widget.h"
20 #include "views/window/window.h" 20 #include "views/window/window.h"
21 21
22 namespace chromeos { 22 namespace chromeos {
23 23
24 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
25 // NetworkMenuButton 25 // NetworkMenuButton
26 26
27 // static 27 // static
28 const int NetworkMenuButton::kNumWifiImages = 9; 28 const int NetworkMenuButton::kNumWifiImages = 9;
29 const int NetworkMenuButton::kThrobDuration = 1000; 29 const int NetworkMenuButton::kThrobDuration = 1000;
30 30
31 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) 31 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
32 : StatusAreaButton(this), 32 : StatusAreaButton(this),
33 host_(host), 33 host_(host),
34 ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)), 34 ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)),
35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { 35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) {
36 animation_connecting_.SetThrobDuration(kThrobDuration); 36 animation_connecting_.SetThrobDuration(kThrobDuration);
37 animation_connecting_.SetTweenType(SlideAnimation::NONE); 37 animation_connecting_.SetTweenType(SlideAnimation::NONE);
38 NetworkChanged(NetworkLibrary::Get()); 38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
39 NetworkLibrary::Get()->AddObserver(this); 39 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
40 } 40 }
41 41
42 NetworkMenuButton::~NetworkMenuButton() { 42 NetworkMenuButton::~NetworkMenuButton() {
43 NetworkLibrary::Get()->RemoveObserver(this); 43 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
44 } 44 }
45 45
46 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
47 // NetworkMenuButton, menus::MenuModel implementation: 47 // NetworkMenuButton, menus::MenuModel implementation:
48 48
49 int NetworkMenuButton::GetItemCount() const { 49 int NetworkMenuButton::GetItemCount() const {
50 return static_cast<int>(menu_items_.size()); 50 return static_cast<int>(menu_items_.size());
51 } 51 }
52 52
53 menus::MenuModel::ItemType NetworkMenuButton::GetTypeAt(int index) const { 53 menus::MenuModel::ItemType NetworkMenuButton::GetTypeAt(int index) const {
(...skipping 25 matching lines...)
79 79
80 bool NetworkMenuButton::IsEnabledAt(int index) const { 80 bool NetworkMenuButton::IsEnabledAt(int index) const {
81 return !(menu_items_[index].flags & FLAG_DISABLED); 81 return !(menu_items_[index].flags & FLAG_DISABLED);
82 } 82 }
83 83
84 void NetworkMenuButton::ActivatedAt(int index) { 84 void NetworkMenuButton::ActivatedAt(int index) {
85 // When we are refreshing the menu, ignore menu item activation. 85 // When we are refreshing the menu, ignore menu item activation.
86 if (refreshing_menu_) 86 if (refreshing_menu_)
87 return; 87 return;
88 88
89 NetworkLibrary* cros = NetworkLibrary::Get(); 89 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
90 int flags = menu_items_[index].flags; 90 int flags = menu_items_[index].flags;
91 if (flags & FLAG_OPTIONS) { 91 if (flags & FLAG_OPTIONS) {
92 host_->OpenButtonOptions(this); 92 host_->OpenButtonOptions(this);
93 } else if (flags & FLAG_TOGGLE_ETHERNET) { 93 } else if (flags & FLAG_TOGGLE_ETHERNET) {
94 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled()); 94 cros->EnableEthernetNetworkDevice(!cros->ethernet_enabled());
95 } else if (flags & FLAG_TOGGLE_WIFI) { 95 } else if (flags & FLAG_TOGGLE_WIFI) {
96 cros->EnableWifiNetworkDevice(!cros->wifi_enabled()); 96 cros->EnableWifiNetworkDevice(!cros->wifi_enabled());
97 } else if (flags & FLAG_TOGGLE_CELLULAR) { 97 } else if (flags & FLAG_TOGGLE_CELLULAR) {
98 cros->EnableCellularNetworkDevice(!cros->cellular_enabled()); 98 cros->EnableCellularNetworkDevice(!cros->cellular_enabled());
99 } else if (flags & FLAG_TOGGLE_OFFLINE) { 99 } else if (flags & FLAG_TOGGLE_OFFLINE) {
(...skipping 77 matching lines...)
177 MenuButton::AnimationProgressed(animation); 177 MenuButton::AnimationProgressed(animation);
178 } 178 }
179 } 179 }
180 180
181 //////////////////////////////////////////////////////////////////////////////// 181 ////////////////////////////////////////////////////////////////////////////////
182 // NetworkMenuButton, StatusAreaButton implementation: 182 // NetworkMenuButton, StatusAreaButton implementation:
183 183
184 void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) { 184 void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) {
185 // If ethernet connected and not current connecting, then show ethernet 185 // If ethernet connected and not current connecting, then show ethernet
186 // pressed icon. Otherwise, show the bars pressed icon. 186 // pressed icon. Otherwise, show the bars pressed icon.
187 if (NetworkLibrary::Get()->ethernet_connected() && 187 if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() &&
188 !animation_connecting_.IsAnimating()) 188 !animation_connecting_.IsAnimating())
189 canvas->DrawBitmapInt(IconForDisplay( 189 canvas->DrawBitmapInt(IconForDisplay(
190 *ResourceBundle::GetSharedInstance(). 190 *ResourceBundle::GetSharedInstance().
191 GetBitmapNamed(IDR_STATUSBAR_NETWORK_WIRED_PRESSED), SkBitmap()), 191 GetBitmapNamed(IDR_STATUSBAR_NETWORK_WIRED_PRESSED), SkBitmap()),
192 0, 0); 192 0, 0);
193 else 193 else
194 canvas->DrawBitmapInt(IconForDisplay( 194 canvas->DrawBitmapInt(IconForDisplay(
195 *ResourceBundle::GetSharedInstance(). 195 *ResourceBundle::GetSharedInstance().
196 GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS_PRESSED), SkBitmap()), 196 GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS_PRESSED), SkBitmap()),
197 0, 0); 197 0, 0);
198 } 198 }
199 199
200 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { 200 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
201 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 0, 0); 201 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 0, 0);
202 } 202 }
203 203
204 // Override the DrawIcon method to draw the wifi icon. 204 // Override the DrawIcon method to draw the wifi icon.
205 // The wifi icon is composed of 1 or more alpha-blended icons to show the 205 // The wifi icon is composed of 1 or more alpha-blended icons to show the
206 // network strength. We also draw an animation for when there's upload/download 206 // network strength. We also draw an animation for when there's upload/download
207 // traffic. 207 // traffic.
208 /* TODO(chocobo): Add this code back in when UI is finalized. 208 /* TODO(chocobo): Add this code back in when UI is finalized.
209 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { 209 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
210 210
211 // First draw the base icon. 211 // First draw the base icon.
212 canvas->DrawBitmapInt(icon(), 0, 0); 212 canvas->DrawBitmapInt(icon(), 0, 0);
213 213
214 // If wifi, we draw the wifi signal bars. 214 // If wifi, we draw the wifi signal bars.
215 NetworkLibrary* cros = NetworkLibrary::Get(); 215 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
216 if (cros->wifi_connecting() || 216 if (cros->wifi_connecting() ||
217 (!cros->ethernet_connected() && cros->wifi_connected())) { 217 (!cros->ethernet_connected() && cros->wifi_connected())) {
218 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 218 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
219 // We want a value between 0-1. 219 // We want a value between 0-1.
220 // 0 reperesents no signal and 1 represents full signal strength. 220 // 0 reperesents no signal and 1 represents full signal strength.
221 double value = cros->wifi_connecting() ? 221 double value = cros->wifi_connecting() ?
222 animation_connecting_.GetCurrentValue() : 222 animation_connecting_.GetCurrentValue() :
223 cros->wifi_strength() / 100.0; 223 cros->wifi_strength() / 100.0;
224 if (value < 0) 224 if (value < 0)
225 value = 0; 225 value = 0;
(...skipping 63 matching lines...)
289 0, 0, paint); 289 0, 0, paint);
290 } 290 }
291 } 291 }
292 } 292 }
293 */ 293 */
294 //////////////////////////////////////////////////////////////////////////////// 294 ////////////////////////////////////////////////////////////////////////////////
295 // NetworkMenuButton, NetworkLibrary::Observer implementation: 295 // NetworkMenuButton, NetworkLibrary::Observer implementation:
296 296
297 void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { 297 void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
298 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 298 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
299 if (CrosLibrary::EnsureLoaded()) { 299 if (CrosLibrary::Get()->EnsureLoaded()) {
300 if (cros->wifi_connecting() || cros->cellular_connecting()) { 300 if (cros->wifi_connecting() || cros->cellular_connecting()) {
301 // Start the connecting animation if not running. 301 // Start the connecting animation if not running.
302 if (!animation_connecting_.IsAnimating()) { 302 if (!animation_connecting_.IsAnimating()) {
303 animation_connecting_.Reset(); 303 animation_connecting_.Reset();
304 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max()); 304 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max());
305 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1)); 305 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1));
306 } 306 }
307 } else { 307 } else {
308 // Stop connecting animation since we are not connecting. 308 // Stop connecting animation since we are not connecting.
309 animation_connecting_.Stop(); 309 animation_connecting_.Stop();
(...skipping 78 matching lines...)
388 if (!badge.empty()) 388 if (!badge.empty())
389 canvas.DrawBitmapInt(badge, kBadgeX, kBadgeY); 389 canvas.DrawBitmapInt(badge, kBadgeX, kBadgeY);
390 return canvas.ExtractBitmap(); 390 return canvas.ExtractBitmap();
391 } 391 }
392 392
393 //////////////////////////////////////////////////////////////////////////////// 393 ////////////////////////////////////////////////////////////////////////////////
394 // NetworkMenuButton, views::ViewMenuDelegate implementation: 394 // NetworkMenuButton, views::ViewMenuDelegate implementation:
395 395
396 void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { 396 void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
397 refreshing_menu_ = true; 397 refreshing_menu_ = true;
398 NetworkLibrary::Get()->RequestWifiScan(); 398 CrosLibrary::Get()->GetNetworkLibrary()->RequestWifiScan();
399 InitMenuItems(); 399 InitMenuItems();
400 network_menu_.Rebuild(); 400 network_menu_.Rebuild();
401 network_menu_.UpdateStates(); 401 network_menu_.UpdateStates();
402 refreshing_menu_ = false; 402 refreshing_menu_ = false;
403 network_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 403 network_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
404 } 404 }
405 405
406 void NetworkMenuButton::InitMenuItems() { 406 void NetworkMenuButton::InitMenuItems() {
407 menu_items_.clear(); 407 menu_items_.clear();
408 // Populate our MenuItems with the current list of wifi networks. 408 // Populate our MenuItems with the current list of wifi networks.
409 NetworkLibrary* cros = NetworkLibrary::Get(); 409 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
410 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 410 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
411 411
412 // Ethernet 412 // Ethernet
413 string16 label = l10n_util::GetStringUTF16( 413 string16 label = l10n_util::GetStringUTF16(
414 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); 414 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
415 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK); 415 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
416 SkBitmap badge = cros->ethernet_connecting() || cros->ethernet_connected() ? 416 SkBitmap badge = cros->ethernet_connecting() || cros->ethernet_connected() ?
417 SkBitmap() : *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED); 417 SkBitmap() : *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED);
418 int flag = (cros->ethernet_connecting() || cros->ethernet_connected()) ? 418 int flag = (cros->ethernet_connecting() || cros->ethernet_connected()) ?
419 FLAG_ETHERNET | FLAG_ASSOCIATED : FLAG_ETHERNET; 419 FLAG_ETHERNET | FLAG_ASSOCIATED : FLAG_ETHERNET;
(...skipping 92 matching lines...)
512 if (host_->ShouldOpenButtonOptions(this)) { 512 if (host_->ShouldOpenButtonOptions(this)) {
513 label = 513 label =
514 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); 514 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG);
515 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, 515 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
516 SkBitmap(), WifiNetwork(), CellularNetwork(), FLAG_OPTIONS)); 516 SkBitmap(), WifiNetwork(), CellularNetwork(), FLAG_OPTIONS));
517 } 517 }
518 } 518 }
519 } 519 }
520 520
521 } // namespace chromeos 521 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/language_menu_button.cc ('k') | chrome/browser/chromeos/status/power_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine