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/. */ 4 5 #ifndef WIDGET_COCOA_MEDIAHARDWAREKEYSEVENTSOURCEMAC_H_ 6 #define WIDGET_COCOA_MEDIAHARDWAREKEYSEVENTSOURCEMAC_H_ 7 8 #import <ApplicationServices/ApplicationServices.h> 9 #import <CoreFoundation/CoreFoundation.h> 10 11 #include "mozilla/dom/MediaControlKeySource.h" 12 #include "nsISupportsImpl.h" 13 14 namespace mozilla { 15 namespace widget { 16 17 class MediaHardwareKeysEventSourceMac final 18 : public mozilla::dom::MediaControlKeySource { 19 public: 20 NS_INLINE_DECL_REFCOUNTING(MediaHardwareKeysEventSourceMac, override) 21 MediaHardwareKeysEventSourceMac() = default; 22 23 static CGEventRef EventTapCallback(CGEventTapProxy proxy, CGEventType type, 24 CGEventRef event, void* refcon); 25 26 bool Open() override; 27 void Close() override; 28 bool IsOpened() const override; 29 30 // Currently we don't support showing supported keys on the touch bar. SetSupportedMediaKeys(const MediaKeysArray & aSupportedKeys)31 void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override {} 32 33 private: 34 ~MediaHardwareKeysEventSourceMac() = default; 35 36 bool StartEventTap(); 37 void StopEventTap(); 38 39 // They are used to intercept mac hardware media keys. 40 CFMachPortRef mEventTap = nullptr; 41 CFRunLoopSourceRef mEventTapSource = nullptr; 42 }; 43 44 } // namespace widget 45 } // namespace mozilla 46 47 #endif 48