| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Samsung Electronics | |
| 3 * | |
| 4 * This library is free software; you can redistribute it and/or | |
| 5 * modify it under the terms of the GNU Library General Public | |
| 6 * License as published by the Free Software Foundation; either | |
| 7 * version 2 of the License, or (at your option) any later version. | |
| 8 * | |
| 9 * This library is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 * Library General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU Library General Public License | |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 17 * Boston, MA 02110-1301, USA. | |
| 18 */ | |
| 19 | |
| 20 #ifndef BatteryManager_h | |
| 21 #define BatteryManager_h | |
| 22 | |
| 23 #if ENABLE(BATTERY_STATUS) | |
| 24 | |
| 25 #include "core/dom/ActiveDOMObject.h" | |
| 26 #include "core/dom/EventTarget.h" | |
| 27 #include "modules/battery/BatteryStatus.h" | |
| 28 | |
| 29 namespace WebCore { | |
| 30 | |
| 31 class BatteryController; | |
| 32 class Navigator; | |
| 33 class ScriptExecutionContext; | |
| 34 | |
| 35 class BatteryManager : public ActiveDOMObject, public RefCounted<BatteryManager>
, public EventTarget { | |
| 36 public: | |
| 37 virtual ~BatteryManager(); | |
| 38 static PassRefPtr<BatteryManager> create(Navigator*); | |
| 39 | |
| 40 // EventTarget implementation. | |
| 41 virtual const WTF::AtomicString& interfaceName() const { return eventNames()
.interfaceForBatteryManager; } | |
| 42 virtual ScriptExecutionContext* scriptExecutionContext() const { return Acti
veDOMObject::scriptExecutionContext(); } | |
| 43 | |
| 44 bool charging(); | |
| 45 double chargingTime(); | |
| 46 double dischargingTime(); | |
| 47 double level(); | |
| 48 | |
| 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange); | |
| 50 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange); | |
| 51 DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange); | |
| 52 DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange); | |
| 53 | |
| 54 void didChangeBatteryStatus(PassRefPtr<Event>, PassRefPtr<BatteryStatus>); | |
| 55 void batteryControllerDestroyed() { m_batteryController = 0; } | |
| 56 | |
| 57 using RefCounted<BatteryManager>::ref; | |
| 58 using RefCounted<BatteryManager>::deref; | |
| 59 | |
| 60 // ActiveDOMObject implementation. | |
| 61 virtual bool canSuspend() const { return true; } | |
| 62 virtual void suspend(ReasonForSuspension); | |
| 63 virtual void resume(); | |
| 64 virtual void stop(); | |
| 65 | |
| 66 protected: | |
| 67 virtual EventTargetData* eventTargetData() { return &m_eventTargetData; } | |
| 68 virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData
; } | |
| 69 | |
| 70 private: | |
| 71 explicit BatteryManager(Navigator*); | |
| 72 | |
| 73 // EventTarget implementation. | |
| 74 virtual void refEventTarget() { ref(); } | |
| 75 virtual void derefEventTarget() { deref(); } | |
| 76 | |
| 77 BatteryController* m_batteryController; | |
| 78 EventTargetData m_eventTargetData; | |
| 79 RefPtr<BatteryStatus> m_batteryStatus; | |
| 80 }; | |
| 81 | |
| 82 } | |
| 83 | |
| 84 #endif // BATTERY_STATUS | |
| 85 #endif // BatteryManager_h | |
| 86 | |
| OLD | NEW |