Commit e918a7d9 authored by Tony de Luna's avatar Tony de Luna Committed by Commit Bot

NetworkList: Refactor section headers

Changes in this cl:
 * Split SectionHeaderRowView and subclasses to a new file.
 * Remove the concept of a "subtitle" in a section header.
 * MobileHeaderRowView no longer subscribes to network updates directly,
   toggle status is triggered by NetworkListView.
 * Display mobile status messages with similar logic as we display WiFi
   status messages.
 * Initializes section headers on NetworkListView constructor to
   simplify logic.
 * Removes unused headers.

Current UI spec no longer has the concept of a "subtitle". It was
confusing that mobile status messages were being shown as a
"subtitle", while WiFi status messages are a label in NetworkListView.

Mobile toggle state and status message logic is complex. Decided to make
NetworkListView call MobileHeaderView to get the mobile status message.
This way we can re-use existing subtitle selection logic.

Change-Id: I46c99d01100db39cc4541910d3b19f670cd1fc50
Reviewed-on: https://chromium-review.googlesource.com/c/1371902
Commit-Queue: Tony De Luna <tonydeluna@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615762}
parent bb0389f4
......@@ -794,6 +794,8 @@ component("ash") {
"system/network/network_observer.h",
"system/network/network_row_title_view.cc",
"system/network/network_row_title_view.h",
"system/network/network_section_header_view.cc",
"system/network/network_section_header_view.h",
"system/network/network_state_list_detailed_view.cc",
"system/network/network_state_list_detailed_view.h",
"system/network/network_tray_icon_strategy.cc",
......
This diff is collapsed.
......@@ -29,14 +29,15 @@ class TrayInfoLabel;
class TriView;
namespace tray {
class NetworkSectionHeaderView;
class MobileSectionHeaderView;
class WifiSectionHeaderView;
// A list of available networks of a given type. This class is used for all
// network types except VPNs. For VPNs, see the |VPNList| class.
class NetworkListView : public NetworkStateListDetailedView,
public network_icon::AnimationObserver {
public:
class SectionHeaderRowView;
NetworkListView(DetailedViewDelegate* delegate, LoginStatus login);
~NetworkListView() override;
......@@ -114,15 +115,15 @@ class NetworkListView : public NetworkStateListDetailedView,
int insertion_index,
TrayInfoLabel** info_label_ptr);
// Creates a cellular/tether/Wi-Fi header row |view| and adds it to
// |scroll_content()| if necessary and reorders the |scroll_content()| placing
// the |view| at |child_index|. Returns the index where the next child should
// be inserted, i.e., the index directly after the last inserted child.
int UpdateSectionHeaderRow(chromeos::NetworkTypePattern pattern,
bool enabled,
int child_index,
SectionHeaderRowView** view,
views::Separator** separator_view);
// Updates a cellular/Wi-Fi header row |view| and reorders the
// |scroll_content()| placing the |view| at |child_index|. Returns the index
// where the next child should be inserted, i.e., the index directly after the
// last inserted child.
int UpdateNetworkSectionHeader(chromeos::NetworkTypePattern pattern,
bool enabled,
int child_index,
NetworkSectionHeaderView* view,
views::Separator** separator_view);
// network_icon::AnimationObserver:
void NetworkIconChanged() override;
......@@ -131,14 +132,16 @@ class NetworkListView : public NetworkStateListDetailedView,
// otherwise false.
bool NeedUpdateViewForNetwork(const NetworkInfo& info) const;
bool needs_relayout_;
bool needs_relayout_ = false;
TrayInfoLabel* no_wifi_networks_view_;
SectionHeaderRowView* mobile_header_view_;
SectionHeaderRowView* wifi_header_view_;
views::Separator* mobile_separator_view_;
views::Separator* wifi_separator_view_;
TriView* connection_warning_;
// Owned by the views heirarchy.
TrayInfoLabel* mobile_status_message_ = nullptr;
TrayInfoLabel* wifi_status_message_ = nullptr;
MobileSectionHeaderView* mobile_header_view_ = nullptr;
WifiSectionHeaderView* wifi_header_view_ = nullptr;
views::Separator* mobile_separator_view_ = nullptr;
views::Separator* wifi_separator_view_ = nullptr;
TriView* connection_warning_ = nullptr;
// An owned list of network info.
std::vector<std::unique_ptr<NetworkInfo>> network_list_;
......
......@@ -21,8 +21,7 @@ const int kLineHeight = 20;
} // namespace
NetworkRowTitleView::NetworkRowTitleView(int title_message_id)
: title_(TrayPopupUtils::CreateDefaultLabel()),
subtitle_(TrayPopupUtils::CreateDefaultLabel()) {
: title_(TrayPopupUtils::CreateDefaultLabel()) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
......@@ -31,26 +30,7 @@ NetworkRowTitleView::NetworkRowTitleView(int title_message_id)
title_->SetLineHeight(kLineHeight);
title_->SetText(l10n_util::GetStringUTF16(title_message_id));
AddChildView(title_);
TrayPopupItemStyle subtitle_style(TrayPopupItemStyle::FontStyle::SYSTEM_INFO);
subtitle_style.SetupLabel(subtitle_);
subtitle_->SetMultiLine(true);
subtitle_->SetLineHeight(kLineHeight);
subtitle_->SetVisible(false);
AddChildView(subtitle_);
}
NetworkRowTitleView::~NetworkRowTitleView() = default;
void NetworkRowTitleView::SetSubtitle(int subtitle_message_id) {
if (subtitle_message_id) {
subtitle_->SetText(l10n_util::GetStringUTF16(subtitle_message_id));
subtitle_->SetVisible(true);
return;
}
subtitle_->SetText(base::string16());
subtitle_->SetVisible(false);
}
} // namespace ash
......@@ -11,19 +11,14 @@
namespace ash {
// Title row for the network section of quick settings, which displays the name
// of a network type (e.g., Wi-Fi or Mobile data). Supports displaying a title
// by itself or a title with an associated subtitle.
// of a network type (e.g., Wi-Fi or Mobile data).
class ASH_EXPORT NetworkRowTitleView : public views::View {
public:
explicit NetworkRowTitleView(int title_message_id);
~NetworkRowTitleView() override;
// Sets the subtitle. If |message_id| is 0, no subtitle will be shown.
void SetSubtitle(int subtitle_message_id);
private:
views::Label* const title_;
views::Label* const subtitle_;
DISALLOW_COPY_AND_ASSIGN(NetworkRowTitleView);
};
......
This diff is collapsed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_NETWORK_NETWORK_SECTION_HEADER_VIEW_H_
#define ASH_SYSTEM_NETWORK_NETWORK_SECTION_HEADER_VIEW_H_
#include "ash/system/network/network_row_title_view.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ash/system/tray/tri_view.h"
#include "chromeos/network/network_state_handler.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
namespace ash {
namespace tray {
// A header row for sections in network detailed view which contains a title and
// a toggle button to turn on/off the section. Subclasses are given the
// opportunity to add extra buttons before the toggle button is added.
class NetworkSectionHeaderView : public views::View,
public views::ButtonListener {
public:
explicit NetworkSectionHeaderView(int title_id);
~NetworkSectionHeaderView() override = default;
// Modify visibility of section toggle
void SetToggleVisibility(bool visible);
// Modify enabled/disabled and on/off state of toggle.
virtual void SetToggleState(bool toggle_enabled, bool is_on);
protected:
void Init(bool enabled);
// This is called before the toggle button is added to give subclasses an
// opportunity to add more buttons before the toggle button. Subclasses can
// add buttons to container() using AddChildView().
virtual void AddExtraButtons(bool enabled);
// Called when |toggle_| is clicked and toggled. Subclasses can override to
// enabled/disable their respective technology, for example.
virtual void OnToggleToggled(bool is_on) = 0;
TriView* container() const { return container_; }
// views::View:
int GetHeightForWidth(int width) const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
void InitializeLayout();
void AddToggleButton(bool enabled);
// Resource ID for the string to use as the title of the section and for the
// accessible text on the section header toggle button.
const int title_id_;
// View containing header row views, including title, toggle, and extra
// buttons.
TriView* container_ = nullptr;
// View containing the header row view. Is a child of the CENTER of
// |container_|.
NetworkRowTitleView* network_row_title_view_ = nullptr;
// ToggleButton to toggle section on or off.
views::ToggleButton* toggle_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(NetworkSectionHeaderView);
};
// "Mobile Data" header row. Mobile Data reflects both Cellular state and
// Tether state. When both technologies are available, Cellular state takes
// precedence over Tether (but in some cases Tether state may be shown).
class MobileSectionHeaderView : public NetworkSectionHeaderView {
public:
MobileSectionHeaderView();
~MobileSectionHeaderView() override;
// Updates mobile toggle state and returns the id of the status message
// that should be shown while connecting to a network. Returns zero when no
// message should be shown.
int UpdateToggleAndGetStatusMessage();
// views::View:
const char* GetClassName() const override;
private:
// NetworkListView::NetworkSectionHeaderView:
void OnToggleToggled(bool is_on) override;
// When Tether is disabled because Bluetooth is off, then enabling Bluetooth
// will enable Tether. If enabling Bluetooth takes longer than some timeout
// period, it is assumed that there was an error. In that case, Tether will
// remain uninitialized and Mobile Data will remain toggled off.
void EnableBluetooth();
void OnEnableBluetoothTimeout();
bool waiting_for_tether_initialize_ = false;
base::OneShotTimer enable_bluetooth_timer_;
base::WeakPtrFactory<MobileSectionHeaderView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MobileSectionHeaderView);
};
class WifiSectionHeaderView : public NetworkSectionHeaderView {
public:
WifiSectionHeaderView();
~WifiSectionHeaderView() override = default;
// NetworkSectionHeaderView:
void SetToggleState(bool toggle_enabled, bool is_on) override;
// views::View:
const char* GetClassName() const override;
private:
// NetworkSectionHeaderView:
void OnToggleToggled(bool is_on) override;
void AddExtraButtons(bool enabled) override;
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// A button to invoke "Join Wi-Fi network" dialog.
views::Button* join_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(WifiSectionHeaderView);
};
} // namespace tray
} // namespace ash
#endif // ASH_SYSTEM_NETWORK_NETWORK_SECTION_HEADER__VIEW_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment