event_monitor.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2014 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_EVENT_MONITOR_H_
  5. #define UI_VIEWS_EVENT_MONITOR_H_
  6. #include <memory>
  7. #include <set>
  8. #include "ui/events/event_observer.h"
  9. #include "ui/events/types/event_type.h"
  10. #include "ui/gfx/geometry/point.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. #include "ui/views/views_export.h"
  13. namespace views {
  14. // RAII-style class that forwards events matching the specified |types| to
  15. // |event_observer| before they are dispatched to the intended target.
  16. // EventObservers cannot modify events nor alter dispatch.
  17. class VIEWS_EXPORT EventMonitor {
  18. public:
  19. virtual ~EventMonitor() = default;
  20. // Create an instance for monitoring application events. This includes all
  21. // events on ChromeOS, but only events targeting Chrome on desktop platforms.
  22. // |context| is used to determine where to observe events from.
  23. // |context| may be destroyed before the EventMonitor.
  24. static std::unique_ptr<EventMonitor> CreateApplicationMonitor(
  25. ui::EventObserver* event_observer,
  26. gfx::NativeWindow context,
  27. const std::set<ui::EventType>& types);
  28. // Create an instance for monitoring events on a specific window.
  29. // The EventMonitor instance must be destroyed before |target_window|.
  30. static std::unique_ptr<EventMonitor> CreateWindowMonitor(
  31. ui::EventObserver* event_observer,
  32. gfx::NativeWindow target_window,
  33. const std::set<ui::EventType>& types);
  34. // Returns the last recorded mouse event location in screen coordinates.
  35. virtual gfx::Point GetLastMouseLocation() = 0;
  36. };
  37. } // namespace views
  38. #endif // UI_VIEWS_EVENT_MONITOR_H_