summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/status
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/status')
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.cc2
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.h3
-rw-r--r--chrome/browser/chromeos/status/feedback_menu_button.cc23
-rw-r--r--chrome/browser/chromeos/status/feedback_menu_button.h7
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.cc32
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.h14
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_button.cc13
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_button.h1
-rw-r--r--chrome/browser/chromeos/status/network_dropdown_button.cc47
-rw-r--r--chrome/browser/chromeos/status/network_dropdown_button.h10
-rw-r--r--chrome/browser/chromeos/status/network_menu.cc565
-rw-r--r--chrome/browser/chromeos/status/network_menu.h25
-rw-r--r--chrome/browser/chromeos/status/network_menu_button.cc213
-rw-r--r--chrome/browser/chromeos/status/network_menu_button.h27
-rw-r--r--chrome/browser/chromeos/status/power_menu_button.cc25
-rw-r--r--chrome/browser/chromeos/status/power_menu_button.h7
-rw-r--r--chrome/browser/chromeos/status/power_menu_button_browsertest.cc20
-rw-r--r--chrome/browser/chromeos/status/status_area_button.cc15
-rw-r--r--chrome/browser/chromeos/status/status_area_button.h13
-rw-r--r--chrome/browser/chromeos/status/status_area_host.h2
-rw-r--r--chrome/browser/chromeos/status/status_area_view.cc13
21 files changed, 639 insertions, 438 deletions
diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc
index f63593f..c5e4bd4 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -34,7 +34,7 @@ ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
set_border(NULL);
set_use_menu_button_paint(true);
SetFont(ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD));
+ ResourceBundle::BaseFont).DeriveFont(1));
SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha
SetShowMultipleIconStates(false);
set_alignment(TextButton::ALIGN_CENTER);
diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h
index 405d00a..76f214a 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.h
+++ b/chrome/browser/chromeos/status/clock_menu_button.h
@@ -59,6 +59,9 @@ class ClockMenuButton : public StatusAreaButton,
// changes.
void UpdateText();
+ protected:
+ virtual int horizontal_padding() { return 3; }
+
private:
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt);
diff --git a/chrome/browser/chromeos/status/feedback_menu_button.cc b/chrome/browser/chromeos/status/feedback_menu_button.cc
index f7cb958..2a0ea52 100644
--- a/chrome/browser/chromeos/status/feedback_menu_button.cc
+++ b/chrome/browser/chromeos/status/feedback_menu_button.cc
@@ -8,7 +8,7 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
-#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "gfx/canvas.h"
#include "grit/generated_resources.h"
@@ -24,28 +24,11 @@ FeedbackMenuButton::FeedbackMenuButton(StatusAreaHost* host)
host_(host) {
DCHECK(host_);
SetTooltipText(l10n_util::GetString(IDS_STATUSBAR_FEEDBACK_TOOLTIP));
-}
-
-FeedbackMenuButton::~FeedbackMenuButton() {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// FeedbackMenuButton, StatusAreaButton implementation:
-
-void FeedbackMenuButton::DrawPressed(gfx::Canvas* canvas) {
- DrawFeedbackIcon(canvas, *ResourceBundle::GetSharedInstance().
- GetBitmapNamed(IDR_STATUSBAR_FEEDBACK_PRESSED));
-}
-
-void FeedbackMenuButton::DrawIcon(gfx::Canvas* canvas) {
- DrawFeedbackIcon(canvas, *ResourceBundle::GetSharedInstance().
+ SetIcon(*ResourceBundle::GetSharedInstance().
GetBitmapNamed(IDR_STATUSBAR_FEEDBACK));
}
-void FeedbackMenuButton::DrawFeedbackIcon(gfx::Canvas* canvas, SkBitmap icon) {
- // Draw the battery icon 5 pixels down to center it.
- static const int kIconVerticalPadding = 5;
- canvas->DrawBitmapInt(icon, 0, kIconVerticalPadding);
+FeedbackMenuButton::~FeedbackMenuButton() {
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/status/feedback_menu_button.h b/chrome/browser/chromeos/status/feedback_menu_button.h
index 9e1590b..3e7d83c 100644
--- a/chrome/browser/chromeos/status/feedback_menu_button.h
+++ b/chrome/browser/chromeos/status/feedback_menu_button.h
@@ -26,10 +26,6 @@ class FeedbackMenuButton : public StatusAreaButton,
virtual ~FeedbackMenuButton();
private:
- // StatusAreaButton implementation.
- virtual void DrawPressed(gfx::Canvas* canvas);
- virtual void DrawIcon(gfx::Canvas* canvas);
-
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt);
@@ -56,9 +52,6 @@ class FeedbackMenuButton : public StatusAreaButton,
virtual void ActivatedAt(int index) {}
virtual void MenuWillShow() {}
- // This method will draw the |icon| in the appropriate place on the |canvas|.
- void DrawFeedbackIcon(gfx::Canvas* canvas, SkBitmap icon);
-
StatusAreaHost* host_;
DISALLOW_COPY_AND_ASSIGN(FeedbackMenuButton);
diff --git a/chrome/browser/chromeos/status/input_method_menu.cc b/chrome/browser/chromeos/status/input_method_menu.cc
index c94e125..ae89e40 100644
--- a/chrome/browser/chromeos/status/input_method_menu.cc
+++ b/chrome/browser/chromeos/status/input_method_menu.cc
@@ -116,19 +116,21 @@ namespace chromeos {
InputMethodMenu::InputMethodMenu(PrefService* pref_service,
bool is_browser_mode,
- bool is_screen_locker_mode)
+ bool is_screen_locker_mode,
+ bool is_out_of_box_experience_mode)
: input_method_descriptors_(CrosLibrary::Get()->GetInputMethodLibrary()->
GetActiveInputMethods()),
model_(NULL),
- // Be aware that the constructor of |language_menu_| calls GetItemCount()
- // in this class. Therefore, GetItemCount() have to return 0 when
- // |model_| is NULL.
- ALLOW_THIS_IN_INITIALIZER_LIST(language_menu_(this)),
- minimum_language_menu_width_(0),
+ // Be aware that the constructor of |input_method_menu_| calls
+ // GetItemCount() in this class. Therefore, GetItemCount() have to return
+ // 0 when |model_| is NULL.
+ ALLOW_THIS_IN_INITIALIZER_LIST(input_method_menu_(this)),
+ minimum_input_method_menu_width_(0),
pref_service_(pref_service),
logged_in_(false),
is_browser_mode_(is_browser_mode),
- is_screen_locker_mode_(is_screen_locker_mode) {
+ is_screen_locker_mode_(is_screen_locker_mode),
+ is_out_of_box_experience_mode_(is_out_of_box_experience_mode) {
DCHECK(input_method_descriptors_.get() &&
!input_method_descriptors_->empty());
@@ -214,7 +216,8 @@ int InputMethodMenu::GetGroupIdAt(int index) const {
DCHECK_GE(index, 0);
if (IndexIsInInputMethodList(index)) {
- return kRadioGroupLanguage;
+ return is_out_of_box_experience_mode_ ?
+ kRadioGroupNone : kRadioGroupLanguage;
}
if (GetPropertyIndex(index, &index)) {
@@ -276,7 +279,8 @@ menus::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const {
}
if (IndexIsInInputMethodList(index)) {
- return menus::MenuModel::TYPE_RADIO;
+ return is_out_of_box_experience_mode_ ?
+ menus::MenuModel::TYPE_COMMAND : menus::MenuModel::TYPE_RADIO;
}
if (GetPropertyIndex(index, &index)) {
@@ -367,7 +371,7 @@ void InputMethodMenu::ActivatedAt(int index) {
void InputMethodMenu::RunMenu(
views::View* unused_source, const gfx::Point& pt) {
PrepareForMenuOpen();
- language_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
+ input_method_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
}
////////////////////////////////////////////////////////////////////////////////
@@ -407,9 +411,9 @@ void InputMethodMenu::PrepareForMenuOpen() {
input_method_descriptors_.reset(CrosLibrary::Get()->GetInputMethodLibrary()->
GetActiveInputMethods());
RebuildModel();
- language_menu_.Rebuild();
- if (minimum_language_menu_width_ > 0) {
- language_menu_.SetMinimumWidth(minimum_language_menu_width_);
+ input_method_menu_.Rebuild();
+ if (minimum_input_method_menu_width_ > 0) {
+ input_method_menu_.SetMinimumWidth(minimum_input_method_menu_width_);
}
}
@@ -604,7 +608,7 @@ void InputMethodMenu::Observe(NotificationType type,
void InputMethodMenu::SetMinimumWidth(int width) {
// On the OOBE network selection screen, fixed width menu would be preferable.
- minimum_language_menu_width_ = width;
+ minimum_input_method_menu_width_ = width;
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/status/input_method_menu.h b/chrome/browser/chromeos/status/input_method_menu.h
index fb87f16..a132c87 100644
--- a/chrome/browser/chromeos/status/input_method_menu.h
+++ b/chrome/browser/chromeos/status/input_method_menu.h
@@ -31,8 +31,11 @@ class InputMethodMenu : public views::ViewMenuDelegate,
public NotificationObserver {
public:
InputMethodMenu(PrefService* pref_service,
+ // TODO(yusukes): combine the three booleans into one enum.
+ // http://crosbug.com/8386.
bool is_browser_mode,
- bool is_screen_locker);
+ bool is_screen_locker,
+ bool is_out_of_box_experience_mode);
virtual ~InputMethodMenu();
// menus::MenuModel implementation.
@@ -92,8 +95,8 @@ class InputMethodMenu : public views::ViewMenuDelegate,
void PrepareForMenuOpen();
// Returns menu2 object for language menu.
- views::Menu2& language_menu() {
- return language_menu_;
+ views::Menu2& input_method_menu() {
+ return input_method_menu_;
}
private:
@@ -141,14 +144,15 @@ class InputMethodMenu : public views::ViewMenuDelegate,
scoped_ptr<menus::SimpleMenuModel> model_;
// The language menu which pops up when the button in status area is clicked.
- views::Menu2 language_menu_;
- int minimum_language_menu_width_;
+ views::Menu2 input_method_menu_;
+ int minimum_input_method_menu_width_;
PrefService* pref_service_;
NotificationRegistrar registrar_;
bool logged_in_;
const bool is_browser_mode_;
const bool is_screen_locker_mode_;
+ const bool is_out_of_box_experience_mode_;
DISALLOW_COPY_AND_ASSIGN(InputMethodMenu);
};
diff --git a/chrome/browser/chromeos/status/input_method_menu_button.cc b/chrome/browser/chromeos/status/input_method_menu_button.cc
index fbc20e4..cd99210 100644
--- a/chrome/browser/chromeos/status/input_method_menu_button.cc
+++ b/chrome/browser/chromeos/status/input_method_menu_button.cc
@@ -36,12 +36,13 @@ InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host)
: StatusAreaButton(this),
InputMethodMenu(GetPrefService(host),
host->IsBrowserMode(),
- host->IsScreenLockerMode()),
+ host->IsScreenLockerMode(),
+ false /* is_out_of_box_experience_mode */),
host_(host) {
set_border(NULL);
set_use_menu_button_paint(true);
SetFont(ResourceBundle::GetSharedInstance().GetFont(
- ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD));
+ ResourceBundle::BaseFont).DeriveFont(1));
SetEnabledColor(0xB3FFFFFF); // White with 70% Alpha
SetDisabledColor(0x00FFFFFF); // White with 00% Alpha (invisible)
SetShowMultipleIconStates(false);
@@ -57,6 +58,14 @@ InputMethodMenuButton::InputMethodMenuButton(StatusAreaHost* host)
////////////////////////////////////////////////////////////////////////////////
// views::View implementation:
+gfx::Size InputMethodMenuButton::GetPreferredSize() {
+ // If not enabled, then hide this button.
+ if (!IsEnabled()) {
+ return gfx::Size(0, 0);
+ }
+ return StatusAreaButton::GetPreferredSize();
+}
+
void InputMethodMenuButton::OnLocaleChanged() {
input_method::OnLocaleChanged();
const InputMethodDescriptor& input_method =
diff --git a/chrome/browser/chromeos/status/input_method_menu_button.h b/chrome/browser/chromeos/status/input_method_menu_button.h
index 41db9a9..d7375d3 100644
--- a/chrome/browser/chromeos/status/input_method_menu_button.h
+++ b/chrome/browser/chromeos/status/input_method_menu_button.h
@@ -24,6 +24,7 @@ class InputMethodMenuButton : public StatusAreaButton,
virtual ~InputMethodMenuButton() {}
// views::View implementation.
+ virtual gfx::Size GetPreferredSize();
virtual void OnLocaleChanged();
private:
diff --git a/chrome/browser/chromeos/status/network_dropdown_button.cc b/chrome/browser/chromeos/status/network_dropdown_button.cc
index d5fd453..bf8a3be 100644
--- a/chrome/browser/chromeos/status/network_dropdown_button.cc
+++ b/chrome/browser/chromeos/status/network_dropdown_button.cc
@@ -34,12 +34,13 @@ NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
parent_window_(parent_window) {
animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(Tween::LINEAR);
- NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
- CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
+ // The initial state will be updated on Refresh.
+ // See network_selection_view.cc.
}
NetworkDropdownButton::~NetworkDropdownButton() {
- CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -62,13 +63,13 @@ void NetworkDropdownButton::AnimationProgressed(const Animation* animation) {
}
void NetworkDropdownButton::Refresh() {
- NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
+ OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary());
}
////////////////////////////////////////////////////////////////////////////////
-// NetworkDropdownButton, NetworkLibrary::Observer implementation:
+// NetworkDropdownButton, NetworkLibrary::NetworkManagerObserver implementation:
-void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) {
+void NetworkDropdownButton::OnNetworkManagerChanged(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,32 +79,31 @@ void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
if (CrosLibrary::Get()->EnsureLoaded()) {
- // Always show the higher priority connection first. Ethernet then wifi.
- if (cros->ethernet_connected()) {
+ // Always show the active network, if any
+ const Network* active_network = cros->active_network();
+ const WirelessNetwork* wireless;
+ if (active_network != NULL) {
animation_connecting_.Stop();
- 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()));
+ 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()));
+ }
} 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()));
+ SetText(ASCIIToWide(cros->wifi_network()->name()));
else if (cros->cellular_connecting())
- SetText(ASCIIToWide(cros->cellular_network().name()));
+ SetText(ASCIIToWide(cros->cellular_network()->name()));
}
if (!cros->Connected() && !cros->Connecting()) {
@@ -118,6 +118,7 @@ void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) {
}
SchedulePaint();
+ UpdateMenu();
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/status/network_dropdown_button.h b/chrome/browser/chromeos/status/network_dropdown_button.h
index 47500f6..ec2e337 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::Observer {
+ public NetworkLibrary::NetworkManagerObserver {
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::Observer implementation.
- virtual void NetworkChanged(NetworkLibrary* obj);
+ // NetworkLibrary::NetworkManagerObserver implementation.
+ virtual void OnNetworkManagerChanged(NetworkLibrary* obj);
// Refreshes button state. Used when language has been changed.
void Refresh();
@@ -37,8 +37,8 @@ class NetworkDropdownButton : public views::MenuButton,
// NetworkMenu implementation:
virtual bool IsBrowserMode() const { return browser_mode_; }
virtual gfx::NativeWindow GetNativeWindow() const { return parent_window_; }
- virtual void OpenButtonOptions() const {}
- virtual bool ShouldOpenButtonOptions() const {return false; }
+ virtual void OpenButtonOptions() {}
+ virtual bool ShouldOpenButtonOptions() const { return false; }
private:
bool browser_mode_;
diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc
index 4899bbd..fb64aa3 100644
--- a/chrome/browser/chromeos/status/network_menu.cc
+++ b/chrome/browser/chromeos/status/network_menu.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/status/network_menu.h"
+#include <algorithm>
+
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
@@ -43,7 +45,7 @@ namespace chromeos {
// NetworkMenu
// static
-const int NetworkMenu::kNumWifiImages = 9;
+const int NetworkMenu::kNumWifiImages = 4;
// NOTE: Use an array rather than just calculating a resource number to avoid
// creating implicit ordering dependencies on the resource values.
@@ -53,11 +55,6 @@ const int NetworkMenu::kBarsImages[kNumWifiImages] = {
IDR_STATUSBAR_NETWORK_BARS2,
IDR_STATUSBAR_NETWORK_BARS3,
IDR_STATUSBAR_NETWORK_BARS4,
- IDR_STATUSBAR_NETWORK_BARS5,
- IDR_STATUSBAR_NETWORK_BARS6,
- IDR_STATUSBAR_NETWORK_BARS7,
- IDR_STATUSBAR_NETWORK_BARS8,
- IDR_STATUSBAR_NETWORK_BARS9,
};
// static
const int NetworkMenu::kBarsImagesBlack[kNumWifiImages] = {
@@ -65,39 +62,26 @@ const int NetworkMenu::kBarsImagesBlack[kNumWifiImages] = {
IDR_STATUSBAR_NETWORK_BARS2_BLACK,
IDR_STATUSBAR_NETWORK_BARS3_BLACK,
IDR_STATUSBAR_NETWORK_BARS4_BLACK,
- IDR_STATUSBAR_NETWORK_BARS5_BLACK,
- IDR_STATUSBAR_NETWORK_BARS6_BLACK,
- IDR_STATUSBAR_NETWORK_BARS7_BLACK,
- IDR_STATUSBAR_NETWORK_BARS8_BLACK,
- IDR_STATUSBAR_NETWORK_BARS9_BLACK,
};
// static
const int NetworkMenu::kBarsImagesLowData[kNumWifiImages] = {
- IDR_STATUSBAR_NETWORK_BARS1_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS2_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS3_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS4_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS5_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS6_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS7_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS8_LOWDATA,
- IDR_STATUSBAR_NETWORK_BARS9_LOWDATA,
+ IDR_STATUSBAR_NETWORK_BARS1_ORANGE,
+ IDR_STATUSBAR_NETWORK_BARS2_ORANGE,
+ IDR_STATUSBAR_NETWORK_BARS3_ORANGE,
+ IDR_STATUSBAR_NETWORK_BARS4_ORANGE,
};
// static
const int NetworkMenu::kBarsImagesVLowData[kNumWifiImages] = {
- IDR_STATUSBAR_NETWORK_BARS1_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS2_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS3_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS4_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS5_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS6_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS7_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS8_VLOWDATA,
- IDR_STATUSBAR_NETWORK_BARS9_VLOWDATA,
+ IDR_STATUSBAR_NETWORK_BARS1_RED,
+ IDR_STATUSBAR_NETWORK_BARS2_RED,
+ IDR_STATUSBAR_NETWORK_BARS3_RED,
+ IDR_STATUSBAR_NETWORK_BARS4_RED,
};
NetworkMenu::NetworkMenu()
: min_width_(-1) {
+ use_settings_ui_ = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableTabbedOptions);
network_menu_.reset(NetworkMenuUI::CreateMenu2(this));
}
@@ -113,30 +97,29 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->network_type = kNetworkTypeEthernet;
if (cros->ethernet_connected()) {
info->status = kNetworkStatusConnected;
- info->ip_address = cros->ethernet_network().ip_address();
+ info->ip_address = cros->ethernet_network() ?
+ cros->ethernet_network()->ip_address() : std::string();
}
info->need_passphrase = false;
info->remembered = true;
} else if (flags & FLAG_WIFI) {
- WifiNetwork wifi;
- bool found = cros->FindWifiNetworkByPath(
- menu_items_[index].wireless_path, &wifi);
- if (found) {
+ WifiNetwork* wifi = cros->FindWifiNetworkByPath(
+ menu_items_[index].wireless_path);
+ if (wifi) {
info->network_type = kNetworkTypeWifi;
- if (wifi.service_path() == cros->wifi_network().service_path()) {
+ if (cros->wifi_network() &&
+ wifi->service_path() == cros->wifi_network()->service_path()) {
if (cros->wifi_connected()) {
info->status = kNetworkStatusConnected;
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED);
} else if (cros->wifi_connecting()) {
info->status = kNetworkStatusConnecting;
- // TODO(stevenjb): Eliminate status message, or localize properly.
info->message = l10n_util::GetStringUTF8(
- IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)
- + ": " + wifi.GetStateString();
- } else if (wifi.state() == STATE_FAILURE) {
+ IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING);
+ } else if (wifi->state() == STATE_FAILURE) {
info->status = kNetworkStatusError;
- info->message = wifi.GetErrorString();
+ info->message = wifi->GetErrorString();
} else {
info->status = kNetworkStatusDisconnected;
info->message = l10n_util::GetStringUTF8(
@@ -147,29 +130,31 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
- if (wifi.encrypted()) {
- if (wifi.IsCertificateLoaded() ||
- wifi.encryption() == SECURITY_8021X) {
+ if (wifi->encrypted()) {
+ info->need_passphrase = true;
+ if (wifi->IsCertificateLoaded() ||
+ wifi->encryption() == SECURITY_8021X) {
+ info->need_passphrase = false;
+ }
+ if (wifi->favorite()) {
+ info->passphrase = wifi->passphrase();
info->need_passphrase = false;
- } else {
- info->need_passphrase = true;
}
} else {
info->need_passphrase = false;
}
- info->ip_address = wifi.ip_address();
- info->remembered = wifi.favorite();
+ info->ip_address = wifi->ip_address();
+ info->remembered = wifi->favorite();
} else {
res = false; // Network not found, hide entry.
}
} else if (flags & FLAG_CELLULAR) {
- CellularNetwork cellular;
- bool found = cros->FindCellularNetworkByPath(
- menu_items_[index].wireless_path, &cellular);
- if (found) {
+ CellularNetwork* cellular = cros->FindCellularNetworkByPath(
+ menu_items_[index].wireless_path);
+ if (cellular) {
info->network_type = kNetworkTypeCellular;
- if (cellular.service_path() ==
- cros->cellular_network().service_path()) {
+ if (cros->cellular_network() && cellular->service_path() ==
+ cros->cellular_network()->service_path()) {
if (cros->cellular_connected()) {
info->status = kNetworkStatusConnected;
info->message = l10n_util::GetStringUTF8(
@@ -179,10 +164,10 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->status = kNetworkStatusConnecting;
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING)
- + ": " + cellular.GetStateString();
- } else if (cellular.state() == STATE_FAILURE) {
+ + ": " + cellular->GetStateString();
+ } else if (cellular->state() == STATE_FAILURE) {
info->status = kNetworkStatusError;
- info->message = cellular.GetErrorString();
+ info->message = cellular->GetErrorString();
} else {
info->status = kNetworkStatusDisconnected;
info->message = l10n_util::GetStringUTF8(
@@ -193,7 +178,7 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
- info->ip_address = cellular.ip_address();
+ info->ip_address = cellular->ip_address();
info->need_passphrase = false;
info->remembered = true;
} else {
@@ -219,41 +204,88 @@ bool NetworkMenu::ConnectToNetworkAt(int index,
int flags = menu_items_[index].flags;
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
if (flags & FLAG_WIFI) {
- WifiNetwork wifi;
- bool found = cros->FindWifiNetworkByPath(
- menu_items_[index].wireless_path, &wifi);
- if (found) {
+ WifiNetwork* wifi = cros->FindWifiNetworkByPath(
+ menu_items_[index].wireless_path);
+ if (wifi) {
// Connect or reconnect.
if (remember >= 0)
- wifi.set_favorite(remember ? true : false);
- if (wifi.encrypted()) {
- if (wifi.IsCertificateLoaded()) {
- cros->ConnectToWifiNetwork(wifi, std::string(), std::string(),
- wifi.cert_path());
- } else if (wifi.encryption() == SECURITY_8021X) {
- // Show the wifi settings/dialog to load/select a certificate.
+ wifi->set_favorite(remember ? true : false);
+ if (cros->wifi_network() &&
+ wifi->service_path() == cros->wifi_network()->service_path()) {
+ // Show the config settings for the active network.
+ ShowWifi(wifi, false);
+ return true;
+ }
+ bool connected = false;
+ if (wifi->encrypted()) {
+ if (wifi->IsCertificateLoaded()) {
+ connected = cros->ConnectToWifiNetwork(
+ wifi, std::string(), std::string(), wifi->cert_path());
+ } else if (wifi->encryption() == SECURITY_8021X) {
+ // Always show the wifi settings/dialog to load/select a certificate.
ShowWifi(wifi, true);
+ return true;
} else {
- cros->ConnectToWifiNetwork(wifi, passphrase, std::string(),
- std::string());
+ if (MenuUI::IsEnabled() || !wifi->passphrase_required()) {
+ connected = cros->ConnectToWifiNetwork(
+ wifi, passphrase, std::string(), std::string());
+ }
}
} else {
- cros->ConnectToWifiNetwork(wifi, std::string(), std::string(),
- std::string());
+ connected = cros->ConnectToWifiNetwork(
+ wifi, std::string(), std::string(), std::string());
+ }
+ if (!connected) {
+ if (!MenuUI::IsEnabled()) {
+ // Show the wifi dialog on a failed attempt for non DOM UI menus.
+ ShowWifi(wifi, true);
+ return true;
+ } else {
+ // If the connection attempt failed immediately (e.g. short password)
+ // keep the menu open so that a retry can be attempted.
+ return false;
+ }
}
+ } else {
+ // If we are attempting to connect to a network that no longer exists,
+ // display a notification.
+ // TODO(stevenjb): Show notification.
}
} else if (flags & FLAG_CELLULAR) {
- CellularNetwork cellular;
- bool found = cros->FindCellularNetworkByPath(
- menu_items_[index].wireless_path, &cellular);
- if (found) {
- // Connect or reconnect.
- cros->ConnectToCellularNetwork(cellular);
+ CellularNetwork* cellular = cros->FindCellularNetworkByPath(
+ menu_items_[index].wireless_path);
+ if (cellular) {
+ if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED) {
+ ActivateCellular(cellular);
+ return true;
+ } else if (cros->cellular_network() &&
+ (cellular->service_path() ==
+ cros->cellular_network()->service_path())) {
+ // Show the config settings for the cellular network.
+ ShowCellular(cellular, false);
+ return true;
+ } else {
+ bool connected = cros->ConnectToCellularNetwork(cellular);
+ if (!connected) {
+ ShowCellular(cellular, true);
+ }
+ }
+ } else {
+ // If we are attempting to connect to a network that no longer exists,
+ // display a notification.
+ // TODO(stevenjb): Show notification.
}
} else if (flags & FLAG_OTHER_NETWORK) {
- bool favorite = remember == 0 ? false : true; // default is true
- cros->ConnectToWifiNetwork(ssid, passphrase, std::string(), std::string(),
- favorite);
+ bool connected = false;
+ if (MenuUI::IsEnabled()) {
+ bool favorite = remember == 0 ? false : true; // default is true
+ connected = cros->ConnectToWifiNetwork(
+ passphrase.empty() ? SECURITY_NONE : SECURITY_UNKNOWN,
+ ssid, passphrase, std::string(), std::string(), favorite);
+ }
+ if (!connected) {
+ ShowOther();
+ }
}
return true;
}
@@ -313,41 +345,16 @@ void NetworkMenu::ActivatedAt(int index) {
cros->EnableCellularNetworkDevice(!cros->cellular_enabled());
} else if (flags & FLAG_TOGGLE_OFFLINE) {
cros->EnableOfflineMode(!cros->offline_mode());
- } else if (flags & FLAG_OTHER_NETWORK) {
- ShowOther();
} else if (flags & FLAG_ETHERNET) {
if (cros->ethernet_connected()) {
ShowEthernet(cros->ethernet_network());
}
} else if (flags & FLAG_WIFI) {
- WifiNetwork wifi;
- bool wifi_exists = cros->FindWifiNetworkByPath(
- menu_items_[index].wireless_path, &wifi);
- if (!wifi_exists) {
- // If we are attempting to connect to a network that no longer exists,
- // display a notification.
- // TODO(stevenjb): Show notification.
- } else if (wifi.service_path() == cros->wifi_network().service_path()) {
- // Show the config settings for the active network.
- ShowWifi(wifi, false);
- } else {
- ConnectToNetworkAt(index, std::string(), std::string(), -1);
- }
+ ConnectToNetworkAt(index, std::string(), std::string(), -1);
+ } else if (flags & FLAG_OTHER_NETWORK) {
+ ConnectToNetworkAt(index, std::string(), std::string(), -1);
} else if (flags & FLAG_CELLULAR) {
- CellularNetwork cellular;
- bool cellular_exists = cros->FindCellularNetworkByPath(
- menu_items_[index].wireless_path, &cellular);
- if (!cellular_exists) {
- // If we are attempting to connect to a network that no longer exists,
- // display a notification.
- // TODO(stevenjb): Show notification.
- } else if (cellular.service_path() ==
- cros->cellular_network().service_path()) {
- // Show the config settings for the cellular network.
- ShowCellular(cellular, false);
- } else {
- ConnectToNetworkAt(index, std::string(), std::string(), -1);
- }
+ ConnectToNetworkAt(index, std::string(), std::string(), -1);
}
}
@@ -378,13 +385,14 @@ SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) {
return *ResourceBundle::GetSharedInstance().GetBitmapNamed(images[index]);
}
-SkBitmap NetworkMenu::IconForNetworkStrength(CellularNetwork cellular) {
+SkBitmap NetworkMenu::IconForNetworkStrength(const CellularNetwork* cellular) {
+ DCHECK(cellular);
// Compose wifi icon by superimposing various icons.
- int index = static_cast<int>(cellular.strength() / 100.0 *
+ int index = static_cast<int>(cellular->strength() / 100.0 *
nextafter(static_cast<float>(kNumWifiImages), 0));
index = std::max(std::min(index, kNumWifiImages - 1), 0);
const int* images = kBarsImages;
- switch (cellular.data_left()) {
+ switch (cellular->data_left()) {
case CellularNetwork::DATA_NONE:
case CellularNetwork::DATA_VERY_LOW:
images = kBarsImagesVLowData;
@@ -400,19 +408,54 @@ SkBitmap NetworkMenu::IconForNetworkStrength(CellularNetwork cellular) {
}
// static
+// TODO(ers) update for GSM when we have the necessary images
+SkBitmap NetworkMenu::BadgeForNetworkTechnology(
+ const CellularNetwork* cellular) {
+
+ int id = -1;
+ 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) {
- // Icons are 24x24.
- static const int kIconWidth = 24;
- static const int kIconHeight = 24;
- // Draw the network icon 3 pixels down to center it.
- static const int kIconX = 0;
- static const int kIconY = 3;
// Draw badge at (14,14).
static const int kBadgeX = 14;
static const int kBadgeY = 14;
- gfx::CanvasSkia canvas(kIconWidth, kIconHeight, false);
- canvas.DrawBitmapInt(icon, kIconX, kIconY);
+ gfx::CanvasSkia canvas(icon.width(), icon.height(), false);
+ canvas.DrawBitmapInt(icon, 0, 0);
if (!badge.empty())
canvas.DrawBitmapInt(badge, kBadgeX, kBadgeY);
return canvas.ExtractBitmap();
@@ -425,9 +468,10 @@ void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) {
refreshing_menu_ = true;
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
cros->RequestWifiScan();
- cros->UpdateSystemInfo();
- InitMenuItems();
- network_menu_->Rebuild();
+
+ // Menu contents are built in UpdateMenu, which is called
+ // when NetworkChagned is called.
+
// Restore menu width, if it was set up.
// NOTE: width isn't checked for correctness here since all width-related
// logic implemented inside |network_menu_|.
@@ -446,75 +490,153 @@ void NetworkMenu::InitMenuItems() {
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ bool no_networks = true;
+ string16 label;
+
// Ethernet
- bool ethernet_connected = cros->ethernet_connected();
- bool ethernet_connecting = cros->ethernet_connecting();
- string16 label = l10n_util::GetStringUTF16(
- IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
- SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
- SkBitmap badge = ethernet_connecting || ethernet_connected ?
- SkBitmap() : *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED);
- int flag = FLAG_ETHERNET;
- if (ethernet_connecting || ethernet_connected)
- flag |= FLAG_ASSOCIATED;
- menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
- IconForDisplay(icon, badge), std::string(), flag));
-
- // Wifi
- const WifiNetworkVector& wifi_networks = cros->wifi_networks();
- const WifiNetwork& active_wifi = cros->wifi_network();
- // Wifi networks ssids.
- for (size_t i = 0; i < wifi_networks.size(); ++i) {
- label = ASCIIToUTF16(wifi_networks[i].name());
- SkBitmap icon = IconForNetworkStrength(wifi_networks[i].strength(), true);
- SkBitmap badge = wifi_networks[i].encrypted() ?
- *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE) : SkBitmap();
- flag = FLAG_WIFI;
- if (wifi_networks[i].service_path() == active_wifi.service_path())
+ bool ethernet_available = cros->ethernet_available();
+ if (ethernet_available) {
+ no_networks = false;
+ bool ethernet_connected = cros->ethernet_connected();
+ bool ethernet_connecting = cros->ethernet_connecting();
+
+ if (ethernet_connecting) {
+ label = l10n_util::GetStringFUTF16(
+ IDS_STATUSBAR_NETWORK_DEVICE_STATUS,
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET),
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING));
+ } else {
+ label = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
+ }
+ SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
+ SkBitmap badge = ethernet_connecting || ethernet_connected ?
+ SkBitmap() : *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED);
+ int flag = FLAG_ETHERNET;
+ if (ethernet_connecting || ethernet_connected)
flag |= FLAG_ASSOCIATED;
- menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
- IconForDisplay(icon, badge), wifi_networks[i].service_path(), flag));
+ menu_items_.push_back(
+ MenuItem(menus::MenuModel::TYPE_COMMAND, label,
+ IconForDisplay(icon, badge), std::string(), flag));
}
- // Cellular
- const CellularNetworkVector& cell_networks = cros->cellular_networks();
- const CellularNetwork& active_cellular = cros->cellular_network();
- // Cellular networks ssids.
- for (size_t i = 0; i < cell_networks.size(); ++i) {
- label = ASCIIToUTF16(cell_networks[i].name());
- SkBitmap icon = IconForNetworkStrength(cell_networks[i].strength(), true);
- // TODO(chocobo): Check cellular network 3g/edge.
- SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G);
-// SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE);
- flag = FLAG_CELLULAR;
- if (cell_networks[i].service_path() == active_cellular.service_path())
- flag |= FLAG_ASSOCIATED;
- menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
- IconForDisplay(icon, badge), cell_networks[i].service_path(), flag));
+ // Wifi Networks
+ bool wifi_available = cros->wifi_available();
+ if (wifi_available) {
+ const WifiNetworkVector& wifi_networks = cros->wifi_networks();
+ const WifiNetwork* active_wifi = cros->wifi_network();
+
+ if (wifi_networks.size() > 0) {
+ no_networks = false;
+ // Separator
+ menu_items_.push_back(MenuItem());
+ }
+ // List Wifi networks.
+ for (size_t i = 0; i < wifi_networks.size(); ++i) {
+ if (wifi_networks[i]->connecting()) {
+ label = l10n_util::GetStringFUTF16(
+ IDS_STATUSBAR_NETWORK_DEVICE_STATUS,
+ ASCIIToUTF16(wifi_networks[i]->name()),
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING));
+ } else {
+ label = ASCIIToUTF16(wifi_networks[i]->name());
+ }
+ SkBitmap icon = IconForNetworkStrength(wifi_networks[i]->strength(),
+ true);
+ SkBitmap badge = wifi_networks[i]->encrypted() ?
+ *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE) : SkBitmap();
+ int flag = FLAG_WIFI;
+ if (active_wifi
+ && wifi_networks[i]->service_path() == active_wifi->service_path())
+ flag |= FLAG_ASSOCIATED;
+ menu_items_.push_back(
+ MenuItem(menus::MenuModel::TYPE_COMMAND, label,
+ IconForDisplay(icon, badge),
+ wifi_networks[i]->service_path(), flag));
+ }
+ }
+
+ // Cellular Networks
+ bool cellular_available = cros->cellular_available();
+ if (cellular_available) {
+ const CellularNetworkVector& cell_networks = cros->cellular_networks();
+ const CellularNetwork* active_cellular = cros->cellular_network();
+
+ bool separator_added = false;
+ // List Cellular networks.
+ for (size_t i = 0; i < cell_networks.size(); ++i) {
+ chromeos::ActivationState activation_state =
+ cell_networks[i]->activation_state();
+ if (activation_state == ACTIVATION_STATE_NOT_ACTIVATED) {
+ // If we are on the OOBE/login screen, do not show activating 3G option.
+ if (!IsBrowserMode())
+ continue;
+ label = l10n_util::GetStringFUTF16(
+ IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE,
+ ASCIIToUTF16(cell_networks[i]->name()));
+ } else if (activation_state == ACTIVATION_STATE_PARTIALLY_ACTIVATED ||
+ activation_state == ACTIVATION_STATE_ACTIVATING) {
+ label = l10n_util::GetStringFUTF16(
+ IDS_STATUSBAR_NETWORK_DEVICE_STATUS,
+ ASCIIToUTF16(cell_networks[i]->name()),
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATING));
+ } else if (cell_networks[i]->connecting()) {
+ label = l10n_util::GetStringFUTF16(
+ IDS_STATUSBAR_NETWORK_DEVICE_STATUS,
+ ASCIIToUTF16(cell_networks[i]->name()),
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING));
+ } else {
+ label = ASCIIToUTF16(cell_networks[i]->name());
+ }
+
+ // First add a separator if necessary.
+ if (!separator_added) {
+ no_networks = false;
+ menu_items_.push_back(MenuItem());
+ separator_added = true;
+ }
+
+ SkBitmap icon = IconForNetworkStrength(cell_networks[i]->strength(),
+ true);
+ SkBitmap badge = BadgeForNetworkTechnology(cell_networks[i]);
+ int flag = FLAG_CELLULAR;
+ if (active_cellular &&
+ cell_networks[i]->service_path() ==
+ active_cellular->service_path() &&
+ (cell_networks[i]->connecting() || cell_networks[i]->connected()))
+ flag |= FLAG_ASSOCIATED;
+ menu_items_.push_back(
+ MenuItem(menus::MenuModel::TYPE_COMMAND, label,
+ IconForDisplay(icon, badge),
+ cell_networks[i]->service_path(), flag));
+ }
}
// No networks available message.
- if (wifi_networks.empty() && cell_networks.empty()) {
+ if (no_networks) {
label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_MENU_ITEM_INDENT,
l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE));
menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
SkBitmap(), std::string(), FLAG_DISABLED));
}
- // Other networks
- menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND,
- l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_OTHER_NETWORKS),
- IconForDisplay(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0),
- SkBitmap()),
- std::string(), FLAG_OTHER_NETWORK));
+ // Add network.
+ if (wifi_available) {
+ // Separator
+ menu_items_.push_back(MenuItem());
- bool wifi_available = cros->wifi_available();
- bool cellular_available = cros->cellular_available();
+ menu_items_.push_back(MenuItem(
+ menus::MenuModel::TYPE_COMMAND,
+ l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_OTHER_NETWORKS),
+ IconForDisplay(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK),
+ SkBitmap()),
+ std::string(), FLAG_OTHER_NETWORK));
+ }
+
+ // Enable / disable wireless.
if (wifi_available || cellular_available) {
- // Separator.
+ // Separator
menu_items_.push_back(MenuItem());
- // Turn Wifi Off. (only if wifi available)
if (wifi_available) {
int id = cros->wifi_enabled() ? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE :
IDS_STATUSBAR_NETWORK_DEVICE_ENABLE;
@@ -524,10 +646,9 @@ void NetworkMenu::InitMenuItems() {
SkBitmap(), std::string(), FLAG_TOGGLE_WIFI));
}
- // Turn Cellular Off. (only if cellular available)
if (cellular_available) {
int id = cros->cellular_enabled() ? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE :
- IDS_STATUSBAR_NETWORK_DEVICE_ENABLE;
+ IDS_STATUSBAR_NETWORK_DEVICE_ENABLE;
label = l10n_util::GetStringFUTF16(id,
l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR));
menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
@@ -535,40 +656,59 @@ void NetworkMenu::InitMenuItems() {
}
}
- // TODO(chocobo): Uncomment once we figure out how to do offline mode.
// Offline mode.
-// menu_items_.push_back(MenuItem(cros->offline_mode() ?
-// menus::MenuModel::TYPE_CHECK : menus::MenuModel::TYPE_COMMAND,
-// l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE),
-// SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE));
+ // TODO(chocobo): Uncomment once we figure out how to do offline mode.
+ // menu_items_.push_back(MenuItem(cros->offline_mode() ?
+ // menus::MenuModel::TYPE_CHECK : menus::MenuModel::TYPE_COMMAND,
+ // l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OFFLINE_MODE),
+ // SkBitmap(), std::string(), FLAG_TOGGLE_OFFLINE));
- if (cros->Connected() || ShouldOpenButtonOptions()) {
- // Separator.
+ bool connected = cros->Connected(); // alwasy call for test expectations.
+ bool show_ip = !MenuUI::IsEnabled() && connected;
+ bool show_settings = ShouldOpenButtonOptions();
+
+ // Separator.
+ if (show_ip || show_settings) {
menu_items_.push_back(MenuItem());
+ }
- // Network settings.
- if (ShouldOpenButtonOptions()) {
- label =
- l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG);
- menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
- SkBitmap(), std::string(), FLAG_OPTIONS));
+ // IP Address
+ if (show_ip) {
+ menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND,
+ ASCIIToUTF16(cros->IPAddress()), SkBitmap(),
+ std::string(), FLAG_DISABLED));
+ }
+
+ // Network settings.
+ if (show_settings) {
+ if (IsBrowserMode()) {
+ label = l10n_util::GetStringUTF16(
+ IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG);
+ } else {
+ label = l10n_util::GetStringUTF16(
+ IDS_STATUSBAR_NETWORK_OPEN_PROXY_SETTINGS_DIALOG);
}
+ menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
+ SkBitmap(), std::string(), FLAG_OPTIONS));
}
}
-void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) const {
+void NetworkMenu::ShowTabbedNetworkSettings(const Network* network) const {
+ DCHECK(network);
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return;
std::string page = StringPrintf("%s?servicePath=%s&networkType=%d",
chrome::kInternetOptionsSubPage,
- EscapeUrlEncodedData(network.service_path()).c_str(),
- network.type());
+ EscapeUrlEncodedData(network->service_path()).c_str(),
+ network->type());
browser->ShowOptionsTab(page);
}
-// TODO(stevenjb): deprecate this once we've committed to the embedded
-// menu UI and fully deprecated NetworkConfigView.
+// TODO(stevenjb): deprecate this once we've committed to tabbed settings
+// and the embedded menu UI (and fully deprecated NetworkConfigView).
+// Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI,
+// otherwise show NetworkConfigView only to get passwords when not connected.
void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view,
bool focus_login) const {
view->set_browser_mode(IsBrowserMode());
@@ -580,28 +720,40 @@ void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view,
view->SetLoginTextfieldFocus();
}
-void NetworkMenu::ShowWifi(const WifiNetwork& wifi, bool focus_login) const{
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableTabbedOptions)) {
+void NetworkMenu::ShowWifi(const WifiNetwork* wifi, bool focus_login) const {
+ DCHECK(wifi);
+ if (use_settings_ui_ &&
+ (MenuUI::IsEnabled() || wifi->connected() || wifi->connecting())) {
ShowTabbedNetworkSettings(wifi);
} else {
ShowNetworkConfigView(new NetworkConfigView(wifi, true), focus_login);
}
}
-void NetworkMenu::ShowCellular(const CellularNetwork& cellular,
+void NetworkMenu::ShowCellular(const CellularNetwork* cellular,
bool focus_login) const {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableTabbedOptions)) {
+ DCHECK(cellular);
+ if (use_settings_ui_ &&
+ (MenuUI::IsEnabled() || cellular->connected() ||
+ cellular->connecting())) {
ShowTabbedNetworkSettings(cellular);
} else {
ShowNetworkConfigView(new NetworkConfigView(cellular), focus_login);
}
}
-void NetworkMenu::ShowEthernet(const EthernetNetwork& ethernet) const {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableTabbedOptions)) {
+void NetworkMenu::ActivateCellular(const CellularNetwork* cellular) const {
+ DCHECK(cellular);
+ Browser* browser = BrowserList::GetLastActive();
+ // TODO(stevenjb) : specify which service to activate.
+ browser->ShowSingletonTab(GURL(chrome::kChromeUIMobileSetupURL));
+}
+
+void NetworkMenu::ShowEthernet(const EthernetNetwork* ethernet) const {
+ DCHECK(ethernet);
+ if (use_settings_ui_ &&
+ (MenuUI::IsEnabled() || ethernet->connected() ||
+ ethernet->connecting())) {
ShowTabbedNetworkSettings(ethernet);
} else {
ShowNetworkConfigView(new NetworkConfigView(ethernet), false);
@@ -609,8 +761,7 @@ void NetworkMenu::ShowEthernet(const EthernetNetwork& ethernet) const {
}
void NetworkMenu::ShowOther() const {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableTabbedOptions)) {
+ if (use_settings_ui_ && MenuUI::IsEnabled()) {
Browser* browser = BrowserList::GetLastActive();
if (browser) {
std::string page = StringPrintf("%s?networkType=%d",
diff --git a/chrome/browser/chromeos/status/network_menu.h b/chrome/browser/chromeos/status/network_menu.h
index 3c8d322..28f4d68 100644
--- a/chrome/browser/chromeos/status/network_menu.h
+++ b/chrome/browser/chromeos/status/network_menu.h
@@ -61,6 +61,8 @@ class NetworkMenu : public views::ViewMenuDelegate,
std::string message;
// IP address (if network is active, empty otherwise)
std::string ip_address;
+ // Remembered passphrase.
+ std::string passphrase;
// true if the network requires a passphrase.
bool need_passphrase;
// true if the network is currently remembered.
@@ -113,11 +115,12 @@ 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(CellularNetwork cellular);
-
+ 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);
@@ -125,11 +128,11 @@ class NetworkMenu : public views::ViewMenuDelegate,
protected:
virtual bool IsBrowserMode() const = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0;
- virtual void OpenButtonOptions() const = 0;
+ virtual void OpenButtonOptions() = 0;
virtual bool ShouldOpenButtonOptions() const = 0;
// Notify subclasses that connection to |network| was initiated.
- virtual void OnConnectNetwork(const Network& network,
+ virtual void OnConnectNetwork(const Network* network,
SkBitmap selected_icon_) {}
// Update the menu (e.g. when the network list or status has changed).
void UpdateMenu();
@@ -176,16 +179,17 @@ class NetworkMenu : public views::ViewMenuDelegate,
void InitMenuItems();
// Shows network details in DOM UI options window.
- void ShowTabbedNetworkSettings(const Network& network) const;
+ void ShowTabbedNetworkSettings(const Network* network) const;
// Show a NetworkConfigView modal dialog instance.
// TODO(stevenjb): deprecate this once all of the UI is embedded in the menu.
void ShowNetworkConfigView(NetworkConfigView* view, bool focus_login) const;
// Wrappers for the ShowNetworkConfigView / ShowTabbedNetworkSettings.
- void ShowWifi(const WifiNetwork& wifi, bool focus_login) const;
- void ShowCellular(const CellularNetwork& cellular, bool focus_login) const;
- void ShowEthernet(const EthernetNetwork& ethernet) const;
+ void ShowWifi(const WifiNetwork* wifi, bool focus_login) const;
+ void ShowCellular(const CellularNetwork* cellular, bool focus_login) const;
+ void ActivateCellular(const CellularNetwork* cellular) const;
+ void ShowEthernet(const EthernetNetwork* ethernet) const;
void ShowOther() const;
// Set to true if we are currently refreshing the menu.
@@ -209,6 +213,9 @@ class NetworkMenu : public views::ViewMenuDelegate,
// Holds minimum width or -1 if it wasn't set up.
int min_width_;
+ // If true, call into the settings UI for network configuration dialogs.
+ bool use_settings_ui_;
+
DISALLOW_COPY_AND_ASSIGN(NetworkMenu);
};
diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc
index 3a37df7..6d2486f 100644
--- a/chrome/browser/chromeos/status/network_menu_button.cc
+++ b/chrome/browser/chromeos/status/network_menu_button.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "gfx/canvas_skia.h"
+#include "gfx/skbitmap_operations.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "views/window/window.h"
@@ -33,13 +34,17 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
host_(host),
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) {
animation_connecting_.SetThrobDuration(kThrobDuration);
- animation_connecting_.SetTweenType(Tween::LINEAR);
- NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
- CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
+ animation_connecting_.SetTweenType(Tween::EASE_IN_OUT);
+ OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary());
+ CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
+ CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this);
}
NetworkMenuButton::~NetworkMenuButton() {
- CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
+ NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
+ netlib->RemoveNetworkManagerObserver(this);
+ netlib->RemoveObserverForAllNetworks(this);
+ netlib->RemoveCellularDataPlanObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
@@ -47,14 +52,16 @@ NetworkMenuButton::~NetworkMenuButton() {
void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
if (animation == &animation_connecting_) {
- // Figure out which image to draw. We want a value between 0-100.
- // 0 reperesents no signal and 100 represents full signal strength.
- int value = static_cast<int>(animation_connecting_.GetCurrentValue()*100.0);
- if (value < 0)
- value = 0;
- else if (value > 100)
- value = 100;
- SetIcon(IconForNetworkStrength(value, false));
+ // Draw animation of bars icon fading in and out.
+ // We are fading between 0 bars and a third of the opacity of 4 bars.
+ // Use the current value of the animation to calculate the alpha value
+ // of how transparent the icon is.
+ SetIcon(SkBitmapOperations::CreateBlendedBitmap(
+ *ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_STATUSBAR_NETWORK_BARS0),
+ *ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_STATUSBAR_NETWORK_BARS4),
+ animation_connecting_.GetCurrentValue() / 3));
SchedulePaint();
} else {
MenuButton::AnimationProgressed(animation);
@@ -64,100 +71,62 @@ void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, StatusAreaButton implementation:
-void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) {
- // If ethernet connected and not current connecting, then show ethernet
- // pressed icon. Otherwise, show the bars pressed icon.
- if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() &&
- !animation_connecting_.is_animating())
- canvas->DrawBitmapInt(IconForDisplay(
- *ResourceBundle::GetSharedInstance().
- GetBitmapNamed(IDR_STATUSBAR_NETWORK_WIRED_PRESSED), SkBitmap()),
- 0, 0);
- else
- canvas->DrawBitmapInt(IconForDisplay(
- *ResourceBundle::GetSharedInstance().
- GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS_PRESSED), SkBitmap()),
- 0, 0);
-}
-
void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
- canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 0, 0);
+ canvas->DrawBitmapInt(IconForDisplay(icon(), badge()),
+ horizontal_padding(), 0);
}
////////////////////////////////////////////////////////////////////////////////
-// NetworkMenuButton, NetworkLibrary::Observer implementation:
+// NetworkMenuButton, NetworkLibrary::NetworkManagerObserver implementation:
-void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
+void NetworkMenuButton::OnNetworkManagerChanged(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()) {
animation_connecting_.Reset();
animation_connecting_.StartThrobbing(std::numeric_limits<int>::max());
- SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1));
+ SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
}
std::string network_name = cros->wifi_connecting() ?
- cros->wifi_network().name() : cros->cellular_network().name();
+ cros->wifi_network()->name() : cros->cellular_network()->name();
+ bool configuring = cros->wifi_connecting() ?
+ cros->wifi_network()->configuring() :
+ cros->cellular_network()->configuring();
SetTooltipText(
- l10n_util::GetStringF(IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP,
- UTF8ToWide(network_name)));
+ l10n_util::GetStringF(configuring ?
+ IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP :
+ IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP,
+ UTF8ToWide(network_name)));
} else {
// Stop connecting animation since we are not connecting.
animation_connecting_.Stop();
-
- // 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 {
+ if (!cros->Connected()) {
SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
SetTooltipText(l10n_util::GetString(
IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
+ } else {
+ SetNetworkIcon(network);
}
}
-
- if (!cros->Connected() && !cros->Connecting()) {
- SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED));
- } else if (!cros->ethernet_connected() && !cros->wifi_connected() &&
- (cros->cellular_connecting() || cros->cellular_connected())) {
- int id = IDR_STATUSBAR_NETWORK_3G;
- switch (cros->cellular_network().data_left()) {
- case CellularNetwork::DATA_NONE:
- case CellularNetwork::DATA_VERY_LOW:
- id = IDR_STATUSBAR_NETWORK_3G_VLOWDATA;
- break;
- case CellularNetwork::DATA_LOW:
- id = IDR_STATUSBAR_NETWORK_3G_LOWDATA;
- break;
- case CellularNetwork::DATA_NORMAL:
- id = IDR_STATUSBAR_NETWORK_3G;
- break;
- }
- SetBadge(*rb.GetBitmapNamed(id));
- } else {
- SetBadge(SkBitmap());
- }
+ SetNetworkBadge(cros, network);
} else {
SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING));
@@ -169,13 +138,29 @@ void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
UpdateMenu();
}
-void NetworkMenuButton::CellularDataPlanChanged(NetworkLibrary* cros) {
- // Call NetworkChanged which will update the icon.
- NetworkChanged(cros);
+////////////////////////////////////////////////////////////////////////////////
+// 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);
+ } 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();
}
-void NetworkMenuButton::SetBadge(const SkBitmap& badge) {
- badge_ = badge;
+void NetworkMenuButton::OnCellularDataPlanChanged(NetworkLibrary* cros) {
+ // Call OnNetworkManagerChanged which will update the icon.
+ OnNetworkManagerChanged(cros);
}
////////////////////////////////////////////////////////////////////////////////
@@ -189,7 +174,7 @@ gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const {
return host_->GetNativeWindow();
}
-void NetworkMenuButton::OpenButtonOptions() const {
+void NetworkMenuButton::OpenButtonOptions() {
host_->OpenButtonOptions(this);
}
@@ -197,4 +182,54 @@ 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 79c5cdb..208efe2 100644
--- a/chrome/browser/chromeos/status/network_menu_button.h
+++ b/chrome/browser/chromeos/status/network_menu_button.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
#pragma once
+#include <string>
+
#include "app/throb_animation.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros/network_library.h"
@@ -46,7 +48,9 @@ class StatusAreaHost;
// The label will be BOLD if the network is currently connected.
class NetworkMenuButton : public StatusAreaButton,
public NetworkMenu,
- public NetworkLibrary::Observer {
+ public NetworkLibrary::NetworkManagerObserver,
+ public NetworkLibrary::NetworkObserver,
+ public NetworkLibrary::CellularDataPlanObserver {
public:
explicit NetworkMenuButton(StatusAreaHost* host);
virtual ~NetworkMenuButton();
@@ -54,26 +58,31 @@ class NetworkMenuButton : public StatusAreaButton,
// AnimationDelegate implementation.
virtual void AnimationProgressed(const Animation* animation);
- // NetworkLibrary::Observer implementation.
- virtual void NetworkChanged(NetworkLibrary* obj);
- virtual void CellularDataPlanChanged(NetworkLibrary* obj);
+ // 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);
// Sets the badge icon.
- void SetBadge(const SkBitmap& badge);
+ void SetBadge(const SkBitmap& badge) { badge_ = badge; }
SkBitmap badge() const { return badge_; }
protected:
// StatusAreaButton implementation.
- virtual void DrawPressed(gfx::Canvas* canvas);
virtual void DrawIcon(gfx::Canvas* canvas);
// NetworkMenu implementation:
virtual bool IsBrowserMode() const;
virtual gfx::NativeWindow GetNativeWindow() const;
- virtual void OpenButtonOptions() const;
+ virtual void OpenButtonOptions();
virtual bool ShouldOpenButtonOptions() const;
private:
+ void SetNetworkIcon(const Network* network);
+ void SetNetworkBadge(NetworkLibrary* cros, const Network* network);
+
// The status area host,
StatusAreaHost* host_;
@@ -86,6 +95,10 @@ 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);
};
diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc
index de942cb..e6adcdc 100644
--- a/chrome/browser/chromeos/status/power_menu_button.cc
+++ b/chrome/browser/chromeos/status/power_menu_button.cc
@@ -20,7 +20,7 @@ namespace chromeos {
// PowerMenuButton
// static
-const int PowerMenuButton::kNumPowerImages = 12;
+const int PowerMenuButton::kNumPowerImages = 16;
PowerMenuButton::PowerMenuButton()
: StatusAreaButton(this),
@@ -110,21 +110,6 @@ void PowerMenuButton::PowerChanged(PowerLibrary* obj) {
////////////////////////////////////////////////////////////////////////////////
// PowerMenuButton, StatusAreaButton implementation:
-void PowerMenuButton::DrawPressed(gfx::Canvas* canvas) {
- DrawPowerIcon(canvas, *ResourceBundle::GetSharedInstance().
- GetBitmapNamed(IDR_STATUSBAR_BATTERY_PRESSED));
-}
-
-void PowerMenuButton::DrawIcon(gfx::Canvas* canvas) {
- DrawPowerIcon(canvas, icon());
-}
-
-void PowerMenuButton::DrawPowerIcon(gfx::Canvas* canvas, SkBitmap icon) {
- // Draw the battery icon 5 pixels down to center it.
- static const int kIconVerticalPadding = 5;
- canvas->DrawBitmapInt(icon, 0, kIconVerticalPadding);
-}
-
void PowerMenuButton::UpdateIconAndLabelInfo() {
PowerLibrary* cros = CrosLibrary::Get()->GetPowerLibrary();
if (!cros)
@@ -168,6 +153,10 @@ void PowerMenuButton::UpdateIconAndLabelInfo() {
IDR_STATUSBAR_BATTERY_CHARGING_10,
IDR_STATUSBAR_BATTERY_CHARGING_11,
IDR_STATUSBAR_BATTERY_CHARGING_12,
+ IDR_STATUSBAR_BATTERY_CHARGING_13,
+ IDR_STATUSBAR_BATTERY_CHARGING_14,
+ IDR_STATUSBAR_BATTERY_CHARGING_15,
+ IDR_STATUSBAR_BATTERY_CHARGING_16,
};
static const int kDischargingImages[kNumPowerImages] = {
IDR_STATUSBAR_BATTERY_DISCHARGING_1,
@@ -182,6 +171,10 @@ void PowerMenuButton::UpdateIconAndLabelInfo() {
IDR_STATUSBAR_BATTERY_DISCHARGING_10,
IDR_STATUSBAR_BATTERY_DISCHARGING_11,
IDR_STATUSBAR_BATTERY_DISCHARGING_12,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_13,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_14,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_15,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_16,
};
int index = static_cast<int>(battery_percentage_ / 100.0 *
diff --git a/chrome/browser/chromeos/status/power_menu_button.h b/chrome/browser/chromeos/status/power_menu_button.h
index 7f27333..b3503e8 100644
--- a/chrome/browser/chromeos/status/power_menu_button.h
+++ b/chrome/browser/chromeos/status/power_menu_button.h
@@ -57,17 +57,12 @@ class PowerMenuButton : public StatusAreaButton,
int icon_id() const { return icon_id_; }
protected:
- // StatusAreaButton implementation.
- virtual void DrawPressed(gfx::Canvas* canvas);
- virtual void DrawIcon(gfx::Canvas* canvas);
+ virtual int icon_width() { return 26; }
private:
// views::ViewMenuDelegate implementation.
virtual void RunMenu(views::View* source, const gfx::Point& pt);
- // This method will draw the |icon| in the appropriate place on the |canvas|.
- void DrawPowerIcon(gfx::Canvas* canvas, SkBitmap icon);
-
// Update the power icon and menu label info depending on the power status.
void UpdateIconAndLabelInfo();
diff --git a/chrome/browser/chromeos/status/power_menu_button_browsertest.cc b/chrome/browser/chromeos/status/power_menu_button_browsertest.cc
index 66042fd..9e383bc 100644
--- a/chrome/browser/chromeos/status/power_menu_button_browsertest.cc
+++ b/chrome/browser/chromeos/status/power_menu_button_browsertest.cc
@@ -93,7 +93,7 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargedTest) {
}
IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
- const int NUM_TIMES = 12; // 6 + 8*12 = 102
+ const int NUM_TIMES = 16;
EXPECT_CALL(*mock_power_library_, battery_is_present())
.Times(NUM_TIMES)
.WillRepeatedly((Return(true)))
@@ -115,7 +115,7 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
.WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
.RetiresOnSaturation();
- // Test the 12 battery charging states.
+ // Test the 16 battery charging states.
// NOTE: Use an array rather than just calculating a resource number to avoid
// creating implicit ordering dependencies on the resource values.
static const int kChargingImages[] = {
@@ -131,9 +131,13 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
IDR_STATUSBAR_BATTERY_CHARGING_10,
IDR_STATUSBAR_BATTERY_CHARGING_11,
IDR_STATUSBAR_BATTERY_CHARGING_12,
+ IDR_STATUSBAR_BATTERY_CHARGING_13,
+ IDR_STATUSBAR_BATTERY_CHARGING_14,
+ IDR_STATUSBAR_BATTERY_CHARGING_15,
+ IDR_STATUSBAR_BATTERY_CHARGING_16,
};
size_t id = 0;
- for (float percent = 6.0; percent < 100.0; percent += 8.0) {
+ for (float percent = 6.0; percent < 100.0; percent += 6.0) {
EXPECT_CALL(*mock_power_library_, battery_percentage())
.WillOnce((Return(percent)))
.RetiresOnSaturation();
@@ -144,7 +148,7 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryChargingTest) {
}
IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) {
- const int NUM_TIMES = 12; // 6 + 8*12 = 102
+ const int NUM_TIMES = 16;
EXPECT_CALL(*mock_power_library_, battery_is_present())
.Times(NUM_TIMES)
.WillRepeatedly((Return(true)))
@@ -166,7 +170,7 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) {
.WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))))
.RetiresOnSaturation();
- // Test the 12 battery discharing states.
+ // Test the 16 battery discharing states.
// NOTE: Use an array rather than just calculating a resource number to avoid
// creating implicit ordering dependencies on the resource values.
static const int kDischargingImages[] = {
@@ -182,9 +186,13 @@ IN_PROC_BROWSER_TEST_F(PowerMenuButtonTest, BatteryDischargingTest) {
IDR_STATUSBAR_BATTERY_DISCHARGING_10,
IDR_STATUSBAR_BATTERY_DISCHARGING_11,
IDR_STATUSBAR_BATTERY_DISCHARGING_12,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_13,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_14,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_15,
+ IDR_STATUSBAR_BATTERY_DISCHARGING_16,
};
size_t id = 0;
- for (float percent = 6.0; percent < 100.0; percent += 8.0) {
+ for (float percent = 6.0; percent < 100.0; percent += 6.0) {
EXPECT_CALL(*mock_power_library_, battery_percentage())
.WillOnce((Return(percent)))
.RetiresOnSaturation();
diff --git a/chrome/browser/chromeos/status/status_area_button.cc b/chrome/browser/chromeos/status/status_area_button.cc
index d2c34e6..eb6c2d5 100644
--- a/chrome/browser/chromeos/status/status_area_button.cc
+++ b/chrome/browser/chromeos/status/status_area_button.cc
@@ -34,21 +34,15 @@ void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) {
if (use_menu_button_paint_) {
views::MenuButton::Paint(canvas, for_drag);
} else {
- if (state() == BS_PUSHED)
- DrawPressed(canvas);
-
DrawIcon(canvas);
PaintFocusBorder(canvas);
}
}
gfx::Size StatusAreaButton::GetPreferredSize() {
- // icons are 24x24
- static const int kIconWidth = 24;
- static const int kIconHeight = 24;
gfx::Insets insets = views::MenuButton::GetInsets();
- gfx::Size prefsize(kIconWidth + insets.width(),
- kIconHeight + insets.height());
+ gfx::Size prefsize(icon_width() + insets.width(),
+ icon_height() + insets.height());
// Adjusts size when use menu button paint.
if (use_menu_button_paint_) {
@@ -65,6 +59,9 @@ gfx::Size StatusAreaButton::GetPreferredSize() {
}
}
+ // Add padding.
+ prefsize.Enlarge(2 * horizontal_padding(), 0);
+
return prefsize;
}
@@ -81,7 +78,7 @@ void StatusAreaButton::SetText(const std::wstring& text) {
}
void StatusAreaButton::DrawIcon(gfx::Canvas* canvas) {
- canvas->DrawBitmapInt(icon(), 0, 0);
+ canvas->DrawBitmapInt(icon(), horizontal_padding(), 0);
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/status/status_area_button.h b/chrome/browser/chromeos/status/status_area_button.h
index 6d57178..cefc474 100644
--- a/chrome/browser/chromeos/status/status_area_button.h
+++ b/chrome/browser/chromeos/status/status_area_button.h
@@ -30,16 +30,19 @@ class StatusAreaButton : public views::MenuButton {
}
protected:
- // Draws the pressed icon. This is called before DrawIcon if the state is
- // pressed. Subclasses should override this method if they need to draw a
- // pressed icon.
- virtual void DrawPressed(gfx::Canvas* canvas) {}
-
// 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);
+ // Subclasses should override these methods to return the correct dimensions.
+ virtual int icon_height() { return 24; }
+ virtual int icon_width() { return 23; }
+
+ // Subclasses can override this method to return more or less padding.
+ // The padding is added to both the left and right side.
+ virtual int horizontal_padding() { return 1; }
+
// True if the button wants to use views::MenuButton drawings.
bool use_menu_button_paint_;
diff --git a/chrome/browser/chromeos/status/status_area_host.h b/chrome/browser/chromeos/status/status_area_host.h
index 7e86e67..7b7691e 100644
--- a/chrome/browser/chromeos/status/status_area_host.h
+++ b/chrome/browser/chromeos/status/status_area_host.h
@@ -33,7 +33,7 @@ class StatusAreaHost {
const views::View* button_view) const = 0;
// Opens options dialog related to the button specified.
- virtual void OpenButtonOptions(const views::View* button_view) const = 0;
+ virtual void OpenButtonOptions(const views::View* button_view) = 0;
// Executes browser command.
virtual void ExecuteBrowserCommand(int id) const = 0;
diff --git a/chrome/browser/chromeos/status/status_area_view.cc b/chrome/browser/chromeos/status/status_area_view.cc
index bd34685..6a89d42 100644
--- a/chrome/browser/chromeos/status/status_area_view.cc
+++ b/chrome/browser/chromeos/status/status_area_view.cc
@@ -17,7 +17,7 @@
namespace chromeos {
// Number of pixels to separate each icon.
-const int kSeparation = 6;
+const int kSeparation = 1;
StatusAreaView::StatusAreaView(StatusAreaHost* host)
: host_(host),
@@ -29,6 +29,10 @@ StatusAreaView::StatusAreaView(StatusAreaHost* host)
}
void StatusAreaView::Init() {
+ // Clock.
+ clock_view_ = new ClockMenuButton(host_);
+ AddChildView(clock_view_);
+
// InputMethod.
input_method_view_ = new InputMethodMenuButton(host_);
AddChildView(input_method_view_);
@@ -44,10 +48,6 @@ void StatusAreaView::Init() {
// Power.
power_view_ = new PowerMenuButton();
AddChildView(power_view_);
-
- // Clock.
- clock_view_ = new ClockMenuButton(host_);
- AddChildView(clock_view_);
}
gfx::Size StatusAreaView::GetPreferredSize() {
@@ -80,7 +80,8 @@ void StatusAreaView::Layout() {
// Put next in row horizontally, and center vertically.
cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height());
- cur_x += cur_size.width() + kSeparation;
+ if (cur_size.width() > 0)
+ cur_x += cur_size.width() + kSeparation;
}
}
}