OLD | NEW |
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/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/display/mouse_cursor_event_filter.h" | 8 #include "ash/display/mouse_cursor_event_filter.h" |
9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 class TestWindowDelegate : public aura::test::TestWindowDelegate { | 39 class TestWindowDelegate : public aura::test::TestWindowDelegate { |
40 public: | 40 public: |
41 TestWindowDelegate() { | 41 TestWindowDelegate() { |
42 } | 42 } |
43 virtual ~TestWindowDelegate() {} | 43 virtual ~TestWindowDelegate() {} |
44 | 44 |
45 void set_min_size(const gfx::Size& size) { | 45 void set_min_size(const gfx::Size& size) { |
46 min_size_ = size; | 46 min_size_ = size; |
47 } | 47 } |
48 | 48 |
| 49 void set_max_size(const gfx::Size& size) { |
| 50 max_size_ = size; |
| 51 } |
| 52 |
49 private: | 53 private: |
50 // Overridden from aura::Test::TestWindowDelegate: | 54 // Overridden from aura::Test::TestWindowDelegate: |
51 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 55 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
52 return min_size_; | 56 return min_size_; |
53 } | 57 } |
54 | 58 |
| 59 virtual gfx::Size GetMaximumSize() const OVERRIDE { |
| 60 return max_size_; |
| 61 } |
| 62 |
55 gfx::Size min_size_; | 63 gfx::Size min_size_; |
| 64 gfx::Size max_size_; |
56 | 65 |
57 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); | 66 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
58 }; | 67 }; |
59 | 68 |
60 class WorkspaceWindowResizerTest : public test::AshTestBase { | 69 class WorkspaceWindowResizerTest : public test::AshTestBase { |
61 public: | 70 public: |
62 WorkspaceWindowResizerTest() : window_(NULL) {} | 71 WorkspaceWindowResizerTest() : window_(NULL) {} |
63 virtual ~WorkspaceWindowResizerTest() {} | 72 virtual ~WorkspaceWindowResizerTest() {} |
64 | 73 |
65 virtual void SetUp() OVERRIDE { | 74 virtual void SetUp() OVERRIDE { |
(...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 window_.get(), gfx::Point(), HTCAPTION, no_attached_windows)); | 1467 window_.get(), gfx::Point(), HTCAPTION, no_attached_windows)); |
1459 ASSERT_TRUE(resizer.get()); | 1468 ASSERT_TRUE(resizer.get()); |
1460 // Move it 100 to the bottom. | 1469 // Move it 100 to the bottom. |
1461 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); | 1470 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); |
1462 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); | 1471 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); |
1463 resizer->CompleteDrag(0); | 1472 resizer->CompleteDrag(0); |
1464 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get())); | 1473 EXPECT_TRUE(ash::wm::HasUserChangedWindowPositionOrSize(window_.get())); |
1465 } | 1474 } |
1466 } | 1475 } |
1467 | 1476 |
| 1477 // Test that a window with a specified max size doesn't exceed it when dragged. |
| 1478 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) { |
| 1479 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); |
| 1480 delegate_.set_max_size(gfx::Size(401, 301)); |
| 1481 |
| 1482 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 1483 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); |
| 1484 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); |
| 1485 EXPECT_EQ(401, window_->bounds().width()); |
| 1486 EXPECT_EQ(301, window_->bounds().height()); |
| 1487 } |
| 1488 |
| 1489 // Test that a window with a specified max width doesn't restrict its height. |
| 1490 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) { |
| 1491 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); |
| 1492 delegate_.set_max_size(gfx::Size(401, 0)); |
| 1493 |
| 1494 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 1495 window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); |
| 1496 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); |
| 1497 EXPECT_EQ(401, window_->bounds().width()); |
| 1498 EXPECT_EQ(302, window_->bounds().height()); |
| 1499 } |
| 1500 |
| 1501 // Test that a window with a specified max size can't be snapped. |
| 1502 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) { |
| 1503 { |
| 1504 // With max size not set we get a phantom window controller for dragging off |
| 1505 // the right hand side. |
| 1506 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 1507 |
| 1508 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 1509 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 1510 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 1511 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); |
| 1512 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); |
| 1513 } |
| 1514 { |
| 1515 // With max size defined, we get no phantom window. |
| 1516 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 1517 delegate_.set_max_size(gfx::Size(300, 200)); |
| 1518 |
| 1519 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 1520 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 1521 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); |
| 1522 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 1523 } |
| 1524 } |
| 1525 |
1468 } // namespace internal | 1526 } // namespace internal |
1469 } // namespace ash | 1527 } // namespace ash |
OLD | NEW |