| 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 19 matching lines...) Expand all Loading... |
| 30 #include "ui/events/test/event_generator.h" | 30 #include "ui/events/test/event_generator.h" |
| 31 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
| 32 #include "ui/keyboard/keyboard_controller_observer.h" | 32 #include "ui/keyboard/keyboard_controller_observer.h" |
| 33 #include "ui/keyboard/keyboard_controller_proxy.h" | 33 #include "ui/keyboard/keyboard_controller_proxy.h" |
| 34 #include "ui/keyboard/keyboard_util.h" | 34 #include "ui/keyboard/keyboard_util.h" |
| 35 #include "ui/wm/core/default_activation_client.h" | 35 #include "ui/wm/core/default_activation_client.h" |
| 36 | 36 |
| 37 namespace keyboard { | 37 namespace keyboard { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 // Verify if the |keyboard| window covers the |container| window completely. |
| 41 void VerifyKeyboardWindowSize(aura::Window* container, aura::Window* keyboard) { |
| 42 ASSERT_EQ(gfx::Rect(0, 0, container->bounds().width(), |
| 43 container->bounds().height()), |
| 44 keyboard->bounds()); |
| 45 } |
| 46 |
| 40 // Steps a layer animation until it is completed. Animations must be enabled. | 47 // Steps a layer animation until it is completed. Animations must be enabled. |
| 41 void RunAnimationForLayer(ui::Layer* layer) { | 48 void RunAnimationForLayer(ui::Layer* layer) { |
| 42 // Animations must be enabled for stepping to work. | 49 // Animations must be enabled for stepping to work. |
| 43 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), | 50 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), |
| 44 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 51 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| 45 | 52 |
| 46 ui::LayerAnimatorTestController controller(layer->GetAnimator()); | 53 ui::LayerAnimatorTestController controller(layer->GetAnimator()); |
| 47 // Multiple steps are required to complete complex animations. | 54 // Multiple steps are required to complete complex animations. |
| 48 // TODO(vollick): This should not be necessary. crbug.com/154017 | 55 // TODO(vollick): This should not be necessary. crbug.com/154017 |
| 49 while (controller.animator()->is_animating()) { | 56 while (controller.animator()->is_animating()) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client); | 215 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient(client); |
| 209 input_method->OnTextInputTypeChanged(client); | 216 input_method->OnTextInputTypeChanged(client); |
| 210 } else { | 217 } else { |
| 211 input_method->SetFocusedTextInputClient(client); | 218 input_method->SetFocusedTextInputClient(client); |
| 212 } | 219 } |
| 213 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { | 220 if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) { |
| 214 input_method->ShowImeIfNeeded(); | 221 input_method->ShowImeIfNeeded(); |
| 215 if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { | 222 if (proxy_->GetKeyboardWindow()->bounds().height() == 0) { |
| 216 // Set initial bounds for test keyboard window. | 223 // Set initial bounds for test keyboard window. |
| 217 proxy_->GetKeyboardWindow()->SetBounds( | 224 proxy_->GetKeyboardWindow()->SetBounds( |
| 218 KeyboardBoundsFromWindowBounds( | 225 FullWidthKeyboardBoundsFromRootBounds(root_window()->bounds(), |
| 219 controller()->GetContainerWindow()->bounds(), 100)); | 226 100)); |
| 220 } | 227 } |
| 221 } | 228 } |
| 222 } | 229 } |
| 223 | 230 |
| 224 bool WillHideKeyboard() { | 231 bool WillHideKeyboard() { |
| 225 return controller_->WillHideKeyboard(); | 232 return controller_->WillHideKeyboard(); |
| 226 } | 233 } |
| 227 | 234 |
| 228 bool ShouldEnableInsets(aura::Window* window) { | 235 bool ShouldEnableInsets(aura::Window* window) { |
| 229 return controller_->ShouldEnableInsets(window); | 236 return controller_->ShouldEnableInsets(window); |
| 230 } | 237 } |
| 231 | 238 |
| 232 base::MessageLoopForUI message_loop_; | 239 base::MessageLoopForUI message_loop_; |
| 233 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 240 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 234 scoped_ptr<TestFocusController> focus_controller_; | 241 scoped_ptr<TestFocusController> focus_controller_; |
| 235 | 242 |
| 236 private: | 243 private: |
| 237 KeyboardControllerProxy* proxy_; | 244 KeyboardControllerProxy* proxy_; |
| 238 scoped_ptr<KeyboardController> controller_; | 245 scoped_ptr<KeyboardController> controller_; |
| 239 scoped_ptr<ui::TextInputClient> test_text_input_client_; | 246 scoped_ptr<ui::TextInputClient> test_text_input_client_; |
| 240 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 247 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
| 241 }; | 248 }; |
| 242 | 249 |
| 243 TEST_F(KeyboardControllerTest, KeyboardSize) { | 250 TEST_F(KeyboardControllerTest, KeyboardSize) { |
| 244 aura::Window* container(controller()->GetContainerWindow()); | 251 aura::Window* container(controller()->GetContainerWindow()); |
| 245 aura::Window* keyboard(proxy()->GetKeyboardWindow()); | 252 aura::Window* keyboard(proxy()->GetKeyboardWindow()); |
| 246 container->SetBounds(gfx::Rect(0, 0, 200, 100)); | 253 gfx::Rect screen_bounds = root_window()->bounds(); |
| 254 root_window()->AddChild(container); |
| 255 container->AddChild(keyboard); |
| 256 const gfx::Rect& initial_bounds = container->bounds(); |
| 257 // The container should be positioned at the bottom of screen and has 0 |
| 258 // height. |
| 259 ASSERT_EQ(gfx::Rect(0, screen_bounds.height(), screen_bounds.width(), 0), |
| 260 initial_bounds); |
| 261 VerifyKeyboardWindowSize(container, keyboard); |
| 262 |
| 263 gfx::Rect new_bounds(initial_bounds.x(), initial_bounds.y(), |
| 264 initial_bounds.width() - 50, 50); |
| 265 |
| 266 // In FULL_WIDTH mode, attempt to change window width or move window up from |
| 267 // the bottom are ignored. Changing window height is supported. |
| 268 gfx::Rect expected_bounds(initial_bounds.x(), initial_bounds.y() - 50, |
| 269 initial_bounds.width(), 50); |
| 270 |
| 271 keyboard->SetBounds(new_bounds); |
| 272 ASSERT_EQ(expected_bounds, container->bounds()); |
| 273 VerifyKeyboardWindowSize(container, keyboard); |
| 274 |
| 275 // Mock a screen rotation. |
| 276 controller()->OnRootWindowResized( |
| 277 gfx::Rect(0, 0, screen_bounds.height(), screen_bounds.width())); |
| 278 // The above call should resize keyboard to new width while keeping the old |
| 279 // height. |
| 280 ASSERT_EQ(gfx::Rect(0, |
| 281 screen_bounds.width() - 50, |
| 282 screen_bounds.height(), |
| 283 50), |
| 284 container->bounds()); |
| 285 VerifyKeyboardWindowSize(container, keyboard); |
| 286 } |
| 287 |
| 288 TEST_F(KeyboardControllerTest, FloatingKeyboardSize) { |
| 289 aura::Window* container(controller()->GetContainerWindow()); |
| 290 aura::Window* keyboard(proxy()->GetKeyboardWindow()); |
| 291 gfx::Rect screen_bounds = root_window()->bounds(); |
| 292 root_window()->AddChild(container); |
| 293 controller()->SetKeyboardMode(FLOATING); |
| 247 | 294 |
| 248 container->AddChild(keyboard); | 295 container->AddChild(keyboard); |
| 249 const gfx::Rect& before_bounds = keyboard->bounds(); | |
| 250 // The initial keyboard should be positioned at the bottom of container and | |
| 251 // has 0 height. | |
| 252 ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds); | |
| 253 | 296 |
| 254 gfx::Rect new_bounds( | 297 gfx::Rect new_bounds(0, 50, 50, 50); |
| 255 before_bounds.x(), before_bounds.y() - 50, | |
| 256 before_bounds.width(), 50); | |
| 257 | |
| 258 keyboard->SetBounds(new_bounds); | 298 keyboard->SetBounds(new_bounds); |
| 259 ASSERT_EQ(new_bounds, keyboard->bounds()); | 299 ASSERT_EQ(new_bounds, container->bounds()); |
| 260 | 300 VerifyKeyboardWindowSize(container, keyboard); |
| 261 // Mock a screen rotation. | |
| 262 container->SetBounds(gfx::Rect(0, 0, 100, 200)); | |
| 263 // The above call should resize keyboard to new width while keeping the old | |
| 264 // height. | |
| 265 ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds()); | |
| 266 } | 301 } |
| 267 | 302 |
| 268 // Tests that tapping/clicking inside the keyboard does not give it focus. | 303 // Tests that tapping/clicking inside the keyboard does not give it focus. |
| 269 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 304 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
| 270 const gfx::Rect& root_bounds = root_window()->bounds(); | 305 const gfx::Rect& root_bounds = root_window()->bounds(); |
| 271 aura::test::EventCountDelegate delegate; | 306 aura::test::EventCountDelegate delegate; |
| 272 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 307 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
| 273 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 308 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 274 window->SetBounds(root_bounds); | 309 window->SetBounds(root_bounds); |
| 275 root_window()->AddChild(window.get()); | 310 root_window()->AddChild(window.get()); |
| 276 window->Show(); | 311 window->Show(); |
| 277 window->Focus(); | 312 window->Focus(); |
| 278 | 313 |
| 279 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 314 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 280 keyboard_container->SetBounds(root_bounds); | |
| 281 | 315 |
| 282 root_window()->AddChild(keyboard_container); | 316 root_window()->AddChild(keyboard_container); |
| 283 keyboard_container->Show(); | 317 keyboard_container->Show(); |
| 284 | 318 |
| 285 ShowKeyboard(); | 319 ShowKeyboard(); |
| 286 | 320 |
| 287 EXPECT_TRUE(window->IsVisible()); | 321 EXPECT_TRUE(window->IsVisible()); |
| 288 EXPECT_TRUE(keyboard_container->IsVisible()); | 322 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 289 EXPECT_TRUE(window->HasFocus()); | 323 EXPECT_TRUE(window->HasFocus()); |
| 290 EXPECT_FALSE(keyboard_container->HasFocus()); | 324 EXPECT_FALSE(keyboard_container->HasFocus()); |
| 291 | 325 |
| 292 // Click on the keyboard. Make sure the keyboard receives the event, but does | 326 // Click on the keyboard. Make sure the keyboard receives the event, but does |
| 293 // not get focus. | 327 // not get focus. |
| 294 EventObserver observer; | 328 EventObserver observer; |
| 295 keyboard_container->AddPreTargetHandler(&observer); | 329 keyboard_container->AddPreTargetHandler(&observer); |
| 296 | 330 |
| 297 ui::test::EventGenerator generator(root_window()); | 331 ui::test::EventGenerator generator(root_window()); |
| 298 generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint()); | 332 generator.MoveMouseTo(keyboard_container->bounds().CenterPoint()); |
| 299 generator.ClickLeftButton(); | 333 generator.ClickLeftButton(); |
| 300 EXPECT_TRUE(window->HasFocus()); | 334 EXPECT_TRUE(window->HasFocus()); |
| 301 EXPECT_FALSE(keyboard_container->HasFocus()); | 335 EXPECT_FALSE(keyboard_container->HasFocus()); |
| 302 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); | 336 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); |
| 303 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); | 337 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 304 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); | 338 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); |
| 305 | 339 |
| 306 // Click outside of the keyboard. It should reach the window behind. | 340 // Click outside of the keyboard. It should reach the window behind. |
| 307 generator.MoveMouseTo(gfx::Point()); | 341 generator.MoveMouseTo(gfx::Point()); |
| 308 generator.ClickLeftButton(); | 342 generator.ClickLeftButton(); |
| 309 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 343 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 310 keyboard_container->RemovePreTargetHandler(&observer); | 344 keyboard_container->RemovePreTargetHandler(&observer); |
| 311 } | 345 } |
| 312 | 346 |
| 313 TEST_F(KeyboardControllerTest, EventHitTestingInContainer) { | |
| 314 const gfx::Rect& root_bounds = root_window()->bounds(); | |
| 315 aura::test::EventCountDelegate delegate; | |
| 316 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | |
| 317 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
| 318 window->SetBounds(root_bounds); | |
| 319 root_window()->AddChild(window.get()); | |
| 320 window->Show(); | |
| 321 window->Focus(); | |
| 322 | |
| 323 aura::Window* keyboard_container(controller()->GetContainerWindow()); | |
| 324 keyboard_container->SetBounds(root_bounds); | |
| 325 | |
| 326 root_window()->AddChild(keyboard_container); | |
| 327 keyboard_container->Show(); | |
| 328 | |
| 329 ShowKeyboard(); | |
| 330 | |
| 331 EXPECT_TRUE(window->IsVisible()); | |
| 332 EXPECT_TRUE(keyboard_container->IsVisible()); | |
| 333 EXPECT_TRUE(window->HasFocus()); | |
| 334 EXPECT_FALSE(keyboard_container->HasFocus()); | |
| 335 | |
| 336 // Make sure hit testing works correctly while the keyboard is visible. | |
| 337 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | |
| 338 ui::EventTarget* root = root_window(); | |
| 339 ui::EventTargeter* targeter = root->GetEventTargeter(); | |
| 340 gfx::Point location = keyboard_window->bounds().CenterPoint(); | |
| 341 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, | |
| 342 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | |
| 343 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); | |
| 344 | |
| 345 location.set_y(keyboard_window->bounds().y() - 5); | |
| 346 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, | |
| 347 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | |
| 348 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); | |
| 349 } | |
| 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(ui::ET_MOUSE_MOVED, location, location, | |
| 374 ui::EventTimeForNow(), 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 | |
| 384 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 347 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { |
| 385 const gfx::Rect& root_bounds = root_window()->bounds(); | |
| 386 | |
| 387 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 348 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 388 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 349 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 389 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 350 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
| 390 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 351 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 391 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 352 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 392 | 353 |
| 393 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 354 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 394 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 355 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 395 new KeyboardContainerObserver(keyboard_container)); | 356 new KeyboardContainerObserver(keyboard_container)); |
| 396 keyboard_container->SetBounds(root_bounds); | |
| 397 root_window()->AddChild(keyboard_container); | 357 root_window()->AddChild(keyboard_container); |
| 398 | 358 |
| 399 SetFocus(&input_client_0); | 359 SetFocus(&input_client_0); |
| 400 | 360 |
| 401 EXPECT_TRUE(keyboard_container->IsVisible()); | 361 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 402 | 362 |
| 403 SetFocus(&no_input_client_0); | 363 SetFocus(&no_input_client_0); |
| 404 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 364 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
| 405 // flicker when the focus of input field quickly change. | 365 // flicker when the focus of input field quickly change. |
| 406 EXPECT_TRUE(keyboard_container->IsVisible()); | 366 EXPECT_TRUE(keyboard_container->IsVisible()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 418 // Cancel keyboard hide. | 378 // Cancel keyboard hide. |
| 419 SetFocus(&input_client_2); | 379 SetFocus(&input_client_2); |
| 420 | 380 |
| 421 EXPECT_FALSE(WillHideKeyboard()); | 381 EXPECT_FALSE(WillHideKeyboard()); |
| 422 EXPECT_TRUE(keyboard_container->IsVisible()); | 382 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 423 } | 383 } |
| 424 | 384 |
| 425 // Test to prevent spurious overscroll boxes when changing tabs during keyboard | 385 // Test to prevent spurious overscroll boxes when changing tabs during keyboard |
| 426 // hide. Refer to crbug.com/401670 for more context. | 386 // hide. Refer to crbug.com/401670 for more context. |
| 427 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { | 387 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { |
| 428 const gfx::Rect& root_bounds = root_window()->bounds(); | |
| 429 | |
| 430 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 388 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
| 431 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 389 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
| 432 | 390 |
| 433 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 391 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 434 keyboard_container->SetBounds(root_bounds); | |
| 435 root_window()->AddChild(keyboard_container); | 392 root_window()->AddChild(keyboard_container); |
| 436 | 393 |
| 437 // Enable touch keyboard / overscroll mode to test insets. | 394 // Enable touch keyboard / overscroll mode to test insets. |
| 438 keyboard::SetTouchKeyboardEnabled(true); | 395 keyboard::SetTouchKeyboardEnabled(true); |
| 439 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 396 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
| 440 | 397 |
| 441 SetFocus(&input_client); | 398 SetFocus(&input_client); |
| 442 SetFocus(&no_input_client); | 399 SetFocus(&no_input_client); |
| 443 // Insets should not be enabled for new windows while keyboard is in the | 400 // Insets should not be enabled for new windows while keyboard is in the |
| 444 // process of hiding when overscroll is enabled. | 401 // process of hiding when overscroll is enabled. |
| 445 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); | 402 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); |
| 446 // Cancel keyboard hide. | 403 // Cancel keyboard hide. |
| 447 SetFocus(&input_client); | 404 SetFocus(&input_client); |
| 448 // Insets should be enabled for new windows as hide was cancelled. | 405 // Insets should be enabled for new windows as hide was cancelled. |
| 449 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); | 406 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); |
| 450 } | 407 } |
| 451 | 408 |
| 452 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 409 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { |
| 453 const gfx::Rect& root_bounds = root_window()->bounds(); | |
| 454 | |
| 455 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); | 410 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
| 456 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 411 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
| 457 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 412 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
| 458 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 413 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
| 459 | 414 |
| 460 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 415 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
| 461 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 416 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
| 462 new KeyboardContainerObserver(keyboard_container)); | 417 new KeyboardContainerObserver(keyboard_container)); |
| 463 keyboard_container->SetBounds(root_bounds); | |
| 464 root_window()->AddChild(keyboard_container); | 418 root_window()->AddChild(keyboard_container); |
| 465 | 419 |
| 466 SetFocus(&input_client_0); | 420 SetFocus(&input_client_0); |
| 467 | 421 |
| 468 EXPECT_TRUE(keyboard_container->IsVisible()); | 422 EXPECT_TRUE(keyboard_container->IsVisible()); |
| 469 | 423 |
| 470 // Lock keyboard. | 424 // Lock keyboard. |
| 471 controller()->set_lock_keyboard(true); | 425 controller()->set_lock_keyboard(true); |
| 472 | 426 |
| 473 SetFocus(&no_input_client_0); | 427 SetFocus(&no_input_client_0); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 transform.Translate(0, kAnimationDistance); | 504 transform.Translate(0, kAnimationDistance); |
| 551 EXPECT_EQ(transform, layer->transform()); | 505 EXPECT_EQ(transform, layer->transform()); |
| 552 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 506 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| 553 | 507 |
| 554 RunAnimationForLayer(layer); | 508 RunAnimationForLayer(layer); |
| 555 EXPECT_TRUE(keyboard_container()->IsVisible()); | 509 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 556 EXPECT_TRUE(keyboard_window()->IsVisible()); | 510 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 557 float show_end_opacity = layer->opacity(); | 511 float show_end_opacity = layer->opacity(); |
| 558 EXPECT_LT(show_start_opacity, show_end_opacity); | 512 EXPECT_LT(show_start_opacity, show_end_opacity); |
| 559 EXPECT_EQ(gfx::Transform(), layer->transform()); | 513 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 560 // KeyboardController should notify the bounds of keyboard window to its | 514 // KeyboardController should notify the bounds of container window to its |
| 561 // observers after show animation finished. | 515 // observers after show animation finished. |
| 562 EXPECT_EQ(keyboard_window()->bounds(), notified_bounds()); | 516 EXPECT_EQ(keyboard_container()->bounds(), notified_bounds()); |
| 563 | 517 |
| 564 // Directly hide keyboard without delay. | 518 // Directly hide keyboard without delay. |
| 565 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); | 519 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); |
| 566 EXPECT_TRUE(keyboard_container()->IsVisible()); | 520 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 567 EXPECT_TRUE(keyboard_container()->layer()->visible()); | 521 EXPECT_TRUE(keyboard_container()->layer()->visible()); |
| 568 EXPECT_TRUE(keyboard_window()->IsVisible()); | 522 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 569 float hide_start_opacity = layer->opacity(); | 523 float hide_start_opacity = layer->opacity(); |
| 570 // KeyboardController should notify the bounds of keyboard window to its | 524 // KeyboardController should notify the bounds of keyboard window to its |
| 571 // observers before hide animation starts. | 525 // observers before hide animation starts. |
| 572 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 526 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 593 // Before hide animation finishes, show keyboard again. | 547 // Before hide animation finishes, show keyboard again. |
| 594 ShowKeyboard(); | 548 ShowKeyboard(); |
| 595 RunAnimationForLayer(layer); | 549 RunAnimationForLayer(layer); |
| 596 EXPECT_TRUE(keyboard_container()->IsVisible()); | 550 EXPECT_TRUE(keyboard_container()->IsVisible()); |
| 597 EXPECT_TRUE(keyboard_window()->IsVisible()); | 551 EXPECT_TRUE(keyboard_window()->IsVisible()); |
| 598 EXPECT_EQ(1.0, layer->opacity()); | 552 EXPECT_EQ(1.0, layer->opacity()); |
| 599 EXPECT_EQ(gfx::Transform(), layer->transform()); | 553 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 600 } | 554 } |
| 601 | 555 |
| 602 } // namespace keyboard | 556 } // namespace keyboard |
| OLD | NEW |