|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_dom_battery_BatteryManager_h |
|
7 #define mozilla_dom_battery_BatteryManager_h |
|
8 |
|
9 #include "Types.h" |
|
10 #include "mozilla/DOMEventTargetHelper.h" |
|
11 #include "mozilla/Observer.h" |
|
12 #include "nsCycleCollectionParticipant.h" |
|
13 |
|
14 class nsPIDOMWindow; |
|
15 class nsIScriptContext; |
|
16 |
|
17 namespace mozilla { |
|
18 |
|
19 namespace hal { |
|
20 class BatteryInformation; |
|
21 } // namespace hal |
|
22 |
|
23 namespace dom { |
|
24 namespace battery { |
|
25 |
|
26 class BatteryManager : public DOMEventTargetHelper |
|
27 , public BatteryObserver |
|
28 { |
|
29 public: |
|
30 BatteryManager(nsPIDOMWindow* aWindow); |
|
31 |
|
32 void Init(); |
|
33 void Shutdown(); |
|
34 |
|
35 // For IObserver. |
|
36 void Notify(const hal::BatteryInformation& aBatteryInfo); |
|
37 |
|
38 /** |
|
39 * Returns whether the battery api is supported (ie. not disabled by the user) |
|
40 * @return whether the battery api is supported. |
|
41 */ |
|
42 static bool HasSupport(); |
|
43 |
|
44 /** |
|
45 * WebIDL Interface |
|
46 */ |
|
47 |
|
48 nsPIDOMWindow* GetParentObject() const |
|
49 { |
|
50 return GetOwner(); |
|
51 } |
|
52 |
|
53 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
54 |
|
55 bool Charging() const |
|
56 { |
|
57 return mCharging; |
|
58 } |
|
59 |
|
60 double ChargingTime() const; |
|
61 |
|
62 double DischargingTime() const; |
|
63 |
|
64 double Level() const |
|
65 { |
|
66 return mLevel; |
|
67 } |
|
68 |
|
69 IMPL_EVENT_HANDLER(chargingchange) |
|
70 IMPL_EVENT_HANDLER(chargingtimechange) |
|
71 IMPL_EVENT_HANDLER(dischargingtimechange) |
|
72 IMPL_EVENT_HANDLER(levelchange) |
|
73 |
|
74 private: |
|
75 /** |
|
76 * Update the battery information stored in the battery manager object using |
|
77 * a battery information object. |
|
78 */ |
|
79 void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo); |
|
80 |
|
81 double mLevel; |
|
82 bool mCharging; |
|
83 /** |
|
84 * Represents the discharging time or the charging time, dpending on the |
|
85 * current battery status (charging or not). |
|
86 */ |
|
87 double mRemainingTime; |
|
88 }; |
|
89 |
|
90 } // namespace battery |
|
91 } // namespace dom |
|
92 } // namespace mozilla |
|
93 |
|
94 #endif // mozilla_dom_battery_BatteryManager_h |