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/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.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/lock_state_controller.h" | 11 #include "ash/wm/lock_state_controller.h" |
12 #include "ash/wm/resize_shadow.h" | 12 #include "ash/wm/resize_shadow.h" |
13 #include "ash/wm/resize_shadow_controller.h" | 13 #include "ash/wm/resize_shadow_controller.h" |
14 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "ash/wm/workspace/snap_sizer.h" | 16 #include "ash/wm/workspace/snap_sizer.h" |
17 #include "ash/wm/workspace_controller.h" | 17 #include "ash/wm/workspace_controller.h" |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
22 #include "ui/aura/client/window_move_client.h" | 22 #include "ui/aura/client/window_move_client.h" |
23 #include "ui/aura/root_window.h" | 23 #include "ui/aura/root_window.h" |
24 #include "ui/aura/test/aura_test_base.h" | 24 #include "ui/aura/test/aura_test_base.h" |
25 #include "ui/aura/test/event_generator.h" | 25 #include "ui/aura/test/event_generator.h" |
26 #include "ui/aura/test/test_window_delegate.h" | 26 #include "ui/aura/test/test_window_delegate.h" |
27 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
28 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 30 #include "ui/views/corewm/window_util.h" |
30 | 31 |
31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
32 // Windows headers define macros for these function names which screw with us. | 33 // Windows headers define macros for these function names which screw with us. |
33 #if defined(CreateWindow) | 34 #if defined(CreateWindow) |
34 #undef CreateWindow | 35 #undef CreateWindow |
35 #endif | 36 #endif |
36 #endif | 37 #endif |
37 | 38 |
38 namespace ash { | 39 namespace ash { |
39 namespace test { | 40 namespace test { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // Drag further than work_area bottom. | 346 // Drag further than work_area bottom. |
346 DragFromCenterBy(target.get(), 0, work_area.height()); | 347 DragFromCenterBy(target.get(), 0, work_area.height()); |
347 // Position should not have changed. | 348 // Position should not have changed. |
348 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); | 349 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); |
349 // Size should have increased by 0, work_area.height() - target->bounds.y() | 350 // Size should have increased by 0, work_area.height() - target->bounds.y() |
350 EXPECT_EQ( | 351 EXPECT_EQ( |
351 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), | 352 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), |
352 target->bounds().size().ToString()); | 353 target->bounds().size().ToString()); |
353 } | 354 } |
354 | 355 |
| 356 TEST_F(ToplevelWindowEventHandlerTest, DontDragIfModalChild) { |
| 357 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); |
| 358 scoped_ptr<aura::Window> w2(CreateWindow(HTCAPTION)); |
| 359 w2->SetBounds(gfx::Rect(100, 0, 100, 100)); |
| 360 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 361 views::corewm::AddTransientChild(w1.get(), w2.get()); |
| 362 gfx::Size size = w1->bounds().size(); |
| 363 |
| 364 // Attempt to drag w1, position and size should not change because w1 has a |
| 365 // modal child. |
| 366 DragFromCenterBy(w1.get(), 100, 100); |
| 367 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); |
| 368 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 369 |
| 370 TouchDragFromCenterBy(w1.get(), 100, 100); |
| 371 EXPECT_EQ("0,0", w1->bounds().origin().ToString()); |
| 372 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 373 } |
| 374 |
355 // Verifies we don't let windows drag to a -y location. | 375 // Verifies we don't let windows drag to a -y location. |
356 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { | 376 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) { |
357 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); | 377 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); |
358 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 378 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
359 target.get()); | 379 target.get()); |
360 generator.MoveMouseTo(0, 5); | 380 generator.MoveMouseTo(0, 5); |
361 generator.DragMouseBy(0, -5); | 381 generator.DragMouseBy(0, -5); |
362 // The y location and height should not have changed. | 382 // The y location and height should not have changed. |
363 EXPECT_EQ(0, target->bounds().y()); | 383 EXPECT_EQ(0, target->bounds().y()); |
364 EXPECT_EQ(100, target->bounds().height()); | 384 EXPECT_EQ(100, target->bounds().height()); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(), | 736 move_client->RunMoveLoop(window2.get(), gfx::Vector2d(), |
717 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 737 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
718 EXPECT_EQ(window1_initial_bounds.ToString(), window1->bounds().ToString()); | 738 EXPECT_EQ(window1_initial_bounds.ToString(), window1->bounds().ToString()); |
719 } | 739 } |
720 | 740 |
721 // Showing the resize shadows when the mouse is over the window edges is tested | 741 // Showing the resize shadows when the mouse is over the window edges is tested |
722 // in resize_shadow_and_cursor_test.cc | 742 // in resize_shadow_and_cursor_test.cc |
723 | 743 |
724 } // namespace test | 744 } // namespace test |
725 } // namespace ash | 745 } // namespace ash |
OLD | NEW |