| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 5 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "ash/system/chromeos/network/network_icon_animation.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" | 14 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/image/image_skia_operations.h" | 22 #include "ui/gfx/image/image_skia_operations.h" |
| 22 #include "ui/gfx/image/image_skia_source.h" | 23 #include "ui/gfx/image/image_skia_source.h" |
| 23 #include "ui/gfx/size_conversions.h" | 24 #include "ui/gfx/size_conversions.h" |
| 24 | 25 |
| 25 using std::max; | 26 using std::max; |
| 26 using std::min; | 27 using std::min; |
| 27 | 28 |
| 29 using ash::network_icon::NetworkIconAnimation; |
| 30 |
| 28 namespace chromeos { | 31 namespace chromeos { |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 // Amount to fade icons while connecting. | 35 // Amount to fade icons while connecting. |
| 33 const double kConnectingImageAlpha = 0.5; | 36 const double kConnectingImageAlpha = 0.5; |
| 34 | 37 |
| 35 // Animation cycle length. | |
| 36 const int kThrobDurationMs = 750; | |
| 37 | |
| 38 // Images for strength bars for wired networks. | 38 // Images for strength bars for wired networks. |
| 39 const int kNumBarsImages = 5; | 39 const int kNumBarsImages = 5; |
| 40 gfx::ImageSkia* kBarsImagesAnimatingDark[kNumBarsImages - 1]; | 40 gfx::ImageSkia* kBarsImagesAnimatingDark[kNumBarsImages - 1]; |
| 41 gfx::ImageSkia* kBarsImagesAnimatingLight[kNumBarsImages - 1]; | 41 gfx::ImageSkia* kBarsImagesAnimatingLight[kNumBarsImages - 1]; |
| 42 | 42 |
| 43 // Imagaes for strength arcs for wireless networks. | 43 // Imagaes for strength arcs for wireless networks. |
| 44 const int kNumArcsImages = 5; | 44 const int kNumArcsImages = 5; |
| 45 gfx::ImageSkia* kArcsImagesAnimatingDark[kNumArcsImages - 1]; | 45 gfx::ImageSkia* kArcsImagesAnimatingDark[kNumArcsImages - 1]; |
| 46 gfx::ImageSkia* kArcsImagesAnimatingLight[kNumArcsImages - 1]; | 46 gfx::ImageSkia* kArcsImagesAnimatingLight[kNumArcsImages - 1]; |
| 47 | 47 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // Clears any previous state then sets the base icon and badges. | 275 // Clears any previous state then sets the base icon and badges. |
| 276 void UpdateIcon(const Network* network); | 276 void UpdateIcon(const Network* network); |
| 277 | 277 |
| 278 // Generates the image. Call after setting the icon and badges. | 278 // Generates the image. Call after setting the icon and badges. |
| 279 void GenerateImage(); | 279 void GenerateImage(); |
| 280 | 280 |
| 281 const gfx::ImageSkia GetImage() const { return image_; } | 281 const gfx::ImageSkia GetImage() const { return image_; } |
| 282 | 282 |
| 283 bool ShouldShowInTray() const; | 283 bool ShouldShowInTray() const; |
| 284 | 284 |
| 285 ConnectionType type() { return type_; } |
| 285 void set_type(ConnectionType type) { type_ = type; } | 286 void set_type(ConnectionType type) { type_ = type; } |
| 286 void set_state(ConnectionState state) { state_ = state; } | 287 void set_state(ConnectionState state) { state_ = state; } |
| 287 void set_icon(const gfx::ImageSkia& icon) { icon_ = icon; } | 288 void set_icon(const gfx::ImageSkia& icon) { icon_ = icon; } |
| 288 void set_top_left_badge(const gfx::ImageSkia* badge) { | 289 void set_top_left_badge(const gfx::ImageSkia* badge) { |
| 289 top_left_badge_ = badge; | 290 top_left_badge_ = badge; |
| 290 } | 291 } |
| 291 void set_top_right_badge(const gfx::ImageSkia* badge) { | 292 void set_top_right_badge(const gfx::ImageSkia* badge) { |
| 292 top_right_badge_ = badge; | 293 top_right_badge_ = badge; |
| 293 } | 294 } |
| 294 void set_bottom_left_badge(const gfx::ImageSkia* badge) { | 295 void set_bottom_left_badge(const gfx::ImageSkia* badge) { |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 return dirty; | 602 return dirty; |
| 602 } | 603 } |
| 603 | 604 |
| 604 //////////////////////////////////////////////////////////////////////////////// | 605 //////////////////////////////////////////////////////////////////////////////// |
| 605 // NetworkMenuIcon | 606 // NetworkMenuIcon |
| 606 | 607 |
| 607 NetworkMenuIcon::NetworkMenuIcon(Delegate* delegate, Mode mode) | 608 NetworkMenuIcon::NetworkMenuIcon(Delegate* delegate, Mode mode) |
| 608 : mode_(mode), | 609 : mode_(mode), |
| 609 delegate_(delegate), | 610 delegate_(delegate), |
| 610 resource_color_theme_(COLOR_DARK), | 611 resource_color_theme_(COLOR_DARK), |
| 611 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), | 612 connecting_index_(-1) { |
| 612 connecting_network_(NULL) { | |
| 613 // Set up the connection animation throbber. | |
| 614 animation_connecting_.SetThrobDuration(kThrobDurationMs); | |
| 615 animation_connecting_.SetTweenType(ui::Tween::LINEAR); | |
| 616 | |
| 617 // Initialize the icon. | 613 // Initialize the icon. |
| 618 icon_.reset(new NetworkIcon(resource_color_theme_)); | 614 icon_.reset(new NetworkIcon(resource_color_theme_)); |
| 619 } | 615 } |
| 620 | 616 |
| 621 NetworkMenuIcon::~NetworkMenuIcon() { | 617 NetworkMenuIcon::~NetworkMenuIcon() { |
| 622 } | 618 } |
| 623 | 619 |
| 624 // Public methods: | 620 // Public methods: |
| 625 | 621 |
| 626 void NetworkMenuIcon::SetResourceColorTheme(ResourceColorTheme color) { | 622 void NetworkMenuIcon::SetResourceColorTheme(ResourceColorTheme color) { |
| 627 if (color == resource_color_theme_) | 623 if (color == resource_color_theme_) |
| 628 return; | 624 return; |
| 629 | 625 |
| 630 resource_color_theme_ = color; | 626 resource_color_theme_ = color; |
| 631 icon_.reset(new NetworkIcon(resource_color_theme_)); | 627 icon_.reset(new NetworkIcon(resource_color_theme_)); |
| 632 } | 628 } |
| 633 | 629 |
| 634 bool NetworkMenuIcon::ShouldShowIconInTray() { | 630 bool NetworkMenuIcon::ShouldShowIconInTray() { |
| 635 if (!icon_.get()) | 631 if (!icon_.get()) |
| 636 return false; | 632 return false; |
| 637 return icon_->ShouldShowInTray(); | 633 return icon_->ShouldShowInTray(); |
| 638 } | 634 } |
| 639 | 635 |
| 640 const gfx::ImageSkia NetworkMenuIcon::GetIconAndText(string16* text) { | 636 const gfx::ImageSkia NetworkMenuIcon::GetIconAndText(string16* text) { |
| 641 SetIconAndText(); | 637 if (SetIconAndText()) |
| 638 NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 639 else |
| 640 NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 642 if (text) | 641 if (text) |
| 643 *text = text_; | 642 *text = text_; |
| 644 icon_->GenerateImage(); | 643 icon_->GenerateImage(); |
| 645 return icon_->GetImage(); | 644 return icon_->GetImage(); |
| 646 } | 645 } |
| 647 | 646 |
| 648 const gfx::ImageSkia NetworkMenuIcon::GetVpnIconAndText(string16* text) { | 647 const gfx::ImageSkia NetworkMenuIcon::GetVpnIconAndText(string16* text) { |
| 649 SetVpnIconAndText(); | 648 if (SetVpnIconAndText()) |
| 649 NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 650 else |
| 651 NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 650 if (text) | 652 if (text) |
| 651 *text = text_; | 653 *text = text_; |
| 652 icon_->GenerateImage(); | 654 icon_->GenerateImage(); |
| 653 return icon_->GetImage(); | 655 return icon_->GetImage(); |
| 654 } | 656 } |
| 655 | 657 |
| 656 void NetworkMenuIcon::AnimationProgressed(const ui::Animation* animation) { | 658 void NetworkMenuIcon::NetworkIconChanged() { |
| 657 if (animation == &animation_connecting_ && delegate_) { | 659 if (!delegate_ || !icon_.get()) |
| 658 // Only update the connecting network from here. | 660 return; |
| 659 if (GetConnectingNetwork() == connecting_network_) | 661 // Only send a message when the icon would change. |
| 660 delegate_->NetworkMenuIconChanged(); | 662 int connecting_index = GetConnectingIndex(); |
| 663 if (connecting_index != connecting_index_) { |
| 664 connecting_index_ = connecting_index; |
| 665 delegate_->NetworkMenuIconChanged(); |
| 661 } | 666 } |
| 662 } | 667 } |
| 663 | 668 |
| 664 // Private methods: | 669 // Private methods: |
| 665 | 670 |
| 666 // If disconnected: returns any connecting non-ethernet network. | 671 // If disconnected: returns any connecting non-ethernet network. |
| 667 // Otherwise, only return a network if the conenction was user initiated. | 672 // Otherwise, only return a network if the conenction was user initiated. |
| 668 const Network* NetworkMenuIcon::GetConnectingNetwork() { | 673 const Network* NetworkMenuIcon::GetConnectingNetwork() { |
| 669 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 674 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 670 const Network* connecting_network = cros->connecting_network(); | 675 const Network* connecting_network = cros->connecting_network(); |
| 671 if (connecting_network && | 676 if (connecting_network && |
| 672 connecting_network->type() != TYPE_ETHERNET && | 677 connecting_network->type() != TYPE_ETHERNET && |
| 673 (!cros->connected_network() || | 678 (!cros->connected_network() || |
| 674 connecting_network->connection_started())) { | 679 connecting_network->connection_started())) { |
| 675 return connecting_network; | 680 return connecting_network; |
| 676 } | 681 } |
| 677 return NULL; | 682 return NULL; |
| 678 } | 683 } |
| 679 | 684 |
| 680 double NetworkMenuIcon::GetAnimation() { | 685 double NetworkMenuIcon::GetAnimation() { |
| 681 if (!animation_connecting_.is_animating()) { | 686 return NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 682 animation_connecting_.Reset(); | |
| 683 animation_connecting_.StartThrobbing(-1 /*throb indefinitely*/); | |
| 684 return 0; | |
| 685 } | |
| 686 return animation_connecting_.GetCurrentValue(); | |
| 687 } | 687 } |
| 688 | 688 |
| 689 int NetworkMenuIcon::GetConnectingIndex() { |
| 690 DCHECK(icon_.get()); |
| 691 double animation = GetAnimation(); |
| 692 int image_count = |
| 693 (icon_->type() == TYPE_WIFI) ? kNumArcsImages - 1 : kNumBarsImages - 1; |
| 694 int index = animation * nextafter(static_cast<float>(image_count), 0); |
| 695 return std::max(std::min(index, image_count - 1), 0); |
| 696 } |
| 697 |
| 698 |
| 689 // TODO(stevenjb): move below SetIconAndText. | 699 // TODO(stevenjb): move below SetIconAndText. |
| 690 void NetworkMenuIcon::SetConnectingIconAndText() { | 700 void NetworkMenuIcon::SetConnectingIconAndText( |
| 691 int image_count; | 701 const Network* connecting_network) { |
| 692 ImageType image_type; | 702 connecting_network_ = connecting_network; |
| 693 gfx::ImageSkia** images; | |
| 694 | |
| 695 ConnectionType type; | 703 ConnectionType type; |
| 696 ConnectionState state; | 704 ConnectionState state; |
| 697 if (connecting_network_) { | 705 if (connecting_network_) { |
| 698 type = connecting_network_->type(); | 706 type = connecting_network_->type(); |
| 699 state = connecting_network_->state(); | 707 state = connecting_network_->state(); |
| 700 if (mode_ == MENU_MODE) { | 708 if (mode_ == MENU_MODE) { |
| 701 text_ = l10n_util::GetStringFUTF16( | 709 text_ = l10n_util::GetStringFUTF16( |
| 702 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, | 710 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, |
| 703 UTF8ToUTF16(connecting_network_->name())); | 711 UTF8ToUTF16(connecting_network_->name())); |
| 704 } else { | 712 } else { |
| 705 text_ = UTF8ToUTF16(connecting_network_->name()); | 713 text_ = UTF8ToUTF16(connecting_network_->name()); |
| 706 } | 714 } |
| 707 } else { | 715 } else { |
| 708 // When called with no connecting network, cellular is initializing. | 716 // When called with no connecting network, cellular is initializing. |
| 709 type = TYPE_CELLULAR; | 717 type = TYPE_CELLULAR; |
| 710 state = STATE_ASSOCIATION; | 718 state = STATE_ASSOCIATION; |
| 711 text_ = l10n_util::GetStringUTF16( | 719 text_ = l10n_util::GetStringUTF16( |
| 712 IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR); | 720 IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR); |
| 713 } | 721 } |
| 714 icon_->set_type(type); | 722 icon_->set_type(type); |
| 715 icon_->set_state(state); | 723 icon_->set_state(state); |
| 716 | 724 |
| 725 ImageType image_type; |
| 726 gfx::ImageSkia** images; |
| 717 if (type == TYPE_WIFI) { | 727 if (type == TYPE_WIFI) { |
| 718 image_count = kNumArcsImages - 1; | |
| 719 image_type = ARCS; | 728 image_type = ARCS; |
| 720 images = resource_color_theme_ == COLOR_DARK ? kArcsImagesAnimatingDark : | 729 images = resource_color_theme_ == COLOR_DARK ? kArcsImagesAnimatingDark : |
| 721 kArcsImagesAnimatingLight; | 730 kArcsImagesAnimatingLight; |
| 722 } else { | 731 } else { |
| 723 image_count = kNumBarsImages - 1; | |
| 724 image_type = BARS; | 732 image_type = BARS; |
| 725 images = resource_color_theme_ == COLOR_DARK ? kBarsImagesAnimatingDark : | 733 images = resource_color_theme_ == COLOR_DARK ? kBarsImagesAnimatingDark : |
| 726 kBarsImagesAnimatingLight; | 734 kBarsImagesAnimatingLight; |
| 727 } | 735 } |
| 728 int index = GetAnimation() * nextafter(static_cast<float>(image_count), 0); | 736 int index = GetConnectingIndex(); |
| 729 index = std::max(std::min(index, image_count - 1), 0); | |
| 730 | 737 |
| 731 // Lazily cache images. | 738 // Lazily cache images. |
| 732 if (!images[index]) { | 739 if (!images[index]) { |
| 733 gfx::ImageSkia source = | 740 gfx::ImageSkia source = |
| 734 GetImage(image_type, index + 1, resource_color_theme_); | 741 GetImage(image_type, index + 1, resource_color_theme_); |
| 735 images[index] = | 742 images[index] = |
| 736 new gfx::ImageSkia(NetworkMenuIcon::GenerateConnectingImage(source)); | 743 new gfx::ImageSkia(NetworkMenuIcon::GenerateConnectingImage(source)); |
| 737 } | 744 } |
| 738 icon_->set_icon(*images[index]); | 745 icon_->set_icon(*images[index]); |
| 739 if (connecting_network_) | 746 if (connecting_network_) |
| 740 icon_->SetBadges(connecting_network_); | 747 icon_->SetBadges(connecting_network_); |
| 741 } | 748 } |
| 742 | 749 |
| 743 // Sets up the icon and badges for GenerateBitmap(). | 750 // Sets up the icon and badges for GenerateBitmap(). |
| 744 void NetworkMenuIcon::SetIconAndText() { | 751 bool NetworkMenuIcon::SetIconAndText() { |
| 745 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 752 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 746 DCHECK(cros); | 753 DCHECK(cros); |
| 747 | 754 |
| 748 icon_->ClearIconAndBadges(); | 755 icon_->ClearIconAndBadges(); |
| 749 | 756 |
| 750 // If we are connecting to a network and it was user-initiated or we are | 757 // If we are connecting to a network and it was user-initiated or we are |
| 751 // not connected, display that. | 758 // not connected, display that. |
| 752 connecting_network_ = GetConnectingNetwork(); | 759 const Network* connecting_network = GetConnectingNetwork(); |
| 753 if (connecting_network_) { | 760 if (connecting_network) { |
| 754 SetConnectingIconAndText(); | 761 SetConnectingIconAndText(connecting_network); |
| 755 return; | 762 return true; |
| 756 } | 763 } |
| 757 | 764 |
| 758 // If not connecting to a network, show the active or connected network. | 765 // If not connecting to a network, show the active or connected network. |
| 759 const Network* network; | 766 const Network* network; |
| 760 if (mode_ == DROPDOWN_MODE && cros->connected_network()) | 767 if (mode_ == DROPDOWN_MODE && cros->connected_network()) |
| 761 network = cros->connected_network(); | 768 network = cros->connected_network(); |
| 762 else | 769 else |
| 763 network = cros->active_nonvirtual_network(); | 770 network = cros->active_nonvirtual_network(); |
| 764 if (network) { | 771 if (network) |
| 765 SetActiveNetworkIconAndText(network); | 772 return SetActiveNetworkIconAndText(network); |
| 766 return; | |
| 767 } | |
| 768 | 773 |
| 769 // If no connected network, check if we are initializing Cellular. | 774 // If no connected network, check if we are initializing Cellular. |
| 770 if (mode_ != DROPDOWN_MODE && cros->cellular_initializing()) { | 775 if (mode_ != DROPDOWN_MODE && cros->cellular_initializing()) { |
| 771 initialize_state_time_ = base::Time::Now(); | 776 initialize_state_time_ = base::Time::Now(); |
| 772 SetConnectingIconAndText(); | 777 SetConnectingIconAndText(NULL); |
| 773 return; | 778 return true; |
| 774 } | 779 } |
| 775 // There can be a delay between leaving the Initializing state and when a | 780 // There can be a delay between leaving the Initializing state and when a |
| 776 // Cellular device shows up, so keep showing the initializing animation | 781 // Cellular device shows up, so keep showing the initializing animation |
| 777 // for a few extra seconds to avoid flashing the disconnect icon. | 782 // for a few extra seconds to avoid flashing the disconnect icon. |
| 778 const int kInitializingDelaySeconds = 1; | 783 const int kInitializingDelaySeconds = 1; |
| 779 base::TimeDelta dtime = base::Time::Now() - initialize_state_time_; | 784 base::TimeDelta dtime = base::Time::Now() - initialize_state_time_; |
| 780 if (dtime.InSeconds() < kInitializingDelaySeconds) { | 785 if (dtime.InSeconds() < kInitializingDelaySeconds) { |
| 781 SetConnectingIconAndText(); | 786 SetConnectingIconAndText(NULL); |
| 782 return; | 787 return true; |
| 783 } | 788 } |
| 784 | 789 |
| 785 // Not connecting, so stop animation. | |
| 786 animation_connecting_.Stop(); | |
| 787 | |
| 788 // No connecting, connected, or active network. | 790 // No connecting, connected, or active network. |
| 789 SetDisconnectedIconAndText(); | 791 SetDisconnectedIconAndText(); |
| 792 return false; |
| 790 } | 793 } |
| 791 | 794 |
| 792 void NetworkMenuIcon::SetVpnIconAndText() { | 795 bool NetworkMenuIcon::SetVpnIconAndText() { |
| 793 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 796 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 794 DCHECK(cros); | 797 DCHECK(cros); |
| 795 | 798 |
| 796 icon_->ClearIconAndBadges(); | 799 icon_->ClearIconAndBadges(); |
| 797 const VirtualNetwork* vpn = cros->virtual_network(); | 800 const VirtualNetwork* vpn = cros->virtual_network(); |
| 798 if (!vpn) { | 801 if (!vpn) { |
| 799 NOTREACHED(); | 802 LOG(WARNING) << "SetVpnIconAndText called with no VPN"; |
| 800 SetDisconnectedIconAndText(); | 803 SetDisconnectedIconAndText(); |
| 801 return; | 804 return false; |
| 802 } | 805 } |
| 803 if (vpn->connecting()) { | 806 if (vpn->connecting()) { |
| 804 connecting_network_ = vpn; | 807 SetConnectingIconAndText(vpn); |
| 805 SetConnectingIconAndText(); | 808 return true; |
| 806 return; | |
| 807 } | 809 } |
| 808 | 810 |
| 809 // If not connecting to a network, show the active/connected VPN. | 811 // If not connecting to a VPN, show the active/connected VPN. |
| 810 SetActiveNetworkIconAndText(vpn); | 812 return SetActiveNetworkIconAndText(vpn); |
| 811 } | 813 } |
| 812 | 814 |
| 813 void NetworkMenuIcon::SetActiveNetworkIconAndText(const Network* network) { | 815 bool NetworkMenuIcon::SetActiveNetworkIconAndText(const Network* network) { |
| 814 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 816 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 815 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 817 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 816 bool animating = false; | 818 bool animating = false; |
| 817 | 819 |
| 818 // Set icon and badges. Call SetDirty() since network may have changed. | 820 // Set icon and badges. Call SetDirty() since network may have changed. |
| 819 icon_->SetDirty(); | 821 icon_->SetDirty(); |
| 820 icon_->SetOrClearVpnConnected(network); | 822 icon_->SetOrClearVpnConnected(network); |
| 821 icon_->UpdateIcon(network); | 823 icon_->UpdateIcon(network); |
| 822 // Overlay the VPN badge if connecting to a VPN. | 824 // Overlay the VPN badge if connecting to a VPN. |
| 823 if (network->type() != TYPE_VPN && | 825 if (network->type() != TYPE_VPN && |
| 824 cros->virtual_network() && cros->virtual_network()->connecting()) { | 826 cros->virtual_network() && cros->virtual_network()->connecting()) { |
| 825 const gfx::ImageSkia* vpn_badge = | 827 const gfx::ImageSkia* vpn_badge = |
| 826 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 828 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
| 827 const double animation = GetAnimation(); | 829 const double animation = GetAnimation(); |
| 828 animating = true; | 830 animating = true; |
| 829 // Even though this is the only place we use vpn_connecting_badge_, | 831 // Even though this is the only place we use vpn_connecting_badge_, |
| 830 // it is important that this is a member variable since we set a | 832 // it is important that this is a member variable since we set a |
| 831 // pointer to it and access that pointer in icon_->GenerateImage(). | 833 // pointer to it and access that pointer in icon_->GenerateImage(). |
| 832 vpn_connecting_badge_ = gfx::ImageSkiaOperations::CreateBlendedImage( | 834 vpn_connecting_badge_ = gfx::ImageSkiaOperations::CreateBlendedImage( |
| 833 GetEmptyImage(vpn_badge->size()), *vpn_badge, animation); | 835 GetEmptyImage(vpn_badge->size()), *vpn_badge, animation); |
| 834 icon_->set_bottom_left_badge(&vpn_connecting_badge_); | 836 icon_->set_bottom_left_badge(&vpn_connecting_badge_); |
| 835 } | 837 } |
| 836 if (!animating) | |
| 837 animation_connecting_.Stop(); | |
| 838 | 838 |
| 839 // Set the text to display. | 839 // Set the text to display. |
| 840 if (network->type() == TYPE_ETHERNET) { | 840 if (network->type() == TYPE_ETHERNET) { |
| 841 if (mode_ == MENU_MODE) { | 841 if (mode_ == MENU_MODE) { |
| 842 text_ = l10n_util::GetStringFUTF16( | 842 text_ = l10n_util::GetStringFUTF16( |
| 843 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 843 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 844 l10n_util::GetStringUTF16( | 844 l10n_util::GetStringUTF16( |
| 845 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); | 845 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); |
| 846 } else { | 846 } else { |
| 847 text_ = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | 847 text_ = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); |
| 848 } | 848 } |
| 849 } else { | 849 } else { |
| 850 if (mode_ == MENU_MODE) { | 850 if (mode_ == MENU_MODE) { |
| 851 text_ = l10n_util::GetStringFUTF16( | 851 text_ = l10n_util::GetStringFUTF16( |
| 852 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, | 852 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 853 UTF8ToUTF16(network->name())); | 853 UTF8ToUTF16(network->name())); |
| 854 } else { | 854 } else { |
| 855 text_ = UTF8ToUTF16(network->name()); | 855 text_ = UTF8ToUTF16(network->name()); |
| 856 } | 856 } |
| 857 } | 857 } |
| 858 return animating; |
| 858 } | 859 } |
| 859 | 860 |
| 860 void NetworkMenuIcon::SetDisconnectedIconAndText() { | 861 void NetworkMenuIcon::SetDisconnectedIconAndText() { |
| 861 icon_->set_icon(GetDisconnectedImage(ARCS, resource_color_theme_)); | 862 icon_->set_icon(GetDisconnectedImage(ARCS, resource_color_theme_)); |
| 862 if (mode_ == MENU_MODE) | 863 if (mode_ == MENU_MODE) |
| 863 text_ = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP); | 864 text_ = l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP); |
| 864 else | 865 else |
| 865 text_ = l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_NONE_SELECTED); | 866 text_ = l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_NONE_SELECTED); |
| 866 } | 867 } |
| 867 | 868 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 gfx::ImageSkia* NetworkMenuIcon::GetVirtualNetworkImage() { | 970 gfx::ImageSkia* NetworkMenuIcon::GetVirtualNetworkImage() { |
| 970 return ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 971 return ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 971 IDR_AURA_UBER_TRAY_NETWORK_VPN); | 972 IDR_AURA_UBER_TRAY_NETWORK_VPN); |
| 972 } | 973 } |
| 973 | 974 |
| 974 int NetworkMenuIcon::NumImages(ImageType type) { | 975 int NetworkMenuIcon::NumImages(ImageType type) { |
| 975 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; | 976 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; |
| 976 } | 977 } |
| 977 | 978 |
| 978 } // chromeos | 979 } // chromeos |
| OLD | NEW |