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

Side by Side Diff: components/mus/ws/window_finder.cc

Issue 1987133002: Delete mus surfaces hit testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests Created 4 years, 7 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
« no previous file with comments | « components/mus/ws/window_finder.h ('k') | components/mus/ws/window_finder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/mus/ws/window_finder.h" 5 #include "components/mus/ws/window_finder.h"
6 6
7 #include "cc/surfaces/surface_id.h"
8 #include "components/mus/surfaces/surfaces_state.h" 7 #include "components/mus/surfaces/surfaces_state.h"
9 #include "components/mus/ws/server_window.h" 8 #include "components/mus/ws/server_window.h"
10 #include "components/mus/ws/server_window_delegate.h" 9 #include "components/mus/ws/server_window_delegate.h"
11 #include "components/mus/ws/server_window_surface.h" 10 #include "components/mus/ws/server_window_surface.h"
12 #include "components/mus/ws/server_window_surface_manager.h" 11 #include "components/mus/ws/server_window_surface_manager.h"
13 #include "components/mus/ws/window_coordinate_conversions.h" 12 #include "components/mus/ws/window_coordinate_conversions.h"
14 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/point_f.h" 14 #include "ui/gfx/geometry/point_f.h"
16 #include "ui/gfx/transform.h" 15 #include "ui/gfx/transform.h"
17 16
18 namespace mus { 17 namespace mus {
19 namespace ws { 18 namespace ws {
20 namespace {
21 19
22 bool IsValidWindowForEvents(ServerWindow* window) { 20 bool IsValidWindowForEvents(ServerWindow* window) {
23 ServerWindowSurfaceManager* surface_manager = window->surface_manager(); 21 ServerWindowSurfaceManager* surface_manager = window->surface_manager();
24 return surface_manager && 22 return surface_manager &&
25 surface_manager->HasSurfaceOfType(mojom::SurfaceType::DEFAULT); 23 surface_manager->HasSurfaceOfType(mojom::SurfaceType::DEFAULT);
26 } 24 }
27 25
28 ServerWindow* FindDeepestVisibleWindowNonSurface(ServerWindow* window, 26 ServerWindow* FindDeepestVisibleWindowForEvents(ServerWindow* window,
29 gfx::Point* location) { 27 gfx::Point* location) {
30 const ServerWindow::Windows children(window->GetChildren()); 28 const ServerWindow::Windows children(window->GetChildren());
31 for (auto iter = children.rbegin(); iter != children.rend(); ++iter) { 29 for (auto iter = children.rbegin(); iter != children.rend(); ++iter) {
32 ServerWindow* child = *iter; 30 ServerWindow* child = *iter;
33 if (!child->visible()) 31 if (!child->visible())
34 continue; 32 continue;
35 33
36 // TODO(sky): support transform. 34 // TODO(sky): support transform.
37 gfx::Point child_location(location->x() - child->bounds().x(), 35 gfx::Point child_location(location->x() - child->bounds().x(),
38 location->y() - child->bounds().y()); 36 location->y() - child->bounds().y());
39 gfx::Rect child_bounds(child->bounds().size()); 37 gfx::Rect child_bounds(child->bounds().size());
40 child_bounds.Inset(-child->extended_hit_test_region().left(), 38 child_bounds.Inset(-child->extended_hit_test_region().left(),
41 -child->extended_hit_test_region().top(), 39 -child->extended_hit_test_region().top(),
42 -child->extended_hit_test_region().right(), 40 -child->extended_hit_test_region().right(),
43 -child->extended_hit_test_region().bottom()); 41 -child->extended_hit_test_region().bottom());
44 if (child_bounds.Contains(child_location)) { 42 if (child_bounds.Contains(child_location)) {
45 *location = child_location; 43 *location = child_location;
46 ServerWindow* result = 44 ServerWindow* result = FindDeepestVisibleWindowForEvents(child, location);
47 FindDeepestVisibleWindowNonSurface(child, location);
48 if (IsValidWindowForEvents(result)) 45 if (IsValidWindowForEvents(result))
49 return result; 46 return result;
50 } 47 }
51 } 48 }
52 return window; 49 return window;
53 } 50 }
54 51
55 gfx::Transform GetTransformToWindowNonSurface(ServerWindow* window) { 52 gfx::Transform GetTransformToWindow(ServerWindow* window) {
56 gfx::Transform transform; 53 gfx::Transform transform;
57 ServerWindow* current = window; 54 ServerWindow* current = window;
58 while (current->parent()) { 55 while (current->parent()) {
59 transform.Translate(-current->bounds().x(), -current->bounds().y()); 56 transform.Translate(-current->bounds().x(), -current->bounds().y());
60 current = current->parent(); 57 current = current->parent();
61 } 58 }
62 return transform; 59 return transform;
63 } 60 }
64 61
65 bool HitTestSurfaceOfType(cc::SurfaceId display_surface_id,
66 ServerWindow* window,
67 mus::mojom::SurfaceType surface_type,
68 gfx::Transform* transform) {
69 *transform = gfx::Transform();
70 ServerWindowSurface* surface =
71 window->GetOrCreateSurfaceManager()->GetSurfaceByType(surface_type);
72 return surface &&
73 window->delegate()
74 ->GetSurfacesState()
75 ->hit_tester()
76 ->GetTransformToTargetSurface(display_surface_id, surface->id(),
77 transform);
78 }
79
80 } // namespace
81
82 ServerWindow* FindDeepestVisibleWindowForEvents(
83 ServerWindow* root_window,
84 cc::SurfaceId display_surface_id,
85 gfx::Point* location) {
86 // TODO(sky): remove this when insets can be set on surface.
87 display_surface_id = cc::SurfaceId();
88
89 if (display_surface_id.is_null()) {
90 // Surface-based hit-testing will not return a valid target if no
91 // CompositorFrame has been submitted (e.g. in unit-tests).
92 return FindDeepestVisibleWindowNonSurface(root_window, location);
93 }
94
95 gfx::Transform transform;
96 cc::SurfaceId target_surface =
97 root_window->delegate()
98 ->GetSurfacesState()
99 ->hit_tester()
100 ->GetTargetSurfaceAtPoint(display_surface_id, *location, &transform);
101 WindowId id = WindowIdFromTransportId(
102 cc::SurfaceIdAllocator::NamespaceForId(target_surface));
103 // TODO(fsamuel): This should be a DCHECK but currently we use stale
104 // information to decide where to route input events. This should be fixed
105 // once we implement a UI scheduler.
106 ServerWindow* target = root_window->GetChildWindow(id);
107 if (target)
108 transform.TransformPoint(location);
109 return target;
110 }
111
112 gfx::Transform GetTransformToWindow(cc::SurfaceId display_surface_id,
113 ServerWindow* window) {
114 if (!display_surface_id.is_null()) {
115 gfx::Transform transform;
116 if (HitTestSurfaceOfType(display_surface_id, window,
117 mus::mojom::SurfaceType::DEFAULT, &transform) ||
118 HitTestSurfaceOfType(display_surface_id, window,
119 mus::mojom::SurfaceType::UNDERLAY, &transform)) {
120 return transform;
121 }
122 }
123
124 return GetTransformToWindowNonSurface(window);
125 }
126
127 } // namespace ws 62 } // namespace ws
128 } // namespace mus 63 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_finder.h ('k') | components/mus/ws/window_finder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698