Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/battery/BatteryManager.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_battery_BatteryManager_h
8
#define mozilla_dom_battery_BatteryManager_h
9
10
#include "mozilla/DOMEventTargetHelper.h"
11
#include "mozilla/HalBatteryInformation.h"
12
#include "nsCycleCollectionParticipant.h"
13
14
namespace mozilla {
15
16
namespace hal {
17
class BatteryInformation;
18
} // namespace hal
19
20
namespace dom {
21
namespace battery {
22
23
class BatteryManager : public DOMEventTargetHelper
24
                     , public hal::BatteryObserver
25
{
26
public:
27
  explicit BatteryManager(nsPIDOMWindowInner* aWindow);
28
29
  void Init();
30
  void Shutdown();
31
32
  // For IObserver.
33
  void Notify(const hal::BatteryInformation& aBatteryInfo) override;
34
35
  /**
36
   * WebIDL Interface
37
   */
38
39
  nsPIDOMWindowInner* GetParentObject() const
40
0
  {
41
0
     return GetOwner();
42
0
  }
43
44
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
45
46
  bool Charging() const;
47
48
  double ChargingTime() const;
49
50
  double DischargingTime() const;
51
52
  double Level() const;
53
54
  IMPL_EVENT_HANDLER(chargingchange)
55
  IMPL_EVENT_HANDLER(chargingtimechange)
56
  IMPL_EVENT_HANDLER(dischargingtimechange)
57
  IMPL_EVENT_HANDLER(levelchange)
58
59
private:
60
  /**
61
   * Update the battery information stored in the battery manager object using
62
   * a battery information object.
63
   */
64
  void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
65
66
  /**
67
   * Represents the battery level, ranging from 0.0 (dead or removed?)
68
   * to 1.0 (fully charged)
69
   */
70
  double mLevel;
71
  bool   mCharging;
72
  /**
73
   * Represents the discharging time or the charging time, depending on the
74
   * current battery status (charging or not).
75
   */
76
  double mRemainingTime;
77
};
78
79
} // namespace battery
80
} // namespace dom
81
} // namespace mozilla
82
83
#endif // mozilla_dom_battery_BatteryManager_h