OLD | NEW |
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 Loading... |
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 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); | 37 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
38 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | 38 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); |
39 } | 39 } |
40 | 40 |
41 NetworkDropdownButton::~NetworkDropdownButton() { | 41 NetworkDropdownButton::~NetworkDropdownButton() { |
42 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | 42 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(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 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); | 65 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
66 } | 66 } |
67 | 67 |
68 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
69 // NetworkDropdownButton, NetworkLibrary::NetworkManagerObserver implementation: | 69 // NetworkDropdownButton, NetworkLibrary::Observer implementation: |
70 | 70 |
71 void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) { | 71 void NetworkDropdownButton::NetworkChanged(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 active network, if any | 81 // Always show the higher priority connection first. Ethernet then wifi. |
82 const Network* active_network = cros->active_network(); | 82 if (cros->ethernet_connected()) { |
83 const WirelessNetwork* wireless; | |
84 if (active_network != NULL) { | |
85 animation_connecting_.Stop(); | 83 animation_connecting_.Stop(); |
86 if (active_network->type() == TYPE_ETHERNET) { | 84 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); |
87 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); | 85 SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); |
88 SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); | 86 } else if (cros->wifi_connected()) { |
89 } else { | 87 animation_connecting_.Stop(); |
90 DCHECK(active_network->type() == TYPE_WIFI || | 88 SetIcon(IconForNetworkStrength( |
91 active_network->type() == TYPE_CELLULAR); | 89 cros->wifi_network()->strength(), true)); |
92 wireless = static_cast<const WirelessNetwork*>(active_network); | 90 SetText(ASCIIToWide(cros->wifi_network()->name())); |
93 SetIcon(IconForNetworkStrength(wireless->strength(), false)); | 91 } else if (cros->cellular_connected()) { |
94 SetText(ASCIIToWide(wireless->name())); | 92 animation_connecting_.Stop(); |
95 } | 93 SetIcon(IconForNetworkStrength( |
| 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 |
102 if (cros->wifi_connecting()) | 103 if (cros->wifi_connecting()) |
103 SetText(ASCIIToWide(cros->wifi_network()->name())); | 104 SetText(ASCIIToWide(cros->wifi_network()->name())); |
104 else if (cros->cellular_connecting()) | 105 else if (cros->cellular_connecting()) |
105 SetText(ASCIIToWide(cros->cellular_network()->name())); | 106 SetText(ASCIIToWide(cros->cellular_network()->name())); |
106 } | 107 } |
107 | 108 |
108 if (!cros->Connected() && !cros->Connecting()) { | 109 if (!cros->Connected() && !cros->Connecting()) { |
109 animation_connecting_.Stop(); | 110 animation_connecting_.Stop(); |
110 SetIcon(SkBitmap()); | 111 SetIcon(SkBitmap()); |
111 SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_NONE)); | 112 SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_NONE)); |
112 } | 113 } |
113 } else { | 114 } else { |
114 animation_connecting_.Stop(); | 115 animation_connecting_.Stop(); |
115 SetIcon(SkBitmap()); | 116 SetIcon(SkBitmap()); |
116 SetText(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); | 117 SetText(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE)); |
117 } | 118 } |
118 | 119 |
119 SchedulePaint(); | 120 SchedulePaint(); |
120 } | 121 } |
121 | 122 |
122 } // namespace chromeos | 123 } // namespace chromeos |
OLD | NEW |