Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Unified Diff: ui/aura/window_targeter.cc

Issue 1119423003: Refactors away method implementations in ui::EventTargeter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactors away method implementations in ui::EventTargeter (moves tests to aura) Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/aura/window_targeter.cc
diff --git a/ui/aura/window_targeter.cc b/ui/aura/window_targeter.cc
index 7303e22bb0e00abefff87cdda6131b93f374d09d..cb0a1129c3afc3be83af99f36eb0e16a153bdde2 100644
--- a/ui/aura/window_targeter.cc
+++ b/ui/aura/window_targeter.cc
@@ -12,49 +12,25 @@
#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 {
-namespace {
-
-bool IsLocatedEvent(const ui::Event& event) {
- return event.IsMouseEvent() || event.IsTouchEvent() ||
- event.IsScrollEvent() || event.IsGestureEvent();
-}
-
-} // namespace
-
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 FindTargetForEventRecursively(window, event);
}
bool WindowTargeter::SubtreeCanAcceptEvent(
@@ -87,18 +63,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 (event->IsLocatedEvent()) {
+ // 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 +118,14 @@ Window* WindowTargeter::FindTargetForKeyEvent(Window* window,
return focused_window ? focused_window : window;
}
+Window* WindowTargeter::FindTargetForNonKeyEvent(Window* root_window,
+ ui::Event* event) {
+ if (!event->IsLocatedEvent())
+ return root_window;
+ return static_cast<Window*>(FindTargetForLocatedEvent(
+ root_window, static_cast<ui::LocatedEvent*>(event)));
+}
+
Window* WindowTargeter::FindTargetInRootWindow(Window* root_window,
const ui::LocatedEvent& event) {
DCHECK_EQ(root_window, root_window->GetRootWindow());
@@ -156,4 +164,30 @@ Window* WindowTargeter::FindTargetInRootWindow(Window* root_window,
return NULL;
}
+ui::EventTarget* WindowTargeter::FindTargetForEventRecursively(
+ Window* root_window,
+ ui::LocatedEvent* event) {
+ scoped_ptr<ui::EventTargetIterator> iter = root_window->GetChildIterator();
+ if (iter) {
+ ui::EventTarget* target = root_window;
+ for (ui::EventTarget* child = iter->GetNextTarget(); child;
+ child = iter->GetNextTarget()) {
+ WindowTargeter* targeter =
+ static_cast<WindowTargeter*>(child->GetEventTargeter());
+ if (!targeter)
+ targeter = this;
+ if (!targeter->SubtreeShouldBeExploredForEvent(child, *event))
+ continue;
+ target->ConvertEventToTarget(child, event);
+ target = child;
+ ui::EventTarget* child_target =
+ targeter->FindTargetForEvent(child, event);
tdanderson 2015/05/13 18:38:25 Recursively?
varkha 2015/05/21 19:11:04 Not so sure. WindowTargeterTest.ScopedWindowTarget
tdanderson 2015/05/22 18:29:55 Seems OK to leave as-is to me, but I think it's wo
varkha 2015/05/22 22:18:33 Yes, the code now reproduces the original flow, no
sadrul 2015/05/28 04:48:38 I think calling FindTargetForEvent is the right th
+ if (child_target)
+ return child_target;
+ }
+ target->ConvertEventToTarget(root_window, event);
+ }
+ return root_window->CanAcceptEvent(*event) ? root_window : NULL;
+}
+
} // namespace aura

Powered by Google App Engine
This is Rietveld 408576698