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/. */
6 #ifndef mozilla_dom_FMRadio_h
7 #define mozilla_dom_FMRadio_h
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"
17 class nsIScriptContext
;
19 BEGIN_FMRADIO_NAMESPACE
23 class FMRadio MOZ_FINAL
: public DOMEventTargetHelper
24 , public hal::SwitchObserver
25 , public FMRadioEventObserver
26 , public nsSupportsWeakReference
27 , public nsIAudioChannelAgentCallback
28 , public nsIDOMEventListener
31 friend class FMRadioRequest
;
36 NS_DECL_ISUPPORTS_INHERITED
37 NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
39 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper
)
41 void Init(nsPIDOMWindow
*aWindow
);
44 /* hal::SwitchObserver */
45 virtual void Notify(const hal::SwitchEvent
& aEvent
) MOZ_OVERRIDE
;
46 /* FMRadioEventObserver */
47 virtual void Notify(const FMRadioEventType
& aType
) MOZ_OVERRIDE
;
49 nsPIDOMWindow
* GetParentObject() const
54 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
56 static bool Enabled();
58 bool AntennaAvailable() const;
60 Nullable
<double> GetFrequency() const;
62 double FrequencyUpperBound() const;
64 double FrequencyLowerBound() const;
66 double ChannelWidth() const;
68 already_AddRefed
<DOMRequest
> Enable(double aFrequency
);
70 already_AddRefed
<DOMRequest
> Disable();
72 already_AddRefed
<DOMRequest
> SetFrequency(double aFrequency
);
74 already_AddRefed
<DOMRequest
> SeekUp();
76 already_AddRefed
<DOMRequest
> SeekDown();
78 already_AddRefed
<DOMRequest
> CancelSeek();
80 IMPL_EVENT_HANDLER(enabled
);
81 IMPL_EVENT_HANDLER(disabled
);
82 IMPL_EVENT_HANDLER(antennaavailablechange
);
83 IMPL_EVENT_HANDLER(frequencychange
);
85 // nsIDOMEventListener
86 NS_IMETHOD
HandleEvent(nsIDOMEvent
* aEvent
);
91 void SetCanPlay(bool aCanPlay
);
92 void EnableAudioChannelAgent();
94 hal::SwitchState mHeadphoneState
;
95 bool mAudioChannelAgentEnabled
;
96 bool mHasInternalAntenna
;
99 nsCOMPtr
<nsIAudioChannelAgent
> mAudioChannelAgent
;
102 END_FMRADIO_NAMESPACE
104 #endif // mozilla_dom_FMRadio_h