summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 20:00:01 +0000
committerbshe@chromium.org <bshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 20:00:01 +0000
commit39e9521b57d2badebea576e14fe8c901e02992fa (patch)
treef30239c7cbd37bdf26a08e8607288ae213919f0b
parent29354a78adb7f5f76313c3012caf8d3791db5fa3 (diff)
downloadchromium_src-39e9521b57d2badebea576e14fe8c901e02992fa.zip
chromium_src-39e9521b57d2badebea576e14fe8c901e02992fa.tar.gz
chromium_src-39e9521b57d2badebea576e14fe8c901e02992fa.tar.bz2
Currently, we try to set virtual keyboard window height both
in native code and in VK's javascript code through window.resizeTo It sometimes creates conflict and cause strange animation issues. In this CL, the window height logic in native side is removed. The default window height is set to 0 and we expect javascript will set the window to correct height. If window is resized from a non zero height to another non zeor height, we current dont do any animation. BUG=363622 Review URL: https://codereview.chromium.org/240443006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265712 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/root_window_controller_unittest.cc8
-rw-r--r--ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc2
-rw-r--r--ash/wm/system_modal_container_layout_manager_unittest.cc33
-rw-r--r--ui/keyboard/keyboard_controller.cc22
-rw-r--r--ui/keyboard/keyboard_controller.h7
-rw-r--r--ui/keyboard/keyboard_controller_proxy.cc4
-rw-r--r--ui/keyboard/keyboard_controller_proxy.h12
-rw-r--r--ui/keyboard/keyboard_controller_unittest.cc63
-rw-r--r--ui/keyboard/keyboard_layout_manager.cc42
-rw-r--r--ui/keyboard/keyboard_layout_manager.h2
-rw-r--r--ui/keyboard/keyboard_util.cc37
-rw-r--r--ui/keyboard/keyboard_util.h5
-rw-r--r--ui/keyboard/resources/constants.js12
-rw-r--r--ui/keyboard/resources/main.js12
14 files changed, 130 insertions, 131 deletions
diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc
index 69aad6b..c6cce9a 100644
--- a/ash/root_window_controller_unittest.cc
+++ b/ash/root_window_controller_unittest.cc
@@ -28,6 +28,7 @@
#include "ui/events/test/test_event_handler.h"
#include "ui/keyboard/keyboard_controller_proxy.h"
#include "ui/keyboard/keyboard_switches.h"
+#include "ui/keyboard/keyboard_util.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -702,6 +703,8 @@ TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
aura::Window* keyboard_window = controller->proxy()->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
+ keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
+ keyboard_container->bounds(), 100));
keyboard_window->Show();
gfx::Rect before = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
@@ -731,9 +734,8 @@ TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
proxy()->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
- keyboard_window->SetBounds(gfx::Rect());
- keyboard_window->Show();
-
+ keyboard_window->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
+ keyboard_container->bounds(), 100));
ui::test::TestEventHandler* handler = new ui::test::TestEventHandler;
root_window->SetEventFilter(handler);
aura::test::EventGenerator root_window_event_generator(root_window);
diff --git a/ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc b/ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc
index 9eb190b..2875d9e 100644
--- a/ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc
+++ b/ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.cc
@@ -99,7 +99,7 @@ bool VirtualKeyboardTray::ClickedOutsideBubble() {
}
bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
- keyboard::KeyboardController::GetInstance()->ShowAndLockKeyboard();
+ keyboard::KeyboardController::GetInstance()->ShowKeyboard(true);
return true;
}
diff --git a/ash/wm/system_modal_container_layout_manager_unittest.cc b/ash/wm/system_modal_container_layout_manager_unittest.cc
index 55f0d8c..568ea50 100644
--- a/ash/wm/system_modal_container_layout_manager_unittest.cc
+++ b/ash/wm/system_modal_container_layout_manager_unittest.cc
@@ -149,8 +149,8 @@ class SystemModalContainerLayoutManagerTest : public AshTestBase {
public:
virtual void SetUp() OVERRIDE {
// Allow a virtual keyboard (and initialize it per default).
- CommandLine::ForCurrentProcess()->AppendSwitch(
- keyboard::switches::kEnableVirtualKeyboard);
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
keyboard::KeyboardController::GetInstance());
@@ -184,31 +184,20 @@ class SystemModalContainerLayoutManagerTest : public AshTestBase {
if (show == keyboard->keyboard_visible())
return;
- // The animation has to run in order to get the notification. Run the
- // animation and wait until its finished.
- ui::ScopedAnimationDurationScaleMode normal_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
- if (show)
- keyboard->ShowAndLockKeyboard();
- else
+ if (show) {
+ keyboard->ShowKeyboard(true);
+ if (keyboard->proxy()->GetKeyboardWindow()->bounds().height() == 0) {
+ keyboard->proxy()->GetKeyboardWindow()->SetBounds(
+ keyboard::KeyboardBoundsFromWindowBounds(
+ keyboard->GetContainerWindow()->bounds(), 100));
+ }
+ } else {
keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL);
-
- WaitForWindowAnimationToBeFinished(keyboard->GetContainerWindow());
+ }
DCHECK_EQ(show, keyboard->keyboard_visible());
}
- void WaitForWindowAnimationToBeFinished(aura::Window* window) {
- DCHECK(window);
- ui::Layer* layer = window->layer();
- ui::LayerAnimatorTestController controller(layer->GetAnimator());
- gfx::AnimationContainerElement* element = layer->GetAnimator();
- while (controller.animator()->is_animating()) {
- controller.StartThreadedAnimationsIfNeeded();
- base::TimeTicks step_time = controller.animator()->last_step_time();
- element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
- }
- }
};
TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) {
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index 4dd085c..52c7c14 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -275,9 +275,9 @@ void KeyboardController::RemoveObserver(KeyboardControllerObserver* observer) {
observer_list_.RemoveObserver(observer);
}
-void KeyboardController::ShowAndLockKeyboard() {
- set_lock_keyboard(true);
- OnShowImeIfNeeded();
+void KeyboardController::ShowKeyboard(bool lock) {
+ set_lock_keyboard(lock);
+ ShowKeyboardInternal();
}
void KeyboardController::OnWindowHierarchyChanged(
@@ -298,7 +298,7 @@ void KeyboardController::OnTextInputStateChanged(
return;
if (IsKeyboardUsabilityExperimentEnabled()) {
- OnShowImeIfNeeded();
+ ShowKeyboardInternal();
return;
}
@@ -337,6 +337,10 @@ void KeyboardController::OnInputMethodDestroyed(
}
void KeyboardController::OnShowImeIfNeeded() {
+ ShowKeyboardInternal();
+}
+
+void KeyboardController::ShowKeyboardInternal() {
if (!container_.get())
return;
@@ -350,7 +354,7 @@ void KeyboardController::OnShowImeIfNeeded() {
proxy_->ReloadKeyboardIfNeeded();
- if (keyboard_visible_)
+ if (keyboard_visible_ || proxy_->GetKeyboardWindow()->bounds().height() == 0)
return;
keyboard_visible_ = true;
@@ -370,10 +374,6 @@ void KeyboardController::OnShowImeIfNeeded() {
!container_->layer()->GetAnimator()->is_animating())
return;
- ShowKeyboard();
-}
-
-void KeyboardController::ShowKeyboard() {
ToggleTouchEventLogging(false);
ui::LayerAnimator* container_animator = container_->layer()->GetAnimator();
@@ -394,6 +394,8 @@ void KeyboardController::ShowKeyboard() {
base::Unretained(this))));
container_animator->AddObserver(animation_observer_.get());
+ proxy_->ShowKeyboardContainer(container_.get());
+
{
// Scope the following animation settings as we don't want to animate
// visibility change that triggered by a call to the base class function
@@ -406,8 +408,6 @@ void KeyboardController::ShowKeyboard() {
container_->SetTransform(gfx::Transform());
container_->layer()->SetOpacity(1.0);
}
-
- proxy_->ShowKeyboardContainer(container_.get());
}
bool KeyboardController::WillHideKeyboard() const {
diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h
index 0541165..d623062 100644
--- a/ui/keyboard/keyboard_controller.h
+++ b/ui/keyboard/keyboard_controller.h
@@ -76,8 +76,9 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
void set_lock_keyboard(bool lock) { lock_keyboard_ = lock; }
- // Force the keyboard to show up if not showing and lock the keyboard.
- void ShowAndLockKeyboard();
+ // Force the keyboard to show up if not showing and lock the keyboard if
+ // |lock| is true.
+ void ShowKeyboard(bool lock);
// Sets the active keyboard controller. KeyboardController takes ownership of
// the instance. Calling ResetIntance with a new instance destroys the
@@ -118,7 +119,7 @@ class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver,
virtual void OnShowImeIfNeeded() OVERRIDE;
// Show virtual keyboard immediately with animation.
- void ShowKeyboard();
+ void ShowKeyboardInternal();
// Returns true if keyboard is scheduled to hide.
bool WillHideKeyboard() const;
diff --git a/ui/keyboard/keyboard_controller_proxy.cc b/ui/keyboard/keyboard_controller_proxy.cc
index acd78f8..9286946 100644
--- a/ui/keyboard/keyboard_controller_proxy.cc
+++ b/ui/keyboard/keyboard_controller_proxy.cc
@@ -54,9 +54,7 @@ class KeyboardContentsDelegate : public content::WebContentsDelegate,
int new_height = pos.height();
bounds.set_y(bounds.y() + bounds.height() - new_height);
bounds.set_height(new_height);
- proxy_->set_resizing_from_contents(true);
keyboard->SetBounds(bounds);
- proxy_->set_resizing_from_contents(false);
}
// Overridden from content::WebContentsDelegate:
@@ -81,7 +79,7 @@ class KeyboardContentsDelegate : public content::WebContentsDelegate,
namespace keyboard {
KeyboardControllerProxy::KeyboardControllerProxy()
- : default_url_(kKeyboardURL), resizing_from_contents_(false) {
+ : default_url_(kKeyboardURL) {
}
KeyboardControllerProxy::~KeyboardControllerProxy() {
diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h
index f05f6f2..0884cd9 100644
--- a/ui/keyboard/keyboard_controller_proxy.h
+++ b/ui/keyboard/keyboard_controller_proxy.h
@@ -52,19 +52,10 @@ class KEYBOARD_EXPORT KeyboardControllerProxy {
// with the proxy.
virtual aura::Window* GetKeyboardWindow();
- // Whether the keyboard window is resizing from its web contents.
- bool resizing_from_contents() const { return resizing_from_contents_; }
-
// Whether the keyboard window is created. The keyboard window is tied to a
// WebContent so we can just check if the WebContent is created or not.
virtual bool HasKeyboardWindow() const;
- // Sets the flag of whether the keyboard window is resizing from
- // its web contents.
- void set_resizing_from_contents(bool resizing) {
- resizing_from_contents_ = resizing;
- }
-
// Gets the InputMethod that will provide notifications about changes in the
// text input context.
virtual ui::InputMethod* GetInputMethod() = 0;
@@ -130,9 +121,6 @@ class KEYBOARD_EXPORT KeyboardControllerProxy {
scoped_ptr<content::WebContents> keyboard_contents_;
- // Whether the current keyboard window is resizing from its web content.
- bool resizing_from_contents_;
-
DISALLOW_COPY_AND_ASSIGN(KeyboardControllerProxy);
};
diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc
index cee5581..4333c84 100644
--- a/ui/keyboard/keyboard_controller_unittest.cc
+++ b/ui/keyboard/keyboard_controller_unittest.cc
@@ -27,6 +27,7 @@
#include "ui/keyboard/keyboard_controller_observer.h"
#include "ui/keyboard/keyboard_controller_proxy.h"
#include "ui/keyboard/keyboard_switches.h"
+#include "ui/keyboard/keyboard_util.h"
namespace keyboard {
namespace {
@@ -193,8 +194,15 @@ class KeyboardControllerTest : public testing::Test {
void SetFocus(ui::TextInputClient* client) {
ui::InputMethod* input_method = proxy()->GetInputMethod();
input_method->SetFocusedTextInputClient(client);
- if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE)
+ if (client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) {
input_method->ShowImeIfNeeded();
+ if (proxy_->GetKeyboardWindow()->bounds().height() == 0) {
+ // Set initial bounds for test keyboard window.
+ proxy_->GetKeyboardWindow()->SetBounds(
+ KeyboardBoundsFromWindowBounds(
+ controller()->GetContainerWindow()->bounds(), 100));
+ }
+ }
}
bool WillHideKeyboard() {
@@ -214,17 +222,27 @@ class KeyboardControllerTest : public testing::Test {
TEST_F(KeyboardControllerTest, KeyboardSize) {
aura::Window* container(controller()->GetContainerWindow());
- gfx::Rect bounds(0, 0, 100, 100);
- container->SetBounds(bounds);
+ aura::Window* keyboard(proxy()->GetKeyboardWindow());
+ container->SetBounds(gfx::Rect(0, 0, 200, 100));
+
+ container->AddChild(keyboard);
+ const gfx::Rect& before_bounds = keyboard->bounds();
+ // The initial keyboard should be positioned at the bottom of container and
+ // has 0 height.
+ ASSERT_EQ(gfx::Rect(0, 100, 200, 0), before_bounds);
- const gfx::Rect& before_bounds = proxy()->GetKeyboardWindow()->bounds();
gfx::Rect new_bounds(
- before_bounds.x(), before_bounds.y(),
- before_bounds.width() / 2, before_bounds.height() / 2);
+ before_bounds.x(), before_bounds.y() - 50,
+ before_bounds.width(), 50);
+
+ keyboard->SetBounds(new_bounds);
+ ASSERT_EQ(new_bounds, keyboard->bounds());
- // The KeyboardController's LayoutManager shouldn't let this happen
- proxy()->GetKeyboardWindow()->SetBounds(new_bounds);
- ASSERT_EQ(before_bounds, proxy()->GetKeyboardWindow()->bounds());
+ // Mock a screen rotation.
+ container->SetBounds(gfx::Rect(0, 0, 100, 200));
+ // The above call should resize keyboard to new width while keeping the old
+ // height.
+ ASSERT_EQ(gfx::Rect(0, 150, 100, 50), keyboard->bounds());
}
// Tests that tapping/clicking inside the keyboard does not give it focus.
@@ -393,33 +411,6 @@ TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
EXPECT_FALSE(keyboard_container->IsVisible());
}
-TEST_F(KeyboardControllerTest, KeyboardResizingFromContents) {
- aura::Window* keyboard_container = controller()->GetContainerWindow();
- aura::Window* keyboard_window = proxy()->GetKeyboardWindow();
- keyboard_container->SetBounds(gfx::Rect(800, 600));
- keyboard_container->AddChild(keyboard_window);
-
- int original_height = keyboard_window->bounds().height();
-
- // Resizes from contents when flag is unset.
- keyboard_window->SetBounds(gfx::Rect(100, 80));
- EXPECT_EQ(original_height, keyboard_window->bounds().height());
-
- // Resizes from contents when flag is set.
- proxy()->set_resizing_from_contents(true);
- keyboard_window->SetBounds(gfx::Rect(100, 80));
- EXPECT_EQ(80, keyboard_window->bounds().height());
-
- // Resizes from container when flag is set.
- keyboard_container->SetBounds(gfx::Rect(400, 300));
- EXPECT_EQ(80, keyboard_window->bounds().height());
-
- // Resizes from container when flag is unset.
- proxy()->set_resizing_from_contents(false);
- keyboard_container->SetBounds(gfx::Rect(800, 600));
- EXPECT_EQ(original_height, keyboard_window->bounds().height());
-}
-
class KeyboardControllerAnimationTest : public KeyboardControllerTest,
public KeyboardControllerObserver {
public:
diff --git a/ui/keyboard/keyboard_layout_manager.cc b/ui/keyboard/keyboard_layout_manager.cc
index 3208541..d7faf0f 100644
--- a/ui/keyboard/keyboard_layout_manager.cc
+++ b/ui/keyboard/keyboard_layout_manager.cc
@@ -4,6 +4,7 @@
#include "ui/keyboard/keyboard_layout_manager.h"
+#include "ui/compositor/layer_animator.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_controller_proxy.h"
#include "ui/keyboard/keyboard_util.h"
@@ -12,14 +13,24 @@ namespace keyboard {
// Overridden from aura::LayoutManager
void KeyboardLayoutManager::OnWindowResized() {
- if (keyboard_ && !controller_->proxy()->resizing_from_contents())
- ResizeKeyboardToDefault(keyboard_);
+ if (keyboard_) {
+ gfx::Rect window_bounds = controller_->GetContainerWindow()->bounds();
+ // Keep the same height when window resize. It usually get called when
+ // screen rotate.
+ int height = keyboard_->bounds().height();
+ keyboard_->SetBounds(gfx::Rect(
+ window_bounds.x(),
+ window_bounds.bottom() - height,
+ window_bounds.width(),
+ height));
+ }
}
void KeyboardLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
DCHECK(!keyboard_);
keyboard_ = child;
- ResizeKeyboardToDefault(keyboard_);
+ keyboard_->SetBounds(DefaultKeyboardBoundsFromWindowBounds(
+ controller_->GetContainerWindow()->bounds()));
}
void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
@@ -28,16 +39,25 @@ void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
// resizing from the contents (through window.resizeTo call in JS).
// The flag resizing_from_contents() is used to determine the source of the
// resize.
- if (controller_->proxy()->resizing_from_contents()) {
+ DCHECK(child == keyboard_);
+
+ ui::LayerAnimator* animator =
+ controller_->GetContainerWindow()->layer()->GetAnimator();
+ // Stops previous animation if a window resize is requested during animation.
+ if (animator->is_animating())
+ animator->StopAnimating();
+
+ gfx::Rect old_bounds = child->bounds();
+ SetChildBoundsDirect(child, requested_bounds);
+ if (old_bounds.height() == 0 && child->bounds().height() != 0) {
+ // The window height is set to 0 initially. If the height of |old_bounds| is
+ // 0 and the new bounds is not 0, it probably means window.resizeTo is
+ // called to set the window height. We should try to show keyboard again in
+ // case the show keyboard request is called before the height is set.
+ controller_->ShowKeyboard(false);
+ } else {
controller_->NotifyKeyboardBoundsChanging(requested_bounds);
- SetChildBoundsDirect(child, requested_bounds);
}
}
-void KeyboardLayoutManager::ResizeKeyboardToDefault(aura::Window* child) {
- gfx::Rect keyboard_bounds = DefaultKeyboardBoundsFromWindowBounds(
- controller_->GetContainerWindow()->bounds());
- SetChildBoundsDirect(child, keyboard_bounds);
-}
-
} // namespace keyboard
diff --git a/ui/keyboard/keyboard_layout_manager.h b/ui/keyboard/keyboard_layout_manager.h
index 52af5c9..bc13f16 100644
--- a/ui/keyboard/keyboard_layout_manager.h
+++ b/ui/keyboard/keyboard_layout_manager.h
@@ -32,8 +32,6 @@ class KeyboardLayoutManager : public aura::LayoutManager {
const gfx::Rect& requested_bounds) OVERRIDE;
private:
- void ResizeKeyboardToDefault(aura::Window* child);
-
KeyboardController* controller_;
aura::Window* keyboard_;
diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc
index 7048be2..1e06795 100644
--- a/ui/keyboard/keyboard_util.cc
+++ b/ui/keyboard/keyboard_util.cc
@@ -43,26 +43,6 @@ bool g_accessibility_keyboard_enabled = false;
base::LazyInstance<GURL> g_override_content_url = LAZY_INSTANCE_INITIALIZER;
-// The ratio between the height of the keyboard and the screen when using the
-// usability keyboard.
-const float kUsabilityKeyboardHeightRatio = 1.0f;
-
-// The default ratio between the height of the keyboard and the screen.
-const float kDefaultKeyboardHeightRatio = 0.41f;
-
-// The ratio between the height of the keyboard and the screen when using the
-// accessibility keyboard.
-const float kAccessibilityKeyboardHeightRatio = 0.3f;
-
-float GetKeyboardHeightRatio(){
- if (keyboard::IsKeyboardUsabilityExperimentEnabled()) {
- return kUsabilityKeyboardHeightRatio;
- } else if (keyboard::GetAccessibilityKeyboardEnabled()) {
- return kAccessibilityKeyboardHeightRatio;
- }
- return kDefaultKeyboardHeightRatio;
-}
-
bool g_touch_keyboard_enabled = false;
} // namespace
@@ -71,12 +51,23 @@ namespace keyboard {
gfx::Rect DefaultKeyboardBoundsFromWindowBounds(
const gfx::Rect& window_bounds) {
- const float kKeyboardHeightRatio = GetKeyboardHeightRatio();
+ // Initialize default keyboard height to 0. The keyboard window height should
+ // only be set by window.resizeTo in virtual keyboard web contents. Otherwise,
+ // the default height may conflict with the new height and causing some
+ // strange animation issues. For keyboard usability experiments, a full screen
+ // virtual keyboard window is always preferred.
int keyboard_height =
- static_cast<int>(window_bounds.height() * kKeyboardHeightRatio);
+ keyboard::IsKeyboardUsabilityExperimentEnabled() ?
+ window_bounds.height() : 0;
+
+ return KeyboardBoundsFromWindowBounds(window_bounds, keyboard_height);
+}
+
+gfx::Rect KeyboardBoundsFromWindowBounds(const gfx::Rect& window_bounds,
+ int keyboard_height) {
return gfx::Rect(
window_bounds.x(),
- window_bounds.y() + window_bounds.height() - keyboard_height,
+ window_bounds.bottom() - keyboard_height,
window_bounds.width(),
keyboard_height);
}
diff --git a/ui/keyboard/keyboard_util.h b/ui/keyboard/keyboard_util.h
index a3a1f8a..4e09d96e 100644
--- a/ui/keyboard/keyboard_util.h
+++ b/ui/keyboard/keyboard_util.h
@@ -42,6 +42,11 @@ enum KeyboardControlEvent {
KEYBOARD_EXPORT gfx::Rect DefaultKeyboardBoundsFromWindowBounds(
const gfx::Rect& window_bounds);
+// Gets the caculated keyboard bounds from |window_bounds|. The keyboard height
+// is specified by |keyboard_height|.
+KEYBOARD_EXPORT gfx::Rect KeyboardBoundsFromWindowBounds(
+ const gfx::Rect& window_bounds, int keyboard_height);
+
// Sets the state of the a11y onscreen keyboard.
KEYBOARD_EXPORT void SetAccessibilityKeyboardEnabled(bool enabled);
diff --git a/ui/keyboard/resources/constants.js b/ui/keyboard/resources/constants.js
index 9636559..9b01704 100644
--- a/ui/keyboard/resources/constants.js
+++ b/ui/keyboard/resources/constants.js
@@ -59,6 +59,18 @@ var KEY_ASPECT_RATIO_PORTRAIT = 1;
var KEY_ASPECT_RATIO_LANDSCAPE = 1.46;
/**
+ * The ratio between the height and width of the compact keyboard.
+ * @type {number}
+ */
+var DEFAULT_KEYBOARD_ASPECT_RATIO = 0.3;
+
+/**
+ * The ratio between the height and width of the a11y keyboard.
+ * @type {number}
+ */
+var DEFAULT_A11Y_KEYBOARD_ASPECT_RATIO = 0.41;
+
+/**
* The default weight of a key.
* @type {number}
*/
diff --git a/ui/keyboard/resources/main.js b/ui/keyboard/resources/main.js
index 8eb8d5b..c837aed 100644
--- a/ui/keyboard/resources/main.js
+++ b/ui/keyboard/resources/main.js
@@ -205,9 +205,14 @@
* @return {Array.<String, number>} The bounds of the keyboard container.
*/
function getKeyboardBounds_() {
+ var keyboard = $('keyboard');
+ var ratio = DEFAULT_KEYBOARD_ASPECT_RATIO;
+ if (keyboard.config && keyboard.config.a11ymode) {
+ ratio = DEFAULT_A11Y_KEYBOARD_ASPECT_RATIO;
+ }
return {
- "width": window.innerWidth,
- "height": window.innerHeight,
+ "width": screen.width,
+ "height": screen.height * ratio
};
}
@@ -566,8 +571,7 @@
*/
function resizeKeyboardContainer(opt_params) {
var params = opt_params ? opt_params : new AlignmentOptions();
- var bounds = getKeyboardBounds();
- if (Math.abs(bounds.height - params.height) > RESIZE_THRESHOLD) {
+ if (Math.abs(window.innerHeight - params.height) > RESIZE_THRESHOLD) {
// Cannot resize more than 50% of screen height due to crbug.com/338829.
window.resizeTo(params.width, params.height);
}