diff options
author | bshe <bshe@chromium.org> | 2015-06-11 08:22:53 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-11 15:24:42 +0000 |
commit | 22e68ea2da8caf496186e1fbac78a041015c80ef (patch) | |
tree | c0fa16d4300ee524c5df008d6eca110870c03b9b | |
parent | cfb044b18e1fc818972697478a238ab39c144148 (diff) | |
download | chromium_src-22e68ea2da8caf496186e1fbac78a041015c80ef.zip chromium_src-22e68ea2da8caf496186e1fbac78a041015c80ef.tar.gz chromium_src-22e68ea2da8caf496186e1fbac78a041015c80ef.tar.bz2 |
Fix centered vk when switch to a new extension while in floating mode
BUG=489366
Review URL: https://codereview.chromium.org/1167733002
Cr-Commit-Position: refs/heads/master@{#333954}
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc | 12 | ||||
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/ash/keyboard_controller_browsertest.cc | 65 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.cc | 22 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.h | 4 |
5 files changed, 68 insertions, 37 deletions
diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc index 090538f..e0c9c5c 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc @@ -114,7 +114,7 @@ AshKeyboardControllerProxy::AshKeyboardControllerProxy( } AshKeyboardControllerProxy::~AshKeyboardControllerProxy() { - DCHECK(!keyboard_controller_); + DCHECK(!keyboard_controller()); } ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { @@ -152,14 +152,14 @@ void AshKeyboardControllerProxy::SetController( keyboard::KeyboardController* controller) { // During KeyboardController destruction, controller can be set to null. if (!controller) { - DCHECK(keyboard_controller_); - keyboard_controller_->RemoveObserver(observer_.get()); - keyboard_controller_ = nullptr; + DCHECK(keyboard_controller()); + keyboard_controller()->RemoveObserver(observer_.get()); + KeyboardControllerProxy::SetController(nullptr); return; } - keyboard_controller_ = controller; + KeyboardControllerProxy::SetController(controller); observer_.reset(new AshKeyboardControllerObserver(browser_context())); - keyboard_controller_->AddObserver(observer_.get()); + keyboard_controller()->AddObserver(observer_.get()); } void AshKeyboardControllerProxy::RenderViewCreated( diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h index e22d363..d78d974 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h @@ -61,8 +61,6 @@ class AshKeyboardControllerProxy // content::WebContentsObserver overrides void RenderViewCreated(content::RenderViewHost* render_view_host) override; - keyboard::KeyboardController* keyboard_controller_; - scoped_ptr<keyboard::KeyboardControllerObserver> observer_; DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerProxy); diff --git a/chrome/browser/ui/ash/keyboard_controller_browsertest.cc b/chrome/browser/ui/ash/keyboard_controller_browsertest.cc index 1144c91..e8a2e9a 100644 --- a/chrome/browser/ui/ash/keyboard_controller_browsertest.cc +++ b/chrome/browser/ui/ash/keyboard_controller_browsertest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ash/shell.h" #include "base/command_line.h" #include "chrome/test/base/in_process_browser_test.h" #include "content/public/browser/web_contents.h" @@ -20,8 +21,8 @@ const int kKeyboardHeightForTest = 100; class VirtualKeyboardWebContentTest : public InProcessBrowserTest { public: - VirtualKeyboardWebContentTest() {}; - ~VirtualKeyboardWebContentTest() override{}; + VirtualKeyboardWebContentTest() {} + ~VirtualKeyboardWebContentTest() override {} void SetUp() override { ui::SetUpInputMethodFactoryForTesting(); @@ -39,12 +40,14 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest { } protected: - void FocusEditableNodeAndShowKeyboard() { + void FocusEditableNodeAndShowKeyboard(const gfx::Rect& init_bounds) { client.reset(new ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT)); ui::InputMethod* input_method = proxy()->GetInputMethod(); input_method->SetFocusedTextInputClient(client.get()); input_method->ShowImeIfNeeded(); - ResizeKeyboardWindow(); + // Mock window.resizeTo that is expected to be called after navigate to a + // new virtual keyboard. + proxy()->GetKeyboardWindow()->SetBounds(init_bounds); } void FocusNonEditableNode() { @@ -53,10 +56,13 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest { input_method->SetFocusedTextInputClient(client.get()); } - void MockEnableIMEInDifferentExtension(const std::string& url) { + void MockEnableIMEInDifferentExtension(const std::string& url, + const gfx::Rect& init_bounds) { keyboard::SetOverrideContentUrl(GURL(url)); keyboard::KeyboardController::GetInstance()->Reload(); - ResizeKeyboardWindow(); + // Mock window.resizeTo that is expected to be called after navigate to a + // new virtual keyboard. + proxy()->GetKeyboardWindow()->SetBounds(init_bounds); } bool IsKeyboardVisible() const { @@ -64,17 +70,6 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest { } private: - // Mock window.resizeTo that is expected to be called after navigate to a new - // virtual keyboard. - void ResizeKeyboardWindow() { - gfx::Rect bounds = proxy()->GetKeyboardWindow()->bounds(); - proxy()->GetKeyboardWindow()->SetBounds(gfx::Rect( - bounds.x(), - bounds.bottom() - kKeyboardHeightForTest, - bounds.width(), - kKeyboardHeightForTest)); - } - scoped_ptr<ui::DummyTextInputClient> client; DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardWebContentTest); @@ -84,16 +79,17 @@ class VirtualKeyboardWebContentTest : public InProcessBrowserTest { // its virtual keyboard should not become visible if previous one is not. IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest, EnableIMEInDifferentExtension) { - FocusEditableNodeAndShowKeyboard(); + gfx::Rect test_bounds(0, 0, 0, kKeyboardHeightForTest); + FocusEditableNodeAndShowKeyboard(test_bounds); EXPECT_TRUE(IsKeyboardVisible()); FocusNonEditableNode(); EXPECT_FALSE(IsKeyboardVisible()); - MockEnableIMEInDifferentExtension("chrome-extension://domain-1"); + MockEnableIMEInDifferentExtension("chrome-extension://domain-1", test_bounds); // Keyboard should not become visible if previous keyboard is not. EXPECT_FALSE(IsKeyboardVisible()); - FocusEditableNodeAndShowKeyboard(); + FocusEditableNodeAndShowKeyboard(test_bounds); // Keyboard should become visible after focus on an editable node. EXPECT_TRUE(IsKeyboardVisible()); @@ -102,8 +98,35 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest, keyboard::KeyboardController::HIDE_REASON_MANUAL); EXPECT_FALSE(IsKeyboardVisible()); - MockEnableIMEInDifferentExtension("chrome-extension://domain-2"); + MockEnableIMEInDifferentExtension("chrome-extension://domain-2", test_bounds); // Keyboard should not become visible if previous keyboard is not, even if it // is currently focused on an editable node. EXPECT_FALSE(IsKeyboardVisible()); } + +// Test for crbug.com/489366. In FLOATING mode, switch to a new IME in a +// different extension should exist FLOATIN mode and position the new IME in +// FULL_WIDTH mode. +IN_PROC_BROWSER_TEST_F(VirtualKeyboardWebContentTest, + IMEInDifferentExtensionNotCentered) { + gfx::Rect test_bounds(0, 0, 0, kKeyboardHeightForTest); + FocusEditableNodeAndShowKeyboard(test_bounds); + keyboard::KeyboardController* controller = + keyboard::KeyboardController::GetInstance(); + const gfx::Rect& screen_bounds = ash::Shell::GetPrimaryRootWindow()->bounds(); + gfx::Rect keyboard_bounds = controller->GetContainerWindow()->bounds(); + EXPECT_EQ(kKeyboardHeightForTest, keyboard_bounds.height()); + EXPECT_EQ(screen_bounds.height(), + keyboard_bounds.height() + keyboard_bounds.y()); + controller->SetKeyboardMode(keyboard::FLOATING); + // Move keyboard to a random place. + proxy()->GetKeyboardWindow()->SetBounds(gfx::Rect(50, 50, 50, 50)); + EXPECT_EQ(gfx::Rect(50, 50, 50, 50), + controller->GetContainerWindow()->bounds()); + + MockEnableIMEInDifferentExtension("chrome-extension://domain-1", test_bounds); + keyboard_bounds = controller->GetContainerWindow()->bounds(); + EXPECT_EQ(kKeyboardHeightForTest, keyboard_bounds.height()); + EXPECT_EQ(screen_bounds.height(), + keyboard_bounds.height() + keyboard_bounds.y()); +} diff --git a/ui/keyboard/keyboard_controller_proxy.cc b/ui/keyboard/keyboard_controller_proxy.cc index 9982138..6b6483c 100644 --- a/ui/keyboard/keyboard_controller_proxy.cc +++ b/ui/keyboard/keyboard_controller_proxy.cc @@ -18,6 +18,7 @@ #include "ui/base/ime/input_method.h" #include "ui/base/ime/text_input_client.h" #include "ui/keyboard/keyboard_constants.h" +#include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_switches.h" #include "ui/keyboard/keyboard_util.h" #include "ui/wm/core/shadow.h" @@ -101,7 +102,9 @@ namespace keyboard { KeyboardControllerProxy::KeyboardControllerProxy( content::BrowserContext* context) - : browser_context_(context), default_url_(kKeyboardURL) { + : browser_context_(context), + default_url_(kKeyboardURL), + keyboard_controller_(nullptr) { } KeyboardControllerProxy::~KeyboardControllerProxy() { @@ -187,17 +190,22 @@ void KeyboardControllerProxy::ReloadKeyboardIfNeeded() { if (keyboard_contents_->GetURL() != GetVirtualKeyboardUrl()) { if (keyboard_contents_->GetURL().GetOrigin() != GetVirtualKeyboardUrl().GetOrigin()) { - // Sets keyboard window height to 0 before navigate to a keyboard in a - // different extension. This keeps the UX the same as Android. - gfx::Rect bounds = GetKeyboardWindow()->bounds(); - bounds.set_y(bounds.y() + bounds.height()); - bounds.set_height(0); - GetKeyboardWindow()->SetBounds(bounds); + // Sets keyboard window rectangle to 0 and close current page before + // navigate to a keyboard in a different extension. This keeps the UX the + // same as Android. Note we need to explicitly close current page as it + // might try to resize keyboard window in javascript on a resize event. + GetKeyboardWindow()->SetBounds(gfx::Rect()); + keyboard_contents_->ClosePage(); + keyboard_controller()->SetKeyboardMode(FULL_WIDTH); } LoadContents(GetVirtualKeyboardUrl()); } } +void KeyboardControllerProxy::SetController(KeyboardController* controller) { + keyboard_controller_ = controller; +} + void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { } diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h index f927849..98051fa 100644 --- a/ui/keyboard/keyboard_controller_proxy.h +++ b/ui/keyboard/keyboard_controller_proxy.h @@ -106,7 +106,7 @@ class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { // KeyboardController owns KeyboardControllerProxy so KeyboardControllerProxy // or its subclasses should not take ownership of the |controller|. // |controller| can be null when KeyboardController is destroying. - virtual void SetController(KeyboardController* controller) {} + virtual void SetController(KeyboardController* controller); protected: // The implementation can choose to setup the WebContents before the virtual @@ -122,6 +122,7 @@ class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { void OnWindowDestroyed(aura::Window* window) override; content::BrowserContext* browser_context() { return browser_context_; } + KeyboardController* keyboard_controller() { return keyboard_controller_; } private: friend class TestApi; @@ -137,6 +138,7 @@ class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { content::BrowserContext* browser_context_; const GURL default_url_; + keyboard::KeyboardController* keyboard_controller_; scoped_ptr<content::WebContents> keyboard_contents_; scoped_ptr<wm::Shadow> shadow_; |