1 // Copyright (c) 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_targeter.h"
7 #include "ui/events/event.h"
8 #include "ui/events/event_target.h"
9 #include "ui/events/event_target_iterator.h"
13 EventTargeter::~EventTargeter() {
16 EventTarget
* EventTargeter::FindTargetForEvent(EventTarget
* root
,
18 if (event
->IsMouseEvent() ||
19 event
->IsScrollEvent() ||
20 event
->IsTouchEvent() ||
21 event
->IsGestureEvent()) {
22 return FindTargetForLocatedEvent(root
,
23 static_cast<LocatedEvent
*>(event
));
28 EventTarget
* EventTargeter::FindTargetForLocatedEvent(EventTarget
* root
,
29 LocatedEvent
* event
) {
30 scoped_ptr
<EventTargetIterator
> iter
= root
->GetChildIterator();
32 EventTarget
* target
= root
;
33 for (EventTarget
* child
= iter
->GetNextTarget(); child
;
34 child
= iter
->GetNextTarget()) {
35 EventTargeter
* targeter
= child
->GetEventTargeter();
38 if (!targeter
->SubtreeShouldBeExploredForEvent(child
, *event
))
40 target
->ConvertEventToTarget(child
, event
);
42 EventTarget
* child_target
=
43 targeter
->FindTargetForLocatedEvent(child
, event
);
47 target
->ConvertEventToTarget(root
, event
);
49 return root
->CanAcceptEvent(*event
) ? root
: NULL
;
52 bool EventTargeter::SubtreeShouldBeExploredForEvent(EventTarget
* target
,
53 const LocatedEvent
& event
) {
54 return SubtreeCanAcceptEvent(target
, event
) &&
55 EventLocationInsideBounds(target
, event
);
58 EventTarget
* EventTargeter::FindNextBestTarget(EventTarget
* previous_target
,
63 bool EventTargeter::SubtreeCanAcceptEvent(EventTarget
* target
,
64 const LocatedEvent
& event
) const {
68 bool EventTargeter::EventLocationInsideBounds(EventTarget
* target
,
69 const LocatedEvent
& event
) const {