Bug 1854367 - Mark storage-access-permission.sub.https.window.html subtest as intermi...
[gecko.git] / dom / battery / BatteryManager.h
blobc92df7e6622fd5b3b12826cbe7bee9690c53c1bb
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_battery_BatteryManager_h
8 #define mozilla_dom_battery_BatteryManager_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/HalBatteryInformation.h"
13 namespace mozilla {
15 namespace hal {
16 class BatteryInformation;
17 } // namespace hal
19 namespace dom::battery {
21 class BatteryManager : public DOMEventTargetHelper,
22 public hal::BatteryObserver {
23 public:
24 explicit BatteryManager(nsPIDOMWindowInner* aWindow);
26 void Init();
27 void Shutdown();
29 // For IObserver.
30 void Notify(const hal::BatteryInformation& aBatteryInfo) override;
32 /**
33 * WebIDL Interface
36 nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
38 virtual JSObject* WrapObject(JSContext* aCx,
39 JS::Handle<JSObject*> aGivenProto) override;
41 bool Charging() const;
43 double ChargingTime() const;
45 double DischargingTime() const;
47 double Level() const;
49 IMPL_EVENT_HANDLER(chargingchange)
50 IMPL_EVENT_HANDLER(chargingtimechange)
51 IMPL_EVENT_HANDLER(dischargingtimechange)
52 IMPL_EVENT_HANDLER(levelchange)
54 private:
55 /**
56 * Update the battery information stored in the battery manager object using
57 * a battery information object.
59 void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
61 /**
62 * Represents the battery level, ranging from 0.0 (dead or removed?)
63 * to 1.0 (fully charged)
65 double mLevel;
66 bool mCharging;
67 /**
68 * Represents the discharging time or the charging time, depending on the
69 * current battery status (charging or not).
71 double mRemainingTime;
74 } // namespace dom::battery
75 } // namespace mozilla
77 #endif // mozilla_dom_battery_BatteryManager_h