| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/ui/ws/window_finder.h" | 5 #include "services/ui/ws/window_finder.h" |
| 6 | 6 |
| 7 #include "base/containers/adapters.h" | 7 #include "base/containers/adapters.h" |
| 8 #include "services/ui/ws/server_window.h" | 8 #include "services/ui/ws/server_window.h" |
| 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 10 #include "services/ui/ws/server_window_delegate.h" | 10 #include "services/ui/ws/server_window_delegate.h" |
| 11 #include "services/ui/ws/window_coordinate_conversions.h" | 11 #include "services/ui/ws/window_coordinate_conversions.h" |
| 12 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 13 #include "ui/gfx/geometry/point_f.h" | 13 #include "ui/gfx/geometry/point_f.h" |
| 14 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 15 | 15 |
| 16 namespace ui { | 16 namespace ui { |
| 17 namespace ws { | 17 namespace ws { |
| 18 namespace { |
| 18 | 19 |
| 19 bool IsValidWindowForEvents(ServerWindow* window) { | 20 bool IsValidWindowForEvents(ServerWindow* window) { |
| 20 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = | 21 ServerWindowCompositorFrameSinkManager* compositor_frame_sink_manager = |
| 21 window->compositor_frame_sink_manager(); | 22 window->compositor_frame_sink_manager(); |
| 22 // Valid windows have at least one of the two surface types. Only an underlay | 23 // Valid windows have at least one of the two surface types. Only an underlay |
| 23 // is valid as we assume the window manager will likely get the event in this | 24 // is valid as we assume the window manager will likely get the event in this |
| 24 // case. | 25 // case. |
| 25 return compositor_frame_sink_manager && | 26 return compositor_frame_sink_manager && |
| 26 compositor_frame_sink_manager->HasCompositorFrameSink(); | 27 compositor_frame_sink_manager->HasCompositorFrameSink(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 ServerWindow* FindDeepestVisibleWindowForEvents(ServerWindow* window, | 30 bool IsLocationInNonclientArea(const ServerWindow* target, |
| 30 gfx::Point* location) { | 31 const gfx::Point& location) { |
| 31 if (!window->can_accept_events()) | 32 if (!target->parent()) |
| 32 return nullptr; | 33 return false; |
| 34 |
| 35 gfx::Rect client_area(target->bounds().size()); |
| 36 client_area.Inset(target->client_area()); |
| 37 if (client_area.Contains(location)) |
| 38 return false; |
| 39 |
| 40 for (const auto& rect : target->additional_client_areas()) { |
| 41 if (rect.Contains(location)) |
| 42 return false; |
| 43 } |
| 44 |
| 45 return true; |
| 46 } |
| 47 |
| 48 bool FindDeepestVisibleWindowForEventsImpl(ServerWindow* window, |
| 49 const gfx::Point& location, |
| 50 DeepestWindow* deepest_window) { |
| 51 if (!window->can_accept_events()) { |
| 52 if (!IsLocationInNonclientArea(window, location) || |
| 53 !IsValidWindowForEvents(window)) { |
| 54 return false; |
| 55 } |
| 56 deepest_window->window = window; |
| 57 deepest_window->in_non_client_area = true; |
| 58 return true; |
| 59 } |
| 33 | 60 |
| 34 const ServerWindow::Windows& children = window->children(); | 61 const ServerWindow::Windows& children = window->children(); |
| 35 const gfx::Point original_location = *location; | |
| 36 for (ServerWindow* child : base::Reversed(children)) { | 62 for (ServerWindow* child : base::Reversed(children)) { |
| 37 if (!child->visible() || !child->can_accept_events()) | 63 if (!child->visible()) |
| 38 continue; | 64 continue; |
| 39 | 65 |
| 40 // TODO(sky): support transform. | 66 // TODO(sky): support transform. |
| 41 gfx::Point location_in_child(original_location.x() - child->bounds().x(), | 67 gfx::Point location_in_child(location.x() - child->bounds().x(), |
| 42 original_location.y() - child->bounds().y()); | 68 location.y() - child->bounds().y()); |
| 43 gfx::Rect child_bounds(child->bounds().size()); | 69 gfx::Rect child_bounds(child->bounds().size()); |
| 44 child_bounds.Inset(-child->extended_hit_test_region().left(), | 70 child_bounds.Inset(-child->extended_hit_test_region().left(), |
| 45 -child->extended_hit_test_region().top(), | 71 -child->extended_hit_test_region().top(), |
| 46 -child->extended_hit_test_region().right(), | 72 -child->extended_hit_test_region().right(), |
| 47 -child->extended_hit_test_region().bottom()); | 73 -child->extended_hit_test_region().bottom()); |
| 48 if (!child_bounds.Contains(location_in_child) || | 74 if (!child_bounds.Contains(location_in_child) || |
| 49 (child->hit_test_mask() && | 75 (child->hit_test_mask() && |
| 50 !child->hit_test_mask()->Contains(location_in_child))) { | 76 !child->hit_test_mask()->Contains(location_in_child))) { |
| 51 continue; | 77 continue; |
| 52 } | 78 } |
| 53 | 79 |
| 54 *location = location_in_child; | 80 if (FindDeepestVisibleWindowForEventsImpl(child, location_in_child, |
| 55 ServerWindow* result = FindDeepestVisibleWindowForEvents(child, location); | 81 deepest_window)) { |
| 56 if (result) | 82 return true; |
| 57 return result; | 83 } |
| 58 } | 84 } |
| 59 return IsValidWindowForEvents(window) ? window : nullptr; | 85 |
| 86 if (!IsValidWindowForEvents(window)) |
| 87 return false; |
| 88 |
| 89 deepest_window->window = window; |
| 90 deepest_window->in_non_client_area = |
| 91 IsLocationInNonclientArea(window, location); |
| 92 return true; |
| 93 } |
| 94 |
| 95 } // namespace |
| 96 |
| 97 DeepestWindow FindDeepestVisibleWindowForEvents(ServerWindow* root_window, |
| 98 const gfx::Point& location) { |
| 99 DeepestWindow result; |
| 100 FindDeepestVisibleWindowForEventsImpl(root_window, location, &result); |
| 101 return result; |
| 60 } | 102 } |
| 61 | 103 |
| 62 gfx::Transform GetTransformToWindow(ServerWindow* window) { | 104 gfx::Transform GetTransformToWindow(ServerWindow* window) { |
| 63 gfx::Transform transform; | 105 gfx::Transform transform; |
| 64 ServerWindow* current = window; | 106 ServerWindow* current = window; |
| 65 while (current->parent()) { | 107 while (current->parent()) { |
| 66 transform.Translate(-current->bounds().x(), -current->bounds().y()); | 108 transform.Translate(-current->bounds().x(), -current->bounds().y()); |
| 67 current = current->parent(); | 109 current = current->parent(); |
| 68 } | 110 } |
| 69 return transform; | 111 return transform; |
| 70 } | 112 } |
| 71 | 113 |
| 72 } // namespace ws | 114 } // namespace ws |
| 73 } // namespace ui | 115 } // namespace ui |
| OLD | NEW |