2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
|
2011-11-02 19:27:06 +04:00
|
|
|
#include "Types.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
#include "mozilla/Observer.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2011-11-02 19:01:32 +04:00
|
|
|
|
2011-11-19 14:37:21 +04:00
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
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 {
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class BatteryManager : public DOMEventTargetHelper
|
2011-11-02 19:27:06 +04:00
|
|
|
, public BatteryObserver
|
2011-11-02 19:01:32 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit 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.
|
2015-03-21 19:28:04 +03:00
|
|
|
void Notify(const hal::BatteryInformation& aBatteryInfo) override;
|
2011-11-02 19:27:06 +04:00
|
|
|
|
2011-11-04 03:31:32 +04:00
|
|
|
/**
|
2013-02-05 16:54:49 +04:00
|
|
|
* WebIDL Interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) 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
|