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
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2018-08-13 04:57:50 +03:00
|
|
|
#include "mozilla/HalBatteryInformation.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
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,
|
2018-08-13 04:57:50 +03:00
|
|
|
public hal::BatteryObserver {
|
2011-11-02 19:01:32 +04:00
|
|
|
public:
|
2016-01-30 20:05:36 +03:00
|
|
|
explicit BatteryManager(nsPIDOMWindowInner* 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
|
|
|
|
*/
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const { return GetOwner(); }
|
2013-02-05 16:54:49 +04:00
|
|
|
|
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
|
|
|
|
2015-08-21 13:29:25 +03:00
|
|
|
bool Charging() const;
|
2013-02-05 16:54:49 +04:00
|
|
|
|
|
|
|
double ChargingTime() const;
|
|
|
|
|
|
|
|
double DischargingTime() const;
|
|
|
|
|
2015-08-21 13:29:25 +03:00
|
|
|
double Level() const;
|
2013-02-05 16:54:49 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-08-10 23:20:37 +03:00
|
|
|
/**
|
|
|
|
* Represents the battery level, ranging from 0.0 (dead or removed?)
|
|
|
|
* to 1.0 (fully charged)
|
|
|
|
*/
|
2011-11-09 12:56:52 +04:00
|
|
|
double mLevel;
|
|
|
|
bool mCharging;
|
2011-11-09 12:58:18 +04:00
|
|
|
/**
|
2015-08-10 23:20:37 +03:00
|
|
|
* Represents the discharging time or the charging time, depending on the
|
2011-11-09 12:58:18 +04:00
|
|
|
* 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
|