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

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

Issue 1008453002: Allow javascript change the virtual keyboard window size and position freely in FLOATING mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 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
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 <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 const ui::InputMethod* input_method) { 434 const ui::InputMethod* input_method) {
435 DCHECK_EQ(input_method_, input_method); 435 DCHECK_EQ(input_method_, input_method);
436 input_method_ = NULL; 436 input_method_ = NULL;
437 } 437 }
438 438
439 void KeyboardController::OnShowImeIfNeeded() { 439 void KeyboardController::OnShowImeIfNeeded() {
440 ShowKeyboardInternal(); 440 ShowKeyboardInternal();
441 } 441 }
442 442
443 bool KeyboardController::ShouldEnableInsets(aura::Window* window) { 443 bool KeyboardController::ShouldEnableInsets(aura::Window* window) {
444 aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); 444 aura::Window* keyboard_window = proxy_->GetKeyboardWindow();
445 return (keyboard_window->GetRootWindow() == window->GetRootWindow() && 445 return (keyboard_window->GetRootWindow() == window->GetRootWindow() &&
446 keyboard::IsKeyboardOverscrollEnabled() && 446 keyboard::IsKeyboardOverscrollEnabled() &&
447 proxy_->GetKeyboardWindow()->IsVisible() && 447 keyboard_window->IsVisible() && keyboard_visible_);
448 keyboard_visible_);
449 } 448 }
450 449
451 void KeyboardController::UpdateWindowInsets(aura::Window* window) { 450 void KeyboardController::UpdateWindowInsets(aura::Window* window) {
452 aura::Window *keyboard_window = proxy_->GetKeyboardWindow(); 451 aura::Window* keyboard_window = proxy_->GetKeyboardWindow();
453 if (window == keyboard_window) 452 if (window == keyboard_window)
454 return; 453 return;
455 454
456 scoped_ptr<content::RenderWidgetHostIterator> widgets( 455 scoped_ptr<content::RenderWidgetHostIterator> widgets(
457 content::RenderWidgetHost::GetRenderWidgetHosts()); 456 content::RenderWidgetHost::GetRenderWidgetHosts());
458 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { 457 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
459 content::RenderWidgetHostView* view = widget->GetView(); 458 content::RenderWidgetHostView* view = widget->GetView();
460 if (view && window->Contains(view->GetNativeView())) { 459 if (view && window->Contains(view->GetNativeView())) {
461 gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen(); 460 gfx::Rect window_bounds = view->GetNativeView()->GetBoundsInScreen();
462 gfx::Rect intersect = gfx::IntersectRects(window_bounds, 461 gfx::Rect intersect =
463 proxy_->GetKeyboardWindow()->bounds()); 462 gfx::IntersectRects(window_bounds, keyboard_window->bounds());
464 int overlap = ShouldEnableInsets(window) ? intersect.height() : 0; 463 int overlap = ShouldEnableInsets(window) ? intersect.height() : 0;
465 if (overlap > 0 && overlap < window_bounds.height()) 464 if (overlap > 0 && overlap < window_bounds.height())
466 view->SetInsets(gfx::Insets(0, 0, overlap, 0)); 465 view->SetInsets(gfx::Insets(0, 0, overlap, 0));
467 else 466 else
468 view->SetInsets(gfx::Insets()); 467 view->SetInsets(gfx::Insets());
469 return; 468 return;
470 } 469 }
471 } 470 }
472 } 471 }
473 472
473 void KeyboardController::OnRootWindowResized(const gfx::Rect& bounds) {
474 // Keep the same height when window resize. It gets called when screen rotate.
475 if (!keyboard_container_initialized() || !proxy_->GetKeyboardWindow())
476 return;
477
478 int container_height = container_->bounds().height();
479 if (keyboard_mode_ == FULL_WIDTH) {
480 container_->SetBounds(gfx::Rect(bounds.x(),
481 bounds.bottom() - container_height,
482 bounds.width(), container_height));
483 } else if (keyboard_mode_ == FLOATING) {
484 // When screen rotate, horizontally center floating virtual keyboard window
485 // and vertically align it to the bottom.
486 int container_width = container_->bounds().width();
487 container_->SetBounds(gfx::Rect(
488 bounds.x() + (bounds.width() - container_width) / 2,
489 bounds.bottom() - container_height, container_width, container_height));
490 }
491 }
492
474 void KeyboardController::ShowKeyboardInternal() { 493 void KeyboardController::ShowKeyboardInternal() {
475 if (!container_.get()) 494 if (!container_.get())
476 return; 495 return;
477 496
478 if (container_->children().empty()) { 497 if (container_->children().empty()) {
479 keyboard::MarkKeyboardLoadStarted(); 498 keyboard::MarkKeyboardLoadStarted();
480 aura::Window* keyboard = proxy_->GetKeyboardWindow(); 499 aura::Window* keyboard = proxy_->GetKeyboardWindow();
481 keyboard->Show(); 500 keyboard->Show();
482 container_->AddChild(keyboard); 501 container_->AddChild(keyboard);
483 keyboard->set_owned_by_parent(false); 502 keyboard->set_owned_by_parent(false);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 window_bounds_observer_->RemoveAllObservedWindows(); 576 window_bounds_observer_->RemoveAllObservedWindows();
558 } 577 }
559 578
560 bool KeyboardController::WillHideKeyboard() const { 579 bool KeyboardController::WillHideKeyboard() const {
561 return weak_factory_.HasWeakPtrs(); 580 return weak_factory_.HasWeakPtrs();
562 } 581 }
563 582
564 void KeyboardController::ShowAnimationFinished() { 583 void KeyboardController::ShowAnimationFinished() {
565 // Notify observers after animation finished to prevent reveal desktop 584 // Notify observers after animation finished to prevent reveal desktop
566 // background during animation. 585 // background during animation.
567 NotifyKeyboardBoundsChanging(proxy_->GetKeyboardWindow()->bounds()); 586 NotifyKeyboardBoundsChanging(container_->bounds());
568 proxy_->EnsureCaretInWorkArea(); 587 proxy_->EnsureCaretInWorkArea();
569 } 588 }
570 589
571 void KeyboardController::HideAnimationFinished() { 590 void KeyboardController::HideAnimationFinished() {
572 proxy_->HideKeyboardContainer(container_.get()); 591 proxy_->HideKeyboardContainer(container_.get());
573 } 592 }
574 593
575 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) { 594 void KeyboardController::AddBoundsChangedObserver(aura::Window* window) {
576 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr; 595 aura::Window* target_window = window ? window->GetToplevelWindow() : nullptr;
577 if (target_window) 596 if (target_window)
578 window_bounds_observer_->AddObservedWindow(target_window); 597 window_bounds_observer_->AddObservedWindow(target_window);
579 } 598 }
580 599
581 } // namespace keyboard 600 } // namespace keyboard
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698