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

Side by Side Diff: ui/aura/window_event_dispatcher.cc

Issue 2681613002: Avoid two targeting phases in aura client-lib and EventProcessor. (Closed)
Patch Set: comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "ui/aura/client/capture_client.h" 14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/cursor_client.h" 15 #include "ui/aura/client/cursor_client.h"
16 #include "ui/aura/client/event_client.h" 16 #include "ui/aura/client/event_client.h"
17 #include "ui/aura/client/focus_client.h" 17 #include "ui/aura/client/focus_client.h"
18 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/screen_position_client.h"
19 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
20 #include "ui/aura/env_input_state_controller.h" 20 #include "ui/aura/env_input_state_controller.h"
21 #include "ui/aura/mus/mus_mouse_location_updater.h" 21 #include "ui/aura/mus/mus_mouse_location_updater.h"
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/aura/window_delegate.h" 23 #include "ui/aura/window_delegate.h"
24 #include "ui/aura/window_targeter.h" 24 #include "ui/aura/window_targeter.h"
25 #include "ui/aura/window_tracker.h" 25 #include "ui/aura/window_tracker.h"
26 #include "ui/aura/window_tree_host.h" 26 #include "ui/aura/window_tree_host.h"
27 #include "ui/base/hit_test.h" 27 #include "ui/base/hit_test.h"
28 #include "ui/compositor/dip_util.h" 28 #include "ui/compositor/dip_util.h"
29 #include "ui/events/event.h" 29 #include "ui/events/event.h"
30 #include "ui/events/event_targeter.h"
30 #include "ui/events/event_utils.h" 31 #include "ui/events/event_utils.h"
31 #include "ui/events/gestures/gesture_recognizer.h" 32 #include "ui/events/gestures/gesture_recognizer.h"
32 #include "ui/events/gestures/gesture_types.h" 33 #include "ui/events/gestures/gesture_types.h"
33 34
34 typedef ui::EventDispatchDetails DispatchDetails; 35 typedef ui::EventDispatchDetails DispatchDetails;
35 36
36 namespace aura { 37 namespace aura {
37 38
38 namespace { 39 namespace {
39 40
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 old_dispatch_target_(NULL), 74 old_dispatch_target_(NULL),
74 synthesize_mouse_move_(false), 75 synthesize_mouse_move_(false),
75 move_hold_count_(0), 76 move_hold_count_(0),
76 dispatching_held_event_(nullptr), 77 dispatching_held_event_(nullptr),
77 observer_manager_(this), 78 observer_manager_(this),
78 env_controller_(new EnvInputStateController), 79 env_controller_(new EnvInputStateController),
79 repost_event_factory_(this), 80 repost_event_factory_(this),
80 held_event_factory_(this) { 81 held_event_factory_(this) {
81 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); 82 ui::GestureRecognizer::Get()->AddGestureEventHelper(this);
82 Env::GetInstance()->AddObserver(this); 83 Env::GetInstance()->AddObserver(this);
83 if (Env::GetInstance()->mode() == Env::Mode::MUS) 84 if (Env::GetInstance()->mode() == Env::Mode::MUS) {
84 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); 85 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>();
86 event_targeter_ = base::MakeUnique<WindowTargeter>();
87 }
85 } 88 }
86 89
87 WindowEventDispatcher::~WindowEventDispatcher() { 90 WindowEventDispatcher::~WindowEventDispatcher() {
88 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); 91 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor");
89 Env::GetInstance()->RemoveObserver(this); 92 Env::GetInstance()->RemoveObserver(this);
90 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); 93 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this);
91 } 94 }
92 95
93 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) { 96 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) {
94 DCHECK(event->type() == ui::ET_MOUSE_PRESSED || 97 DCHECK(event->type() == ui::ET_MOUSE_PRESSED ||
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 void WindowEventDispatcher::SetNativeCapture() { 412 void WindowEventDispatcher::SetNativeCapture() {
410 host_->SetCapture(); 413 host_->SetCapture();
411 } 414 }
412 415
413 void WindowEventDispatcher::ReleaseNativeCapture() { 416 void WindowEventDispatcher::ReleaseNativeCapture() {
414 host_->ReleaseCapture(); 417 host_->ReleaseCapture();
415 } 418 }
416 419
417 //////////////////////////////////////////////////////////////////////////////// 420 ////////////////////////////////////////////////////////////////////////////////
418 // WindowEventDispatcher, ui::EventProcessor implementation: 421 // WindowEventDispatcher, ui::EventProcessor implementation:
419 ui::EventTarget* WindowEventDispatcher::GetRootTarget() { 422 ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) {
420 return window(); 423 if (Env::GetInstance()->mode() == Env::Mode::LOCAL)
424 return window();
425
426 if (!event->target())
427 return window();
428
429 ui::EventTarget* target = event->target();
sky 2017/02/15 20:47:17 Using ui::EventTarget rather the Window makes this
riajiang 2017/02/16 00:34:08 This function returns ui::EventTarget so I think m
sky 2017/02/16 01:03:02 Ugh! This is one of those places made painful by m
430 ui::EventTarget* ancestor_with_targeter = target;
431 for (ui::EventTarget* ancestor = target->GetParentTarget(); ancestor;
432 ancestor = ancestor->GetParentTarget()) {
433 if (ancestor->GetEventTargeter())
434 ancestor_with_targeter = ancestor;
435 if (ancestor == window())
sky 2017/02/16 01:03:02 Is this check really necessary?
riajiang 2017/02/16 19:10:35 Because GetParentTarget() will go all the way up t
436 break;
437 }
438
439 if (ancestor_with_targeter != target && event->IsLocatedEvent()) {
440 gfx::Point location = event->AsLocatedEvent()->location();
441 gfx::Point root_location = event->AsLocatedEvent()->root_location();
442 Window::ConvertPointToTarget(static_cast<Window*>(target),
443 static_cast<Window*>(ancestor_with_targeter),
444 &location);
445 Window::ConvertPointToTarget(static_cast<Window*>(target),
446 static_cast<Window*>(ancestor_with_targeter),
447 &root_location);
448 event->AsLocatedEvent()->set_location(location);
449 event->AsLocatedEvent()->set_root_location(root_location);
450 }
451 return ancestor_with_targeter;
452 }
453
454 ui::EventTargeter* WindowEventDispatcher::GetDefaultEventTargeter() {
455 return event_targeter_.get();
421 } 456 }
422 457
423 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) { 458 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) {
424 // The held events are already in |window()|'s coordinate system. So it is 459 // The held events are already in |window()|'s coordinate system. So it is
425 // not necessary to apply the transform to convert from the host's 460 // not necessary to apply the transform to convert from the host's
426 // coordinate system to |window()|'s coordinate system. 461 // coordinate system to |window()|'s coordinate system.
427 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event)) 462 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event))
428 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); 463 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event));
429 464
430 if (mus_mouse_location_updater_) 465 if (mus_mouse_location_updater_)
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 } 905 }
871 906
872 // This flag is set depending on the gestures recognized in the call above, 907 // This flag is set depending on the gestures recognized in the call above,
873 // and needs to propagate with the forwarded event. 908 // and needs to propagate with the forwarded event.
874 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); 909 event->set_may_cause_scrolling(orig_event.may_cause_scrolling());
875 910
876 return PreDispatchLocatedEvent(target, event); 911 return PreDispatchLocatedEvent(target, event);
877 } 912 }
878 913
879 } // namespace aura 914 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698