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

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

Issue 4235005: Push for ers:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 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 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_dropdown_button.h" 5 #include "chrome/browser/chromeos/status/network_dropdown_button.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 16 matching lines...) Expand all
27 gfx::NativeWindow parent_window) 27 gfx::NativeWindow parent_window)
28 : MenuButton(NULL, 28 : MenuButton(NULL,
29 l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE), 29 l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE),
30 this, 30 this,
31 true), 31 true),
32 browser_mode_(browser_mode), 32 browser_mode_(browser_mode),
33 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), 33 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
34 parent_window_(parent_window) { 34 parent_window_(parent_window) {
35 animation_connecting_.SetThrobDuration(kThrobDuration); 35 animation_connecting_.SetThrobDuration(kThrobDuration);
36 animation_connecting_.SetTweenType(Tween::LINEAR); 36 animation_connecting_.SetTweenType(Tween::LINEAR);
37 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); 37 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary());
38 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); 38 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
39 } 39 }
40 40
41 NetworkDropdownButton::~NetworkDropdownButton() { 41 NetworkDropdownButton::~NetworkDropdownButton() {
42 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); 42 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this);
43 } 43 }
44 44
45 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
46 // NetworkMenuButton, AnimationDelegate implementation: 46 // NetworkMenuButton, AnimationDelegate implementation:
47 47
48 void NetworkDropdownButton::AnimationProgressed(const Animation* animation) { 48 void NetworkDropdownButton::AnimationProgressed(const Animation* animation) {
49 if (animation == &animation_connecting_) { 49 if (animation == &animation_connecting_) {
50 // Figure out which image to draw. We want a value between 0-100. 50 // Figure out which image to draw. We want a value between 0-100.
51 // 0 represents no signal and 100 represents full signal strength. 51 // 0 represents no signal and 100 represents full signal strength.
52 int value = static_cast<int>(animation_connecting_.GetCurrentValue()*100.0); 52 int value = static_cast<int>(animation_connecting_.GetCurrentValue()*100.0);
53 if (value < 0) 53 if (value < 0)
54 value = 0; 54 value = 0;
55 else if (value > 100) 55 else if (value > 100)
56 value = 100; 56 value = 100;
57 SetIcon(IconForNetworkStrength(value, true)); 57 SetIcon(IconForNetworkStrength(value, true));
58 SchedulePaint(); 58 SchedulePaint();
59 } else { 59 } else {
60 MenuButton::AnimationProgressed(animation); 60 MenuButton::AnimationProgressed(animation);
61 } 61 }
62 } 62 }
63 63
64 void NetworkDropdownButton::Refresh() { 64 void NetworkDropdownButton::Refresh() {
65 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); 65 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary());
66 } 66 }
67 67
68 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
69 // NetworkDropdownButton, NetworkLibrary::Observer implementation: 69 // NetworkDropdownButton, NetworkLibrary::NetworkManagerObserver implementation:
70 70
71 void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) { 71 void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) {
72 // Show network that we will actually use. It could be another network than 72 // Show network that we will actually use. It could be another network than
73 // user selected. For example user selected WiFi network but we have Ethernet 73 // user selected. For example user selected WiFi network but we have Ethernet
74 // connection and Chrome OS device will actually use Ethernet. 74 // connection and Chrome OS device will actually use Ethernet.
75 75
76 // This gets called on initialization, so any changes should be reflected 76 // This gets called on initialization, so any changes should be reflected
77 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). 77 // in CrosMock::SetNetworkLibraryStatusAreaExpectations().
78 78
79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 79 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
80 if (CrosLibrary::Get()->EnsureLoaded()) { 80 if (CrosLibrary::Get()->EnsureLoaded()) {
81 // Always show the higher priority connection first. Ethernet then wifi. 81 // Always show the active network, if any
82 if (cros->ethernet_connected()) { 82 const Network* active_network = cros->active_network();
83 const WirelessNetwork* wireless;
84 if (active_network != NULL) {
83 animation_connecting_.Stop(); 85 animation_connecting_.Stop();
84 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); 86 if (active_network->type() == TYPE_ETHERNET) {
85 SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); 87 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED));
86 } else if (cros->wifi_connected()) { 88 SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET));
87 animation_connecting_.Stop(); 89 } else {
88 SetIcon(IconForNetworkStrength( 90 DCHECK(active_network->type() == TYPE_WIFI ||
89 cros->wifi_network()->strength(), true)); 91 active_network->type() == TYPE_CELLULAR);
90 SetText(ASCIIToWide(cros->wifi_network()->name())); 92 wireless = static_cast<const WirelessNetwork*>(active_network);
91 } else if (cros->cellular_connected()) { 93 SetIcon(IconForNetworkStrength(wireless->strength(), false));
92 animation_connecting_.Stop(); 94 SetText(ASCIIToWide(wireless->name()));
93 SetIcon(IconForNetworkStrength( 95 }
94 cros->cellular_network()->strength(), false));
95 SetText(ASCIIToWide(cros->cellular_network()->name()));
96 } else if (cros->wifi_connecting() || cros->cellular_connecting()) { 96 } else if (cros->wifi_connecting() || cros->cellular_connecting()) {
97 if (!animation_connecting_.is_animating()) { 97 if (!animation_connecting_.is_animating()) {
98 animation_connecting_.Reset(); 98 animation_connecting_.Reset();
99 animation_connecting_.StartThrobbing(-1); 99 animation_connecting_.StartThrobbing(-1);
100 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1_BLACK)); 100 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1_BLACK));
101 } 101 }
102
103 if (cros->wifi_connecting()) 102 if (cros->wifi_connecting())
104 SetText(ASCIIToWide(cros->wifi_network()->name())); 103 SetText(ASCIIToWide(cros->wifi_network()->name()));
105 else if (cros->cellular_connecting()) 104 else if (cros->cellular_connecting())
106 SetText(ASCIIToWide(cros->cellular_network()->name())); 105 SetText(ASCIIToWide(cros->cellular_network()->name()));
107 } 106 }
108 107
109 if (!cros->Connected() && !cros->Connecting()) { 108 if (!cros->Connected() && !cros->Connecting()) {
110 animation_connecting_.Stop(); 109 animation_connecting_.Stop();
111 SetIcon(SkBitmap()); 110 SetIcon(SkBitmap());
112 SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_NONE)); 111 SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_NONE));
113 } 112 }
114 } else { 113 } else {
115 animation_connecting_.Stop(); 114 animation_connecting_.Stop();
116 SetIcon(SkBitmap()); 115 SetIcon(SkBitmap());
117 SetText(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); 116 SetText(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE));
118 } 117 }
119 118
120 SchedulePaint(); 119 SchedulePaint();
121 } 120 }
122 121
123 } // namespace chromeos 122 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_dropdown_button.h ('k') | chrome/browser/chromeos/status/network_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698