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_POWER_STATUS_VIEW_H_ | 5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ |
6 #define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ | 6 #define ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ |
7 | 7 |
8 #include "chromeos/dbus/power_supply_status.h" | 8 #include "ash/system/chromeos/power/power_status.h" |
9 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 class ImageView; | 12 class ImageView; |
13 class Label; | 13 class Label; |
14 } | 14 } |
15 | 15 |
16 namespace ash { | 16 namespace ash { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 class PowerStatusView : public views::View { | 19 class PowerStatusView : public views::View, public PowerStatus::Observer { |
20 public: | 20 public: |
21 enum ViewType { | 21 enum ViewType { |
22 VIEW_DEFAULT, | 22 VIEW_DEFAULT, |
23 VIEW_NOTIFICATION | 23 VIEW_NOTIFICATION |
24 }; | 24 }; |
25 | 25 |
26 PowerStatusView(ViewType view_type, bool default_view_right_align); | 26 PowerStatusView(ViewType view_type, bool default_view_right_align); |
27 virtual ~PowerStatusView() {} | 27 virtual ~PowerStatusView(); |
28 | |
29 void UpdatePowerStatus(const chromeos::PowerSupplyStatus& status); | |
30 const base::string16& accessible_name() const { return accessible_name_; } | |
31 | 28 |
32 // Overridden from views::View. | 29 // Overridden from views::View. |
33 virtual gfx::Size GetPreferredSize() OVERRIDE; | 30 virtual gfx::Size GetPreferredSize() OVERRIDE; |
34 virtual int GetHeightForWidth(int width) OVERRIDE; | 31 virtual int GetHeightForWidth(int width) OVERRIDE; |
35 virtual void Layout() OVERRIDE; | 32 virtual void Layout() OVERRIDE; |
36 | 33 |
| 34 // Overridden from PowerStatus::Observer. |
| 35 virtual void OnPowerStatusChanged() OVERRIDE; |
| 36 |
37 private: | 37 private: |
38 void LayoutDefaultView(); | 38 void LayoutDefaultView(); |
39 void LayoutNotificationView(); | 39 void LayoutNotificationView(); |
40 void UpdateText(); | |
41 void UpdateIcon(); | |
42 void Update(); | |
43 void UpdateTextForDefaultView(); | 40 void UpdateTextForDefaultView(); |
44 void UpdateTextForNotificationView(); | 41 void UpdateTextForNotificationView(); |
45 base::string16 GetBatteryTimeAccessibilityString(int hour, int min); | |
46 | 42 |
47 // Overridden from views::View. | 43 // Overridden from views::View. |
48 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; | 44 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; |
49 | 45 |
50 // Layout default view UI items on the right side of system tray pop up item | 46 // Layout default view UI items on the right side of system tray pop up item |
51 // if true; otherwise, layout the UI items on the left side. | 47 // if true; otherwise, layout the UI items on the left side. |
52 bool default_view_right_align_; | 48 bool default_view_right_align_; |
53 | 49 |
54 // Labels used only for VIEW_NOTIFICATION. | 50 // Labels used only for VIEW_NOTIFICATION. |
55 views::Label* status_label_; | 51 views::Label* status_label_; |
56 views::Label* time_label_; | 52 views::Label* time_label_; |
57 | 53 |
58 // Labels used only for VIEW_DEFAULT. | 54 // Labels used only for VIEW_DEFAULT. |
59 views::Label* time_status_label_; | 55 views::Label* time_status_label_; |
60 views::Label* percentage_label_; | 56 views::Label* percentage_label_; |
61 | 57 |
62 // Battery status indicator icon. | 58 // Battery status indicator icon. |
63 views::ImageView* icon_; | 59 views::ImageView* icon_; |
64 | 60 |
65 // Index of the current icon in the icon array image, or -1 if unknown. | |
66 int icon_image_index_; | |
67 | |
68 // Horizontal offset of the current icon in the icon array image. | |
69 int icon_image_offset_; | |
70 | |
71 // Battery charging may be unreliable for non-standard power supplies. | |
72 // It may change from charging to discharging frequently depending on | |
73 // charger power and current power consumption. We show different UIs | |
74 // when in this state. See TrayPower::IsBatteryChargingUnreliable. | |
75 bool battery_charging_unreliable_; | |
76 | |
77 ViewType view_type_; | 61 ViewType view_type_; |
78 | 62 |
79 chromeos::PowerSupplyStatus supply_status_; | |
80 | |
81 base::string16 accessible_name_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PowerStatusView); | 63 DISALLOW_COPY_AND_ASSIGN(PowerStatusView); |
84 }; | 64 }; |
85 | 65 |
86 } // namespace internal | 66 } // namespace internal |
87 } // namespace ash | 67 } // namespace ash |
88 | 68 |
89 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ | 69 #endif // ASH_SYSTEM_CHROMEOS_POWER_POWER_STATUS_VIEW_H_ |
OLD | NEW |