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

Unified Diff: ui/aura/window_event_dispatcher.cc

Issue 2681613002: Avoid two targeting phases in aura client-lib and EventProcessor. (Closed)
Patch Set: tests Created 3 years, 10 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
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_event_dispatcher.cc
diff --git a/ui/aura/window_event_dispatcher.cc b/ui/aura/window_event_dispatcher.cc
index 6cd3c43e2dad9addd866098702afd9b64af79343..e808cb145984ab0be9d213a4e62a43e5cf915b1a 100644
--- a/ui/aura/window_event_dispatcher.cc
+++ b/ui/aura/window_event_dispatcher.cc
@@ -60,6 +60,21 @@ bool IsEventCandidateForHold(const ui::Event& event) {
return false;
}
+void ConvertEventLocationToTarget(ui::EventTarget* event_target,
+ ui::EventTarget* target,
+ ui::Event* event) {
+ if (target != event_target && event->IsLocatedEvent()) {
sadrul 2017/03/03 02:33:20 early out instead.
riajiang 2017/03/03 04:53:08 Done.
+ gfx::Point location = event->AsLocatedEvent()->location();
+ gfx::Point root_location = event->AsLocatedEvent()->root_location();
+ Window::ConvertPointToTarget(static_cast<Window*>(event_target),
+ static_cast<Window*>(target), &location);
+ Window::ConvertPointToTarget(static_cast<Window*>(event_target),
+ static_cast<Window*>(target), &root_location);
+ event->AsLocatedEvent()->set_location(location);
+ event->AsLocatedEvent()->set_root_location(root_location);
+ }
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -76,6 +91,7 @@ WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host)
dispatching_held_event_(nullptr),
observer_manager_(this),
env_controller_(new EnvInputStateController),
+ event_targeter_(new WindowTargeter),
repost_event_factory_(this),
held_event_factory_(this) {
ui::GestureRecognizer::Get()->AddGestureEventHelper(this);
@@ -90,6 +106,10 @@ WindowEventDispatcher::~WindowEventDispatcher() {
ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this);
}
+ui::EventTargeter* WindowEventDispatcher::GetDefaultEventTargeter() {
+ return event_targeter_.get();
+}
+
void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) {
DCHECK(event->type() == ui::ET_MOUSE_PRESSED ||
event->type() == ui::ET_GESTURE_TAP_DOWN ||
@@ -416,8 +436,33 @@ void WindowEventDispatcher::ReleaseNativeCapture() {
////////////////////////////////////////////////////////////////////////////////
// WindowEventDispatcher, ui::EventProcessor implementation:
-ui::EventTarget* WindowEventDispatcher::GetRootTarget() {
- return window();
+ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) {
+ if (Env::GetInstance()->mode() == Env::Mode::LOCAL)
+ return window();
+
+ if (!event->target())
+ return window();
+
+ ui::EventTarget* event_target = event->target();
+ if (event->IsLocatedEvent()) {
+ ui::EventTarget* target = event_targeter_->FindTargetInRootWindow(
+ window(), *event->AsLocatedEvent());
+ if (target) {
+ ConvertEventLocationToTarget(event_target, target, event);
+ return target;
+ }
+ }
+
+ ui::EventTarget* ancestor_with_targeter = event_target;
+ for (ui::EventTarget* ancestor = event_target->GetParentTarget(); ancestor;
+ ancestor = ancestor->GetParentTarget()) {
+ if (ancestor->GetEventTargeter())
+ ancestor_with_targeter = ancestor;
+ if (ancestor == window())
+ break;
+ }
+ ConvertEventLocationToTarget(event_target, ancestor_with_targeter, event);
+ return ancestor_with_targeter;
}
void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) {
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698