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 KeyboardBoundsFromWindowBounds(root_window()->bounds(), 100)); |
219 controller()->GetContainerWindow()->bounds(), 100)); | |
220 } | 226 } |
221 } | 227 } |
222 } | 228 } |
223 | 229 |
224 bool WillHideKeyboard() { | 230 bool WillHideKeyboard() { |
225 return controller_->WillHideKeyboard(); | 231 return controller_->WillHideKeyboard(); |
226 } | 232 } |
227 | 233 |
228 bool ShouldEnableInsets(aura::Window* window) { | 234 bool ShouldEnableInsets(aura::Window* window) { |
229 return controller_->ShouldEnableInsets(window); | 235 return controller_->ShouldEnableInsets(window); |
230 } | 236 } |
231 | 237 |
232 base::MessageLoopForUI message_loop_; | 238 base::MessageLoopForUI message_loop_; |
233 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 239 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
234 scoped_ptr<TestFocusController> focus_controller_; | 240 scoped_ptr<TestFocusController> focus_controller_; |
235 | 241 |
236 private: | 242 private: |
237 KeyboardControllerProxy* proxy_; | 243 KeyboardControllerProxy* proxy_; |
238 scoped_ptr<KeyboardController> controller_; | 244 scoped_ptr<KeyboardController> controller_; |
239 scoped_ptr<ui::TextInputClient> test_text_input_client_; | 245 scoped_ptr<ui::TextInputClient> test_text_input_client_; |
240 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); | 246 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerTest); |
241 }; | 247 }; |
242 | 248 |
243 TEST_F(KeyboardControllerTest, KeyboardSize) { | 249 TEST_F(KeyboardControllerTest, KeyboardSize) { |
244 aura::Window* container(controller()->GetContainerWindow()); | 250 aura::Window* container(controller()->GetContainerWindow()); |
245 aura::Window* keyboard(proxy()->GetKeyboardWindow()); | 251 aura::Window* keyboard(proxy()->GetKeyboardWindow()); |
246 container->SetBounds(gfx::Rect(0, 0, 200, 100)); | 252 gfx::Rect screen_bounds = root_window()->bounds(); |
| 253 root_window()->AddChild(container); |
| 254 container->AddChild(keyboard); |
| 255 const gfx::Rect& initial_bounds = container->bounds(); |
| 256 // The container should be positioned at the bottom of screen and has 0 |
| 257 // height. |
| 258 ASSERT_EQ(gfx::Rect(0, screen_bounds.height(), screen_bounds.width(), 0), |
| 259 initial_bounds); |
| 260 VerifyKeyboardWindowSize(container, keyboard); |
| 261 |
| 262 gfx::Rect new_bounds(initial_bounds.x(), initial_bounds.y(), |
| 263 initial_bounds.width() - 50, 50); |
| 264 |
| 265 // In FULL_WIDTH mode, attempt to change window width or move window up from |
| 266 // the bottom are ignored. Changing window height is supported. |
| 267 gfx::Rect expected_bounds(initial_bounds.x(), initial_bounds.y() - 50, |
| 268 initial_bounds.width(), 50); |
| 269 |
| 270 keyboard->SetBounds(new_bounds); |
| 271 ASSERT_EQ(expected_bounds, container->bounds()); |
| 272 VerifyKeyboardWindowSize(container, keyboard); |
| 273 |
| 274 // Mock a screen rotation. |
| 275 controller()->OnRootWindowResized( |
| 276 gfx::Rect(0, 0, screen_bounds.height(), screen_bounds.width())); |
| 277 // The above call should resize keyboard to new width while keeping the old |
| 278 // height. |
| 279 ASSERT_EQ(gfx::Rect(0, screen_bounds.width() - 50, |
| 280 root_window()->bounds().height(), 50), |
| 281 container->bounds()); |
| 282 VerifyKeyboardWindowSize(container, keyboard); |
| 283 } |
| 284 |
| 285 TEST_F(KeyboardControllerTest, FloatingKeyboardSize) { |
| 286 aura::Window* container(controller()->GetContainerWindow()); |
| 287 aura::Window* keyboard(proxy()->GetKeyboardWindow()); |
| 288 gfx::Rect screen_bounds = root_window()->bounds(); |
| 289 root_window()->AddChild(container); |
| 290 controller()->SetKeyboardMode(FLOATING); |
247 | 291 |
248 container->AddChild(keyboard); | 292 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 | 293 |
254 gfx::Rect new_bounds( | 294 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); | 295 keyboard->SetBounds(new_bounds); |
259 ASSERT_EQ(new_bounds, keyboard->bounds()); | 296 ASSERT_EQ(new_bounds, container->bounds()); |
260 | 297 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 } | 298 } |
267 | 299 |
268 // Tests that tapping/clicking inside the keyboard does not give it focus. | 300 // Tests that tapping/clicking inside the keyboard does not give it focus. |
269 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { | 301 TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) { |
270 const gfx::Rect& root_bounds = root_window()->bounds(); | 302 const gfx::Rect& root_bounds = root_window()->bounds(); |
271 aura::test::EventCountDelegate delegate; | 303 aura::test::EventCountDelegate delegate; |
272 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 304 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
273 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 305 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
274 window->SetBounds(root_bounds); | 306 window->SetBounds(root_bounds); |
275 root_window()->AddChild(window.get()); | 307 root_window()->AddChild(window.get()); |
276 window->Show(); | 308 window->Show(); |
277 window->Focus(); | 309 window->Focus(); |
278 | 310 |
279 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 311 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
280 keyboard_container->SetBounds(root_bounds); | |
281 | 312 |
282 root_window()->AddChild(keyboard_container); | 313 root_window()->AddChild(keyboard_container); |
283 keyboard_container->Show(); | 314 keyboard_container->Show(); |
284 | 315 |
285 ShowKeyboard(); | 316 ShowKeyboard(); |
286 | 317 |
287 EXPECT_TRUE(window->IsVisible()); | 318 EXPECT_TRUE(window->IsVisible()); |
288 EXPECT_TRUE(keyboard_container->IsVisible()); | 319 EXPECT_TRUE(keyboard_container->IsVisible()); |
289 EXPECT_TRUE(window->HasFocus()); | 320 EXPECT_TRUE(window->HasFocus()); |
290 EXPECT_FALSE(keyboard_container->HasFocus()); | 321 EXPECT_FALSE(keyboard_container->HasFocus()); |
291 | 322 |
292 // Click on the keyboard. Make sure the keyboard receives the event, but does | 323 // Click on the keyboard. Make sure the keyboard receives the event, but does |
293 // not get focus. | 324 // not get focus. |
294 EventObserver observer; | 325 EventObserver observer; |
295 keyboard_container->AddPreTargetHandler(&observer); | 326 keyboard_container->AddPreTargetHandler(&observer); |
296 | 327 |
297 ui::test::EventGenerator generator(root_window()); | 328 ui::test::EventGenerator generator(root_window()); |
298 generator.MoveMouseTo(proxy()->GetKeyboardWindow()->bounds().CenterPoint()); | 329 generator.MoveMouseTo(keyboard_container->bounds().CenterPoint()); |
299 generator.ClickLeftButton(); | 330 generator.ClickLeftButton(); |
300 EXPECT_TRUE(window->HasFocus()); | 331 EXPECT_TRUE(window->HasFocus()); |
301 EXPECT_FALSE(keyboard_container->HasFocus()); | 332 EXPECT_FALSE(keyboard_container->HasFocus()); |
302 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); | 333 EXPECT_EQ("0 0", delegate.GetMouseButtonCountsAndReset()); |
303 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); | 334 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_PRESSED)); |
304 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); | 335 EXPECT_EQ(1, observer.GetEventCount(ui::ET_MOUSE_RELEASED)); |
305 | 336 |
306 // Click outside of the keyboard. It should reach the window behind. | 337 // Click outside of the keyboard. It should reach the window behind. |
307 generator.MoveMouseTo(gfx::Point()); | 338 generator.MoveMouseTo(gfx::Point()); |
308 generator.ClickLeftButton(); | 339 generator.ClickLeftButton(); |
309 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 340 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
310 keyboard_container->RemovePreTargetHandler(&observer); | 341 keyboard_container->RemovePreTargetHandler(&observer); |
311 } | 342 } |
312 | 343 |
313 TEST_F(KeyboardControllerTest, EventHitTestingInContainer) { | 344 TEST_F(KeyboardControllerTest, EventHitTestingInContainer) { |
314 const gfx::Rect& root_bounds = root_window()->bounds(); | 345 const gfx::Rect& root_bounds = root_window()->bounds(); |
315 aura::test::EventCountDelegate delegate; | 346 aura::test::EventCountDelegate delegate; |
316 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 347 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
317 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 348 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
318 window->SetBounds(root_bounds); | 349 window->SetBounds(root_bounds); |
319 root_window()->AddChild(window.get()); | 350 root_window()->AddChild(window.get()); |
320 window->Show(); | 351 window->Show(); |
321 window->Focus(); | 352 window->Focus(); |
322 | 353 |
323 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 354 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
324 keyboard_container->SetBounds(root_bounds); | |
325 | 355 |
326 root_window()->AddChild(keyboard_container); | 356 root_window()->AddChild(keyboard_container); |
327 keyboard_container->Show(); | 357 keyboard_container->Show(); |
328 | 358 |
329 ShowKeyboard(); | 359 ShowKeyboard(); |
330 | 360 |
331 EXPECT_TRUE(window->IsVisible()); | 361 EXPECT_TRUE(window->IsVisible()); |
332 EXPECT_TRUE(keyboard_container->IsVisible()); | 362 EXPECT_TRUE(keyboard_container->IsVisible()); |
333 EXPECT_TRUE(window->HasFocus()); | 363 EXPECT_TRUE(window->HasFocus()); |
334 EXPECT_FALSE(keyboard_container->HasFocus()); | 364 EXPECT_FALSE(keyboard_container->HasFocus()); |
335 | 365 |
336 // Make sure hit testing works correctly while the keyboard is visible. | 366 // Make sure hit testing works correctly while the keyboard is visible. |
337 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); | 367 aura::Window* keyboard_window = proxy()->GetKeyboardWindow(); |
338 ui::EventTarget* root = root_window(); | 368 ui::EventTarget* root = root_window(); |
339 ui::EventTargeter* targeter = root->GetEventTargeter(); | 369 ui::EventTargeter* targeter = root->GetEventTargeter(); |
340 gfx::Point location = keyboard_window->bounds().CenterPoint(); | 370 gfx::Point location = keyboard_container->bounds().CenterPoint(); |
341 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, | 371 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, location, location, |
342 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 372 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
343 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); | 373 EXPECT_EQ(keyboard_window, targeter->FindTargetForEvent(root, &mouse1)); |
344 | 374 |
345 location.set_y(keyboard_window->bounds().y() - 5); | 375 location.set_y(keyboard_container->bounds().y() - 5); |
346 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, | 376 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, location, location, |
347 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 377 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
348 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); | 378 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse2)); |
349 } | 379 } |
350 | 380 |
351 TEST_F(KeyboardControllerTest, KeyboardWindowCreation) { | 381 TEST_F(KeyboardControllerTest, KeyboardWindowCreation) { |
352 const gfx::Rect& root_bounds = root_window()->bounds(); | 382 const gfx::Rect& root_bounds = root_window()->bounds(); |
353 aura::test::EventCountDelegate delegate; | 383 aura::test::EventCountDelegate delegate; |
354 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); | 384 scoped_ptr<aura::Window> window(new aura::Window(&delegate)); |
355 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 385 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
(...skipping 19 matching lines...) Expand all Loading... |
375 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse)); | 405 EXPECT_EQ(window.get(), targeter->FindTargetForEvent(root, &mouse)); |
376 EXPECT_FALSE(proxy()->HasKeyboardWindow()); | 406 EXPECT_FALSE(proxy()->HasKeyboardWindow()); |
377 | 407 |
378 EXPECT_EQ( | 408 EXPECT_EQ( |
379 controller()->GetContainerWindow(), | 409 controller()->GetContainerWindow(), |
380 controller()->GetContainerWindow()->GetEventHandlerForPoint(location)); | 410 controller()->GetContainerWindow()->GetEventHandlerForPoint(location)); |
381 EXPECT_FALSE(proxy()->HasKeyboardWindow()); | 411 EXPECT_FALSE(proxy()->HasKeyboardWindow()); |
382 } | 412 } |
383 | 413 |
384 TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) { | 414 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); | 415 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
388 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 416 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
389 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); | 417 ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT); |
390 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 418 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
391 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 419 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
392 | 420 |
393 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 421 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
394 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 422 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
395 new KeyboardContainerObserver(keyboard_container)); | 423 new KeyboardContainerObserver(keyboard_container)); |
396 keyboard_container->SetBounds(root_bounds); | |
397 root_window()->AddChild(keyboard_container); | 424 root_window()->AddChild(keyboard_container); |
398 | 425 |
399 SetFocus(&input_client_0); | 426 SetFocus(&input_client_0); |
400 | 427 |
401 EXPECT_TRUE(keyboard_container->IsVisible()); | 428 EXPECT_TRUE(keyboard_container->IsVisible()); |
402 | 429 |
403 SetFocus(&no_input_client_0); | 430 SetFocus(&no_input_client_0); |
404 // Keyboard should not immediately hide itself. It is delayed to avoid layout | 431 // Keyboard should not immediately hide itself. It is delayed to avoid layout |
405 // flicker when the focus of input field quickly change. | 432 // flicker when the focus of input field quickly change. |
406 EXPECT_TRUE(keyboard_container->IsVisible()); | 433 EXPECT_TRUE(keyboard_container->IsVisible()); |
(...skipping 11 matching lines...) Expand all Loading... |
418 // Cancel keyboard hide. | 445 // Cancel keyboard hide. |
419 SetFocus(&input_client_2); | 446 SetFocus(&input_client_2); |
420 | 447 |
421 EXPECT_FALSE(WillHideKeyboard()); | 448 EXPECT_FALSE(WillHideKeyboard()); |
422 EXPECT_TRUE(keyboard_container->IsVisible()); | 449 EXPECT_TRUE(keyboard_container->IsVisible()); |
423 } | 450 } |
424 | 451 |
425 // Test to prevent spurious overscroll boxes when changing tabs during keyboard | 452 // Test to prevent spurious overscroll boxes when changing tabs during keyboard |
426 // hide. Refer to crbug.com/401670 for more context. | 453 // hide. Refer to crbug.com/401670 for more context. |
427 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { | 454 TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) { |
428 const gfx::Rect& root_bounds = root_window()->bounds(); | |
429 | |
430 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); | 455 ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT); |
431 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); | 456 ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE); |
432 | 457 |
433 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 458 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
434 keyboard_container->SetBounds(root_bounds); | |
435 root_window()->AddChild(keyboard_container); | 459 root_window()->AddChild(keyboard_container); |
436 | 460 |
437 // Enable touch keyboard / overscroll mode to test insets. | 461 // Enable touch keyboard / overscroll mode to test insets. |
438 keyboard::SetTouchKeyboardEnabled(true); | 462 keyboard::SetTouchKeyboardEnabled(true); |
439 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 463 EXPECT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
440 | 464 |
441 SetFocus(&input_client); | 465 SetFocus(&input_client); |
442 SetFocus(&no_input_client); | 466 SetFocus(&no_input_client); |
443 // Insets should not be enabled for new windows while keyboard is in the | 467 // Insets should not be enabled for new windows while keyboard is in the |
444 // process of hiding when overscroll is enabled. | 468 // process of hiding when overscroll is enabled. |
445 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); | 469 EXPECT_FALSE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); |
446 // Cancel keyboard hide. | 470 // Cancel keyboard hide. |
447 SetFocus(&input_client); | 471 SetFocus(&input_client); |
448 // Insets should be enabled for new windows as hide was cancelled. | 472 // Insets should be enabled for new windows as hide was cancelled. |
449 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); | 473 EXPECT_TRUE(ShouldEnableInsets(proxy()->GetKeyboardWindow())); |
450 } | 474 } |
451 | 475 |
452 TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) { | 476 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); | 477 ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT); |
456 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); | 478 ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT); |
457 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); | 479 ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE); |
458 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); | 480 ui::DummyTextInputClient no_input_client_1(ui::TEXT_INPUT_TYPE_NONE); |
459 | 481 |
460 aura::Window* keyboard_container(controller()->GetContainerWindow()); | 482 aura::Window* keyboard_container(controller()->GetContainerWindow()); |
461 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( | 483 scoped_ptr<KeyboardContainerObserver> keyboard_container_observer( |
462 new KeyboardContainerObserver(keyboard_container)); | 484 new KeyboardContainerObserver(keyboard_container)); |
463 keyboard_container->SetBounds(root_bounds); | |
464 root_window()->AddChild(keyboard_container); | 485 root_window()->AddChild(keyboard_container); |
465 | 486 |
466 SetFocus(&input_client_0); | 487 SetFocus(&input_client_0); |
467 | 488 |
468 EXPECT_TRUE(keyboard_container->IsVisible()); | 489 EXPECT_TRUE(keyboard_container->IsVisible()); |
469 | 490 |
470 // Lock keyboard. | 491 // Lock keyboard. |
471 controller()->set_lock_keyboard(true); | 492 controller()->set_lock_keyboard(true); |
472 | 493 |
473 SetFocus(&no_input_client_0); | 494 SetFocus(&no_input_client_0); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 transform.Translate(0, kAnimationDistance); | 571 transform.Translate(0, kAnimationDistance); |
551 EXPECT_EQ(transform, layer->transform()); | 572 EXPECT_EQ(transform, layer->transform()); |
552 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 573 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
553 | 574 |
554 RunAnimationForLayer(layer); | 575 RunAnimationForLayer(layer); |
555 EXPECT_TRUE(keyboard_container()->IsVisible()); | 576 EXPECT_TRUE(keyboard_container()->IsVisible()); |
556 EXPECT_TRUE(keyboard_window()->IsVisible()); | 577 EXPECT_TRUE(keyboard_window()->IsVisible()); |
557 float show_end_opacity = layer->opacity(); | 578 float show_end_opacity = layer->opacity(); |
558 EXPECT_LT(show_start_opacity, show_end_opacity); | 579 EXPECT_LT(show_start_opacity, show_end_opacity); |
559 EXPECT_EQ(gfx::Transform(), layer->transform()); | 580 EXPECT_EQ(gfx::Transform(), layer->transform()); |
560 // KeyboardController should notify the bounds of keyboard window to its | 581 // KeyboardController should notify the bounds of container window to its |
561 // observers after show animation finished. | 582 // observers after show animation finished. |
562 EXPECT_EQ(keyboard_window()->bounds(), notified_bounds()); | 583 EXPECT_EQ(keyboard_container()->bounds(), notified_bounds()); |
563 | 584 |
564 // Directly hide keyboard without delay. | 585 // Directly hide keyboard without delay. |
565 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); | 586 controller()->HideKeyboard(KeyboardController::HIDE_REASON_AUTOMATIC); |
566 EXPECT_TRUE(keyboard_container()->IsVisible()); | 587 EXPECT_TRUE(keyboard_container()->IsVisible()); |
567 EXPECT_TRUE(keyboard_container()->layer()->visible()); | 588 EXPECT_TRUE(keyboard_container()->layer()->visible()); |
568 EXPECT_TRUE(keyboard_window()->IsVisible()); | 589 EXPECT_TRUE(keyboard_window()->IsVisible()); |
569 float hide_start_opacity = layer->opacity(); | 590 float hide_start_opacity = layer->opacity(); |
570 // KeyboardController should notify the bounds of keyboard window to its | 591 // KeyboardController should notify the bounds of keyboard window to its |
571 // observers before hide animation starts. | 592 // observers before hide animation starts. |
572 EXPECT_EQ(gfx::Rect(), notified_bounds()); | 593 EXPECT_EQ(gfx::Rect(), notified_bounds()); |
(...skipping 20 matching lines...) Expand all Loading... |
593 // Before hide animation finishes, show keyboard again. | 614 // Before hide animation finishes, show keyboard again. |
594 ShowKeyboard(); | 615 ShowKeyboard(); |
595 RunAnimationForLayer(layer); | 616 RunAnimationForLayer(layer); |
596 EXPECT_TRUE(keyboard_container()->IsVisible()); | 617 EXPECT_TRUE(keyboard_container()->IsVisible()); |
597 EXPECT_TRUE(keyboard_window()->IsVisible()); | 618 EXPECT_TRUE(keyboard_window()->IsVisible()); |
598 EXPECT_EQ(1.0, layer->opacity()); | 619 EXPECT_EQ(1.0, layer->opacity()); |
599 EXPECT_EQ(gfx::Transform(), layer->transform()); | 620 EXPECT_EQ(gfx::Transform(), layer->transform()); |
600 } | 621 } |
601 | 622 |
602 } // namespace keyboard | 623 } // namespace keyboard |
OLD | NEW |