| OLD | NEW |
| 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 <memory> |
| 8 |
| 7 #include "ui/aura/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
| 8 #include "ui/aura/client/event_client.h" | 10 #include "ui/aura/client/event_client.h" |
| 9 #include "ui/aura/client/focus_client.h" | 11 #include "ui/aura/client/focus_client.h" |
| 10 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 11 #include "ui/aura/window_delegate.h" | 13 #include "ui/aura/window_delegate.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 14 #include "ui/events/event_target.h" | 16 #include "ui/events/event_target.h" |
| 15 #include "ui/events/event_target_iterator.h" | 17 #include "ui/events/event_target_iterator.h" |
| 16 | 18 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 | 54 |
| 53 bool WindowTargeter::EventLocationInsideBounds( | 55 bool WindowTargeter::EventLocationInsideBounds( |
| 54 Window* window, | 56 Window* window, |
| 55 const ui::LocatedEvent& event) const { | 57 const ui::LocatedEvent& event) const { |
| 56 gfx::Point point = event.location(); | 58 gfx::Point point = event.location(); |
| 57 if (window->parent()) | 59 if (window->parent()) |
| 58 Window::ConvertPointToTarget(window->parent(), window, &point); | 60 Window::ConvertPointToTarget(window->parent(), window, &point); |
| 59 return gfx::Rect(window->bounds().size()).Contains(point); | 61 return gfx::Rect(window->bounds().size()).Contains(point); |
| 60 } | 62 } |
| 61 | 63 |
| 64 bool WindowTargeter::EventLocationInsideBoundsRecursive(Window* window, |
| 65 gfx::Point point, |
| 66 gfx::Point location) { |
| 67 Window* parent = window->parent(); |
| 68 bool canAccept = true; |
| 69 if (parent) { |
| 70 if (parent->delegate_ && |
| 71 !parent->delegate_->ShouldDescendIntoChildForEventHandling(window, |
| 72 location)) { |
| 73 canAccept = false; |
| 74 } |
| 75 Window::ConvertPointToTarget(window->parent(), window, &point); |
| 76 } |
| 77 |
| 78 bool inBounds = gfx::Rect(window->bounds().size()).Contains(point); |
| 79 canAccept = canAccept && (window->IsVisible() && !window->ignore_events()); |
| 80 client::EventClient* client = client::GetEventClient(window->GetRootWindow()); |
| 81 if (client && !client->CanProcessEventsWithinSubtree(window)) |
| 82 canAccept = false; |
| 83 if (inBounds && canAccept) { |
| 84 return true; |
| 85 } |
| 86 std::unique_ptr<ui::EventTargetIterator> iter = window->GetChildIterator(); |
| 87 if (iter) { |
| 88 for (ui::EventTarget* child = iter->GetNextTarget(); child; |
| 89 child = iter->GetNextTarget()) { |
| 90 if (EventLocationInsideBoundsRecursive(static_cast<Window*>(child), point, |
| 91 location)) |
| 92 return true; |
| 93 } |
| 94 } |
| 95 return false; |
| 96 } |
| 97 |
| 62 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, | 98 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, |
| 63 ui::Event* event) { | 99 ui::Event* event) { |
| 64 Window* window = static_cast<Window*>(root); | 100 Window* window = static_cast<Window*>(root); |
| 65 Window* target = event->IsKeyEvent() | 101 Window* target = event->IsKeyEvent() |
| 66 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) | 102 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) |
| 67 : FindTargetForNonKeyEvent(window, event); | 103 : FindTargetForNonKeyEvent(window, event); |
| 68 if (target && !window->parent() && !window->Contains(target)) { | 104 if (target && !window->parent() && !window->Contains(target)) { |
| 69 // |window| is the root window, but |target| is not a descendent of | 105 // |window| is the root window, but |target| is not a descendent of |
| 70 // |window|. So do not allow dispatching from here. Instead, dispatch the | 106 // |window|. So do not allow dispatching from here. Instead, dispatch the |
| 71 // event through the WindowEventDispatcher that owns |target|. | 107 // event through the WindowEventDispatcher that owns |target|. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 93 ui::EventTarget* WindowTargeter::FindNextBestTarget( | 129 ui::EventTarget* WindowTargeter::FindNextBestTarget( |
| 94 ui::EventTarget* previous_target, | 130 ui::EventTarget* previous_target, |
| 95 ui::Event* event) { | 131 ui::Event* event) { |
| 96 return nullptr; | 132 return nullptr; |
| 97 } | 133 } |
| 98 | 134 |
| 99 bool WindowTargeter::SubtreeShouldBeExploredForEvent( | 135 bool WindowTargeter::SubtreeShouldBeExploredForEvent( |
| 100 Window* window, | 136 Window* window, |
| 101 const ui::LocatedEvent& event) { | 137 const ui::LocatedEvent& event) { |
| 102 return SubtreeCanAcceptEvent(window, event) && | 138 return SubtreeCanAcceptEvent(window, event) && |
| 103 EventLocationInsideBounds(window, event); | 139 EventLocationInsideBoundsRecursive(window, event.location(), |
| 140 event.location()); |
| 104 } | 141 } |
| 105 | 142 |
| 106 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, | 143 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, |
| 107 const ui::KeyEvent& key) { | 144 const ui::KeyEvent& key) { |
| 108 Window* root_window = window->GetRootWindow(); | 145 Window* root_window = window->GetRootWindow(); |
| 109 client::FocusClient* focus_client = client::GetFocusClient(root_window); | 146 client::FocusClient* focus_client = client::GetFocusClient(root_window); |
| 110 if (!focus_client) | 147 if (!focus_client) |
| 111 return window; | 148 return window; |
| 112 Window* focused_window = focus_client->GetFocusedWindow(); | 149 Window* focused_window = focus_client->GetFocusedWindow(); |
| 113 if (!focused_window) | 150 if (!focused_window) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); | 227 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); |
| 191 if (child_target_window) | 228 if (child_target_window) |
| 192 return child_target_window; | 229 return child_target_window; |
| 193 } | 230 } |
| 194 target->ConvertEventToTarget(root_window, event); | 231 target->ConvertEventToTarget(root_window, event); |
| 195 } | 232 } |
| 196 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; | 233 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; |
| 197 } | 234 } |
| 198 | 235 |
| 199 } // namespace aura | 236 } // namespace aura |
| OLD | NEW |