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

Side by Side Diff: ash/wm/drag_window_resizer_unittest.cc

Issue 1838003002: Create drag windows on all displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « ash/wm/drag_window_resizer.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/wm/drag_window_resizer.h" 5 #include "ash/wm/drag_window_resizer.h"
6 6
7 #include "ash/display/display_layout_builder.h"
8 #include "ash/display/display_manager.h"
7 #include "ash/display/mouse_cursor_event_filter.h" 9 #include "ash/display/mouse_cursor_event_filter.h"
8 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h" 11 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shell.h" 12 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 13 #include "ash/shell_window_ids.h"
12 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
13 #include "ash/test/cursor_manager_test_api.h" 15 #include "ash/test/cursor_manager_test_api.h"
14 #include "ash/test/display_manager_test_api.h" 16 #include "ash/test/display_manager_test_api.h"
15 #include "ash/wm/drag_window_controller.h" 17 #include "ash/wm/drag_window_controller.h"
16 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 341
340 UpdateDisplay("800x600,800x600"); 342 UpdateDisplay("800x600,800x600");
341 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 343 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
342 ASSERT_EQ(2U, root_windows.size()); 344 ASSERT_EQ(2U, root_windows.size());
343 345
344 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 346 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
345 gfx::Screen::GetScreen()->GetPrimaryDisplay()); 347 gfx::Screen::GetScreen()->GetPrimaryDisplay());
346 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 348 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
347 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 349 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
348 { 350 {
349 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( 351 // Hold the center of the window so that the window doesn't stick to the
350 window_.get(), gfx::Point(), HTCAPTION)); 352 // edge when cragging around the edge of the display.
stevenjb 2016/03/30 21:22:44 dragging
oshima 2016/03/30 21:40:56 Done.
353 scoped_ptr<WindowResizer> resizer(
354 CreateDragWindowResizer(window_.get(), gfx::Point(25, 30), HTCAPTION));
351 ASSERT_TRUE(resizer.get()); 355 ASSERT_TRUE(resizer.get());
352 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; 356 DragWindowResizer* drag_resizer = DragWindowResizer::instance_;
353 ASSERT_TRUE(drag_resizer); 357 ASSERT_TRUE(drag_resizer);
354 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); 358 EXPECT_FALSE(drag_resizer->drag_window_controller_.get());
355 359
356 // The pointer is inside the primary root. The drag window controller 360 // The pointer is inside the primary root. The drag window controller
357 // should be NULL. 361 // should be NULL.
358 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); 362 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
359 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); 363 DragWindowController* controller =
364 drag_resizer->drag_window_controller_.get();
365 EXPECT_EQ(0, controller->GetDragWindowsCountForTest());
360 366
361 // The window spans both root windows. 367 // The window spans both root windows.
362 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); 368 resizer->Drag(CalculateDragPoint(*resizer, 773, 10), 0);
363 EXPECT_EQ(1u, drag_resizer->drag_window_controllers_.size()); 369 EXPECT_EQ(1, controller->GetDragWindowsCountForTest());
364 DragWindowController* controller = 370 const aura::Window* drag_window = controller->GetDragWindowForTest(0);
365 drag_resizer->drag_window_controllers_[0]; 371 ASSERT_TRUE(drag_window);
366 ASSERT_TRUE(controller);
367 372
368 ASSERT_TRUE(controller->drag_widget_); 373 const ui::Layer* drag_layer = drag_window->layer();
369 ui::Layer* drag_layer =
370 controller->drag_widget_->GetNativeWindow()->layer();
371 ASSERT_TRUE(drag_layer); 374 ASSERT_TRUE(drag_layer);
372 // Check if |resizer->layer_| is properly set to the drag widget. 375 // Check if |resizer->layer_| is properly set to the drag widget.
373 const std::vector<ui::Layer*>& layers = drag_layer->children(); 376 const std::vector<ui::Layer*>& layers = drag_layer->children();
374 EXPECT_FALSE(layers.empty()); 377 EXPECT_FALSE(layers.empty());
375 EXPECT_EQ(controller->layer_owner_->root(), layers.back()); 378 EXPECT_EQ(controller->GetDragLayerOwnerForTest(0)->root(), layers.back());
376 379
377 // |window_| should be opaque since the pointer is still on the primary 380 // |window_| should be opaque since the pointer is still on the primary
378 // root window. The drag window should be semi-transparent. 381 // root window. The drag window should be semi-transparent.
379 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 382 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
380 ASSERT_TRUE(controller->drag_widget_);
381 EXPECT_GT(1.0f, drag_layer->opacity()); 383 EXPECT_GT(1.0f, drag_layer->opacity());
382 384
383 // Enter the pointer to the secondary display. 385 // Enter the pointer to the secondary display.
384 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 386 resizer->Drag(CalculateDragPoint(*resizer, 775, 10), 0);
385 EXPECT_EQ(1u, drag_resizer->drag_window_controllers_.size()); 387 EXPECT_EQ(1, controller->GetDragWindowsCountForTest());
386 controller = drag_resizer->drag_window_controllers_[0];
387 ASSERT_TRUE(controller);
388 // |window_| should be transparent, and the drag window should be opaque. 388 // |window_| should be transparent, and the drag window should be opaque.
389 EXPECT_GT(1.0f, window_->layer()->opacity()); 389 EXPECT_GT(1.0f, window_->layer()->opacity());
390 EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity()); 390 EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity());
391 391
392 resizer->CompleteDrag(); 392 resizer->CompleteDrag();
393 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 393 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
394 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 394 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
395 } 395 }
396 396
397 // Do the same test with RevertDrag(). 397 // Do the same test with RevertDrag().
398 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 398 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
399 gfx::Screen::GetScreen()->GetPrimaryDisplay()); 399 gfx::Screen::GetScreen()->GetPrimaryDisplay());
400 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 400 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
401 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 401 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
402 { 402 {
403 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( 403 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer(
404 window_.get(), gfx::Point(), HTCAPTION)); 404 window_.get(), gfx::Point(), HTCAPTION));
405 ASSERT_TRUE(resizer.get()); 405 ASSERT_TRUE(resizer.get());
406 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; 406 DragWindowResizer* drag_resizer = DragWindowResizer::instance_;
407 DragWindowController* controller =
408 drag_resizer->drag_window_controller_.get();
407 ASSERT_TRUE(drag_resizer); 409 ASSERT_TRUE(drag_resizer);
408 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); 410 EXPECT_FALSE(controller);
409 411
410 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); 412 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
411 resizer->RevertDrag(); 413 resizer->RevertDrag();
412 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 414 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
413 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 415 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
414 } 416 }
415 } 417 }
416 418
419 TEST_F(DragWindowResizerTest, DragWindowControllerAcrossThreeDisplays) {
420 if (!SupportsMultipleDisplays())
421 return;
422
423 UpdateDisplay("400x600,400x600,800x600");
424 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
425
426 // Layout so that all three displays touch each other.
427 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
428 DisplayIdList list = display_manager->GetCurrentDisplayIdList();
429 ASSERT_EQ(3u, list.size());
430 ASSERT_EQ(gfx::Screen::GetScreen()->GetPrimaryDisplay().id(), list[0]);
431 DisplayLayoutBuilder builder(list[0]);
432 builder.AddDisplayPlacement(list[1], list[0], DisplayPlacement::RIGHT, 0);
433 builder.AddDisplayPlacement(list[2], list[0], DisplayPlacement::BOTTOM, 0);
434 display_manager->SetLayoutForCurrentDisplays(builder.Build());
435 // Sanity check.
436 ASSERT_EQ(gfx::Rect(0, 000, 400, 600),
437 display_manager->GetDisplayForId(list[0]).bounds());
438 ASSERT_EQ(gfx::Rect(400, 0, 400, 600),
439 display_manager->GetDisplayForId(list[1]).bounds());
440 ASSERT_EQ(gfx::Rect(0, 600, 800, 600),
441 display_manager->GetDisplayForId(list[2]).bounds());
442
443 // Create a window on 2nd display.
444 window_->SetBoundsInScreen(gfx::Rect(400, 0, 100, 100),
445 display_manager->GetDisplayForId(list[1]));
446 ASSERT_EQ(root_windows[1], window_->GetRootWindow());
447
448 // Hold the center of the window so that the window doesn't stick to the edge
449 // when dragging around the edge of the display.
450 scoped_ptr<WindowResizer> resizer(
451 CreateDragWindowResizer(window_.get(), gfx::Point(50, 50), HTCAPTION));
452 ASSERT_TRUE(resizer.get());
453 DragWindowResizer* drag_resizer = DragWindowResizer::instance_;
454 ASSERT_TRUE(drag_resizer);
455 EXPECT_FALSE(drag_resizer->drag_window_controller_.get());
456 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
457 DragWindowController* controller =
458 drag_resizer->drag_window_controller_.get();
459 ASSERT_TRUE(controller);
460 ASSERT_EQ(1, controller->GetDragWindowsCountForTest());
461 const aura::Window* drag_window0 = controller->GetDragWindowForTest(0);
462 ASSERT_TRUE(drag_window0);
463 const ui::Layer* drag_layer0 = drag_window0->layer();
464 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow());
465
466 // |window_| should be opaque since the pointer is still on the primary
467 // root window. The drag window should be semi-transparent.
468 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
469 EXPECT_GT(1.0f, drag_layer0->opacity());
470
471 // The window spans across 3 displays, dragging to 3rd display.
472 resizer->Drag(CalculateDragPoint(*resizer, -50, 549), 0);
473 ASSERT_EQ(2, controller->GetDragWindowsCountForTest());
474 drag_window0 = controller->GetDragWindowForTest(0);
475 const aura::Window* drag_window1 = controller->GetDragWindowForTest(1);
476 drag_layer0 = drag_window0->layer();
477 const ui::Layer* drag_layer1 = drag_window1->layer();
478 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow());
479 EXPECT_EQ(root_windows[2], drag_window1->GetRootWindow());
480
481 // |window_| should be opaque since the pointer is still on the 2nd
482 // root window. The drag window should be semi-transparent.
483 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
484 EXPECT_GT(1.0f, drag_layer0->opacity());
485 EXPECT_GT(1.0f, drag_layer1->opacity());
486
487 resizer->Drag(CalculateDragPoint(*resizer, -51, 549), 0);
488 ASSERT_EQ(2, controller->GetDragWindowsCountForTest());
489 drag_window0 = controller->GetDragWindowForTest(0);
490 drag_window1 = controller->GetDragWindowForTest(1);
491 drag_layer0 = drag_window0->layer();
492 drag_layer1 = drag_window1->layer();
493 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow());
494 EXPECT_EQ(root_windows[2], drag_window1->GetRootWindow());
495
496 // |window_| should be transparent since the pointer is still on the primary
497 // root window. The drag window should be semi-transparent.
498 EXPECT_GT(1.0f, window_->layer()->opacity());
499 EXPECT_FLOAT_EQ(1.0f, drag_layer0->opacity());
500 EXPECT_GT(1.0f, drag_layer1->opacity());
501
502 // Enter the pointer to the 3rd. Since it's bottom, the window snaps and
503 // no drag windwos are created.
504 resizer->Drag(CalculateDragPoint(*resizer, -51, 551), 0);
505 ASSERT_EQ(1, controller->GetDragWindowsCountForTest());
506 drag_window0 = controller->GetDragWindowForTest(0);
507 drag_layer0 = drag_window0->layer();
508 EXPECT_EQ(root_windows[2], drag_window0->GetRootWindow());
509
510 // |window_| should be transparent, and the drag window should be opaque.
511 EXPECT_FLOAT_EQ(0.0f, window_->layer()->opacity());
512 EXPECT_FLOAT_EQ(1.0f, drag_layer0->opacity());
513
514 resizer->CompleteDrag();
515 EXPECT_EQ(root_windows[2], window_->GetRootWindow());
516 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
517 }
518
417 // Verifies if the resizer sets and resets 519 // Verifies if the resizer sets and resets
418 // MouseCursorEventFilter::mouse_warp_mode_ as expected. 520 // MouseCursorEventFilter::mouse_warp_mode_ as expected.
419 TEST_F(DragWindowResizerTest, WarpMousePointer) { 521 TEST_F(DragWindowResizerTest, WarpMousePointer) {
420 MouseCursorEventFilter* event_filter = 522 MouseCursorEventFilter* event_filter =
421 Shell::GetInstance()->mouse_cursor_filter(); 523 Shell::GetInstance()->mouse_cursor_filter();
422 ASSERT_TRUE(event_filter); 524 ASSERT_TRUE(event_filter);
423 window_->SetBounds(gfx::Rect(0, 0, 50, 60)); 525 window_->SetBounds(gfx::Rect(0, 0, 50, 60));
424 526
425 EXPECT_TRUE(event_filter->mouse_warp_enabled_); 527 EXPECT_TRUE(event_filter->mouse_warp_enabled_);
426 { 528 {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 ASSERT_TRUE(resizer.get()); 721 ASSERT_TRUE(resizer.get());
620 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); 722 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0);
621 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); 723 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200)));
622 EXPECT_EQ("401,200", 724 EXPECT_EQ("401,200",
623 aura::Env::GetInstance()->last_mouse_location().ToString()); 725 aura::Env::GetInstance()->last_mouse_location().ToString());
624 resizer->CompleteDrag(); 726 resizer->CompleteDrag();
625 } 727 }
626 } 728 }
627 729
628 } // namespace ash 730 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/drag_window_resizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698