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

Side by Side Diff: ash/shelf/shelf_widget_unittest.cc

Issue 118553004: aura: Add an EasyResizeWindowTargeter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r243131 Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_widget.cc ('k') | ui/aura/window_targeter.h » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ash/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf.h" 8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_button.h" 9 #include "ash/shelf/shelf_button.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_model.h" 11 #include "ash/shelf/shelf_model.h"
12 #include "ash/shelf/shelf_view.h" 12 #include "ash/shelf/shelf_view.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/shelf_test_api.h" 15 #include "ash/test/shelf_test_api.h"
16 #include "ash/test/shelf_view_test_api.h" 16 #include "ash/test/shelf_view_test_api.h"
17 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
18 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
19 #include "ui/events/event_utils.h"
19 #include "ui/gfx/display.h" 20 #include "ui/gfx/display.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
21 #include "ui/views/corewm/corewm_switches.h" 22 #include "ui/views/corewm/corewm_switches.h"
22 #include "ui/views/view.h" 23 #include "ui/views/view.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 namespace ash { 26 namespace ash {
26 27
27 namespace { 28 namespace {
28 29
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 Shelf* shelf = shelf_widget->shelf(); 183 Shelf* shelf = shelf_widget->shelf();
183 ASSERT_TRUE(shelf != NULL); 184 ASSERT_TRUE(shelf != NULL);
184 185
185 const int status_width = 186 const int status_width =
186 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); 187 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width();
187 EXPECT_GT(status_width, 0); 188 EXPECT_GT(status_width, 0);
188 EXPECT_EQ(status_width, 189 EXPECT_EQ(status_width,
189 shelf_widget->GetContentsView()->width() - 190 shelf_widget->GetContentsView()->width() -
190 test::ShelfTestAPI(shelf).shelf_view()->width()); 191 test::ShelfTestAPI(shelf).shelf_view()->width());
191 } 192 }
192 #endif 193 #endif // defined(OS_CHROMEOS)
194
195 // Tests that the shelf lets mouse-events close to the edge fall through to the
196 // window underneath.
197 TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
198 ShelfWidget* shelf_widget = GetShelfWidget();
199 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
200 EXPECT_TRUE(!shelf_bounds.IsEmpty());
201 internal::ShelfLayoutManager* shelf_layout_manager =
202 shelf_widget->shelf_layout_manager();
203 ASSERT_TRUE(shelf_layout_manager);
204 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
205
206 // Create a Widget which overlaps with the shelf in the top edge.
207 const int kOverlapSize = 15;
208 const int kWindowHeight = 200;
209 views::Widget* widget = new views::Widget;
210 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
211 params.bounds = gfx::Rect(0, shelf_bounds.y() - kWindowHeight + kOverlapSize,
212 200, kWindowHeight);
213 params.context = CurrentContext();
214 // Widget is now owned by the parent window.
215 widget->Init(params);
216 widget->Show();
217 gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen();
218 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
219
220
221 ui::EventTarget* root = widget->GetNativeWindow()->GetRootWindow();
222 ui::EventTargeter* targeter = root->GetEventTargeter();
223 {
224 // Create a mouse-event targetting the top of the shelf widget. The
225 // window-targeter should find |widget| as the target (instead of the
226 // shelf).
227 gfx::Point event_location(20, shelf_bounds.y() + 1);
228 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
229 ui::EF_NONE, ui::EF_NONE);
230 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
231 EXPECT_EQ(widget->GetNativeWindow(), target);
232 }
233
234 // Now auto-hide (hidden) the shelf.
235 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
236 shelf_layout_manager->LayoutShelf();
237 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
238 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
239 shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
240 EXPECT_TRUE(!shelf_bounds.IsEmpty());
241
242 // Move |widget| so it still overlaps the shelf.
243 widget->SetBounds(gfx::Rect(0, shelf_bounds.y() - kWindowHeight +
244 kOverlapSize, 200, kWindowHeight));
245 widget_bounds = widget->GetWindowBoundsInScreen();
246 EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
247 {
248 // Create a mouse-event targetting the top of the shelf widget. This time,
249 // window-target should find the shelf as the target.
250 gfx::Point event_location(20, shelf_bounds.y() + 1);
251 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
252 ui::EF_NONE, ui::EF_NONE);
253 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
254 EXPECT_EQ(shelf_widget->GetNativeWindow(), target);
255 }
256 }
257
258 // Tests that the shelf has a slightly larger hit-region for touch-events when
259 // it's in the auto-hidden state.
260 TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) {
261 ShelfWidget* shelf_widget = GetShelfWidget();
262 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
263 EXPECT_TRUE(!shelf_bounds.IsEmpty());
264 internal::ShelfLayoutManager* shelf_layout_manager =
265 shelf_widget->shelf_layout_manager();
266 ASSERT_TRUE(shelf_layout_manager);
267 EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
268
269 // Create a widget to make sure that the shelf does auto-hide.
270 views::Widget* widget = new views::Widget;
271 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
272 params.bounds = gfx::Rect(0, 0, 200, 200);
273 params.context = CurrentContext();
274 // Widget is now owned by the parent window.
275 widget->Init(params);
276 widget->Show();
277
278 ui::EventTarget* root = shelf_widget->GetNativeWindow()->GetRootWindow();
279 ui::EventTargeter* targeter = root->GetEventTargeter();
280 // Touch just over the shelf. Since the shelf is visible, the window-targeter
281 // should not find the shelf as the target.
282 {
283 gfx::Point event_location(20, shelf_bounds.y() - 1);
284 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0,
285 ui::EventTimeForNow());
286 EXPECT_NE(shelf_widget->GetNativeWindow(),
287 targeter->FindTargetForEvent(root, &touch));
288 }
289
290 // Now auto-hide (hidden) the shelf.
291 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
292 shelf_layout_manager->LayoutShelf();
293 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
294 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
295 shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
296 EXPECT_TRUE(!shelf_bounds.IsEmpty());
297
298 // Touch just over the shelf again. This time, the targeter should find the
299 // shelf as the target.
300 {
301 gfx::Point event_location(20, shelf_bounds.y() - 1);
302 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0,
303 ui::EventTimeForNow());
304 EXPECT_EQ(shelf_widget->GetNativeWindow(),
305 targeter->FindTargetForEvent(root, &touch));
306 }
307 }
193 308
194 } // namespace ash 309 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_widget.cc ('k') | ui/aura/window_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698