summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/ash_strings.grd3
-rw-r--r--ash/system/chromeos/network/network_icon.cc357
-rw-r--r--ash/system/chromeos/network/network_icon.h32
-rw-r--r--ash/system/chromeos/network/network_icon_animation.cc11
-rw-r--r--ash/system/chromeos/network/network_icon_animation.h6
-rw-r--r--ash/system/chromeos/network/network_state_list_detailed_view.cc333
-rw-r--r--ash/system/chromeos/network/network_state_list_detailed_view.h27
-rw-r--r--ash/system/chromeos/network/tray_network.cc265
-rw-r--r--ash/system/chromeos/network/tray_network.h34
-rw-r--r--ash/system/chromeos/network/tray_network_state_observer.cc14
-rw-r--r--ash/system/chromeos/network/tray_network_state_observer.h3
11 files changed, 351 insertions, 734 deletions
diff --git a/ash/ash_strings.grd b/ash/ash_strings.grd
index 26b02dd..f60c11b 100644
--- a/ash/ash_strings.grd
+++ b/ash/ash_strings.grd
@@ -338,9 +338,6 @@ Press Ctrl+Alt+Z to disable.
<message name="IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR" desc="Message for the status area when initializing the cellular device.">
Initializing cellular modem...
</message>
- <message name="IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING" desc="Message when scanning for cellular networks">
- Searching for cellular networks...
- </message>
<message name="IDS_ASH_STATUS_TRAY_SMS" desc="The label used in the status tray for SMS.">
SMS
</message>
diff --git a/ash/system/chromeos/network/network_icon.cc b/ash/system/chromeos/network/network_icon.cc
index 2a90d26..da2ff25 100644
--- a/ash/system/chromeos/network/network_icon.cc
+++ b/ash/system/chromeos/network/network_icon.cc
@@ -7,14 +7,11 @@
#include "ash/shell.h"
#include "ash/system/chromeos/network/network_icon_animation.h"
#include "ash/system/chromeos/network/network_icon_animation_observer.h"
-#include "base/utf_string_conversions.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "grit/ash_resources.h"
-#include "grit/ash_strings.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
-#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia_operations.h"
@@ -32,25 +29,11 @@ namespace network_icon {
namespace {
//------------------------------------------------------------------------------
-// Struct to pass icon badges to NetworkIconImageSource.
-struct Badges {
- Badges()
- : top_left(NULL),
- top_right(NULL),
- bottom_left(NULL),
- bottom_right(NULL) {
- }
- const gfx::ImageSkia* top_left;
- const gfx::ImageSkia* top_right;
- const gfx::ImageSkia* bottom_left;
- const gfx::ImageSkia* bottom_right;
-};
+// NetworkIconImpl class used for maintaining a map of network state and images.
-//------------------------------------------------------------------------------
-// class used for maintaining a map of network state and images.
class NetworkIconImpl {
public:
- explicit NetworkIconImpl(IconType icon_type);
+ NetworkIconImpl(const std::string& service_path, ResourceColorTheme color);
// Determines whether or not the associated network might be dirty and if so
// updates and generates the icon. Does nothing if network no longer exists.
@@ -65,17 +48,14 @@ class NetworkIconImpl {
// Updates the local state for cellular networks. Returns true if changed.
bool UpdateCellularState(const chromeos::NetworkState* network);
- // Updates the VPN badge. Returns true if changed.
- bool UpdateVPNBadge();
-
- // Gets |badges| based on |network| and the current state.
- void GetBadges(const NetworkState* network, Badges* badges);
-
// Gets the appropriate icon and badges and composites the image.
void GenerateImage(const chromeos::NetworkState* network);
- // Defines color theme and VPN badging
- const IconType icon_type_;
+ // Service path for the network this icon is associated with.
+ std::string service_path_;
+
+ // Color theme for the icon.
+ ResourceColorTheme color_;
// Cached state of the network when the icon was last generated.
std::string state_;
@@ -86,9 +66,6 @@ class NetworkIconImpl {
// Cached technology badge for the network when the icon was last generated.
const gfx::ImageSkia* technology_badge_;
- // Cached vpn badge for the network when the icon was last generated.
- const gfx::ImageSkia* vpn_badge_;
-
// Cached roaming state of the network when the icon was last generated.
std::string roaming_state_;
@@ -105,25 +82,39 @@ class NetworkIconImpl {
typedef std::map<std::string, NetworkIconImpl*> NetworkIconMap;
-NetworkIconMap* GetIconMap(IconType icon_type) {
- typedef std::map<IconType, NetworkIconMap*> IconTypeMap;
- static IconTypeMap* s_icon_map = NULL;
- if (s_icon_map == NULL)
- s_icon_map = new IconTypeMap;
- if (s_icon_map->count(icon_type) == 0)
- (*s_icon_map)[icon_type] = new NetworkIconMap;
- return (*s_icon_map)[icon_type];
+NetworkIconMap* GetIconMap(ResourceColorTheme color) {
+ if (color == COLOR_DARK) {
+ static NetworkIconMap* s_icon_map_dark = NULL;
+ if (s_icon_map_dark == NULL)
+ s_icon_map_dark = new NetworkIconMap;
+ return s_icon_map_dark;
+ } else {
+ static NetworkIconMap* s_icon_map_light = NULL;
+ if (s_icon_map_light == NULL)
+ s_icon_map_light = new NetworkIconMap;
+ return s_icon_map_light;
+ }
}
//------------------------------------------------------------------------------
// Utilities for generating icon images.
-// 'NONE' will default to ARCS behavior where appropriate (e.g. no network or
-// if a new type gets added).
enum ImageType {
- ARCS,
- BARS,
- NONE
+ ARCS = 0,
+ BARS
+};
+
+struct Badges {
+ Badges()
+ : top_left(NULL),
+ top_right(NULL),
+ bottom_left(NULL),
+ bottom_right(NULL) {
+ }
+ const gfx::ImageSkia* top_left;
+ const gfx::ImageSkia* top_right;
+ const gfx::ImageSkia* bottom_left;
+ const gfx::ImageSkia* bottom_right;
};
// Amount to fade icons while connecting.
@@ -224,72 +215,55 @@ class NetworkIconImageSource : public gfx::ImageSkiaSource {
//------------------------------------------------------------------------------
// Utilities for extracting icon images.
-bool IconTypeIsDark(IconType icon_type) {
- return (icon_type != ICON_TYPE_TRAY);
-}
-
-bool IconTypeHasVPNBadge(IconType icon_type) {
- return (icon_type != ICON_TYPE_LIST);
-}
-
int NumImagesForType(ImageType type) {
- return (type == BARS) ? kNumBarsImages : kNumArcsImages;
+ return (type == ARCS) ? kNumArcsImages : kNumBarsImages;
}
-gfx::ImageSkia** ImageListForType(ImageType image_type, IconType icon_type) {
+gfx::ImageSkia** ImageListForType(ImageType type,
+ ResourceColorTheme color) {
gfx::ImageSkia** images;
- if (image_type == BARS) {
- images = IconTypeIsDark(icon_type) ?
- kBarsImagesAnimatingDark : kBarsImagesAnimatingLight;
- } else {
- images = IconTypeIsDark(icon_type) ?
+ if (type == ARCS) {
+ images = (color == COLOR_DARK) ?
kArcsImagesAnimatingDark : kArcsImagesAnimatingLight;
+ } else {
+ images = (color == COLOR_DARK) ?
+ kBarsImagesAnimatingDark : kBarsImagesAnimatingLight;
}
return images;
}
-gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) {
+gfx::ImageSkia* BaseImageForType(ImageType type,
+ ResourceColorTheme color) {
gfx::ImageSkia* image;
- if (image_type == BARS) {
+ if (type == ARCS) {
image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IconTypeIsDark(icon_type) ?
- IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK :
- IDR_AURA_UBER_TRAY_NETWORK_BARS_LIGHT);
- } else {
- image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IconTypeIsDark(icon_type) ?
+ color == COLOR_DARK ?
IDR_AURA_UBER_TRAY_NETWORK_ARCS_DARK :
IDR_AURA_UBER_TRAY_NETWORK_ARCS_LIGHT);
+ } else {
+ image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ color == COLOR_DARK ?
+ IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK :
+ IDR_AURA_UBER_TRAY_NETWORK_BARS_LIGHT);
}
return image;
}
-ImageType ImageTypeForNetworkType(const std::string& type) {
- if (type == flimflam::kTypeWifi || type == flimflam::kTypeWimax)
- return ARCS;
- else if (type == flimflam::kTypeCellular)
- return BARS;
- return NONE;
-}
-
-gfx::ImageSkia GetImageForIndex(ImageType image_type,
- IconType icon_type,
+gfx::ImageSkia GetImageForIndex(ImageType type,
+ ResourceColorTheme color,
int index) {
- int num_images = NumImagesForType(image_type);
+ int num_images = NumImagesForType(type);
if (index < 0 || index >= num_images)
return gfx::ImageSkia();
- gfx::ImageSkia* images = BaseImageForType(image_type, icon_type);
+ gfx::ImageSkia* images = BaseImageForType(type, color);
int width = images->width();
int height = images->height() / num_images;
return gfx::ImageSkiaOperations::ExtractSubset(*images,
gfx::Rect(0, index * height, width, height));
}
-const gfx::ImageSkia GetDisconnectedImage(const std::string& type,
- IconType icon_type) {
- ImageType image_type = ImageTypeForNetworkType(type);
- const int disconnected_index = 0;
- return GetImageForIndex(image_type, icon_type, disconnected_index);
+const gfx::ImageSkia GetDisconnectedImage(ResourceColorTheme color) {
+ return GetImageForIndex(ARCS, color, 0);
}
int StrengthIndex(int strength, int count) {
@@ -302,54 +276,56 @@ int StrengthIndex(int strength, int count) {
}
int GetStrengthIndex(const NetworkState* network) {
- ImageType image_type = ImageTypeForNetworkType(network->type());
- if (image_type == ARCS)
+ if (network->type() == flimflam::kTypeWifi) {
return StrengthIndex(network->signal_strength(), kNumArcsImages);
- else if (image_type == BARS)
+ } else if (network->type() == flimflam::kTypeWimax) {
return StrengthIndex(network->signal_strength(), kNumBarsImages);
+ } else if (network->type() == flimflam::kTypeCellular) {
+ return StrengthIndex(network->signal_strength(), kNumBarsImages);
+ }
return 0;
}
const gfx::ImageSkia* BadgeForNetworkTechnology(const NetworkState* network,
- IconType icon_type) {
+ ResourceColorTheme color) {
const int kUnknownBadgeType = -1;
int id = kUnknownBadgeType;
if (network->technology() == flimflam::kNetworkTechnologyEvdo) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_3G_DARK :
IDR_AURA_UBER_TRAY_NETWORK_3G_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnology1Xrtt) {
id = IDR_AURA_UBER_TRAY_NETWORK_1X;
} else if (network->technology() == flimflam::kNetworkTechnologyGprs) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK :
IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyEdge) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_EDGE_DARK :
IDR_AURA_UBER_TRAY_NETWORK_EDGE_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyUmts) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_3G_DARK :
IDR_AURA_UBER_TRAY_NETWORK_3G_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyHspa) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_HSPA_DARK :
IDR_AURA_UBER_TRAY_NETWORK_HSPA_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyHspaPlus) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_DARK :
IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyLte) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_LTE_DARK :
IDR_AURA_UBER_TRAY_NETWORK_LTE_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyLteAdvanced) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_DARK :
IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_LIGHT;
} else if (network->technology() == flimflam::kNetworkTechnologyGsm) {
- id = IconTypeIsDark(icon_type) ?
+ id = (color == COLOR_DARK) ?
IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK :
IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT;
}
@@ -359,24 +335,22 @@ const gfx::ImageSkia* BadgeForNetworkTechnology(const NetworkState* network,
return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id);
}
-const gfx::ImageSkia* BadgeForVPN(IconType icon_type) {
- return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE);
-}
-
gfx::ImageSkia GetIcon(const NetworkState* network,
- IconType icon_type,
+ ResourceColorTheme color,
int strength_index) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const std::string& type = network->type();
if (type == flimflam::kTypeEthernet) {
return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED);
- } else if (type == flimflam::kTypeWifi ||
- type == flimflam::kTypeWimax ||
- type == flimflam::kTypeCellular) {
+ } else if (type == flimflam::kTypeWifi) {
+ DCHECK(strength_index > 0);
+ return GetImageForIndex(ARCS, color, strength_index);
+ } else if (type == flimflam::kTypeWimax) {
+ DCHECK(strength_index > 0);
+ return GetImageForIndex(BARS, color, strength_index);
+ } else if (type == flimflam::kTypeCellular) {
DCHECK(strength_index > 0);
- return GetImageForIndex(
- ImageTypeForNetworkType(type), icon_type, strength_index);
+ return GetImageForIndex(BARS, color, strength_index);
} else if (type == flimflam::kTypeVPN) {
return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN);
} else {
@@ -385,20 +359,57 @@ gfx::ImageSkia GetIcon(const NetworkState* network,
}
}
+void GetBadges(const NetworkState* network,
+ ResourceColorTheme color,
+ Badges* badges) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ chromeos::NetworkStateHandler* handler = chromeos::NetworkStateHandler::Get();
+
+ bool use_dark_icons = color == COLOR_DARK;
+ const std::string& type = network->type();
+ if (type == flimflam::kTypeWifi) {
+ if (network->security() != flimflam::kSecurityNone && use_dark_icons) {
+ badges->bottom_right = rb.GetImageSkiaNamed(
+ IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK);
+ }
+ } else if (type == flimflam::kTypeWimax) {
+ badges->top_left = rb.GetImageSkiaNamed(
+ use_dark_icons ?
+ IDR_AURA_UBER_TRAY_NETWORK_4G_DARK :
+ IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT);
+ } else if (type == flimflam::kTypeCellular) {
+ if (network->roaming() == flimflam::kRoamingStateRoaming) {
+ // For networks that are always in roaming don't show roaming badge.
+ const DeviceState* device =
+ handler->GetDeviceState(network->device_path());
+ if (!device->provider_requires_roaming()) {
+ badges->bottom_right = rb.GetImageSkiaNamed(
+ use_dark_icons ?
+ IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK :
+ IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT);
+ }
+ }
+ if (!network->IsConnectingState()) {
+ badges->top_left = BadgeForNetworkTechnology(network, color);
+ }
+ }
+}
+
//------------------------------------------------------------------------------
// Get connecting images
-gfx::ImageSkia GetConnectingImage(const std::string& type, IconType icon_type) {
- ImageType image_type = ImageTypeForNetworkType(type);
+gfx::ImageSkia GetConnectingImage(const std::string& type,
+ ResourceColorTheme color) {
+ ImageType image_type = (type == flimflam::kTypeWifi) ? ARCS : BARS;
int image_count = NumImagesForType(image_type) - 1;
- gfx::ImageSkia** images = ImageListForType(image_type, icon_type);
+ gfx::ImageSkia** images = ImageListForType(image_type, color);
double animation = NetworkIconAnimation::GetInstance()->GetAnimation();
int index = animation * nextafter(static_cast<float>(image_count), 0);
index = std::max(std::min(index, image_count - 1), 0);
// Lazily cache images.
if (!images[index]) {
- gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1);
+ gfx::ImageSkia source = GetImageForIndex(image_type, color, index + 1);
images[index] = new gfx::ImageSkia(
gfx::ImageSkiaOperations::CreateBlendedImage(
gfx::ImageSkia(new EmptyImageSource(source.size()), source.size()),
@@ -415,17 +426,17 @@ gfx::ImageSkia GetConnectingImage(const std::string& type, IconType icon_type) {
//------------------------------------------------------------------------------
// NetworkIconImpl
-NetworkIconImpl::NetworkIconImpl(IconType icon_type)
- : icon_type_(icon_type),
+NetworkIconImpl::NetworkIconImpl(const std::string& service_path,
+ ResourceColorTheme color)
+ : service_path_(service_path),
+ color_(color),
strength_index_(-1),
- technology_badge_(NULL),
- vpn_badge_(NULL) {
+ technology_badge_(NULL) {
// Default image
- image_ = GetDisconnectedImage(flimflam::kTypeWifi, icon_type);
+ image_ = GetDisconnectedImage(color);
}
void NetworkIconImpl::Update(const NetworkState* network) {
- DCHECK(network);
// Determine whether or not we need to update the icon.
bool dirty = image_.isNull();
@@ -442,9 +453,6 @@ void NetworkIconImpl::Update(const NetworkState* network) {
if (type == flimflam::kTypeCellular)
dirty |= UpdateCellularState(network);
- if (IconTypeHasVPNBadge(icon_type_) && type != flimflam::kTypeVPN)
- dirty |= UpdateVPNBadge();
-
if (dirty) {
// Set the icon and badges based on the network and generate the image.
GenerateImage(network);
@@ -463,7 +471,7 @@ bool NetworkIconImpl::UpdateWirelessStrengthIndex(const NetworkState* network) {
bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) {
bool dirty = false;
const gfx::ImageSkia* technology_badge =
- BadgeForNetworkTechnology(network, icon_type_);
+ BadgeForNetworkTechnology(network, color_);
if (technology_badge != technology_badge_) {
technology_badge_ = technology_badge;
dirty = true;
@@ -476,62 +484,10 @@ bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) {
return dirty;
}
-bool NetworkIconImpl::UpdateVPNBadge() {
- const NetworkState* vpn =
- chromeos::NetworkStateHandler::Get()->ConnectedNetworkByType(
- flimflam::kTypeVPN);
- if (vpn && vpn_badge_ == NULL) {
- vpn_badge_ = BadgeForVPN(icon_type_);
- return true;
- } else if (!vpn && vpn_badge_ != NULL) {
- vpn_badge_ = NULL;
- return true;
- }
- return false;
-}
-
-void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) {
- DCHECK(network);
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- chromeos::NetworkStateHandler* handler = chromeos::NetworkStateHandler::Get();
-
- const std::string& type = network->type();
- if (type == flimflam::kTypeWifi) {
- if (network->security() != flimflam::kSecurityNone &&
- IconTypeIsDark(icon_type_)) {
- badges->bottom_right = rb.GetImageSkiaNamed(
- IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK);
- }
- } else if (type == flimflam::kTypeWimax) {
- badges->top_left = rb.GetImageSkiaNamed(
- IconTypeIsDark(icon_type_) ?
- IDR_AURA_UBER_TRAY_NETWORK_4G_DARK :
- IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT);
- } else if (type == flimflam::kTypeCellular) {
- if (network->roaming() == flimflam::kRoamingStateRoaming) {
- // For networks that are always in roaming don't show roaming badge.
- const DeviceState* device =
- handler->GetDeviceState(network->device_path());
- DCHECK(device);
- if (!device->provider_requires_roaming()) {
- badges->bottom_right = rb.GetImageSkiaNamed(
- IconTypeIsDark(icon_type_) ?
- IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK :
- IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT);
- }
- }
- }
- if (!network->IsConnectingState()) {
- badges->top_left = technology_badge_;
- badges->bottom_left = vpn_badge_;
- }
-}
-
void NetworkIconImpl::GenerateImage(const NetworkState* network) {
- DCHECK(network);
- gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_);
+ gfx::ImageSkia icon = GetIcon(network, color_, strength_index_);
Badges badges;
- GetBadges(network, &badges);
+ GetBadges(network, color_, &badges);
image_ = gfx::ImageSkia(
new NetworkIconImageSource(icon, badges), icon.size());
}
@@ -540,21 +496,24 @@ void NetworkIconImpl::GenerateImage(const NetworkState* network) {
// Public interface
gfx::ImageSkia GetImageForNetwork(const NetworkState* network,
- IconType icon_type) {
- DCHECK(network);
- // Handle connecting icons.
+ ResourceColorTheme color,
+ AnimationObserver* observer) {
if (network->IsConnectingState()) {
- NetworkIconAnimation::GetInstance()->AddNetwork(network->path());
- return GetConnectingImage(network->type(), icon_type);
+ if (observer)
+ NetworkIconAnimation::GetInstance()->AddObserver(observer);
+ return GetConnectingImage(network->type(), color);
}
- NetworkIconAnimation::GetInstance()->RemoveNetwork(network->path());
+ // Not connecting, remove observer.
+ if (observer)
+ NetworkIconAnimation::GetInstance()->RemoveObserver(observer);
+
+ NetworkIconMap* icon_map = GetIconMap(color);
// Find or add the icon.
- NetworkIconMap* icon_map = GetIconMap(icon_type);
NetworkIconImpl* icon;
NetworkIconMap::iterator iter = icon_map->find(network->path());
if (iter == icon_map->end()) {
- icon = new NetworkIconImpl(icon_type);
+ icon = new NetworkIconImpl(network->path(), color);
icon_map->insert(std::make_pair(network->path(), icon));
} else {
icon = iter->second;
@@ -565,37 +524,5 @@ gfx::ImageSkia GetImageForNetwork(const NetworkState* network,
return icon->image();
}
-gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type,
- const std::string& network_type) {
- return GetConnectingImage(network_type, icon_type);
-}
-
-gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type,
- const std::string& network_type) {
- return GetDisconnectedImage(network_type, icon_type);
-}
-
-string16 GetLabelForNetwork(const chromeos::NetworkState* network,
- IconType icon_type) {
- DCHECK(network);
- if (icon_type == ICON_TYPE_LIST) {
- if (network->IsConnectingState()) {
- return l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_NETWORK_LIST_CONNECTING,
- UTF8ToUTF16(network->name()));
- }
- } else {
- if (network->IsConnectedState()) {
- return l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, UTF8ToUTF16(network->name()));
- }
- if (network->IsConnectingState()) {
- return l10n_util::GetStringFUTF16(
- IDS_ASH_STATUS_TRAY_NETWORK_CONNECTING, UTF8ToUTF16(network->name()));
- }
- }
- return UTF8ToUTF16(network->name());
-}
-
} // namespace network_icon
} // namespace ash
diff --git a/ash/system/chromeos/network/network_icon.h b/ash/system/chromeos/network/network_icon.h
index 06c2491..728c0e0 100644
--- a/ash/system/chromeos/network/network_icon.h
+++ b/ash/system/chromeos/network/network_icon.h
@@ -7,7 +7,6 @@
#include <string>
-#include "base/string16.h"
#include "ui/gfx/image/image_skia.h"
namespace chromeos {
@@ -19,30 +18,19 @@ namespace network_icon {
class AnimationObserver;
-// Type of icon which dictates color theme and VPN badging
-enum IconType {
- ICON_TYPE_TRAY, // light icons with VPN badges
- ICON_TYPE_DEFAULT_VIEW, // dark icons with VPN badges
- ICON_TYPE_LIST, // dark icons without VPN badges
+// Color theme based on icon background.
+enum ResourceColorTheme {
+ COLOR_DARK,
+ COLOR_LIGHT,
};
-// Gets the image for the network associated with |service_path|. |network| must
-// not be NULL. |icon_type| determines the color theme and whether or not to
-// show the VPN badge. This caches badged icons per network per |icon_type|.
+// Get the image for the network associated with |service_path|.
+// |color| determines the color theme. If the icon is animating (i.e the
+// network is connecting) and |observer| is provided, it will be notified
+// when the icon changes.
gfx::ImageSkia GetImageForNetwork(const chromeos::NetworkState* network,
- IconType icon_type);
-
-// Gets the image for a connecting network type.
-gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type,
- const std::string& network_type);
-
-// Gets the image for a disconnected network type.
-gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type,
- const std::string& network_type);
-
-// Returns the label for |network| based on |icon_type|. |network| can be NULL.
-string16 GetLabelForNetwork(const chromeos::NetworkState* network,
- IconType icon_type);
+ ResourceColorTheme color,
+ AnimationObserver* observer);
} // namespace network_icon
} // namespace ash
diff --git a/ash/system/chromeos/network/network_icon_animation.cc b/ash/system/chromeos/network/network_icon_animation.cc
index 55da41e..55cc7f0 100644
--- a/ash/system/chromeos/network/network_icon_animation.cc
+++ b/ash/system/chromeos/network/network_icon_animation.cc
@@ -48,17 +48,6 @@ void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) {
animation_.Stop();
}
-void NetworkIconAnimation::AddNetwork(const std::string& network_id) {
- networks_.insert(network_id);
- // Animation will start (if stopped) when GetAnimation is called.
-}
-
-void NetworkIconAnimation::RemoveNetwork(const std::string& network_id) {
- networks_.erase(network_id);
- if (networks_.empty())
- animation_.Reset();
-}
-
// static
NetworkIconAnimation* NetworkIconAnimation::GetInstance() {
static NetworkIconAnimation* s_icon_animation =
diff --git a/ash/system/chromeos/network/network_icon_animation.h b/ash/system/chromeos/network/network_icon_animation.h
index fd47af8..9a1dfc3 100644
--- a/ash/system/chromeos/network/network_icon_animation.h
+++ b/ash/system/chromeos/network/network_icon_animation.h
@@ -5,9 +5,6 @@
#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_H_
#define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_ICON_ANIMATION_H_
-#include <set>
-#include <string>
-
#include "ash/ash_export.h"
#include "base/observer_list.h"
#include "ui/base/animation/animation_delegate.h"
@@ -29,8 +26,6 @@ class ASH_EXPORT NetworkIconAnimation : public ui::AnimationDelegate {
void AddObserver(AnimationObserver* observer);
void RemoveObserver(AnimationObserver* observer);
- void AddNetwork(const std::string& network_id);
- void RemoveNetwork(const std::string& network_id);
// ui::AnimationDelegate implementation.
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
@@ -40,7 +35,6 @@ class ASH_EXPORT NetworkIconAnimation : public ui::AnimationDelegate {
private:
ui::ThrobAnimation animation_;
ObserverList<AnimationObserver> observers_;
- std::set<std::string> networks_;
};
} // namespace network_icon
diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc
index 4ea2046..48cc927 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.cc
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc
@@ -8,8 +8,6 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/chromeos/network/network_icon.h"
-#include "ash/system/chromeos/network/network_icon_animation.h"
-#include "ash/system/chromeos/network/tray_network.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
@@ -17,6 +15,7 @@
#include "ash/system/tray/tray_views.h"
#include "base/utf_string_conversions.h"
#include "chromeos/network/device_state.h"
+#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "grit/ash_resources.h"
@@ -44,22 +43,10 @@ const int kNetworkListHeight = 203;
// Create a label with the font size and color used in the network info bubble.
views::Label* CreateInfoBubbleLabel(const string16& text) {
+ const SkColor text_color = SkColorSetARGB(127, 0, 0, 0);
views::Label* label = new views::Label(text);
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- label->SetFont(rb.GetFont(ui::ResourceBundle::SmallFont));
- label->SetEnabledColor(SkColorSetARGB(127, 0, 0, 0));
- return label;
-}
-
-// Create a label formatted for info items in the menu
-views::Label* CreateMenuInfoLabel(const string16& text) {
- views::Label* label = new views::Label(text);
- label->set_border(views::Border::CreateEmptyBorder(
- ash::kTrayPopupPaddingBetweenItems,
- ash::kTrayPopupPaddingHorizontal,
- ash::kTrayPopupPaddingBetweenItems, 0));
- label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
+ label->SetFont(label->font().DeriveFont(-1));
+ label->SetEnabledColor(text_color);
return label;
}
@@ -102,13 +89,14 @@ class NonActivatableSettingsBubble : public views::BubbleDelegateView {
//------------------------------------------------------------------------------
struct NetworkInfo {
- NetworkInfo(const std::string& path)
+ NetworkInfo(const std::string& path, const string16& description)
: service_path(path),
+ description(description),
highlight(false) {
}
std::string service_path;
- string16 label;
+ string16 description;
gfx::ImageSkia image;
bool highlight;
};
@@ -117,10 +105,8 @@ struct NetworkInfo {
// NetworkStateListDetailedView
NetworkStateListDetailedView::NetworkStateListDetailedView(
- TrayNetwork* tray_network,
- user::LoginStatus login)
- : NetworkDetailedView(tray_network),
- tray_network_(tray_network),
+ SystemTrayItem* owner, user::LoginStatus login)
+ : NetworkDetailedView(owner),
login_(login),
info_icon_(NULL),
button_wifi_(NULL),
@@ -133,16 +119,12 @@ NetworkStateListDetailedView::NetworkStateListDetailedView(
settings_(NULL),
proxy_settings_(NULL),
scanning_view_(NULL),
- no_wifi_networks_view_(NULL),
- no_cellular_networks_view_(NULL),
info_bubble_(NULL) {
- network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
}
NetworkStateListDetailedView::~NetworkStateListDetailedView() {
if (info_bubble_)
info_bubble_->GetWidget()->CloseNow();
- network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
}
void NetworkStateListDetailedView::ManagerChanged() {
@@ -161,13 +143,12 @@ void NetworkStateListDetailedView::NetworkListChanged() {
void NetworkStateListDetailedView::NetworkServiceChanged(
const chromeos::NetworkState* network) {
- UpdateNetworkState();
RefreshNetworkList();
Layout();
}
void NetworkStateListDetailedView::NetworkIconChanged() {
- UpdateNetworkState();
+ UpdateNetworkIcons();
RefreshNetworkList();
Layout();
}
@@ -256,8 +237,23 @@ void NetworkStateListDetailedView::ClickedOn(views::View* sender) {
} else {
std::map<views::View*, std::string>::iterator found =
network_map_.find(sender);
- if (found != network_map_.end())
- tray_network_->ConnectToNetwork(found->second);
+ if (found != network_map_.end()) {
+ std::string service_path = found->second;
+ const chromeos::NetworkState* network =
+ chromeos::NetworkStateHandler::Get()->GetNetworkState(service_path);
+ if (!network)
+ return;
+ if (!network->IsConnectedState()) {
+ chromeos::NetworkConfigurationHandler::Get()->Connect(
+ service_path,
+ base::Bind(&base::DoNothing),
+ chromeos::network_handler::ErrorCallback());
+ } else {
+ // This will show the settings UI for a connected network.
+ // TODO(stevenjb): Change the API to explicitly show network settings.
+ delegate->ConnectToNetwork(service_path);
+ }
+ }
}
}
@@ -376,10 +372,22 @@ void NetworkStateListDetailedView::UpdateNetworks(
const chromeos::NetworkState* network = *iter;
if (network->type() == flimflam::kTypeVPN)
continue; // Skip VPNs
- NetworkInfo* info = new NetworkInfo(network->path());
+ string16 description;
+ if (network->IsConnectingState()) {
+ description = l10n_util::GetStringFUTF16(
+ IDS_ASH_STATUS_TRAY_NETWORK_CONNECTING,
+ UTF8ToUTF16(network->name()));
+ } else {
+ description = UTF8ToUTF16(network->name());
+ }
+ NetworkInfo* info = new NetworkInfo(network->path(), description);
+ info->highlight =
+ network->IsConnectedState() || network->IsConnectingState();
+ info->image = network_icon::GetImageForNetwork(network,
+ network_icon::COLOR_DARK,
+ this);
network_list_.push_back(info);
}
- UpdateNetworkState();
RefreshNetworkList();
UpdateHeaderButtons();
@@ -387,183 +395,116 @@ void NetworkStateListDetailedView::UpdateNetworks(
UpdateNetworkExtra();
}
-void NetworkStateListDetailedView::UpdateNetworkState() {
- NetworkStateHandler* handler = NetworkStateHandler::Get();
- for (size_t i = 0; i < network_list_.size(); ++i) {
- NetworkInfo* info = network_list_[i];
- const chromeos::NetworkState* network =
- handler->GetNetworkState(info->service_path);
- if (!network)
- continue;
- info->image = network_icon::GetImageForNetwork(
- network, network_icon::ICON_TYPE_LIST);
- info->label = network_icon::GetLabelForNetwork(
- network, network_icon::ICON_TYPE_LIST);
- info->highlight =
- network->IsConnectedState() || network->IsConnectingState();
- }
-}
-
void NetworkStateListDetailedView::RefreshNetworkList() {
network_map_.clear();
std::set<std::string> new_service_paths;
- bool needs_relayout = UpdateNetworkListEntries(&new_service_paths);
- // Remove old children
- std::set<std::string> remove_service_paths;
- for (ServicePathMap::const_iterator it = service_path_map_.begin();
- it != service_path_map_.end(); ++it) {
- if (new_service_paths.find(it->first) == new_service_paths.end()) {
- remove_service_paths.insert(it->first);
- scroll_content()->RemoveChildView(it->second);
- needs_relayout = true;
- }
- }
-
- for (std::set<std::string>::const_iterator remove_it =
- remove_service_paths.begin();
- remove_it != remove_service_paths.end(); ++remove_it) {
- service_path_map_.erase(*remove_it);
- }
-
- if (needs_relayout) {
- views::View* selected_view = NULL;
- for (ServicePathMap::const_iterator iter = service_path_map_.begin();
- iter != service_path_map_.end(); ++iter) {
- if (iter->second->hover()) {
- selected_view = iter->second;
- break;
- }
- }
- scroll_content()->SizeToPreferredSize();
- static_cast<views::View*>(scroller())->Layout();
- if (selected_view)
- scroll_content()->ScrollRectToVisible(selected_view->bounds());
- }
-}
+ bool needs_relayout = false;
+ views::View* highlighted_view = NULL;
-bool NetworkStateListDetailedView::CreateOrUpdateInfoLabel(
- int index, const string16& text, views::Label** label) {
- if (*label == NULL) {
- *label = CreateMenuInfoLabel(text);
- scroll_content()->AddChildViewAt(*label, index);
- return true;
- } else {
- (*label)->SetText(text);
- return OrderChild(*label, index);
+ if (service_path_map_.empty()) {
+ scroll_content()->RemoveAllChildViews(true);
+ scanning_view_ = NULL;
}
-}
-bool NetworkStateListDetailedView::UpdateNetworkChild(
- int index, const NetworkInfo* info) {
- bool needs_relayout = false;
- HoverHighlightView* container = NULL;
- ServicePathMap::const_iterator found =
- service_path_map_.find(info->service_path);
- gfx::Font::FontStyle font =
- info->highlight ? gfx::Font::BOLD : gfx::Font::NORMAL;
- if (found == service_path_map_.end()) {
- container = new HoverHighlightView(this);
- container->AddIconAndLabel(info->image, info->label, font);
- scroll_content()->AddChildViewAt(container, index);
- container->set_border(views::Border::CreateEmptyBorder(
- 0, kTrayPopupPaddingHorizontal, 0, 0));
+ // TODO(stevenjb): Support cellular_initializing
+
+ // Insert child views. Order is:
+ // * Highlit networks (connected and connecting)
+ // * "Scanning..."
+ // * Un-highlit networks (not connected). Usually empty while scanning.
+
+ bool wifi_scanning =
+ NetworkStateHandler::Get()->GetScanningByType(flimflam::kTypeWifi);
+ if (wifi_scanning && scanning_view_ == NULL) {
+ scanning_view_ = new views::Label(
+ ui::ResourceBundle::GetSharedInstance().
+ GetLocalizedString(IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE));
+ scanning_view_->set_border(views::Border::CreateEmptyBorder(20, 0, 10, 0));
+ scanning_view_->SetFont(
+ scanning_view_->font().DeriveFont(0, gfx::Font::ITALIC));
+ // Initially insert "scanning" first.
+ scroll_content()->AddChildViewAt(scanning_view_, 0);
+ needs_relayout = true;
+ } else if (!wifi_scanning && scanning_view_ != NULL) {
+ scroll_content()->RemoveChildView(scanning_view_);
+ scanning_view_ = NULL;
needs_relayout = true;
- } else {
- container = found->second;
- container->RemoveAllChildViews(true);
- container->AddIconAndLabel(info->image, info->label, font);
- container->Layout();
- container->SchedulePaint();
- needs_relayout = OrderChild(container, index);
- }
-
- network_map_[container] = info->service_path;
- service_path_map_[info->service_path] = container;
- return needs_relayout;
-}
-
-bool NetworkStateListDetailedView::OrderChild(views::View* view, int index) {
- if (scroll_content()->child_at(index) != view) {
- scroll_content()->ReorderChildView(view, index);
- return true;
}
- return false;
-}
-bool NetworkStateListDetailedView::UpdateNetworkListEntries(
- std::set<std::string>* new_service_paths) {
- bool needs_relayout = false;
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- NetworkStateHandler* handler = NetworkStateHandler::Get();
-
- // Insert child views
- int index = 0;
-
- // Highlighted networks
+ int child_index_offset = 0;
for (size_t i = 0; i < network_list_.size(); ++i) {
- const NetworkInfo* info = network_list_[i];
- if (info->highlight) {
- if (UpdateNetworkChild(index++, info))
+ NetworkInfo* info = network_list_[i];
+ if (scanning_view_ && child_index_offset == 0 && !info->highlight)
+ child_index_offset = 1;
+ // |child_index| determines the position of the view, which is the same
+ // as the list index for highlit views, and offset by one for any
+ // non-highlit views when scanning.
+ int child_index = child_index_offset + i;
+ std::map<std::string, HoverHighlightView*>::const_iterator it =
+ service_path_map_.find(info->service_path);
+ HoverHighlightView* container = NULL;
+ std::string description;
+ if (it == service_path_map_.end()) {
+ // Create a new view.
+ container = new HoverHighlightView(this);
+ container->AddIconAndLabel(
+ info->image,
+ info->description,
+ info->highlight ? gfx::Font::BOLD : gfx::Font::NORMAL);
+ scroll_content()->AddChildViewAt(container, child_index);
+ container->set_border(views::Border::CreateEmptyBorder(
+ 0, kTrayPopupPaddingHorizontal, 0, 0));
+ needs_relayout = true;
+ } else {
+ container = it->second;
+ container->RemoveAllChildViews(true);
+ container->AddIconAndLabel(
+ info->image,
+ info->description,
+ info->highlight ? gfx::Font::BOLD : gfx::Font::NORMAL);
+ container->Layout();
+ container->SchedulePaint();
+
+ // Reordering the view if necessary.
+ views::View* child = scroll_content()->child_at(child_index);
+ if (child != container) {
+ scroll_content()->ReorderChildView(container, child_index);
needs_relayout = true;
- new_service_paths->insert(info->service_path);
+ }
}
- }
- // Cellular initializing
- int status_message_id = tray_network_->GetUninitializedMsg();
- if (!status_message_id &&
- handler->TechnologyEnabled(NetworkStateHandler::kMatchTypeMobile) &&
- !handler->FirstNetworkByType(NetworkStateHandler::kMatchTypeMobile)) {
- status_message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS;
- }
- if (status_message_id) {
- string16 text = rb.GetLocalizedString(status_message_id);
- if (CreateOrUpdateInfoLabel(index++, text, &no_cellular_networks_view_))
- needs_relayout = true;
- } else if (no_cellular_networks_view_) {
- scroll_content()->RemoveChildView(no_cellular_networks_view_);
- no_cellular_networks_view_ = NULL;
- needs_relayout = true;
+ if (info->highlight)
+ highlighted_view = container;
+ network_map_[container] = info->service_path;
+ service_path_map_[info->service_path] = container;
+ new_service_paths.insert(info->service_path);
}
- // "Wifi Enabled / Disabled"
- if (network_list_.empty()) {
- int message_id = handler->TechnologyEnabled(flimflam::kTypeWifi) ?
- IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED :
- IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
- string16 text = rb.GetLocalizedString(message_id);
- if (CreateOrUpdateInfoLabel(index++, text, &no_wifi_networks_view_))
+ std::set<std::string> remove_service_paths;
+ for (std::map<std::string, HoverHighlightView*>::const_iterator it =
+ service_path_map_.begin(); it != service_path_map_.end(); ++it) {
+ if (new_service_paths.find(it->first) == new_service_paths.end()) {
+ remove_service_paths.insert(it->first);
+ scroll_content()->RemoveChildView(it->second);
needs_relayout = true;
- } else if (no_wifi_networks_view_) {
- scroll_content()->RemoveChildView(no_wifi_networks_view_);
- no_wifi_networks_view_ = NULL;
- needs_relayout = true;
+ }
}
- // "Wifi Scanning"
- if (handler->GetScanningByType(flimflam::kTypeWifi)) {
- string16 text =
- rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE);
- if (CreateOrUpdateInfoLabel(index++, text, &scanning_view_))
- needs_relayout = true;
- } else if (scanning_view_ != NULL) {
- scroll_content()->RemoveChildView(scanning_view_);
- scanning_view_ = NULL;
- needs_relayout = true;
+ for (std::set<std::string>::const_iterator remove_it =
+ remove_service_paths.begin();
+ remove_it != remove_service_paths.end(); ++remove_it) {
+ service_path_map_.erase(*remove_it);
}
- // Un-highlighted networks
- for (size_t i = 0; i < network_list_.size(); ++i) {
- const NetworkInfo* info = network_list_[i];
- if (!info->highlight) {
- if (UpdateNetworkChild(index++, info))
- needs_relayout = true;
- new_service_paths->insert(info->service_path);
- }
- }
+ // TODO(stevenjb): Support no wifi / cellular networks
- return needs_relayout;
+ if (needs_relayout) {
+ scroll_content()->SizeToPreferredSize();
+ static_cast<views::View*>(scroller())->Layout();
+ if (highlighted_view)
+ scroll_content()->ScrollRectToVisible(highlighted_view->bounds());
+ }
}
void NetworkStateListDetailedView::UpdateNetworkEntries() {
@@ -627,6 +568,22 @@ void NetworkStateListDetailedView::UpdateNetworkExtra() {
turn_on_wifi_->parent()->Layout();
}
+void NetworkStateListDetailedView::UpdateNetworkIcons() {
+ chromeos::NetworkStateHandler* handler = chromeos::NetworkStateHandler::Get();
+ for (size_t i = 0; i < network_list_.size(); ++i) {
+ NetworkInfo* info = network_list_[i];
+ const chromeos::NetworkState* network =
+ handler->GetNetworkState(info->service_path);
+ if (!network)
+ continue;
+ info->image = network_icon::GetImageForNetwork(network,
+ network_icon::COLOR_DARK,
+ this);
+ info->highlight =
+ network->IsConnectedState() || network->IsConnectingState();
+ }
+}
+
void NetworkStateListDetailedView::CreateSettingsEntry() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (login_ != user::LOGGED_IN_NONE) {
diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.h b/ash/system/chromeos/network/network_state_list_detailed_view.h
index 787e47c..1ffb509 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.h
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.h
@@ -27,9 +27,6 @@ class BubbleDelegateView;
namespace ash {
namespace internal {
-
-class TrayNetwork;
-
namespace tray {
struct NetworkInfo;
@@ -39,8 +36,7 @@ class NetworkStateListDetailedView : public NetworkDetailedView,
public ViewClickListener,
public network_icon::AnimationObserver {
public:
- NetworkStateListDetailedView(TrayNetwork* tray_network,
- user::LoginStatus login);
+ NetworkStateListDetailedView(SystemTrayItem* owner, user::LoginStatus login);
virtual ~NetworkStateListDetailedView();
// Overridden from NetworkDetailedView:
@@ -63,9 +59,6 @@ class NetworkStateListDetailedView : public NetworkDetailedView,
virtual void ClickedOn(views::View* sender) OVERRIDE;
private:
- typedef std::map<views::View*, std::string> NetworkMap;
- typedef std::map<std::string, HoverHighlightView*> ServicePathMap;
-
// Create UI components.
void CreateHeaderEntry();
void CreateHeaderButtons();
@@ -74,16 +67,11 @@ class NetworkStateListDetailedView : public NetworkDetailedView,
// Update UI components.
void UpdateHeaderButtons();
- void UpdateNetworks(const NetworkStateList& networks);
- void UpdateNetworkState();
void RefreshNetworkList();
- bool CreateOrUpdateInfoLabel(
- int index, const string16& text, views::Label** label);
- bool UpdateNetworkChild(int index, const NetworkInfo* info);
- bool OrderChild(views::View* view, int index);
- bool UpdateNetworkListEntries(std::set<std::string>* new_service_paths);
+ void UpdateNetworks(const NetworkStateList& networks);
void UpdateNetworkEntries();
void UpdateNetworkExtra();
+ void UpdateNetworkIcons();
// Adds a settings entry when logged in, and an entry for changing proxy
// settings otherwise.
@@ -94,17 +82,14 @@ class NetworkStateListDetailedView : public NetworkDetailedView,
bool ResetInfoBubble();
views::View* CreateNetworkInfoView();
- // Typed pointer to the owning tray item.
- TrayNetwork* tray_network_;
-
// Track login state.
user::LoginStatus login_;
// A map of child views to their network service path.
- NetworkMap network_map_;
+ std::map<views::View*, std::string> network_map_;
// A map of network service paths to their view.
- ServicePathMap service_path_map_;
+ std::map<std::string, HoverHighlightView*> service_path_map_;
// An owned list of network info.
ScopedVector<NetworkInfo> network_list_;
@@ -126,8 +111,6 @@ class NetworkStateListDetailedView : public NetworkDetailedView,
TrayPopupLabelButton* settings_;
TrayPopupLabelButton* proxy_settings_;
views::Label* scanning_view_;
- views::Label* no_wifi_networks_view_;
- views::Label* no_cellular_networks_view_;
// A small bubble for displaying network info.
views::BubbleDelegateView* info_bubble_;
diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc
index 4611540..0f10da1 100644
--- a/ash/system/chromeos/network/tray_network.cc
+++ b/ash/system/chromeos/network/tray_network.cc
@@ -6,7 +6,6 @@
#include "ash/ash_switches.h"
#include "ash/shell.h"
-#include "ash/system/chromeos/network/network_icon_animation.h"
#include "ash/system/chromeos/network/network_list_detailed_view.h"
#include "ash/system/chromeos/network/network_list_detailed_view_base.h"
#include "ash/system/chromeos/network/network_state_list_detailed_view.h"
@@ -19,9 +18,6 @@
#include "ash/system/tray/tray_item_view.h"
#include "ash/system/tray/tray_notification_view.h"
#include "base/command_line.h"
-#include "base/utf_string_conversions.h"
-#include "chromeos/network/network_configuration_handler.h"
-#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
@@ -64,14 +60,16 @@ bool UseNewNetworkHandlers() {
} // namespace
-using chromeos::NetworkState;
-using chromeos::NetworkStateHandler;
-
namespace ash {
namespace internal {
namespace tray {
+enum ColorTheme {
+ LIGHT,
+ DARK,
+};
+
class NetworkMessages {
public:
struct Message {
@@ -101,70 +99,39 @@ class NetworkMessages {
MessageMap messages_;
};
-class NetworkTrayView : public TrayItemView,
- public network_icon::AnimationObserver {
+class NetworkTrayView : public TrayItemView {
public:
- explicit NetworkTrayView(TrayNetwork* network_tray)
- : TrayItemView(network_tray),
- network_tray_(network_tray) {
+ NetworkTrayView(SystemTrayItem* owner, ColorTheme size)
+ : TrayItemView(owner), color_theme_(size) {
SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
- image_view_ = new views::ImageView;
+ image_view_ = color_theme_ == DARK ?
+ new FixedSizedImageView(0, kTrayPopupItemHeight) :
+ new views::ImageView;
AddChildView(image_view_);
NetworkIconInfo info;
- if (UseNewNetworkHandlers()) {
- UpdateNetworkStateHandlerIcon();
- network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
- } else {
- Shell::GetInstance()->system_tray_delegate()->
- GetMostRelevantNetworkIcon(&info, false);
- UpdateIcon(info.tray_icon_visible, info.image);
- }
+ Shell::GetInstance()->system_tray_delegate()->
+ GetMostRelevantNetworkIcon(&info, false);
+ Update(info);
}
- virtual ~NetworkTrayView() {
- if (UseNewNetworkHandlers())
- network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
- }
+ virtual ~NetworkTrayView() {}
void Update(const NetworkIconInfo& info) {
- if (UseNewNetworkHandlers())
- return;
- UpdateIcon(info.tray_icon_visible, info.image);
+ image_view_->SetImage(info.image);
+ SetVisible(info.tray_icon_visible);
+ SchedulePaint();
UpdateConnectionStatus(info.name, info.connected);
}
- void UpdateNetworkStateHandlerIcon() {
- DCHECK(UseNewNetworkHandlers());
- NetworkStateHandler* handler = NetworkStateHandler::Get();
- gfx::ImageSkia image;
- string16 name;
- network_tray_->GetNetworkStateHandlerImageAndLabel(
- network_icon::ICON_TYPE_TRAY, &image, &name);
- bool show_in_tray = !image.isNull();
- UpdateIcon(show_in_tray, image);
- const NetworkState* connected_network = handler->ConnectedNetworkByType(
- NetworkStateHandler::kMatchTypeNonVirtual);
- if (connected_network)
- UpdateConnectionStatus(UTF8ToUTF16(connected_network->name()), true);
- else
- UpdateConnectionStatus(string16(), false);
- }
-
// views::View override.
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE {
state->name = connection_status_string_;
state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
}
- // network_icon::AnimationObserver
- virtual void NetworkIconChanged() OVERRIDE {
- if (UseNewNetworkHandlers())
- UpdateNetworkStateHandlerIcon();
- }
-
private:
// Updates connection status and notifies accessibility event when necessary.
void UpdateConnectionStatus(const string16& network_name, bool connected) {
@@ -182,62 +149,32 @@ class NetworkTrayView : public TrayItemView,
}
}
- void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) {
- image_view_->SetImage(image);
- SetVisible(tray_icon_visible);
- SchedulePaint();
- }
-
- TrayNetwork* network_tray_;
views::ImageView* image_view_;
+ ColorTheme color_theme_;
string16 connection_status_string_;
DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
};
-class NetworkDefaultView : public TrayItemMore,
- public network_icon::AnimationObserver {
+class NetworkDefaultView : public TrayItemMore {
public:
- NetworkDefaultView(TrayNetwork* network_tray, bool show_more)
- : TrayItemMore(network_tray, show_more),
- network_tray_(network_tray) {
+ NetworkDefaultView(SystemTrayItem* owner, bool show_more)
+ : TrayItemMore(owner, show_more) {
Update();
- if (UseNewNetworkHandlers())
- network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
}
- virtual ~NetworkDefaultView() {
- if (UseNewNetworkHandlers())
- network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
- }
+ virtual ~NetworkDefaultView() {}
void Update() {
- if (UseNewNetworkHandlers()) {
- gfx::ImageSkia image;
- string16 label;
- network_tray_->GetNetworkStateHandlerImageAndLabel(
- network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label);
- SetImage(&image);
- SetLabel(label);
- SetAccessibleName(label);
- } else {
- NetworkIconInfo info;
- Shell::GetInstance()->system_tray_delegate()->
- GetMostRelevantNetworkIcon(&info, true);
- SetImage(&info.image);
- SetLabel(info.description);
- SetAccessibleName(info.description);
- }
- }
-
- // network_icon::AnimationObserver
- virtual void NetworkIconChanged() OVERRIDE {
- Update();
+ NetworkIconInfo info;
+ Shell::GetInstance()->system_tray_delegate()->
+ GetMostRelevantNetworkIcon(&info, true);
+ SetImage(&info.image);
+ SetLabel(info.description);
+ SetAccessibleName(info.description);
}
private:
- TrayNetwork* network_tray_;
-
DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
};
@@ -294,10 +231,10 @@ class NetworkWifiDetailedView : public NetworkDetailedView {
class NetworkMessageView : public views::View,
public views::LinkListener {
public:
- NetworkMessageView(TrayNetwork* tray_network,
+ NetworkMessageView(TrayNetwork* owner,
TrayNetwork::MessageType message_type,
const NetworkMessages::Message& network_msg)
- : tray_network_(tray_network),
+ : owner_(owner),
message_type_(message_type),
network_type_(network_msg.network_type_) {
SetLayoutManager(
@@ -336,14 +273,14 @@ class NetworkMessageView : public views::View,
// Overridden from views::LinkListener.
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
- tray_network_->LinkClicked(message_type_, source->id());
+ owner_->LinkClicked(message_type_, source->id());
}
TrayNetwork::MessageType message_type() const { return message_type_; }
TrayNetwork::NetworkType network_type() const { return network_type_; }
private:
- TrayNetwork* tray_network_;
+ TrayNetwork* owner_;
TrayNetwork::MessageType message_type_;
TrayNetwork::NetworkType network_type_;
@@ -352,9 +289,8 @@ class NetworkMessageView : public views::View,
class NetworkNotificationView : public TrayNotificationView {
public:
- explicit NetworkNotificationView(TrayNetwork* tray_network)
- : TrayNotificationView(tray_network, 0),
- tray_network_(tray_network) {
+ explicit NetworkNotificationView(TrayNetwork* owner)
+ : TrayNotificationView(owner, 0) {
CreateMessageView();
InitView(network_message_view_);
SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
@@ -364,13 +300,13 @@ class NetworkNotificationView : public TrayNotificationView {
// Overridden from TrayNotificationView.
virtual void OnClose() OVERRIDE {
- tray_network_->ClearNetworkMessage(network_message_view_->message_type());
+ tray_network()->ClearNetworkMessage(network_message_view_->message_type());
}
virtual void OnClickAction() OVERRIDE {
if (network_message_view_->message_type() !=
TrayNetwork::MESSAGE_DATA_PROMO)
- tray_network_->PopupDetailedView(0, true);
+ owner()->PopupDetailedView(0, true);
}
void Update() {
@@ -382,16 +318,19 @@ class NetworkNotificationView : public TrayNotificationView {
}
private:
+ TrayNetwork* tray_network() {
+ return static_cast<TrayNetwork*>(owner());
+ }
+
void CreateMessageView() {
// Display the first (highest priority) message.
- CHECK(!tray_network_->messages()->messages().empty());
+ CHECK(!tray_network()->messages()->messages().empty());
NetworkMessages::MessageMap::const_iterator iter =
- tray_network_->messages()->messages().begin();
+ tray_network()->messages()->messages().begin();
network_message_view_ =
- new NetworkMessageView(tray_network_, iter->first, iter->second);
+ new NetworkMessageView(tray_network(), iter->first, iter->second);
}
- TrayNetwork* tray_network_;
tray::NetworkMessageView* network_message_view_;
DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
@@ -406,8 +345,7 @@ TrayNetwork::TrayNetwork(SystemTray* system_tray)
detailed_(NULL),
notification_(NULL),
messages_(new tray::NetworkMessages()),
- request_wifi_view_(false),
- uninitialized_msg_(0) {
+ request_wifi_view_(false) {
if (UseNewNetworkHandlers())
network_state_observer_.reset(new TrayNetworkStateObserver(this));
Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this);
@@ -419,15 +357,14 @@ TrayNetwork::~TrayNetwork() {
views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
CHECK(tray_ == NULL);
- tray_ = new tray::NetworkTrayView(this);
+ tray_ = new tray::NetworkTrayView(this, tray::LIGHT);
return tray_;
}
views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
CHECK(default_ == NULL);
- CHECK(tray_ != NULL);
- default_ = new tray::NetworkDefaultView(
- this, status != user::LOGGED_IN_LOCKED);
+ default_ =
+ new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED);
return default_;
}
@@ -530,112 +467,6 @@ void TrayNetwork::OnWillToggleWifi() {
}
}
-void TrayNetwork::TrayNetworkUpdated() {
- if (tray_ && UseNewNetworkHandlers())
- tray_->UpdateNetworkStateHandlerIcon();
- if (default_)
- default_->Update();
-}
-
-void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) {
- if (!network->IsConnectingState())
- connecting_networks_.erase(network->path());
-}
-
-void TrayNetwork::ConnectToNetwork(const std::string& service_path) {
- DCHECK(UseNewNetworkHandlers());
- const NetworkState* network =
- NetworkStateHandler::Get()->GetNetworkState(service_path);
- if (!network)
- return;
- if (!network->IsConnectedState()) {
- chromeos::NetworkConfigurationHandler::Get()->Connect(
- service_path,
- base::Bind(&base::DoNothing),
- chromeos::network_handler::ErrorCallback());
- connecting_networks_.insert(service_path);
- } else {
- // This will show the settings UI for a connected network.
- // TODO(stevenjb): Change the API to explicitly show network settings.
- Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork(
- service_path);
- }
-}
-
-bool TrayNetwork::HasConnectingNetwork(const std::string& service_path) {
- return connecting_networks_.count(service_path) > 0;
-}
-
-void TrayNetwork::GetNetworkStateHandlerImageAndLabel(
- network_icon::IconType icon_type,
- gfx::ImageSkia* image,
- string16* label) {
- NetworkStateHandler* handler = NetworkStateHandler::Get();
- const NetworkState* network = handler->ConnectedNetworkByType(
- NetworkStateHandler::kMatchTypeNonVirtual);
- if (network && network->type() == flimflam::kTypeEthernet &&
- icon_type == network_icon::ICON_TYPE_TRAY) {
- *image = gfx::ImageSkia(); // Don't show ethernet in the tray.
- return;
- }
- const NetworkState* connecting_network = handler->ConnectingNetworkByType(
- NetworkStateHandler::kMatchTypeWireless);
- // If we are connecting to a network, and there is either no connected
- // network, or the connection was user requested, use the connecting
- // network.
- if (connecting_network &&
- (!network ||
- HasConnectingNetwork(connecting_network->path()))) {
- network = connecting_network;
- }
- if (!network) {
- // If no connecting network, check for cellular initializing.
- int uninitialized_msg = GetUninitializedMsg();
- if (uninitialized_msg != 0) {
- *image = network_icon::GetImageForConnectingNetwork(
- icon_type, flimflam::kTypeCellular);
- if (label)
- *label = l10n_util::GetStringUTF16(uninitialized_msg);
- } else {
- // Otherwise show the disconnected wifi icon.
- *image = network_icon::GetImageForDisconnectedNetwork(
- icon_type, flimflam::kTypeWifi);
- if (label) {
- *label = l10n_util::GetStringUTF16(
- IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED);
- }
- }
- return;
- }
- // Get icon and label for connected or connecting network.
- *image = network_icon::GetImageForNetwork(network, icon_type);
- if (label)
- *label = network_icon::GetLabelForNetwork(network, icon_type);
-}
-
-int TrayNetwork::GetUninitializedMsg() {
- NetworkStateHandler* handler = NetworkStateHandler::Get();
- if (handler->TechnologyUninitialized(
- NetworkStateHandler::kMatchTypeMobile)) {
- uninitialized_msg_ = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
- uninitialized_state_time_ = base::Time::Now();
- return uninitialized_msg_;
- } else if (handler->GetScanningByType(
- NetworkStateHandler::kMatchTypeMobile)) {
- uninitialized_msg_ = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING;
- uninitialized_state_time_ = base::Time::Now();
- return uninitialized_msg_;
- }
- // There can be a delay between leaving the Initializing state and when
- // a Cellular device shows up, so keep showing the initializing
- // animation for a bit to avoid flashing the disconnect icon.
- const int kInitializingDelaySeconds = 1;
- base::TimeDelta dtime = base::Time::Now() - uninitialized_state_time_;
- if (dtime.InSeconds() < kInitializingDelaySeconds)
- return uninitialized_msg_;
- return 0;
-}
-
void TrayNetwork::LinkClicked(MessageType message_type, int link_id) {
tray::NetworkMessages::MessageMap::const_iterator iter =
messages()->messages().find(message_type);
diff --git a/ash/system/chromeos/network/tray_network.h b/ash/system/chromeos/network/tray_network.h
index 3105c1f..45297a28 100644
--- a/ash/system/chromeos/network/tray_network.h
+++ b/ash/system/chromeos/network/tray_network.h
@@ -5,17 +5,9 @@
#ifndef ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_H
#define ASH_SYSTEM_CHROMEOS_NETWORK_TRAY_NETWORK_H
-#include <set>
-
-#include "ash/system/chromeos/network/network_icon.h"
#include "ash/system/chromeos/network/network_observer.h"
#include "ash/system/tray/system_tray_item.h"
#include "base/memory/scoped_ptr.h"
-#include "base/time.h"
-
-namespace chromeos {
-class NetworkState;
-}
namespace ash {
namespace internal {
@@ -65,28 +57,7 @@ class TrayNetwork : public SystemTrayItem,
virtual void ClearNetworkMessage(MessageType message_type) OVERRIDE;
virtual void OnWillToggleWifi() OVERRIDE;
- // Called when the network for the tray icon may have been updated.
- void TrayNetworkUpdated();
-
- // Called when the properties for |network| may have been updated.
- void NetworkServiceChanged(const chromeos::NetworkState* network);
-
- // Request a network connection (called from detailed view).
- void ConnectToNetwork(const std::string& service_path);
-
- // Returns true if a user initiated connection to |network| occured.
- bool HasConnectingNetwork(const std::string& service_path);
-
- // Gets the correct icon and label for |icon_type|.
- void GetNetworkStateHandlerImageAndLabel(network_icon::IconType icon_type,
- gfx::ImageSkia* image,
- string16* label);
-
- // Updates and returns the appropriate message id if a network technology
- // (i.e. cellular) is uninitialized.
- int GetUninitializedMsg();
-
-private:
+ private:
friend class tray::NetworkMessageView;
friend class tray::NetworkNotificationView;
@@ -101,9 +72,6 @@ private:
scoped_ptr<tray::NetworkMessages> messages_;
bool request_wifi_view_;
scoped_ptr<TrayNetworkStateObserver> network_state_observer_;
- std::set<std::string> connecting_networks_;
- base::Time uninitialized_state_time_;
- int uninitialized_msg_;
DISALLOW_COPY_AND_ASSIGN(TrayNetwork);
};
diff --git a/ash/system/chromeos/network/tray_network_state_observer.cc b/ash/system/chromeos/network/tray_network_state_observer.cc
index a33eeaa..6faed5d 100644
--- a/ash/system/chromeos/network/tray_network_state_observer.cc
+++ b/ash/system/chromeos/network/tray_network_state_observer.cc
@@ -43,24 +43,10 @@ void TrayNetworkStateObserver::NetworkListChanged() {
tray::NetworkDetailedView* detailed = tray_->detailed();
if (detailed)
detailed->NetworkListChanged();
- tray_->TrayNetworkUpdated();
-}
-
-void TrayNetworkStateObserver::DeviceListChanged() {
- tray::NetworkDetailedView* detailed = tray_->detailed();
- if (detailed)
- detailed->ManagerChanged();
- tray_->TrayNetworkUpdated();
-}
-
-void TrayNetworkStateObserver::DefaultNetworkChanged(
- const chromeos::NetworkState* network) {
- tray_->TrayNetworkUpdated();
}
void TrayNetworkStateObserver::NetworkPropertiesUpdated(
const chromeos::NetworkState* network) {
- tray_->NetworkServiceChanged(network);
tray::NetworkDetailedView* detailed = tray_->detailed();
if (detailed)
detailed->NetworkServiceChanged(network);
diff --git a/ash/system/chromeos/network/tray_network_state_observer.h b/ash/system/chromeos/network/tray_network_state_observer.h
index 94ea75f..d6f4d3b 100644
--- a/ash/system/chromeos/network/tray_network_state_observer.h
+++ b/ash/system/chromeos/network/tray_network_state_observer.h
@@ -30,9 +30,6 @@ class TrayNetworkStateObserver : public chromeos::NetworkStateHandlerObserver {
// NetworkStateHandlerObserver overrides.
virtual void NetworkManagerChanged() OVERRIDE;
virtual void NetworkListChanged() OVERRIDE;
- virtual void DeviceListChanged() OVERRIDE;
- virtual void DefaultNetworkChanged(
- const chromeos::NetworkState* network) OVERRIDE;
virtual void NetworkPropertiesUpdated(
const chromeos::NetworkState* network) OVERRIDE;