| 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 |
| 17 namespace aura { | 19 namespace aura { |
| 20 const char kHasIndependentBoundsKey[] = "__INDEPENDENT_BOUNDS__"; |
| 18 | 21 |
| 19 WindowTargeter::WindowTargeter() {} | 22 WindowTargeter::WindowTargeter() {} |
| 20 WindowTargeter::~WindowTargeter() {} | 23 WindowTargeter::~WindowTargeter() {} |
| 21 | 24 |
| 22 Window* WindowTargeter::FindTargetForLocatedEvent(Window* window, | 25 Window* WindowTargeter::FindTargetForLocatedEvent(Window* window, |
| 23 ui::LocatedEvent* event) { | 26 ui::LocatedEvent* event) { |
| 24 if (!window->parent()) { | 27 if (!window->parent()) { |
| 25 Window* target = FindTargetInRootWindow(window, *event); | 28 Window* target = FindTargetInRootWindow(window, *event); |
| 26 if (target) { | 29 if (target) { |
| 27 window->ConvertEventToTarget(target, event); | 30 window->ConvertEventToTarget(target, event); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 | 55 |
| 53 bool WindowTargeter::EventLocationInsideBounds( | 56 bool WindowTargeter::EventLocationInsideBounds( |
| 54 Window* window, | 57 Window* window, |
| 55 const ui::LocatedEvent& event) const { | 58 const ui::LocatedEvent& event) const { |
| 56 gfx::Point point = event.location(); | 59 gfx::Point point = event.location(); |
| 57 if (window->parent()) | 60 if (window->parent()) |
| 58 Window::ConvertPointToTarget(window->parent(), window, &point); | 61 Window::ConvertPointToTarget(window->parent(), window, &point); |
| 59 return gfx::Rect(window->bounds().size()).Contains(point); | 62 return gfx::Rect(window->bounds().size()).Contains(point); |
| 60 } | 63 } |
| 61 | 64 |
| 65 bool WindowTargeter::ChildHasBoundsOutsideParent(Window* parent, |
| 66 Window* child) { |
| 67 if (!parent || !child) |
| 68 return false; |
| 69 return !!child->GetNativeWindowProperty(aura::kHasIndependentBoundsKey); |
| 70 } |
| 71 |
| 72 bool WindowTargeter::HasIndependentChildWithEvent(Window* window, |
| 73 const gfx::Point& event_point, |
| 74 bool in_parent_coordinates) { |
| 75 gfx::Point point(event_point); |
| 76 Window* parent = window->parent(); |
| 77 bool can_accept = true; |
| 78 if (parent) { |
| 79 if (!in_parent_coordinates) |
| 80 Window::ConvertPointToTarget(window, parent, &point); |
| 81 if (parent->delegate_ && |
| 82 !parent->delegate_->ShouldDescendIntoChildForEventHandling(window, |
| 83 point)) { |
| 84 can_accept = false; |
| 85 } |
| 86 Window::ConvertPointToTarget(parent, window, &point); |
| 87 } |
| 88 bool in_bounds = gfx::Rect(window->bounds().size()).Contains(point); |
| 89 can_accept = can_accept && (window->IsVisible() && !window->ignore_events()); |
| 90 client::EventClient* client = client::GetEventClient(window->GetRootWindow()); |
| 91 if (client && !client->CanProcessEventsWithinSubtree(window)) |
| 92 can_accept = false; |
| 93 if (in_bounds && can_accept && ChildHasBoundsOutsideParent(parent, window)) |
| 94 return true; |
| 95 std::unique_ptr<ui::EventTargetIterator> iter = window->GetChildIterator(); |
| 96 if (iter) { |
| 97 for (ui::EventTarget* child = iter->GetNextTarget(); child; |
| 98 child = iter->GetNextTarget()) { |
| 99 if (HasIndependentChildWithEvent(static_cast<Window*>(child), point, |
| 100 true)) |
| 101 return true; |
| 102 } |
| 103 } |
| 104 return false; |
| 105 } |
| 106 |
| 62 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, | 107 ui::EventTarget* WindowTargeter::FindTargetForEvent(ui::EventTarget* root, |
| 63 ui::Event* event) { | 108 ui::Event* event) { |
| 64 Window* window = static_cast<Window*>(root); | 109 Window* window = static_cast<Window*>(root); |
| 65 Window* target = event->IsKeyEvent() | 110 Window* target = event->IsKeyEvent() |
| 66 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) | 111 ? FindTargetForKeyEvent(window, *event->AsKeyEvent()) |
| 67 : FindTargetForNonKeyEvent(window, event); | 112 : FindTargetForNonKeyEvent(window, event); |
| 68 if (target && !window->parent() && !window->Contains(target)) { | 113 if (target && !window->parent() && !window->Contains(target)) { |
| 69 // |window| is the root window, but |target| is not a descendent of | 114 // |window| is the root window, but |target| is not a descendent of |
| 70 // |window|. So do not allow dispatching from here. Instead, dispatch the | 115 // |window|. So do not allow dispatching from here. Instead, dispatch the |
| 71 // event through the WindowEventDispatcher that owns |target|. | 116 // event through the WindowEventDispatcher that owns |target|. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 92 | 137 |
| 93 ui::EventTarget* WindowTargeter::FindNextBestTarget( | 138 ui::EventTarget* WindowTargeter::FindNextBestTarget( |
| 94 ui::EventTarget* previous_target, | 139 ui::EventTarget* previous_target, |
| 95 ui::Event* event) { | 140 ui::Event* event) { |
| 96 return nullptr; | 141 return nullptr; |
| 97 } | 142 } |
| 98 | 143 |
| 99 bool WindowTargeter::SubtreeShouldBeExploredForEvent( | 144 bool WindowTargeter::SubtreeShouldBeExploredForEvent( |
| 100 Window* window, | 145 Window* window, |
| 101 const ui::LocatedEvent& event) { | 146 const ui::LocatedEvent& event) { |
| 102 return SubtreeCanAcceptEvent(window, event) && | 147 return (SubtreeCanAcceptEvent(window, event) && |
| 103 EventLocationInsideBounds(window, event); | 148 EventLocationInsideBounds(window, event)) || |
| 149 HasIndependentChildWithEvent(window, event.location(), true); |
| 104 } | 150 } |
| 105 | 151 |
| 106 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, | 152 Window* WindowTargeter::FindTargetForKeyEvent(Window* window, |
| 107 const ui::KeyEvent& key) { | 153 const ui::KeyEvent& key) { |
| 108 Window* root_window = window->GetRootWindow(); | 154 Window* root_window = window->GetRootWindow(); |
| 109 client::FocusClient* focus_client = client::GetFocusClient(root_window); | 155 client::FocusClient* focus_client = client::GetFocusClient(root_window); |
| 110 if (!focus_client) | 156 if (!focus_client) |
| 111 return window; | 157 return window; |
| 112 Window* focused_window = focus_client->GetFocusedWindow(); | 158 Window* focused_window = focus_client->GetFocusedWindow(); |
| 113 if (!focused_window) | 159 if (!focused_window) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); | 236 static_cast<Window*>(targeter->FindTargetForEvent(child, event)); |
| 191 if (child_target_window) | 237 if (child_target_window) |
| 192 return child_target_window; | 238 return child_target_window; |
| 193 } | 239 } |
| 194 target->ConvertEventToTarget(root_window, event); | 240 target->ConvertEventToTarget(root_window, event); |
| 195 } | 241 } |
| 196 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; | 242 return root_window->CanAcceptEvent(*event) ? root_window : nullptr; |
| 197 } | 243 } |
| 198 | 244 |
| 199 } // namespace aura | 245 } // namespace aura |
| OLD | NEW |