| OLD | NEW |
| 1 // Copyright (c) 2009 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 <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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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(Tween::LINEAR); |
| 38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); | 38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
| 39 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); | 39 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 NetworkMenuButton::~NetworkMenuButton() { | 42 NetworkMenuButton::~NetworkMenuButton() { |
| 43 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); | 43 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 47 // NetworkMenuButton, menus::MenuModel implementation: | 47 // NetworkMenuButton, menus::MenuModel implementation: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() && | 187 if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() && |
| 188 !animation_connecting_.IsAnimating()) | 188 !animation_connecting_.is_animating()) |
| 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 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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; |
| 226 else if (value > 1) | 226 else if (value > 1) |
| 227 value = 1; | 227 value = 1; |
| 228 | 228 |
| 229 // If we are animating network traffic and not connecting, then we need to | 229 // If we are animating network traffic and not connecting, then we need to |
| 230 // figure out if we are to also draw the extra image. | 230 // figure out if we are to also draw the extra image. |
| 231 int downloading_index = -1; | 231 int downloading_index = -1; |
| 232 int uploading_index = -1; | 232 int uploading_index = -1; |
| 233 if (!animation_connecting_.IsAnimating()) { | 233 if (!animation_connecting_.is_animating()) { |
| 234 // For network animation, we only show animation in one direction. | 234 // For network animation, we only show animation in one direction. |
| 235 // So when we are hiding, we just use 1 minus the value. | 235 // So when we are hiding, we just use 1 minus the value. |
| 236 // We have kNumWifiImages + 1 number of states. For the first state, where | 236 // We have kNumWifiImages + 1 number of states. For the first state, where |
| 237 // we are not adding any images, we set the index to -1. | 237 // we are not adding any images, we set the index to -1. |
| 238 if (animation_downloading_.IsAnimating()) { | 238 if (animation_downloading_.is_animating()) { |
| 239 double value_downloading = animation_downloading_.IsShowing() ? | 239 double value_downloading = animation_downloading_.IsShowing() ? |
| 240 animation_downloading_.GetCurrentValue() : | 240 animation_downloading_.GetCurrentValue() : |
| 241 1.0 - animation_downloading_.GetCurrentValue(); | 241 1.0 - animation_downloading_.GetCurrentValue(); |
| 242 downloading_index = static_cast<int>(value_downloading * | 242 downloading_index = static_cast<int>(value_downloading * |
| 243 nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1; | 243 nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1; |
| 244 } | 244 } |
| 245 if (animation_uploading_.IsAnimating()) { | 245 if (animation_uploading_.is_animating()) { |
| 246 double value_uploading = animation_uploading_.IsShowing() ? | 246 double value_uploading = animation_uploading_.IsShowing() ? |
| 247 animation_uploading_.GetCurrentValue() : | 247 animation_uploading_.GetCurrentValue() : |
| 248 1.0 - animation_uploading_.GetCurrentValue(); | 248 1.0 - animation_uploading_.GetCurrentValue(); |
| 249 uploading_index = static_cast<int>(value_uploading * | 249 uploading_index = static_cast<int>(value_uploading * |
| 250 nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1; | 250 nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1; |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 // We need to determine opacity for each of the kNumWifiImages images. | 254 // We need to determine opacity for each of the kNumWifiImages images. |
| 255 // We split the range (0-1) into equal ranges per kNumWifiImages images. | 255 // We split the range (0-1) into equal ranges per kNumWifiImages images. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::Get()->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_.is_animating()) { |
| 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(); |
| 310 | 310 |
| 311 // Always show the higher priority connection first. Ethernet then wifi. | 311 // Always show the higher priority connection first. Ethernet then wifi. |
| 312 if (cros->ethernet_connected()) | 312 if (cros->ethernet_connected()) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (host_->ShouldOpenButtonOptions(this)) { | 511 if (host_->ShouldOpenButtonOptions(this)) { |
| 512 label = | 512 label = |
| 513 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); | 513 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); |
| 514 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 514 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
| 515 SkBitmap(), WifiNetwork(), CellularNetwork(), FLAG_OPTIONS)); | 515 SkBitmap(), WifiNetwork(), CellularNetwork(), FLAG_OPTIONS)); |
| 516 } | 516 } |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 | 519 |
| 520 } // namespace chromeos | 520 } // namespace chromeos |
| OLD | NEW |