| 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/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "ash/shell_window_ids.h" | 6 #include "ash/shell_window_ids.h" |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "ash/test/shell_test_api.h" | 8 #include "ash/test/shell_test_api.h" |
| 9 #include "ash/test/test_activation_delegate.h" | 9 #include "ash/test/test_activation_delegate.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate); | 136 DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 TEST_F(WindowManagerTest, Focus) { | 139 TEST_F(WindowManagerTest, Focus) { |
| 140 // The IME event filter interferes with the basic key event propagation we | 140 // The IME event filter interferes with the basic key event propagation we |
| 141 // attempt to do here, so we remove it. | 141 // attempt to do here, so we remove it. |
| 142 test::ShellTestApi shell_test(Shell::GetInstance()); | 142 test::ShellTestApi shell_test(Shell::GetInstance()); |
| 143 Shell::GetInstance()->RemovePreTargetHandler( | 143 Shell::GetInstance()->RemovePreTargetHandler( |
| 144 shell_test.input_method_event_filter()); | 144 shell_test.input_method_event_filter()); |
| 145 | 145 |
| 146 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 146 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 147 root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); | 147 root_window->SetBounds(gfx::Rect(0, 0, 510, 510)); |
| 148 | 148 |
| 149 // Supplied ids are negative so as not to collide with shell ids. | 149 // Supplied ids are negative so as not to collide with shell ids. |
| 150 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe | 150 // TODO(beng): maybe introduce a MAKE_SHELL_ID() macro that generates a safe |
| 151 // id beyond shell id max? | 151 // id beyond shell id max? |
| 152 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( | 152 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 153 SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500))); | 153 SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500))); |
| 154 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( | 154 scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow( |
| 155 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); | 155 SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 156 scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( | 156 scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 176 | 176 |
| 177 // Click on a sub-window (w121) to focus it. | 177 // Click on a sub-window (w121) to focus it. |
| 178 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 178 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 179 w121.get()); | 179 w121.get()); |
| 180 generator.ClickLeftButton(); | 180 generator.ClickLeftButton(); |
| 181 | 181 |
| 182 aura::client::FocusClient* focus_client = | 182 aura::client::FocusClient* focus_client = |
| 183 aura::client::GetFocusClient(w121.get()); | 183 aura::client::GetFocusClient(w121.get()); |
| 184 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); | 184 EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow()); |
| 185 | 185 |
| 186 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 187 |
| 186 // The key press should be sent to the focused sub-window. | 188 // The key press should be sent to the focused sub-window. |
| 187 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false); | 189 ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false); |
| 188 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); | 190 dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); |
| 189 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); | 191 EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code()); |
| 190 | 192 |
| 191 // Touch on a sub-window (w122) to focus it. | 193 // Touch on a sub-window (w122) to focus it. |
| 192 gfx::Point click_point = w122->bounds().CenterPoint(); | 194 gfx::Point click_point = w122->bounds().CenterPoint(); |
| 193 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); | 195 aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point); |
| 194 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime()); | 196 ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime()); |
| 195 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev); | 197 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev); |
| 196 focus_client = aura::client::GetFocusClient(w122.get()); | 198 focus_client = aura::client::GetFocusClient(w122.get()); |
| 197 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); | 199 EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow()); |
| 198 | 200 |
| 199 // The key press should be sent to the focused sub-window. | 201 // The key press should be sent to the focused sub-window. |
| 200 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); | 202 dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev); |
| 201 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); | 203 EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code()); |
| 202 | 204 |
| 203 // Hiding the focused window will set the focus to its parent if | 205 // Hiding the focused window will set the focus to its parent if |
| 204 // it's focusable. | 206 // it's focusable. |
| 205 w122->Hide(); | 207 w122->Hide(); |
| 206 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), | 208 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), |
| 207 aura::client::GetFocusClient(w122.get())); | 209 aura::client::GetFocusClient(w122.get())); |
| 208 EXPECT_EQ(w12.get(), | 210 EXPECT_EQ(w12.get(), |
| 209 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); | 211 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
| 210 | 212 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 227 EXPECT_EQ(w123.get(), | 229 EXPECT_EQ(w123.get(), |
| 228 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); | 230 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
| 229 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); | 231 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); |
| 230 | 232 |
| 231 // Hiding the focused window will set the focus to NULL because | 233 // Hiding the focused window will set the focus to NULL because |
| 232 // parent window is not focusable. | 234 // parent window is not focusable. |
| 233 w123->Hide(); | 235 w123->Hide(); |
| 234 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), | 236 EXPECT_EQ(aura::client::GetFocusClient(w12.get()), |
| 235 aura::client::GetFocusClient(w123.get())); | 237 aura::client::GetFocusClient(w123.get())); |
| 236 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); | 238 EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
| 237 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); | 239 EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); |
| 238 | 240 |
| 239 // Set the focus back to w123 | 241 // Set the focus back to w123 |
| 240 aura::client::SetActivationDelegate(w1.get(), NULL); | 242 aura::client::SetActivationDelegate(w1.get(), NULL); |
| 241 w123->Show(); | 243 w123->Show(); |
| 242 w123->Focus(); | 244 w123->Focus(); |
| 243 EXPECT_EQ(w123.get(), | 245 EXPECT_EQ(w123.get(), |
| 244 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); | 246 aura::client::GetFocusClient(w12.get())->GetFocusedWindow()); |
| 245 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); | 247 aura::client::SetActivationDelegate(w1.get(), &activation_delegate); |
| 246 | 248 |
| 247 // Removing the focused window will set the focus to NULL because | 249 // Removing the focused window will set the focus to NULL because |
| 248 // parent window is not focusable. | 250 // parent window is not focusable. |
| 249 w12->RemoveChild(w123.get()); | 251 w12->RemoveChild(w123.get()); |
| 250 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); | 252 EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get())); |
| 251 EXPECT_FALSE(root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); | 253 EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&keyev)); |
| 252 } | 254 } |
| 253 | 255 |
| 254 // Various assertion testing for activating windows. | 256 // Various assertion testing for activating windows. |
| 255 TEST_F(WindowManagerTest, ActivateOnMouse) { | 257 TEST_F(WindowManagerTest, ActivateOnMouse) { |
| 256 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 258 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 257 | 259 |
| 258 test::TestActivationDelegate d1; | 260 test::TestActivationDelegate d1; |
| 259 aura::test::TestWindowDelegate wd; | 261 aura::test::TestWindowDelegate wd; |
| 260 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | 262 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
| 261 &wd, -1, gfx::Rect(10, 10, 50, 50))); | 263 &wd, -1, gfx::Rect(10, 10, 50, 50))); |
| 262 d1.SetWindow(w1.get()); | 264 d1.SetWindow(w1.get()); |
| 263 test::TestActivationDelegate d2; | 265 test::TestActivationDelegate d2; |
| 264 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | 266 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 265 &wd, -2, gfx::Rect(70, 70, 50, 50))); | 267 &wd, -2, gfx::Rect(70, 70, 50, 50))); |
| 266 d2.SetWindow(w2.get()); | 268 d2.SetWindow(w2.get()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 w3.get()); | 403 w3.get()); |
| 402 wm::ActivateWindow(p1.get()); | 404 wm::ActivateWindow(p1.get()); |
| 403 EXPECT_TRUE(wm::IsActiveWindow(p1.get())); | 405 EXPECT_TRUE(wm::IsActiveWindow(p1.get())); |
| 404 generator3.ClickLeftButton(); | 406 generator3.ClickLeftButton(); |
| 405 EXPECT_TRUE(wm::IsActiveWindow(p1.get())); | 407 EXPECT_TRUE(wm::IsActiveWindow(p1.get())); |
| 406 } | 408 } |
| 407 } | 409 } |
| 408 | 410 |
| 409 // Essentially the same as ActivateOnMouse, but for touch events. | 411 // Essentially the same as ActivateOnMouse, but for touch events. |
| 410 TEST_F(WindowManagerTest, ActivateOnTouch) { | 412 TEST_F(WindowManagerTest, ActivateOnTouch) { |
| 411 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 413 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 412 | 414 |
| 413 test::TestActivationDelegate d1; | 415 test::TestActivationDelegate d1; |
| 414 aura::test::TestWindowDelegate wd; | 416 aura::test::TestWindowDelegate wd; |
| 415 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( | 417 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate( |
| 416 &wd, -1, gfx::Rect(10, 10, 50, 50))); | 418 &wd, -1, gfx::Rect(10, 10, 50, 50))); |
| 417 d1.SetWindow(w1.get()); | 419 d1.SetWindow(w1.get()); |
| 418 test::TestActivationDelegate d2; | 420 test::TestActivationDelegate d2; |
| 419 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( | 421 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate( |
| 420 &wd, -2, gfx::Rect(70, 70, 50, 50))); | 422 &wd, -2, gfx::Rect(70, 70, 50, 50))); |
| 421 d2.SetWindow(w2.get()); | 423 d2.SetWindow(w2.get()); |
| 422 | 424 |
| 423 aura::client::FocusClient* focus_client = | 425 aura::client::FocusClient* focus_client = |
| 424 aura::client::GetFocusClient(w1.get()); | 426 aura::client::GetFocusClient(w1.get()); |
| 425 | 427 |
| 426 d1.Clear(); | 428 d1.Clear(); |
| 427 d2.Clear(); | 429 d2.Clear(); |
| 428 | 430 |
| 429 // Activate window1. | 431 // Activate window1. |
| 430 wm::ActivateWindow(w1.get()); | 432 wm::ActivateWindow(w1.get()); |
| 431 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 433 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 432 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); | 434 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
| 433 EXPECT_EQ(1, d1.activated_count()); | 435 EXPECT_EQ(1, d1.activated_count()); |
| 434 EXPECT_EQ(0, d1.lost_active_count()); | 436 EXPECT_EQ(0, d1.lost_active_count()); |
| 435 d1.Clear(); | 437 d1.Clear(); |
| 436 | 438 |
| 437 // Touch window2. | 439 // Touch window2. |
| 438 gfx::Point press_point = w2->bounds().CenterPoint(); | 440 gfx::Point press_point = w2->bounds().CenterPoint(); |
| 439 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); | 441 aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point); |
| 440 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime()); | 442 ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime()); |
| 441 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev1); | 443 |
| 444 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 445 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev1); |
| 442 | 446 |
| 443 // Window2 should have become active. | 447 // Window2 should have become active. |
| 444 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 448 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 445 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); | 449 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
| 446 EXPECT_EQ(0, d1.activated_count()); | 450 EXPECT_EQ(0, d1.activated_count()); |
| 447 EXPECT_EQ(1, d1.lost_active_count()); | 451 EXPECT_EQ(1, d1.lost_active_count()); |
| 448 EXPECT_EQ(1, d2.activated_count()); | 452 EXPECT_EQ(1, d2.activated_count()); |
| 449 EXPECT_EQ(0, d2.lost_active_count()); | 453 EXPECT_EQ(0, d2.lost_active_count()); |
| 450 d1.Clear(); | 454 d1.Clear(); |
| 451 d2.Clear(); | 455 d2.Clear(); |
| 452 | 456 |
| 453 // Touch window1, but set it up so w1 doesn't activate on touch. | 457 // Touch window1, but set it up so w1 doesn't activate on touch. |
| 454 press_point = w1->bounds().CenterPoint(); | 458 press_point = w1->bounds().CenterPoint(); |
| 455 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); | 459 aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point); |
| 456 d1.set_activate(false); | 460 d1.set_activate(false); |
| 457 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime()); | 461 ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime()); |
| 458 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev2); | 462 dispatcher->AsRootWindowHostDelegate()->OnHostTouchEvent(&touchev2); |
| 459 | 463 |
| 460 // Window2 should still be active and focused. | 464 // Window2 should still be active and focused. |
| 461 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 465 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
| 462 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); | 466 EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow()); |
| 463 EXPECT_EQ(0, d1.activated_count()); | 467 EXPECT_EQ(0, d1.activated_count()); |
| 464 EXPECT_EQ(0, d1.lost_active_count()); | 468 EXPECT_EQ(0, d1.lost_active_count()); |
| 465 EXPECT_EQ(0, d2.activated_count()); | 469 EXPECT_EQ(0, d2.activated_count()); |
| 466 EXPECT_EQ(0, d2.lost_active_count()); | 470 EXPECT_EQ(0, d2.lost_active_count()); |
| 467 d1.Clear(); | 471 d1.Clear(); |
| 468 d2.Clear(); | 472 d2.Clear(); |
| 469 | 473 |
| 470 // Destroy window2, this should make window1 active. | 474 // Destroy window2, this should make window1 active. |
| 471 d1.set_activate(true); | 475 d1.set_activate(true); |
| 472 w2.reset(); | 476 w2.reset(); |
| 473 EXPECT_EQ(0, d2.activated_count()); | 477 EXPECT_EQ(0, d2.activated_count()); |
| 474 EXPECT_EQ(1, d2.lost_active_count()); | 478 EXPECT_EQ(1, d2.lost_active_count()); |
| 475 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 479 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 476 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); | 480 EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow()); |
| 477 EXPECT_EQ(1, d1.activated_count()); | 481 EXPECT_EQ(1, d1.activated_count()); |
| 478 EXPECT_EQ(0, d1.lost_active_count()); | 482 EXPECT_EQ(0, d1.lost_active_count()); |
| 479 } | 483 } |
| 480 | 484 |
| 481 TEST_F(WindowManagerTest, MouseEventCursors) { | 485 TEST_F(WindowManagerTest, MouseEventCursors) { |
| 482 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 486 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 483 | 487 |
| 484 // Create a window. | 488 // Create a window. |
| 485 const int kWindowLeft = 123; | 489 const int kWindowLeft = 123; |
| 486 const int kWindowTop = 45; | 490 const int kWindowTop = 45; |
| 487 HitTestWindowDelegate window_delegate; | 491 HitTestWindowDelegate window_delegate; |
| 488 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 492 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
| 489 &window_delegate, | 493 &window_delegate, |
| 490 -1, | 494 -1, |
| 491 gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); | 495 gfx::Rect(kWindowLeft, kWindowTop, 640, 480))); |
| 492 | 496 |
| 493 // Create two mouse movement events we can switch between. | 497 // Create two mouse movement events we can switch between. |
| 494 gfx::Point point1(kWindowLeft, kWindowTop); | 498 gfx::Point point1(kWindowLeft, kWindowTop); |
| 495 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); | 499 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1); |
| 496 | 500 |
| 497 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); | 501 gfx::Point point2(kWindowLeft + 1, kWindowTop + 1); |
| 498 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); | 502 aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2); |
| 499 | 503 |
| 504 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 505 |
| 500 // Cursor starts as a pointer (set during Shell::Init()). | 506 // Cursor starts as a pointer (set during Shell::Init()). |
| 501 EXPECT_EQ(ui::kCursorPointer, root_window->last_cursor().native_type()); | 507 EXPECT_EQ(ui::kCursorPointer, dispatcher->last_cursor().native_type()); |
| 502 | 508 |
| 503 { | 509 { |
| 504 // Resize edges and corners show proper cursors. | 510 // Resize edges and corners show proper cursors. |
| 505 window_delegate.set_hittest_code(HTBOTTOM); | 511 window_delegate.set_hittest_code(HTBOTTOM); |
| 506 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); | 512 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); |
| 507 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); | 513 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); |
| 508 EXPECT_EQ(ui::kCursorSouthResize, root_window->last_cursor().native_type()); | 514 EXPECT_EQ(ui::kCursorSouthResize, dispatcher->last_cursor().native_type()); |
| 509 } | 515 } |
| 510 | 516 |
| 511 { | 517 { |
| 512 window_delegate.set_hittest_code(HTBOTTOMLEFT); | 518 window_delegate.set_hittest_code(HTBOTTOMLEFT); |
| 513 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); | 519 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); |
| 514 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); | 520 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); |
| 515 EXPECT_EQ(ui::kCursorSouthWestResize, | 521 EXPECT_EQ(ui::kCursorSouthWestResize, |
| 516 root_window->last_cursor().native_type()); | 522 dispatcher->last_cursor().native_type()); |
| 517 } | 523 } |
| 518 | 524 |
| 519 { | 525 { |
| 520 window_delegate.set_hittest_code(HTBOTTOMRIGHT); | 526 window_delegate.set_hittest_code(HTBOTTOMRIGHT); |
| 521 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); | 527 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); |
| 522 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); | 528 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); |
| 523 EXPECT_EQ(ui::kCursorSouthEastResize, | 529 EXPECT_EQ(ui::kCursorSouthEastResize, |
| 524 root_window->last_cursor().native_type()); | 530 dispatcher->last_cursor().native_type()); |
| 525 } | 531 } |
| 526 | 532 |
| 527 { | 533 { |
| 528 window_delegate.set_hittest_code(HTLEFT); | 534 window_delegate.set_hittest_code(HTLEFT); |
| 529 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); | 535 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); |
| 530 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); | 536 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); |
| 531 EXPECT_EQ(ui::kCursorWestResize, root_window->last_cursor().native_type()); | 537 EXPECT_EQ(ui::kCursorWestResize, dispatcher->last_cursor().native_type()); |
| 532 } | 538 } |
| 533 | 539 |
| 534 { | 540 { |
| 535 window_delegate.set_hittest_code(HTRIGHT); | 541 window_delegate.set_hittest_code(HTRIGHT); |
| 536 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); | 542 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); |
| 537 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); | 543 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); |
| 538 EXPECT_EQ(ui::kCursorEastResize, root_window->last_cursor().native_type()); | 544 EXPECT_EQ(ui::kCursorEastResize, dispatcher->last_cursor().native_type()); |
| 539 } | 545 } |
| 540 | 546 |
| 541 { | 547 { |
| 542 window_delegate.set_hittest_code(HTTOP); | 548 window_delegate.set_hittest_code(HTTOP); |
| 543 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); | 549 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); |
| 544 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); | 550 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); |
| 545 EXPECT_EQ(ui::kCursorNorthResize, root_window->last_cursor().native_type()); | 551 EXPECT_EQ(ui::kCursorNorthResize, dispatcher->last_cursor().native_type()); |
| 546 } | 552 } |
| 547 | 553 |
| 548 { | 554 { |
| 549 window_delegate.set_hittest_code(HTTOPLEFT); | 555 window_delegate.set_hittest_code(HTTOPLEFT); |
| 550 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); | 556 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); |
| 551 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); | 557 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); |
| 552 EXPECT_EQ(ui::kCursorNorthWestResize, | 558 EXPECT_EQ(ui::kCursorNorthWestResize, |
| 553 root_window->last_cursor().native_type()); | 559 dispatcher->last_cursor().native_type()); |
| 554 } | 560 } |
| 555 | 561 |
| 556 { | 562 { |
| 557 window_delegate.set_hittest_code(HTTOPRIGHT); | 563 window_delegate.set_hittest_code(HTTOPRIGHT); |
| 558 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); | 564 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0x0); |
| 559 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); | 565 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move2); |
| 560 EXPECT_EQ(ui::kCursorNorthEastResize, | 566 EXPECT_EQ(ui::kCursorNorthEastResize, |
| 561 root_window->last_cursor().native_type()); | 567 dispatcher->last_cursor().native_type()); |
| 562 } | 568 } |
| 563 | 569 |
| 564 { | 570 { |
| 565 // Client area uses null cursor. | 571 // Client area uses null cursor. |
| 566 window_delegate.set_hittest_code(HTCLIENT); | 572 window_delegate.set_hittest_code(HTCLIENT); |
| 567 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); | 573 ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0x0); |
| 568 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); | 574 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&move1); |
| 569 EXPECT_EQ(ui::kCursorNull, root_window->last_cursor().native_type()); | 575 EXPECT_EQ(ui::kCursorNull, dispatcher->last_cursor().native_type()); |
| 570 } | 576 } |
| 571 } | 577 } |
| 572 | 578 |
| 573 #if defined(OS_WIN) | 579 #if defined(OS_WIN) |
| 574 #define MAYBE_TransformActivate DISABLED_TransformActivate | 580 #define MAYBE_TransformActivate DISABLED_TransformActivate |
| 575 #else | 581 #else |
| 576 #define MAYBE_TransformActivate TransformActivate | 582 #define MAYBE_TransformActivate TransformActivate |
| 577 #endif | 583 #endif |
| 578 TEST_F(WindowManagerTest, MAYBE_TransformActivate) { | 584 TEST_F(WindowManagerTest, MAYBE_TransformActivate) { |
| 579 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 585 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 580 gfx::Size size = root_window->bounds().size(); | 586 gfx::Size size = root_window->bounds().size(); |
| 581 EXPECT_EQ(gfx::Rect(size).ToString(), | 587 EXPECT_EQ(gfx::Rect(size).ToString(), |
| 582 Shell::GetScreen()->GetDisplayNearestPoint( | 588 Shell::GetScreen()->GetDisplayNearestPoint( |
| 583 gfx::Point()).bounds().ToString()); | 589 gfx::Point()).bounds().ToString()); |
| 584 | 590 |
| 585 // Rotate it clock-wise 90 degrees. | 591 // Rotate it clock-wise 90 degrees. |
| 586 gfx::Transform transform; | 592 gfx::Transform transform; |
| 587 transform.Translate(size.width(), 0); | 593 transform.Translate(size.width(), 0); |
| 588 transform.Rotate(90.0f); | 594 transform.Rotate(90.0f); |
| 589 root_window->SetTransform(transform); | 595 root_window->SetTransform(transform); |
| 590 | 596 |
| 591 test::TestActivationDelegate d1; | 597 test::TestActivationDelegate d1; |
| 592 aura::test::TestWindowDelegate wd; | 598 aura::test::TestWindowDelegate wd; |
| 593 scoped_ptr<aura::Window> w1( | 599 scoped_ptr<aura::Window> w1( |
| 594 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50))); | 600 CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 10, 50, 50))); |
| 595 d1.SetWindow(w1.get()); | 601 d1.SetWindow(w1.get()); |
| 596 w1->Show(); | 602 w1->Show(); |
| 597 | 603 |
| 598 gfx::Point miss_point(5, 5); | 604 gfx::Point miss_point(5, 5); |
| 599 transform.TransformPoint(&miss_point); | 605 transform.TransformPoint(&miss_point); |
| 600 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, | 606 ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED, |
| 601 miss_point, | 607 miss_point, |
| 602 miss_point, | 608 miss_point, |
| 603 ui::EF_LEFT_MOUSE_BUTTON); | 609 ui::EF_LEFT_MOUSE_BUTTON); |
| 604 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); | 610 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 611 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev1); |
| 605 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); | 612 EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
| 606 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, | 613 ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED, |
| 607 miss_point, | 614 miss_point, |
| 608 miss_point, | 615 miss_point, |
| 609 ui::EF_LEFT_MOUSE_BUTTON); | 616 ui::EF_LEFT_MOUSE_BUTTON); |
| 610 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseup); | 617 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseup); |
| 611 | 618 |
| 612 gfx::Point hit_point(5, 15); | 619 gfx::Point hit_point(5, 15); |
| 613 transform.TransformPoint(&hit_point); | 620 transform.TransformPoint(&hit_point); |
| 614 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, | 621 ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED, |
| 615 hit_point, | 622 hit_point, |
| 616 hit_point, | 623 hit_point, |
| 617 ui::EF_LEFT_MOUSE_BUTTON); | 624 ui::EF_LEFT_MOUSE_BUTTON); |
| 618 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev2); | 625 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev2); |
| 619 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 626 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 620 EXPECT_EQ(w1.get(), | 627 EXPECT_EQ(w1.get(), |
| 621 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); | 628 aura::client::GetFocusClient(w1.get())->GetFocusedWindow()); |
| 622 } | 629 } |
| 623 | 630 |
| 624 TEST_F(WindowManagerTest, AdditionalFilters) { | 631 TEST_F(WindowManagerTest, AdditionalFilters) { |
| 625 // The IME event filter interferes with the basic key event propagation we | 632 // The IME event filter interferes with the basic key event propagation we |
| 626 // attempt to do here, so we remove it. | 633 // attempt to do here, so we remove it. |
| 627 test::ShellTestApi shell_test(Shell::GetInstance()); | 634 test::ShellTestApi shell_test(Shell::GetInstance()); |
| 628 Shell::GetInstance()->RemovePreTargetHandler( | 635 Shell::GetInstance()->RemovePreTargetHandler( |
| 629 shell_test.input_method_event_filter()); | 636 shell_test.input_method_event_filter()); |
| 630 | 637 |
| 631 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); | 638 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
| 632 | 639 |
| 633 // Creates a window and make it active | 640 // Creates a window and make it active |
| 634 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( | 641 scoped_ptr<aura::Window> w1(CreateTestWindowInShell( |
| 635 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); | 642 SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100))); |
| 636 wm::ActivateWindow(w1.get()); | 643 wm::ActivateWindow(w1.get()); |
| 637 | 644 |
| 638 // Creates two addition filters | 645 // Creates two addition filters |
| 639 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); | 646 scoped_ptr<CustomEventHandler> f1(new CustomEventHandler); |
| 640 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); | 647 scoped_ptr<CustomEventHandler> f2(new CustomEventHandler); |
| 641 | 648 |
| 642 // Adds them to root window event filter. | 649 // Adds them to root window event filter. |
| 643 views::corewm::CompoundEventFilter* env_filter = | 650 views::corewm::CompoundEventFilter* env_filter = |
| 644 Shell::GetInstance()->env_filter(); | 651 Shell::GetInstance()->env_filter(); |
| 645 env_filter->AddHandler(f1.get()); | 652 env_filter->AddHandler(f1.get()); |
| 646 env_filter->AddHandler(f2.get()); | 653 env_filter->AddHandler(f2.get()); |
| 647 | 654 |
| 648 // Dispatches mouse and keyboard events. | 655 // Dispatches mouse and keyboard events. |
| 649 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); | 656 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); |
| 650 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); | 657 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 658 dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); |
| 651 ui::MouseEvent mouse_pressed( | 659 ui::MouseEvent mouse_pressed( |
| 652 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); | 660 ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); |
| 653 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_pressed); | 661 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_pressed); |
| 654 | 662 |
| 655 // Both filters should get the events. | 663 // Both filters should get the events. |
| 656 EXPECT_EQ(1, f1->num_key_events()); | 664 EXPECT_EQ(1, f1->num_key_events()); |
| 657 EXPECT_EQ(1, f1->num_mouse_events()); | 665 EXPECT_EQ(1, f1->num_mouse_events()); |
| 658 EXPECT_EQ(1, f2->num_key_events()); | 666 EXPECT_EQ(1, f2->num_key_events()); |
| 659 EXPECT_EQ(1, f2->num_mouse_events()); | 667 EXPECT_EQ(1, f2->num_mouse_events()); |
| 660 | 668 |
| 661 f1->Reset(); | 669 f1->Reset(); |
| 662 f2->Reset(); | 670 f2->Reset(); |
| 663 | 671 |
| 664 // Makes f1 consume events. | 672 // Makes f1 consume events. |
| 665 f1->set_key_event_handling_result(ui::ER_CONSUMED); | 673 f1->set_key_event_handling_result(ui::ER_CONSUMED); |
| 666 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); | 674 f1->set_mouse_event_handling_result(ui::ER_CONSUMED); |
| 667 | 675 |
| 668 // Dispatches events. | 676 // Dispatches events. |
| 669 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); | 677 dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); |
| 670 ui::MouseEvent mouse_released( | 678 ui::MouseEvent mouse_released( |
| 671 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); | 679 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0x0); |
| 672 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_released); | 680 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_released); |
| 673 | 681 |
| 674 // f1 should still get the events but f2 no longer gets them. | 682 // f1 should still get the events but f2 no longer gets them. |
| 675 EXPECT_EQ(1, f1->num_key_events()); | 683 EXPECT_EQ(1, f1->num_key_events()); |
| 676 EXPECT_EQ(1, f1->num_mouse_events()); | 684 EXPECT_EQ(1, f1->num_mouse_events()); |
| 677 EXPECT_EQ(0, f2->num_key_events()); | 685 EXPECT_EQ(0, f2->num_key_events()); |
| 678 EXPECT_EQ(0, f2->num_mouse_events()); | 686 EXPECT_EQ(0, f2->num_mouse_events()); |
| 679 | 687 |
| 680 f1->Reset(); | 688 f1->Reset(); |
| 681 f2->Reset(); | 689 f2->Reset(); |
| 682 | 690 |
| 683 // Remove f1 from additonal filters list. | 691 // Remove f1 from additonal filters list. |
| 684 env_filter->RemoveHandler(f1.get()); | 692 env_filter->RemoveHandler(f1.get()); |
| 685 | 693 |
| 686 // Dispatches events. | 694 // Dispatches events. |
| 687 root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); | 695 dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(&key_event); |
| 688 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_pressed); | 696 dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_pressed); |
| 689 | 697 |
| 690 // f1 should get no events since it's out and f2 should get them. | 698 // f1 should get no events since it's out and f2 should get them. |
| 691 EXPECT_EQ(0, f1->num_key_events()); | 699 EXPECT_EQ(0, f1->num_key_events()); |
| 692 EXPECT_EQ(0, f1->num_mouse_events()); | 700 EXPECT_EQ(0, f1->num_mouse_events()); |
| 693 EXPECT_EQ(1, f2->num_key_events()); | 701 EXPECT_EQ(1, f2->num_key_events()); |
| 694 EXPECT_EQ(1, f2->num_mouse_events()); | 702 EXPECT_EQ(1, f2->num_mouse_events()); |
| 695 | 703 |
| 696 env_filter->RemoveHandler(f2.get()); | 704 env_filter->RemoveHandler(f2.get()); |
| 697 } | 705 } |
| 698 | 706 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 observer_a.reset(); | 839 observer_a.reset(); |
| 832 observer_b.reset(); | 840 observer_b.reset(); |
| 833 generator.MoveMouseTo(50, 50); | 841 generator.MoveMouseTo(50, 50); |
| 834 EXPECT_TRUE(observer_a.did_visibility_change()); | 842 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 835 EXPECT_FALSE(observer_b.did_visibility_change()); | 843 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 836 EXPECT_TRUE(observer_a.is_cursor_visible()); | 844 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 837 } | 845 } |
| 838 #endif | 846 #endif |
| 839 | 847 |
| 840 } // namespace ash | 848 } // namespace ash |
| OLD | NEW |