OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ | 5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ |
6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ | 6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ |
7 | 7 |
8 #include "ash/system/chromeos/power/power_status.h" | 8 #include "ash/system/chromeos/power/power_status.h" |
9 #include "ash/system/tray/system_tray_item.h" | 9 #include "ash/system/tray/system_tray_item.h" |
10 | 10 |
11 class SkBitmap; | 11 class SkBitmap; |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 class Image; | 14 class Image; |
15 class ImageSkia; | 15 class ImageSkia; |
16 } | 16 } |
17 | 17 |
18 namespace message_center { | 18 namespace message_center { |
19 class MessageCenter; | 19 class MessageCenter; |
20 } | 20 } |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace internal { | 23 namespace internal { |
24 | 24 |
25 namespace tray { | 25 namespace tray { |
26 class PowerNotificationView; | 26 class PowerNotificationView; |
27 class PowerTrayView; | 27 class PowerTrayView; |
28 } | 28 } |
29 | 29 |
30 enum IconSet { | |
31 ICON_LIGHT, | |
32 ICON_DARK | |
33 }; | |
34 | |
35 class ASH_EXPORT TrayPower : public SystemTrayItem, | 30 class ASH_EXPORT TrayPower : public SystemTrayItem, |
36 public PowerStatus::Observer { | 31 public PowerStatus::Observer { |
37 public: | 32 public: |
38 // Visible for testing. | 33 // Visible for testing. |
39 enum NotificationState { | 34 enum NotificationState { |
40 NOTIFICATION_NONE, | 35 NOTIFICATION_NONE, |
41 | 36 |
42 // Low battery charge. | 37 // Low battery charge. |
43 NOTIFICATION_LOW_POWER, | 38 NOTIFICATION_LOW_POWER, |
44 | 39 |
45 // Critically low battery charge. | 40 // Critically low battery charge. |
46 NOTIFICATION_CRITICAL, | 41 NOTIFICATION_CRITICAL, |
47 }; | 42 }; |
48 | 43 |
49 TrayPower(SystemTray* system_tray, | 44 TrayPower(SystemTray* system_tray, |
50 message_center::MessageCenter* message_center); | 45 message_center::MessageCenter* message_center); |
51 virtual ~TrayPower(); | 46 virtual ~TrayPower(); |
52 | 47 |
53 // Gets whether battery charging is unreliable for |supply_status|. | |
54 // When a non-standard power supply is connected, the battery may | |
55 // change from being charged to discharged frequently depending on the | |
56 // charger power and power consumption, i.e usage. In this case we | |
57 // do not want to show either a charging or discharging state. | |
58 static bool IsBatteryChargingUnreliable( | |
59 const chromeos::PowerSupplyStatus& supply_status); | |
60 | |
61 // Gets the icon index in the battery icon array image based on | |
62 // |supply_status|. If |supply_status| is uncertain about the power state, | |
63 // returns -1. | |
64 static int GetBatteryImageIndex( | |
65 const chromeos::PowerSupplyStatus& supply_status); | |
66 | |
67 // Gets the horizontal offset in the battery icon array image based on | |
68 // |supply_status|. | |
69 static int GetBatteryImageOffset( | |
70 const chromeos::PowerSupplyStatus& supply_status); | |
71 | |
72 // Looks up the actual icon in the icon array image for |image_index|. | |
73 static gfx::ImageSkia GetBatteryImage(int image_index, | |
74 int image_offset, | |
75 bool charging_unreliable, | |
76 IconSet icon_set); | |
77 | |
78 // Gets the battery accessible string for |supply_status|. | |
79 static base::string16 GetAccessibleNameString( | |
80 const chromeos::PowerSupplyStatus& supply_status); | |
81 | |
82 // Gets rounded battery percentage for |battery_percentage|. | |
83 static int GetRoundedBatteryPercentage(double battery_percentage); | |
84 | |
85 private: | 48 private: |
86 friend class TrayPowerTest; | 49 friend class TrayPowerTest; |
87 | 50 |
88 // Overridden from SystemTrayItem. | 51 // Overridden from SystemTrayItem. |
89 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; | 52 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; |
90 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; | 53 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; |
91 virtual views::View* CreateNotificationView( | 54 virtual views::View* CreateNotificationView( |
92 user::LoginStatus status) OVERRIDE; | 55 user::LoginStatus status) OVERRIDE; |
93 virtual void DestroyTrayView() OVERRIDE; | 56 virtual void DestroyTrayView() OVERRIDE; |
94 virtual void DestroyDefaultView() OVERRIDE; | 57 virtual void DestroyDefaultView() OVERRIDE; |
95 virtual void DestroyNotificationView() OVERRIDE; | 58 virtual void DestroyNotificationView() OVERRIDE; |
96 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; | 59 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; |
97 virtual void UpdateAfterShelfAlignmentChange( | 60 virtual void UpdateAfterShelfAlignmentChange( |
98 ShelfAlignment alignment) OVERRIDE; | 61 ShelfAlignment alignment) OVERRIDE; |
99 | 62 |
100 // Overridden from PowerStatus::Observer. | 63 // Overridden from PowerStatus::Observer. |
101 virtual void OnPowerStatusChanged( | 64 virtual void OnPowerStatusChanged() OVERRIDE; |
102 const chromeos::PowerSupplyStatus& status) OVERRIDE; | |
103 | |
104 // Requests a power status update. | |
105 void RequestStatusUpdate() const; | |
106 | 65 |
107 // Show a notification that a low-power USB charger has been connected. | 66 // Show a notification that a low-power USB charger has been connected. |
108 // Returns true if a notification was shown or explicitly hidden. | 67 // Returns true if a notification was shown or explicitly hidden. |
109 bool MaybeShowUsbChargerNotification( | 68 bool MaybeShowUsbChargerNotification(); |
110 const chromeos::PowerSupplyStatus& old_status, | |
111 const chromeos::PowerSupplyStatus& new_status); | |
112 | 69 |
113 // Sets |notification_state_|. Returns true if a notification should be shown. | 70 // Sets |notification_state_|. Returns true if a notification should be shown. |
114 bool UpdateNotificationState(const chromeos::PowerSupplyStatus& status); | 71 bool UpdateNotificationState(); |
115 bool UpdateNotificationStateForRemainingTime(int remaining_seconds); | 72 bool UpdateNotificationStateForRemainingTime(); |
116 bool UpdateNotificationStateForRemainingPercentage( | 73 bool UpdateNotificationStateForRemainingPercentage(); |
117 double remaining_percentage); | |
118 | 74 |
119 message_center::MessageCenter* message_center_; // Not owned. | 75 message_center::MessageCenter* message_center_; // Not owned. |
120 tray::PowerTrayView* power_tray_; | 76 tray::PowerTrayView* power_tray_; |
121 tray::PowerNotificationView* notification_view_; | 77 tray::PowerNotificationView* notification_view_; |
122 NotificationState notification_state_; | 78 NotificationState notification_state_; |
123 | 79 |
124 // Power supply status at the last update. | 80 // Was a USB charger connected the last time OnPowerStatusChanged() was |
125 chromeos::PowerSupplyStatus last_power_supply_status_; | 81 // called? |
| 82 bool usb_charger_was_connected_; |
126 | 83 |
127 DISALLOW_COPY_AND_ASSIGN(TrayPower); | 84 DISALLOW_COPY_AND_ASSIGN(TrayPower); |
128 }; | 85 }; |
129 | 86 |
130 } // namespace internal | 87 } // namespace internal |
131 } // namespace ash | 88 } // namespace ash |
132 | 89 |
133 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ | 90 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ |
OLD | NEW |