diff options
Diffstat (limited to 'chrome/browser/chromeos/status')
6 files changed, 97 insertions, 185 deletions
diff --git a/chrome/browser/chromeos/status/network_dropdown_button.cc b/chrome/browser/chromeos/status/network_dropdown_button.cc index 8deb193..cade402 100644 --- a/chrome/browser/chromeos/status/network_dropdown_button.cc +++ b/chrome/browser/chromeos/status/network_dropdown_button.cc @@ -34,12 +34,12 @@ NetworkDropdownButton::NetworkDropdownButton(bool browser_mode, parent_window_(parent_window) { animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetTweenType(Tween::LINEAR); - OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); - CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); + NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); + CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); } NetworkDropdownButton::~NetworkDropdownButton() { - CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); + CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); } //////////////////////////////////////////////////////////////////////////////// @@ -62,13 +62,13 @@ void NetworkDropdownButton::AnimationProgressed(const Animation* animation) { } void NetworkDropdownButton::Refresh() { - OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); + NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); } //////////////////////////////////////////////////////////////////////////////// -// NetworkDropdownButton, NetworkLibrary::NetworkManagerObserver implementation: +// NetworkDropdownButton, NetworkLibrary::Observer implementation: -void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) { +void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) { // Show network that we will actually use. It could be another network than // user selected. For example user selected WiFi network but we have Ethernet // connection and Chrome OS device will actually use Ethernet. @@ -78,27 +78,28 @@ void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); if (CrosLibrary::Get()->EnsureLoaded()) { - // Always show the active network, if any - const Network* active_network = cros->active_network(); - const WirelessNetwork* wireless; - if (active_network != NULL) { + // Always show the higher priority connection first. Ethernet then wifi. + if (cros->ethernet_connected()) { animation_connecting_.Stop(); - if (active_network->type() == TYPE_ETHERNET) { - SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); - SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); - } else { - DCHECK(active_network->type() == TYPE_WIFI || - active_network->type() == TYPE_CELLULAR); - wireless = static_cast<const WirelessNetwork*>(active_network); - SetIcon(IconForNetworkStrength(wireless->strength(), false)); - SetText(ASCIIToWide(wireless->name())); - } + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); + SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); + } else if (cros->wifi_connected()) { + animation_connecting_.Stop(); + SetIcon(IconForNetworkStrength( + cros->wifi_network()->strength(), true)); + SetText(ASCIIToWide(cros->wifi_network()->name())); + } else if (cros->cellular_connected()) { + animation_connecting_.Stop(); + SetIcon(IconForNetworkStrength( + cros->cellular_network()->strength(), false)); + SetText(ASCIIToWide(cros->cellular_network()->name())); } else if (cros->wifi_connecting() || cros->cellular_connecting()) { if (!animation_connecting_.is_animating()) { animation_connecting_.Reset(); animation_connecting_.StartThrobbing(-1); SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1_BLACK)); } + if (cros->wifi_connecting()) SetText(ASCIIToWide(cros->wifi_network()->name())); else if (cros->cellular_connecting()) diff --git a/chrome/browser/chromeos/status/network_dropdown_button.h b/chrome/browser/chromeos/status/network_dropdown_button.h index 2968e42..47500f6 100644 --- a/chrome/browser/chromeos/status/network_dropdown_button.h +++ b/chrome/browser/chromeos/status/network_dropdown_button.h @@ -19,7 +19,7 @@ namespace chromeos { // See NetworkMenu for more details. class NetworkDropdownButton : public views::MenuButton, public NetworkMenu, - public NetworkLibrary::NetworkManagerObserver { + public NetworkLibrary::Observer { public: NetworkDropdownButton(bool browser_mode, gfx::NativeWindow parent_window); virtual ~NetworkDropdownButton(); @@ -27,8 +27,8 @@ class NetworkDropdownButton : public views::MenuButton, // AnimationDelegate implementation. virtual void AnimationProgressed(const Animation* animation); - // NetworkLibrary::NetworkManagerObserver implementation. - virtual void OnNetworkManagerChanged(NetworkLibrary* obj); + // NetworkLibrary::Observer implementation. + virtual void NetworkChanged(NetworkLibrary* obj); // Refreshes button state. Used when language has been changed. void Refresh(); diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc index 159b09c..428865b 100644 --- a/chrome/browser/chromeos/status/network_menu.cc +++ b/chrome/browser/chromeos/status/network_menu.cc @@ -389,47 +389,6 @@ SkBitmap NetworkMenu::IconForNetworkStrength(const CellularNetwork* cellular) { } // static -// TODO(ers) update for GSM when we have the necessary images -SkBitmap NetworkMenu::BadgeForNetworkTechnology( - const CellularNetwork* cellular) { - - int id; - if (cellular->network_technology() == NETWORK_TECHNOLOGY_EVDO) { - switch (cellular->data_left()) { - case CellularNetwork::DATA_NONE: - case CellularNetwork::DATA_VERY_LOW: - id = IDR_STATUSBAR_NETWORK_3G_ERROR; - break; - case CellularNetwork::DATA_LOW: - id = IDR_STATUSBAR_NETWORK_3G_WARN; - break; - case CellularNetwork::DATA_NORMAL: - id = IDR_STATUSBAR_NETWORK_3G; - break; - } - } else if (cellular->network_technology() == NETWORK_TECHNOLOGY_1XRTT) { - switch (cellular->data_left()) { - case CellularNetwork::DATA_NONE: - case CellularNetwork::DATA_VERY_LOW: - id = IDR_STATUSBAR_NETWORK_1X_ERROR; - break; - case CellularNetwork::DATA_LOW: - id = IDR_STATUSBAR_NETWORK_1X_WARN; - break; - case CellularNetwork::DATA_NORMAL: - id = IDR_STATUSBAR_NETWORK_1X; - break; - } - } else { - id = -1; - } - if (id == -1) - return SkBitmap(); - else - return *ResourceBundle::GetSharedInstance().GetBitmapNamed(id); -} - -// static SkBitmap NetworkMenu::IconForDisplay(SkBitmap icon, SkBitmap badge) { // Draw badge at (14,14). static const int kBadgeX = 14; @@ -570,7 +529,9 @@ void NetworkMenu::InitMenuItems() { } SkBitmap icon = IconForNetworkStrength(cell_networks[i]->strength(), true); - SkBitmap badge = BadgeForNetworkTechnology(cell_networks[i]); + // TODO(chocobo): Check cellular network 3g/edge. + SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G); + // SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE); int flag = FLAG_CELLULAR; if (active_cellular && cell_networks[i]->service_path() == diff --git a/chrome/browser/chromeos/status/network_menu.h b/chrome/browser/chromeos/status/network_menu.h index a68e928..8f57c61 100644 --- a/chrome/browser/chromeos/status/network_menu.h +++ b/chrome/browser/chromeos/status/network_menu.h @@ -115,12 +115,11 @@ class NetworkMenu : public views::ViewMenuDelegate, // |black| is used to specify whether to return a black icon for display // on a light background or a white icon for display on a dark background. static SkBitmap IconForNetworkStrength(int strength, bool black); + // Returns the Icon for a network strength for CellularNetwork |cellular|. // This returns different colored bars depending on cellular data left. static SkBitmap IconForNetworkStrength(const CellularNetwork* cellular); - // Returns the Badge for a given network technology. - // This returns different colored symbols depending on cellular data left. - static SkBitmap BadgeForNetworkTechnology(const CellularNetwork* cellular); + // This method will convert the |icon| bitmap to the correct size for display. // If the |badge| icon is not empty, it will draw that on top of the icon. static SkBitmap IconForDisplay(SkBitmap icon, SkBitmap badge); diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index b8cbe00..48b5187 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -35,16 +35,12 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetTweenType(Tween::EASE_IN_OUT); - OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); - CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); - CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this); + NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); + CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); } NetworkMenuButton::~NetworkMenuButton() { - NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); - netlib->RemoveNetworkManagerObserver(this); - netlib->RemoveObserverForAllNetworks(this); - netlib->RemoveCellularDataPlanObserver(this); + CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); } //////////////////////////////////////////////////////////////////////////////// @@ -77,27 +73,11 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { } //////////////////////////////////////////////////////////////////////////////// -// NetworkMenuButton, NetworkLibrary::NetworkManagerObserver implementation: +// NetworkMenuButton, NetworkLibrary::Observer implementation: -void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) { +void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); if (CrosLibrary::Get()->EnsureLoaded()) { - // Add an observer for the active network, if any - const Network* network = cros->active_network(); - if (active_network_.empty() || network == NULL || - active_network_ != network->service_path()) { - if (!active_network_.empty()) { - cros->RemoveNetworkObserver(active_network_, this); - } - if (network != NULL) { - cros->AddNetworkObserver(network->service_path(), this); - } - } - if (network) - active_network_ = network->service_path(); - else - active_network_ = ""; - if (cros->wifi_connecting() || cros->cellular_connecting()) { // Start the connecting animation if not running. if (!animation_connecting_.is_animating()) { @@ -118,35 +98,68 @@ void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) { } else { // Stop connecting animation since we are not connecting. animation_connecting_.Stop(); - if (!cros->Connected()) { + + // Always show the higher priority connection first. Ethernet then wifi. + if (cros->ethernet_connected()) { + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); + SetTooltipText( + l10n_util::GetStringF( + IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, + l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET))); + } else if (cros->wifi_connected()) { + SetIcon(IconForNetworkStrength( + cros->wifi_network()->strength(), false)); + SetTooltipText(l10n_util::GetStringF( + IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, + UTF8ToWide(cros->wifi_network()->name()))); + } else if (cros->cellular_connected()) { + const CellularNetwork* cellular = cros->cellular_network(); + if (cellular->data_left() == CellularNetwork::DATA_NONE) { + // If no data, then we show 0 bars. + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); + } else { + SetIcon(IconForNetworkStrength(cellular)); + } + SetTooltipText(l10n_util::GetStringF( + IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, + UTF8ToWide(cellular->name()))); + } else { SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); SetTooltipText(l10n_util::GetString( IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); - } else { - SetNetworkIcon(network); } } - SetNetworkBadge(cros, network); - } else { - SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); - SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); - SetTooltipText(l10n_util::GetString( - IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); - } - - SchedulePaint(); - UpdateMenu(); -} -//////////////////////////////////////////////////////////////////////////////// -// NetworkMenuButton, NetworkLibrary::NetworkObserver implementation: -void NetworkMenuButton::OnNetworkChanged(NetworkLibrary* cros, - const Network* network) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - if (CrosLibrary::Get()->EnsureLoaded()) { - // Always show the active network connection, if any. - SetNetworkIcon(network); - SetNetworkBadge(cros, network); + // Figure out whether or not to show a badge. + int id = -1; + if (cros->Connecting()) { + if (cros->cellular_connecting()) { + id = IDR_STATUSBAR_NETWORK_3G; + } + } else if (cros->Connected()) { + if (!cros->ethernet_connected() && !cros->wifi_connected() && + cros->cellular_connected()) { + switch (cros->cellular_network()->data_left()) { + case CellularNetwork::DATA_NONE: + case CellularNetwork::DATA_VERY_LOW: + id = IDR_STATUSBAR_NETWORK_3G_ERROR; + break; + case CellularNetwork::DATA_LOW: + id = IDR_STATUSBAR_NETWORK_3G_WARN; + break; + case CellularNetwork::DATA_NORMAL: + id = IDR_STATUSBAR_NETWORK_3G; + break; + } + } + } else { + id = IDR_STATUSBAR_NETWORK_DISCONNECTED; + } + if (id != -1) { + SetBadge(*rb.GetBitmapNamed(id)); + } else { + SetBadge(SkBitmap()); + } } else { SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); @@ -158,9 +171,9 @@ void NetworkMenuButton::OnNetworkChanged(NetworkLibrary* cros, UpdateMenu(); } -void NetworkMenuButton::OnCellularDataPlanChanged(NetworkLibrary* cros) { - // Call OnNetworkManagerChanged which will update the icon. - OnNetworkManagerChanged(cros); +void NetworkMenuButton::CellularDataPlanChanged(NetworkLibrary* cros) { + // Call NetworkChanged which will update the icon. + NetworkChanged(cros); } //////////////////////////////////////////////////////////////////////////////// @@ -182,54 +195,4 @@ bool NetworkMenuButton::ShouldOpenButtonOptions() const { return host_->ShouldOpenButtonOptions(this); } -//////////////////////////////////////////////////////////////////////////////// -// NetworkMenuButton, private methods - -void NetworkMenuButton::SetNetworkIcon(const Network* network) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - if (network && network->is_active()) { - if (network->type() == TYPE_ETHERNET) { - SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); - SetTooltipText( - l10n_util::GetStringF( - IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, - l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET))); - } else if (network->type() == TYPE_WIFI) { - const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); - SetIcon(IconForNetworkStrength(wifi->strength(), false)); - SetTooltipText(l10n_util::GetStringF( - IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, - UTF8ToWide(wifi->name()))); - } else if (network->type() == TYPE_CELLULAR) { - const CellularNetwork* cellular = - static_cast<const CellularNetwork*>(network); - if (cellular->data_left() == CellularNetwork::DATA_NONE) { - // If no data, then we show 0 bars. - SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); - } else { - SetIcon(IconForNetworkStrength(cellular)); - } - SetTooltipText(l10n_util::GetStringF( - IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, - UTF8ToWide(cellular->name()))); - } - } -} - -void NetworkMenuButton::SetNetworkBadge(NetworkLibrary* cros, - const Network* network) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - // Figure out whether or not to show a badge. - if (network && network->type() == TYPE_CELLULAR && - (network->is_active() || network->connecting())) { - const CellularNetwork* cellular - = static_cast<const CellularNetwork*>(network); - SetBadge(BadgeForNetworkTechnology(cellular)); - } else if (!cros->Connected() && !cros->Connecting()) { - SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); - } else { - SetBadge(SkBitmap()); - } -} - } // namespace chromeos diff --git a/chrome/browser/chromeos/status/network_menu_button.h b/chrome/browser/chromeos/status/network_menu_button.h index c2b2e71..f8b27db 100644 --- a/chrome/browser/chromeos/status/network_menu_button.h +++ b/chrome/browser/chromeos/status/network_menu_button.h @@ -46,9 +46,7 @@ class StatusAreaHost; // The label will be BOLD if the network is currently connected. class NetworkMenuButton : public StatusAreaButton, public NetworkMenu, - public NetworkLibrary::NetworkManagerObserver, - public NetworkLibrary::NetworkObserver, - public NetworkLibrary::CellularDataPlanObserver { + public NetworkLibrary::Observer { public: explicit NetworkMenuButton(StatusAreaHost* host); virtual ~NetworkMenuButton(); @@ -56,12 +54,9 @@ class NetworkMenuButton : public StatusAreaButton, // AnimationDelegate implementation. virtual void AnimationProgressed(const Animation* animation); - // NetworkLibrary::NetworkManagerObserver implementation. - virtual void OnNetworkManagerChanged(NetworkLibrary* cros); - // NetworkLibrary::NetworkObserver implementation. - virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); - // NetworkLibrary::CellularDataPlanObserver implementation. - virtual void OnCellularDataPlanChanged(NetworkLibrary* cros); + // NetworkLibrary::Observer implementation. + virtual void NetworkChanged(NetworkLibrary* obj); + virtual void CellularDataPlanChanged(NetworkLibrary* obj); // Sets the badge icon. void SetBadge(const SkBitmap& badge) { badge_ = badge; } @@ -78,9 +73,6 @@ class NetworkMenuButton : public StatusAreaButton, virtual bool ShouldOpenButtonOptions() const; private: - void SetNetworkIcon(const Network* network); - void SetNetworkBadge(NetworkLibrary* cros, const Network* network); - // The status area host, StatusAreaHost* host_; @@ -93,10 +85,6 @@ class NetworkMenuButton : public StatusAreaButton, // The duration of the icon throbbing in milliseconds. static const int kThrobDuration; - // If any network is currently active, this is the service path of the one - // whose status is displayed in the network menu button. - std::string active_network_; - DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); }; |