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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer_unittest.cc

Issue 10823199: While dragging a window, show a semi-transparent aura window instead of the standard gray phantom wi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win_aura Created 8 years, 4 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
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/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/property_util.h" 11 #include "ash/wm/property_util.h"
12 #include "ash/wm/workspace_controller.h" 12 #include "ash/wm/workspace_controller.h"
13 #include "ash/wm/workspace/phantom_window_controller.h"
13 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
14 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
15 #include "ui/aura/test/test_window_delegate.h" 16 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
17 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
18 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
19 20
20 namespace ash { 21 namespace ash {
21 namespace internal { 22 namespace internal {
22 namespace { 23 namespace {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 56 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
56 root->SetHostSize(gfx::Size(800, kRootHeight)); 57 root->SetHostSize(gfx::Size(800, kRootHeight));
57 58
58 aura::Window* default_container = 59 aura::Window* default_container =
59 Shell::GetContainer(root, kShellWindowId_DefaultContainer); 60 Shell::GetContainer(root, kShellWindowId_DefaultContainer);
60 61
61 gfx::Rect root_bounds(root->bounds()); 62 gfx::Rect root_bounds(root->bounds());
62 EXPECT_EQ(kRootHeight, root_bounds.height()); 63 EXPECT_EQ(kRootHeight, root_bounds.height());
63 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 64 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
64 window_.reset(new aura::Window(&delegate_)); 65 window_.reset(new aura::Window(&delegate_));
66 window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
65 window_->Init(ui::LAYER_NOT_DRAWN); 67 window_->Init(ui::LAYER_NOT_DRAWN);
66 window_->SetParent(default_container); 68 window_->SetParent(default_container);
67 window_->set_id(1); 69 window_->set_id(1);
68 70
69 window2_.reset(new aura::Window(&delegate2_)); 71 window2_.reset(new aura::Window(&delegate2_));
72 window2_->SetType(aura::client::WINDOW_TYPE_NORMAL);
70 window2_->Init(ui::LAYER_NOT_DRAWN); 73 window2_->Init(ui::LAYER_NOT_DRAWN);
71 window2_->SetParent(default_container); 74 window2_->SetParent(default_container);
72 window2_->set_id(2); 75 window2_->set_id(2);
73 76
74 window3_.reset(new aura::Window(&delegate3_)); 77 window3_.reset(new aura::Window(&delegate3_));
78 window3_->SetType(aura::client::WINDOW_TYPE_NORMAL);
75 window3_->Init(ui::LAYER_NOT_DRAWN); 79 window3_->Init(ui::LAYER_NOT_DRAWN);
76 window3_->SetParent(default_container); 80 window3_->SetParent(default_container);
77 window3_->set_id(3); 81 window3_->set_id(3);
78 } 82 }
79 83
80 virtual void TearDown() OVERRIDE { 84 virtual void TearDown() OVERRIDE {
81 window_.reset(); 85 window_.reset();
82 window2_.reset(); 86 window2_.reset();
83 window3_.reset(); 87 window3_.reset();
84 AshTestBase::TearDown(); 88 AshTestBase::TearDown();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 137 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
134 }; 138 };
135 139
136 // Fails on win_aura since wm::GetRootWindowRelativeToWindow is not implemented 140 // Fails on win_aura since wm::GetRootWindowRelativeToWindow is not implemented
137 // yet for the platform. 141 // yet for the platform.
138 #if defined(OS_WIN) 142 #if defined(OS_WIN)
139 #define MAYBE_WindowDragWithMultiMonitors \ 143 #define MAYBE_WindowDragWithMultiMonitors \
140 DISABLED_WindowDragWithMultiMonitors 144 DISABLED_WindowDragWithMultiMonitors
141 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ 145 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \
142 DISABLED_WindowDragWithMultiMonitorsRightToLeft 146 DISABLED_WindowDragWithMultiMonitorsRightToLeft
147 #define MAYBE_PhantomStyle DISABLED_PhantomStyle
143 #else 148 #else
144 #define MAYBE_WindowDragWithMultiMonitors WindowDragWithMultiMonitors 149 #define MAYBE_WindowDragWithMultiMonitors WindowDragWithMultiMonitors
145 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ 150 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \
146 WindowDragWithMultiMonitorsRightToLeft 151 WindowDragWithMultiMonitorsRightToLeft
152 #define MAYBE_PhantomStyle PhantomStyle
147 #endif 153 #endif
148 154
149 // Assertions around attached window resize dragging from the right with 2 155 // Assertions around attached window resize dragging from the right with 2
150 // windows. 156 // windows.
151 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 157 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
152 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 158 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
153 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 159 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
154 160
155 std::vector<aura::Window*> windows; 161 std::vector<aura::Window*> windows;
156 windows.push_back(window2_.get()); 162 windows.push_back(window2_.get());
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 568 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
563 ASSERT_TRUE(resizer.get()); 569 ASSERT_TRUE(resizer.get());
564 // Move the mouse near the right edge, (798, 0), of the primary display. 570 // Move the mouse near the right edge, (798, 0), of the primary display.
565 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); 571 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0);
566 resizer->CompleteDrag(0); 572 resizer->CompleteDrag(0);
567 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 573 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
568 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); 574 EXPECT_EQ("798,0 50x60", window_->bounds().ToString());
569 } 575 }
570 } 576 }
571 577
578 // Verifies the style of the drag phantom window is correct.
579 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) {
580 UpdateDisplay("800x600,800x600");
581 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
582 ASSERT_EQ(2U, root_windows.size());
583
584 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
585 gfx::Screen::GetPrimaryDisplay());
586 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
587 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
588 {
589 SetGridSize(0);
590 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
591 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
592 ASSERT_TRUE(resizer.get());
593 EXPECT_FALSE(resizer->snap_phantom_window_controller_for_testing());
594 EXPECT_FALSE(resizer->drag_phantom_window_controller_for_testing());
595
596 // The pointer is inside the primary root. Both phantoms should be NULL.
597 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
598 EXPECT_FALSE(resizer->snap_phantom_window_controller_for_testing());
599 EXPECT_FALSE(resizer->drag_phantom_window_controller_for_testing());
600
601 // The window spans both root windows.
602 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0);
603 EXPECT_FALSE(resizer->snap_phantom_window_controller_for_testing());
604 PhantomWindowController* controller =
605 resizer->drag_phantom_window_controller_for_testing();
606 ASSERT_TRUE(controller);
607 EXPECT_EQ(PhantomWindowController::STYLE_WINDOW, controller->style());
608 // |window_| should be opaque since the pointer is still on the primary
609 // root window. The phantom should be semi-transparent.
610 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
611 EXPECT_GT(1.0f, controller->GetOpacity());
612
613 // Enter the pointer to the secondary display.
614 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
615 EXPECT_FALSE(resizer->snap_phantom_window_controller_for_testing());
616 controller = resizer->drag_phantom_window_controller_for_testing();
617 ASSERT_TRUE(controller);
618 EXPECT_EQ(PhantomWindowController::STYLE_WINDOW, controller->style());
619 // |window_| should be transparent, and the phantom should be opaque.
620 EXPECT_GT(1.0f, window_->layer()->opacity());
621 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity());
622
623 resizer->CompleteDrag(0);
624 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
625 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
626 }
627
628 // Do the same test with RevertDrag().
629 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
630 gfx::Screen::GetPrimaryDisplay());
631 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
632 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
633 {
634 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
635 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
636 ASSERT_TRUE(resizer.get());
637 EXPECT_FALSE(resizer->snap_phantom_window_controller_for_testing());
638 EXPECT_FALSE(resizer->drag_phantom_window_controller_for_testing());
639
640 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
641 resizer->RevertDrag();
642 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
643 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
644 }
645 }
646
572 // Verifies windows are correctly restacked when reordering multiple windows. 647 // Verifies windows are correctly restacked when reordering multiple windows.
573 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 648 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
574 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 649 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
575 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 650 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
576 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 651 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
577 652
578 { 653 {
579 std::vector<aura::Window*> windows; 654 std::vector<aura::Window*> windows;
580 windows.push_back(window2_.get()); 655 windows.push_back(window2_.get());
581 SetGridSize(10); 656 SetGridSize(10);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, 836 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
762 // the window should move to the exact position. 837 // the window should move to the exact position.
763 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); 838 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
764 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); 839 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
765 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); 840 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
766 } 841 }
767 842
768 } // namespace 843 } // namespace
769 } // namespace test 844 } // namespace test
770 } // namespace ash 845 } // namespace ash
OLDNEW
« ash/wm/workspace/phantom_window_controller.cc ('K') | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698