diff options
author | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 18:40:00 +0000 |
---|---|---|
committer | chocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 18:40:00 +0000 |
commit | 58989e64342e17a630cf98a1c8efa514eba7c1ce (patch) | |
tree | 96a241b28bd24f2b6cef94e57306629c326761c6 /chrome/browser/chromeos/status | |
parent | 25252d649a2ffb210592e0356ea0cc38dd7747db (diff) | |
download | chromium_src-58989e64342e17a630cf98a1c8efa514eba7c1ce.zip chromium_src-58989e64342e17a630cf98a1c8efa514eba7c1ce.tar.gz chromium_src-58989e64342e17a630cf98a1c8efa514eba7c1ce.tar.bz2 |
New network icons for ChromeOS
TEST=none
BUGS=none
Review URL: http://codereview.chromium.org/634001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39462 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/status')
6 files changed, 109 insertions, 116 deletions
diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index 4cbb37c..dbeb0f6 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -22,48 +22,16 @@ namespace chromeos { // NetworkMenuButton // static -const int NetworkMenuButton::kNumWifiImages = 3; -const int NetworkMenuButton::kMinOpacity = 50; -const int NetworkMenuButton::kMaxOpacity = 256; +const int NetworkMenuButton::kNumWifiImages = 9; const int NetworkMenuButton::kThrobDuration = 1000; -SkBitmap* NetworkMenuButton::menu_wifi_icons_ = NULL; -SkBitmap* NetworkMenuButton::menu_wired_icon_ = NULL; -SkBitmap* NetworkMenuButton::menu_disconnected_icon_ = NULL; NetworkMenuButton::NetworkMenuButton(gfx::NativeWindow parent_window) : StatusAreaButton(this), ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)), parent_window_(parent_window), - ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST(animation_downloading_(this)), - ALLOW_THIS_IN_INITIALIZER_LIST(animation_uploading_(this)) { - // Initialize the static menu icons. - static bool initialized = false; - if (!initialized) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - menu_wired_icon_ = new SkBitmap(SkBitmapOperations::CreateInvertedBitmap( - *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED))); - menu_disconnected_icon_ = new SkBitmap( - SkBitmapOperations::CreateInvertedBitmap( - *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED))); - menu_wifi_icons_ = new SkBitmap[kNumWifiImages + 1]; - SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_DOT); - menu_wifi_icons_[0] = SkBitmapOperations::CreateInvertedBitmap(icon); - for (int i = 0; i < kNumWifiImages; i++) { - icon = SkBitmapOperations::CreateSuperimposedBitmap(icon, - *rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_UP1 + i)); - icon = SkBitmapOperations::CreateSuperimposedBitmap(icon, - *rb.GetBitmapNamed(IDR_STATUSBAR_WIFI_DOWN1 + i)); - menu_wifi_icons_[i + 1] = SkBitmapOperations::CreateInvertedBitmap(icon); - } - initialized = true; - } + ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetTweenType(SlideAnimation::NONE); - animation_downloading_.SetThrobDuration(kThrobDuration); - animation_downloading_.SetTweenType(SlideAnimation::NONE); - animation_uploading_.SetThrobDuration(kThrobDuration); - animation_uploading_.SetTweenType(SlideAnimation::NONE); NetworkChanged(NetworkLibrary::Get()); NetworkLibrary::Get()->AddObserver(this); } @@ -163,22 +131,59 @@ bool NetworkMenuButton::OnPasswordDialogAccept(const std::string& ssid, // NetworkMenuButton, AnimationDelegate implementation: void NetworkMenuButton::AnimationProgressed(const Animation* animation) { - if (animation == &animation_connecting_ || - animation == &animation_downloading_ || - animation == &animation_uploading_) + 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)); SchedulePaint(); - else + } else { MenuButton::AnimationProgressed(animation); + } } //////////////////////////////////////////////////////////////////////////////// // NetworkMenuButton, StatusAreaButton implementation: +void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { + // Draw the network icon 4 pixels down to center it. + // Because the status icon is 24x24 but the images are 24x16. + static const int kIconVerticalPadding = 4; + canvas->DrawBitmapInt(icon(), 0, kIconVerticalPadding); + + // Draw badge at (14,14) if there is one. + static const int x = 14; + static const int y = 14; + NetworkLibrary* cros = NetworkLibrary::Get(); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + if (cros->EnsureLoaded()) { + if (!cros->Connected()) { + canvas->DrawBitmapInt( + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED), x, y); + } else if (cros->cellular_connecting() || cros->cellular_connected()) { + // TODO(chocobo): Check cellular network 3g/edge. + canvas->DrawBitmapInt( + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G), x, y); +// canvas->DrawBitmapInt( +// *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE), x, y); + } + } else { + canvas->DrawBitmapInt( + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING), x, y); + } +} + // Override the DrawIcon method to draw the wifi icon. // The wifi icon is composed of 1 or more alpha-blended icons to show the // network strength. We also draw an animation for when there's upload/download // traffic. +/* TODO(chocobo): Add this code back in when UI is finalized. void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { + // First draw the base icon. canvas->DrawBitmapInt(icon(), 0, 0); @@ -261,43 +266,43 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { } } } - +*/ //////////////////////////////////////////////////////////////////////////////// // NetworkMenuButton, NetworkLibrary::Observer implementation: void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { - int id = IDR_STATUSBAR_WARNING; + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); if (cros->EnsureLoaded()) { - id = IDR_STATUSBAR_NETWORK_DISCONNECTED; - if (cros->wifi_connecting()) { + if (cros->wifi_connecting() || cros->cellular_connecting()) { // Start the connecting animation if not running. if (!animation_connecting_.IsAnimating()) { animation_connecting_.Reset(); animation_connecting_.StartThrobbing(std::numeric_limits<int>::max()); + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1)); } - // Stop network traffic animation when we are connecting. - animation_downloading_.Stop(); - animation_uploading_.Stop(); - - id = IDR_STATUSBAR_WIFI_DOT; } 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()) { - id = IDR_STATUSBAR_WIRED; - } else if (cros->wifi_connected()) { - id = IDR_STATUSBAR_WIFI_DOT; - } + if (cros->ethernet_connected()) + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED)); + else if (cros->wifi_connected()) + SetIcon(IconForNetworkStrength(cros->wifi_strength(), false)); + else if (cros->cellular_connected()) + SetIcon(IconForNetworkStrength(cros->cellular_strength(), false)); + else + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); } + } else { + SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); } - SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(id)); SchedulePaint(); } void NetworkMenuButton::NetworkTraffic(NetworkLibrary* cros, int traffic_type) { +/* TODO(chocobo): Add this code back in when network traffic UI is finalized. if (!cros->ethernet_connected() && cros->wifi_connected() && !cros->wifi_connecting()) { // For downloading/uploading animation, we want to force at least one cycle @@ -308,24 +313,21 @@ void NetworkMenuButton::NetworkTraffic(NetworkLibrary* cros, int traffic_type) { if (traffic_type & TRAFFIC_UPLOAD) animation_uploading_.StartThrobbing(2); } + */ } // static -SkBitmap NetworkMenuButton::IconForWifiStrength(int strength) { +SkBitmap NetworkMenuButton::IconForNetworkStrength(int strength, bool black) { // Compose wifi icon by superimposing various icons. int index = static_cast<int>(strength / 100.0 * - nextafter(static_cast<float>(kNumWifiImages + 1), 0)); + nextafter(static_cast<float>(kNumWifiImages), 0)); if (index < 0) index = 0; - if (index > kNumWifiImages) - index = kNumWifiImages; - return menu_wifi_icons_[index]; -} - -// static -SkBitmap NetworkMenuButton::IconForCellularStrength(int strength) { - // TODO(chocobo): need to switch to cellular icons when they are ready. - return IconForWifiStrength(strength); + if (index >= kNumWifiImages) + index = kNumWifiImages - 1; + int base = black ? IDR_STATUSBAR_NETWORK_BARS1_BLACK : + IDR_STATUSBAR_NETWORK_BARS1; + return *ResourceBundle::GetSharedInstance().GetBitmapNamed(base + index); } //////////////////////////////////////////////////////////////////////////////// @@ -344,9 +346,7 @@ void NetworkMenuButton::InitMenuItems() { menu_items_.clear(); // Populate our MenuItems with the current list of wifi networks. NetworkLibrary* cros = NetworkLibrary::Get(); - // If cros is not loaded, then have an empty menu. - if (!cros->EnsureLoaded()) - return; + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); bool offline_mode = cros->offline_mode(); @@ -363,8 +363,8 @@ void NetworkMenuButton::InitMenuItems() { l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI), l10n_util::GetStringUTF16(status)); SkBitmap icon = cros->wifi_connected() ? - IconForWifiStrength(cros->wifi_strength()) : - *menu_disconnected_icon_; + IconForNetworkStrength(cros->wifi_strength(), true) : + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED); menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, icon, WifiNetwork(), CellularNetwork(), FLAG_DISABLED)); @@ -419,8 +419,8 @@ void NetworkMenuButton::InitMenuItems() { l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR), l10n_util::GetStringUTF16(status)); icon = cros->cellular_connected() ? - IconForCellularStrength(cros->cellular_strength()) : - *menu_disconnected_icon_; + IconForNetworkStrength(cros->cellular_strength(), true) : + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED); menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, icon, WifiNetwork(), CellularNetwork(), FLAG_DISABLED)); @@ -473,8 +473,9 @@ void NetworkMenuButton::InitMenuItems() { label = l10n_util::GetStringFUTF16(IDS_STATUSBAR_NETWORK_DEVICE_STATUS, l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET), l10n_util::GetStringUTF16(status)); - icon = cros->ethernet_connected() ? *menu_wired_icon_ : - *menu_disconnected_icon_; + icon = cros->ethernet_connected() ? + *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK) : + *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED); menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, icon, WifiNetwork(), CellularNetwork(), FLAG_DISABLED)); diff --git a/chrome/browser/chromeos/status/network_menu_button.h b/chrome/browser/chromeos/status/network_menu_button.h index 1ae4c80..1ebd3db4 100644 --- a/chrome/browser/chromeos/status/network_menu_button.h +++ b/chrome/browser/chromeos/status/network_menu_button.h @@ -128,9 +128,10 @@ class NetworkMenuButton : public StatusAreaButton, }; typedef std::vector<MenuItem> MenuItemVector; - static SkBitmap IconForWifiStrength(int strength); - - static SkBitmap IconForCellularStrength(int strength); + // Returns the Icon for a network strength between 0 and 100. + // |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); // views::ViewMenuDelegate implementation. virtual void RunMenu(views::View* source, const gfx::Point& pt); @@ -144,21 +145,6 @@ class NetworkMenuButton : public StatusAreaButton, // The number of wifi strength images. static const int kNumWifiImages; - // The minimum opacity of the wifi bars. - static const int kMinOpacity; - - // The maximum opacity of the wifi bars. - static const int kMaxOpacity; - - // The wifi icons used in menu. These are built on initialization. - static SkBitmap* menu_wifi_icons_; - - // The ethernet icon used in menu, - static SkBitmap* menu_wired_icon_; - - // The disconnected icon used in menu, - static SkBitmap* menu_disconnected_icon_; - // Our menu items. MenuItemVector menu_items_; @@ -174,12 +160,6 @@ class NetworkMenuButton : public StatusAreaButton, // The throb animation that does the wifi connecting animation. ThrobAnimation animation_connecting_; - // The throb animation that does the downloading animation. - ThrobAnimation animation_downloading_; - - // The throb animation that does the uploading animation. - ThrobAnimation animation_uploading_; - // The duration of the icon throbbing in milliseconds. static const int kThrobDuration; diff --git a/chrome/browser/chromeos/status/power_menu_button.cc b/chrome/browser/chromeos/status/power_menu_button.cc index de3eddb..b0345ee 100644 --- a/chrome/browser/chromeos/status/power_menu_button.cc +++ b/chrome/browser/chromeos/status/power_menu_button.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/status/power_menu_button.h" +#include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/time.h" @@ -16,7 +17,7 @@ namespace chromeos { // PowerMenuButton // static -const int PowerMenuButton::kNumPowerImages = 16; +const int PowerMenuButton::kNumPowerImages = 12; PowerMenuButton::PowerMenuButton() : StatusAreaButton(this), @@ -99,6 +100,17 @@ void PowerMenuButton::PowerChanged(PowerLibrary* obj) { UpdateIcon(); } +//////////////////////////////////////////////////////////////////////////////// +// PowerMenuButton, StatusAreaButton implementation: + +void PowerMenuButton::DrawIcon(gfx::Canvas* canvas) { + // Draw the battery icon 6 pixels down to center it. + // Because the status icon is 24x24 but the images are 24x16. + // But since the images are shifted up by 4 pixels, we draw at 6 pixels down. + static const int kIconVerticalPadding = 6; + canvas->DrawBitmapInt(icon(), 0, kIconVerticalPadding); +} + void PowerMenuButton::UpdateIcon() { PowerLibrary* cros = PowerLibrary::Get(); int id = IDR_STATUSBAR_BATTERY_UNKNOWN; diff --git a/chrome/browser/chromeos/status/power_menu_button.h b/chrome/browser/chromeos/status/power_menu_button.h index 5ac9e0b..1828f1f 100644 --- a/chrome/browser/chromeos/status/power_menu_button.h +++ b/chrome/browser/chromeos/status/power_menu_button.h @@ -46,6 +46,10 @@ class PowerMenuButton : public StatusAreaButton, // PowerLibrary::Observer implementation. virtual void PowerChanged(PowerLibrary* obj); + protected: + // StatusAreaButton implementation. + virtual void DrawIcon(gfx::Canvas* canvas); + private: // views::ViewMenuDelegate implementation. virtual void RunMenu(views::View* source, const gfx::Point& pt); diff --git a/chrome/browser/chromeos/status/status_area_button.cc b/chrome/browser/chromeos/status/status_area_button.cc index 9a4a0f3..d779eea 100644 --- a/chrome/browser/chromeos/status/status_area_button.cc +++ b/chrome/browser/chromeos/status/status_area_button.cc @@ -23,28 +23,23 @@ StatusAreaButton::StatusAreaButton(views::ViewMenuDelegate* menu_delegate) } void StatusAreaButton::Paint(gfx::Canvas* canvas, bool for_drag) { - int bitmap_id; - - switch (state()) { - case BS_NORMAL: - bitmap_id = IDR_STATUSBAR_CONTAINER; - break; - case BS_HOT: - bitmap_id = IDR_STATUSBAR_CONTAINER_HOVER; - break; - case BS_PUSHED: - bitmap_id = IDR_STATUSBAR_CONTAINER_PRESSED; - break; - default: - bitmap_id = IDR_STATUSBAR_CONTAINER; - NOTREACHED(); + if (state() == BS_PUSHED) { + canvas->DrawBitmapInt(*ResourceBundle::GetSharedInstance(). + GetBitmapNamed(IDR_STATUSBAR_PRESSED), 0, 0); } - SkBitmap* container = - ResourceBundle::GetSharedInstance().GetBitmapNamed(bitmap_id); - canvas->DrawBitmapInt(*container, 0, 0); DrawIcon(canvas); } +gfx::Size StatusAreaButton::GetPreferredSize() { + // icons are 24x24 + static const int kIconWidth = 24; + static const int kIconHeight = 24; + gfx::Insets insets = GetInsets(); + gfx::Size prefsize(kIconWidth + insets.width(), + kIconHeight + insets.height()); + return prefsize; +} + void StatusAreaButton::DrawIcon(gfx::Canvas* canvas) { canvas->DrawBitmapInt(icon(), 0, 0); } diff --git a/chrome/browser/chromeos/status/status_area_button.h b/chrome/browser/chromeos/status/status_area_button.h index 308f601..cb7728d 100644 --- a/chrome/browser/chromeos/status/status_area_button.h +++ b/chrome/browser/chromeos/status/status_area_button.h @@ -17,6 +17,7 @@ class StatusAreaButton : public views::MenuButton { explicit StatusAreaButton(views::ViewMenuDelegate* menu_delegate); virtual ~StatusAreaButton() {} virtual void Paint(gfx::Canvas* canvas, bool for_drag); + virtual gfx::Size GetPreferredSize(); protected: // Draws the icon for this status area button on the canvas. |