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/system/network/network_state_list_detailed_view.h" | 5 #include "ash/system/network/network_state_list_detailed_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
11 #include "ash/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
12 #include "ash/resources/vector_icons/vector_icons.h" | 12 #include "ash/resources/vector_icons/vector_icons.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/session/session_controller.h" | 14 #include "ash/session/session_controller.h" |
15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
16 #include "ash/shell_port.h" | 16 #include "ash/shell_port.h" |
17 #include "ash/strings/grit/ash_strings.h" | 17 #include "ash/strings/grit/ash_strings.h" |
18 #include "ash/system/network/network_icon.h" | 18 #include "ash/system/network/network_icon.h" |
19 #include "ash/system/network/network_icon_animation.h" | 19 #include "ash/system/network/network_icon_animation.h" |
20 #include "ash/system/network/network_info.h" | |
21 #include "ash/system/network/network_list.h" | 20 #include "ash/system/network/network_list.h" |
22 #include "ash/system/network/network_list_view_base.h" | 21 #include "ash/system/network/network_list_view_base.h" |
23 #include "ash/system/network/tray_network_state_observer.h" | 22 #include "ash/system/network/tray_network_state_observer.h" |
24 #include "ash/system/network/vpn_list_view.h" | 23 #include "ash/system/network/vpn_list_view.h" |
25 #include "ash/system/networking_config_delegate.h" | |
26 #include "ash/system/tray/fixed_sized_image_view.h" | |
27 #include "ash/system/tray/hover_highlight_view.h" | |
28 #include "ash/system/tray/system_menu_button.h" | 24 #include "ash/system/tray/system_menu_button.h" |
29 #include "ash/system/tray/system_tray.h" | 25 #include "ash/system/tray/system_tray.h" |
30 #include "ash/system/tray/system_tray_controller.h" | 26 #include "ash/system/tray/system_tray_controller.h" |
31 #include "ash/system/tray/system_tray_delegate.h" | |
32 #include "ash/system/tray/throbber_view.h" | |
33 #include "ash/system/tray/tray_constants.h" | 27 #include "ash/system/tray/tray_constants.h" |
34 #include "ash/system/tray/tray_details_view.h" | 28 #include "ash/system/tray/tray_details_view.h" |
35 #include "ash/system/tray/tray_popup_header_button.h" | 29 #include "ash/system/tray/tray_popup_header_button.h" |
36 #include "ash/system/tray/tri_view.h" | 30 #include "ash/system/tray/tri_view.h" |
37 #include "ash/wm_window.h" | 31 #include "ash/wm_window.h" |
38 #include "base/command_line.h" | 32 #include "base/command_line.h" |
39 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
40 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
41 #include "base/threading/thread_task_runner_handle.h" | 35 #include "base/threading/thread_task_runner_handle.h" |
42 #include "base/time/time.h" | 36 #include "base/time/time.h" |
(...skipping 29 matching lines...) Expand all Loading... |
72 using chromeos::NetworkStateHandler; | 66 using chromeos::NetworkStateHandler; |
73 using chromeos::NetworkTypePattern; | 67 using chromeos::NetworkTypePattern; |
74 | 68 |
75 namespace ash { | 69 namespace ash { |
76 namespace tray { | 70 namespace tray { |
77 namespace { | 71 namespace { |
78 | 72 |
79 // Delay between scan requests. | 73 // Delay between scan requests. |
80 const int kRequestScanDelaySeconds = 10; | 74 const int kRequestScanDelaySeconds = 10; |
81 | 75 |
82 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | |
83 void SetupConnectedItem(HoverHighlightView* container, | |
84 const base::string16& text, | |
85 const gfx::ImageSkia& image) { | |
86 container->AddIconAndLabels( | |
87 image, text, | |
88 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | |
89 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION); | |
90 style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED); | |
91 style.SetupLabel(container->sub_text_label()); | |
92 } | |
93 | |
94 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | |
95 void SetupConnectingItem(HoverHighlightView* container, | |
96 const base::string16& text, | |
97 const gfx::ImageSkia& image) { | |
98 container->AddIconAndLabels( | |
99 image, text, | |
100 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING)); | |
101 ThrobberView* throbber = new ThrobberView; | |
102 throbber->Start(); | |
103 container->AddRightView(throbber); | |
104 } | |
105 | |
106 } // namespace | 76 } // namespace |
107 | 77 |
108 //------------------------------------------------------------------------------ | 78 //------------------------------------------------------------------------------ |
109 | 79 |
110 // This margin value is used throughout the bubble: | 80 // This margin value is used throughout the bubble: |
111 // - margins inside the border | 81 // - margins inside the border |
112 // - horizontal spacing between bubble border and parent bubble border | 82 // - horizontal spacing between bubble border and parent bubble border |
113 // - distance between top of this bubble's border and the bottom of the anchor | 83 // - distance between top of this bubble's border and the bottom of the anchor |
114 // view (horizontal rule). | 84 // view (horizontal rule). |
115 int kBubbleMargin = 8; | 85 int kBubbleMargin = 8; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 if (bubble_text.empty()) | 408 if (bubble_text.empty()) |
439 bubble_text = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NO_NETWORKS); | 409 bubble_text = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NO_NETWORKS); |
440 | 410 |
441 auto* label = new views::Label(bubble_text); | 411 auto* label = new views::Label(bubble_text); |
442 label->SetMultiLine(true); | 412 label->SetMultiLine(true); |
443 label->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | 413 label->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); |
444 label->SetSelectable(true); | 414 label->SetSelectable(true); |
445 return label; | 415 return label; |
446 } | 416 } |
447 | 417 |
448 views::View* NetworkStateListDetailedView::CreateControlledByExtensionView( | |
449 const NetworkInfo& info) { | |
450 NetworkingConfigDelegate* networking_config_delegate = | |
451 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); | |
452 if (!networking_config_delegate) | |
453 return nullptr; | |
454 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> | |
455 extension_info = | |
456 networking_config_delegate->LookUpExtensionForNetwork(info.guid); | |
457 if (!extension_info) | |
458 return nullptr; | |
459 | |
460 // Get the tooltip text. | |
461 base::string16 tooltip_text = l10n_util::GetStringFUTF16( | |
462 IDS_ASH_STATUS_TRAY_EXTENSION_CONTROLLED_WIFI, | |
463 base::UTF8ToUTF16(extension_info->extension_name)); | |
464 | |
465 views::ImageView* controlled_icon = | |
466 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); | |
467 | |
468 controlled_icon->SetImage( | |
469 gfx::CreateVectorIcon(kCaptivePortalIcon, kMenuIconColor)); | |
470 controlled_icon->SetTooltipText(tooltip_text); | |
471 return controlled_icon; | |
472 } | |
473 | |
474 void NetworkStateListDetailedView::CallRequestScan() { | 418 void NetworkStateListDetailedView::CallRequestScan() { |
475 VLOG(1) << "Requesting Network Scan."; | 419 VLOG(1) << "Requesting Network Scan."; |
476 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 420 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
477 // Periodically request a scan while this UI is open. | 421 // Periodically request a scan while this UI is open. |
478 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 422 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
479 FROM_HERE, | 423 FROM_HERE, |
480 base::Bind(&NetworkStateListDetailedView::CallRequestScan, AsWeakPtr()), | 424 base::Bind(&NetworkStateListDetailedView::CallRequestScan, AsWeakPtr()), |
481 base::TimeDelta::FromSeconds(kRequestScanDelaySeconds)); | 425 base::TimeDelta::FromSeconds(kRequestScanDelaySeconds)); |
482 } | 426 } |
483 | 427 |
484 views::View* NetworkStateListDetailedView::CreateViewForNetwork( | |
485 const NetworkInfo& info) { | |
486 HoverHighlightView* container = new HoverHighlightView(this); | |
487 if (info.connected) | |
488 SetupConnectedItem(container, info.label, info.image); | |
489 else if (info.connecting) | |
490 SetupConnectingItem(container, info.label, info.image); | |
491 else | |
492 container->AddIconAndLabel(info.image, info.label); | |
493 container->SetTooltipText(info.tooltip); | |
494 views::View* controlled_icon = CreateControlledByExtensionView(info); | |
495 if (controlled_icon) | |
496 container->AddChildView(controlled_icon); | |
497 return container; | |
498 } | |
499 | |
500 NetworkTypePattern NetworkStateListDetailedView::GetNetworkTypePattern() const { | |
501 return list_type_ == LIST_TYPE_VPN ? NetworkTypePattern::VPN() | |
502 : NetworkTypePattern::NonVirtual(); | |
503 } | |
504 | |
505 void NetworkStateListDetailedView::UpdateViewForNetwork( | |
506 views::View* view, | |
507 const NetworkInfo& info) { | |
508 HoverHighlightView* container = static_cast<HoverHighlightView*>(view); | |
509 DCHECK(!container->has_children()); | |
510 if (info.connected) | |
511 SetupConnectedItem(container, info.label, info.image); | |
512 else if (info.connecting) | |
513 SetupConnectingItem(container, info.label, info.image); | |
514 else | |
515 container->AddIconAndLabel(info.image, info.label); | |
516 views::View* controlled_icon = CreateControlledByExtensionView(info); | |
517 container->SetTooltipText(info.tooltip); | |
518 if (controlled_icon) | |
519 view->AddChildView(controlled_icon); | |
520 } | |
521 | |
522 views::Label* NetworkStateListDetailedView::CreateInfoLabel() { | |
523 views::Label* label = new views::Label(); | |
524 label->SetBorder(views::CreateEmptyBorder(kTrayPopupPaddingBetweenItems, | |
525 kTrayPopupPaddingHorizontal, | |
526 kTrayPopupPaddingBetweenItems, 0)); | |
527 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
528 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); | |
529 return label; | |
530 } | |
531 | |
532 void NetworkStateListDetailedView::OnNetworkEntryClicked(views::View* sender) { | 428 void NetworkStateListDetailedView::OnNetworkEntryClicked(views::View* sender) { |
533 HandleViewClicked(sender); | 429 HandleViewClicked(sender); |
534 } | 430 } |
535 | 431 |
536 void NetworkStateListDetailedView::OnOtherWifiClicked() { | |
537 ShellPort::Get()->RecordUserMetricsAction( | |
538 UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED); | |
539 Shell::Get()->system_tray_controller()->ShowNetworkCreate(shill::kTypeWifi); | |
540 } | |
541 | |
542 void NetworkStateListDetailedView::RelayoutScrollList() { | 432 void NetworkStateListDetailedView::RelayoutScrollList() { |
543 scroller()->Layout(); | 433 scroller()->Layout(); |
544 } | 434 } |
545 | 435 |
546 } // namespace tray | 436 } // namespace tray |
547 } // namespace ash | 437 } // namespace ash |
OLD | NEW |