scoped_event_dispatcher.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_
  5. #define UI_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_
  6. #include "base/auto_reset.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "ui/events/events_export.h"
  9. namespace ui {
  10. class PlatformEventDispatcher;
  11. // A temporary PlatformEventDispatcher can be installed on a
  12. // PlatformEventSource that overrides all installed event dispatchers, and
  13. // always gets a chance to dispatch the event first. The PlatformEventSource
  14. // returns a ScopedEventDispatcher object in such cases. This
  15. // ScopedEventDispatcher object can be used to dispatch the event to any
  16. // previous overridden dispatcher. When this object is destroyed, it removes the
  17. // override-dispatcher, and restores the previous override-dispatcher.
  18. class EVENTS_EXPORT ScopedEventDispatcher {
  19. public:
  20. ScopedEventDispatcher(PlatformEventDispatcher** scoped_dispatcher,
  21. PlatformEventDispatcher* new_dispatcher);
  22. ScopedEventDispatcher(const ScopedEventDispatcher&) = delete;
  23. ScopedEventDispatcher& operator=(const ScopedEventDispatcher&) = delete;
  24. ~ScopedEventDispatcher();
  25. operator PlatformEventDispatcher*() const { return original_; }
  26. private:
  27. raw_ptr<PlatformEventDispatcher> original_;
  28. base::AutoReset<PlatformEventDispatcher*> restore_;
  29. };
  30. } // namespace ui
  31. #endif // UI_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_