| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/keyboard/keyboard_controller.h" | 5 #include "ui/keyboard/keyboard_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Multiple steps are required to complete complex animations. | 57 // Multiple steps are required to complete complex animations. |
| 58 // TODO(vollick): This should not be necessary. crbug.com/154017 | 58 // TODO(vollick): This should not be necessary. crbug.com/154017 |
| 59 while (controller.animator()->is_animating()) { | 59 while (controller.animator()->is_animating()) { |
| 60 controller.StartThreadedAnimationsIfNeeded(); | 60 controller.StartThreadedAnimationsIfNeeded(); |
| 61 base::TimeTicks step_time = controller.animator()->last_step_time(); | 61 base::TimeTicks step_time = controller.animator()->last_step_time(); |
| 62 controller.animator()->Step(step_time + | 62 controller.animator()->Step(step_time + |
| 63 base::TimeDelta::FromMilliseconds(1000)); | 63 base::TimeDelta::FromMilliseconds(1000)); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 class ScopedTouchKeyboardEnabler { |
| 68 public: |
| 69 ScopedTouchKeyboardEnabler() : enabled_(keyboard::GetTouchKeyboardEnabled()) { |
| 70 keyboard::SetTouchKeyboardEnabled(true); |
| 71 } |
| 72 |
| 73 ~ScopedTouchKeyboardEnabler() { keyboard::SetTouchKeyboardEnabled(enabled_); } |
| 74 |
| 75 private: |
| 76 const bool enabled_; |
| 77 }; |
| 78 |
| 79 class ScopedAccessibilityKeyboardEnabler { |
| 80 public: |
| 81 ScopedAccessibilityKeyboardEnabler() |
| 82 : enabled_(keyboard::GetAccessibilityKeyboardEnabled()) { |
| 83 keyboard::SetAccessibilityKeyboardEnabled(true); |
| 84 } |
| 85 |
| 86 ~ScopedAccessibilityKeyboardEnabler() { |
| 87 keyboard::SetAccessibilityKeyboardEnabled(enabled_); |
| 88 } |
| 89 |
| 90 private: |
| 91 const bool enabled_; |
| 92 }; |
| 93 |
| 67 // An event handler that focuses a window when it is clicked/touched on. This is | 94 // An event handler that focuses a window when it is clicked/touched on. This is |
| 68 // used to match the focus manger behaviour in ash and views. | 95 // used to match the focus manger behaviour in ash and views. |
| 69 class TestFocusController : public ui::EventHandler { | 96 class TestFocusController : public ui::EventHandler { |
| 70 public: | 97 public: |
| 71 explicit TestFocusController(aura::Window* root) | 98 explicit TestFocusController(aura::Window* root) |
| 72 : root_(root) { | 99 : root_(root) { |
| 73 root_->AddPreTargetHandler(this); | 100 root_->AddPreTargetHandler(this); |
| 74 } | 101 } |
| 75 | 102 |
| 76 ~TestFocusController() override { root_->RemovePreTargetHandler(this); } | 103 ~TestFocusController() override { root_->RemovePreTargetHandler(this); } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 controller()->SetKeyboardMode(FLOATING); | 395 controller()->SetKeyboardMode(FLOATING); |
| 369 container->AddChild(keyboard); | 396 container->AddChild(keyboard); |
| 370 gfx::Rect new_bounds(0, 50, 50, 50); | 397 gfx::Rect new_bounds(0, 50, 50, 50); |
| 371 keyboard->SetBounds(new_bounds); | 398 keyboard->SetBounds(new_bounds); |
| 372 ASSERT_EQ(new_bounds, container->bounds()); | 399 ASSERT_EQ(new_bounds, container->bounds()); |
| 373 VerifyKeyboardWindowSize(container, keyboard); | 400 VerifyKeyboardWindowSize(container, keyboard); |
| 374 } | 401 } |
| 375 | 402 |
| 376 // Tests that tapping/clicking inside the keyboard does not give it focus. | 403 // Tests that tapping/clicking inside the keyboard does not give it focus. |
| 377 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 404 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
| 378 keyboard::SetAccessibilityKeyboardEnabled(true); | 405 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 379 const gfx::Rect& root_bounds = root_window()->bounds(); | 406 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 380 aura::test::EventCountDelegate delegate; | 407 aura::test::EventCountDelegate delegate; |
| 381 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); | 408 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 382 window->Init(ui::LAYER_NOT_DRAWN); | 409 window->Init(ui::LAYER_NOT_DRAWN); |
| 383 window->SetBounds(root_bounds); | 410 window->SetBounds(root_bounds); |
| 384 root_window()->AddChild(window.get()); | 411 root_window()->AddChild(window.get()); |
| 385 window->Show(); | 412 window->Show(); |
| 386 window->Focus(); | 413 window->Focus(); |
| 387 | 414 |
| 388 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 415 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 409 EXPECT_FALSE(keyboard_container->HasFocus()); | 436 EXPECT_FALSE(keyboard_container->HasFocus()); |
| 410 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); | 437 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); |
| 411 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); | 438 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 412 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); | 439 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); |
| 413 | 440 |
| 414 // Click outside of the keyboard. It should reach the window behind. | 441 // Click outside of the keyboard. It should reach the window behind. |
| 415 generator.MoveMouseTo(gfx::Point()); | 442 generator.MoveMouseTo(gfx::Point()); |
| 416 generator.ClickLeftButton(); | 443 generator.ClickLeftButton(); |
| 417 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 444 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 418 keyboard_container->RemovePreTargetHandler(&observer); | 445 keyboard_container->RemovePreTargetHandler(&observer); |
| 419 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 420 } | 446 } |
| 421 | 447 |
| 422 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 448 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 423 keyboard::SetAccessibilityKeyboardEnabled(true); | 449 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 424 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 450 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 425 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 451 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 426 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 452 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 427 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 453 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 428 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 454 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 429 | 455 |
| 430 base::RunLoop run_loop; | 456 base::RunLoop run_loop; |
| 431 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 457 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 432 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 458 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 433 new KeyboardContainerObserver(keyboard_container, &run_loop)); | 459 new KeyboardContainerObserver(keyboard_container, &run_loop)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 450 EXPECT_TRUE(keyboard_container->IsVisible()); | 476 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 451 | 477 |
| 452 // Schedule to hide keyboard. | 478 // Schedule to hide keyboard. |
| 453 SetFocus(&no_input_client_1); | 479 SetFocus(&no_input_client_1); |
| 454 EXPECT_TRUE(WillHideKeyboard()); | 480 EXPECT_TRUE(WillHideKeyboard()); |
| 455 // Cancel keyboard hide. | 481 // Cancel keyboard hide. |
| 456 SetFocus(&input_client_2); | 482 SetFocus(&input_client_2); |
| 457 | 483 |
| 458 EXPECT_FALSE(WillHideKeyboard()); | 484 EXPECT_FALSE(WillHideKeyboard()); |
| 459 EXPECT_TRUE(keyboard_container->IsVisible()); | 485 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 460 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 461 } | 486 } |
| 462 | 487 |
| 463 // Test to prevent spurious overscroll boxes when changing tabs during keyboard | 488 // Test to prevent spurious overscroll boxes when changing tabs during keyboard |
| 464 // hide. Refer to crbug.com/401670 for more context. | 489 // hide. Refer to crbug.com/401670 for more context. |
| 465 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { | 490 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { |
| 466 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 491 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 467 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 492 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 468 | 493 |
| 469 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 494 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 470 root_window()->AddChild(keyboard_container); | 495 root_window()->AddChild(keyboard_container); |
| 471 | 496 |
| 472 // Enable touch keyboard / overscroll mode to test insets. | 497 // Enable touch keyboard / overscroll mode to test insets. |
| 473 keyboard::SetTouchKeyboardEnabled(true); | 498 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 474 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 499 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
| 475 | 500 |
| 476 SetFocus(&input_client); | 501 SetFocus(&input_client); |
| 477 SetFocus(&no_input_client); | 502 SetFocus(&no_input_client); |
| 478 // Insets should not be enabled for new windows while keyboard is in the | 503 // Insets should not be enabled for new windows while keyboard is in the |
| 479 // process of hiding when overscroll is enabled. | 504 // process of hiding when overscroll is enabled. |
| 480 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 505 EXPECT_FALSE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 481 // Cancel keyboard hide. | 506 // Cancel keyboard hide. |
| 482 SetFocus(&input_client); | 507 SetFocus(&input_client); |
| 483 // Insets should be enabled for new windows as hide was cancelled. | 508 // Insets should be enabled for new windows as hide was cancelled. |
| 484 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); | 509 EXPECT_TRUE(ShouldEnableInsets(ui()->GetKeyboardWindow())); |
| 485 } | 510 } |
| 486 | 511 |
| 487 // Verify switch to FLOATING mode will reset the overscroll or resize and when | 512 // Verify switch to FLOATING mode will reset the overscroll or resize and when |
| 488 // in FLOATING mode, overscroll or resize wont be triggered. | 513 // in FLOATING mode, overscroll or resize wont be triggered. |
| 489 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { | 514 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { |
| 490 keyboard::SetAccessibilityKeyboardEnabled(true); | 515 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 491 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 516 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 492 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 517 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 493 | 518 |
| 494 base::RunLoop run_loop; | 519 base::RunLoop run_loop; |
| 495 aura::Window* container(controller()->GetContainerWindow()); | 520 aura::Window* container(controller()->GetContainerWindow()); |
| 496 root_window()->AddChild(container); | 521 root_window()->AddChild(container); |
| 497 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 522 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 498 new KeyboardContainerObserver(container, &run_loop)); | 523 new KeyboardContainerObserver(container, &run_loop)); |
| 499 gfx::Rect screen_bounds = root_window()->bounds(); | 524 gfx::Rect screen_bounds = root_window()->bounds(); |
| 500 keyboard::SetTouchKeyboardEnabled(true); | 525 ScopedTouchKeyboardEnabler scoped_touch_keyboard_enabler; |
| 501 | 526 |
| 502 SetFocus(&input_client); | 527 SetFocus(&input_client); |
| 503 gfx::Rect expected_bounds( | 528 gfx::Rect expected_bounds( |
| 504 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 529 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 505 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 530 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 506 // Verify overscroll or resize is in effect. | 531 // Verify overscroll or resize is in effect. |
| 507 EXPECT_EQ(expected_bounds, notified_bounds()); | 532 EXPECT_EQ(expected_bounds, notified_bounds()); |
| 508 EXPECT_EQ(1, number_of_calls()); | 533 EXPECT_EQ(1, number_of_calls()); |
| 509 | 534 |
| 510 controller()->SetKeyboardMode(FLOATING); | 535 controller()->SetKeyboardMode(FLOATING); |
| 511 // Switch to FLOATING should clear overscroll or resize. | 536 // Switch to FLOATING should clear overscroll or resize. |
| 512 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 537 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 513 EXPECT_EQ(2, number_of_calls()); | 538 EXPECT_EQ(2, number_of_calls()); |
| 514 SetFocus(&no_input_client); | 539 SetFocus(&no_input_client); |
| 515 run_loop.Run(); | 540 run_loop.Run(); |
| 516 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 541 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 517 EXPECT_EQ(3, number_of_calls()); | 542 EXPECT_EQ(3, number_of_calls()); |
| 518 SetFocus(&input_client); | 543 SetFocus(&input_client); |
| 519 // In FLOATING mode, no overscroll or resize should be triggered. | 544 // In FLOATING mode, no overscroll or resize should be triggered. |
| 520 EXPECT_EQ(3, number_of_calls()); | 545 EXPECT_EQ(3, number_of_calls()); |
| 521 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 546 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 522 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 523 } | 547 } |
| 524 | 548 |
| 525 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right | 549 // Verify switch to FULL_WIDTH mode will move virtual keyboard to the right |
| 526 // place and sets the correct overscroll. | 550 // place and sets the correct overscroll. |
| 527 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { | 551 TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) { |
| 552 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 528 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 553 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 529 | 554 |
| 530 aura::Window* container(controller()->GetContainerWindow()); | 555 aura::Window* container(controller()->GetContainerWindow()); |
| 531 root_window()->AddChild(container); | 556 root_window()->AddChild(container); |
| 532 gfx::Rect screen_bounds = root_window()->bounds(); | 557 gfx::Rect screen_bounds = root_window()->bounds(); |
| 533 keyboard::SetTouchKeyboardEnabled(true); | |
| 534 SetFocus(&input_client); | 558 SetFocus(&input_client); |
| 535 | 559 |
| 536 controller()->SetKeyboardMode(FLOATING); | 560 controller()->SetKeyboardMode(FLOATING); |
| 537 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 561 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 538 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); | 562 EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds()); |
| 539 | 563 |
| 540 controller()->SetKeyboardMode(FULL_WIDTH); | 564 controller()->SetKeyboardMode(FULL_WIDTH); |
| 541 gfx::Rect expected_bounds( | 565 gfx::Rect expected_bounds( |
| 542 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 566 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 543 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 567 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 544 EXPECT_EQ(expected_bounds, notified_bounds()); | 568 EXPECT_EQ(expected_bounds, notified_bounds()); |
| 545 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); | 569 EXPECT_EQ(expected_bounds, controller()->current_keyboard_bounds()); |
| 546 } | 570 } |
| 547 | 571 |
| 548 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 572 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 549 keyboard::SetAccessibilityKeyboardEnabled(true); | 573 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 550 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 574 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 551 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 575 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 552 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 576 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 553 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 577 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 554 | 578 |
| 555 base::RunLoop run_loop; | 579 base::RunLoop run_loop; |
| 556 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 580 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 557 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( | 581 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 558 new KeyboardContainerObserver(keyboard_container, &run_loop)); | 582 new KeyboardContainerObserver(keyboard_container, &run_loop)); |
| 559 root_window()->AddChild(keyboard_container); | 583 root_window()->AddChild(keyboard_container); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 576 // Unlock keyboard. | 600 // Unlock keyboard. |
| 577 controller()->set_keyboard_locked(false); | 601 controller()->set_keyboard_locked(false); |
| 578 | 602 |
| 579 // Keyboard should hide when focus on no input client. | 603 // Keyboard should hide when focus on no input client. |
| 580 SetFocus(&no_input_client_1); | 604 SetFocus(&no_input_client_1); |
| 581 EXPECT_TRUE(WillHideKeyboard()); | 605 EXPECT_TRUE(WillHideKeyboard()); |
| 582 | 606 |
| 583 // Wait for hide keyboard to finish. | 607 // Wait for hide keyboard to finish. |
| 584 run_loop.Run(); | 608 run_loop.Run(); |
| 585 EXPECT_FALSE(keyboard_container->IsVisible()); | 609 EXPECT_FALSE(keyboard_container->IsVisible()); |
| 586 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 587 } | 610 } |
| 588 | 611 |
| 589 // Tests that deactivates keyboard will get closed event. | 612 // Tests that deactivates keyboard will get closed event. |
| 590 TEST_F(KeyboardControllerTest, CloseKeyboard) { | 613 TEST_F(KeyboardControllerTest, CloseKeyboard) { |
| 591 keyboard::SetAccessibilityKeyboardEnabled(true); | 614 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 592 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 615 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 593 root_window()->AddChild(keyboard_container); | 616 root_window()->AddChild(keyboard_container); |
| 594 keyboard_container->Show(); | 617 keyboard_container->Show(); |
| 595 | 618 |
| 596 ShowKeyboard(); | 619 ShowKeyboard(); |
| 597 EXPECT_TRUE(keyboard_container->IsVisible()); | 620 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 598 EXPECT_FALSE(IsKeyboardClosed()); | 621 EXPECT_FALSE(IsKeyboardClosed()); |
| 599 | 622 |
| 600 root_window()->RemoveChild(keyboard_container); | 623 root_window()->RemoveChild(keyboard_container); |
| 601 ResetController(); | 624 ResetController(); |
| 602 EXPECT_TRUE(IsKeyboardClosed()); | 625 EXPECT_TRUE(IsKeyboardClosed()); |
| 603 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 604 } | 626 } |
| 605 | 627 |
| 606 class KeyboardControllerAnimationTest : public KeyboardControllerTest { | 628 class KeyboardControllerAnimationTest : public KeyboardControllerTest { |
| 607 public: | 629 public: |
| 608 KeyboardControllerAnimationTest() {} | 630 KeyboardControllerAnimationTest() {} |
| 609 ~KeyboardControllerAnimationTest() override {} | 631 ~KeyboardControllerAnimationTest() override {} |
| 610 | 632 |
| 611 void SetUp() override { | 633 void SetUp() override { |
| 612 // We cannot short-circuit animations for this test. | 634 // We cannot short-circuit animations for this test. |
| 613 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 635 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 632 aura::Window* keyboard_window() { | 654 aura::Window* keyboard_window() { |
| 633 return ui()->GetKeyboardWindow(); | 655 return ui()->GetKeyboardWindow(); |
| 634 } | 656 } |
| 635 | 657 |
| 636 private: | 658 private: |
| 637 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); | 659 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerAnimationTest); |
| 638 }; | 660 }; |
| 639 | 661 |
| 640 // Tests virtual keyboard has correct show and hide animation. | 662 // Tests virtual keyboard has correct show and hide animation. |
| 641 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { | 663 TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) { |
| 664 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 642 ui::Layer* layer = keyboard_container()->layer(); | 665 ui::Layer* layer = keyboard_container()->layer(); |
| 643 keyboard::SetAccessibilityKeyboardEnabled(true); | |
| 644 ShowKeyboard(); | 666 ShowKeyboard(); |
| 645 | 667 |
| 646 // Keyboard container and window should immediately become visible before | 668 // Keyboard container and window should immediately become visible before |
| 647 // animation starts. | 669 // animation starts. |
| 648 EXPECT_TRUE(keyboard_container()->IsVisible()); | 670 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 649 EXPECT_TRUE(keyboard_window()->IsVisible()); | 671 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 650 float show_start_opacity = layer->opacity(); | 672 float show_start_opacity = layer->opacity(); |
| 651 gfx::Transform transform; | 673 gfx::Transform transform; |
| 652 transform.Translate(0, kAnimationDistance); | 674 transform.Translate(0, kAnimationDistance); |
| 653 EXPECT_EQ(transform, layer->transform()); | 675 EXPECT_EQ(transform, layer->transform()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 674 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 696 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 675 | 697 |
| 676 RunAnimationForLayer(layer); | 698 RunAnimationForLayer(layer); |
| 677 EXPECT_FALSE(keyboard_container()->IsVisible()); | 699 EXPECT_FALSE(keyboard_container()->IsVisible()); |
| 678 EXPECT_FALSE(keyboard_container()->layer()->visible()); | 700 EXPECT_FALSE(keyboard_container()->layer()->visible()); |
| 679 EXPECT_FALSE(keyboard_window()->IsVisible()); | 701 EXPECT_FALSE(keyboard_window()->IsVisible()); |
| 680 float hide_end_opacity = layer->opacity(); | 702 float hide_end_opacity = layer->opacity(); |
| 681 EXPECT_GT(hide_start_opacity, hide_end_opacity); | 703 EXPECT_GT(hide_start_opacity, hide_end_opacity); |
| 682 EXPECT_EQ(transform, layer->transform()); | 704 EXPECT_EQ(transform, layer->transform()); |
| 683 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 705 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 684 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 685 } | 706 } |
| 686 | 707 |
| 687 // Show keyboard during keyboard hide animation should abort the hide animation | 708 // Show keyboard during keyboard hide animation should abort the hide animation |
| 688 // and the keyboard should animate in. | 709 // and the keyboard should animate in. |
| 689 // Test for crbug.com/333284. | 710 // Test for crbug.com/333284. |
| 690 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { | 711 TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) { |
| 691 keyboard::SetAccessibilityKeyboardEnabled(true); | 712 ScopedAccessibilityKeyboardEnabler scoped_keyboard_enabler; |
| 692 ui::Layer* layer = keyboard_container()->layer(); | 713 ui::Layer* layer = keyboard_container()->layer(); |
| 693 ShowKeyboard(); | 714 ShowKeyboard(); |
| 694 RunAnimationForLayer(layer); | 715 RunAnimationForLayer(layer); |
| 695 | 716 |
| 696 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); | 717 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); |
| 697 // Before hide animation finishes, show keyboard again. | 718 // Before hide animation finishes, show keyboard again. |
| 698 ShowKeyboard(); | 719 ShowKeyboard(); |
| 699 RunAnimationForLayer(layer); | 720 RunAnimationForLayer(layer); |
| 700 EXPECT_TRUE(keyboard_container()->IsVisible()); | 721 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 701 EXPECT_TRUE(keyboard_window()->IsVisible()); | 722 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 702 EXPECT_EQ(1.0, layer->opacity()); | 723 EXPECT_EQ(1.0, layer->opacity()); |
| 703 EXPECT_EQ(gfx::Transform(), layer->transform()); | 724 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 704 keyboard::SetAccessibilityKeyboardEnabled(false); | |
| 705 } | 725 } |
| 706 | 726 |
| 707 // Test for crbug.com/568274. | 727 // Test for crbug.com/568274. |
| 708 TEST_F(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { | 728 TEST_F(KeyboardControllerTest, FloatingKeyboardShowOnFirstTap) { |
| 729 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 709 aura::Window* container(controller()->GetContainerWindow()); | 730 aura::Window* container(controller()->GetContainerWindow()); |
| 710 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 731 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 711 root_window()->AddChild(container); | 732 root_window()->AddChild(container); |
| 712 | 733 |
| 713 keyboard::SetTouchKeyboardEnabled(true); | |
| 714 controller()->SetKeyboardMode(FLOATING); | 734 controller()->SetKeyboardMode(FLOATING); |
| 715 container->AddChild(keyboard); | 735 container->AddChild(keyboard); |
| 716 // Mock focus on an input field. | 736 // Mock focus on an input field. |
| 717 ui()->GetInputMethod()->ShowImeIfNeeded(); | 737 ui()->GetInputMethod()->ShowImeIfNeeded(); |
| 718 // Mock set keyboard size from javascript side. In floating mode, virtual | 738 // Mock set keyboard size from javascript side. In floating mode, virtual |
| 719 // keyboard's size is decided by client. | 739 // keyboard's size is decided by client. |
| 720 gfx::Rect new_bounds(0, 50, 50, 50); | 740 gfx::Rect new_bounds(0, 50, 50, 50); |
| 721 keyboard->SetBounds(new_bounds); | 741 keyboard->SetBounds(new_bounds); |
| 722 ASSERT_EQ(new_bounds, container->bounds()); | 742 ASSERT_EQ(new_bounds, container->bounds()); |
| 723 EXPECT_TRUE(keyboard->IsVisible()); | 743 EXPECT_TRUE(keyboard->IsVisible()); |
| 724 EXPECT_TRUE(container->IsVisible()); | 744 EXPECT_TRUE(container->IsVisible()); |
| 725 } | 745 } |
| 726 | 746 |
| 727 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { | 747 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { |
| 748 ScopedTouchKeyboardEnabler scoped_keyboard_enabler; |
| 728 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 749 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 729 | 750 |
| 730 aura::Window* container(controller()->GetContainerWindow()); | 751 aura::Window* container(controller()->GetContainerWindow()); |
| 731 root_window()->AddChild(container); | 752 root_window()->AddChild(container); |
| 732 | 753 |
| 733 keyboard::SetTouchKeyboardEnabled(true); | |
| 734 controller()->SetKeyboardMode(FULL_WIDTH); | 754 controller()->SetKeyboardMode(FULL_WIDTH); |
| 735 SetFocus(&input_client); | 755 SetFocus(&input_client); |
| 736 gfx::Rect new_bounds(0, 0, 1280, 800); | 756 gfx::Rect new_bounds(0, 0, 1280, 800); |
| 737 ASSERT_NE(new_bounds, root_window()->bounds()); | 757 ASSERT_NE(new_bounds, root_window()->bounds()); |
| 738 EXPECT_EQ(1, number_of_calls()); | 758 EXPECT_EQ(1, number_of_calls()); |
| 739 root_window()->SetBounds(new_bounds); | 759 root_window()->SetBounds(new_bounds); |
| 740 EXPECT_EQ(2, number_of_calls()); | 760 EXPECT_EQ(2, number_of_calls()); |
| 741 MockRotateScreen(); | 761 MockRotateScreen(); |
| 742 EXPECT_EQ(3, number_of_calls()); | 762 EXPECT_EQ(3, number_of_calls()); |
| 743 } | 763 } |
| 744 | 764 |
| 745 } // namespace keyboard | 765 } // namespace keyboard |
| OLD | NEW |