| 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 "ui/wm/core/window_modality_controller.h" | 5 #include "ui/wm/core/window_modality_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/test/child_modal_window.h" | 9 #include "ash/test/child_modal_window.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
| 12 #include "ui/aura/test/event_generator.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 16 #include "ui/base/ui_base_types.h" | 17 #include "ui/base/ui_base_types.h" |
| 17 #include "ui/events/test/event_generator.h" | |
| 18 #include "ui/views/test/capture_tracking_view.h" | 18 #include "ui/views/test/capture_tracking_view.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 #include "ui/wm/core/window_util.h" | 20 #include "ui/wm/core/window_util.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 | 23 |
| 24 typedef test::AshTestBase WindowModalityControllerTest; | 24 typedef test::AshTestBase WindowModalityControllerTest; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 aura::test::TestWindowDelegate d; | 182 aura::test::TestWindowDelegate d; |
| 183 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, | 183 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, |
| 184 gfx::Rect(0, 0, 100, 100))); | 184 gfx::Rect(0, 0, 100, 100))); |
| 185 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, | 185 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, |
| 186 gfx::Rect(20, 20, 50, 50))); | 186 gfx::Rect(20, 20, 50, 50))); |
| 187 | 187 |
| 188 ::wm::AddTransientChild(w1.get(), w11.get()); | 188 ::wm::AddTransientChild(w1.get(), w11.get()); |
| 189 | 189 |
| 190 { | 190 { |
| 191 // Clicking a point within w1 should activate that window. | 191 // Clicking a point within w1 should activate that window. |
| 192 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 192 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 193 gfx::Point(10, 10)); | 193 gfx::Point(10, 10)); |
| 194 generator.ClickLeftButton(); | 194 generator.ClickLeftButton(); |
| 195 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 195 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 196 } | 196 } |
| 197 | 197 |
| 198 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 198 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 199 | 199 |
| 200 { | 200 { |
| 201 // Clicking a point within w1 should activate w11. | 201 // Clicking a point within w1 should activate w11. |
| 202 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 202 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 203 gfx::Point(10, 10)); | 203 gfx::Point(10, 10)); |
| 204 generator.ClickLeftButton(); | 204 generator.ClickLeftButton(); |
| 205 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); | 205 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Events on modal parent activate. | 209 // Events on modal parent activate. |
| 210 TEST_F(WindowModalityControllerTest, EventsForEclipsedWindows) { | 210 TEST_F(WindowModalityControllerTest, EventsForEclipsedWindows) { |
| 211 aura::test::TestWindowDelegate d; | 211 aura::test::TestWindowDelegate d; |
| 212 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, | 212 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d, -1, |
| 213 gfx::Rect(0, 0, 100, 100))); | 213 gfx::Rect(0, 0, 100, 100))); |
| 214 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, | 214 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d, -11, |
| 215 gfx::Rect(20, 20, 50, 50))); | 215 gfx::Rect(20, 20, 50, 50))); |
| 216 ::wm::AddTransientChild(w1.get(), w11.get()); | 216 ::wm::AddTransientChild(w1.get(), w11.get()); |
| 217 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(&d, -2, | 217 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(&d, -2, |
| 218 gfx::Rect(0, 0, 50, 50))); | 218 gfx::Rect(0, 0, 50, 50))); |
| 219 | 219 |
| 220 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 220 w11->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 221 | 221 |
| 222 // Partially eclipse w1 with w2. | 222 // Partially eclipse w1 with w2. |
| 223 wm::ActivateWindow(w2.get()); | 223 wm::ActivateWindow(w2.get()); |
| 224 { | 224 { |
| 225 // Clicking a point on w1 that is not eclipsed by w2. | 225 // Clicking a point on w1 that is not eclipsed by w2. |
| 226 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 226 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 227 gfx::Point(90, 90)); | 227 gfx::Point(90, 90)); |
| 228 generator.ClickLeftButton(); | 228 generator.ClickLeftButton(); |
| 229 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); | 229 EXPECT_TRUE(wm::IsActiveWindow(w11.get())); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Creates windows w1 and non activatiable child w11. Creates transient window | 233 // Creates windows w1 and non activatiable child w11. Creates transient window |
| 234 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to | 234 // w2 and adds it as a transeint child of w1. Ensures that w2 is parented to |
| 235 // the parent of w1, and that GetModalTransient(w11) returns w2. | 235 // the parent of w1, and that GetModalTransient(w11) returns w2. |
| 236 TEST_F(WindowModalityControllerTest, GetModalTransient) { | 236 TEST_F(WindowModalityControllerTest, GetModalTransient) { |
| 237 aura::test::TestWindowDelegate d; | 237 aura::test::TestWindowDelegate d; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 NULL, Shell::GetPrimaryRootWindow()); | 269 NULL, Shell::GetPrimaryRootWindow()); |
| 270 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); | 270 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); |
| 271 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; | 271 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView; |
| 272 widget->client_view()->AddChildView(view); | 272 widget->client_view()->AddChildView(view); |
| 273 widget->SetBounds(gfx::Rect(0, 0, 200, 200)); | 273 widget->SetBounds(gfx::Rect(0, 0, 200, 200)); |
| 274 view->SetBoundsRect(widget->client_view()->GetLocalBounds()); | 274 view->SetBoundsRect(widget->client_view()->GetLocalBounds()); |
| 275 widget->Show(); | 275 widget->Show(); |
| 276 | 276 |
| 277 gfx::Point center(view->width() / 2, view->height() / 2); | 277 gfx::Point center(view->width() / 2, view->height() / 2); |
| 278 views::View::ConvertPointToScreen(view, ¢er); | 278 views::View::ConvertPointToScreen(view, ¢er); |
| 279 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); | 279 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); |
| 280 generator.PressLeftButton(); | 280 generator.PressLeftButton(); |
| 281 EXPECT_TRUE(view->got_press()); | 281 EXPECT_TRUE(view->got_press()); |
| 282 | 282 |
| 283 views::Widget* modal_widget = | 283 views::Widget* modal_widget = |
| 284 views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView()); | 284 views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView()); |
| 285 scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView()); | 285 scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView()); |
| 286 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 286 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 287 views::test::CaptureTrackingView* modal_view = | 287 views::test::CaptureTrackingView* modal_view = |
| 288 new views::test::CaptureTrackingView; | 288 new views::test::CaptureTrackingView; |
| 289 modal_widget->client_view()->AddChildView(modal_view); | 289 modal_widget->client_view()->AddChildView(modal_view); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 // Modality should prevent events from being passed to the transient parent. | 342 // Modality should prevent events from being passed to the transient parent. |
| 343 TEST_F(WindowModalityControllerTest, TouchEvent) { | 343 TEST_F(WindowModalityControllerTest, TouchEvent) { |
| 344 TouchTrackerWindowDelegate d1; | 344 TouchTrackerWindowDelegate d1; |
| 345 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1, | 345 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(&d1, |
| 346 -1, gfx::Rect(0, 0, 100, 100))); | 346 -1, gfx::Rect(0, 0, 100, 100))); |
| 347 TouchTrackerWindowDelegate d11; | 347 TouchTrackerWindowDelegate d11; |
| 348 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11, | 348 scoped_ptr<aura::Window> w11(CreateTestWindowInShellWithDelegate(&d11, |
| 349 -11, gfx::Rect(20, 20, 50, 50))); | 349 -11, gfx::Rect(20, 20, 50, 50))); |
| 350 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 350 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 351 gfx::Point(10, 10)); | 351 gfx::Point(10, 10)); |
| 352 | 352 |
| 353 ::wm::AddTransientChild(w1.get(), w11.get()); | 353 ::wm::AddTransientChild(w1.get(), w11.get()); |
| 354 d1.reset(); | 354 d1.reset(); |
| 355 d11.reset(); | 355 d11.reset(); |
| 356 | 356 |
| 357 { | 357 { |
| 358 // Clicking a point within w1 should activate that window. | 358 // Clicking a point within w1 should activate that window. |
| 359 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); | 359 generator.PressMoveAndReleaseTouchTo(gfx::Point(10, 10)); |
| 360 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 360 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 361 EXPECT_TRUE(d1.received_touch()); | 361 EXPECT_TRUE(d1.received_touch()); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 472 |
| 473 EXPECT_TRUE(wm::IsActiveWindow(child)); | 473 EXPECT_TRUE(wm::IsActiveWindow(child)); |
| 474 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); | 474 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 475 EXPECT_FALSE(wm::IsActiveWindow(parent)); | 475 EXPECT_FALSE(wm::IsActiveWindow(parent)); |
| 476 | 476 |
| 477 EXPECT_TRUE(child->HasFocus()); | 477 EXPECT_TRUE(child->HasFocus()); |
| 478 EXPECT_FALSE(modal_parent->HasFocus()); | 478 EXPECT_FALSE(modal_parent->HasFocus()); |
| 479 EXPECT_FALSE(parent->HasFocus()); | 479 EXPECT_FALSE(parent->HasFocus()); |
| 480 | 480 |
| 481 { | 481 { |
| 482 ui::test::EventGenerator generator( | 482 aura::test::EventGenerator generator( |
| 483 Shell::GetPrimaryRootWindow(), | 483 Shell::GetPrimaryRootWindow(), |
| 484 parent->bounds().origin() + | 484 parent->bounds().origin() + |
| 485 gfx::Vector2d(10, parent->bounds().height() - 10)); | 485 gfx::Vector2d(10, parent->bounds().height() - 10)); |
| 486 generator.ClickLeftButton(); | 486 generator.ClickLeftButton(); |
| 487 generator.ClickLeftButton(); | 487 generator.ClickLeftButton(); |
| 488 | 488 |
| 489 EXPECT_TRUE(wm::IsActiveWindow(child)); | 489 EXPECT_TRUE(wm::IsActiveWindow(child)); |
| 490 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); | 490 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 491 EXPECT_FALSE(wm::IsActiveWindow(parent)); | 491 EXPECT_FALSE(wm::IsActiveWindow(parent)); |
| 492 | 492 |
| 493 EXPECT_TRUE(child->HasFocus()); | 493 EXPECT_TRUE(child->HasFocus()); |
| 494 EXPECT_FALSE(modal_parent->HasFocus()); | 494 EXPECT_FALSE(modal_parent->HasFocus()); |
| 495 EXPECT_FALSE(parent->HasFocus()); | 495 EXPECT_FALSE(parent->HasFocus()); |
| 496 } | 496 } |
| 497 | 497 |
| 498 { | 498 { |
| 499 ui::test::EventGenerator generator( | 499 aura::test::EventGenerator generator( |
| 500 Shell::GetPrimaryRootWindow(), | 500 Shell::GetPrimaryRootWindow(), |
| 501 parent->bounds().origin() + gfx::Vector2d(10, 10)); | 501 parent->bounds().origin() + gfx::Vector2d(10, 10)); |
| 502 generator.ClickLeftButton(); | 502 generator.ClickLeftButton(); |
| 503 | 503 |
| 504 EXPECT_FALSE(wm::IsActiveWindow(child)); | 504 EXPECT_FALSE(wm::IsActiveWindow(child)); |
| 505 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); | 505 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 506 EXPECT_TRUE(wm::IsActiveWindow(parent)); | 506 EXPECT_TRUE(wm::IsActiveWindow(parent)); |
| 507 | 507 |
| 508 EXPECT_FALSE(child->HasFocus()); | 508 EXPECT_FALSE(child->HasFocus()); |
| 509 EXPECT_FALSE(modal_parent->HasFocus()); | 509 EXPECT_FALSE(modal_parent->HasFocus()); |
| 510 EXPECT_TRUE(parent->HasFocus()); | 510 EXPECT_TRUE(parent->HasFocus()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 { | 513 { |
| 514 ui::test::EventGenerator generator( | 514 aura::test::EventGenerator generator( |
| 515 Shell::GetPrimaryRootWindow(), | 515 Shell::GetPrimaryRootWindow(), |
| 516 child->bounds().origin() + gfx::Vector2d(10, 10)); | 516 child->bounds().origin() + gfx::Vector2d(10, 10)); |
| 517 generator.ClickLeftButton(); | 517 generator.ClickLeftButton(); |
| 518 | 518 |
| 519 EXPECT_TRUE(wm::IsActiveWindow(child)); | 519 EXPECT_TRUE(wm::IsActiveWindow(child)); |
| 520 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); | 520 EXPECT_FALSE(wm::IsActiveWindow(modal_parent)); |
| 521 EXPECT_FALSE(wm::IsActiveWindow(parent)); | 521 EXPECT_FALSE(wm::IsActiveWindow(parent)); |
| 522 | 522 |
| 523 EXPECT_TRUE(child->HasFocus()); | 523 EXPECT_TRUE(child->HasFocus()); |
| 524 EXPECT_FALSE(modal_parent->HasFocus()); | 524 EXPECT_FALSE(modal_parent->HasFocus()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 577 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 578 | 578 |
| 579 wm::ActivateWindow(w3.get()); | 579 wm::ActivateWindow(w3.get()); |
| 580 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 580 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 581 | 581 |
| 582 wm::ActivateWindow(w4.get()); | 582 wm::ActivateWindow(w4.get()); |
| 583 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 583 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 584 } | 584 } |
| 585 | 585 |
| 586 } // namespace ash | 586 } // namespace ash |
| OLD | NEW |