Bug 1943650 - Command-line --help output misformatted after --dbus-service. r=emilio
[gecko.git] / dom / media / mediacontrol / MediaControlKeyManager.h
blob9b029f3bc9bd7a93fc923c80053be68d14181f07
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_
6 #define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLKEYMANAGER_H_
8 #include "MediaControlKeySource.h"
9 #include "MediaEventSource.h"
10 #include "nsIObserver.h"
12 namespace mozilla::dom {
14 /**
15 * MediaControlKeyManager is a wrapper of MediaControlKeySource, which
16 * is used to manage creating and destroying a real media keys event source.
18 * It monitors the amount of the media controller in MediaService, and would
19 * create the event source when there is any existing controller and destroy it
20 * when there is no controller.
22 class MediaControlKeyManager final : public MediaControlKeySource,
23 public MediaControlKeyListener {
24 public:
25 NS_INLINE_DECL_REFCOUNTING(MediaControlKeyManager, override)
27 MediaControlKeyManager();
29 // MediaControlKeySource methods
30 bool Open() override;
31 void Close() override;
32 bool IsOpened() const override;
34 void SetPlaybackState(MediaSessionPlaybackState aState) override;
35 MediaSessionPlaybackState GetPlaybackState() const override;
37 // MediaControlKeyListener methods
38 void OnActionPerformed(const MediaControlAction& aAction) override;
40 void SetMediaMetadata(const MediaMetadataBase& aMetadata) override;
41 void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override;
42 void SetEnableFullScreen(bool aIsEnabled) override;
43 void SetEnablePictureInPictureMode(bool aIsEnabled) override;
44 void SetPositionState(const Maybe<PositionState>& aState) override;
46 private:
47 ~MediaControlKeyManager();
48 void Shutdown();
50 class Observer final : public nsIObserver {
51 public:
52 NS_DECL_ISUPPORTS
53 NS_DECL_NSIOBSERVER
54 explicit Observer(MediaControlKeyManager* aManager);
56 protected:
57 virtual ~Observer() = default;
59 MediaControlKeyManager* MOZ_OWNING_REF mManager;
61 RefPtr<Observer> mObserver;
62 void OnPreferenceChange();
64 bool StartMonitoringControlKeys();
65 void StopMonitoringControlKeys();
66 RefPtr<MediaControlKeySource> mEventSource;
67 MediaMetadataBase mMetadata;
68 nsTArray<MediaControlKey> mSupportedKeys;
71 } // namespace mozilla::dom
73 #endif