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

Side by Side Diff: ui/keyboard/keyboard_layout_manager.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_layout_manager.h" 5 #include "ui/keyboard/keyboard_layout_manager.h"
6 6
7 #include "ui/compositor/layer_animator.h" 7 #include "ui/compositor/layer_animator.h"
8 #include "ui/keyboard/keyboard_controller.h" 8 #include "ui/keyboard/keyboard_controller.h"
9 #include "ui/keyboard/keyboard_controller_proxy.h" 9 #include "ui/keyboard/keyboard_controller_proxy.h"
10 #include "ui/keyboard/keyboard_util.h" 10 #include "ui/keyboard/keyboard_util.h"
11 11
12 namespace keyboard { 12 namespace keyboard {
13 13
14 // Overridden from aura::LayoutManager 14 // Overridden from aura::LayoutManager
15 void KeyboardLayoutManager::OnWindowResized() { 15 void KeyboardLayoutManager::OnWindowResized() {
16 if (keyboard_) { 16 if (keyboard_) {
17 gfx::Rect window_bounds = controller_->GetContainerWindow()->bounds(); 17 // Container window is the top level window of the virtual keyboard window.
18 // Keep the same height when window resize. It usually get called when 18 // To support window.moveTo for the virtual keyboard window, as it actually
19 // screen rotate. 19 // moves the top level window, the container window should be set to the
20 int height = keyboard_->bounds().height(); 20 // desired bounds before changing the bounds of the virtual keyboard window.
21 keyboard_->SetBounds(gfx::Rect( 21 gfx::Rect container_bounds = controller_->GetContainerWindow()->bounds();
22 window_bounds.x(), 22 // Always align container window and keyboard window.
23 window_bounds.bottom() - height, 23 SetChildBoundsDirect(keyboard_, gfx::Rect(0, 0, container_bounds.width(),
24 window_bounds.width(), 24 container_bounds.height()));
25 height));
26 } 25 }
27 } 26 }
28 27
29 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) { 28 void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
30 DCHECK(!keyboard_); 29 DCHECK(!keyboard_);
31 keyboard_ = child; 30 keyboard_ = child;
32 keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds( 31 if (controller_->keyboard_mode() == FULL_WIDTH) {
33 controller_->GetContainerWindow()->bounds())); 32 controller_->GetContainerWindow()->SetBounds(
33 DefaultKeyboardBoundsFromWindowBounds(
34 controller_->GetContainerWindow()->GetRootWindow()->bounds()));
35 } else if (controller_->keyboard_mode() == FLOATING) {
36 controller_->GetContainerWindow()->SetBounds(child->bounds());
sadrul 2015/03/20 17:32:17 Looks like you are setting container-bounds == key
bshe 2015/03/27 16:29:16 Discussed offline. The child bounds is used by con
37 }
34 } 38 }
35 39
36 void KeyboardLayoutManager::SetChildBounds(aura::Window* child, 40 void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
37 const gfx::Rect& requested_bounds) { 41 const gfx::Rect& requested_bounds) {
38 // SetChildBounds can be invoked by resizing from the container or by
39 // resizing from the contents (through window.resizeTo call in JS).
40 // The flag resizing_from_contents() is used to determine the source of the
41 // resize.
42 DCHECK(child == keyboard_); 42 DCHECK(child == keyboard_);
43 43
44 // Request to change the bounds of child window (AKA the virtual keyboard
45 // window) should change the container window first. Then the child window is
46 // resized and covers the container window. Note the child's bound is only set
47 // in OnWindowResized.
48 gfx::Rect old_bounds = controller_->GetContainerWindow()->bounds();
49 gfx::Rect new_bounds = requested_bounds;
50 if (controller_->keyboard_mode() == FULL_WIDTH) {
51 gfx::Rect window_bounds =
52 controller_->GetContainerWindow()->GetRootWindow()->bounds();
53 new_bounds.set_y(window_bounds.height() - new_bounds.height());
54 new_bounds.set_width(window_bounds.width());
55 }
56 // Keyboard bounds should only be reset when it actually changes. Otherwise
57 // it interrupts the initial animation of showing the keyboard. Described in
58 // crbug.com/356753.
59 if (new_bounds == old_bounds) {
60 return;
61 }
62
44 ui::LayerAnimator* animator = 63 ui::LayerAnimator* animator =
45 controller_->GetContainerWindow()->layer()->GetAnimator(); 64 controller_->GetContainerWindow()->layer()->GetAnimator();
46 // Stops previous animation if a window resize is requested during animation. 65 // Stops previous animation if a window resize is requested during animation.
47 if (animator->is_animating()) 66 if (animator->is_animating())
48 animator->StopAnimating(); 67 animator->StopAnimating();
49 68
50 gfx::Rect old_bounds = child->bounds(); 69 controller_->GetContainerWindow()->SetBounds(new_bounds);
51 SetChildBoundsDirect(child, requested_bounds); 70
52 if (old_bounds.height() == 0 && child->bounds().height() != 0 && 71 if (controller_->keyboard_mode() == FULL_WIDTH) {
53 controller_->show_on_resize()) { 72 if (old_bounds.height() == 0 && child->bounds().height() != 0 &&
54 // The window height is set to 0 initially or before switch to an IME in a 73 controller_->show_on_resize()) {
55 // different extension. Virtual keyboard window may wait for this bounds 74 // The window height is set to 0 initially or before switch to an IME in a
56 // change to correctly animate in. 75 // different extension. Virtual keyboard window may wait for this bounds
57 controller_->ShowKeyboard(false); 76 // change to correctly animate in.
58 } else { 77 controller_->ShowKeyboard(false);
59 // We need to send out this notification only if keyboard is visible since 78 } else {
60 // keyboard window is resized even if keyboard is hidden. 79 // We need to send out this notification only if keyboard is visible since
61 if (controller_->keyboard_visible()) 80 // keyboard window is resized even if keyboard is hidden.
62 controller_->NotifyKeyboardBoundsChanging(requested_bounds); 81 if (controller_->keyboard_visible())
82 controller_->NotifyKeyboardBoundsChanging(requested_bounds);
83 }
84 } else if (controller_->keyboard_mode() == FLOATING) {
85 controller_->NotifyKeyboardBoundsChanging(gfx::Rect());
63 } 86 }
64 } 87 }
65 88
66 } // namespace keyboard 89 } // namespace keyboard
OLDNEW
« ash/root_window_controller_unittest.cc ('K') | « ui/keyboard/keyboard_controller_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698