OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | 5 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
6 | 6 |
7 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" | 7 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/aura/window_event_dispatcher.h" | 10 #include "ui/aura/window_event_dispatcher.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 }; | 55 }; |
56 | 56 |
57 TEST_F(ShapedAppWindowTargeterTest, HitTestBasic) { | 57 TEST_F(ShapedAppWindowTargeterTest, HitTestBasic) { |
58 aura::Window* window = widget()->GetNativeWindow(); | 58 aura::Window* window = widget()->GetNativeWindow(); |
59 { | 59 { |
60 // Without any custom shapes, the event should be targeted correctly to the | 60 // Without any custom shapes, the event should be targeted correctly to the |
61 // window. | 61 // window. |
62 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 62 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
63 gfx::Point(40, 40), gfx::Point(40, 40), | 63 gfx::Point(40, 40), gfx::Point(40, 40), |
64 ui::EF_NONE, ui::EF_NONE); | 64 ui::EF_NONE, ui::EF_NONE); |
65 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 65 ui::EventDispatchDetails details = |
| 66 event_processor()->OnEventFromSource(&move); |
66 ASSERT_FALSE(details.dispatcher_destroyed); | 67 ASSERT_FALSE(details.dispatcher_destroyed); |
67 EXPECT_EQ(window, move.target()); | 68 EXPECT_EQ(window, move.target()); |
68 } | 69 } |
69 | 70 |
70 scoped_ptr<SkRegion> region(new SkRegion); | 71 scoped_ptr<SkRegion> region(new SkRegion); |
71 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); | 72 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); |
72 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); | 73 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); |
73 app_window()->UpdateShape(region.Pass()); | 74 app_window()->UpdateShape(region.Pass()); |
74 { | 75 { |
75 // With the custom shape, the events that don't fall within the custom shape | 76 // With the custom shape, the events that don't fall within the custom shape |
76 // will go through to the root window. | 77 // will go through to the root window. |
77 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 78 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
78 gfx::Point(40, 40), gfx::Point(40, 40), | 79 gfx::Point(40, 40), gfx::Point(40, 40), |
79 ui::EF_NONE, ui::EF_NONE); | 80 ui::EF_NONE, ui::EF_NONE); |
80 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 81 ui::EventDispatchDetails details = |
| 82 event_processor()->OnEventFromSource(&move); |
81 ASSERT_FALSE(details.dispatcher_destroyed); | 83 ASSERT_FALSE(details.dispatcher_destroyed); |
82 EXPECT_EQ(root_window(), move.target()); | 84 EXPECT_EQ(root_window(), move.target()); |
83 | 85 |
84 // But events within the shape will still reach the window. | 86 // But events within the shape will still reach the window. |
85 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, | 87 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, |
86 gfx::Point(80, 80), gfx::Point(80, 80), | 88 gfx::Point(80, 80), gfx::Point(80, 80), |
87 ui::EF_NONE, ui::EF_NONE); | 89 ui::EF_NONE, ui::EF_NONE); |
88 details = dispatcher()->OnEventFromSource(&move2); | 90 details = event_processor()->OnEventFromSource(&move2); |
89 ASSERT_FALSE(details.dispatcher_destroyed); | 91 ASSERT_FALSE(details.dispatcher_destroyed); |
90 EXPECT_EQ(window, move2.target()); | 92 EXPECT_EQ(window, move2.target()); |
91 } | 93 } |
92 } | 94 } |
93 | 95 |
94 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { | 96 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { |
95 // Install a window-targeter on the root window that allows a window to | 97 // Install a window-targeter on the root window that allows a window to |
96 // receive events outside of its bounds. Verify that this window-targeter is | 98 // receive events outside of its bounds. Verify that this window-targeter is |
97 // active unless the window has a custom shape. | 99 // active unless the window has a custom shape. |
98 gfx::Insets inset(-30, -30, -30, -30); | 100 gfx::Insets inset(-30, -30, -30, -30); |
99 root_window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | 101 root_window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
100 new wm::EasyResizeWindowTargeter(root_window(), inset, inset))); | 102 new wm::EasyResizeWindowTargeter(root_window(), inset, inset))); |
101 | 103 |
102 aura::Window* window = widget()->GetNativeWindow(); | 104 aura::Window* window = widget()->GetNativeWindow(); |
103 { | 105 { |
104 // Without any custom shapes, an event within the window bounds should be | 106 // Without any custom shapes, an event within the window bounds should be |
105 // targeted correctly to the window. | 107 // targeted correctly to the window. |
106 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 108 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
107 gfx::Point(40, 40), gfx::Point(40, 40), | 109 gfx::Point(40, 40), gfx::Point(40, 40), |
108 ui::EF_NONE, ui::EF_NONE); | 110 ui::EF_NONE, ui::EF_NONE); |
109 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 111 ui::EventDispatchDetails details = |
| 112 event_processor()->OnEventFromSource(&move); |
110 ASSERT_FALSE(details.dispatcher_destroyed); | 113 ASSERT_FALSE(details.dispatcher_destroyed); |
111 EXPECT_EQ(window, move.target()); | 114 EXPECT_EQ(window, move.target()); |
112 } | 115 } |
113 { | 116 { |
114 // Without any custom shapes, an event that falls just outside the window | 117 // Without any custom shapes, an event that falls just outside the window |
115 // bounds should also be targeted correctly to the window, because of the | 118 // bounds should also be targeted correctly to the window, because of the |
116 // targeter installed on the root-window. | 119 // targeter installed on the root-window. |
117 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 120 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
118 gfx::Point(10, 10), gfx::Point(10, 10), | 121 gfx::Point(10, 10), gfx::Point(10, 10), |
119 ui::EF_NONE, ui::EF_NONE); | 122 ui::EF_NONE, ui::EF_NONE); |
120 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 123 ui::EventDispatchDetails details = |
| 124 event_processor()->OnEventFromSource(&move); |
121 ASSERT_FALSE(details.dispatcher_destroyed); | 125 ASSERT_FALSE(details.dispatcher_destroyed); |
122 EXPECT_EQ(window, move.target()); | 126 EXPECT_EQ(window, move.target()); |
123 } | 127 } |
124 | 128 |
125 scoped_ptr<SkRegion> region(new SkRegion); | 129 scoped_ptr<SkRegion> region(new SkRegion); |
126 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); | 130 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); |
127 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); | 131 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); |
128 app_window()->UpdateShape(region.Pass()); | 132 app_window()->UpdateShape(region.Pass()); |
129 { | 133 { |
130 // With the custom shape, the events that don't fall within the custom shape | 134 // With the custom shape, the events that don't fall within the custom shape |
131 // will go through to the root window. | 135 // will go through to the root window. |
132 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 136 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
133 gfx::Point(10, 10), gfx::Point(10, 10), | 137 gfx::Point(10, 10), gfx::Point(10, 10), |
134 ui::EF_NONE, ui::EF_NONE); | 138 ui::EF_NONE, ui::EF_NONE); |
135 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 139 ui::EventDispatchDetails details = |
| 140 event_processor()->OnEventFromSource(&move); |
136 ASSERT_FALSE(details.dispatcher_destroyed); | 141 ASSERT_FALSE(details.dispatcher_destroyed); |
137 EXPECT_EQ(root_window(), move.target()); | 142 EXPECT_EQ(root_window(), move.target()); |
138 } | 143 } |
139 | 144 |
140 // Remove the custom shape. This should restore the behaviour of targeting the | 145 // Remove the custom shape. This should restore the behaviour of targeting the |
141 // app window for events just outside its bounds. | 146 // app window for events just outside its bounds. |
142 app_window()->UpdateShape(scoped_ptr<SkRegion>()); | 147 app_window()->UpdateShape(scoped_ptr<SkRegion>()); |
143 { | 148 { |
144 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 149 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
145 gfx::Point(10, 10), gfx::Point(10, 10), | 150 gfx::Point(10, 10), gfx::Point(10, 10), |
146 ui::EF_NONE, ui::EF_NONE); | 151 ui::EF_NONE, ui::EF_NONE); |
147 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 152 ui::EventDispatchDetails details = |
| 153 event_processor()->OnEventFromSource(&move); |
148 ASSERT_FALSE(details.dispatcher_destroyed); | 154 ASSERT_FALSE(details.dispatcher_destroyed); |
149 EXPECT_EQ(window, move.target()); | 155 EXPECT_EQ(window, move.target()); |
150 } | 156 } |
151 } | 157 } |
152 | 158 |
153 // Tests targeting of events on a window with an EasyResizeWindowTargeter | 159 // Tests targeting of events on a window with an EasyResizeWindowTargeter |
154 // installed on its container. | 160 // installed on its container. |
155 TEST_F(ShapedAppWindowTargeterTest, ResizeInsetsWithinBounds) { | 161 TEST_F(ShapedAppWindowTargeterTest, ResizeInsetsWithinBounds) { |
156 aura::Window* window = widget()->GetNativeWindow(); | 162 aura::Window* window = widget()->GetNativeWindow(); |
157 { | 163 { |
158 // An event in the center of the window should always have | 164 // An event in the center of the window should always have |
159 // |window| as its target. | 165 // |window| as its target. |
160 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 166 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
161 gfx::Point(80, 80), gfx::Point(80, 80), | 167 gfx::Point(80, 80), gfx::Point(80, 80), |
162 ui::EF_NONE, ui::EF_NONE); | 168 ui::EF_NONE, ui::EF_NONE); |
163 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 169 ui::EventDispatchDetails details = |
| 170 event_processor()->OnEventFromSource(&move); |
164 ASSERT_FALSE(details.dispatcher_destroyed); | 171 ASSERT_FALSE(details.dispatcher_destroyed); |
165 EXPECT_EQ(window, move.target()); | 172 EXPECT_EQ(window, move.target()); |
166 } | 173 } |
167 { | 174 { |
168 // Without an EasyResizeTargeter on the container, an event | 175 // Without an EasyResizeTargeter on the container, an event |
169 // inside the window and within 5px of an edge should have | 176 // inside the window and within 5px of an edge should have |
170 // |window| as its target. | 177 // |window| as its target. |
171 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 178 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
172 gfx::Point(32, 37), gfx::Point(32, 37), | 179 gfx::Point(32, 37), gfx::Point(32, 37), |
173 ui::EF_NONE, ui::EF_NONE); | 180 ui::EF_NONE, ui::EF_NONE); |
174 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 181 ui::EventDispatchDetails details = |
| 182 event_processor()->OnEventFromSource(&move); |
175 ASSERT_FALSE(details.dispatcher_destroyed); | 183 ASSERT_FALSE(details.dispatcher_destroyed); |
176 EXPECT_EQ(window, move.target()); | 184 EXPECT_EQ(window, move.target()); |
177 } | 185 } |
178 | 186 |
179 // The EasyResizeTargeter specifies an inset of 5px within the window. | 187 // The EasyResizeTargeter specifies an inset of 5px within the window. |
180 app_window_views()->InstallEasyResizeTargeterOnContainer(); | 188 app_window_views()->InstallEasyResizeTargeterOnContainer(); |
181 | 189 |
182 { | 190 { |
183 // An event in the center of the window should always have | 191 // An event in the center of the window should always have |
184 // |window| as its target. | 192 // |window| as its target. |
185 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 193 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
186 gfx::Point(80, 80), gfx::Point(80, 80), | 194 gfx::Point(80, 80), gfx::Point(80, 80), |
187 ui::EF_NONE, ui::EF_NONE); | 195 ui::EF_NONE, ui::EF_NONE); |
188 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 196 ui::EventDispatchDetails details = |
| 197 event_processor()->OnEventFromSource(&move); |
189 ASSERT_FALSE(details.dispatcher_destroyed); | 198 ASSERT_FALSE(details.dispatcher_destroyed); |
190 EXPECT_EQ(window, move.target()); | 199 EXPECT_EQ(window, move.target()); |
191 } | 200 } |
192 { | 201 { |
193 // With an EasyResizeTargeter on the container, an event | 202 // With an EasyResizeTargeter on the container, an event |
194 // inside the window and within 5px of an edge should have | 203 // inside the window and within 5px of an edge should have |
195 // root_window() as its target. | 204 // root_window() as its target. |
196 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 205 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
197 gfx::Point(32, 37), gfx::Point(32, 37), | 206 gfx::Point(32, 37), gfx::Point(32, 37), |
198 ui::EF_NONE, ui::EF_NONE); | 207 ui::EF_NONE, ui::EF_NONE); |
199 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); | 208 ui::EventDispatchDetails details = |
| 209 event_processor()->OnEventFromSource(&move); |
200 ASSERT_FALSE(details.dispatcher_destroyed); | 210 ASSERT_FALSE(details.dispatcher_destroyed); |
201 EXPECT_EQ(root_window(), move.target()); | 211 EXPECT_EQ(root_window(), move.target()); |
202 } | 212 } |
203 } | 213 } |
OLD | NEW |