| 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 "services/ui/ws/server_window.h" | 7 #include "services/ui/ws/server_window.h" |
| 8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 8 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" | 9 #include "services/ui/ws/server_window_compositor_frame_sink_manager_test_api.h" |
| 10 #include "services/ui/ws/test_server_window_delegate.h" | 10 #include "services/ui/ws/test_server_window_delegate.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 EnableHitTest(&child1); | 26 EnableHitTest(&child1); |
| 27 child1.SetVisible(true); | 27 child1.SetVisible(true); |
| 28 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 28 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 29 | 29 |
| 30 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 30 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
| 31 root.Add(&child2); | 31 root.Add(&child2); |
| 32 EnableHitTest(&child2); | 32 EnableHitTest(&child2); |
| 33 child2.SetVisible(true); | 33 child2.SetVisible(true); |
| 34 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); | 34 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); |
| 35 | 35 |
| 36 gfx::Point local_point(16, 16); | 36 EXPECT_EQ( |
| 37 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point)); | 37 &child2, |
| 38 EXPECT_EQ(gfx::Point(1, 1), local_point); | 38 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); |
| 39 | 39 |
| 40 local_point.SetPoint(13, 14); | 40 EXPECT_EQ( |
| 41 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point)); | 41 &child1, |
| 42 EXPECT_EQ(gfx::Point(3, 4), local_point); | 42 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 43 | 43 |
| 44 local_point.SetPoint(13, 14); | |
| 45 child1.set_can_accept_events(false); | 44 child1.set_can_accept_events(false); |
| 46 EXPECT_EQ(nullptr, FindDeepestVisibleWindowForEvents(&root, &local_point)); | 45 EXPECT_EQ( |
| 47 EXPECT_EQ(gfx::Point(13, 14), local_point); | 46 nullptr, |
| 47 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 48 | 48 |
| 49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); | 49 child2.set_extended_hit_test_region(gfx::Insets(10, 10, 10, 10)); |
| 50 local_point.SetPoint(13, 14); | 50 EXPECT_EQ( |
| 51 EXPECT_EQ(&child2, FindDeepestVisibleWindowForEvents(&root, &local_point)); | 51 &child2, |
| 52 EXPECT_EQ(gfx::Point(-2, -1), local_point); | 52 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)).window); |
| 53 } |
| 54 |
| 55 TEST(WindowFinderTest, FindDeepestVisibleWindowNonClientArea) { |
| 56 TestServerWindowDelegate window_delegate; |
| 57 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 58 EnableHitTest(&root); |
| 59 window_delegate.set_root_window(&root); |
| 60 root.SetVisible(true); |
| 61 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 62 |
| 63 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 64 root.Add(&child1); |
| 65 EnableHitTest(&child1); |
| 66 child1.SetVisible(true); |
| 67 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 68 |
| 69 DeepestWindow result = |
| 70 FindDeepestVisibleWindowForEvents(&root, gfx::Point(13, 14)); |
| 71 EXPECT_EQ(&child1, result.window); |
| 72 EXPECT_FALSE(result.in_non_client_area); |
| 73 |
| 74 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 75 EXPECT_EQ(&child1, result.window); |
| 76 EXPECT_FALSE(result.in_non_client_area); |
| 77 |
| 78 // 11, 11 is over the non-client area. |
| 79 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
| 80 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 81 EXPECT_EQ(&child1, result.window); |
| 82 EXPECT_TRUE(result.in_non_client_area); |
| 83 |
| 84 // 15, 15 is over the client area. |
| 85 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); |
| 86 EXPECT_EQ(&child1, result.window); |
| 87 EXPECT_FALSE(result.in_non_client_area); |
| 88 |
| 89 // set_can_accept_events(false) should not impact the result for the |
| 90 // non-client area. |
| 91 child1.set_can_accept_events(false); |
| 92 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)); |
| 93 child1.SetClientArea(gfx::Insets(2, 3, 4, 5), std::vector<gfx::Rect>()); |
| 94 EXPECT_EQ(&child1, result.window); |
| 95 EXPECT_TRUE(result.in_non_client_area); |
| 96 |
| 97 // set_can_accept_events(false) means the client area won't be matched though. |
| 98 result = FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)); |
| 99 EXPECT_EQ(&root, result.window); |
| 100 EXPECT_FALSE(result.in_non_client_area); |
| 53 } | 101 } |
| 54 | 102 |
| 55 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { | 103 TEST(WindowFinderTest, FindDeepestVisibleWindowHitTestMask) { |
| 56 TestServerWindowDelegate window_delegate; | 104 TestServerWindowDelegate window_delegate; |
| 57 ServerWindow root(&window_delegate, WindowId(1, 2)); | 105 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 58 window_delegate.set_root_window(&root); | 106 window_delegate.set_root_window(&root); |
| 59 EnableHitTest(&root); | 107 EnableHitTest(&root); |
| 60 root.SetVisible(true); | 108 root.SetVisible(true); |
| 61 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 109 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 62 | 110 |
| 63 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); | 111 ServerWindow child_with_mask(&window_delegate, WindowId(1, 4)); |
| 64 root.Add(&child_with_mask); | 112 root.Add(&child_with_mask); |
| 65 EnableHitTest(&child_with_mask); | 113 EnableHitTest(&child_with_mask); |
| 66 child_with_mask.SetVisible(true); | 114 child_with_mask.SetVisible(true); |
| 67 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20)); | 115 child_with_mask.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 68 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); | 116 child_with_mask.SetHitTestMask(gfx::Rect(2, 2, 16, 16)); |
| 69 | 117 |
| 70 // Test a point inside the window but outside the mask. | 118 // Test a point inside the window but outside the mask. |
| 71 gfx::Point point_outside_mask(11, 11); | 119 EXPECT_EQ( |
| 72 EXPECT_EQ(&root, | 120 &root, |
| 73 FindDeepestVisibleWindowForEvents(&root, &point_outside_mask)); | 121 FindDeepestVisibleWindowForEvents(&root, gfx::Point(11, 11)).window); |
| 74 EXPECT_EQ(gfx::Point(11, 11), point_outside_mask); | |
| 75 | 122 |
| 76 // Test a point inside the window and inside the mask. | 123 // Test a point inside the window and inside the mask. |
| 77 gfx::Point point_inside_mask(15, 15); | 124 EXPECT_EQ( |
| 78 EXPECT_EQ(&child_with_mask, | 125 &child_with_mask, |
| 79 FindDeepestVisibleWindowForEvents(&root, &point_inside_mask)); | 126 FindDeepestVisibleWindowForEvents(&root, gfx::Point(15, 15)).window); |
| 80 EXPECT_EQ(gfx::Point(5, 5), point_inside_mask); | |
| 81 } | 127 } |
| 82 | 128 |
| 83 TEST(WindowFinderTest, FindDeepestVisibleWindowForEventsOverNonTarget) { | 129 TEST(WindowFinderTest, FindDeepestVisibleWindowOverNonTarget) { |
| 84 TestServerWindowDelegate window_delegate; | 130 TestServerWindowDelegate window_delegate; |
| 85 ServerWindow root(&window_delegate, WindowId(1, 2)); | 131 ServerWindow root(&window_delegate, WindowId(1, 2)); |
| 86 window_delegate.set_root_window(&root); | 132 window_delegate.set_root_window(&root); |
| 87 root.SetVisible(true); | 133 root.SetVisible(true); |
| 88 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 134 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 89 | 135 |
| 90 // Create two windows, |child1| and |child2|. The two overlap but |child2| is | 136 // Create two windows, |child1| and |child2|. The two overlap but |child2| is |
| 91 // not a valid event target. | 137 // not a valid event target. |
| 92 ServerWindow child1(&window_delegate, WindowId(1, 3)); | 138 ServerWindow child1(&window_delegate, WindowId(1, 3)); |
| 93 root.Add(&child1); | 139 root.Add(&child1); |
| 94 EnableHitTest(&child1); | 140 EnableHitTest(&child1); |
| 95 child1.SetVisible(true); | 141 child1.SetVisible(true); |
| 96 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); | 142 child1.SetBounds(gfx::Rect(10, 10, 20, 20)); |
| 97 | 143 |
| 98 ServerWindow child2(&window_delegate, WindowId(1, 4)); | 144 ServerWindow child2(&window_delegate, WindowId(1, 4)); |
| 99 root.Add(&child2); | 145 root.Add(&child2); |
| 100 child2.SetVisible(true); | 146 child2.SetVisible(true); |
| 101 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); | 147 child2.SetBounds(gfx::Rect(15, 15, 20, 20)); |
| 102 | 148 |
| 103 // |location_point| is over |child2| and |child1|, but as |child2| isn't a | 149 // 16, 16 is over |child2| and |child1|, but as |child2| isn't a valid event |
| 104 // valid event taret |child2| should be picked. | 150 // target |child1| should be picked. |
| 105 gfx::Point local_point(16, 16); | 151 EXPECT_EQ( |
| 106 EXPECT_EQ(&child1, FindDeepestVisibleWindowForEvents(&root, &local_point)); | 152 &child1, |
| 107 EXPECT_EQ(gfx::Point(6, 6), local_point); | 153 FindDeepestVisibleWindowForEvents(&root, gfx::Point(16, 16)).window); |
| 108 } | 154 } |
| 109 | 155 |
| 110 } // namespace ws | 156 } // namespace ws |
| 111 } // namespace ui | 157 } // namespace ui |
| OLD | NEW |