|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_dom_FMRadio_h |
|
7 #define mozilla_dom_FMRadio_h |
|
8 |
|
9 #include "AudioChannelAgent.h" |
|
10 #include "FMRadioCommon.h" |
|
11 #include "mozilla/DOMEventTargetHelper.h" |
|
12 #include "mozilla/HalTypes.h" |
|
13 #include "nsCycleCollectionParticipant.h" |
|
14 #include "nsWeakReference.h" |
|
15 |
|
16 class nsPIDOMWindow; |
|
17 class nsIScriptContext; |
|
18 |
|
19 BEGIN_FMRADIO_NAMESPACE |
|
20 |
|
21 class DOMRequest; |
|
22 |
|
23 class FMRadio MOZ_FINAL : public DOMEventTargetHelper |
|
24 , public hal::SwitchObserver |
|
25 , public FMRadioEventObserver |
|
26 , public nsSupportsWeakReference |
|
27 , public nsIAudioChannelAgentCallback |
|
28 , public nsIDOMEventListener |
|
29 |
|
30 { |
|
31 friend class FMRadioRequest; |
|
32 |
|
33 public: |
|
34 FMRadio(); |
|
35 |
|
36 NS_DECL_ISUPPORTS_INHERITED |
|
37 NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK |
|
38 |
|
39 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) |
|
40 |
|
41 void Init(nsPIDOMWindow *aWindow); |
|
42 void Shutdown(); |
|
43 |
|
44 /* hal::SwitchObserver */ |
|
45 virtual void Notify(const hal::SwitchEvent& aEvent) MOZ_OVERRIDE; |
|
46 /* FMRadioEventObserver */ |
|
47 virtual void Notify(const FMRadioEventType& aType) MOZ_OVERRIDE; |
|
48 |
|
49 nsPIDOMWindow* GetParentObject() const |
|
50 { |
|
51 return GetOwner(); |
|
52 } |
|
53 |
|
54 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
55 |
|
56 static bool Enabled(); |
|
57 |
|
58 bool AntennaAvailable() const; |
|
59 |
|
60 Nullable<double> GetFrequency() const; |
|
61 |
|
62 double FrequencyUpperBound() const; |
|
63 |
|
64 double FrequencyLowerBound() const; |
|
65 |
|
66 double ChannelWidth() const; |
|
67 |
|
68 already_AddRefed<DOMRequest> Enable(double aFrequency); |
|
69 |
|
70 already_AddRefed<DOMRequest> Disable(); |
|
71 |
|
72 already_AddRefed<DOMRequest> SetFrequency(double aFrequency); |
|
73 |
|
74 already_AddRefed<DOMRequest> SeekUp(); |
|
75 |
|
76 already_AddRefed<DOMRequest> SeekDown(); |
|
77 |
|
78 already_AddRefed<DOMRequest> CancelSeek(); |
|
79 |
|
80 IMPL_EVENT_HANDLER(enabled); |
|
81 IMPL_EVENT_HANDLER(disabled); |
|
82 IMPL_EVENT_HANDLER(antennaavailablechange); |
|
83 IMPL_EVENT_HANDLER(frequencychange); |
|
84 |
|
85 // nsIDOMEventListener |
|
86 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); |
|
87 |
|
88 private: |
|
89 ~FMRadio(); |
|
90 |
|
91 void SetCanPlay(bool aCanPlay); |
|
92 void EnableAudioChannelAgent(); |
|
93 |
|
94 hal::SwitchState mHeadphoneState; |
|
95 bool mAudioChannelAgentEnabled; |
|
96 bool mHasInternalAntenna; |
|
97 bool mIsShutdown; |
|
98 |
|
99 nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent; |
|
100 }; |
|
101 |
|
102 END_FMRADIO_NAMESPACE |
|
103 |
|
104 #endif // mozilla_dom_FMRadio_h |
|
105 |