Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/resources/vector_icons/vector_icons.h" | |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
| 11 #include "ash/strings/grit/ash_strings.h" | 12 #include "ash/strings/grit/ash_strings.h" |
| 12 #include "ash/system/network/network_icon.h" | 13 #include "ash/system/network/network_icon.h" |
| 13 #include "ash/system/network/network_icon_animation.h" | 14 #include "ash/system/network/network_icon_animation.h" |
| 14 #include "ash/system/network/network_info.h" | 15 #include "ash/system/network/network_info.h" |
| 15 #include "ash/system/network/network_state_list_detailed_view.h" | 16 #include "ash/system/network/network_state_list_detailed_view.h" |
| 16 #include "ash/system/networking_config_delegate.h" | 17 #include "ash/system/networking_config_delegate.h" |
| 17 #include "ash/system/tray/hover_highlight_view.h" | 18 #include "ash/system/tray/hover_highlight_view.h" |
| 18 #include "ash/system/tray/system_menu_button.h" | 19 #include "ash/system/tray/system_menu_button.h" |
| 19 #include "ash/system/tray/system_tray_controller.h" | 20 #include "ash/system/tray/system_tray_controller.h" |
| 20 #include "ash/system/tray/system_tray_delegate.h" | 21 #include "ash/system/tray/system_tray_delegate.h" |
| 21 #include "ash/system/tray/tray_constants.h" | 22 #include "ash/system/tray/tray_constants.h" |
| 22 #include "ash/system/tray/tray_popup_item_style.h" | 23 #include "ash/system/tray/tray_popup_item_style.h" |
| 23 #include "ash/system/tray/tray_popup_utils.h" | 24 #include "ash/system/tray/tray_popup_utils.h" |
| 24 #include "ash/system/tray/tri_view.h" | 25 #include "ash/system/tray/tri_view.h" |
| 26 #include "base/i18n/number_formatting.h" | |
| 25 #include "base/memory/ptr_util.h" | 27 #include "base/memory/ptr_util.h" |
| 26 #include "base/strings/string16.h" | 28 #include "base/strings/string16.h" |
| 27 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 28 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 29 #include "chromeos/login/login_state.h" | 31 #include "chromeos/login/login_state.h" |
| 30 #include "chromeos/network/managed_network_configuration_handler.h" | 32 #include "chromeos/network/managed_network_configuration_handler.h" |
| 31 #include "chromeos/network/network_state.h" | 33 #include "chromeos/network/network_state.h" |
| 32 #include "chromeos/network/network_state_handler.h" | 34 #include "chromeos/network/network_state_handler.h" |
| 33 #include "chromeos/network/proxy/ui_proxy_config_service.h" | 35 #include "chromeos/network/proxy/ui_proxy_config_service.h" |
| 34 #include "components/device_event_log/device_event_log.h" | 36 #include "components/device_event_log/device_event_log.h" |
| 35 #include "third_party/cros_system_api/dbus/service_constants.h" | 37 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 36 #include "third_party/skia/include/core/SkColor.h" | 38 #include "third_party/skia/include/core/SkColor.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/gfx/canvas.h" | |
| 38 #include "ui/gfx/font.h" | 41 #include "ui/gfx/font.h" |
| 39 #include "ui/gfx/image/image_skia.h" | 42 #include "ui/gfx/image/image_skia.h" |
| 40 #include "ui/gfx/paint_vector_icon.h" | 43 #include "ui/gfx/paint_vector_icon.h" |
| 41 #include "ui/gfx/text_constants.h" | 44 #include "ui/gfx/text_constants.h" |
| 42 #include "ui/views/background.h" | 45 #include "ui/views/background.h" |
| 43 #include "ui/views/border.h" | 46 #include "ui/views/border.h" |
| 44 #include "ui/views/controls/button/toggle_button.h" | 47 #include "ui/views/controls/button/toggle_button.h" |
| 45 #include "ui/views/controls/image_view.h" | 48 #include "ui/views/controls/image_view.h" |
| 46 #include "ui/views/controls/label.h" | 49 #include "ui/views/controls/label.h" |
| 47 #include "ui/views/controls/scroll_view.h" | 50 #include "ui/views/controls/scroll_view.h" |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 | 564 |
| 562 // No networks or other messages (fallback). | 565 // No networks or other messages (fallback). |
| 563 if (index == 0) { | 566 if (index == 0) { |
| 564 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, | 567 UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, |
| 565 &no_wifi_networks_view_); | 568 &no_wifi_networks_view_); |
| 566 } | 569 } |
| 567 | 570 |
| 568 return new_guids; | 571 return new_guids; |
| 569 } | 572 } |
| 570 | 573 |
| 571 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, | 574 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, |
|
Kyle Horimoto
2017/06/12 17:22:09
Question: "Update" implies that this will be calle
lesliewatkins
2017/06/12 18:06:05
Reset() (called at the beginning of Update) preven
| |
| 572 const NetworkInfo& info) { | 575 const NetworkInfo& info) { |
| 573 view->Reset(); | 576 view->Reset(); |
| 574 view->AddIconAndLabel(info.image, info.label); | 577 view->AddIconAndLabel(info.image, info.label); |
| 575 if (info.connected) | 578 if (info.connected) |
| 576 SetupConnectedScrollListItem(view); | 579 SetupConnectedScrollListItem(view); |
| 577 else if (info.connecting) | 580 else if (info.connecting) |
| 578 SetupConnectingScrollListItem(view); | 581 SetupConnectingScrollListItem(view); |
| 579 view->SetTooltipText(info.tooltip); | 582 view->SetTooltipText(info.tooltip); |
| 580 views::View* controlled_icon = CreateControlledByExtensionView(info); | 583 views::View* power_icon = CreatePowerStatusView(info); |
|
Kyle Horimoto
2017/06/12 17:22:09
nit: Can you move the code from here onward to a h
lesliewatkins
2017/06/12 18:06:05
I went the line break route for now.
Done.
| |
| 581 if (controlled_icon) | 584 if (power_icon) { |
| 582 view->AddRightView(controlled_icon); | 585 view->AddRightView(power_icon); |
|
Kyle Horimoto
2017/06/12 17:22:09
nit: Return early to avoid the extra indentation f
stevenjb
2017/06/12 17:30:04
I would actually suggest against that, at least wi
lesliewatkins
2017/06/12 18:06:05
Acknowledged.
| |
| 586 } else { | |
| 587 views::View* controlled_icon = CreateControlledByExtensionView(info); | |
| 588 if (controlled_icon) | |
| 589 view->AddRightView(controlled_icon); | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 views::View* NetworkListView::CreatePowerStatusView(const NetworkInfo& info) { | |
| 594 // Mobile can be Cellular or Tether. | |
| 595 if (info.type != NetworkInfo::Type::MOBILE) | |
| 596 return nullptr; | |
| 597 | |
| 598 const chromeos::NetworkState* network = | |
| 599 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( | |
| 600 info.guid); | |
| 601 | |
| 602 // Only return a battery icon for Tether network type. | |
| 603 if (!NetworkTypePattern::Tether().MatchesType(network->type())) | |
| 604 return nullptr; | |
| 605 | |
| 606 views::ImageView* icon = TrayPopupUtils::CreateMainImageView(); | |
|
Kyle Horimoto
2017/06/12 17:22:09
Are we sure CreateMainImageView() is the right fun
lesliewatkins
2017/06/12 18:06:05
Looking more closely at these methods, I believe y
| |
| 607 gfx::Size canvas_size = gfx::Size(kMenuIconSize, kMenuIconSize); | |
| 608 gfx::Canvas canvas(canvas_size, 1.0f, false /* opaque */); | |
| 609 | |
| 610 // Paint the battery's base (background) color. | |
| 611 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize, | |
| 612 kMenuIconColorDisabled); | |
| 613 // Paint the charged portion of the battery. | |
| 614 const int charge_height = network->battery_percentage() * kMenuIconSize / 100; | |
| 615 gfx::Rect clip_rect(0, kMenuIconSize - charge_height, kMenuIconSize, | |
| 616 charge_height); | |
| 617 canvas.Save(); | |
| 618 canvas.ClipRect(clip_rect); | |
| 619 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize, | |
| 620 kMenuIconColor); | |
| 621 canvas.Restore(); | |
| 622 | |
| 623 // Show the battery icon with correct charge height. | |
| 624 icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(canvas.GetBitmap())); | |
| 625 // Show the numeric battery percentage on hover. | |
| 626 icon->SetTooltipText(base::FormatPercent(network->battery_percentage())); | |
|
Kyle Horimoto
2017/06/12 17:22:09
Does this need to be localized? I could imagine th
stevenjb
2017/06/12 17:30:03
That's what base::FormatPercent does :)
lesliewatkins
2017/06/12 18:06:05
Yes, but I think FormatPercent() does do the local
| |
| 627 | |
| 628 return icon; | |
| 583 } | 629 } |
| 584 | 630 |
| 585 views::View* NetworkListView::CreateControlledByExtensionView( | 631 views::View* NetworkListView::CreateControlledByExtensionView( |
| 586 const NetworkInfo& info) { | 632 const NetworkInfo& info) { |
| 587 NetworkingConfigDelegate* networking_config_delegate = | 633 NetworkingConfigDelegate* networking_config_delegate = |
| 588 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); | 634 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); |
| 589 if (!networking_config_delegate) | 635 if (!networking_config_delegate) |
| 590 return nullptr; | 636 return nullptr; |
| 591 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> | 637 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> |
| 592 extension_info = | 638 extension_info = |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 784 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
| 739 0, 0, 0, kTrayPopupLabelRightPadding))); | 785 0, 0, 0, kTrayPopupLabelRightPadding))); |
| 740 | 786 |
| 741 // Nothing to the right of the text. | 787 // Nothing to the right of the text. |
| 742 connection_warning->SetContainerVisible(TriView::Container::END, false); | 788 connection_warning->SetContainerVisible(TriView::Container::END, false); |
| 743 return connection_warning; | 789 return connection_warning; |
| 744 } | 790 } |
| 745 | 791 |
| 746 } // namespace tray | 792 } // namespace tray |
| 747 } // namespace ash | 793 } // namespace ash |
| OLD | NEW |