Index: ui/aura/window_targeter.cc |
diff --git a/ui/aura/window_targeter.cc b/ui/aura/window_targeter.cc |
index 7303e22bb0e00abefff87cdda6131b93f374d09d..f19d1819e2d0ac850977f87d967ac14bdd63028a 100644 |
--- a/ui/aura/window_targeter.cc |
+++ b/ui/aura/window_targeter.cc |
@@ -12,6 +12,7 @@ |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/aura/window_tree_host.h" |
#include "ui/events/event_target.h" |
+#include "ui/events/event_target_iterator.h" |
namespace aura { |
@@ -27,34 +28,19 @@ bool IsLocatedEvent(const ui::Event& event) { |
WindowTargeter::WindowTargeter() {} |
WindowTargeter::~WindowTargeter() {} |
-ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, |
- ui::Event* event) { |
+ui::EventTarget* WindowTargeter::FindTargetForLocatedEvent( |
+ ui::EventTarget* root, |
+ ui::LocatedEvent* event) { |
Window* window = static_cast<Window*>(root); |
- Window* target = event->IsKeyEvent() ? |
- FindTargetForKeyEvent(window, *static_cast<ui::KeyEvent*>(event)) : |
- static_cast<Window*>(EventTargeter::FindTargetForEvent(root, event)); |
- if (target && !window->parent() && !window->Contains(target)) { |
- // |window| is the root window, but |target| is not a descendent of |
- // |window|. So do not allow dispatching from here. Instead, dispatch the |
- // event through the WindowEventDispatcher that owns |target|. |
- aura::Window* new_root = target->GetRootWindow(); |
- if (IsLocatedEvent(*event)) { |
- // The event has been transformed to be in |target|'s coordinate system. |
- // But dispatching the event through the EventProcessor requires the event |
- // to be in the host's coordinate system. So, convert the event to be in |
- // the root's coordinate space, and then to the host's coordinate space by |
- // applying the host's transform. |
- ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); |
- located_event->ConvertLocationToTarget(target, new_root); |
- located_event->UpdateForRootTransform( |
- new_root->GetHost()->GetRootTransform()); |
+ if (!window->parent()) { |
+ Window* target = FindTargetInRootWindow(window, *event); |
+ if (target) { |
+ window->ConvertEventToTarget(target, event); |
+ return target; |
} |
- ignore_result( |
- new_root->GetHost()->event_processor()->OnEventFromSource(event)); |
- |
- target = NULL; |
} |
- return target; |
+ |
+ return EventTargeter::FindTargetForEvent(root, event); |
} |
bool WindowTargeter::SubtreeCanAcceptEvent( |
@@ -87,18 +73,42 @@ bool WindowTargeter::EventLocationInsideBounds( |
return gfx::Rect(window->bounds().size()).Contains(point); |
} |
-ui::EventTarget* WindowTargeter::FindTargetForLocatedEvent( |
- ui::EventTarget* root, |
- ui::LocatedEvent* event) { |
+ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, |
+ ui::Event* event) { |
Window* window = static_cast<Window*>(root); |
- if (!window->parent()) { |
- Window* target = FindTargetInRootWindow(window, *event); |
- if (target) { |
- window->ConvertEventToTarget(target, event); |
- return target; |
+ Window* target = |
+ event->IsKeyEvent() |
+ ? FindTargetForKeyEvent(window, *static_cast<ui::KeyEvent*>(event)) |
+ : FindTargetForNonKeyEvent(window, event); |
+ if (target && !window->parent() && !window->Contains(target)) { |
+ // |window| is the root window, but |target| is not a descendent of |
+ // |window|. So do not allow dispatching from here. Instead, dispatch the |
+ // event through the WindowEventDispatcher that owns |target|. |
+ aura::Window* new_root = target->GetRootWindow(); |
+ if (IsLocatedEvent(*event)) { |
+ // The event has been transformed to be in |target|'s coordinate system. |
+ // But dispatching the event through the EventProcessor requires the event |
+ // to be in the host's coordinate system. So, convert the event to be in |
+ // the root's coordinate space, and then to the host's coordinate space by |
+ // applying the host's transform. |
+ ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event); |
+ located_event->ConvertLocationToTarget(target, new_root); |
+ located_event->UpdateForRootTransform( |
+ new_root->GetHost()->GetRootTransform()); |
} |
+ ignore_result( |
+ new_root->GetHost()->event_processor()->OnEventFromSource(event)); |
+ |
+ target = NULL; |
} |
- return EventTargeter::FindTargetForLocatedEvent(root, event); |
+ return target; |
+} |
+ |
+bool WindowTargeter::SubtreeShouldBeExploredForEvent( |
+ ui::EventTarget* target, |
+ const ui::LocatedEvent& event) { |
+ return SubtreeCanAcceptEvent(target, event) && |
+ EventLocationInsideBounds(target, event); |
} |
Window* WindowTargeter::FindTargetForKeyEvent(Window* window, |
@@ -118,6 +128,18 @@ Window* WindowTargeter::FindTargetForKeyEvent(Window* window, |
return focused_window ? focused_window : window; |
} |
+Window* WindowTargeter::FindTargetForNonKeyEvent(Window* root_window, |
+ ui::Event* event) { |
+ ui::EventTarget* target = NULL; |
+ if (IsLocatedEvent(*event)) { |
+ target = FindTargetForLocatedEvent(root_window, |
+ static_cast<ui::LocatedEvent*>(event)); |
+ } else { |
+ target = EventTargeter::FindTargetForEvent(root_window, event); |
+ } |
+ return static_cast<Window*>(target); |
+} |
+ |
Window* WindowTargeter::FindTargetInRootWindow(Window* root_window, |
const ui::LocatedEvent& event) { |
DCHECK_EQ(root_window, root_window->GetRootWindow()); |