dom/battery/BatteryManager.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef mozilla_dom_battery_BatteryManager_h
     7 #define mozilla_dom_battery_BatteryManager_h
     9 #include "Types.h"
    10 #include "mozilla/DOMEventTargetHelper.h"
    11 #include "mozilla/Observer.h"
    12 #include "nsCycleCollectionParticipant.h"
    14 class nsPIDOMWindow;
    15 class nsIScriptContext;
    17 namespace mozilla {
    19 namespace hal {
    20 class BatteryInformation;
    21 } // namespace hal
    23 namespace dom {
    24 namespace battery {
    26 class BatteryManager : public DOMEventTargetHelper
    27                      , public BatteryObserver
    28 {
    29 public:
    30   BatteryManager(nsPIDOMWindow* aWindow);
    32   void Init();
    33   void Shutdown();
    35   // For IObserver.
    36   void Notify(const hal::BatteryInformation& aBatteryInfo);
    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();
    44   /**
    45    * WebIDL Interface
    46    */
    48   nsPIDOMWindow* GetParentObject() const
    49   {
    50      return GetOwner();
    51   }
    53   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    55   bool Charging() const
    56   {
    57     return mCharging;
    58   }
    60   double ChargingTime() const;
    62   double DischargingTime() const;
    64   double Level() const
    65   {
    66     return mLevel;
    67   }
    69   IMPL_EVENT_HANDLER(chargingchange)
    70   IMPL_EVENT_HANDLER(chargingtimechange)
    71   IMPL_EVENT_HANDLER(dischargingtimechange)
    72   IMPL_EVENT_HANDLER(levelchange)
    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);
    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 };
    90 } // namespace battery
    91 } // namespace dom
    92 } // namespace mozilla
    94 #endif // mozilla_dom_battery_BatteryManager_h

mercurial