2011-11-02 19:01:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 19:01:32 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_dom_battery_BatteryManager_h
|
|
|
|
#define mozilla_dom_battery_BatteryManager_h
|
|
|
|
|
2012-02-08 06:53:33 +04:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2011-11-02 19:01:32 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2011-11-02 19:27:06 +04:00
|
|
|
#include "mozilla/Observer.h"
|
|
|
|
#include "Types.h"
|
2012-02-08 06:53:33 +04:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2011-11-02 19:01:32 +04:00
|
|
|
|
2011-11-19 14:37:21 +04:00
|
|
|
class nsPIDOMWindow;
|
|
|
|
class nsIScriptContext;
|
|
|
|
|
2011-11-02 19:01:32 +04:00
|
|
|
namespace mozilla {
|
2011-11-02 19:27:06 +04:00
|
|
|
|
|
|
|
namespace hal {
|
|
|
|
class BatteryInformation;
|
|
|
|
} // namespace hal
|
|
|
|
|
2011-11-02 19:01:32 +04:00
|
|
|
namespace dom {
|
|
|
|
namespace battery {
|
|
|
|
|
2012-02-08 06:53:33 +04:00
|
|
|
class BatteryManager : public nsDOMEventTargetHelper
|
2011-11-02 19:27:06 +04:00
|
|
|
, public BatteryObserver
|
2011-11-02 19:01:32 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-01-07 06:53:23 +04:00
|
|
|
BatteryManager(nsPIDOMWindow* aWindow);
|
2011-11-02 19:01:32 +04:00
|
|
|
|
2014-01-07 06:53:23 +04:00
|
|
|
void Init();
|
2011-11-02 19:27:06 +04:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// For IObserver.
|
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo);
|
|
|
|
|
2011-11-04 03:31:32 +04:00
|
|
|
/**
|
|
|
|
* Returns whether the battery api is supported (ie. not disabled by the user)
|
|
|
|
* @return whether the battery api is supported.
|
|
|
|
*/
|
|
|
|
static bool HasSupport();
|
|
|
|
|
2013-02-05 16:54:49 +04:00
|
|
|
/**
|
|
|
|
* WebIDL Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
2013-04-25 20:29:54 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2013-02-05 16:54:49 +04:00
|
|
|
|
|
|
|
bool Charging() const
|
|
|
|
{
|
|
|
|
return mCharging;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ChargingTime() const;
|
|
|
|
|
|
|
|
double DischargingTime() const;
|
|
|
|
|
|
|
|
double Level() const
|
|
|
|
{
|
|
|
|
return mLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(chargingchange)
|
|
|
|
IMPL_EVENT_HANDLER(chargingtimechange)
|
|
|
|
IMPL_EVENT_HANDLER(dischargingtimechange)
|
|
|
|
IMPL_EVENT_HANDLER(levelchange)
|
2011-11-04 03:31:32 +04:00
|
|
|
|
2011-11-02 19:01:32 +04:00
|
|
|
private:
|
2011-11-02 19:27:06 +04: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 12:56:52 +04:00
|
|
|
double mLevel;
|
|
|
|
bool mCharging;
|
2011-11-09 12:58:18 +04:00
|
|
|
/**
|
|
|
|
* Represents the discharging time or the charging time, dpending on the
|
|
|
|
* current battery status (charging or not).
|
|
|
|
*/
|
|
|
|
double mRemainingTime;
|
2011-11-02 19:01:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace battery
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_battery_BatteryManager_h
|