blob: 4e5fbafc5f497bb3df2c47bc80e7a158dfe6642a [file] [log] [blame]
[email protected]7407bf32013-12-05 22:00:411// 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 Tapuska1963fcc2017-09-25 22:50:428#include "base/memory/weak_ptr.h"
[email protected]7407bf32013-12-05 22:00:419#include "ui/events/event_dispatcher.h"
penghuang17134c6c2017-03-23 00:01:0710#include "ui/events/event_sink.h"
[email protected]7407bf32013-12-05 22:00:4111#include "ui/events/event_source.h"
12
13namespace ui {
14
riajiang762dcf02017-03-03 06:23:5515class EventTargeter;
16
penghuang17134c6c2017-03-23 00:01:0717// EventProcessor inherits EventSink to receive an event from an EventSource
18// and dispatches it to a tree of EventTargets.
19class EVENTS_EXPORT EventProcessor : public EventDispatcherDelegate,
20 public EventSink {
[email protected]7407bf32013-12-05 22:00:4121 public:
Dave Tapuska1963fcc2017-09-25 22:50:4222 EventProcessor();
23 ~EventProcessor() override;
[email protected]7407bf32013-12-05 22:00:4124
penghuang17134c6c2017-03-23 00:01:0725 // EventSink overrides:
26 EventDispatchDetails OnEventFromSource(Event* event) override;
27
riajiang762dcf02017-03-03 06:23:5528 // 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]7407bf32013-12-05 22:00:4135
[email protected]4c5d7c92013-12-13 17:17:3936 protected:
tdandersonfb66d872014-09-30 22:15:3537 // 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);
tdandersona46326c2014-09-10 22:49:5544
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 Tapuska1963fcc2017-09-25 22:50:4250
51 private:
Jeremy Roman0cd9a522019-07-15 15:34:1752 base::WeakPtrFactory<EventProcessor> weak_ptr_factory_{this};
Dave Tapuska1963fcc2017-09-25 22:50:4253 DISALLOW_COPY_AND_ASSIGN(EventProcessor);
[email protected]7407bf32013-12-05 22:00:4154};
55
56} // namespace ui
57
58#endif // UI_EVENTS_EVENT_PROCESSOR_H_