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. 4 5 #include "ui/events/event_targeter.h" 6 7 #include "ui/events/event.h" 8 #include "ui/events/event_target.h" 9 #include "ui/events/event_target_iterator.h" 10 11 namespace ui { 12 13 EventTargeter::~EventTargeter() { 14 } 15 16 EventTarget* EventTargeter::FindTargetForEvent(EventTarget* root, 17 Event* event) { 18 if (event->IsMouseEvent() || 19 event->IsScrollEvent() || 20 event->IsTouchEvent() || 21 event->IsGestureEvent()) { 22 return FindTargetForLocatedEvent(root, 23 static_cast<LocatedEvent*>(event)); 24 } 25 return root; 26 } 27 28 EventTarget* EventTargeter::FindTargetForLocatedEvent(EventTarget* root, 29 LocatedEvent* event) { 30 scoped_ptr<EventTargetIterator> iter = root->GetChildIterator(); 31 if (iter) { 32 EventTarget* target = root; 33 EventTarget* child = NULL; 34 while ((child = iter->GetNextTarget())) { 35 if (!SubtreeShouldBeExploredForEvent(child, *event)) 36 continue; 37 target->ConvertEventToTarget(child, event); 38 EventTargeter* targeter = child->GetEventTargeter(); 39 EventTarget* child_target = targeter ? 40 targeter->FindTargetForLocatedEvent(child, event) : 41 FindTargetForLocatedEvent(child, event); 42 if (child_target) 43 return child_target; 44 target = child; 45 } 46 target->ConvertEventToTarget(root, event); 47 } 48 return root->CanAcceptEvent(*event) ? root : NULL; 49 } 50 51 bool EventTargeter::SubtreeShouldBeExploredForEvent(EventTarget* target, 52 const LocatedEvent& event) { 53 return true; 54 } 55 56 } // namespace ui 57