Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: ash/common/system/chromeos/network/network_state_list_detailed_view.cc

Issue 2742513003: Revert of Remove a lot of pre-MD code from NetworkStateListDetailedView (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/common/system/chromeos/network/network_state_list_detailed_view.cc
diff --git a/ash/common/system/chromeos/network/network_state_list_detailed_view.cc b/ash/common/system/chromeos/network/network_state_list_detailed_view.cc
index 6b72f843ab88f6da3941d0006926a1d059e00180..14e9becd36959fc94a68b70d4ebedd92cf45ccab 100644
--- a/ash/common/system/chromeos/network/network_state_list_detailed_view.cc
+++ b/ash/common/system/chromeos/network/network_state_list_detailed_view.cc
@@ -8,10 +8,11 @@
#include <vector>
#include "ash/common/ash_constants.h"
-#include "ash/common/strings/grit/ash_strings.h"
+#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/system/chromeos/network/network_icon.h"
#include "ash/common/system/chromeos/network/network_icon_animation.h"
#include "ash/common/system/chromeos/network/network_info.h"
+#include "ash/common/system/chromeos/network/network_list.h"
#include "ash/common/system/chromeos/network/network_list_md.h"
#include "ash/common/system/chromeos/network/network_list_view_base.h"
#include "ash/common/system/chromeos/network/tray_network_state_observer.h"
@@ -73,6 +74,10 @@
namespace tray {
namespace {
+bool UseMd() {
+ return MaterialDesignController::IsSystemTrayMenuMaterial();
+}
+
// Delay between scan requests.
const int kRequestScanDelaySeconds = 10;
@@ -160,6 +165,95 @@
NetworkStateListDetailedView* detailed_view_;
DISALLOW_COPY_AND_ASSIGN(InfoBubble);
+};
+
+//------------------------------------------------------------------------------
+
+const int kFadeIconMs = 500;
+
+// A throbber view that fades in/out when shown/hidden.
+class ScanningThrobber : public ThrobberView {
+ public:
+ ScanningThrobber() {
+ SetPaintToLayer();
+ layer()->SetFillsBoundsOpaquely(false);
+ layer()->SetOpacity(1.0);
+ accessible_name_ =
+ l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE);
+ }
+ ~ScanningThrobber() override {}
+
+ // views::View
+ void SetVisible(bool visible) override {
+ layer()->GetAnimator()->StopAnimating(); // Stop any previous animation.
+ ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
+ animation.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kFadeIconMs));
+ layer()->SetOpacity(visible ? 1.0 : 0.0);
+ }
+
+ void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
+ node_data->SetName(accessible_name_);
+ node_data->role = ui::AX_ROLE_BUSY_INDICATOR;
+ }
+
+ private:
+ base::string16 accessible_name_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScanningThrobber);
+};
+
+//------------------------------------------------------------------------------
+
+// An image button showing the info icon similar to TrayPopupHeaderButton,
+// but without the toggle properties, that fades in/out when shown/hidden.
+class InfoIcon : public views::ImageButton {
+ public:
+ explicit InfoIcon(views::ButtonListener* listener)
+ : views::ImageButton(listener) {
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ SetImage(
+ STATE_NORMAL,
+ bundle.GetImageNamed(IDR_AURA_UBER_TRAY_NETWORK_INFO).ToImageSkia());
+ SetImage(STATE_HOVERED,
+ bundle.GetImageNamed(IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER)
+ .ToImageSkia());
+ SetImageAlignment(ALIGN_CENTER, ALIGN_MIDDLE);
+ SetAccessibleName(
+ bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_INFO));
+ SetPaintToLayer();
+ layer()->SetFillsBoundsOpaquely(false);
+ layer()->SetOpacity(1.0);
+ }
+
+ ~InfoIcon() override {}
+
+ // views::View
+ gfx::Size GetPreferredSize() const override {
+ return gfx::Size(kTrayPopupItemMinHeight, kTrayPopupItemMinHeight);
+ }
+
+ void SetVisible(bool visible) override {
+ layer()->GetAnimator()->StopAnimating(); // Stop any previous animation.
+ ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
+ animation.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(kFadeIconMs));
+ layer()->SetOpacity(visible ? 1.0 : 0.0);
+ }
+
+ // views::CustomButton
+ void StateChanged(ButtonState old_state) override {
+ if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
+ set_background(views::Background::CreateSolidBackground(
+ kTrayPopupHoverBackgroundColor));
+ } else {
+ set_background(nullptr);
+ }
+ SchedulePaint();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(InfoIcon);
};
//------------------------------------------------------------------------------
@@ -222,16 +316,25 @@
: NetworkDetailedView(owner),
list_type_(list_type),
login_(login),
- info_button_(nullptr),
- settings_button_(nullptr),
- proxy_settings_button_(nullptr),
- info_bubble_(nullptr) {
+ prev_wifi_scanning_state_(false),
+ info_icon_(nullptr),
+ info_button_md_(nullptr),
+ settings_button_md_(nullptr),
+ proxy_settings_button_md_(nullptr),
+ info_bubble_(nullptr),
+ scanning_throbber_(nullptr) {
if (list_type == LIST_TYPE_VPN) {
// Use a specialized class to list VPNs.
network_list_view_.reset(new VPNListView(this));
} else {
// Use a common class to list any other network types.
- network_list_view_.reset(new NetworkListView(this));
+ // TODO(varkha): NetworkListViewMd is a temporary fork of NetworkListView.
+ // NetworkListView will go away when Material Design becomes default.
+ // See crbug.com/614453.
+ if (UseMd())
+ network_list_view_.reset(new NetworkListViewMd(this));
+ else
+ network_list_view_.reset(new NetworkListView(this));
}
}
@@ -250,11 +353,15 @@
void NetworkStateListDetailedView::Init() {
Reset();
- info_button_ = nullptr;
- settings_button_ = nullptr;
- proxy_settings_button_ = nullptr;
+ info_icon_ = nullptr;
+ info_button_md_ = nullptr;
+ settings_button_md_ = nullptr;
+ proxy_settings_button_md_ = nullptr;
+ scanning_throbber_ = nullptr;
CreateScrollableList();
+ if (!UseMd())
+ CreateNetworkExtra();
CreateTitleRow(list_type_ == ListType::LIST_TYPE_NETWORK
? IDS_ASH_STATUS_TRAY_NETWORK
: IDS_ASH_STATUS_TRAY_VPN);
@@ -273,12 +380,12 @@
void NetworkStateListDetailedView::HandleButtonPressed(views::Button* sender,
const ui::Event& event) {
- if (sender == info_button_) {
+ if (sender == info_button_md_) {
ToggleInfoBubble();
return;
- } else if (sender == settings_button_) {
+ } else if (sender == settings_button_md_) {
ShowSettings();
- } else if (sender == proxy_settings_button_) {
+ } else if (sender == proxy_settings_button_md_) {
WmShell::Get()->system_tray_controller()->ShowProxySettings();
}
@@ -320,17 +427,17 @@
if (login_ == LoginStatus::LOCKED)
return;
- DCHECK(!info_button_);
+ DCHECK(!info_button_md_);
tri_view()->SetContainerVisible(TriView::Container::END, true);
- info_button_ = new SystemMenuButton(
+ info_button_md_ = new SystemMenuButton(
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuInfoIcon,
IDS_ASH_STATUS_TRAY_NETWORK_INFO);
- tri_view()->AddView(TriView::Container::END, info_button_);
+ tri_view()->AddView(TriView::Container::END, info_button_md_);
if (login_ != LoginStatus::NOT_LOGGED_IN) {
- DCHECK(!settings_button_);
- settings_button_ = new SystemMenuButton(
+ DCHECK(!settings_button_md_);
+ settings_button_md_ = new SystemMenuButton(
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_NETWORK_SETTINGS);
@@ -339,14 +446,14 @@
// creation flow) when session is started but UI flow continues within
// login UI, i.e., no browser window is yet avaialable.
if (!WmShell::Get()->system_tray_delegate()->ShouldShowSettings())
- settings_button_->SetEnabled(false);
-
- tri_view()->AddView(TriView::Container::END, settings_button_);
+ settings_button_md_->SetEnabled(false);
+
+ tri_view()->AddView(TriView::Container::END, settings_button_md_);
} else {
- proxy_settings_button_ = new SystemMenuButton(
+ proxy_settings_button_md_ = new SystemMenuButton(
this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon,
IDS_ASH_STATUS_TRAY_NETWORK_PROXY_SETTINGS);
- tri_view()->AddView(TriView::Container::END, proxy_settings_button_);
+ tri_view()->AddView(TriView::Container::END, proxy_settings_button_md_);
}
}
@@ -357,32 +464,104 @@
WmShell::Get()->system_tray_controller()->ShowNetworkSettings(std::string());
}
+void NetworkStateListDetailedView::CreateNetworkExtra() {
+ DCHECK(!UseMd());
+}
+
+void NetworkStateListDetailedView::SetScanningStateForThrobberView(
+ bool is_scanning) {
+ if (UseMd())
+ return;
+
+ // Hide the network info button if the device is scanning for Wi-Fi networks
+ // and display the WiFi scanning indicator.
+ info_icon_->SetVisible(!is_scanning);
+ scanning_throbber_->SetVisible(is_scanning);
+ // Set the element, network info button or the wifi scanning indicator, as
+ // focusable based on which one is active/visible.
+ // NOTE: As we do not want to lose focus from the network info throbber view,
+ // the order of below operation is important.
+ if (is_scanning) {
+ scanning_throbber_->SetFocusBehavior(FocusBehavior::ALWAYS);
+ info_icon_->SetFocusBehavior(FocusBehavior::NEVER);
+ } else {
+ info_icon_->SetFocusBehavior(FocusBehavior::ALWAYS);
+ scanning_throbber_->SetFocusBehavior(FocusBehavior::NEVER);
+ }
+ // If the Network Info view was in focus while this toggle operation was
+ // being performed then the focus should remain on this view.
+ if (info_icon_->HasFocus() && is_scanning)
+ scanning_throbber_->RequestFocus();
+ else if (scanning_throbber_->HasFocus() && !is_scanning)
+ info_icon_->RequestFocus();
+}
+
+void NetworkStateListDetailedView::UpdateTechnologyButton(
+ TrayPopupHeaderButton* button,
+ const NetworkTypePattern& technology) {
+ NetworkStateHandler::TechnologyState state =
+ NetworkHandler::Get()->network_state_handler()->GetTechnologyState(
+ technology);
+ if (state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) {
+ button->SetVisible(false);
+ return;
+ }
+ button->SetVisible(true);
+ if (state == NetworkStateHandler::TECHNOLOGY_AVAILABLE) {
+ button->SetEnabled(true);
+ button->SetToggled(true);
+ } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLED) {
+ button->SetEnabled(true);
+ button->SetToggled(false);
+ } else if (state == NetworkStateHandler::TECHNOLOGY_ENABLING) {
+ button->SetEnabled(false);
+ button->SetToggled(false);
+ } else { // Initializing
+ button->SetEnabled(false);
+ button->SetToggled(true);
+ }
+}
+
void NetworkStateListDetailedView::UpdateNetworkList() {
network_list_view_->Update();
}
void NetworkStateListDetailedView::UpdateHeaderButtons() {
- if (proxy_settings_button_) {
- proxy_settings_button_->SetEnabled(
+ if (proxy_settings_button_md_) {
+ proxy_settings_button_md_->SetEnabled(
NetworkHandler::Get()->network_state_handler()->DefaultNetwork() !=
nullptr);
}
+
if (list_type_ != LIST_TYPE_VPN) {
bool scanning =
NetworkHandler::Get()->network_state_handler()->GetScanningByType(
NetworkTypePattern::WiFi());
ShowProgress(-1, scanning);
- info_button_->SetTooltipText(l10n_util::GetStringUTF16(
+ info_button_md_->SetTooltipText(l10n_util::GetStringUTF16(
scanning ? IDS_ASH_STATUS_TRAY_WIFI_SCANNING_MESSAGE
: IDS_ASH_STATUS_TRAY_NETWORK_INFO));
}
+}
+
+bool NetworkStateListDetailedView::OrderChild(views::View* view, int index) {
+ if (scroll_content()->child_at(index) != view) {
+ scroll_content()->ReorderChildView(view, index);
+ return true;
+ }
+ return false;
+}
+
+void NetworkStateListDetailedView::CreateSettingsEntry() {
+ DCHECK(!UseMd());
}
void NetworkStateListDetailedView::ToggleInfoBubble() {
if (ResetInfoBubble())
return;
- info_bubble_ = new InfoBubble(info_button_, CreateNetworkInfoView(), this);
+ info_bubble_ = new InfoBubble(UseMd() ? info_button_md_ : info_icon_,
+ CreateNetworkInfoView(), this);
views::BubbleDialogDelegateView::CreateBubble(info_bubble_)->Show();
info_bubble_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
}
@@ -459,6 +638,18 @@
}
return container;
+}
+
+const gfx::ImageSkia*
+NetworkStateListDetailedView::GetControlledByExtensionIcon() {
+ // Lazily load the icon from the resource bundle.
+ if (controlled_by_extension_icon_.IsEmpty()) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ controlled_by_extension_icon_ =
+ rb.GetImageNamed(IDR_AURA_UBER_TRAY_NETWORK_CONTROLLED);
+ }
+ DCHECK(!controlled_by_extension_icon_.IsEmpty());
+ return controlled_by_extension_icon_.ToImageSkia();
}
views::View* NetworkStateListDetailedView::CreateControlledByExtensionView(
@@ -481,9 +672,7 @@
views::ImageView* controlled_icon =
new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
- controlled_icon->SetImage(
- ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_AURA_UBER_TRAY_NETWORK_CONTROLLED));
+ controlled_icon->SetImage(GetControlledByExtensionIcon());
controlled_icon->SetTooltipText(tooltip_text);
return controlled_icon;
}
@@ -496,6 +685,13 @@
FROM_HERE,
base::Bind(&NetworkStateListDetailedView::CallRequestScan, AsWeakPtr()),
base::TimeDelta::FromSeconds(kRequestScanDelaySeconds));
+}
+
+void NetworkStateListDetailedView::ToggleMobile() {
+ NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
+ bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::Mobile());
+ chromeos::NetworkConnect::Get()->SetTechnologyEnabled(
+ NetworkTypePattern::Mobile(), !enabled);
}
views::View* NetworkStateListDetailedView::CreateViewForNetwork(
@@ -508,6 +704,10 @@
else
container->AddIconAndLabel(info.image, info.label, info.highlight);
container->set_tooltip(info.tooltip);
+ if (!UseMd()) {
+ container->SetBorder(
+ views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
+ }
views::View* controlled_icon = CreateControlledByExtensionView(info);
if (controlled_icon)
container->AddChildView(controlled_icon);
« no previous file with comments | « ash/common/system/chromeos/network/network_state_list_detailed_view.h ('k') | ash/resources/ash_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698