| 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_menu_button.h" | 5 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
| 25 // NetworkMenuButton | 25 // NetworkMenuButton |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 const int NetworkMenuButton::kThrobDuration = 1000; | 28 const int NetworkMenuButton::kThrobDuration = 1000; |
| 29 | 29 |
| 30 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) | 30 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) |
| 31 : StatusAreaButton(this), | 31 : StatusAreaButton(this), |
| 32 NetworkMenu(), | 32 NetworkMenu(), |
| 33 host_(host), | 33 host_(host), |
| 34 icon_(NULL), |
| 35 badge_(NULL), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { | 36 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { |
| 35 animation_connecting_.SetThrobDuration(kThrobDuration); | 37 animation_connecting_.SetThrobDuration(kThrobDuration); |
| 36 animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); | 38 animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); |
| 37 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); | 39 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
| 38 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | 40 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); |
| 39 CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this); | 41 CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this); |
| 40 } | 42 } |
| 41 | 43 |
| 42 NetworkMenuButton::~NetworkMenuButton() { | 44 NetworkMenuButton::~NetworkMenuButton() { |
| 43 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 45 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 host_->OpenButtonOptions(this); | 101 host_->OpenButtonOptions(this); |
| 100 } | 102 } |
| 101 | 103 |
| 102 bool NetworkMenuButton::ShouldOpenButtonOptions() const { | 104 bool NetworkMenuButton::ShouldOpenButtonOptions() const { |
| 103 return host_->ShouldOpenButtonOptions(this); | 105 return host_->ShouldOpenButtonOptions(this); |
| 104 } | 106 } |
| 105 | 107 |
| 106 //////////////////////////////////////////////////////////////////////////////// | 108 //////////////////////////////////////////////////////////////////////////////// |
| 107 // NetworkMenuButton, private methods | 109 // NetworkMenuButton, private methods |
| 108 | 110 |
| 109 void NetworkMenuButton::SetIconAndBadge(const SkBitmap& icon, | 111 void NetworkMenuButton::SetIconAndBadge(const SkBitmap* icon, |
| 110 const SkBitmap& badge) { | 112 const SkBitmap* badge) { |
| 111 icon_ = icon; | 113 icon_ = icon; |
| 112 badge_ = badge; | 114 badge_ = badge; |
| 113 SetIcon(IconForDisplay(icon_, badge_)); | 115 SetIcon(IconForDisplay(icon_, badge_)); |
| 114 } | 116 } |
| 115 | 117 |
| 116 void NetworkMenuButton::SetIconOnly(const SkBitmap& icon) { | 118 void NetworkMenuButton::SetIconOnly(const SkBitmap* icon) { |
| 117 icon_ = icon; | 119 icon_ = icon; |
| 118 SetIcon(IconForDisplay(icon_, badge_)); | 120 SetIcon(IconForDisplay(icon_, badge_)); |
| 119 } | 121 } |
| 120 | 122 |
| 121 void NetworkMenuButton::SetBadgeOnly(const SkBitmap& badge) { | 123 void NetworkMenuButton::SetBadgeOnly(const SkBitmap* badge) { |
| 122 badge_ = badge; | 124 badge_ = badge; |
| 123 SetIcon(IconForDisplay(icon_, badge_)); | 125 SetIcon(IconForDisplay(icon_, badge_)); |
| 124 } | 126 } |
| 125 | 127 |
| 126 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros, | 128 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros, |
| 127 const Network* network) { | 129 const Network* network) { |
| 128 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 130 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 129 | 131 |
| 130 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) { | 132 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) { |
| 131 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), | 133 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), |
| 132 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); | 134 rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); |
| 133 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( | 135 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( |
| 134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); | 136 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); |
| 135 return; | 137 return; |
| 136 } | 138 } |
| 137 | 139 |
| 138 if (!cros->Connected() && !cros->Connecting()) { | 140 if (!cros->Connected() && !cros->Connecting()) { |
| 139 animation_connecting_.Stop(); | 141 animation_connecting_.Stop(); |
| 140 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), | 142 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), |
| 141 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); | 143 rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); |
| 142 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( | 144 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( |
| 143 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); | 145 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); |
| 144 return; | 146 return; |
| 145 } | 147 } |
| 146 | 148 |
| 147 if (cros->wifi_connecting() || cros->cellular_connecting()) { | 149 if (cros->wifi_connecting() || cros->cellular_connecting()) { |
| 148 // Start the connecting animation if not running. | 150 // Start the connecting animation if not running. |
| 149 if (!animation_connecting_.is_animating()) { | 151 if (!animation_connecting_.is_animating()) { |
| 150 animation_connecting_.Reset(); | 152 animation_connecting_.Reset(); |
| 151 animation_connecting_.StartThrobbing(-1); | 153 animation_connecting_.StartThrobbing(-1); |
| 152 SetIconOnly(IconForNetworkConnecting(0, false)); | 154 SetIconOnly(IconForNetworkConnecting(0, false)); |
| 153 } | 155 } |
| 154 const WirelessNetwork* wireless = NULL; | 156 const WirelessNetwork* wireless = NULL; |
| 155 if (cros->wifi_connecting()) { | 157 if (cros->wifi_connecting()) { |
| 156 wireless = cros->wifi_network(); | 158 wireless = cros->wifi_network(); |
| 157 SetBadgeOnly(SkBitmap()); | 159 SetBadgeOnly(NULL); |
| 158 } else { // cellular_connecting | 160 } else { // cellular_connecting |
| 159 wireless = cros->cellular_network(); | 161 wireless = cros->cellular_network(); |
| 160 SetBadgeOnly(BadgeForNetworkTechnology(cros->cellular_network())); | 162 SetBadgeOnly(BadgeForNetworkTechnology(cros->cellular_network())); |
| 161 } | 163 } |
| 162 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( | 164 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 163 wireless->configuring() ? IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP | 165 wireless->configuring() ? IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP |
| 164 : IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, | 166 : IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, |
| 165 UTF8ToUTF16(wireless->name())))); | 167 UTF8ToUTF16(wireless->name())))); |
| 166 } else { | 168 } else { |
| 167 // Stop connecting animation since we are not connecting. | 169 // Stop connecting animation since we are not connecting. |
| 168 animation_connecting_.Stop(); | 170 animation_connecting_.Stop(); |
| 169 // Only set the icon, if it is an active network that changed. | 171 // Only set the icon, if it is an active network that changed. |
| 170 if (network && network->is_active()) { | 172 if (network && network->is_active()) { |
| 171 if (network->type() == TYPE_ETHERNET) { | 173 if (network->type() == TYPE_ETHERNET) { |
| 172 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED), SkBitmap()); | 174 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_WIRED), NULL); |
| 173 SetTooltipText( | 175 SetTooltipText( |
| 174 UTF16ToWide(l10n_util::GetStringFUTF16( | 176 UTF16ToWide(l10n_util::GetStringFUTF16( |
| 175 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 177 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 176 l10n_util::GetStringUTF16( | 178 l10n_util::GetStringUTF16( |
| 177 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)))); | 179 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)))); |
| 178 } else if (network->type() == TYPE_WIFI) { | 180 } else if (network->type() == TYPE_WIFI) { |
| 179 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); | 181 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); |
| 180 SetIconAndBadge(IconForNetworkStrength(wifi, false), SkBitmap()); | 182 SetIconAndBadge(IconForNetworkStrength(wifi, false), NULL); |
| 181 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( | 183 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 182 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 184 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 183 UTF8ToUTF16(wifi->name())))); | 185 UTF8ToUTF16(wifi->name())))); |
| 184 } else if (network->type() == TYPE_CELLULAR) { | 186 } else if (network->type() == TYPE_CELLULAR) { |
| 185 const CellularNetwork* cellular = | 187 const CellularNetwork* cellular = |
| 186 static_cast<const CellularNetwork*>(network); | 188 static_cast<const CellularNetwork*>(network); |
| 187 SetIconAndBadge(IconForNetworkStrength(cellular, false), | 189 SetIconAndBadge(IconForNetworkStrength(cellular, false), |
| 188 BadgeForNetworkTechnology(cellular)); | 190 BadgeForNetworkTechnology(cellular)); |
| 189 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( | 191 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( |
| 190 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 192 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 202 cros->RemoveNetworkObserver(active_network_, this); | 204 cros->RemoveNetworkObserver(active_network_, this); |
| 203 } | 205 } |
| 204 if (!new_network.empty()) { | 206 if (!new_network.empty()) { |
| 205 cros->AddNetworkObserver(new_network, this); | 207 cros->AddNetworkObserver(new_network, this); |
| 206 } | 208 } |
| 207 active_network_ = new_network; | 209 active_network_ = new_network; |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 | 212 |
| 211 } // namespace chromeos | 213 } // namespace chromeos |
| OLD | NEW |