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

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

Issue 380343002: aura: Make sure redirected events have the correct location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix-clang-build Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/window_event_dispatcher_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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_targeter.h" 5 #include "ui/aura/window_targeter.h"
6 6
7 #include "ui/aura/client/capture_client.h" 7 #include "ui/aura/client/capture_client.h"
8 #include "ui/aura/client/event_client.h" 8 #include "ui/aura/client/event_client.h"
9 #include "ui/aura/client/focus_client.h" 9 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
11 #include "ui/aura/window_delegate.h" 11 #include "ui/aura/window_delegate.h"
12 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_tree_host.h" 13 #include "ui/aura/window_tree_host.h"
14 #include "ui/events/event_target.h" 14 #include "ui/events/event_target.h"
15 15
16 namespace aura { 16 namespace aura {
17 17
18 namespace {
19
20 bool IsLocatedEvent(const ui::Event& event) {
21 return event.IsMouseEvent() || event.IsTouchEvent() ||
22 event.IsScrollEvent() || event.IsGestureEvent();
23 }
24
25 } // namespace
26
18 WindowTargeter::WindowTargeter() {} 27 WindowTargeter::WindowTargeter() {}
19 WindowTargeter::~WindowTargeter() {} 28 WindowTargeter::~WindowTargeter() {}
20 29
21 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, 30 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root,
22 ui::Event* event) { 31 ui::Event* event) {
23 Window* window = static_cast<Window*>(root); 32 Window* window = static_cast<Window*>(root);
24 Window* target = event->IsKeyEvent() ? 33 Window* target = event->IsKeyEvent() ?
25 FindTargetForKeyEvent(window, *static_cast<ui::KeyEvent*>(event)) : 34 FindTargetForKeyEvent(window, *static_cast<ui::KeyEvent*>(event)) :
26 static_cast<Window*>(EventTargeter::FindTargetForEvent(root, event)); 35 static_cast<Window*>(EventTargeter::FindTargetForEvent(root, event));
27 if (target && !window->parent()) { 36 if (target && !window->parent() && !window->Contains(target)) {
28 // |window| is the root window. 37 // |window| is the root window, but |target| is not a descendent of
29 if (!window->Contains(target)) { 38 // |window|. So do not allow dispatching from here. Instead, dispatch the
30 // |target| is not a descendent of |window|. So do not allow dispatching 39 // event through the WindowEventDispatcher that owns |target|.
31 // from here. Instead, dispatch the event through the 40 aura::Window* new_root = target->GetRootWindow();
32 // WindowEventDispatcher that owns |target|. 41 if (IsLocatedEvent(*event)) {
33 ui::EventDispatchDetails details ALLOW_UNUSED = 42 // The event has been transformed to be in |target|'s coordinate system.
34 target->GetHost()->event_processor()->OnEventFromSource(event); 43 // But dispatching the event through the EventProcessor requires the event
35 target = NULL; 44 // to be in the host's coordinate system. So, convert the event to be in
45 // the root's coordinate space, and then to the host's coordinate space by
46 // applying the host's transform.
47 ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(event);
48 located_event->ConvertLocationToTarget(target, new_root);
49 located_event->UpdateForRootTransform(
50 new_root->GetHost()->GetRootTransform());
36 } 51 }
52 ui::EventDispatchDetails details ALLOW_UNUSED =
53 new_root->GetHost()->event_processor()->OnEventFromSource(event);
54 target = NULL;
37 } 55 }
38 return target; 56 return target;
39 } 57 }
40 58
41 bool WindowTargeter::SubtreeCanAcceptEvent( 59 bool WindowTargeter::SubtreeCanAcceptEvent(
42 ui::EventTarget* target, 60 ui::EventTarget* target,
43 const ui::LocatedEvent& event) const { 61 const ui::LocatedEvent& event) const {
44 aura::Window* window = static_cast<aura::Window*>(target); 62 aura::Window* window = static_cast<aura::Window*>(target);
45 if (!window->IsVisible()) 63 if (!window->IsVisible())
46 return false; 64 return false;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 153
136 // If the initial touch is outside the root window, target the root. 154 // If the initial touch is outside the root window, target the root.
137 if (!root_window->bounds().Contains(event.location())) 155 if (!root_window->bounds().Contains(event.location()))
138 return root_window; 156 return root_window;
139 } 157 }
140 158
141 return NULL; 159 return NULL;
142 } 160 }
143 161
144 } // namespace aura 162 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698