native_widget_mac_event_monitor.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_VIEWS_COCOA_NATIVE_WIDGET_MAC_EVENT_MONITOR_H_
  5. #define UI_VIEWS_COCOA_NATIVE_WIDGET_MAC_EVENT_MONITOR_H_
  6. #include "base/callback_helpers.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "ui/views/views_export.h"
  10. namespace ui {
  11. class Event;
  12. } // namespace ui
  13. namespace views {
  14. class NativeWidgetMacNSWindowHost;
  15. // A class for event monitoring. This will create a NSEvent local monitor in
  16. // for this widget (in this process or in a remote process). The monitor will
  17. // call back through the Client interface.
  18. class VIEWS_EXPORT NativeWidgetMacEventMonitor {
  19. public:
  20. class Client {
  21. public:
  22. // Called for every observed NSEvent. If this client handles the event,
  23. // it should set `event_handled` to true. The initial value of
  24. // `event_handled` will be true if another client handled this event.
  25. virtual void NativeWidgetMacEventMonitorOnEvent(ui::Event* event,
  26. bool* event_handled) = 0;
  27. };
  28. ~NativeWidgetMacEventMonitor();
  29. private:
  30. friend class NativeWidgetMacNSWindowHost;
  31. explicit NativeWidgetMacEventMonitor(Client* client);
  32. const raw_ptr<Client> client_;
  33. // Scoped closure runner that will unregister `this` from its
  34. // NativeWidgetMacNSWindowHost when `this` is destroyed.
  35. base::ScopedClosureRunner remove_closure_runner_;
  36. };
  37. } // namespace views
  38. #endif // UI_VIEWS_COCOA_NATIVE_WIDGET_MAC_EVENT_MONITOR_H_