Commit 1f410001 authored by chocobo@google.com's avatar chocobo@google.com

New wifi icons animation.

BUG=none
TEST=25538
Review URL: http://codereview.chromium.org/315008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30318 0039d316-1c4b-4281-b951-d872f2087c98
parent 50c73bd0
...@@ -402,14 +402,20 @@ ...@@ -402,14 +402,20 @@
<include name="IDR_STATUSBAR_BATTERY_DISCHARGING_15" file="statusbar_battery15d.png" type="BINDATA" /> <include name="IDR_STATUSBAR_BATTERY_DISCHARGING_15" file="statusbar_battery15d.png" type="BINDATA" />
<include name="IDR_STATUSBAR_BATTERY_DISCHARGING_16" file="statusbar_battery16d.png" type="BINDATA" /> <include name="IDR_STATUSBAR_BATTERY_DISCHARGING_16" file="statusbar_battery16d.png" type="BINDATA" />
<include name="IDR_STATUSBAR_NETWORK_DISCONNECTED" file="statusbar_network_disconnected.png" type="BINDATA" /> <include name="IDR_STATUSBAR_NETWORK_DISCONNECTED" file="statusbar_network_disconnected.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_1" file="statusbar_wifi_1.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOT" file="statusbar_wifi_dot.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_2" file="statusbar_wifi_2.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN1" file="statusbar_wifi_down1.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_3" file="statusbar_wifi_3.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN2" file="statusbar_wifi_down2.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_4" file="statusbar_wifi_4.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN3" file="statusbar_wifi_down3.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_5" file="statusbar_wifi_5.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN1P" file="statusbar_wifi_down1p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_6" file="statusbar_wifi_6.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN2P" file="statusbar_wifi_down2p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_7" file="statusbar_wifi_7.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_DOWN3P" file="statusbar_wifi_down3p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_8" file="statusbar_wifi_8.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIFI_UP1" file="statusbar_wifi_up1.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_UP2" file="statusbar_wifi_up2.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_UP3" file="statusbar_wifi_up3.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_UP1P" file="statusbar_wifi_up1p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_UP2P" file="statusbar_wifi_up2p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIFI_UP3P" file="statusbar_wifi_up3p.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WARNING" file="statusbar_wifi_warning.png" type="BINDATA" />
<include name="IDR_STATUSBAR_WIRED" file="statusbar_wired.png" type="BINDATA" /> <include name="IDR_STATUSBAR_WIRED" file="statusbar_wired.png" type="BINDATA" />
</if> </if>
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <algorithm> #include <algorithm>
#include "base/message_loop.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "chrome/browser/chrome_thread.h" #include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros_library.h" #include "chrome/browser/chromeos/cros_library.h"
#include "net/url_request/url_request_job.h"
// Allows InvokeLater without adding refcounting. This class is a Singleton and // Allows InvokeLater without adding refcounting. This class is a Singleton and
// won't be deleted until it's last InvokeLater is run. // won't be deleted until it's last InvokeLater is run.
...@@ -19,16 +19,26 @@ struct RunnableMethodTraits<CrosNetworkLibrary> { ...@@ -19,16 +19,26 @@ struct RunnableMethodTraits<CrosNetworkLibrary> {
void ReleaseCallee(CrosNetworkLibrary* obj) {} void ReleaseCallee(CrosNetworkLibrary* obj) {}
}; };
CrosNetworkLibrary::CrosNetworkLibrary() { ////////////////////////////////////////////////////////////////////////////////
// CrosNetworkLibrary
// static
const int CrosNetworkLibrary::kNetworkTrafficeTimerSecs = 1;
CrosNetworkLibrary::CrosNetworkLibrary()
: traffic_type_(0),
ethernet_connected_(false) {
if (CrosLibrary::loaded()) { if (CrosLibrary::loaded()) {
Init(); Init();
} }
g_url_request_job_tracker.AddObserver(this);
} }
CrosNetworkLibrary::~CrosNetworkLibrary() { CrosNetworkLibrary::~CrosNetworkLibrary() {
if (CrosLibrary::loaded()) { if (CrosLibrary::loaded()) {
chromeos::DisconnectNetworkStatus(network_status_connection_); chromeos::DisconnectNetworkStatus(network_status_connection_);
} }
g_url_request_job_tracker.RemoveObserver(this);
} }
// static // static
...@@ -41,6 +51,31 @@ bool CrosNetworkLibrary::loaded() { ...@@ -41,6 +51,31 @@ bool CrosNetworkLibrary::loaded() {
return CrosLibrary::loaded(); return CrosLibrary::loaded();
} }
////////////////////////////////////////////////////////////////////////////////
// CrosNetworkLibrary, URLRequestJobTracker::JobObserver implementation:
void CrosNetworkLibrary::OnJobAdded(URLRequestJob* job) {
CheckNetworkTraffic(false);
}
void CrosNetworkLibrary::OnJobRemoved(URLRequestJob* job) {
CheckNetworkTraffic(false);
}
void CrosNetworkLibrary::OnJobDone(URLRequestJob* job,
const URLRequestStatus& status) {
CheckNetworkTraffic(false);
}
void CrosNetworkLibrary::OnJobRedirect(URLRequestJob* job, const GURL& location,
int status_code) {
CheckNetworkTraffic(false);
}
void CrosNetworkLibrary::OnBytesRead(URLRequestJob* job, int byte_count) {
CheckNetworkTraffic(true);
}
void CrosNetworkLibrary::AddObserver(Observer* observer) { void CrosNetworkLibrary::AddObserver(Observer* observer) {
observers_.AddObserver(observer); observers_.AddObserver(observer);
} }
...@@ -158,3 +193,45 @@ void CrosNetworkLibrary::UpdateNetworkStatus( ...@@ -158,3 +193,45 @@ void CrosNetworkLibrary::UpdateNetworkStatus(
} }
FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this));
} }
void CrosNetworkLibrary::CheckNetworkTraffic(bool download) {
// If we already have a pending upload and download notification, then
// shortcut and return.
if (traffic_type_ == (Observer::TRAFFIC_DOWNLOAD | Observer::TRAFFIC_UPLOAD))
return;
// Figure out if we are uploading and/or downloading. We are downloading
// if download == true. We are uploading if we have upload progress.
if (download)
traffic_type_ |= Observer::TRAFFIC_DOWNLOAD;
if ((traffic_type_ & Observer::TRAFFIC_UPLOAD) == 0) {
URLRequestJobTracker::JobIterator it;
for (it = g_url_request_job_tracker.begin();
it != g_url_request_job_tracker.end();
++it) {
URLRequestJob* job = *it;
if (job->GetUploadProgress() > 0) {
traffic_type_ |= Observer::TRAFFIC_UPLOAD;
break;
}
}
}
// If we have new traffic data to send out and the timer is not currently
// running, then start a new timer.
if (traffic_type_ && !timer_.IsRunning()) {
timer_.Start(base::TimeDelta::FromSeconds(kNetworkTrafficeTimerSecs), this,
&CrosNetworkLibrary::NetworkTrafficTimerFired);
}
}
void CrosNetworkLibrary:: NetworkTrafficTimerFired() {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &CrosNetworkLibrary::NotifyNetworkTraffic,
traffic_type_));
// Reset traffic type so that we don't send the same data next time.
traffic_type_ = 0;
}
void CrosNetworkLibrary::NotifyNetworkTraffic(int traffic_type) {
FOR_EACH_OBSERVER(Observer, observers_, NetworkTraffic(this, traffic_type));
}
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "base/platform_thread.h" #include "base/platform_thread.h"
#include "base/singleton.h" #include "base/singleton.h"
#include "base/string16.h" #include "base/string16.h"
#include "base/timer.h"
#include "net/url_request/url_request_job_tracker.h"
#include "third_party/cros/chromeos_network.h" #include "third_party/cros/chromeos_network.h"
struct WifiNetwork { struct WifiNetwork {
...@@ -51,11 +53,22 @@ typedef std::vector<WifiNetwork> WifiNetworkVector; ...@@ -51,11 +53,22 @@ typedef std::vector<WifiNetwork> WifiNetworkVector;
// This class handles the interaction with the ChromeOS network library APIs. // This class handles the interaction with the ChromeOS network library APIs.
// Classes can add themselves as observers. Users can get an instance of this // Classes can add themselves as observers. Users can get an instance of this
// library class like this: CrosNetworkLibrary::Get() // library class like this: CrosNetworkLibrary::Get()
class CrosNetworkLibrary { class CrosNetworkLibrary : public URLRequestJobTracker::JobObserver {
public: public:
class Observer { class Observer {
public: public:
// A bitfield mask for traffic types.
enum TrafficTypes {
TRAFFIC_DOWNLOAD = 0x1,
TRAFFIC_UPLOAD = 0x2,
} TrafficTypeMasks;
// Called when the network has changed. (wifi networks, and ethernet)
virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0; virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0;
// Called when network traffic has been detected.
// Takes a bitfield of TrafficTypeMasks.
virtual void NetworkTraffic(CrosNetworkLibrary* obj, int traffic_type) = 0;
}; };
// This gets the singleton CrosNetworkLibrary // This gets the singleton CrosNetworkLibrary
...@@ -64,6 +77,14 @@ class CrosNetworkLibrary { ...@@ -64,6 +77,14 @@ class CrosNetworkLibrary {
// Returns true if the ChromeOS library was loaded. // Returns true if the ChromeOS library was loaded.
static bool loaded(); static bool loaded();
// URLRequestJobTracker::JobObserver methods (called on the IO thread):
virtual void OnJobAdded(URLRequestJob* job);
virtual void OnJobRemoved(URLRequestJob* job);
virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status);
virtual void OnJobRedirect(URLRequestJob* job, const GURL& location,
int status_code);
virtual void OnBytesRead(URLRequestJob* job, int byte_count);
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
...@@ -104,8 +125,35 @@ class CrosNetworkLibrary { ...@@ -104,8 +125,35 @@ class CrosNetworkLibrary {
void UpdateNetworkStatus(const WifiNetworkVector& networks, void UpdateNetworkStatus(const WifiNetworkVector& networks,
bool ethernet_connected); bool ethernet_connected);
// Checks network traffic to see if there is any uploading.
// If there is download traffic, then true is passed in for download.
// If there is network traffic then start timer that invokes
// NetworkTrafficTimerFired.
void CheckNetworkTraffic(bool download);
// Called when the timer fires and we need to send out NetworkTraffic
// notifications.
void NetworkTrafficTimerFired();
// This is a helper method to notify the observers on the UI thread.
void NotifyNetworkTraffic(int traffic_type);
// This will notify all obeservers on the UI thread.
void NotifyObservers();
ObserverList<Observer> observers_; ObserverList<Observer> observers_;
// The amount of time to wait between each NetworkTraffic notifications.
static const int kNetworkTrafficeTimerSecs;
// Timer for sending NetworkTraffic notification every
// kNetworkTrafficeTimerSecs seconds.
base::OneShotTimer<CrosNetworkLibrary> timer_;
// The current traffic type that will be sent out for the next NetworkTraffic
// notification. This is a bitfield of TrafficTypeMasks.
int traffic_type_;
// The network status connection for monitoring network status changes. // The network status connection for monitoring network status changes.
chromeos::NetworkStatusConnection network_status_connection_; chromeos::NetworkStatusConnection network_status_connection_;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <limits> #include <limits>
#include "app/gfx/canvas.h"
#include "app/l10n_util.h" #include "app/l10n_util.h"
#include "app/resource_bundle.h" #include "app/resource_bundle.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -18,17 +19,25 @@ ...@@ -18,17 +19,25 @@
// NetworkMenuButton // NetworkMenuButton
// static // static
const int NetworkMenuButton::kNumWifiImages = 8; const int NetworkMenuButton::kNumWifiImages = 3;
const int NetworkMenuButton::kMinOpacity = 50;
const int NetworkMenuButton::kMaxOpacity = 256;
const int NetworkMenuButton::kThrobDuration = 1000; const int NetworkMenuButton::kThrobDuration = 1000;
NetworkMenuButton::NetworkMenuButton(gfx::NativeWindow browser_window) NetworkMenuButton::NetworkMenuButton(gfx::NativeWindow browser_window)
: StatusAreaButton(this), : StatusAreaButton(this),
ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)),
browser_window_(browser_window), browser_window_(browser_window),
ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
animation_.SetThrobDuration(kThrobDuration); ALLOW_THIS_IN_INITIALIZER_LIST(animation_downloading_(this)),
animation_.SetTweenType(SlideAnimation::NONE); ALLOW_THIS_IN_INITIALIZER_LIST(animation_uploading_(this)) {
UpdateIcon(); animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(SlideAnimation::NONE);
animation_downloading_.SetThrobDuration(kThrobDuration);
animation_downloading_.SetTweenType(SlideAnimation::NONE);
animation_uploading_.SetThrobDuration(kThrobDuration);
animation_uploading_.SetTweenType(SlideAnimation::NONE);
NetworkChanged(CrosNetworkLibrary::Get());
CrosNetworkLibrary::Get()->AddObserver(this); CrosNetworkLibrary::Get()->AddObserver(this);
} }
...@@ -113,12 +122,104 @@ bool NetworkMenuButton::OnPasswordDialogAccept(const std::string& ssid, ...@@ -113,12 +122,104 @@ bool NetworkMenuButton::OnPasswordDialogAccept(const std::string& ssid,
// NetworkMenuButton, AnimationDelegate implementation: // NetworkMenuButton, AnimationDelegate implementation:
void NetworkMenuButton::AnimationProgressed(const Animation* animation) { void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
if (animation == &animation_) if (animation == &animation_connecting_ ||
UpdateIcon(); animation == &animation_downloading_ ||
animation == &animation_uploading_)
SchedulePaint();
else else
MenuButton::AnimationProgressed(animation); MenuButton::AnimationProgressed(animation);
} }
////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, StatusAreaButton implementation:
// Override the DrawIcon method to draw the wifi icon.
// The wifi icon is composed of 1 or more alpha-blended icons to show the
// network strength. We also draw an animation for when there's upload/download
// traffic.
void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
// First draw the base icon.
canvas->DrawBitmapInt(icon(), 0, 0);
// If wifi, we draw the wifi signal bars.
CrosNetworkLibrary* cros = CrosNetworkLibrary::Get();
if (cros->wifi_connecting() ||
(!cros->ethernet_connected() && !cros->wifi_ssid().empty())) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
// We want a value between 0-1.
// 0 reperesents no signal and 1 represents full signal strength.
double value = cros->wifi_connecting() ?
animation_connecting_.GetCurrentValue() : cros->wifi_strength() / 100.0;
if (value < 0)
value = 0;
else if (value > 1)
value = 1;
// If we are animating network traffic and not connecting, then we need to
// figure out if we are to also draw the extra image.
int downloading_index = -1;
int uploading_index = -1;
if (!animation_connecting_.IsAnimating()) {
// For network animation, we only show animation in one direction.
// So when we are hiding, we just use 1 minus the value.
// We have kNumWifiImages + 1 number of states. For the first state, where
// we are not adding any images, we set the index to -1.
if (animation_downloading_.IsAnimating()) {
double value_downloading = animation_downloading_.IsShowing() ?
animation_downloading_.GetCurrentValue() :
1.0 - animation_downloading_.GetCurrentValue();
downloading_index = static_cast<int>(value_downloading *
nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1;
}
if (animation_uploading_.IsAnimating()) {
double value_uploading = animation_uploading_.IsShowing() ?
animation_uploading_.GetCurrentValue() :
1.0 - animation_uploading_.GetCurrentValue();
uploading_index = static_cast<int>(value_uploading *
nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1;
}
}
// We need to determine opacity for each of the kNumWifiImages images.
// We split the range (0-1) into equal ranges per kNumWifiImages images.
// For example if kNumWifiImages is 3, then [0-0.33) is the first image and
// [0.33-0.66) is the second image and [0.66-1] is the last image.
// For each of the image:
// If value < the range of this image, draw at kMinOpacity opacity.
// If value > the range of this image, draw at kMaxOpacity-1 opacity.
// If value within the range of this image, draw at an opacity value
// between kMinOpacity and kMaxOpacity-1 relative to where in the range
// value is at.
double value_per_image = 1.0 / kNumWifiImages;
SkPaint paint;
for (int i = 0; i < kNumWifiImages; i++) {
if (value > value_per_image) {
paint.setAlpha(kMaxOpacity - 1);
value -= value_per_image;
} else {
// Map value between 0 and value_per_image to [kMinOpacity,kMaxOpacity).
paint.setAlpha(kMinOpacity + static_cast<int>(value / value_per_image *
nextafter(static_cast<float>(kMaxOpacity - kMinOpacity), 0)));
// For following iterations, we want to draw at kMinOpacity.
// So we set value to 0 here.
value = 0;
}
canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_UP1 + i),
0, 0, paint);
canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_DOWN1 + i),
0, 0, paint);
// Draw network traffic downloading/uploading image if necessary.
if (i == downloading_index)
canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_DOWN1P + i),
0, 0, paint);
if (i == uploading_index)
canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_UP1P + i),
0, 0, paint);
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, views::ViewMenuDelegate implementation: // NetworkMenuButton, views::ViewMenuDelegate implementation:
...@@ -134,43 +235,48 @@ void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { ...@@ -134,43 +235,48 @@ void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, CrosNetworkLibrary::Observer implementation: // NetworkMenuButton, CrosNetworkLibrary::Observer implementation:
void NetworkMenuButton::NetworkChanged(CrosNetworkLibrary* obj) { void NetworkMenuButton::NetworkChanged(CrosNetworkLibrary* cros) {
UpdateIcon(); int id = IDR_STATUSBAR_WARNING;
} if (cros->loaded()) {
id = IDR_STATUSBAR_NETWORK_DISCONNECTED;
if (cros->wifi_connecting()) {
// Start the connecting animation if not running.
if (!animation_connecting_.IsAnimating()) {
animation_connecting_.Reset();
animation_connecting_.StartThrobbing(std::numeric_limits<int>::max());
}
// Stop network traffic animation when we are connecting.
animation_downloading_.Stop();
animation_uploading_.Stop();
void NetworkMenuButton::UpdateIcon() { id = IDR_STATUSBAR_WIFI_DOT;
CrosNetworkLibrary* cros = CrosNetworkLibrary::Get(); } else {
int id = IDR_STATUSBAR_NETWORK_DISCONNECTED; // Stop connecting animation since we are not connecting.
if (cros->wifi_connecting()) { animation_connecting_.Stop();
// Start the connecting animation if not running.
if (!animation_.IsAnimating()) // Always show the higher priority connection first. Ethernet then wifi.
animation_.StartThrobbing(std::numeric_limits<int>::max()); if (cros->ethernet_connected()) {
id = IDR_STATUSBAR_WIRED;
// We need to map the value of 0-1 in the animation to 0 - kNumWifiImages-1. } else if (!cros->wifi_ssid().empty()) {
int index = static_cast<int>(animation_.GetCurrentValue() * id = IDR_STATUSBAR_WIFI_DOT;
nextafter(static_cast<float>(kNumWifiImages), 0)); }
id = IDR_STATUSBAR_WIFI_1 + index;
} 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 = static_cast<int>(cros->wifi_strength() / 100.0 *
nextafter(static_cast<float>(kNumWifiImages), 0));
// Make sure that index is between 0 and kNumWifiImages - 1
if (index < 0)
index = 0;
if (index >= kNumWifiImages)
index = kNumWifiImages - 1;
id = IDR_STATUSBAR_WIFI_1 + index;
} }
} }
SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(id)); SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(id));
SchedulePaint(); SchedulePaint();
} }
void NetworkMenuButton::NetworkTraffic(CrosNetworkLibrary* cros,
int traffic_type) {
if (!cros->ethernet_connected() && !cros->wifi_ssid().empty() &&
!cros->wifi_connecting()) {
// For downloading/uploading animation, we want to force at least one cycle
// so that it looks smooth. And if we keep downloading/uploading, we will
// keep calling StartThrobbing which will update the cycle count back to 2.
if (traffic_type & TRAFFIC_DOWNLOAD)
animation_downloading_.StartThrobbing(2);
if (traffic_type & TRAFFIC_UPLOAD)
animation_uploading_.StartThrobbing(2);
}
}
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
class Browser; class Browser;
class SkBitmap; class SkBitmap;
namespace gfx {
class Canvas;
}
// The network menu button in the status area. // The network menu button in the status area.
// This class will handle getting the wifi networks and populating the menu. // This class will handle getting the wifi networks and populating the menu.
// It will also handle the status icon changing and connecting to another // It will also handle the status icon changing and connecting to another
...@@ -59,20 +63,29 @@ class NetworkMenuButton : public StatusAreaButton, ...@@ -59,20 +63,29 @@ class NetworkMenuButton : public StatusAreaButton,
// CrosNetworkLibrary::Observer implementation. // CrosNetworkLibrary::Observer implementation.
virtual void NetworkChanged(CrosNetworkLibrary* obj); virtual void NetworkChanged(CrosNetworkLibrary* obj);
virtual void NetworkTraffic(CrosNetworkLibrary* cros,
int traffic_type);
protected:
// StatusAreaButton implementation.
virtual void DrawIcon(gfx::Canvas* canvas);
private: private:
// views::ViewMenuDelegate implementation. // views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt); virtual void RunMenu(views::View* source, const gfx::Point& pt);
// Update the icon to either the connecting, connected, or disconnected icon.
void UpdateIcon();
// Set to true if we are currently refreshing the menu. // Set to true if we are currently refreshing the menu.
bool refreshing_menu_; bool refreshing_menu_;
// The number of wifi strength images. // The number of wifi strength images.
static const int kNumWifiImages; static const int kNumWifiImages;
// The minimum opacity of the wifi bars.
static const int kMinOpacity;
// The maximum opacity of the wifi bars.
static const int kMaxOpacity;
// A list of wifi networks. // A list of wifi networks.
WifiNetworkVector wifi_networks_; WifiNetworkVector wifi_networks_;
...@@ -86,9 +99,15 @@ class NetworkMenuButton : public StatusAreaButton, ...@@ -86,9 +99,15 @@ class NetworkMenuButton : public StatusAreaButton,
gfx::NativeWindow browser_window_; gfx::NativeWindow browser_window_;
// The throb animation that does the wifi connecting animation. // The throb animation that does the wifi connecting animation.
ThrobAnimation animation_; ThrobAnimation animation_connecting_;
// The throb animation that does the downloading animation.
ThrobAnimation animation_downloading_;
// The throb animation that does the uploading animation.
ThrobAnimation animation_uploading_;
// The duration of the wifi connecting icon throbbing in milliseconds. // The duration of the icon throbbing in milliseconds.
static const int kThrobDuration; static const int kThrobDuration;
DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
......
...@@ -272,6 +272,8 @@ class NetworkSection : public SettingsContentsSection, ...@@ -272,6 +272,8 @@ class NetworkSection : public SettingsContentsSection,
// CrosNetworkLibrary::Observer implementation. // CrosNetworkLibrary::Observer implementation.
virtual void NetworkChanged(CrosNetworkLibrary* obj); virtual void NetworkChanged(CrosNetworkLibrary* obj);
virtual void NetworkTraffic(CrosNetworkLibrary* obj,
int traffic_type) {}
protected: protected:
// SettingsContentsSection overrides: // SettingsContentsSection overrides:
......
...@@ -23,7 +23,7 @@ StatusAreaButton::StatusAreaButton(views::ViewMenuDelegate* menu_delegate) ...@@ -23,7 +23,7 @@ StatusAreaButton::StatusAreaButton(views::ViewMenuDelegate* menu_delegate)
void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) { void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) {
int bitmap_id; int bitmap_id;
switch(state()) { switch (state()) {
case BS_NORMAL: case BS_NORMAL:
bitmap_id = IDR_STATUSBAR_CONTAINER; bitmap_id = IDR_STATUSBAR_CONTAINER;
break; break;
...@@ -40,5 +40,9 @@ void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) { ...@@ -40,5 +40,9 @@ void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) {
SkBitmap* container = SkBitmap* container =
ResourceBundle::GetSharedInstance().GetBitmapNamed(bitmap_id); ResourceBundle::GetSharedInstance().GetBitmapNamed(bitmap_id);
canvas->DrawBitmapInt(*container, 0, 0); canvas->DrawBitmapInt(*container, 0, 0);
DrawIcon(canvas);
}
void StatusAreaButton::DrawIcon(gfx::Canvas* canvas) {
canvas->DrawBitmapInt(icon(), 0, 0); canvas->DrawBitmapInt(icon(), 0, 0);
} }
...@@ -12,9 +12,17 @@ ...@@ -12,9 +12,17 @@
// Shows current button state by drawing a border around the current icon. // Shows current button state by drawing a border around the current icon.
class StatusAreaButton : public views::MenuButton { class StatusAreaButton : public views::MenuButton {
public: public:
StatusAreaButton(views::ViewMenuDelegate* menu_delegate); explicit StatusAreaButton(views::ViewMenuDelegate* menu_delegate);
virtual ~StatusAreaButton() {} virtual ~StatusAreaButton() {}
virtual void Paint(gfx::Canvas* canvas, bool for_drag); virtual void Paint(gfx::Canvas* canvas, bool for_drag);
protected:
// Draws the icon for this status area button on the canvas.
// Subclasses should override this method if they need to draw their own icon.
// Otherwise, just call SetIcon() and the it will be handled for you.
virtual void DrawIcon(gfx::Canvas* canvas);
DISALLOW_COPY_AND_ASSIGN(StatusAreaButton);
}; };
#endif // CHROME_BROWSER_CHROMEOS_STATUS_AREA_BUTTON_H_ #endif // CHROME_BROWSER_CHROMEOS_STATUS_AREA_BUTTON_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment