[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 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 | |
| 5 | #ifndef UI_EVENTS_EVENT_PROCESSOR_H_ |
| 6 | #define UI_EVENTS_EVENT_PROCESSOR_H_ |
| 7 | |
Dave Tapuska | 1963fcc | 2017-09-25 22:50:42 | [diff] [blame] | 8 | #include "base/memory/weak_ptr.h" |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 9 | #include "ui/events/event_dispatcher.h" |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 10 | #include "ui/events/event_sink.h" |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 11 | #include "ui/events/event_source.h" |
| 12 | |
| 13 | namespace ui { |
| 14 | |
riajiang | 762dcf0 | 2017-03-03 06:23:55 | [diff] [blame] | 15 | class EventTargeter; |
| 16 | |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 17 | // EventProcessor inherits EventSink to receive an event from an EventSource |
| 18 | // and dispatches it to a tree of EventTargets. |
| 19 | class EVENTS_EXPORT EventProcessor : public EventDispatcherDelegate, |
| 20 | public EventSink { |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 21 | public: |
Dave Tapuska | 1963fcc | 2017-09-25 22:50:42 | [diff] [blame] | 22 | EventProcessor(); |
| 23 | ~EventProcessor() override; |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 24 | |
penghuang | 17134c6c | 2017-03-23 00:01:07 | [diff] [blame] | 25 | // EventSink overrides: |
| 26 | EventDispatchDetails OnEventFromSource(Event* event) override; |
| 27 | |
riajiang | 762dcf0 | 2017-03-03 06:23:55 | [diff] [blame] | 28 | // Returns the EventTarget with the right EventTargeter that we should use for |
| 29 | // dispatching this |event|. |
| 30 | virtual EventTarget* GetRootForEvent(Event* event) = 0; |
| 31 | |
| 32 | // If the root target returned by GetRootForEvent() does not have a |
| 33 | // targeter set, then the default targeter is used to find the target. |
| 34 | virtual EventTargeter* GetDefaultEventTargeter() = 0; |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 35 | |
[email protected] | 4c5d7c9 | 2013-12-13 17:17:39 | [diff] [blame] | 36 | protected: |
tdanderson | fb66d87 | 2014-09-30 22:15:35 | [diff] [blame] | 37 | // Invoked at the start of processing, before an EventTargeter is used to |
| 38 | // find the target of the event. If processing should not take place, marks |
| 39 | // |event| as handled. Otherwise updates |event| so that the targeter can |
| 40 | // operate correctly (e.g., it can be used to update the location of the |
| 41 | // event when dispatching from an EventSource in high-DPI) and updates any |
| 42 | // members in the event processor as necessary. |
| 43 | virtual void OnEventProcessingStarted(Event* event); |
tdanderson | a46326c | 2014-09-10 22:49:55 | [diff] [blame] | 44 | |
| 45 | // Invoked when the processing of |event| has finished (i.e., when no further |
| 46 | // dispatching of |event| will be performed by this EventProcessor). Note |
| 47 | // that the last target to which |event| was dispatched may have been |
| 48 | // destroyed. |
| 49 | virtual void OnEventProcessingFinished(Event* event); |
Dave Tapuska | 1963fcc | 2017-09-25 22:50:42 | [diff] [blame] | 50 | |
| 51 | private: |
Jeremy Roman | 0cd9a52 | 2019-07-15 15:34:17 | [diff] [blame] | 52 | base::WeakPtrFactory<EventProcessor> weak_ptr_factory_{this}; |
Dave Tapuska | 1963fcc | 2017-09-25 22:50:42 | [diff] [blame] | 53 | DISALLOW_COPY_AND_ASSIGN(EventProcessor); |
[email protected] | 7407bf3 | 2013-12-05 22:00:41 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // namespace ui |
| 57 | |
| 58 | #endif // UI_EVENTS_EVENT_PROCESSOR_H_ |