event_source.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2013 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_EVENT_SOURCE_H_
  5. #define UI_EVENTS_EVENT_SOURCE_H_
  6. #include <list>
  7. #include <memory>
  8. #include <vector>
  9. #include "ui/events/event_dispatcher.h"
  10. #include "ui/events/event_rewriter.h"
  11. #include "ui/events/events_export.h"
  12. namespace ui {
  13. class Event;
  14. class EventSink;
  15. // EventSource receives events from the native platform (e.g. X11, win32 etc.)
  16. // and sends the events to an EventSink.
  17. class EVENTS_EXPORT EventSource {
  18. public:
  19. EventSource();
  20. EventSource(const EventSource&) = delete;
  21. EventSource& operator=(const EventSource&) = delete;
  22. virtual ~EventSource();
  23. virtual EventSink* GetEventSink() = 0;
  24. // Adds a rewriter to modify events before they are sent to the
  25. // EventSink. The rewriter must be explicitly removed from the
  26. // EventSource before the rewriter is destroyed. The EventSource
  27. // does not take ownership of the rewriter.
  28. void AddEventRewriter(EventRewriter* rewriter);
  29. void RemoveEventRewriter(EventRewriter* rewriter);
  30. // Sends the event through all rewriters and onto the source's EventSink.
  31. EventDispatchDetails SendEventToSink(const Event* event);
  32. // Send the event to the sink after rewriting; subclass overrides may queue
  33. // events before delivery, i.e. for the WindowService.
  34. virtual EventDispatchDetails DeliverEventToSink(Event* event);
  35. protected:
  36. // Sends the event through the rewriters and onto the source's EventSink.
  37. // If |rewriter| is valid, |event| is only sent to the subsequent rewriters.
  38. // This is used for asynchronous reposting of events processed by |rewriter|.
  39. // TODO(kpschoedel): Remove along with old EventRewriter API.
  40. EventDispatchDetails SendEventToSinkFromRewriter(
  41. const Event* event,
  42. const EventRewriter* rewriter);
  43. private:
  44. // Implementation of EventRewriterContinuation. No details need to be
  45. // visible outside of event_source.cc.
  46. class EventRewriterContinuationImpl;
  47. // It's sufficient to have one EventRewriterContinuationImpl for each
  48. // registered EventRewriter, so a list of them also serves as a list
  49. // of registered rewriters.
  50. typedef std::list<std::unique_ptr<EventRewriterContinuationImpl>>
  51. EventRewriterList;
  52. // Returns the EventRewriterContinuation for a given EventRewriter,
  53. // or |rewriter_list_.end()| if the rewriter is not registered.
  54. EventRewriterList::iterator FindContinuation(const EventRewriter* rewriter);
  55. EventRewriterList rewriter_list_;
  56. friend class EventRewriter; // TODO(kpschoedel): Remove along with old API.
  57. friend class EventSourceTestApi;
  58. };
  59. } // namespace ui
  60. #endif // UI_EVENTS_EVENT_SOURCE_H_