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

Side by Side Diff: ash/common/system/chromeos/power/power_status.cc

Issue 2316183003: Move a bunch of ash-only vector icons to ash/. (Closed)
Patch Set: drop the "id". Just "icon". It's cleaner. Created 4 years, 3 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/common/system/chromeos/power/power_status.h" 5 #include "ash/common/system/chromeos/power/power_status.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/resources/vector_icons/vector_icons.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/power_manager_client.h" 16 #include "chromeos/dbus/power_manager_client.h"
16 #include "grit/ash_resources.h" 17 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/l10n/time_format.h" 20 #include "ui/base/l10n/time_format.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/display/display.h" 22 #include "ui/display/display.h"
22 #include "ui/display/screen.h" 23 #include "ui/display/screen.h"
23 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/image/image_skia_operations.h" 27 #include "ui/gfx/image/image_skia_operations.h"
27 #include "ui/gfx/paint_vector_icon.h" 28 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icons_public.h"
29 29
30 namespace ash { 30 namespace ash {
31 namespace { 31 namespace {
32 32
33 // Updates |proto| to ensure that its fields are consistent. 33 // Updates |proto| to ensure that its fields are consistent.
34 void SanitizeProto(power_manager::PowerSupplyProperties* proto) { 34 void SanitizeProto(power_manager::PowerSupplyProperties* proto) {
35 DCHECK(proto); 35 DCHECK(proto);
36 36
37 if (proto->battery_state() == 37 if (proto->battery_state() ==
38 power_manager::PowerSupplyProperties_BatteryState_FULL) 38 power_manager::PowerSupplyProperties_BatteryState_FULL)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return IDS_ASH_POWER_SOURCE_PORT_RIGHT_BACK; 93 return IDS_ASH_POWER_SOURCE_PORT_RIGHT_BACK;
94 case power_manager::PowerSupplyProperties_PowerSource_Port_BACK_LEFT: 94 case power_manager::PowerSupplyProperties_PowerSource_Port_BACK_LEFT:
95 return IDS_ASH_POWER_SOURCE_PORT_BACK_LEFT; 95 return IDS_ASH_POWER_SOURCE_PORT_BACK_LEFT;
96 case power_manager::PowerSupplyProperties_PowerSource_Port_BACK_RIGHT: 96 case power_manager::PowerSupplyProperties_PowerSource_Port_BACK_RIGHT:
97 return IDS_ASH_POWER_SOURCE_PORT_BACK_RIGHT; 97 return IDS_ASH_POWER_SOURCE_PORT_BACK_RIGHT;
98 } 98 }
99 NOTREACHED(); 99 NOTREACHED();
100 return 0; 100 return 0;
101 } 101 }
102 102
103 gfx::VectorIconId VectorIconIdForIconBadge(PowerStatus::IconBadge icon_badge) { 103 const gfx::VectorIcon& VectorIconForIconBadge(
104 PowerStatus::IconBadge icon_badge) {
104 switch (icon_badge) { 105 switch (icon_badge) {
105 case PowerStatus::ICON_BADGE_NONE: 106 case PowerStatus::ICON_BADGE_NONE:
106 return gfx::VectorIconId::VECTOR_ICON_NONE; 107 return gfx::kNoneIcon;
107 case PowerStatus::ICON_BADGE_ALERT: 108 case PowerStatus::ICON_BADGE_ALERT:
108 return gfx::VectorIconId::SYSTEM_TRAY_BATTERY_ALERT; 109 return kSystemTrayBatteryAlertIcon;
109 case PowerStatus::ICON_BADGE_BOLT: 110 case PowerStatus::ICON_BADGE_BOLT:
110 return gfx::VectorIconId::SYSTEM_TRAY_BATTERY_BOLT; 111 return kSystemTrayBatteryBoltIcon;
111 case PowerStatus::ICON_BADGE_X: 112 case PowerStatus::ICON_BADGE_X:
112 return gfx::VectorIconId::SYSTEM_TRAY_BATTERY_X; 113 return kSystemTrayBatteryXIcon;
113 case PowerStatus::ICON_BADGE_UNRELIABLE: 114 case PowerStatus::ICON_BADGE_UNRELIABLE:
114 return gfx::VectorIconId::SYSTEM_TRAY_BATTERY_UNRELIABLE; 115 return kSystemTrayBatteryUnreliableIcon;
115 } 116 }
116 NOTREACHED(); 117 NOTREACHED();
117 return gfx::VectorIconId::VECTOR_ICON_NONE; 118 return gfx::kNoneIcon;
118 } 119 }
119 120
120 static PowerStatus* g_power_status = NULL; 121 static PowerStatus* g_power_status = NULL;
121 122
122 // Minimum battery percentage rendered in UI. 123 // Minimum battery percentage rendered in UI.
123 const int kMinBatteryPercent = 1; 124 const int kMinBatteryPercent = 1;
124 125
125 // Width and height of battery images. 126 // Width and height of battery images.
126 const int kBatteryImageHeight = 25; 127 const int kBatteryImageHeight = 25;
127 const int kBatteryImageWidth = 25; 128 const int kBatteryImageWidth = 25;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 const SkColor badge_color = 402 const SkColor badge_color =
402 use_alert_color ? kBatteryAlertColor : kBatteryBadgeColor; 403 use_alert_color ? kBatteryAlertColor : kBatteryBadgeColor;
403 const SkColor charge_color = 404 const SkColor charge_color =
404 use_alert_color ? kBatteryAlertColor : kBatteryChargeColor; 405 use_alert_color ? kBatteryAlertColor : kBatteryChargeColor;
405 gfx::Canvas canvas( 406 gfx::Canvas canvas(
406 gfx::Size(kBatteryCanvasSizeMd, kBatteryCanvasSizeMd), 407 gfx::Size(kBatteryCanvasSizeMd, kBatteryCanvasSizeMd),
407 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(), 408 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(),
408 false); 409 false);
409 410
410 // Paint the battery's base (background) color. 411 // Paint the battery's base (background) color.
411 PaintVectorIcon(&canvas, gfx::VectorIconId::SYSTEM_TRAY_BATTERY, 412 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSizeMd,
412 kBatteryCanvasSizeMd, kBatteryBaseColor); 413 kBatteryBaseColor);
413 414
414 // Paint the charged portion of the battery. Note that |charge_height| adjusts 415 // Paint the charged portion of the battery. Note that |charge_height| adjusts
415 // for the 2dp of padding between the bottom of the battery icon and the 416 // for the 2dp of padding between the bottom of the battery icon and the
416 // bottom edge of |canvas|. 417 // bottom edge of |canvas|.
417 const int charge_height = info.charge_level + 2; 418 const int charge_height = info.charge_level + 2;
418 gfx::Rect clip_rect(0, kBatteryCanvasSizeMd - charge_height, 419 gfx::Rect clip_rect(0, kBatteryCanvasSizeMd - charge_height,
419 kBatteryCanvasSizeMd, charge_height); 420 kBatteryCanvasSizeMd, charge_height);
420 canvas.Save(); 421 canvas.Save();
421 canvas.ClipRect(clip_rect); 422 canvas.ClipRect(clip_rect);
422 PaintVectorIcon(&canvas, gfx::VectorIconId::SYSTEM_TRAY_BATTERY, 423 PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSizeMd,
423 kBatteryCanvasSizeMd, charge_color); 424 charge_color);
424 canvas.Restore(); 425 canvas.Restore();
425 426
426 // Paint the badge over top of the battery, if applicable. 427 // Paint the badge over top of the battery, if applicable.
427 if (info.icon_badge != ICON_BADGE_NONE) { 428 if (info.icon_badge != ICON_BADGE_NONE) {
428 PaintVectorIcon(&canvas, VectorIconIdForIconBadge(info.icon_badge), 429 PaintVectorIcon(&canvas, VectorIconForIconBadge(info.icon_badge),
429 kBatteryCanvasSizeMd, badge_color); 430 kBatteryCanvasSizeMd, badge_color);
430 } 431 }
431 432
432 return gfx::ImageSkia(canvas.ExtractImageRep()); 433 return gfx::ImageSkia(canvas.ExtractImageRep());
433 } 434 }
434 435
435 gfx::ImageSkia PowerStatus::GetBatteryImageNonMd( 436 gfx::ImageSkia PowerStatus::GetBatteryImageNonMd(
436 const BatteryImageInfo& info) const { 437 const BatteryImageInfo& info) const {
437 gfx::Image all; 438 gfx::Image all;
438 all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(info.resource_id); 439 all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(info.resource_id);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 508 }
508 509
509 void PowerStatus::PowerChanged( 510 void PowerStatus::PowerChanged(
510 const power_manager::PowerSupplyProperties& proto) { 511 const power_manager::PowerSupplyProperties& proto) {
511 proto_ = proto; 512 proto_ = proto;
512 SanitizeProto(&proto_); 513 SanitizeProto(&proto_);
513 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged()); 514 FOR_EACH_OBSERVER(Observer, observers_, OnPowerStatusChanged());
514 } 515 }
515 516
516 } // namespace ash 517 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698