| 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 "ash/common/system/chromeos/network/tray_network.h" | 5 #include "ash/common/system/chromeos/network/tray_network.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/wm_shelf_util.h" | 7 #include "ash/common/shelf/wm_shelf_util.h" |
| 8 #include "ash/common/system/chromeos/network/network_icon.h" | 8 #include "ash/common/system/chromeos/network/network_icon.h" |
| 9 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 9 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 using chromeos::NetworkTypePattern; | 41 using chromeos::NetworkTypePattern; |
| 42 | 42 |
| 43 namespace ash { | 43 namespace ash { |
| 44 namespace tray { | 44 namespace tray { |
| 45 | 45 |
| 46 class NetworkTrayView : public TrayItemView, | 46 class NetworkTrayView : public TrayItemView, |
| 47 public network_icon::AnimationObserver { | 47 public network_icon::AnimationObserver { |
| 48 public: | 48 public: |
| 49 explicit NetworkTrayView(TrayNetwork* network_tray) | 49 explicit NetworkTrayView(TrayNetwork* network_tray) |
| 50 : TrayItemView(network_tray) { | 50 : TrayItemView(network_tray) { |
| 51 SetLayoutManager( | 51 CreateImageView(); |
| 52 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 53 | |
| 54 image_view_ = new views::ImageView; | |
| 55 AddChildView(image_view_); | |
| 56 | |
| 57 UpdateNetworkStateHandlerIcon(); | 52 UpdateNetworkStateHandlerIcon(); |
| 58 } | 53 } |
| 59 | 54 |
| 60 ~NetworkTrayView() override { | 55 ~NetworkTrayView() override { |
| 61 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 56 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 62 } | 57 } |
| 63 | 58 |
| 64 const char* GetClassName() const override { return "NetworkTrayView"; } | 59 const char* GetClassName() const override { return "NetworkTrayView"; } |
| 65 | 60 |
| 66 void UpdateNetworkStateHandlerIcon() { | 61 void UpdateNetworkStateHandlerIcon() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 const NetworkState* connected_network = | 76 const NetworkState* connected_network = |
| 82 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); | 77 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
| 83 if (connected_network) { | 78 if (connected_network) { |
| 84 UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()), | 79 UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()), |
| 85 true); | 80 true); |
| 86 } else { | 81 } else { |
| 87 UpdateConnectionStatus(base::string16(), false); | 82 UpdateConnectionStatus(base::string16(), false); |
| 88 } | 83 } |
| 89 } | 84 } |
| 90 | 85 |
| 91 void UpdateAlignment(ShelfAlignment alignment) { | |
| 92 SetLayoutManager(new views::BoxLayout(IsHorizontalAlignment(alignment) | |
| 93 ? views::BoxLayout::kHorizontal | |
| 94 : views::BoxLayout::kVertical, | |
| 95 0, 0, 0)); | |
| 96 Layout(); | |
| 97 } | |
| 98 | |
| 99 // views::View: | 86 // views::View: |
| 100 void GetAccessibleState(ui::AXViewState* state) override { | 87 void GetAccessibleState(ui::AXViewState* state) override { |
| 101 state->name = connection_status_string_; | 88 state->name = connection_status_string_; |
| 102 state->role = ui::AX_ROLE_BUTTON; | 89 state->role = ui::AX_ROLE_BUTTON; |
| 103 } | 90 } |
| 104 | 91 |
| 105 // network_icon::AnimationObserver: | 92 // network_icon::AnimationObserver: |
| 106 void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); } | 93 void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); } |
| 107 | 94 |
| 108 private: | 95 private: |
| 109 // Updates connection status and notifies accessibility event when necessary. | 96 // Updates connection status and notifies accessibility event when necessary. |
| 110 void UpdateConnectionStatus(const base::string16& network_name, | 97 void UpdateConnectionStatus(const base::string16& network_name, |
| 111 bool connected) { | 98 bool connected) { |
| 112 base::string16 new_connection_status_string; | 99 base::string16 new_connection_status_string; |
| 113 if (connected) { | 100 if (connected) { |
| 114 new_connection_status_string = l10n_util::GetStringFUTF16( | 101 new_connection_status_string = l10n_util::GetStringFUTF16( |
| 115 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); | 102 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); |
| 116 } | 103 } |
| 117 if (new_connection_status_string != connection_status_string_) { | 104 if (new_connection_status_string != connection_status_string_) { |
| 118 connection_status_string_ = new_connection_status_string; | 105 connection_status_string_ = new_connection_status_string; |
| 119 if (!connection_status_string_.empty()) | 106 if (!connection_status_string_.empty()) |
| 120 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 107 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 121 } | 108 } |
| 122 } | 109 } |
| 123 | 110 |
| 124 void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) { | 111 void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) { |
| 125 image_view_->SetImage(image); | 112 image_view()->SetImage(image); |
| 126 SetVisible(tray_icon_visible); | 113 SetVisible(tray_icon_visible); |
| 127 SchedulePaint(); | 114 SchedulePaint(); |
| 128 } | 115 } |
| 129 | 116 |
| 130 views::ImageView* image_view_; | |
| 131 base::string16 connection_status_string_; | 117 base::string16 connection_status_string_; |
| 132 | 118 |
| 133 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 119 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
| 134 }; | 120 }; |
| 135 | 121 |
| 136 class NetworkDefaultView : public TrayItemMore, | 122 class NetworkDefaultView : public TrayItemMore, |
| 137 public network_icon::AnimationObserver { | 123 public network_icon::AnimationObserver { |
| 138 public: | 124 public: |
| 139 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) | 125 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) |
| 140 : TrayItemMore(network_tray, show_more) { | 126 : TrayItemMore(network_tray, show_more) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 default_ = NULL; | 287 default_ = NULL; |
| 302 } | 288 } |
| 303 | 289 |
| 304 void TrayNetwork::DestroyDetailedView() { | 290 void TrayNetwork::DestroyDetailedView() { |
| 305 detailed_ = NULL; | 291 detailed_ = NULL; |
| 306 } | 292 } |
| 307 | 293 |
| 308 void TrayNetwork::UpdateAfterLoginStatusChange(LoginStatus status) {} | 294 void TrayNetwork::UpdateAfterLoginStatusChange(LoginStatus status) {} |
| 309 | 295 |
| 310 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 296 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 311 if (tray_) { | 297 if (tray_) |
| 312 SetTrayImageItemBorder(tray_, alignment); | 298 SetTrayImageItemBorder(tray_, alignment); |
| 313 tray_->UpdateAlignment(alignment); | |
| 314 } | |
| 315 } | 299 } |
| 316 | 300 |
| 317 void TrayNetwork::RequestToggleWifi() { | 301 void TrayNetwork::RequestToggleWifi() { |
| 318 // This will always be triggered by a user action (e.g. keyboard shortcut) | 302 // This will always be triggered by a user action (e.g. keyboard shortcut) |
| 319 if (!detailed_ || | 303 if (!detailed_ || |
| 320 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { | 304 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
| 321 request_wifi_view_ = true; | 305 request_wifi_view_ = true; |
| 322 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 306 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| 323 } | 307 } |
| 324 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 308 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 337 void TrayNetwork::NetworkStateChanged() { | 321 void TrayNetwork::NetworkStateChanged() { |
| 338 if (tray_) | 322 if (tray_) |
| 339 tray_->UpdateNetworkStateHandlerIcon(); | 323 tray_->UpdateNetworkStateHandlerIcon(); |
| 340 if (default_) | 324 if (default_) |
| 341 default_->Update(); | 325 default_->Update(); |
| 342 if (detailed_) | 326 if (detailed_) |
| 343 detailed_->Update(); | 327 detailed_->Update(); |
| 344 } | 328 } |
| 345 | 329 |
| 346 } // namespace ash | 330 } // namespace ash |
| OLD | NEW |