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() { ...@@ -29,7 +29,10 @@ const NetworkState* GetConnectedNetwork() {
return handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); 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(); CreateImageView();
UpdateNetworkStateHandlerIcon(); UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(GetConnectedNetwork(), true /* notify_a11y */); UpdateConnectionStatus(GetConnectedNetwork(), true /* notify_a11y */);
...@@ -43,6 +46,11 @@ const char* NetworkTrayView::GetClassName() const { ...@@ -43,6 +46,11 @@ const char* NetworkTrayView::GetClassName() const {
return "NetworkTrayView"; 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( views::View* NetworkTrayView::GetTooltipHandlerForPoint(
const gfx::Point& point) { const gfx::Point& point) {
return GetLocalBounds().Contains(point) ? this : nullptr; return GetLocalBounds().Contains(point) ? this : nullptr;
...@@ -56,6 +64,28 @@ bool NetworkTrayView::GetTooltipText(const gfx::Point& p, ...@@ -56,6 +64,28 @@ bool NetworkTrayView::GetTooltipText(const gfx::Point& p,
return true; 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() { void NetworkTrayView::UpdateNetworkStateHandlerIcon() {
gfx::ImageSkia image; gfx::ImageSkia image;
base::string16 name; base::string16 name;
...@@ -76,21 +106,6 @@ void NetworkTrayView::UpdateNetworkStateHandlerIcon() { ...@@ -76,21 +106,6 @@ void NetworkTrayView::UpdateNetworkStateHandlerIcon() {
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 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( void NetworkTrayView::UpdateConnectionStatus(
const NetworkState* connected_network, const NetworkState* connected_network,
bool notify_a11y) { bool notify_a11y) {
...@@ -146,12 +161,5 @@ void NetworkTrayView::UpdateConnectionStatus( ...@@ -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 tray
} // namespace ash } // namespace ash
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
#ifndef ASH_SYSTEM_NETWORK_NETWORK_TRAY_VIEW_H_ #ifndef ASH_SYSTEM_NETWORK_NETWORK_TRAY_VIEW_H_
#define 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/session/session_observer.h"
#include "ash/system/network/network_icon_animation_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 "ash/system/tray/tray_item_view.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -22,7 +25,8 @@ const chromeos::NetworkState* GetConnectedNetwork(); ...@@ -22,7 +25,8 @@ const chromeos::NetworkState* GetConnectedNetwork();
class NetworkTrayView : public TrayItemView, class NetworkTrayView : public TrayItemView,
public network_icon::AnimationObserver, public network_icon::AnimationObserver,
public SessionObserver { public SessionObserver,
public TrayNetworkStateObserver::Delegate {
public: public:
explicit NetworkTrayView(Shelf* shelf); explicit NetworkTrayView(Shelf* shelf);
...@@ -30,8 +34,6 @@ class NetworkTrayView : public TrayItemView, ...@@ -30,8 +34,6 @@ class NetworkTrayView : public TrayItemView,
const char* GetClassName() const override; const char* GetClassName() const override;
void UpdateNetworkStateHandlerIcon();
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override; views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
...@@ -44,16 +46,23 @@ class NetworkTrayView : public TrayItemView, ...@@ -44,16 +46,23 @@ class NetworkTrayView : public TrayItemView,
// SessionObserver: // SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override; void OnSessionStateChanged(session_manager::SessionState state) override;
// Updates connection status and notifies accessibility event when necessary. // TrayNetworkStateObserver::Delegate:
void UpdateConnectionStatus(const chromeos::NetworkState* connected_network, void NetworkStateChanged(bool notify_a11y) override;
bool notify_a11y);
private: private:
void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image); 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_string_;
base::string16 connection_status_tooltip_; base::string16 connection_status_tooltip_;
std::unique_ptr<TrayNetworkStateObserver> network_state_observer_;
DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
}; };
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "ash/system/model/clock_model.h" #include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/network/network_tray_view.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/power/tray_power.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
...@@ -39,7 +38,7 @@ namespace ash { ...@@ -39,7 +38,7 @@ namespace ash {
class UnifiedSystemTray::UiDelegate : public MessageCenterUiDelegate { class UnifiedSystemTray::UiDelegate : public MessageCenterUiDelegate {
public: public:
UiDelegate(UnifiedSystemTray* owner); explicit UiDelegate(UnifiedSystemTray* owner);
~UiDelegate() override; ~UiDelegate() override;
// MessageCenterUiDelegate: // MessageCenterUiDelegate:
...@@ -113,36 +112,6 @@ void UnifiedSystemTray::UiDelegate::HideMessageCenter() { ...@@ -113,36 +112,6 @@ void UnifiedSystemTray::UiDelegate::HideMessageCenter() {
owner_->HideBubbleInternal(); 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) UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
: TrayBackgroundView(shelf), : TrayBackgroundView(shelf),
ui_delegate_(std::make_unique<UiDelegate>(this)), ui_delegate_(std::make_unique<UiDelegate>(this)),
...@@ -163,8 +132,6 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf) ...@@ -163,8 +132,6 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
// It is possible in unit tests that it's missing. // It is possible in unit tests that it's missing.
if (chromeos::NetworkHandler::IsInitialized()) { if (chromeos::NetworkHandler::IsInitialized()) {
tray::NetworkTrayView* network_item = new tray::NetworkTrayView(shelf); tray::NetworkTrayView* network_item = new tray::NetworkTrayView(shelf);
network_state_delegate_ =
std::make_unique<NetworkStateDelegate>(network_item);
tray_container()->AddChildView(network_item); tray_container()->AddChildView(network_item);
} }
......
...@@ -99,7 +99,7 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView { ...@@ -99,7 +99,7 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
UnifiedSystemTrayModel* model() { return model_.get(); } UnifiedSystemTrayModel* model() { return model_.get(); }
private: private:
const static base::TimeDelta kNotificationCountUpdateDelay; static const base::TimeDelta kNotificationCountUpdateDelay;
friend class UnifiedSystemTrayTest; friend class UnifiedSystemTrayTest;
friend class UnifiedSystemTrayTestApi; friend class UnifiedSystemTrayTestApi;
...@@ -107,9 +107,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView { ...@@ -107,9 +107,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
// Private class implements MessageCenterUiDelegate. // Private class implements MessageCenterUiDelegate.
class UiDelegate; class UiDelegate;
// Private class implements TrayNetworkStateObserver::Delegate.
class NetworkStateDelegate;
// Forwarded from UiDelegate. // Forwarded from UiDelegate.
void ShowBubbleInternal(bool show_by_click); void ShowBubbleInternal(bool show_by_click);
void HideBubbleInternal(); void HideBubbleInternal();
...@@ -118,8 +115,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView { ...@@ -118,8 +115,6 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
const std::unique_ptr<UiDelegate> ui_delegate_; const std::unique_ptr<UiDelegate> ui_delegate_;
std::unique_ptr<NetworkStateDelegate> network_state_delegate_;
std::unique_ptr<UnifiedSystemTrayBubble> bubble_; std::unique_ptr<UnifiedSystemTrayBubble> bubble_;
// Model class that stores UnifiedSystemTray's UI specific variables. // 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