| 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/common/window_state.h" | 11 #include "ash/wm/common/window_state.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_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "ash/wm/workspace_controller.h" | 16 #include "ash/wm/workspace_controller.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/client/capture_client.h" | 21 #include "ui/aura/client/capture_client.h" |
| 22 #include "ui/aura/test/aura_test_base.h" | 22 #include "ui/aura/test/aura_test_base.h" |
| 23 #include "ui/aura/test/test_window_delegate.h" | 23 #include "ui/aura/test/test_window_delegate.h" |
| 24 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
| 25 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
| 26 #include "ui/display/screen.h" |
| 26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
| 27 #include "ui/events/test/event_generator.h" | 28 #include "ui/events/test/event_generator.h" |
| 28 #include "ui/gfx/screen.h" | |
| 29 #include "ui/wm/core/window_util.h" | 29 #include "ui/wm/core/window_util.h" |
| 30 #include "ui/wm/public/window_move_client.h" | 30 #include "ui/wm/public/window_move_client.h" |
| 31 | 31 |
| 32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 33 // 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. |
| 34 #if defined(CreateWindow) | 34 #if defined(CreateWindow) |
| 35 #undef CreateWindow | 35 #undef CreateWindow |
| 36 #endif | 36 #endif |
| 37 #endif | 37 #endif |
| 38 | 38 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 // Simulate a large bottom-right to top-left drag. Window size should be | 330 // Simulate a large bottom-right to top-left drag. Window size should be |
| 331 // clamped to minimum and position should not change. | 331 // clamped to minimum and position should not change. |
| 332 DragFromCenterBy(w1.get(), -333, -444); | 332 DragFromCenterBy(w1.get(), -333, -444); |
| 333 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 333 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 334 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); | 334 EXPECT_EQ(gfx::Size(40, 40).ToString(), w1->bounds().size().ToString()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 TEST_F(ToplevelWindowEventHandlerTest, BottomRightWorkArea) { | 337 TEST_F(ToplevelWindowEventHandlerTest, BottomRightWorkArea) { |
| 338 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); | 338 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); |
| 339 gfx::Rect work_area = gfx::Screen::GetScreen() | 339 gfx::Rect work_area = display::Screen::GetScreen() |
| 340 ->GetDisplayNearestWindow(target.get()) | 340 ->GetDisplayNearestWindow(target.get()) |
| 341 .work_area(); | 341 .work_area(); |
| 342 gfx::Point position = target->bounds().origin(); | 342 gfx::Point position = target->bounds().origin(); |
| 343 // Drag further than work_area bottom. | 343 // Drag further than work_area bottom. |
| 344 DragFromCenterBy(target.get(), 100, work_area.height()); | 344 DragFromCenterBy(target.get(), 100, work_area.height()); |
| 345 // Position should not have changed. | 345 // Position should not have changed. |
| 346 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); | 346 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); |
| 347 // Size should have increased by 100, work_area.height() - target->bounds.y() | 347 // Size should have increased by 100, work_area.height() - target->bounds.y() |
| 348 EXPECT_EQ( | 348 EXPECT_EQ( |
| 349 gfx::Size(200, work_area.height() - target->bounds().y()).ToString(), | 349 gfx::Size(200, work_area.height() - target->bounds().y()).ToString(), |
| 350 target->bounds().size().ToString()); | 350 target->bounds().size().ToString()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftWorkArea) { | 353 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftWorkArea) { |
| 354 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); | 354 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); |
| 355 gfx::Rect work_area = gfx::Screen::GetScreen() | 355 gfx::Rect work_area = display::Screen::GetScreen() |
| 356 ->GetDisplayNearestWindow(target.get()) | 356 ->GetDisplayNearestWindow(target.get()) |
| 357 .work_area(); | 357 .work_area(); |
| 358 gfx::Point position = target->bounds().origin(); | 358 gfx::Point position = target->bounds().origin(); |
| 359 // Drag further than work_area bottom. | 359 // Drag further than work_area bottom. |
| 360 DragFromCenterBy(target.get(), -30, work_area.height()); | 360 DragFromCenterBy(target.get(), -30, work_area.height()); |
| 361 // origin is now at 70, 100. | 361 // origin is now at 70, 100. |
| 362 EXPECT_EQ(position.x() - 30, target->bounds().x()); | 362 EXPECT_EQ(position.x() - 30, target->bounds().x()); |
| 363 EXPECT_EQ(position.y(), target->bounds().y()); | 363 EXPECT_EQ(position.y(), target->bounds().y()); |
| 364 // Size should have increased by 30, work_area.height() - target->bounds.y() | 364 // Size should have increased by 30, work_area.height() - target->bounds.y() |
| 365 EXPECT_EQ( | 365 EXPECT_EQ( |
| 366 gfx::Size(130, work_area.height() - target->bounds().y()).ToString(), | 366 gfx::Size(130, work_area.height() - target->bounds().y()).ToString(), |
| 367 target->bounds().size().ToString()); | 367 target->bounds().size().ToString()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(ToplevelWindowEventHandlerTest, BottomWorkArea) { | 370 TEST_F(ToplevelWindowEventHandlerTest, BottomWorkArea) { |
| 371 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); | 371 std::unique_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); |
| 372 gfx::Rect work_area = gfx::Screen::GetScreen() | 372 gfx::Rect work_area = display::Screen::GetScreen() |
| 373 ->GetDisplayNearestWindow(target.get()) | 373 ->GetDisplayNearestWindow(target.get()) |
| 374 .work_area(); | 374 .work_area(); |
| 375 gfx::Point position = target->bounds().origin(); | 375 gfx::Point position = target->bounds().origin(); |
| 376 // Drag further than work_area bottom. | 376 // Drag further than work_area bottom. |
| 377 DragFromCenterBy(target.get(), 0, work_area.height()); | 377 DragFromCenterBy(target.get(), 0, work_area.height()); |
| 378 // Position should not have changed. | 378 // Position should not have changed. |
| 379 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); | 379 EXPECT_EQ(position.ToString(), target->bounds().origin().ToString()); |
| 380 // Size should have increased by 0, work_area.height() - target->bounds.y() | 380 // Size should have increased by 0, work_area.height() - target->bounds.y() |
| 381 EXPECT_EQ( | 381 EXPECT_EQ( |
| 382 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), | 382 gfx::Size(100, work_area.height() - target->bounds().y()).ToString(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 410 generator.MoveMouseTo(0, 5); | 410 generator.MoveMouseTo(0, 5); |
| 411 generator.DragMouseBy(0, -5); | 411 generator.DragMouseBy(0, -5); |
| 412 // The y location and height should not have changed. | 412 // The y location and height should not have changed. |
| 413 EXPECT_EQ(0, target->bounds().y()); | 413 EXPECT_EQ(0, target->bounds().y()); |
| 414 EXPECT_EQ(100, target->bounds().height()); | 414 EXPECT_EQ(100, target->bounds().height()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 // Verifies we don't let windows go bigger than the display width. | 417 // Verifies we don't let windows go bigger than the display width. |
| 418 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { | 418 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) { |
| 419 std::unique_ptr<aura::Window> target(CreateWindow(HTRIGHT)); | 419 std::unique_ptr<aura::Window> target(CreateWindow(HTRIGHT)); |
| 420 gfx::Rect work_area = | 420 gfx::Rect work_area = display::Screen::GetScreen() |
| 421 gfx::Screen::GetScreen()->GetDisplayNearestWindow(target.get()).bounds(); | 421 ->GetDisplayNearestWindow(target.get()) |
| 422 .bounds(); |
| 422 DragFromCenterBy(target.get(), work_area.width() * 2, 0); | 423 DragFromCenterBy(target.get(), work_area.width() * 2, 0); |
| 423 // The y location and height should not have changed. | 424 // The y location and height should not have changed. |
| 424 EXPECT_EQ(work_area.width(), target->bounds().width()); | 425 EXPECT_EQ(work_area.width(), target->bounds().width()); |
| 425 } | 426 } |
| 426 | 427 |
| 427 // Verifies that touch-gestures drag the window correctly. | 428 // Verifies that touch-gestures drag the window correctly. |
| 428 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { | 429 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { |
| 429 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( | 430 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( |
| 430 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); | 431 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); |
| 431 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 432 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 772 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 772 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 773 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 773 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); | 774 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); |
| 774 } | 775 } |
| 775 | 776 |
| 776 // Showing the resize shadows when the mouse is over the window edges is tested | 777 // Showing the resize shadows when the mouse is over the window edges is tested |
| 777 // in resize_shadow_and_cursor_test.cc | 778 // in resize_shadow_and_cursor_test.cc |
| 778 | 779 |
| 779 } // namespace test | 780 } // namespace test |
| 780 } // namespace ash | 781 } // namespace ash |
| OLD | NEW |