dom/battery/BatteryManager.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/battery/BatteryManager.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_dom_battery_BatteryManager_h
    1.10 +#define mozilla_dom_battery_BatteryManager_h
    1.11 +
    1.12 +#include "Types.h"
    1.13 +#include "mozilla/DOMEventTargetHelper.h"
    1.14 +#include "mozilla/Observer.h"
    1.15 +#include "nsCycleCollectionParticipant.h"
    1.16 +
    1.17 +class nsPIDOMWindow;
    1.18 +class nsIScriptContext;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +
    1.22 +namespace hal {
    1.23 +class BatteryInformation;
    1.24 +} // namespace hal
    1.25 +
    1.26 +namespace dom {
    1.27 +namespace battery {
    1.28 +
    1.29 +class BatteryManager : public DOMEventTargetHelper
    1.30 +                     , public BatteryObserver
    1.31 +{
    1.32 +public:
    1.33 +  BatteryManager(nsPIDOMWindow* aWindow);
    1.34 +
    1.35 +  void Init();
    1.36 +  void Shutdown();
    1.37 +
    1.38 +  // For IObserver.
    1.39 +  void Notify(const hal::BatteryInformation& aBatteryInfo);
    1.40 +
    1.41 +  /**
    1.42 +   * Returns whether the battery api is supported (ie. not disabled by the user)
    1.43 +   * @return whether the battery api is supported.
    1.44 +   */
    1.45 +  static bool HasSupport();
    1.46 +
    1.47 +  /**
    1.48 +   * WebIDL Interface
    1.49 +   */
    1.50 +
    1.51 +  nsPIDOMWindow* GetParentObject() const
    1.52 +  {
    1.53 +     return GetOwner();
    1.54 +  }
    1.55 +
    1.56 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.57 +
    1.58 +  bool Charging() const
    1.59 +  {
    1.60 +    return mCharging;
    1.61 +  }
    1.62 +
    1.63 +  double ChargingTime() const;
    1.64 +
    1.65 +  double DischargingTime() const;
    1.66 +
    1.67 +  double Level() const
    1.68 +  {
    1.69 +    return mLevel;
    1.70 +  }
    1.71 +
    1.72 +  IMPL_EVENT_HANDLER(chargingchange)
    1.73 +  IMPL_EVENT_HANDLER(chargingtimechange)
    1.74 +  IMPL_EVENT_HANDLER(dischargingtimechange)
    1.75 +  IMPL_EVENT_HANDLER(levelchange)
    1.76 +
    1.77 +private:
    1.78 +  /**
    1.79 +   * Update the battery information stored in the battery manager object using
    1.80 +   * a battery information object.
    1.81 +   */
    1.82 +  void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
    1.83 +
    1.84 +  double mLevel;
    1.85 +  bool   mCharging;
    1.86 +  /**
    1.87 +   * Represents the discharging time or the charging time, dpending on the
    1.88 +   * current battery status (charging or not).
    1.89 +   */
    1.90 +  double mRemainingTime;
    1.91 +};
    1.92 +
    1.93 +} // namespace battery
    1.94 +} // namespace dom
    1.95 +} // namespace mozilla
    1.96 +
    1.97 +#endif // mozilla_dom_battery_BatteryManager_h

mercurial