Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / events / event_processor.cc
blobb508508aa06394c1ca274745fe89aa4f08668058
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"
10 namespace ui {
12 EventDispatchDetails EventProcessor::OnEventFromSource(Event* event) {
13 EventTarget* root = GetRootTarget();
14 CHECK(root);
15 EventTargeter* targeter = root->GetEventTargeter();
16 CHECK(targeter);
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;
34 while (target) {
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())
41 event->SetHandled();
44 if (details.dispatcher_destroyed)
45 return details;
47 if (details.target_destroyed || event->handled())
48 break;
50 target = targeter->FindNextBestTarget(target, event_to_dispatch);
53 OnEventProcessingFinished(event);
54 return details;
57 void EventProcessor::OnEventProcessingStarted(Event* event) {
60 void EventProcessor::OnEventProcessingFinished(Event* event) {
63 } // namespace ui