| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 KeyboardController* controller() { return controller_.get(); } | 199 KeyboardController* controller() { return controller_.get(); } |
| 200 | 200 |
| 201 void ShowKeyboard() { | 201 void ShowKeyboard() { |
| 202 test_text_input_client_.reset( | 202 test_text_input_client_.reset( |
| 203 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); | 203 new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); |
| 204 SetFocus(test_text_input_client_.get()); | 204 SetFocus(test_text_input_client_.get()); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void MockRotateScreen() { | 207 void MockRotateScreen() { |
| 208 const gfx::Rect root_bounds = root_window()->bounds(); | 208 const gfx::Rect root_bounds = root_window()->bounds(); |
| 209 controller_->OnWindowBoundsChanged(root_window(), gfx::Rect(), | 209 root_window()->SetBounds( |
| 210 gfx::Rect(0, | 210 gfx::Rect(0, 0, root_bounds.height(), root_bounds.width())); |
| 211 0, | |
| 212 root_bounds.height(), | |
| 213 root_bounds.width())); | |
| 214 } | 211 } |
| 215 | 212 |
| 216 protected: | 213 protected: |
| 217 // KeyboardControllerObserver overrides | 214 // KeyboardControllerObserver overrides |
| 218 void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override { | 215 void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override { |
| 219 notified_bounds_ = new_bounds; | 216 notified_bounds_ = new_bounds; |
| 220 number_of_calls_++; | 217 number_of_calls_++; |
| 221 } | 218 } |
| 222 | 219 |
| 223 int number_of_calls() const { return number_of_calls_; } | 220 int number_of_calls() const { return number_of_calls_; } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 aura::Window* keyboard(ui()->GetKeyboardWindow()); | 265 aura::Window* keyboard(ui()->GetKeyboardWindow()); |
| 269 gfx::Rect screen_bounds = root_window()->bounds(); | 266 gfx::Rect screen_bounds = root_window()->bounds(); |
| 270 root_window()->AddChild(container); | 267 root_window()->AddChild(container); |
| 271 container->AddChild(keyboard); | 268 container->AddChild(keyboard); |
| 272 const gfx::Rect& initial_bounds = container->bounds(); | 269 const gfx::Rect& initial_bounds = container->bounds(); |
| 273 // The container should be positioned at the bottom of screen and has 0 | 270 // The container should be positioned at the bottom of screen and has 0 |
| 274 // height. | 271 // height. |
| 275 ASSERT_EQ(gfx::Rect(), initial_bounds); | 272 ASSERT_EQ(gfx::Rect(), initial_bounds); |
| 276 VerifyKeyboardWindowSize(container, keyboard); | 273 VerifyKeyboardWindowSize(container, keyboard); |
| 277 | 274 |
| 278 | |
| 279 // In FULL_WIDTH mode, attempt to change window width or move window up from | 275 // In FULL_WIDTH mode, attempt to change window width or move window up from |
| 280 // the bottom are ignored. Changing window height is supported. | 276 // the bottom are ignored. Changing window height is supported. |
| 281 gfx::Rect expected_bounds(0, | 277 gfx::Rect expected_bounds(0, |
| 282 screen_bounds.height() - 50, | 278 screen_bounds.height() - 50, |
| 283 screen_bounds.width(), | 279 screen_bounds.width(), |
| 284 50); | 280 50); |
| 285 | 281 |
| 286 // The x position of new bounds may not be 0 if shelf is on the left side of | 282 // The x position of new bounds may not be 0 if shelf is on the left side of |
| 287 // screen. In FULL_WIDTH mode, the virtual keyboard should always align with | 283 // screen. In FULL_WIDTH mode, the virtual keyboard should always align with |
| 288 // the left edge of screen. See http://crbug.com/510595. | 284 // the left edge of screen. See http://crbug.com/510595. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 ui()->GetInputMethod()->ShowImeIfNeeded(); | 632 ui()->GetInputMethod()->ShowImeIfNeeded(); |
| 637 // Mock set keyboard size from javascript side. In floating mode, virtual | 633 // Mock set keyboard size from javascript side. In floating mode, virtual |
| 638 // keyboard's size is decided by client. | 634 // keyboard's size is decided by client. |
| 639 gfx::Rect new_bounds(0, 50, 50, 50); | 635 gfx::Rect new_bounds(0, 50, 50, 50); |
| 640 keyboard->SetBounds(new_bounds); | 636 keyboard->SetBounds(new_bounds); |
| 641 ASSERT_EQ(new_bounds, container->bounds()); | 637 ASSERT_EQ(new_bounds, container->bounds()); |
| 642 EXPECT_TRUE(keyboard->IsVisible()); | 638 EXPECT_TRUE(keyboard->IsVisible()); |
| 643 EXPECT_TRUE(container->IsVisible()); | 639 EXPECT_TRUE(container->IsVisible()); |
| 644 } | 640 } |
| 645 | 641 |
| 642 TEST_F(KeyboardControllerTest, DisplayChangeShouldNotifyBoundsChange) { |
| 643 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 644 |
| 645 aura::Window* container(controller()->GetContainerWindow()); |
| 646 root_window()->AddChild(container); |
| 647 |
| 648 keyboard::SetTouchKeyboardEnabled(true); |
| 649 controller()->SetKeyboardMode(FULL_WIDTH); |
| 650 SetFocus(&input_client); |
| 651 gfx::Rect new_bounds(0, 0, 1280, 800); |
| 652 ASSERT_NE(new_bounds, root_window()->bounds()); |
| 653 EXPECT_EQ(1, number_of_calls()); |
| 654 root_window()->SetBounds(new_bounds); |
| 655 EXPECT_EQ(2, number_of_calls()); |
| 656 MockRotateScreen(); |
| 657 EXPECT_EQ(3, number_of_calls()); |
| 658 } |
| 659 |
| 646 } // namespace keyboard | 660 } // namespace keyboard |
| OLD | NEW |