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

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: khorimoto@ comments 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
« no previous file with comments | « ash/system/network/network_list.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
581 if (controlled_icon) 584 // Add an additional icon to the right of the label for networks
582 view->AddRightView(controlled_icon); 585 // that require it (e.g. Tether, controlled by extension).
586 views::View* power_icon = CreatePowerStatusView(info);
587 if (power_icon) {
588 view->AddRightView(power_icon);
589 } else {
590 views::View* controlled_icon = CreateControlledByExtensionView(info);
591 if (controlled_icon)
592 view->AddRightView(controlled_icon);
593 }
594 }
595
596 views::View* NetworkListView::CreatePowerStatusView(const NetworkInfo& info) {
597 // Mobile can be Cellular or Tether.
598 if (info.type != NetworkInfo::Type::MOBILE)
599 return nullptr;
600
601 const chromeos::NetworkState* network =
602 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
603 info.guid);
604
605 // Only return a battery icon for Tether network type.
606 if (!NetworkTypePattern::Tether().MatchesType(network->type()))
607 return nullptr;
608
609 views::ImageView* icon = TrayPopupUtils::CreateMoreImageView();
610 gfx::Size canvas_size = gfx::Size(kMenuIconSize, kMenuIconSize);
Evan Stade 2017/06/14 18:04:38 Hi all, I am making some changes to the battery i
Kyle Horimoto 2017/06/15 20:14:23 Thanks for the heads-up, Evan! Just wanted to clar
611 gfx::Canvas canvas(canvas_size, 1.0f, false /* opaque */);
612
613 // Paint the battery's base (background) color.
614 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize,
615 kMenuIconColorDisabled);
616 // Paint the charged portion of the battery.
617 const int charge_height = network->battery_percentage() * kMenuIconSize / 100;
618 gfx::Rect clip_rect(0, kMenuIconSize - charge_height, kMenuIconSize,
619 charge_height);
620 canvas.Save();
621 canvas.ClipRect(clip_rect);
622 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize,
623 kMenuIconColor);
624 canvas.Restore();
625
626 // Show the battery icon with correct charge height.
627 icon->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(canvas.GetBitmap()));
628 // Show the numeric battery percentage on hover.
629 icon->SetTooltipText(base::FormatPercent(network->battery_percentage()));
630
631 return icon;
583 } 632 }
584 633
585 views::View* NetworkListView::CreateControlledByExtensionView( 634 views::View* NetworkListView::CreateControlledByExtensionView(
586 const NetworkInfo& info) { 635 const NetworkInfo& info) {
587 NetworkingConfigDelegate* networking_config_delegate = 636 NetworkingConfigDelegate* networking_config_delegate =
588 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); 637 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate();
589 if (!networking_config_delegate) 638 if (!networking_config_delegate)
590 return nullptr; 639 return nullptr;
591 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo> 640 std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo>
592 extension_info = 641 extension_info =
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( 787 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets(
739 0, 0, 0, kTrayPopupLabelRightPadding))); 788 0, 0, 0, kTrayPopupLabelRightPadding)));
740 789
741 // Nothing to the right of the text. 790 // Nothing to the right of the text.
742 connection_warning->SetContainerVisible(TriView::Container::END, false); 791 connection_warning->SetContainerVisible(TriView::Container::END, false);
743 return connection_warning; 792 return connection_warning;
744 } 793 }
745 794
746 } // namespace tray 795 } // namespace tray
747 } // namespace ash 796 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/network_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698