tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BatteryManager.h (2010B)


      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/. */
      6 
      7 #ifndef mozilla_dom_battery_BatteryManager_h
      8 #define mozilla_dom_battery_BatteryManager_h
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "mozilla/HalBatteryInformation.h"
     12 
     13 namespace mozilla {
     14 
     15 namespace hal {
     16 class BatteryInformation;
     17 }  // namespace hal
     18 
     19 namespace dom::battery {
     20 
     21 class BatteryManager final : public DOMEventTargetHelper,
     22                             public hal::BatteryObserver {
     23 public:
     24  explicit BatteryManager(nsPIDOMWindowInner* aWindow);
     25 
     26  void Init();
     27  void Shutdown();
     28 
     29  // For IObserver.
     30  void Notify(const hal::BatteryInformation& aBatteryInfo) override;
     31 
     32  /**
     33   * WebIDL Interface
     34   */
     35 
     36  nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
     37 
     38  JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     39 
     40  bool Charging() const;
     41 
     42  double ChargingTime() const;
     43 
     44  double DischargingTime() const;
     45 
     46  double Level() const;
     47 
     48  IMPL_EVENT_HANDLER(chargingchange)
     49  IMPL_EVENT_HANDLER(chargingtimechange)
     50  IMPL_EVENT_HANDLER(dischargingtimechange)
     51  IMPL_EVENT_HANDLER(levelchange)
     52 
     53 private:
     54  /**
     55   * Update the battery information stored in the battery manager object using
     56   * a battery information object.
     57   */
     58  void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
     59 
     60  /**
     61   * Represents the battery level, ranging from 0.0 (dead or removed?)
     62   * to 1.0 (fully charged)
     63   */
     64  double mLevel;
     65  bool mCharging;
     66  /**
     67   * Represents the discharging time or the charging time, depending on the
     68   * current battery status (charging or not).
     69   */
     70  double mRemainingTime;
     71 };
     72 
     73 }  // namespace dom::battery
     74 }  // namespace mozilla
     75 
     76 #endif  // mozilla_dom_battery_BatteryManager_h