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.
5 #include "ui/events/event_processor.h"
7 #include "ui/events/event_target.h"
8 #include "ui/events/event_targeter.h"
12 EventDispatchDetails
EventProcessor::OnEventFromSource(Event
* event
) {
13 EventTarget
* root
= GetRootTarget();
15 EventTargeter
* targeter
= root
->GetEventTargeter();
18 // If |event| is in the process of being dispatched or has already been
19 // dispatched, then dispatch a copy of the event instead.
20 bool dispatch_original_event
= event
->phase() == EP_PREDISPATCH
;
21 Event
* event_to_dispatch
= event
;
22 scoped_ptr
<Event
> event_copy
;
23 if (!dispatch_original_event
) {
24 event_copy
= Event::Clone(*event
);
25 event_to_dispatch
= event_copy
.get();
28 OnEventProcessingStarted(event_to_dispatch
);
29 EventTarget
* target
= NULL
;
30 if (!event_to_dispatch
->handled())
31 target
= targeter
->FindTargetForEvent(root
, event_to_dispatch
);
33 EventDispatchDetails details
;
35 details
= DispatchEvent(target
, event_to_dispatch
);
37 if (!dispatch_original_event
) {
38 if (event_to_dispatch
->stopped_propagation())
39 event
->StopPropagation();
40 else if (event_to_dispatch
->handled())
44 if (details
.dispatcher_destroyed
)
47 if (details
.target_destroyed
|| event
->handled())
50 target
= targeter
->FindNextBestTarget(target
, event_to_dispatch
);
53 OnEventProcessingFinished(event
);
57 void EventProcessor::OnEventProcessingStarted(Event
* event
) {
60 void EventProcessor::OnEventProcessingFinished(Event
* event
) {