Commit 29a38a99 authored by Tony de Luna's avatar Tony de Luna Committed by Commit Bot

Move TrayNetworkStateObserver to NetworkTrayView

Make NetworkTrayView own its network state observer. We want to have
multiple instances of NetworkTrayView in the future, one for each
network icon type.

Now each instance is responsible of subscribing to network state
updates.

BUG=902409

Change-Id: I5dabfbff662dea6c975a4d64e63691194c7e5476
Reviewed-on: https://chromium-review.googlesource.com/c/1332210Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Tony De Luna <tonydeluna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608028}
parent 7f3afb9f
......@@ -29,7 +29,10 @@ const NetworkState* GetConnectedNetwork() {
return handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
}
NetworkTrayView::NetworkTrayView(Shelf* shelf) : TrayItemView(shelf) {
NetworkTrayView::NetworkTrayView(Shelf* shelf)
: TrayItemView(shelf),
network_state_observer_(
std::make_unique<TrayNetworkStateObserver>(this)) {
CreateImageView();
UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(GetConnectedNetwork(), true /* notify_a11y */);
......@@ -43,6 +46,11 @@ const char* NetworkTrayView::GetClassName() const {
return "NetworkTrayView";
}
void NetworkTrayView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetName(connection_status_string_);
node_data->role = ax::mojom::Role::kButton;
}
views::View* NetworkTrayView::GetTooltipHandlerForPoint(
const gfx::Point& point) {
return GetLocalBounds().Contains(point) ? this : nullptr;
......@@ -56,6 +64,28 @@ bool NetworkTrayView::GetTooltipText(const gfx::Point& p,
return true;
}
void NetworkTrayView::NetworkIconChanged() {
UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(GetConnectedNetwork(), false /* notify_a11y */);
}
void NetworkTrayView::OnSessionStateChanged(
session_manager::SessionState state) {
UpdateNetworkStateHandlerIcon();
}
void NetworkTrayView::NetworkStateChanged(bool notify_a11y) {
UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(GetConnectedNetwork(), notify_a11y);
}
void NetworkTrayView::UpdateIcon(bool tray_icon_visible,
const gfx::ImageSkia& image) {
image_view()->SetImage(image);
SetVisible(tray_icon_visible);
SchedulePaint();
}
void NetworkTrayView::UpdateNetworkStateHandlerIcon() {
gfx::ImageSkia image;
base::string16 name;
......@@ -76,21 +106,6 @@ void NetworkTrayView::UpdateNetworkStateHandlerIcon() {
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
}
void NetworkTrayView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetName(connection_status_string_);
node_data->role = ax::mojom::Role::kButton;
}
void NetworkTrayView::NetworkIconChanged() {
UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(GetConnectedNetwork(), false /* notify_a11y */);
}
void NetworkTrayView::OnSessionStateChanged(
session_manager::SessionState state) {
UpdateNetworkStateHandlerIcon();
}
void NetworkTrayView::UpdateConnectionStatus(
const NetworkState* connected_network,
bool notify_a11y) {
......@@ -146,12 +161,5 @@ void NetworkTrayView::UpdateConnectionStatus(
}
}
void NetworkTrayView::UpdateIcon(bool tray_icon_visible,
const gfx::ImageSkia& image) {
image_view()->SetImage(image);
SetVisible(tray_icon_visible);
SchedulePaint();
}
} // namespace tray
} // namespace ash
......@@ -5,8 +5,11 @@
#ifndef ASH_SYSTEM_NETWORK_NETWORK_TRAY_VIEW_H_
#define ASH_SYSTEM_NETWORK_NETWORK_TRAY_VIEW_H_
#include <memory>
#include "ash/session/session_observer.h"
#include "ash/system/network/network_icon_animation_observer.h"
#include "ash/system/network/tray_network_state_observer.h"
#include "ash/system/tray/tray_item_view.h"
#include "base/macros.h"
......@@ -22,7 +25,8 @@ const chromeos::NetworkState* GetConnectedNetwork();
class NetworkTrayView : public TrayItemView,
public network_icon::AnimationObserver,
public SessionObserver {
public SessionObserver,
public TrayNetworkStateObserver::Delegate {
public:
explicit NetworkTrayView(Shelf* shelf);
......@@ -30,8 +34,6 @@ class NetworkTrayView : public TrayItemView,
const char* GetClassName() const override;
void UpdateNetworkStateHandlerIcon();
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
......@@ -44,16 +46,23 @@ class NetworkTrayView : public TrayItemView,
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
// Updates connection status and notifies accessibility event when necessary.
void UpdateConnectionStatus(const chromeos::NetworkState* connected_network,
bool notify_a11y);
// TrayNetworkStateObserver::Delegate:
void NetworkStateChanged(bool notify_a11y) override;
private:
void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image);
void UpdateNetworkStateHandlerIcon();
// Updates connection status and notifies accessibility event when necessary.
void UpdateConnectionStatus(const chromeos::NetworkState* connected_network,
bool notify_a11y);
base::string16 connection_status_string_;
base::string16 connection_status_tooltip_;
std::unique_ptr<TrayNetworkStateObserver> network_state_observer_;
DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
};
......
......@@ -15,7 +15,6 @@
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/network/network_tray_view.h"
#include "ash/system/network/tray_network_state_observer.h"
#include "ash/system/power/tray_power.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h"
......@@ -39,7 +38,7 @@ namespace ash {
class UnifiedSystemTray::UiDelegate : public MessageCenterUiDelegate {
public:
UiDelegate(UnifiedSystemTray* owner);
explicit UiDelegate(UnifiedSystemTray* owner);
~UiDelegate() override;
// MessageCenterUiDelegate:
......@@ -113,36 +112,6 @@ void UnifiedSystemTray::UiDelegate::HideMessageCenter() {
owner_->HideBubbleInternal();
}
class UnifiedSystemTray::NetworkStateDelegate
: public TrayNetworkStateObserver::Delegate {
public:
explicit NetworkStateDelegate(tray::NetworkTrayView* tray_view);
~NetworkStateDelegate() override;
// TrayNetworkStateObserver::Delegate
void NetworkStateChanged(bool notify_a11y) override;
private:
tray::NetworkTrayView* const tray_view_;
const std::unique_ptr<TrayNetworkStateObserver> network_state_observer_;
DISALLOW_COPY_AND_ASSIGN(NetworkStateDelegate);
};
UnifiedSystemTray::NetworkStateDelegate::NetworkStateDelegate(
tray::NetworkTrayView* tray_view)
: tray_view_(tray_view),
network_state_observer_(
std::make_unique<TrayNetworkStateObserver>(this)) {}
UnifiedSystemTray::NetworkStateDelegate::~NetworkStateDelegate() = default;
void UnifiedSystemTray::NetworkStateDelegate::NetworkStateChanged(
bool notify_a11y) {
tray_view_->UpdateNetworkStateHandlerIcon();
tray_view_->UpdateConnectionStatus(tray::GetConnectedNetwork(), notify_a11y);
}
UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
: TrayBackgroundView(shelf),
ui_delegate_(std::make_unique<UiDelegate>(this)),
......@@ -163,8 +132,6 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
// It is possible in unit tests that it's missing.
if (chromeos::NetworkHandler::IsInitialized()) {
tray::NetworkTrayView* network_item = new tray::NetworkTrayView(shelf);
network_state_delegate_ =
std::make_unique<NetworkStateDelegate>(network_item);
tray_container()->AddChildView(network_item);
}
......
......@@ -99,7 +99,7 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
UnifiedSystemTrayModel* model() { return model_.get(); }
private:
const static base::TimeDelta kNotificationCountUpdateDelay;
static const base::TimeDelta kNotificationCountUpdateDelay;
friend class UnifiedSystemTrayTest;
friend class UnifiedSystemTrayTestApi;
......@@ -107,9 +107,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
// Private class implements MessageCenterUiDelegate.
class UiDelegate;
// Private class implements TrayNetworkStateObserver::Delegate.
class NetworkStateDelegate;
// Forwarded from UiDelegate.
void ShowBubbleInternal(bool show_by_click);
void HideBubbleInternal();
......@@ -118,8 +115,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
const std::unique_ptr<UiDelegate> ui_delegate_;
std::unique_ptr<NetworkStateDelegate> network_state_delegate_;
std::unique_ptr<UnifiedSystemTrayBubble> bubble_;
// Model class that stores UnifiedSystemTray's UI specific variables.
......
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