summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
authorchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 01:00:20 +0000
committerchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-09 01:00:20 +0000
commit93be709bf1fb20f800ad65d4c95b97370d70f033 (patch)
tree40a59d23239114f3ee36792ff5ff779565399d59 /chrome/browser/chromeos
parent00e4e5f0f9e3e5df3f075acaa21b166c5960450a (diff)
downloadchromium_src-93be709bf1fb20f800ad65d4c95b97370d70f033.zip
chromium_src-93be709bf1fb20f800ad65d4c95b97370d70f033.tar.gz
chromium_src-93be709bf1fb20f800ad65d4c95b97370d70f033.tar.bz2
Implement animation using ThrobAnimation.
Fix so that we show ethernet icon if connected even if wifi is connected. BUG=23923 TEST=none Review URL: http://codereview.chromium.org/262031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/network_menu_button.cc87
-rw-r--r--chrome/browser/chromeos/network_menu_button.h25
-rw-r--r--chrome/browser/chromeos/power_menu_button.cc6
3 files changed, 46 insertions, 72 deletions
diff --git a/chrome/browser/chromeos/network_menu_button.cc b/chrome/browser/chromeos/network_menu_button.cc
index bf8e74c..46853ba 100644
--- a/chrome/browser/chromeos/network_menu_button.cc
+++ b/chrome/browser/chromeos/network_menu_button.cc
@@ -4,10 +4,11 @@
#include "chrome/browser/chromeos/network_menu_button.h"
+#include <limits>
+
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/string_util.h"
-#include "base/time.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
#include "grit/generated_resources.h"
@@ -20,16 +21,17 @@
// static
const int NetworkMenuButton::kNumWifiImages = 8;
-const int NetworkMenuButton::kAnimationDelayMillis = 100;
+const int NetworkMenuButton::kThrobDuration = 1000;
NetworkMenuButton::NetworkMenuButton(Browser* browser)
: MenuButton(NULL, std::wstring(), this, false),
refreshing_menu_(false),
- network_menu_(this),
+ ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)),
browser_(browser),
- icon_animation_index_(0),
- icon_animation_increasing_(true) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)) {
SetShowHighlighted(false);
+ animation_.SetThrobDuration(kThrobDuration);
+ animation_.SetTweenType(SlideAnimation::NONE);
UpdateIcon();
CrosNetworkLibrary::Get()->AddObserver(this);
}
@@ -113,6 +115,16 @@ bool NetworkMenuButton::OnPasswordDialogAccept(const std::string& ssid,
}
////////////////////////////////////////////////////////////////////////////////
+// NetworkMenuButton, AnimationDelegate implementation:
+
+void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
+ if (animation == &animation_)
+ UpdateIcon();
+ else
+ MenuButton::AnimationProgressed(animation);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, views::ViewMenuDelegate implementation:
void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt,
@@ -129,61 +141,34 @@ void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt,
// NetworkMenuButton, CrosNetworkLibrary::Observer implementation:
void NetworkMenuButton::NetworkChanged(CrosNetworkLibrary* obj) {
- if (CrosNetworkLibrary::Get()->wifi_connecting()) {
- StartConnectingAnimation();
- } else {
- StopConnectingAnimation();
- UpdateIcon();
- }
-}
-
-void NetworkMenuButton::StartConnectingAnimation() {
- if (!timer_.IsRunning()) {
- icon_animation_index_ = 0;
- icon_animation_increasing_ = true;
- timer_.Start(base::TimeDelta::FromMilliseconds(kAnimationDelayMillis), this,
- &NetworkMenuButton::UpdateIcon);
- }
-}
-
-void NetworkMenuButton::StopConnectingAnimation() {
- if (timer_.IsRunning()) {
- timer_.Stop();
- }
+ UpdateIcon();
}
void NetworkMenuButton::UpdateIcon() {
CrosNetworkLibrary* cros = CrosNetworkLibrary::Get();
int id = IDR_STATUSBAR_DISCONNECTED;
if (cros->wifi_connecting()) {
- // Get the next frame. Reverse direction if necessary.
- if (icon_animation_increasing_) {
- icon_animation_index_++;
- if (icon_animation_index_ >= kNumWifiImages) {
- icon_animation_index_ = kNumWifiImages - 1;
- icon_animation_increasing_ = false;
- }
- } else {
- icon_animation_index_--;
- if (icon_animation_index_ < 0) {
- icon_animation_index_ = 0;
- icon_animation_increasing_ = true;
- }
- }
- id = IDR_STATUSBAR_WIFI_1 + icon_animation_index_;
+ // Start the connecting animation if not running.
+ if (!animation_.IsAnimating())
+ animation_.StartThrobbing(std::numeric_limits<int>::max());
+
+ // We need to map the value of 0-1 in the animation to 0 - kNumWifiImages-1.
+ int index = static_cast<int>(animation_.GetCurrentValue() *
+ nextafter(static_cast<float>(kNumWifiImages), 0));
+ id = IDR_STATUSBAR_WIFI_1 + index;
} else {
- if (cros->wifi_ssid().empty()) {
- if (cros->ethernet_connected())
- id = IDR_STATUSBAR_WIRED;
- else
- id = IDR_STATUSBAR_DISCONNECTED;
- } else {
+ // Stop connecting animation since we are not connecting.
+ if (animation_.IsAnimating())
+ animation_.Stop();
+
+ // Always show the higher priority connection first. So ethernet then wifi.
+ if (cros->ethernet_connected()) {
+ id = IDR_STATUSBAR_WIRED;
+ } else if (!cros->wifi_ssid().empty()) {
// Gets the wifi image of 1-8 bars depending on signal strength. Signal
// strength is from 0 to 100, so we need to convert that to 0 to 7.
- int index = floor(cros->wifi_strength() / (100.0 / kNumWifiImages));
- // This can happen if the signal strength is 100.
- if (index == kNumWifiImages)
- index--;
+ int index = static_cast<int>(cros->wifi_strength() / 100.0 *
+ nextafter(static_cast<float>(kNumWifiImages), 0));
id = IDR_STATUSBAR_WIFI_1 + index;
}
}
diff --git a/chrome/browser/chromeos/network_menu_button.h b/chrome/browser/chromeos/network_menu_button.h
index 6f6fe38..7247325 100644
--- a/chrome/browser/chromeos/network_menu_button.h
+++ b/chrome/browser/chromeos/network_menu_button.h
@@ -7,6 +7,7 @@
#include <string>
+#include "app/throb_animation.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros_network_library.h"
#include "chrome/browser/chromeos/password_dialog_view.h"
@@ -53,6 +54,9 @@ class NetworkMenuButton : public views::MenuButton,
virtual bool OnPasswordDialogAccept(const std::string& ssid,
const string16& password);
+ // AnimationDelegate implementation.
+ virtual void AnimationProgressed(const Animation* animation);
+
// CrosNetworkLibrary::Observer implementation.
virtual void NetworkChanged(CrosNetworkLibrary* obj);
@@ -61,12 +65,6 @@ class NetworkMenuButton : public views::MenuButton,
virtual void RunMenu(views::View* source, const gfx::Point& pt,
gfx::NativeView hwnd);
- // Start animating the icon to show that we are connecting to a network.
- void StartConnectingAnimation();
-
- // Stop animating the icon and set the appropriate icon.
- void StopConnectingAnimation();
-
// Update the icon to either the connecting, connected, or disconnected icon.
void UpdateIcon();
@@ -88,18 +86,11 @@ class NetworkMenuButton : public views::MenuButton,
// The browser window that owns us.
Browser* browser_;
- // TODO(chocobo): Look into replacing our own animation with throb_animation.
- // A timer for animating the icon when we are connecting.
- base::RepeatingTimer<NetworkMenuButton> timer_;
-
- // Current frame of the animated connecting icon.
- int icon_animation_index_;
-
- // Whether the next frame for the animated connecting icon is increasing.
- bool icon_animation_increasing_;
+ // The throb animation that does the wifi connecting animation.
+ ThrobAnimation animation_;
- // The number of milliseconds between frames of animated connecting icon..
- static const int kAnimationDelayMillis;
+ // The duration of the wifi connecting icon throbbing in milliseconds.
+ static const int kThrobDuration;
DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
};
diff --git a/chrome/browser/chromeos/power_menu_button.cc b/chrome/browser/chromeos/power_menu_button.cc
index cdf6999..e2dd205 100644
--- a/chrome/browser/chromeos/power_menu_button.cc
+++ b/chrome/browser/chromeos/power_menu_button.cc
@@ -111,10 +111,8 @@ void PowerMenuButton::UpdateIcon() {
cros->battery_percentage();
// Gets the power image depending on battery percentage. Percentage is
// from 0 to 100, so we need to convert that to 0 to kNumPowerImages - 1.
- int index = floor(percent / (100.0 / kNumPowerImages));
- // This can happen if the battery is 100% full.
- if (index == kNumPowerImages)
- index--;
+ int index = static_cast<int>(percent / 100.0 *
+ nextafter(static_cast<float>(kNumPowerImages), 0));
if (cros->line_power_on())
id = IDR_STATUSBAR_BATTERY_CHARGING_1 + index;
else