OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/system/network/network_list.h" | 5 #include "ash/system/network/network_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <memory> |
8 | 8 |
| 9 #include "ash/shell.h" |
| 10 #include "ash/shell_port.h" |
9 #include "ash/strings/grit/ash_strings.h" | 11 #include "ash/strings/grit/ash_strings.h" |
10 #include "ash/system/network/network_icon.h" | 12 #include "ash/system/network/network_icon.h" |
11 #include "ash/system/network/network_icon_animation.h" | 13 #include "ash/system/network/network_icon_animation.h" |
12 #include "ash/system/network/network_list_delegate.h" | 14 #include "ash/system/network/network_info.h" |
| 15 #include "ash/system/network/network_state_list_detailed_view.h" |
| 16 #include "ash/system/networking_config_delegate.h" |
| 17 #include "ash/system/tray/fixed_sized_image_view.h" |
| 18 #include "ash/system/tray/hover_highlight_view.h" |
13 #include "ash/system/tray/system_menu_button.h" | 19 #include "ash/system/tray/system_menu_button.h" |
| 20 #include "ash/system/tray/system_tray_controller.h" |
| 21 #include "ash/system/tray/system_tray_delegate.h" |
| 22 #include "ash/system/tray/throbber_view.h" |
14 #include "ash/system/tray/tray_constants.h" | 23 #include "ash/system/tray/tray_constants.h" |
15 #include "ash/system/tray/tray_popup_item_style.h" | 24 #include "ash/system/tray/tray_popup_item_style.h" |
16 #include "ash/system/tray/tray_popup_utils.h" | 25 #include "ash/system/tray/tray_popup_utils.h" |
17 #include "ash/system/tray/tri_view.h" | 26 #include "ash/system/tray/tri_view.h" |
18 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 28 #include "base/strings/string16.h" |
| 29 #include "base/strings/utf_string_conversions.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 31 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
21 #include "chromeos/dbus/power_manager_client.h" | 32 #include "chromeos/dbus/power_manager_client.h" |
22 #include "chromeos/login/login_state.h" | 33 #include "chromeos/login/login_state.h" |
23 #include "chromeos/network/managed_network_configuration_handler.h" | 34 #include "chromeos/network/managed_network_configuration_handler.h" |
24 #include "chromeos/network/network_state.h" | 35 #include "chromeos/network/network_state.h" |
25 #include "chromeos/network/network_state_handler.h" | 36 #include "chromeos/network/network_state_handler.h" |
26 #include "chromeos/network/network_state_handler_observer.h" | 37 #include "chromeos/network/network_state_handler_observer.h" |
27 #include "chromeos/network/proxy/ui_proxy_config_service.h" | 38 #include "chromeos/network/proxy/ui_proxy_config_service.h" |
28 #include "components/device_event_log/device_event_log.h" | 39 #include "components/device_event_log/device_event_log.h" |
| 40 #include "third_party/skia/include/core/SkColor.h" |
29 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/gfx/color_palette.h" | 43 #include "ui/gfx/color_palette.h" |
32 #include "ui/gfx/font.h" | 44 #include "ui/gfx/font.h" |
| 45 #include "ui/gfx/image/image_skia.h" |
33 #include "ui/gfx/paint_vector_icon.h" | 46 #include "ui/gfx/paint_vector_icon.h" |
| 47 #include "ui/gfx/text_constants.h" |
34 #include "ui/views/background.h" | 48 #include "ui/views/background.h" |
| 49 #include "ui/views/border.h" |
35 #include "ui/views/controls/button/toggle_button.h" | 50 #include "ui/views/controls/button/toggle_button.h" |
36 #include "ui/views/controls/image_view.h" | 51 #include "ui/views/controls/image_view.h" |
37 #include "ui/views/controls/label.h" | 52 #include "ui/views/controls/label.h" |
38 #include "ui/views/controls/separator.h" | 53 #include "ui/views/controls/separator.h" |
39 #include "ui/views/layout/box_layout.h" | 54 #include "ui/views/layout/box_layout.h" |
40 #include "ui/views/layout/fill_layout.h" | 55 #include "ui/views/layout/fill_layout.h" |
41 #include "ui/views/painter.h" | 56 #include "ui/views/painter.h" |
42 #include "ui/views/view.h" | 57 #include "ui/views/view.h" |
43 | 58 |
44 using chromeos::LoginState; | 59 using chromeos::LoginState; |
(...skipping 21 matching lines...) Expand all Loading... |
66 global_network_config->GetBooleanWithoutPathExpansion( | 81 global_network_config->GetBooleanWithoutPathExpansion( |
67 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, | 82 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, |
68 &policy_prohibites_unmanaged); | 83 &policy_prohibites_unmanaged); |
69 } | 84 } |
70 if (!policy_prohibites_unmanaged) | 85 if (!policy_prohibites_unmanaged) |
71 return false; | 86 return false; |
72 return !managed_configuration_handler->FindPolicyByGuidAndProfile( | 87 return !managed_configuration_handler->FindPolicyByGuidAndProfile( |
73 network->guid(), network->profile_path()); | 88 network->guid(), network->profile_path()); |
74 } | 89 } |
75 | 90 |
| 91 // TODO(varkha|mohsen): Consolidate with a similar method in |
| 92 // BluetoothDetailedView (see https://crbug.com/686924). |
| 93 void SetupConnectedItem(HoverHighlightView* container, |
| 94 const base::string16& text, |
| 95 const gfx::ImageSkia& image) { |
| 96 container->AddIconAndLabels( |
| 97 image, text, |
| 98 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); |
| 99 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 100 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); |
| 101 style.SetupLabel(container->sub_text_label()); |
| 102 } |
| 103 |
| 104 // TODO(varkha|mohsen): Consolidate with a similar method in |
| 105 // BluetoothDetailedView (see https://crbug.com/686924). |
| 106 void SetupConnectingItem(HoverHighlightView* container, |
| 107 const base::string16& text, |
| 108 const gfx::ImageSkia& image) { |
| 109 container->AddIconAndLabels( |
| 110 image, text, |
| 111 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); |
| 112 ThrobberView* throbber = new ThrobberView; |
| 113 throbber->Start(); |
| 114 container->AddRightView(throbber); |
| 115 } |
| 116 |
76 } // namespace | 117 } // namespace |
77 | 118 |
78 // A header row for sections in network detailed view which contains a title and | 119 // A header row for sections in network detailed view which contains a title and |
79 // a toggle button to turn on/off the section. Subclasses are given the | 120 // a toggle button to turn on/off the section. Subclasses are given the |
80 // opportunity to add extra buttons before the toggle button is added. | 121 // opportunity to add extra buttons before the toggle button is added. |
81 class NetworkListView::SectionHeaderRowView : public views::View, | 122 class NetworkListView::SectionHeaderRowView : public views::View, |
82 public views::ButtonListener { | 123 public views::ButtonListener { |
83 public: | 124 public: |
84 explicit SectionHeaderRowView(int title_id) | 125 explicit SectionHeaderRowView(int title_id) |
85 : title_id_(title_id), | 126 : title_id_(title_id), |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 void OnToggleToggled(bool is_on) override { | 244 void OnToggleToggled(bool is_on) override { |
204 // TODO (hansberry): Persist toggle to settings/preferences. | 245 // TODO (hansberry): Persist toggle to settings/preferences. |
205 } | 246 } |
206 | 247 |
207 private: | 248 private: |
208 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | 249 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); |
209 }; | 250 }; |
210 | 251 |
211 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 252 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
212 public: | 253 public: |
213 explicit WifiHeaderRowView(NetworkListDelegate* network_list_delegate) | 254 WifiHeaderRowView() |
214 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 255 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
215 network_list_delegate_(network_list_delegate), | |
216 join_(nullptr) {} | 256 join_(nullptr) {} |
217 | 257 |
218 ~WifiHeaderRowView() override {} | 258 ~WifiHeaderRowView() override {} |
219 | 259 |
220 void SetIsOn(bool enabled) override { | 260 void SetIsOn(bool enabled) override { |
221 join_->SetEnabled(enabled); | 261 join_->SetEnabled(enabled); |
222 SectionHeaderRowView::SetIsOn(enabled); | 262 SectionHeaderRowView::SetIsOn(enabled); |
223 } | 263 } |
224 | 264 |
225 const char* GetClassName() const override { return "WifiHeaderRowView"; } | 265 const char* GetClassName() const override { return "WifiHeaderRowView"; } |
(...skipping 19 matching lines...) Expand all Loading... |
245 join_ = new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | 285 join_ = new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, |
246 normal_image, disabled_image, | 286 normal_image, disabled_image, |
247 IDS_ASH_STATUS_TRAY_OTHER_WIFI); | 287 IDS_ASH_STATUS_TRAY_OTHER_WIFI); |
248 join_->SetInkDropColor(prominent_color); | 288 join_->SetInkDropColor(prominent_color); |
249 join_->SetEnabled(enabled); | 289 join_->SetEnabled(enabled); |
250 container()->AddView(TriView::Container::END, join_); | 290 container()->AddView(TriView::Container::END, join_); |
251 } | 291 } |
252 | 292 |
253 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 293 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
254 if (sender == join_) { | 294 if (sender == join_) { |
255 network_list_delegate_->OnOtherWifiClicked(); | 295 ShellPort::Get()->RecordUserMetricsAction( |
| 296 UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED); |
| 297 Shell::Get()->system_tray_controller()->ShowNetworkCreate( |
| 298 shill::kTypeWifi); |
256 return; | 299 return; |
257 } | 300 } |
258 SectionHeaderRowView::ButtonPressed(sender, event); | 301 SectionHeaderRowView::ButtonPressed(sender, event); |
259 } | 302 } |
260 | 303 |
261 private: | 304 private: |
262 // Full opacity for badge. | 305 // Full opacity for badge. |
263 static constexpr int kJoinBadgeAlpha = 0xFF; | 306 static constexpr int kJoinBadgeAlpha = 0xFF; |
264 | 307 |
265 // .30 opacity for icon. | 308 // .30 opacity for icon. |
266 static constexpr int kJoinIconAlpha = 0x4D; | 309 static constexpr int kJoinIconAlpha = 0x4D; |
267 | 310 |
268 // .38 opacity for disabled badge. | 311 // .38 opacity for disabled badge. |
269 static constexpr int kDisabledJoinBadgeAlpha = 0x61; | 312 static constexpr int kDisabledJoinBadgeAlpha = 0x61; |
270 | 313 |
271 // .30 * .38 opacity for disabled icon. | 314 // .30 * .38 opacity for disabled icon. |
272 static constexpr int kDisabledJoinIconAlpha = 0x1D; | 315 static constexpr int kDisabledJoinIconAlpha = 0x1D; |
273 | 316 |
274 NetworkListDelegate* network_list_delegate_; | |
275 | |
276 // A button to invoke "Join Wi-Fi network" dialog. | 317 // A button to invoke "Join Wi-Fi network" dialog. |
277 SystemMenuButton* join_; | 318 SystemMenuButton* join_; |
278 | 319 |
279 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView); | 320 DISALLOW_COPY_AND_ASSIGN(WifiHeaderRowView); |
280 }; | 321 }; |
281 | 322 |
282 } // namespace | 323 } // namespace |
283 | 324 |
284 // NetworkListView: | 325 // NetworkListView: |
285 | 326 |
286 NetworkListView::NetworkListView(NetworkListDelegate* delegate) | 327 NetworkListView::NetworkListView( |
287 : needs_relayout_(false), | 328 tray::NetworkStateListDetailedView* detailed_view) |
288 delegate_(delegate), | 329 : NetworkListViewBase(detailed_view), |
| 330 needs_relayout_(false), |
289 no_wifi_networks_view_(nullptr), | 331 no_wifi_networks_view_(nullptr), |
290 no_cellular_networks_view_(nullptr), | 332 no_cellular_networks_view_(nullptr), |
291 cellular_header_view_(nullptr), | 333 cellular_header_view_(nullptr), |
292 tether_header_view_(nullptr), | 334 tether_header_view_(nullptr), |
293 wifi_header_view_(nullptr), | 335 wifi_header_view_(nullptr), |
294 cellular_separator_view_(nullptr), | 336 cellular_separator_view_(nullptr), |
295 tether_separator_view_(nullptr), | 337 tether_separator_view_(nullptr), |
296 wifi_separator_view_(nullptr), | 338 wifi_separator_view_(nullptr), |
297 connection_warning_(nullptr) { | 339 connection_warning_(nullptr) {} |
298 CHECK(delegate_); | |
299 } | |
300 | 340 |
301 NetworkListView::~NetworkListView() { | 341 NetworkListView::~NetworkListView() { |
302 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 342 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
303 } | 343 } |
304 | 344 |
305 void NetworkListView::Update() { | 345 void NetworkListView::Update() { |
306 CHECK(container()); | 346 CHECK(container()); |
307 | 347 |
308 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 348 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
309 | 349 |
(...skipping 28 matching lines...) Expand all Loading... |
338 void NetworkListView::UpdateNetworks( | 378 void NetworkListView::UpdateNetworks( |
339 const NetworkStateHandler::NetworkStateList& networks) { | 379 const NetworkStateHandler::NetworkStateList& networks) { |
340 SCOPED_NET_LOG_IF_SLOW(); | 380 SCOPED_NET_LOG_IF_SLOW(); |
341 // |network_list_| contains all the info and is going to be cleared and | 381 // |network_list_| contains all the info and is going to be cleared and |
342 // recreated. Save them to |last_network_info_map_|. | 382 // recreated. Save them to |last_network_info_map_|. |
343 last_network_info_map_.clear(); | 383 last_network_info_map_.clear(); |
344 for (auto& info : network_list_) | 384 for (auto& info : network_list_) |
345 last_network_info_map_[info->guid] = std::move(info); | 385 last_network_info_map_[info->guid] = std::move(info); |
346 | 386 |
347 network_list_.clear(); | 387 network_list_.clear(); |
348 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | |
349 for (const auto* network : networks) { | 388 for (const auto* network : networks) { |
350 if (!pattern.MatchesType(network->type())) | 389 if (!NetworkTypePattern::NonVirtual().MatchesType(network->type())) |
351 continue; | 390 continue; |
352 | 391 |
353 // Do not add Wi-Fi networks that are associated with a Tether network. | 392 // Do not add Wi-Fi networks that are associated with a Tether network. |
354 if (NetworkTypePattern::WiFi().MatchesType(network->type()) && | 393 if (NetworkTypePattern::WiFi().MatchesType(network->type()) && |
355 !network->tether_guid().empty()) | 394 !network->tether_guid().empty()) |
356 continue; | 395 continue; |
357 | 396 |
358 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); | 397 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); |
359 } | 398 } |
360 } | 399 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 return; | 506 return; |
468 | 507 |
469 views::View* selected_view = nullptr; | 508 views::View* selected_view = nullptr; |
470 for (const auto& iter : network_guid_map_) { | 509 for (const auto& iter : network_guid_map_) { |
471 if (iter.second->IsMouseHovered()) { | 510 if (iter.second->IsMouseHovered()) { |
472 selected_view = iter.second; | 511 selected_view = iter.second; |
473 break; | 512 break; |
474 } | 513 } |
475 } | 514 } |
476 container()->SizeToPreferredSize(); | 515 container()->SizeToPreferredSize(); |
477 delegate_->RelayoutScrollList(); | 516 detailed_view()->RelayoutScrollList(); |
478 if (selected_view) | 517 if (selected_view) |
479 container()->ScrollRectToVisible(selected_view->bounds()); | 518 container()->ScrollRectToVisible(selected_view->bounds()); |
480 } | 519 } |
481 | 520 |
482 std::unique_ptr<std::set<std::string>> | 521 std::unique_ptr<std::set<std::string>> |
483 NetworkListView::UpdateNetworkListEntries() { | 522 NetworkListView::UpdateNetworkListEntries() { |
484 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 523 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
485 | 524 |
486 // Keep an index where the next child should be inserted. | 525 // Keep an index where the next child should be inserted. |
487 int index = 0; | 526 int index = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
498 if (!connection_warning_) | 537 if (!connection_warning_) |
499 connection_warning_ = CreateConnectionWarning(); | 538 connection_warning_ = CreateConnectionWarning(); |
500 PlaceViewAtIndex(connection_warning_, index++); | 539 PlaceViewAtIndex(connection_warning_, index++); |
501 } | 540 } |
502 | 541 |
503 // First add high-priority networks (not Wi-Fi nor cellular). | 542 // First add high-priority networks (not Wi-Fi nor cellular). |
504 std::unique_ptr<std::set<std::string>> new_guids = | 543 std::unique_ptr<std::set<std::string>> new_guids = |
505 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 544 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
506 index += new_guids->size(); | 545 index += new_guids->size(); |
507 | 546 |
508 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | 547 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
509 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { | 548 index = UpdateSectionHeaderRow( |
510 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 549 NetworkTypePattern::Cellular(), |
511 index = UpdateSectionHeaderRow( | 550 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, |
512 NetworkTypePattern::Cellular(), | 551 &cellular_header_view_, &cellular_separator_view_); |
513 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 552 } |
514 &cellular_header_view_, &cellular_separator_view_); | |
515 } | |
516 | 553 |
517 // Cellular initializing. | 554 // Cellular initializing. |
518 int message_id = network_icon::GetCellularUninitializedMsg(); | 555 int cellular_message_id = network_icon::GetCellularUninitializedMsg(); |
519 if (!message_id && | 556 if (!cellular_message_id && |
520 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 557 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
521 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 558 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
522 message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 559 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
523 } | 560 } |
524 UpdateInfoLabel(message_id, index, &no_cellular_networks_view_); | 561 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); |
525 if (message_id) | 562 if (cellular_message_id) |
526 ++index; | 563 ++index; |
527 | 564 |
528 // Add cellular networks. | 565 // Add cellular networks. |
529 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 566 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
530 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 567 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); |
531 index += new_cellular_guids->size(); | 568 index += new_cellular_guids->size(); |
532 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 569 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
533 } | |
534 | 570 |
535 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | 571 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing |
536 // it to include Tether. See crbug.com/693647. | 572 // it to include Tether. See crbug.com/693647. |
537 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | 573 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
538 index = UpdateSectionHeaderRow( | 574 index = UpdateSectionHeaderRow( |
539 NetworkTypePattern::Tether(), | 575 NetworkTypePattern::Tether(), |
540 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | 576 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, |
541 &tether_header_view_, &tether_separator_view_); | 577 &tether_header_view_, &tether_separator_view_); |
542 | 578 |
543 // TODO (hansberry): Should a message similar to | 579 // TODO (hansberry): Should a message similar to |
544 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology | 580 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is |
545 // is enabled but no networks are around? | 581 // enabled but no networks are around? |
546 | 582 |
547 // Add Tether networks. | 583 // Add Tether networks. |
548 std::unique_ptr<std::set<std::string>> new_tether_guids = | 584 std::unique_ptr<std::set<std::string>> new_tether_guids = |
549 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | 585 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); |
550 index += new_tether_guids->size(); | 586 index += new_tether_guids->size(); |
551 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); | 587 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); |
552 } | 588 } |
553 | 589 |
554 if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { | 590 index = UpdateSectionHeaderRow( |
555 index = UpdateSectionHeaderRow( | 591 NetworkTypePattern::WiFi(), |
556 NetworkTypePattern::WiFi(), | 592 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
557 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 593 &wifi_header_view_, &wifi_separator_view_); |
558 &wifi_header_view_, &wifi_separator_view_); | |
559 | 594 |
560 // "Wifi Enabled / Disabled". | 595 // "Wifi Enabled / Disabled". |
561 int message_id = 0; | 596 int wifi_message_id = 0; |
562 if (network_list_.empty()) { | 597 if (network_list_.empty()) { |
563 message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 598 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
564 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 599 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
565 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | 600 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
566 } | 601 } |
567 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); | 602 UpdateInfoLabel(wifi_message_id, index, &no_wifi_networks_view_); |
568 if (message_id) | 603 if (wifi_message_id) |
569 ++index; | 604 ++index; |
570 | 605 |
571 // Add Wi-Fi networks. | 606 // Add Wi-Fi networks. |
572 std::unique_ptr<std::set<std::string>> new_wifi_guids = | 607 std::unique_ptr<std::set<std::string>> new_wifi_guids = |
573 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); | 608 UpdateNetworkChildren(NetworkInfo::Type::WIFI, index); |
574 index += new_wifi_guids->size(); | 609 index += new_wifi_guids->size(); |
575 new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end()); | 610 new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end()); |
576 } | |
577 | 611 |
578 // No networks or other messages (fallback). | 612 // No networks or other messages (fallback). |
579 if (index == 0) { | 613 if (index == 0) { |
580 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, | 614 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, |
581 &no_wifi_networks_view_); | 615 &no_wifi_networks_view_); |
582 } | 616 } |
583 | 617 |
584 return new_guids; | 618 return new_guids; |
585 } | 619 } |
586 | 620 |
| 621 HoverHighlightView* NetworkListView::CreateViewForNetwork( |
| 622 const NetworkInfo& info) { |
| 623 HoverHighlightView* container = new HoverHighlightView(detailed_view()); |
| 624 if (info.connected) |
| 625 SetupConnectedItem(container, info.label, info.image); |
| 626 else if (info.connecting) |
| 627 SetupConnectingItem(container, info.label, info.image); |
| 628 else |
| 629 container->AddIconAndLabel(info.image, info.label); |
| 630 container->SetTooltipText(info.tooltip); |
| 631 views::View* controlled_icon = CreateControlledByExtensionView(info); |
| 632 if (controlled_icon) |
| 633 container->AddChildView(controlled_icon); |
| 634 return container; |
| 635 } |
| 636 |
| 637 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, |
| 638 const NetworkInfo& info) { |
| 639 DCHECK(!view->has_children()); |
| 640 if (info.connected) |
| 641 SetupConnectedItem(view, info.label, info.image); |
| 642 else if (info.connecting) |
| 643 SetupConnectingItem(view, info.label, info.image); |
| 644 else |
| 645 view->AddIconAndLabel(info.image, info.label); |
| 646 views::View* controlled_icon = CreateControlledByExtensionView(info); |
| 647 view->SetTooltipText(info.tooltip); |
| 648 if (controlled_icon) |
| 649 view->AddChildView(controlled_icon); |
| 650 } |
| 651 |
| 652 views::View* NetworkListView::CreateControlledByExtensionView( |
| 653 const NetworkInfo& info) { |
| 654 NetworkingConfigDelegate* networking_config_delegate = |
| 655 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); |
| 656 if (!networking_config_delegate) |
| 657 return nullptr; |
| 658 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> |
| 659 extension_info = |
| 660 networking_config_delegate->LookUpExtensionForNetwork(info.guid); |
| 661 if (!extension_info) |
| 662 return nullptr; |
| 663 |
| 664 // Get the tooltip text. |
| 665 base::string16 tooltip_text = l10n_util::GetStringFUTF16( |
| 666 IDS_ASH_STATUS_TRAY_EXTENSION_CONTROLLED_WIFI, |
| 667 base::UTF8ToUTF16(extension_info->extension_name)); |
| 668 |
| 669 views::ImageView* controlled_icon = |
| 670 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); |
| 671 |
| 672 controlled_icon->SetImage( |
| 673 gfx::CreateVectorIcon(kCaptivePortalIcon, kMenuIconColor)); |
| 674 controlled_icon->SetTooltipText(tooltip_text); |
| 675 return controlled_icon; |
| 676 } |
| 677 |
587 std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( | 678 std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( |
588 NetworkInfo::Type type, | 679 NetworkInfo::Type type, |
589 int index) { | 680 int index) { |
590 std::unique_ptr<std::set<std::string>> new_guids(new std::set<std::string>); | 681 std::unique_ptr<std::set<std::string>> new_guids(new std::set<std::string>); |
591 for (const auto& info : network_list_) { | 682 for (const auto& info : network_list_) { |
592 if (info->type != type) | 683 if (info->type != type) |
593 continue; | 684 continue; |
594 UpdateNetworkChild(index++, info.get()); | 685 UpdateNetworkChild(index++, info.get()); |
595 new_guids->insert(info->guid); | 686 new_guids->insert(info->guid); |
596 } | 687 } |
597 return new_guids; | 688 return new_guids; |
598 } | 689 } |
599 | 690 |
600 void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { | 691 void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { |
601 views::View* network_view = nullptr; | 692 HoverHighlightView* network_view = nullptr; |
602 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); | 693 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); |
603 if (found == network_guid_map_.end()) { | 694 if (found == network_guid_map_.end()) { |
604 network_view = delegate_->CreateViewForNetwork(*info); | 695 network_view = CreateViewForNetwork(*info); |
605 } else { | 696 } else { |
606 network_view = found->second; | 697 network_view = found->second; |
607 if (NeedUpdateViewForNetwork(*info)) { | 698 if (NeedUpdateViewForNetwork(*info)) { |
608 network_view->RemoveAllChildViews(true); | 699 network_view->RemoveAllChildViews(true); |
609 delegate_->UpdateViewForNetwork(network_view, *info); | 700 UpdateViewForNetwork(network_view, *info); |
610 network_view->Layout(); | 701 network_view->Layout(); |
611 network_view->SchedulePaint(); | 702 network_view->SchedulePaint(); |
612 } | 703 } |
613 } | 704 } |
614 PlaceViewAtIndex(network_view, index); | 705 PlaceViewAtIndex(network_view, index); |
615 if (info->disable) | 706 if (info->disable) |
616 network_view->SetEnabled(false); | 707 network_view->SetEnabled(false); |
617 network_map_[network_view] = info->guid; | 708 network_map_[network_view] = info->guid; |
618 network_guid_map_[info->guid] = network_view; | 709 network_guid_map_[info->guid] = network_view; |
619 } | 710 } |
(...skipping 16 matching lines...) Expand all Loading... |
636 if (!message_id) { | 727 if (!message_id) { |
637 if (label) { | 728 if (label) { |
638 needs_relayout_ = true; | 729 needs_relayout_ = true; |
639 delete label; | 730 delete label; |
640 *label_ptr = nullptr; | 731 *label_ptr = nullptr; |
641 } | 732 } |
642 return; | 733 return; |
643 } | 734 } |
644 base::string16 text = | 735 base::string16 text = |
645 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); | 736 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); |
646 if (!label) | 737 if (!label) { |
647 label = delegate_->CreateInfoLabel(); | 738 // TODO(mohsen): Update info label to follow MD specs. See |
| 739 // https://crbug.com/687778. |
| 740 label = new views::Label(); |
| 741 label->SetBorder(views::CreateEmptyBorder( |
| 742 kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal, |
| 743 kTrayPopupPaddingBetweenItems, 0)); |
| 744 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 745 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); |
| 746 } |
648 label->SetText(text); | 747 label->SetText(text); |
649 PlaceViewAtIndex(label, insertion_index); | 748 PlaceViewAtIndex(label, insertion_index); |
650 *label_ptr = label; | 749 *label_ptr = label; |
651 } | 750 } |
652 | 751 |
653 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 752 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
654 bool enabled, | 753 bool enabled, |
655 int child_index, | 754 int child_index, |
656 SectionHeaderRowView** view, | 755 SectionHeaderRowView** view, |
657 views::Separator** separator_view) { | 756 views::Separator** separator_view) { |
658 if (!*view) { | 757 if (!*view) { |
659 if (pattern.Equals(NetworkTypePattern::Cellular())) | 758 if (pattern.Equals(NetworkTypePattern::Cellular())) |
660 *view = new CellularHeaderRowView(); | 759 *view = new CellularHeaderRowView(); |
661 else if (pattern.Equals(NetworkTypePattern::Tether())) | 760 else if (pattern.Equals(NetworkTypePattern::Tether())) |
662 *view = new TetherHeaderRowView(); | 761 *view = new TetherHeaderRowView(); |
663 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 762 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
664 *view = new WifiHeaderRowView(delegate_); | 763 *view = new WifiHeaderRowView(); |
665 else | 764 else |
666 NOTREACHED(); | 765 NOTREACHED(); |
667 (*view)->Init(enabled); | 766 (*view)->Init(enabled); |
668 } | 767 } |
669 // Show or hide a separator above the header. The separator should only be | 768 // Show or hide a separator above the header. The separator should only be |
670 // visible when the header row is not at the top of the list. | 769 // visible when the header row is not at the top of the list. |
671 if (child_index > 0) { | 770 if (child_index > 0) { |
672 if (!*separator_view) | 771 if (!*separator_view) |
673 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); | 772 *separator_view = TrayPopupUtils::CreateListSubHeaderSeparator(); |
674 PlaceViewAtIndex(*separator_view, child_index++); | 773 PlaceViewAtIndex(*separator_view, child_index++); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | 821 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
723 style.SetupLabel(label); | 822 style.SetupLabel(label); |
724 connection_warning->AddView(TriView::Container::CENTER, label); | 823 connection_warning->AddView(TriView::Container::CENTER, label); |
725 | 824 |
726 // Nothing to the right of the text. | 825 // Nothing to the right of the text. |
727 connection_warning->SetContainerVisible(TriView::Container::END, false); | 826 connection_warning->SetContainerVisible(TriView::Container::END, false); |
728 return connection_warning; | 827 return connection_warning; |
729 } | 828 } |
730 | 829 |
731 } // namespace ash | 830 } // namespace ash |
OLD | NEW |