| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/aura/client/focus_client.h" | 14 #include "ui/aura/client/focus_client.h" |
| 14 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
| 15 #include "ui/aura/test/aura_test_helper.h" | 16 #include "ui/aura/test/aura_test_helper.h" |
| 16 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 19 #include "ui/base/ime/dummy_text_input_client.h" | 20 #include "ui/base/ime/dummy_text_input_client.h" |
| 20 #include "ui/base/ime/input_method.h" | 21 #include "ui/base/ime/input_method.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 109 } |
| 109 return window_.get(); | 110 return window_.get(); |
| 110 } | 111 } |
| 111 ui::InputMethod* GetInputMethod() override { return input_method_; } | 112 ui::InputMethod* GetInputMethod() override { return input_method_; } |
| 112 void SetUpdateInputType(ui::TextInputType type) override {} | 113 void SetUpdateInputType(ui::TextInputType type) override {} |
| 113 void ReloadKeyboardIfNeeded() override {}; | 114 void ReloadKeyboardIfNeeded() override {}; |
| 114 void InitInsets(const gfx::Rect& keyboard_bounds) override {} | 115 void InitInsets(const gfx::Rect& keyboard_bounds) override {} |
| 115 void ResetInsets() override {} | 116 void ResetInsets() override {} |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 scoped_ptr<aura::Window> window_; | 119 std::unique_ptr<aura::Window> window_; |
| 119 aura::test::TestWindowDelegate delegate_; | 120 aura::test::TestWindowDelegate delegate_; |
| 120 ui::InputMethod* input_method_; | 121 ui::InputMethod* input_method_; |
| 121 | 122 |
| 122 DISALLOW_COPY_AND_ASSIGN(TestKeyboardUI); | 123 DISALLOW_COPY_AND_ASSIGN(TestKeyboardUI); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 // Keeps a count of all the events a window receives. | 126 // Keeps a count of all the events a window receives. |
| 126 class EventObserver : public ui::EventHandler { | 127 class EventObserver : public ui::EventHandler { |
| 127 public: | 128 public: |
| 128 EventObserver() {} | 129 EventObserver() {} |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 244 |
| 244 bool ShouldEnableInsets(aura::Window* window) { | 245 bool ShouldEnableInsets(aura::Window* window) { |
| 245 aura::Window* keyboard_window = ui_->GetKeyboardWindow(); | 246 aura::Window* keyboard_window = ui_->GetKeyboardWindow(); |
| 246 return (keyboard_window->GetRootWindow() == window->GetRootWindow() && | 247 return (keyboard_window->GetRootWindow() == window->GetRootWindow() && |
| 247 keyboard::IsKeyboardOverscrollEnabled() && | 248 keyboard::IsKeyboardOverscrollEnabled() && |
| 248 keyboard_window->IsVisible() && | 249 keyboard_window->IsVisible() && |
| 249 controller_->keyboard_visible()); | 250 controller_->keyboard_visible()); |
| 250 } | 251 } |
| 251 | 252 |
| 252 base::MessageLoopForUI message_loop_; | 253 base::MessageLoopForUI message_loop_; |
| 253 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 254 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 254 scoped_ptr<TestFocusController> focus_controller_; | 255 std::unique_ptr<TestFocusController> focus_controller_; |
| 255 | 256 |
| 256 private: | 257 private: |
| 257 int number_of_calls_; | 258 int number_of_calls_; |
| 258 gfx::Rect notified_bounds_; | 259 gfx::Rect notified_bounds_; |
| 259 KeyboardUI* ui_; | 260 KeyboardUI* ui_; |
| 260 scoped_ptr<KeyboardController> controller_; | 261 std::unique_ptr<KeyboardController> controller_; |
| 261 scoped_ptr<ui::TextInputClient> test_text_input_client_; | 262 std::unique_ptr<ui::TextInputClient> test_text_input_client_; |
| 262 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 263 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
| 263 }; | 264 }; |
| 264 | 265 |
| 265 TEST_F(KeyboardControllerTest, KeyboardSize) { | 266 TEST_F(KeyboardControllerTest, KeyboardSize) { |
| 266 aura::Window* container(controller()->GetContainerWindow()); | 267 aura::Window* container(controller()->GetContainerWindow()); |
| 267 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 268 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 268 gfx::Rect screen_bounds = root_window()->bounds(); | 269 gfx::Rect screen_bounds = root_window()->bounds(); |
| 269 root_window()->AddChild(container); | 270 root_window()->AddChild(container); |
| 270 container->AddChild(keyboard); | 271 container->AddChild(keyboard); |
| 271 const gfx::Rect& initial_bounds = container->bounds(); | 272 const gfx::Rect& initial_bounds = container->bounds(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 keyboard->SetBounds(new_bounds); | 313 keyboard->SetBounds(new_bounds); |
| 313 ASSERT_EQ(new_bounds, container->bounds()); | 314 ASSERT_EQ(new_bounds, container->bounds()); |
| 314 VerifyKeyboardWindowSize(container, keyboard); | 315 VerifyKeyboardWindowSize(container, keyboard); |
| 315 } | 316 } |
| 316 | 317 |
| 317 // Tests that tapping/clicking inside the keyboard does not give it focus. | 318 // Tests that tapping/clicking inside the keyboard does not give it focus. |
| 318 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 319 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
| 319 keyboard::SetAccessibilityKeyboardEnabled(true); | 320 keyboard::SetAccessibilityKeyboardEnabled(true); |
| 320 const gfx::Rect& root_bounds = root_window()->bounds(); | 321 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 321 aura::test::EventCountDelegate delegate; | 322 aura::test::EventCountDelegate delegate; |
| 322 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 323 std::unique_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 323 window->Init(ui::LAYER_NOT_DRAWN); | 324 window->Init(ui::LAYER_NOT_DRAWN); |
| 324 window->SetBounds(root_bounds); | 325 window->SetBounds(root_bounds); |
| 325 root_window()->AddChild(window.get()); | 326 root_window()->AddChild(window.get()); |
| 326 window->Show(); | 327 window->Show(); |
| 327 window->Focus(); | 328 window->Focus(); |
| 328 | 329 |
| 329 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 330 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 330 | 331 |
| 331 root_window()->AddChild(keyboard_container); | 332 root_window()->AddChild(keyboard_container); |
| 332 keyboard_container->Show(); | 333 keyboard_container->Show(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 362 | 363 |
| 363 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 364 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 364 keyboard::SetAccessibilityKeyboardEnabled(true); | 365 keyboard::SetAccessibilityKeyboardEnabled(true); |
| 365 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 366 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 366 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 367 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 367 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 368 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 368 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 369 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 369 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 370 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 370 | 371 |
| 371 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 372 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 372 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 373 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 373 new KeyboardContainerObserver(keyboard_container)); | 374 new KeyboardContainerObserver(keyboard_container)); |
| 374 root_window()->AddChild(keyboard_container); | 375 root_window()->AddChild(keyboard_container); |
| 375 | 376 |
| 376 SetFocus(&input_client_0); | 377 SetFocus(&input_client_0); |
| 377 | 378 |
| 378 EXPECT_TRUE(keyboard_container->IsVisible()); | 379 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 379 | 380 |
| 380 SetFocus(&no_input_client_0); | 381 SetFocus(&no_input_client_0); |
| 381 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 382 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
| 382 // flicker when the focus of input field quickly change. | 383 // flicker when the focus of input field quickly change. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 427 |
| 427 // Verify switch to FLOATING mode will reset the overscroll or resize and when | 428 // Verify switch to FLOATING mode will reset the overscroll or resize and when |
| 428 // in FLOATING mode, overscroll or resize wont be triggered. | 429 // in FLOATING mode, overscroll or resize wont be triggered. |
| 429 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { | 430 TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) { |
| 430 keyboard::SetAccessibilityKeyboardEnabled(true); | 431 keyboard::SetAccessibilityKeyboardEnabled(true); |
| 431 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 432 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 432 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 433 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 433 | 434 |
| 434 aura::Window* container(controller()->GetContainerWindow()); | 435 aura::Window* container(controller()->GetContainerWindow()); |
| 435 root_window()->AddChild(container); | 436 root_window()->AddChild(container); |
| 436 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 437 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 437 new KeyboardContainerObserver(container)); | 438 new KeyboardContainerObserver(container)); |
| 438 gfx::Rect screen_bounds = root_window()->bounds(); | 439 gfx::Rect screen_bounds = root_window()->bounds(); |
| 439 keyboard::SetTouchKeyboardEnabled(true); | 440 keyboard::SetTouchKeyboardEnabled(true); |
| 440 | 441 |
| 441 SetFocus(&input_client); | 442 SetFocus(&input_client); |
| 442 gfx::Rect expected_bounds( | 443 gfx::Rect expected_bounds( |
| 443 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, | 444 0, screen_bounds.height() - kDefaultVirtualKeyboardHeight, |
| 444 screen_bounds.width(), kDefaultVirtualKeyboardHeight); | 445 screen_bounds.width(), kDefaultVirtualKeyboardHeight); |
| 445 // Verify overscroll or resize is in effect. | 446 // Verify overscroll or resize is in effect. |
| 446 EXPECT_EQ(expected_bounds, notified_bounds()); | 447 EXPECT_EQ(expected_bounds, notified_bounds()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 } | 486 } |
| 486 | 487 |
| 487 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 488 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 488 keyboard::SetAccessibilityKeyboardEnabled(true); | 489 keyboard::SetAccessibilityKeyboardEnabled(true); |
| 489 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 490 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 490 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 491 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 491 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 492 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 492 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 493 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 493 | 494 |
| 494 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 495 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 495 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 496 std::unique_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 496 new KeyboardContainerObserver(keyboard_container)); | 497 new KeyboardContainerObserver(keyboard_container)); |
| 497 root_window()->AddChild(keyboard_container); | 498 root_window()->AddChild(keyboard_container); |
| 498 | 499 |
| 499 SetFocus(&input_client_0); | 500 SetFocus(&input_client_0); |
| 500 | 501 |
| 501 EXPECT_TRUE(keyboard_container->IsVisible()); | 502 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 502 | 503 |
| 503 // Lock keyboard. | 504 // Lock keyboard. |
| 504 controller()->set_lock_keyboard(true); | 505 controller()->set_lock_keyboard(true); |
| 505 | 506 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 // Mock set keyboard size from javascript side. In floating mode, virtual | 638 // Mock set keyboard size from javascript side. In floating mode, virtual |
| 638 // keyboard's size is decided by client. | 639 // keyboard's size is decided by client. |
| 639 gfx::Rect new_bounds(0, 50, 50, 50); | 640 gfx::Rect new_bounds(0, 50, 50, 50); |
| 640 keyboard->SetBounds(new_bounds); | 641 keyboard->SetBounds(new_bounds); |
| 641 ASSERT_EQ(new_bounds, container->bounds()); | 642 ASSERT_EQ(new_bounds, container->bounds()); |
| 642 EXPECT_TRUE(keyboard->IsVisible()); | 643 EXPECT_TRUE(keyboard->IsVisible()); |
| 643 EXPECT_TRUE(container->IsVisible()); | 644 EXPECT_TRUE(container->IsVisible()); |
| 644 } | 645 } |
| 645 | 646 |
| 646 } // namespace keyboard | 647 } // namespace keyboard |
| OLD | NEW |