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