| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 aura::Window* root_; | 80 aura::Window* root_; |
| 81 DISALLOW_COPY_AND_ASSIGN(TestFocusController); | 81 DISALLOW_COPY_AND_ASSIGN(TestFocusController); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 class TestKeyboardControllerProxy : public KeyboardControllerProxy { | 84 class TestKeyboardControllerProxy : public KeyboardControllerProxy { |
| 85 public: | 85 public: |
| 86 TestKeyboardControllerProxy() | 86 TestKeyboardControllerProxy() |
| 87 : window_(new aura::Window(&delegate_)), | 87 : input_method_( |
| 88 input_method_(ui::CreateInputMethod(NULL, | 88 ui::CreateInputMethod(NULL, gfx::kNullAcceleratedWidget)) {} |
| 89 gfx::kNullAcceleratedWidget)) { | |
| 90 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
| 91 window_->set_owned_by_parent(false); | |
| 92 } | |
| 93 | 89 |
| 94 virtual ~TestKeyboardControllerProxy() { | 90 virtual ~TestKeyboardControllerProxy() { |
| 95 // Destroy the window before the delegate. | 91 // Destroy the window before the delegate. |
| 96 window_.reset(); | 92 window_.reset(); |
| 97 } | 93 } |
| 98 | 94 |
| 99 // Overridden from KeyboardControllerProxy: | 95 // Overridden from KeyboardControllerProxy: |
| 100 virtual bool HasKeyboardWindow() const OVERRIDE { return true; } | 96 virtual bool HasKeyboardWindow() const OVERRIDE { return window_; } |
| 101 virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); } | 97 virtual aura::Window* GetKeyboardWindow() OVERRIDE { |
| 98 if (!window_) { |
| 99 window_.reset(new aura::Window(&delegate_)); |
| 100 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 101 window_->set_owned_by_parent(false); |
| 102 } |
| 103 return window_.get(); |
| 104 } |
| 102 virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; } | 105 virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; } |
| 103 virtual ui::InputMethod* GetInputMethod() OVERRIDE { | 106 virtual ui::InputMethod* GetInputMethod() OVERRIDE { |
| 104 return input_method_.get(); | 107 return input_method_.get(); |
| 105 } | 108 } |
| 106 virtual void RequestAudioInput(content::WebContents* web_contents, | 109 virtual void RequestAudioInput(content::WebContents* web_contents, |
| 107 const content::MediaStreamRequest& request, | 110 const content::MediaStreamRequest& request, |
| 108 const content::MediaResponseCallback& callback) OVERRIDE { return; } | 111 const content::MediaResponseCallback& callback) OVERRIDE { return; } |
| 109 virtual void LoadSystemKeyboard() OVERRIDE {}; | 112 virtual void LoadSystemKeyboard() OVERRIDE {}; |
| 110 virtual void ReloadKeyboardIfNeeded() OVERRIDE {}; | 113 virtual void ReloadKeyboardIfNeeded() OVERRIDE {}; |
| 111 | 114 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, | 341 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, |
| 339 ui::EF_NONE); | 342 ui::EF_NONE); |
| 340 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); | 343 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); |
| 341 | 344 |
| 342 location.set_y(keyboard_window->bounds().y() - 5); | 345 location.set_y(keyboard_window->bounds().y() - 5); |
| 343 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, | 346 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, |
| 344 ui::EF_NONE); | 347 ui::EF_NONE); |
| 345 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); | 348 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); |
| 346 } | 349 } |
| 347 | 350 |
| 351 TEST_F(KeyboardControllerTest, KeyboardWindowCreation) { |
| 352 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 353 aura::test::EventCountDelegate delegate; |
| 354 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 355 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 356 window->SetBounds(root_bounds); |
| 357 root_window()->AddChild(window.get()); |
| 358 window->Show(); |
| 359 window->Focus(); |
| 360 |
| 361 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 362 keyboard_container->SetBounds(root_bounds); |
| 363 |
| 364 root_window()->AddChild(keyboard_container); |
| 365 keyboard_container->Show(); |
| 366 |
| 367 EXPECT_FALSE(proxy()->HasKeyboardWindow()); |
| 368 |
| 369 ui::EventTarget* root = root_window(); |
| 370 ui::EventTargeter* targeter = root->GetEventTargeter(); |
| 371 gfx::Point location(root_window()->bounds().width() / 2, |
| 372 root_window()->bounds().height() - 10); |
| 373 ui::MouseEvent mouse( |
| 374 ui::ET_MOUSE_MOVED, location, location, ui::EF_NONE, ui::EF_NONE); |
| 375 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse)); |
| 376 EXPECT_FALSE(proxy()->HasKeyboardWindow()); |
| 377 |
| 378 EXPECT_EQ( |
| 379 controller()->GetContainerWindow(), |
| 380 controller()->GetContainerWindow()->GetEventHandlerForPoint(location)); |
| 381 EXPECT_FALSE(proxy()->HasKeyboardWindow()); |
| 382 } |
| 383 |
| 348 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 384 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 349 const gfx::Rect& root_bounds = root_window()->bounds(); | 385 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 350 | 386 |
| 351 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 387 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 352 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 388 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 353 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 389 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 354 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 390 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 355 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 391 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 356 | 392 |
| 357 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 393 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 SetFocus(&input_client); | 600 SetFocus(&input_client); |
| 565 EXPECT_TRUE(keyboard_container->IsVisible()); | 601 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 566 | 602 |
| 567 SetFocus(&no_input_client); | 603 SetFocus(&no_input_client); |
| 568 // Keyboard should not hide itself after lost focus. | 604 // Keyboard should not hide itself after lost focus. |
| 569 EXPECT_TRUE(keyboard_container->IsVisible()); | 605 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 570 EXPECT_FALSE(WillHideKeyboard()); | 606 EXPECT_FALSE(WillHideKeyboard()); |
| 571 } | 607 } |
| 572 | 608 |
| 573 } // namespace keyboard | 609 } // namespace keyboard |
| OLD | NEW |