2011-11-02 08:01:32 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-02 08:01:32 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_battery_BatteryManager_h
|
|
|
|
#define mozilla_dom_battery_BatteryManager_h
|
|
|
|
|
|
|
|
#include "nsIDOMBatteryManager.h"
|
2012-02-07 18:53:33 -08:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2011-11-02 08:01:32 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2011-11-02 08:27:06 -07:00
|
|
|
#include "mozilla/Observer.h"
|
|
|
|
#include "Types.h"
|
2012-02-07 18:53:33 -08:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2011-11-02 08:01:32 -07:00
|
|
|
|
2011-11-19 02:37:21 -08:00
|
|
|
class nsPIDOMWindow;
|
|
|
|
class nsIScriptContext;
|
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
namespace mozilla {
|
2011-11-02 08:27:06 -07:00
|
|
|
|
|
|
|
namespace hal {
|
|
|
|
class BatteryInformation;
|
|
|
|
} // namespace hal
|
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
namespace dom {
|
|
|
|
namespace battery {
|
|
|
|
|
2012-02-07 18:53:33 -08:00
|
|
|
class BatteryManager : public nsDOMEventTargetHelper
|
2012-07-05 03:05:09 -07:00
|
|
|
, public nsIDOMBatteryManager
|
2011-11-02 08:27:06 -07:00
|
|
|
, public BatteryObserver
|
2011-11-02 08:01:32 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-07-05 03:05:09 -07:00
|
|
|
NS_DECL_NSIDOMBATTERYMANAGER
|
2012-02-07 18:53:33 -08:00
|
|
|
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
|
2011-11-02 08:01:32 -07:00
|
|
|
|
|
|
|
BatteryManager();
|
|
|
|
|
2012-03-12 17:56:07 -07:00
|
|
|
void Init(nsPIDOMWindow *aWindow);
|
2011-11-02 08:27:06 -07:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// For IObserver.
|
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BatteryManager,
|
2012-02-07 18:53:33 -08:00
|
|
|
nsDOMEventTargetHelper)
|
2011-11-02 08:01:32 -07:00
|
|
|
|
2011-11-03 16:31:32 -07:00
|
|
|
/**
|
|
|
|
* Returns whether the battery api is supported (ie. not disabled by the user)
|
|
|
|
* @return whether the battery api is supported.
|
|
|
|
*/
|
|
|
|
static bool HasSupport();
|
|
|
|
|
|
|
|
|
2011-11-02 08:01:32 -07:00
|
|
|
private:
|
2011-11-02 08:27:06 -07:00
|
|
|
/**
|
|
|
|
* Update the battery information stored in the battery manager object using
|
|
|
|
* a battery information object.
|
|
|
|
*/
|
|
|
|
void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
|
|
|
|
|
2011-11-09 00:56:52 -08:00
|
|
|
double mLevel;
|
|
|
|
bool mCharging;
|
2011-11-09 00:58:18 -08:00
|
|
|
/**
|
|
|
|
* Represents the discharging time or the charging time, dpending on the
|
|
|
|
* current battery status (charging or not).
|
|
|
|
*/
|
|
|
|
double mRemainingTime;
|
2011-11-02 08:01:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace battery
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_battery_BatteryManager_h
|