Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: ash/system/network/network_list.cc

Issue 2932373002: Add a battery icon to the right of Tether networks in system tray. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 573
571 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, 574 void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view,
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);
581 if (controlled_icon) 584 if (power_icon) {
582 view->AddRightView(controlled_icon); 585 view->AddRightView(power_icon);
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 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
stevenjb 2017/06/12 16:20:51 handler is only used once, so no need for local.
lesliewatkins 2017/06/12 16:53:34 Done.
599 const chromeos::NetworkState* network =
600 handler->GetNetworkStateFromGuid(info.guid);
601
602 // Only return a battery icon for Tether network type.
603 if (NetworkTypePattern::Tether().MatchesType(network->type())) {
stevenjb 2017/06/12 16:20:51 invert and early exit
lesliewatkins 2017/06/12 16:53:35 Done.
604 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView();
stevenjb 2017/06/12 16:20:51 Why 'right_icon'?
lesliewatkins 2017/06/12 16:53:35 A holdover from before the icon creation was in it
605 int canvas_size = gfx::Size(kMenuIconSize, kMenuIconSize);
606 gfx::Canvas canvas(canvas_size, 1.0f, false /* opaque */);
607
608 // Paint the battery's base (background) color.
609 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize,
610 kMenuIconColorDisabled);
611 // Paint the charged portion of the battery.
612 const int charge_height =
613 network->battery_percentage() * kMenuIconSize / 100;
614 gfx::Rect clip_rect(0, kBatteryCanvasSize - charge_height,
615 kMenuIconSize charge_height);
616 canvas.Save();
617 canvas.ClipRect(clip_rect);
618 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize,
619 kMenuIconColor);
620 canvas.Restore();
621
622 // Show the battery icon with correct charge height.
623 right_icon->SetImage(
624 gfx::ImageSkia::CreateFrom1xBitmap(canvas.GetBitmap()));
625 // Show the numeric battery percentage on hover.
626 right_icon->SetTooltipText(
627 base::FormatPercent(network->battery_percentage()));
628
629 return right_icon;
630 }
631
632 return nullptr;
583 } 633 }
584 634
585 views::View* NetworkListView::CreateControlledByExtensionView( 635 views::View* NetworkListView::CreateControlledByExtensionView(
586 const NetworkInfo& info) { 636 const NetworkInfo& info) {
587 NetworkingConfigDelegate* networking_config_delegate = 637 NetworkingConfigDelegate* networking_config_delegate =
588 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); 638 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate();
589 if (!networking_config_delegate) 639 if (!networking_config_delegate)
590 return nullptr; 640 return nullptr;
591 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> 641 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo>
592 extension_info = 642 extension_info =
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( 788 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets(
739 0, 0, 0, kTrayPopupLabelRightPadding))); 789 0, 0, 0, kTrayPopupLabelRightPadding)));
740 790
741 // Nothing to the right of the text. 791 // Nothing to the right of the text.
742 connection_warning->SetContainerVisible(TriView::Container::END, false); 792 connection_warning->SetContainerVisible(TriView::Container::END, false);
743 return connection_warning; 793 return connection_warning;
744 } 794 }
745 795
746 } // namespace tray 796 } // namespace tray
747 } // namespace ash 797 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698