Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ui/keyboard/keyboard_controller.cc

Issue 240443006: Remove native VK window height logic and wait for resizeTo to setup VK window height (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura/window_delegate.h" 10 #include "ui/aura/window_delegate.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 268 }
269 269
270 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) { 270 void KeyboardController::AddObserver(KeyboardControllerObserver* observer) {
271 observer_list_.AddObserver(observer); 271 observer_list_.AddObserver(observer);
272 } 272 }
273 273
274 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) { 274 void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) {
275 observer_list_.RemoveObserver(observer); 275 observer_list_.RemoveObserver(observer);
276 } 276 }
277 277
278 void KeyboardController::ShowAndLockKeyboard() { 278 void KeyboardController::ShowKeyboard(bool lock) {
279 set_lock_keyboard(true); 279 set_lock_keyboard(lock);
280 OnShowImeIfNeeded(); 280 ShowKeyboardInternal();
281 } 281 }
282 282
283 void KeyboardController::OnWindowHierarchyChanged( 283 void KeyboardController::OnWindowHierarchyChanged(
284 const HierarchyChangeParams& params) { 284 const HierarchyChangeParams& params) {
285 if (params.new_parent && params.target == container_.get()) 285 if (params.new_parent && params.target == container_.get())
286 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient()); 286 OnTextInputStateChanged(proxy_->GetInputMethod()->GetTextInputClient());
287 } 287 }
288 288
289 void KeyboardController::Reload() { 289 void KeyboardController::Reload() {
290 // Makes sure the keyboard window is initialized. 290 // Makes sure the keyboard window is initialized.
291 proxy_->GetKeyboardWindow(); 291 proxy_->GetKeyboardWindow();
292 proxy_->ReloadKeyboardIfNeeded(); 292 proxy_->ReloadKeyboardIfNeeded();
293 } 293 }
294 294
295 void KeyboardController::OnTextInputStateChanged( 295 void KeyboardController::OnTextInputStateChanged(
296 const ui::TextInputClient* client) { 296 const ui::TextInputClient* client) {
297 if (!container_.get()) 297 if (!container_.get())
298 return; 298 return;
299 299
300 if (IsKeyboardUsabilityExperimentEnabled()) { 300 if (IsKeyboardUsabilityExperimentEnabled()) {
301 OnShowImeIfNeeded(); 301 ShowKeyboardInternal();
302 return; 302 return;
303 } 303 }
304 304
305 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; 305 type_ = client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
306 306
307 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) { 307 if (type_ == ui::TEXT_INPUT_TYPE_NONE && !lock_keyboard_) {
308 if (keyboard_visible_) { 308 if (keyboard_visible_) {
309 // Set the visibility state here so that any queries for visibility 309 // Set the visibility state here so that any queries for visibility
310 // before the timer fires returns the correct future value. 310 // before the timer fires returns the correct future value.
311 keyboard_visible_ = false; 311 keyboard_visible_ = false;
(...skipping 18 matching lines...) Expand all
330 } 330 }
331 } 331 }
332 332
333 void KeyboardController::OnInputMethodDestroyed( 333 void KeyboardController::OnInputMethodDestroyed(
334 const ui::InputMethod* input_method) { 334 const ui::InputMethod* input_method) {
335 DCHECK_EQ(input_method_, input_method); 335 DCHECK_EQ(input_method_, input_method);
336 input_method_ = NULL; 336 input_method_ = NULL;
337 } 337 }
338 338
339 void KeyboardController::OnShowImeIfNeeded() { 339 void KeyboardController::OnShowImeIfNeeded() {
340 ShowKeyboardInternal();
341 }
342
343 void KeyboardController::ShowKeyboardInternal() {
340 if (!container_.get()) 344 if (!container_.get())
341 return; 345 return;
342 346
343 if (container_->children().empty()) { 347 if (container_->children().empty()) {
344 keyboard::MarkKeyboardLoadStarted(); 348 keyboard::MarkKeyboardLoadStarted();
345 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 349 aura::Window* keyboard = proxy_->GetKeyboardWindow();
346 keyboard->Show(); 350 keyboard->Show();
347 container_->AddChild(keyboard); 351 container_->AddChild(keyboard);
348 keyboard->set_owned_by_parent(false); 352 keyboard->set_owned_by_parent(false);
349 } 353 }
350 354
351 proxy_->ReloadKeyboardIfNeeded(); 355 proxy_->ReloadKeyboardIfNeeded();
352 356
353 if (keyboard_visible_) 357 if (keyboard_visible_ || proxy_->GetKeyboardWindow()->bounds().height() == 0)
354 return; 358 return;
355 359
356 keyboard_visible_ = true; 360 keyboard_visible_ = true;
357 361
358 // If the controller is in the process of hiding the keyboard, do not log 362 // If the controller is in the process of hiding the keyboard, do not log
359 // the stat here since the keyboard will not actually be shown. 363 // the stat here since the keyboard will not actually be shown.
360 if (!WillHideKeyboard()) 364 if (!WillHideKeyboard())
361 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW); 365 keyboard::LogKeyboardControlEvent(keyboard::KEYBOARD_CONTROL_SHOW);
362 366
363 weak_factory_.InvalidateWeakPtrs(); 367 weak_factory_.InvalidateWeakPtrs();
364 368
365 // If |container_| has hide animation, its visibility is set to false when 369 // If |container_| has hide animation, its visibility is set to false when
366 // hide animation finished. So even if the container is visible at this 370 // hide animation finished. So even if the container is visible at this
367 // point, it may in the process of hiding. We still need to show keyboard 371 // point, it may in the process of hiding. We still need to show keyboard
368 // container in this case. 372 // container in this case.
369 if (container_->IsVisible() && 373 if (container_->IsVisible() &&
370 !container_->layer()->GetAnimator()->is_animating()) 374 !container_->layer()->GetAnimator()->is_animating())
371 return; 375 return;
372 376
373 ShowKeyboard();
374 }
375
376 void KeyboardController::ShowKeyboard() {
377 ToggleTouchEventLogging(false); 377 ToggleTouchEventLogging(false);
378 ui::LayerAnimator* container_animator = container_->layer()->GetAnimator(); 378 ui::LayerAnimator* container_animator = container_->layer()->GetAnimator();
379 379
380 // If the container is not animating, makes sure the position and opacity 380 // If the container is not animating, makes sure the position and opacity
381 // are at begin states for animation. 381 // are at begin states for animation.
382 if (!container_animator->is_animating()) { 382 if (!container_animator->is_animating()) {
383 gfx::Transform transform; 383 gfx::Transform transform;
384 transform.Translate(0, proxy_->GetKeyboardWindow()->bounds().height()); 384 transform.Translate(0, proxy_->GetKeyboardWindow()->bounds().height());
385 container_->SetTransform(transform); 385 container_->SetTransform(transform);
386 container_->layer()->SetOpacity(kAnimationStartOrAfterHideOpacity); 386 container_->layer()->SetOpacity(kAnimationStartOrAfterHideOpacity);
387 } 387 }
388 388
389 container_animator->set_preemption_strategy( 389 container_animator->set_preemption_strategy(
390 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 390 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
391 animation_observer_.reset(new CallbackAnimationObserver( 391 animation_observer_.reset(new CallbackAnimationObserver(
392 container_animator, 392 container_animator,
393 base::Bind(&KeyboardController::ShowAnimationFinished, 393 base::Bind(&KeyboardController::ShowAnimationFinished,
394 base::Unretained(this)))); 394 base::Unretained(this))));
395 container_animator->AddObserver(animation_observer_.get()); 395 container_animator->AddObserver(animation_observer_.get());
396 396
397 proxy_->ShowKeyboardContainer(container_.get());
398
397 { 399 {
398 // Scope the following animation settings as we don't want to animate 400 // Scope the following animation settings as we don't want to animate
399 // visibility change that triggered by a call to the base class function 401 // visibility change that triggered by a call to the base class function
400 // ShowKeyboardContainer with these settings. The container should become 402 // ShowKeyboardContainer with these settings. The container should become
401 // visible immediately. 403 // visible immediately.
402 ui::ScopedLayerAnimationSettings settings(container_animator); 404 ui::ScopedLayerAnimationSettings settings(container_animator);
403 settings.SetTweenType(gfx::Tween::EASE_IN); 405 settings.SetTweenType(gfx::Tween::EASE_IN);
404 settings.SetTransitionDuration( 406 settings.SetTransitionDuration(
405 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); 407 base::TimeDelta::FromMilliseconds(kAnimationDurationMs));
406 container_->SetTransform(gfx::Transform()); 408 container_->SetTransform(gfx::Transform());
407 container_->layer()->SetOpacity(1.0); 409 container_->layer()->SetOpacity(1.0);
408 } 410 }
409
410 proxy_->ShowKeyboardContainer(container_.get());
411 } 411 }
412 412
413 bool KeyboardController::WillHideKeyboard() const { 413 bool KeyboardController::WillHideKeyboard() const {
414 return weak_factory_.HasWeakPtrs(); 414 return weak_factory_.HasWeakPtrs();
415 } 415 }
416 416
417 void KeyboardController::ShowAnimationFinished() { 417 void KeyboardController::ShowAnimationFinished() {
418 // Notify observers after animation finished to prevent reveal desktop 418 // Notify observers after animation finished to prevent reveal desktop
419 // background during animation. 419 // background during animation.
420 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); 420 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds());
421 proxy_->EnsureCaretInWorkArea(); 421 proxy_->EnsureCaretInWorkArea();
422 } 422 }
423 423
424 void KeyboardController::HideAnimationFinished() { 424 void KeyboardController::HideAnimationFinished() {
425 proxy_->HideKeyboardContainer(container_.get()); 425 proxy_->HideKeyboardContainer(container_.get());
426 } 426 }
427 427
428 } // namespace keyboard 428 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698