summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorazurewei <azurewei@chromium.org>2016-03-23 21:28:36 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 04:30:38 +0000
commit09c089d0d14e2c0cf1675ab353d676498b0495e4 (patch)
treeb52eabc18c3c2ecd8e0813c6165255b1f19435e5
parentcdc755c0552ebca53e2a86d678a3dd7f7f5dbcf6 (diff)
downloadchromium_src-09c089d0d14e2c0cf1675ab353d676498b0495e4.zip
chromium_src-09c089d0d14e2c0cf1675ab353d676498b0495e4.tar.gz
chromium_src-09c089d0d14e2c0cf1675ab353d676498b0495e4.tar.bz2
Add inputMethodPrivate.showInputView API.
A new private API is needed to let the IME menu show the virtual emoji\handwriting\voice keyboard directly. This is easy when the '--enable-virtual-keyboard' flag is turned on, or the 'On-screen keyboard' is enabled. Just calling keyboard_controller::ShowKeyboard() could finish the work. While, when neither of these two keyboards is enabled, the API should create the instance of the input view window and make sure it will only be shown once. When the virtual keyboard is enabled, the input view window could be popped up automatically by system when the cursor is focused into a input filed. But if the virtual keyboard is brought up by inputMethodPrivate.showInputView API with the '--enable-virtual-keyboard' flag off, the input view window should never be automatically shown after it's hidden. BUG=570761 TEST=None Review URL: https://codereview.chromium.org/1796063002 Cr-Commit-Position: refs/heads/master@{#383030}
-rw-r--r--chrome/browser/chromeos/extensions/input_method_api.cc34
-rw-r--r--chrome/browser/chromeos/extensions/input_method_api.h17
-rw-r--r--chrome/common/extensions/api/input_method_private.json13
-rw-r--r--extensions/browser/extension_function_histogram_value.h1
-rw-r--r--tools/metrics/histograms/histograms.xml1
-rw-r--r--ui/keyboard/keyboard_controller.cc3
-rw-r--r--ui/keyboard/keyboard_controller_unittest.cc12
7 files changed, 80 insertions, 1 deletions
diff --git a/chrome/browser/chromeos/extensions/input_method_api.cc b/chrome/browser/chromeos/extensions/input_method_api.cc
index debfdf6..fa69f45 100644
--- a/chrome/browser/chromeos/extensions/input_method_api.cc
+++ b/chrome/browser/chromeos/extensions/input_method_api.cc
@@ -9,6 +9,7 @@
#include <string>
#include <utility>
+#include "ash/shell.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/values.h"
@@ -34,6 +35,7 @@
#include "ui/base/ime/chromeos/ime_keyboard.h"
#include "ui/base/ime/chromeos/input_method_descriptor.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
+#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
namespace AddWordToDictionary =
@@ -57,6 +59,8 @@ namespace {
// Prefix, which is used by XKB.
const char kXkbPrefix[] = "xkb:";
+const char kErrorFailToShowInputView[] =
+ "Unable to show the input view window.";
} // namespace
@@ -228,6 +232,36 @@ InputMethodPrivateSetXkbLayoutFunction::Run() {
#endif
}
+ExtensionFunction::ResponseAction
+InputMethodPrivateShowInputViewFunction::Run() {
+#if !defined(OS_CHROMEOS)
+ EXTENSION_FUNCTION_VALIDATE(false);
+#else
+ keyboard::KeyboardController* keyboard_controller =
+ keyboard::KeyboardController::GetInstance();
+ if (keyboard_controller) {
+ keyboard_controller->ShowKeyboard(false);
+ return RespondNow(NoArguments());
+ }
+
+ if (keyboard::IsKeyboardEnabled())
+ return RespondNow(Error(kErrorFailToShowInputView));
+
+ // Forcibly enables the a11y onscreen keyboard if there is on keyboard enabled
+ // for now. And re-disables it after showing once.
+ keyboard::SetAccessibilityKeyboardEnabled(true);
+ ash::Shell::GetInstance()->CreateKeyboard();
+ keyboard_controller = keyboard::KeyboardController::GetInstance();
+ if (!keyboard_controller) {
+ keyboard::SetAccessibilityKeyboardEnabled(false);
+ return RespondNow(Error(kErrorFailToShowInputView));
+ }
+ keyboard_controller->ShowKeyboard(false);
+ keyboard::SetAccessibilityKeyboardEnabled(false);
+ return RespondNow(NoArguments());
+#endif
+}
+
InputMethodAPI::InputMethodAPI(content::BrowserContext* context)
: context_(context) {
EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName);
diff --git a/chrome/browser/chromeos/extensions/input_method_api.h b/chrome/browser/chromeos/extensions/input_method_api.h
index d2adfdc..ad3b9f1 100644
--- a/chrome/browser/chromeos/extensions/input_method_api.h
+++ b/chrome/browser/chromeos/extensions/input_method_api.h
@@ -157,6 +157,23 @@ class InputMethodPrivateSetXkbLayoutFunction
DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateSetXkbLayoutFunction);
};
+// Implements the inputMethodPrivate.showInputView method.
+class InputMethodPrivateShowInputViewFunction
+ : public UIThreadExtensionFunction {
+ public:
+ InputMethodPrivateShowInputViewFunction() {}
+
+ protected:
+ ~InputMethodPrivateShowInputViewFunction() override {}
+
+ ResponseAction Run() override;
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("inputMethodPrivate.showInputView",
+ INPUTMETHODPRIVATE_SHOWINPUTVIEW)
+ DISALLOW_COPY_AND_ASSIGN(InputMethodPrivateShowInputViewFunction);
+};
+
class InputMethodAPI : public BrowserContextKeyedAPI,
public extensions::EventRouter::Observer {
public:
diff --git a/chrome/common/extensions/api/input_method_private.json b/chrome/common/extensions/api/input_method_private.json
index f88212c..69d1862 100644
--- a/chrome/common/extensions/api/input_method_private.json
+++ b/chrome/common/extensions/api/input_method_private.json
@@ -218,6 +218,19 @@
"description": "Name of the MenuItem which was activated"
}
]
+ }, {
+ "name": "showInputView",
+ "type": "function",
+ "description": "Shows the input view window. If the input view window is already shown, this function will do nothing.",
+ "parameters": [
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "description": "Called when the operation completes.",
+ "parameters": []
+ }
+ ]
}
],
"events": [
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index 6eb5fad..4bfb028 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -1171,6 +1171,7 @@ enum HistogramValue {
INPUTMETHODPRIVATE_NOTIFYIMEMENUITEMACTIVATED,
INPUT_IME_SHOWWINDOW,
INPUT_IME_HIDEWINDOW,
+ INPUTMETHODPRIVATE_SHOWINPUTVIEW,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 40ee1f2..20ee338 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -66959,6 +66959,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1110" label="INPUTMETHODPRIVATE_NOTIFYIMEMENUITEMACTIVATED"/>
<int value="1111" label="INPUT_IME_SHOWWINDOW"/>
<int value="1112" label="INPUT_IME_HIDEWINDOW"/>
+ <int value="1113" label="INPUTMETHODPRIVATE_SHOWINPUTVIEW"/>
</enum>
<enum name="ExtensionInstallCause" type="int">
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index 9eeb347..ad1e640 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -388,7 +388,8 @@ void KeyboardController::OnInputMethodDestroyed(
}
void KeyboardController::OnShowImeIfNeeded() {
- ShowKeyboardInternal();
+ if (IsKeyboardEnabled())
+ ShowKeyboardInternal();
}
void KeyboardController::ShowKeyboardInternal() {
diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc
index 4e048a9..63bbeac 100644
--- a/ui/keyboard/keyboard_controller_unittest.cc
+++ b/ui/keyboard/keyboard_controller_unittest.cc
@@ -316,6 +316,7 @@ TEST_F(KeyboardControllerTest, FloatingKeyboardSize) {
// Tests that tapping/clicking inside the keyboard does not give it focus.
TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
+ keyboard::SetAccessibilityKeyboardEnabled(true);
const gfx::Rect& root_bounds = root_window()->bounds();
aura::test::EventCountDelegate delegate;
scoped_ptr<aura::Window> window(new aura::Window(&delegate));
@@ -356,9 +357,11 @@ TEST_F(KeyboardControllerTest, ClickDoesNotFocusKeyboard) {
generator.ClickLeftButton();
EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset());
keyboard_container->RemovePreTargetHandler(&observer);
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
+ keyboard::SetAccessibilityKeyboardEnabled(true);
ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_2(ui::TEXT_INPUT_TYPE_TEXT);
@@ -394,6 +397,7 @@ TEST_F(KeyboardControllerTest, VisibilityChangeWithTextInputTypeChange) {
EXPECT_FALSE(WillHideKeyboard());
EXPECT_TRUE(keyboard_container->IsVisible());
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
// Test to prevent spurious overscroll boxes when changing tabs during keyboard
@@ -423,6 +427,7 @@ TEST_F(KeyboardControllerTest, CheckOverscrollInsetDuringVisibilityChange) {
// Verify switch to FLOATING mode will reset the overscroll or resize and when
// in FLOATING mode, overscroll or resize wont be triggered.
TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) {
+ keyboard::SetAccessibilityKeyboardEnabled(true);
ui::DummyTextInputClient input_client(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client(ui::TEXT_INPUT_TYPE_NONE);
@@ -453,6 +458,7 @@ TEST_F(KeyboardControllerTest, FloatingKeyboardDontOverscrollOrResize) {
// In FLOATING mode, no overscroll or resize should be triggered.
EXPECT_EQ(3, number_of_calls());
EXPECT_EQ(gfx::Rect(), controller()->current_keyboard_bounds());
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
// Verify switch to FULL_WIDTH mode will move virtual keyboard to the right
@@ -479,6 +485,7 @@ TEST_F(KeyboardControllerTest, SwitchToFullWidthVirtualKeyboard) {
}
TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
+ keyboard::SetAccessibilityKeyboardEnabled(true);
ui::DummyTextInputClient input_client_0(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient input_client_1(ui::TEXT_INPUT_TYPE_TEXT);
ui::DummyTextInputClient no_input_client_0(ui::TEXT_INPUT_TYPE_NONE);
@@ -514,6 +521,7 @@ TEST_F(KeyboardControllerTest, AlwaysVisibleWhenLocked) {
// Wait for hide keyboard to finish.
base::MessageLoop::current()->Run();
EXPECT_FALSE(keyboard_container->IsVisible());
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
class KeyboardControllerAnimationTest : public KeyboardControllerTest {
@@ -553,6 +561,7 @@ class KeyboardControllerAnimationTest : public KeyboardControllerTest {
// Tests virtual keyboard has correct show and hide animation.
TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
ui::Layer* layer = keyboard_container()->layer();
+ keyboard::SetAccessibilityKeyboardEnabled(true);
ShowKeyboard();
// Keyboard container and window should immediately become visible before
@@ -593,12 +602,14 @@ TEST_F(KeyboardControllerAnimationTest, ContainerAnimation) {
EXPECT_GT(hide_start_opacity, hide_end_opacity);
EXPECT_EQ(transform, layer->transform());
EXPECT_EQ(gfx::Rect(), notified_bounds());
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
// Show keyboard during keyboard hide animation should abort the hide animation
// and the keyboard should animate in.
// Test for crbug.com/333284.
TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) {
+ keyboard::SetAccessibilityKeyboardEnabled(true);
ui::Layer* layer = keyboard_container()->layer();
ShowKeyboard();
RunAnimationForLayer(layer);
@@ -611,6 +622,7 @@ TEST_F(KeyboardControllerAnimationTest, ContainerShowWhileHide) {
EXPECT_TRUE(keyboard_window()->IsVisible());
EXPECT_EQ(1.0, layer->opacity());
EXPECT_EQ(gfx::Transform(), layer->transform());
+ keyboard::SetAccessibilityKeyboardEnabled(false);
}
// Test for crbug.com/568274.