summaryrefslogtreecommitdiffstats
path: root/ash/system
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 22:05:40 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 22:05:40 +0000
commitd8b88357329667910f8cb95658f433d85f9412ad (patch)
tree4970dbc64393cdd7db67cff27ee38cbe53dde155 /ash/system
parentd6e9f94e80fa19afd5b46454cbbacfc962fb8ef8 (diff)
downloadchromium_src-d8b88357329667910f8cb95658f433d85f9412ad.zip
chromium_src-d8b88357329667910f8cb95658f433d85f9412ad.tar.gz
chromium_src-d8b88357329667910f8cb95658f433d85f9412ad.tar.bz2
Fix tray and detailed view for vpns
BUG=179605 Review URL: https://codereview.chromium.org/12493005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186515 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system')
-rw-r--r--ash/system/chromeos/network/network_icon.cc133
-rw-r--r--ash/system/chromeos/network/network_state_list_detailed_view.cc3
-rw-r--r--ash/system/chromeos/network/tray_network.cc23
-rw-r--r--ash/system/chromeos/network/tray_vpn.cc4
4 files changed, 118 insertions, 45 deletions
diff --git a/ash/system/chromeos/network/network_icon.cc b/ash/system/chromeos/network/network_icon.cc
index 4212a72..f241eb1 100644
--- a/ash/system/chromeos/network/network_icon.cc
+++ b/ash/system/chromeos/network/network_icon.cc
@@ -131,13 +131,12 @@ const double kConnectingImageAlpha = 0.5;
// Images for strength bars for wired networks.
const int kNumBarsImages = 5;
-gfx::ImageSkia* kBarsImagesAnimatingDark[kNumBarsImages - 1];
-gfx::ImageSkia* kBarsImagesAnimatingLight[kNumBarsImages - 1];
// Imagaes for strength arcs for wireless networks.
const int kNumArcsImages = 5;
-gfx::ImageSkia* kArcsImagesAnimatingDark[kNumArcsImages - 1];
-gfx::ImageSkia* kArcsImagesAnimatingLight[kNumArcsImages - 1];
+
+// Number of discrete images to use for alpha fade animation
+const int kNumFadeImages = 10;
//------------------------------------------------------------------------------
// Classes for generating scaled images.
@@ -236,18 +235,6 @@ int NumImagesForType(ImageType type) {
return (type == BARS) ? kNumBarsImages : kNumArcsImages;
}
-gfx::ImageSkia** ImageListForType(ImageType image_type, IconType icon_type) {
- gfx::ImageSkia** images;
- if (image_type == BARS) {
- images = IconTypeIsDark(icon_type) ?
- kBarsImagesAnimatingDark : kBarsImagesAnimatingLight;
- } else {
- images = IconTypeIsDark(icon_type) ?
- kArcsImagesAnimatingDark : kArcsImagesAnimatingLight;
- }
- return images;
-}
-
gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) {
gfx::ImageSkia* image;
if (image_type == BARS) {
@@ -297,6 +284,69 @@ const gfx::ImageSkia GetDisconnectedImage(const std::string& type,
return GetImageForIndex(image_type, icon_type, disconnected_index);
}
+gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type,
+ IconType icon_type,
+ double animation) {
+ static gfx::ImageSkia* s_bars_images_dark[kNumBarsImages - 1];
+ static gfx::ImageSkia* s_bars_images_light[kNumBarsImages - 1];
+ static gfx::ImageSkia* s_arcs_images_dark[kNumArcsImages - 1];
+ static gfx::ImageSkia* s_arcs_images_light[kNumArcsImages - 1];
+ int image_count = NumImagesForType(image_type) - 1;
+ int index = animation * nextafter(static_cast<float>(image_count), 0);
+ index = std::max(std::min(index, image_count - 1), 0);
+ gfx::ImageSkia** images;
+ bool dark = IconTypeIsDark(icon_type);
+ if (image_type == BARS)
+ images = dark ? s_bars_images_dark : s_bars_images_light;
+ else
+ images = dark ? s_arcs_images_dark : s_arcs_images_light;
+ if (!images[index]) {
+ // Lazily cache images.
+ gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1);
+ images[index] = new gfx::ImageSkia(
+ gfx::ImageSkiaOperations::CreateBlendedImage(
+ gfx::ImageSkia(new EmptyImageSource(source.size()), source.size()),
+ source,
+ kConnectingImageAlpha));
+ }
+ return images[index];
+}
+
+gfx::ImageSkia* ConnectingVpnImage(double animation) {
+ int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0);
+ static gfx::ImageSkia* s_vpn_images[kNumFadeImages];
+ if (!s_vpn_images[index]) {
+ // Lazily cache images.
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN);
+ s_vpn_images[index] = new gfx::ImageSkia(
+ gfx::ImageSkiaOperations::CreateBlendedImage(
+ gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()),
+ *icon,
+ animation));
+ }
+ return s_vpn_images[index];
+}
+
+gfx::ImageSkia* ConnectingVpnBadge(double animation) {
+ int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0);
+ static gfx::ImageSkia* s_vpn_badges[kNumFadeImages];
+ if (!s_vpn_badges[index]) {
+ // Lazily cache images.
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ gfx::ImageSkia* icon =
+ rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); // For size
+ gfx::ImageSkia* badge =
+ rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE);
+ s_vpn_badges[index] = new gfx::ImageSkia(
+ gfx::ImageSkiaOperations::CreateBlendedImage(
+ gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()),
+ *badge,
+ animation));
+ }
+ return s_vpn_badges[index];
+}
+
int StrengthIndex(int strength, int count) {
// Return an index in the range [1, count-1].
const float findex = (static_cast<float>(strength) / 100.0f) *
@@ -393,26 +443,40 @@ gfx::ImageSkia GetIcon(const NetworkState* network,
//------------------------------------------------------------------------------
// Get connecting images
-gfx::ImageSkia GetConnectingImage(const std::string& type, IconType icon_type) {
- ImageType image_type = ImageTypeForNetworkType(type);
- int image_count = NumImagesForType(image_type) - 1;
- gfx::ImageSkia** images = ImageListForType(image_type, icon_type);
+gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) {
+ NetworkStateHandler* handler = NetworkStateHandler::Get();
+ const NetworkState* connected_network = NULL;
+ if (icon_type == ICON_TYPE_TRAY) {
+ connected_network = handler->ConnectedNetworkByType(
+ NetworkStateHandler::kMatchTypeNonVirtual);
+ }
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);
- images[index] = new gfx::ImageSkia(
- gfx::ImageSkiaOperations::CreateBlendedImage(
- gfx::ImageSkia(new EmptyImageSource(source.size()), source.size()),
- source,
- kConnectingImageAlpha));
+ if (connected_network) {
+ gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type);
+ Badges badges;
+ badges.bottom_left = ConnectingVpnBadge(animation);
+ return gfx::ImageSkia(
+ new NetworkIconImageSource(icon, badges), icon.size());
+ } else {
+ gfx::ImageSkia* icon = ConnectingVpnImage(animation);
+ return gfx::ImageSkia(
+ new NetworkIconImageSource(*icon, Badges()), icon->size());
}
- gfx::ImageSkia& icon = *images[index];
+}
+
+gfx::ImageSkia GetConnectingImage(const std::string& network_type,
+ IconType icon_type) {
+ if (network_type == flimflam::kTypeVPN)
+ return GetConnectingVpnImage(icon_type);
+
+ ImageType image_type = ImageTypeForNetworkType(network_type);
+ double animation = NetworkIconAnimation::GetInstance()->GetAnimation();
+
+ gfx::ImageSkia* icon = ConnectingWirelessImage(
+ image_type, icon_type, animation);
return gfx::ImageSkia(
- new NetworkIconImageSource(icon, Badges()), icon.size());
+ new NetworkIconImageSource(*icon, Badges()), icon->size());
}
} // namespace
@@ -483,8 +547,7 @@ bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) {
bool NetworkIconImpl::UpdateVPNBadge() {
const NetworkState* vpn =
- chromeos::NetworkStateHandler::Get()->ConnectedNetworkByType(
- flimflam::kTypeVPN);
+ NetworkStateHandler::Get()->ConnectedNetworkByType(flimflam::kTypeVPN);
if (vpn && vpn_badge_ == NULL) {
vpn_badge_ = BadgeForVPN(icon_type_);
return true;
@@ -498,7 +561,7 @@ bool NetworkIconImpl::UpdateVPNBadge() {
void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) {
DCHECK(network);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- chromeos::NetworkStateHandler* handler = chromeos::NetworkStateHandler::Get();
+ NetworkStateHandler* handler = NetworkStateHandler::Get();
const std::string& type = network->type();
if (type == flimflam::kTypeWifi) {
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 699014a..aa973b0 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.cc
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc
@@ -773,6 +773,8 @@ void NetworkStateListDetailedView::ConnectToNetwork(
NetworkStateHandler::Get()->GetNetworkState(service_path);
if (!network)
return;
+ if (!network->IsConnectedState())
+ TrayNetworkStateObserver::AddConnectingNetwork(service_path);
if (CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kEnableNewNetworkConfigurationHandlers) &&
!network->IsConnectedState()) {
@@ -780,7 +782,6 @@ void NetworkStateListDetailedView::ConnectToNetwork(
service_path,
base::Bind(&base::DoNothing),
chromeos::network_handler::ErrorCallback());
- TrayNetworkStateObserver::AddConnectingNetwork(service_path);
} else {
// This will show the settings UI for a connected network.
// TODO(stevenjb): Change the API to explicitly show network settings.
diff --git a/ash/system/chromeos/network/tray_network.cc b/ash/system/chromeos/network/tray_network.cc
index 161d519..895a039 100644
--- a/ash/system/chromeos/network/tray_network.cc
+++ b/ash/system/chromeos/network/tray_network.cc
@@ -550,23 +550,32 @@ void TrayNetwork::GetNetworkStateHandlerImageAndLabel(
gfx::ImageSkia* image,
string16* label) {
NetworkStateHandler* handler = NetworkStateHandler::Get();
- const NetworkState* network = handler->ConnectedNetworkByType(
+ const NetworkState* connected_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 (!connecting_network && icon_type == network_icon::ICON_TYPE_TRAY)
+ connecting_network = handler->ConnectingNetworkByType(flimflam::kTypeVPN);
+
+ const NetworkState* network;
// 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 || TrayNetworkStateObserver::HasConnectingNetwork(
+ (!connected_network || TrayNetworkStateObserver::HasConnectingNetwork(
connecting_network->path()))) {
network = connecting_network;
+ } else {
+ network = connected_network;
}
+
+ // Don't show ethernet in the tray
+ if (icon_type == network_icon::ICON_TYPE_TRAY &&
+ network && network->type() == flimflam::kTypeEthernet) {
+ *image = gfx::ImageSkia();
+ return;
+ }
+
if (!network) {
// If no connecting network, check if we are activating a network.
const NetworkState* mobile_network = handler->FirstNetworkByType(
diff --git a/ash/system/chromeos/network/tray_vpn.cc b/ash/system/chromeos/network/tray_vpn.cc
index 7a6dace..42e3536 100644
--- a/ash/system/chromeos/network/tray_vpn.cc
+++ b/ash/system/chromeos/network/tray_vpn.cc
@@ -97,12 +97,12 @@ class VpnDefaultView : public TrayItemMore,
NetworkStateHandler* handler = NetworkStateHandler::Get();
const NetworkState* vpn = handler->FirstNetworkByType(
flimflam::kTypeVPN);
- if (!vpn) {
+ if (!vpn || (vpn->connection_state() == flimflam::kStateIdle)) {
*image = network_icon::GetImageForDisconnectedNetwork(
network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN);
if (label) {
*label = l10n_util::GetStringUTF16(
- IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED);
+ IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
}
return;
}