michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_battery_BatteryManager_h michael@0: #define mozilla_dom_battery_BatteryManager_h michael@0: michael@0: #include "Types.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/Observer.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: class nsPIDOMWindow; michael@0: class nsIScriptContext; michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace hal { michael@0: class BatteryInformation; michael@0: } // namespace hal michael@0: michael@0: namespace dom { michael@0: namespace battery { michael@0: michael@0: class BatteryManager : public DOMEventTargetHelper michael@0: , public BatteryObserver michael@0: { michael@0: public: michael@0: BatteryManager(nsPIDOMWindow* aWindow); michael@0: michael@0: void Init(); michael@0: void Shutdown(); michael@0: michael@0: // For IObserver. michael@0: void Notify(const hal::BatteryInformation& aBatteryInfo); michael@0: michael@0: /** michael@0: * Returns whether the battery api is supported (ie. not disabled by the user) michael@0: * @return whether the battery api is supported. michael@0: */ michael@0: static bool HasSupport(); michael@0: michael@0: /** michael@0: * WebIDL Interface michael@0: */ michael@0: michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: bool Charging() const michael@0: { michael@0: return mCharging; michael@0: } michael@0: michael@0: double ChargingTime() const; michael@0: michael@0: double DischargingTime() const; michael@0: michael@0: double Level() const michael@0: { michael@0: return mLevel; michael@0: } michael@0: michael@0: IMPL_EVENT_HANDLER(chargingchange) michael@0: IMPL_EVENT_HANDLER(chargingtimechange) michael@0: IMPL_EVENT_HANDLER(dischargingtimechange) michael@0: IMPL_EVENT_HANDLER(levelchange) michael@0: michael@0: private: michael@0: /** michael@0: * Update the battery information stored in the battery manager object using michael@0: * a battery information object. michael@0: */ michael@0: void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo); michael@0: michael@0: double mLevel; michael@0: bool mCharging; michael@0: /** michael@0: * Represents the discharging time or the charging time, dpending on the michael@0: * current battery status (charging or not). michael@0: */ michael@0: double mRemainingTime; michael@0: }; michael@0: michael@0: } // namespace battery michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_battery_BatteryManager_h