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
= targeter
?
43 targeter
->FindTargetForLocatedEvent(child
, event
) :
44 FindTargetForLocatedEvent(child
, event
);
48 target
->ConvertEventToTarget(root
, event
);
50 return root
->CanAcceptEvent(*event
) ? root
: NULL
;
53 bool EventTargeter::SubtreeShouldBeExploredForEvent(EventTarget
* target
,
54 const LocatedEvent
& event
) {
55 return SubtreeCanAcceptEvent(target
, event
) &&
56 EventLocationInsideBounds(target
, event
);
59 EventTarget
* EventTargeter::FindNextBestTarget(EventTarget
* previous_target
,
64 bool EventTargeter::SubtreeCanAcceptEvent(EventTarget
* target
,
65 const LocatedEvent
& event
) const {
69 bool EventTargeter::EventLocationInsideBounds(EventTarget
* target
,
70 const LocatedEvent
& event
) const {