Chromium Code Reviews| Index: ash/system/network/network_list.cc |
| diff --git a/ash/system/network/network_list.cc b/ash/system/network/network_list.cc |
| index 5415eabb3c6d5b5315992a82b241e91250cb3815..9e48c9f257855c2b3073f524cdae60977cc021a1 100644 |
| --- a/ash/system/network/network_list.cc |
| +++ b/ash/system/network/network_list.cc |
| @@ -6,6 +6,7 @@ |
| #include <memory> |
| +#include "ash/resources/vector_icons/vector_icons.h" |
| #include "ash/shell.h" |
| #include "ash/shell_port.h" |
| #include "ash/strings/grit/ash_strings.h" |
| @@ -22,6 +23,7 @@ |
| #include "ash/system/tray/tray_popup_item_style.h" |
| #include "ash/system/tray/tray_popup_utils.h" |
| #include "ash/system/tray/tri_view.h" |
| +#include "base/i18n/number_formatting.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/utf_string_conversions.h" |
| @@ -35,6 +37,7 @@ |
| #include "third_party/cros_system_api/dbus/service_constants.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/gfx/canvas.h" |
| #include "ui/gfx/font.h" |
| #include "ui/gfx/image/image_skia.h" |
| #include "ui/gfx/paint_vector_icon.h" |
| @@ -577,9 +580,56 @@ void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view, |
| else if (info.connecting) |
| SetupConnectingScrollListItem(view); |
| view->SetTooltipText(info.tooltip); |
| - views::View* controlled_icon = CreateControlledByExtensionView(info); |
| - if (controlled_icon) |
| - view->AddRightView(controlled_icon); |
| + views::View* power_icon = CreatePowerStatusView(info); |
| + if (power_icon) { |
| + view->AddRightView(power_icon); |
| + } else { |
| + views::View* controlled_icon = CreateControlledByExtensionView(info); |
| + if (controlled_icon) |
| + view->AddRightView(controlled_icon); |
| + } |
| +} |
| + |
| +views::View* NetworkListView::CreatePowerStatusView(const NetworkInfo& info) { |
| + // Mobile can be Cellular or Tether. |
| + if (info.type != NetworkInfo::Type::MOBILE) |
| + return nullptr; |
| + |
| + 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.
|
| + const chromeos::NetworkState* network = |
| + handler->GetNetworkStateFromGuid(info.guid); |
| + |
| + // Only return a battery icon for Tether network type. |
| + 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.
|
| + 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
|
| + int canvas_size = gfx::Size(kMenuIconSize, kMenuIconSize); |
| + gfx::Canvas canvas(canvas_size, 1.0f, false /* opaque */); |
| + |
| + // Paint the battery's base (background) color. |
| + PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize, |
| + kMenuIconColorDisabled); |
| + // Paint the charged portion of the battery. |
| + const int charge_height = |
| + network->battery_percentage() * kMenuIconSize / 100; |
| + gfx::Rect clip_rect(0, kBatteryCanvasSize - charge_height, |
| + kMenuIconSize charge_height); |
| + canvas.Save(); |
| + canvas.ClipRect(clip_rect); |
| + PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kMenuIconSize, |
| + kMenuIconColor); |
| + canvas.Restore(); |
| + |
| + // Show the battery icon with correct charge height. |
| + right_icon->SetImage( |
| + gfx::ImageSkia::CreateFrom1xBitmap(canvas.GetBitmap())); |
| + // Show the numeric battery percentage on hover. |
| + right_icon->SetTooltipText( |
| + base::FormatPercent(network->battery_percentage())); |
| + |
| + return right_icon; |
| + } |
| + |
| + return nullptr; |
| } |
| views::View* NetworkListView::CreateControlledByExtensionView( |