dom/battery/BatteryManager.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef mozilla_dom_battery_BatteryManager_h
michael@0 7 #define mozilla_dom_battery_BatteryManager_h
michael@0 8
michael@0 9 #include "Types.h"
michael@0 10 #include "mozilla/DOMEventTargetHelper.h"
michael@0 11 #include "mozilla/Observer.h"
michael@0 12 #include "nsCycleCollectionParticipant.h"
michael@0 13
michael@0 14 class nsPIDOMWindow;
michael@0 15 class nsIScriptContext;
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18
michael@0 19 namespace hal {
michael@0 20 class BatteryInformation;
michael@0 21 } // namespace hal
michael@0 22
michael@0 23 namespace dom {
michael@0 24 namespace battery {
michael@0 25
michael@0 26 class BatteryManager : public DOMEventTargetHelper
michael@0 27 , public BatteryObserver
michael@0 28 {
michael@0 29 public:
michael@0 30 BatteryManager(nsPIDOMWindow* aWindow);
michael@0 31
michael@0 32 void Init();
michael@0 33 void Shutdown();
michael@0 34
michael@0 35 // For IObserver.
michael@0 36 void Notify(const hal::BatteryInformation& aBatteryInfo);
michael@0 37
michael@0 38 /**
michael@0 39 * Returns whether the battery api is supported (ie. not disabled by the user)
michael@0 40 * @return whether the battery api is supported.
michael@0 41 */
michael@0 42 static bool HasSupport();
michael@0 43
michael@0 44 /**
michael@0 45 * WebIDL Interface
michael@0 46 */
michael@0 47
michael@0 48 nsPIDOMWindow* GetParentObject() const
michael@0 49 {
michael@0 50 return GetOwner();
michael@0 51 }
michael@0 52
michael@0 53 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 54
michael@0 55 bool Charging() const
michael@0 56 {
michael@0 57 return mCharging;
michael@0 58 }
michael@0 59
michael@0 60 double ChargingTime() const;
michael@0 61
michael@0 62 double DischargingTime() const;
michael@0 63
michael@0 64 double Level() const
michael@0 65 {
michael@0 66 return mLevel;
michael@0 67 }
michael@0 68
michael@0 69 IMPL_EVENT_HANDLER(chargingchange)
michael@0 70 IMPL_EVENT_HANDLER(chargingtimechange)
michael@0 71 IMPL_EVENT_HANDLER(dischargingtimechange)
michael@0 72 IMPL_EVENT_HANDLER(levelchange)
michael@0 73
michael@0 74 private:
michael@0 75 /**
michael@0 76 * Update the battery information stored in the battery manager object using
michael@0 77 * a battery information object.
michael@0 78 */
michael@0 79 void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
michael@0 80
michael@0 81 double mLevel;
michael@0 82 bool mCharging;
michael@0 83 /**
michael@0 84 * Represents the discharging time or the charging time, dpending on the
michael@0 85 * current battery status (charging or not).
michael@0 86 */
michael@0 87 double mRemainingTime;
michael@0 88 };
michael@0 89
michael@0 90 } // namespace battery
michael@0 91 } // namespace dom
michael@0 92 } // namespace mozilla
michael@0 93
michael@0 94 #endif // mozilla_dom_battery_BatteryManager_h

mercurial