OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/mus/ws/window_finder.h" | |
6 | |
7 #include "components/mus/surfaces/surfaces_state.h" | |
8 #include "components/mus/ws/server_window.h" | |
9 #include "components/mus/ws/server_window_delegate.h" | |
10 #include "components/mus/ws/server_window_surface.h" | |
11 #include "components/mus/ws/server_window_surface_manager.h" | |
12 #include "components/mus/ws/window_coordinate_conversions.h" | |
13 #include "ui/gfx/geometry/point.h" | |
14 #include "ui/gfx/geometry/point_f.h" | |
15 #include "ui/gfx/transform.h" | |
16 | |
17 namespace mus { | |
18 namespace ws { | |
19 | |
20 bool IsValidWindowForEvents(ServerWindow* window) { | |
21 ServerWindowSurfaceManager* surface_manager = window->surface_manager(); | |
22 return surface_manager && | |
23 surface_manager->HasSurfaceOfType(mojom::SurfaceType::DEFAULT); | |
24 } | |
25 | |
26 ServerWindow* FindDeepestVisibleWindowForEvents(ServerWindow* window, | |
27 gfx::Point* location) { | |
28 const ServerWindow::Windows children(window->GetChildren()); | |
29 for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { | |
30 ServerWindow* child = *iter; | |
31 if (!child->visible()) | |
32 continue; | |
33 | |
34 // TODO(sky): support transform. | |
35 gfx::Point child_location(location->x() - child->bounds().x(), | |
36 location->y() - child->bounds().y()); | |
37 gfx::Rect child_bounds(child->bounds().size()); | |
38 child_bounds.Inset(-child->extended_hit_test_region().left(), | |
39 -child->extended_hit_test_region().top(), | |
40 -child->extended_hit_test_region().right(), | |
41 -child->extended_hit_test_region().bottom()); | |
42 if (!child_bounds.Contains(child_location)) | |
43 continue; | |
44 | |
45 if (child->hit_test_mask() && | |
46 !child->hit_test_mask()->Contains(child_location)) | |
47 continue; | |
48 | |
49 *location = child_location; | |
50 ServerWindow* result = FindDeepestVisibleWindowForEvents(child, location); | |
51 if (IsValidWindowForEvents(result)) | |
52 return result; | |
53 } | |
54 return window; | |
55 } | |
56 | |
57 gfx::Transform GetTransformToWindow(ServerWindow* window) { | |
58 gfx::Transform transform; | |
59 ServerWindow* current = window; | |
60 while (current->parent()) { | |
61 transform.Translate(-current->bounds().x(), -current->bounds().y()); | |
62 current = current->parent(); | |
63 } | |
64 return transform; | |
65 } | |
66 | |
67 } // namespace ws | |
68 } // namespace mus | |
OLD | NEW |