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#include "ui/events/event_processor.h"
6
7#include "ui/events/event_target.h"
8#include "ui/events/event_targeter.h"
9
10namespace ui {
11
12EventDispatchDetails EventProcessor::OnEventFromSource(Event* event) {
13  EventTarget* root = GetRootTarget();
14  CHECK(root);
15  EventTargeter* targeter = root->GetEventTargeter();
16  CHECK(targeter);
17  PrepareEventForDispatch(event);
18
19  // If |event| is in the process of being dispatched or has already been
20  // dispatched, then dispatch a copy of the event instead.
21  bool dispatch_original_event = event->phase() == EP_PREDISPATCH;
22  Event* event_to_dispatch = event;
23  scoped_ptr<Event> event_copy;
24  if (!dispatch_original_event) {
25    event_copy = Event::Clone(*event);
26    event_to_dispatch = event_copy.get();
27  }
28
29  EventTarget* target = targeter->FindTargetForEvent(root, event_to_dispatch);
30  EventDispatchDetails details;
31  while (target) {
32    details = DispatchEvent(target, event_to_dispatch);
33
34    if (!dispatch_original_event) {
35      if (event_to_dispatch->stopped_propagation())
36        event->StopPropagation();
37      else if (event_to_dispatch->handled())
38        event->SetHandled();
39    }
40
41    if (details.dispatcher_destroyed)
42      return details;
43
44    if (details.target_destroyed || event->handled())
45      break;
46
47    target = targeter->FindNextBestTarget(target, event_to_dispatch);
48  }
49
50  OnEventProcessingFinished(event);
51  return details;
52}
53
54void EventProcessor::PrepareEventForDispatch(Event* event) {
55}
56
57void EventProcessor::OnEventProcessingFinished(Event* event) {
58}
59
60}  // namespace ui
61