Commit 582fd8ff authored by bshe's avatar bshe Committed by Commit bot

Add chrome.virtualKeyboardPrivate.setHotrodKeyboard api

BUG=524291

Review URL: https://codereview.chromium.org/1315233006

Cr-Commit-Position: refs/heads/master@{#347873}
parent ac5372f9
......@@ -72,7 +72,10 @@ bool ChromeVirtualKeyboardDelegate::GetKeyboardConfig(
base::DictionaryValue* results) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
results->SetString("layout", keyboard::GetKeyboardLayout());
// TODO(bshe): Consolidate a11y, hotrod and normal mode into a mode enum. See
// crbug.com/529474.
results->SetBoolean("a11ymode", keyboard::GetAccessibilityKeyboardEnabled());
results->SetBoolean("hotrodmode", keyboard::GetHotrodKeyboardEnabled());
scoped_ptr<base::ListValue> features(new base::ListValue());
features->AppendString(GenerateFeatureFlag(
"floatingvirtualkeyboard", keyboard::IsFloatingVirtualKeyboardEnabled()));
......@@ -117,6 +120,18 @@ bool ChromeVirtualKeyboardDelegate::OnKeyboardLoaded() {
return true;
}
void ChromeVirtualKeyboardDelegate::SetHotrodKeyboard(bool enable) {
if (keyboard::GetHotrodKeyboardEnabled() == enable)
return;
keyboard::SetHotrodKeyboardEnabled(enable);
// This reloads virtual keyboard even if it exists. This ensures virtual
// keyboard gets the correct state of the hotrod keyboard through
// chrome.virtualKeyboardPrivate.getKeyboardConfig.
if (enable && keyboard::IsKeyboardEnabled())
ash::Shell::GetInstance()->CreateKeyboard();
}
bool ChromeVirtualKeyboardDelegate::LockKeyboard(bool state) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
keyboard::KeyboardController* controller =
......
......@@ -18,6 +18,7 @@ class ChromeVirtualKeyboardDelegate : public VirtualKeyboardDelegate {
bool HideKeyboard() override;
bool InsertText(const base::string16& text) override;
bool OnKeyboardLoaded() override;
void SetHotrodKeyboard(bool enable) override;
bool LockKeyboard(bool state) override;
bool SendKeyEvent(const std::string& type,
int char_value,
......
......@@ -87,6 +87,7 @@ function mockExtensionApis(mockController) {
'sendKeyEvent',
'setMode',
'setKeyboardState',
'setHotrodKeyboard'
];
var inputMethodPrivateMethods = [
......
......@@ -36,6 +36,9 @@ class VirtualKeyboardDelegate {
// For example, settings should be blocked when the session is locked.
virtual bool IsLanguageSettingsEnabled() = 0;
// Sets the state of the hotrod virtual keyboad.
virtual void SetHotrodKeyboard(bool enable) = 0;
// Activate and lock the virtual keyboad on screen or dismiss the keyboard
// regardless of the state of text focus. Used in a11y mode to allow typing
// hotkeys without the need for text focus. Returns true if successful.
......
......@@ -79,6 +79,18 @@ bool VirtualKeyboardPrivateHideKeyboardFunction::RunSync() {
return false;
}
bool VirtualKeyboardPrivateSetHotrodKeyboardFunction::RunSync() {
VirtualKeyboardDelegate* delegate = GetDelegate(this);
if (delegate) {
bool enable;
EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enable));
delegate->SetHotrodKeyboard(enable);
return true;
}
error_ = kNotYetImplementedError;
return false;
}
bool VirtualKeyboardPrivateLockKeyboardFunction::RunSync() {
VirtualKeyboardDelegate* delegate = GetDelegate(this);
if (delegate) {
......
......@@ -53,6 +53,19 @@ class VirtualKeyboardPrivateHideKeyboardFunction
bool RunSync() override;
};
class VirtualKeyboardPrivateSetHotrodKeyboardFunction
: public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("virtualKeyboardPrivate.setHotrodKeyboard",
VIRTUALKEYBOARDPRIVATE_SETHOTRODKEYBOARD);
protected:
~VirtualKeyboardPrivateSetHotrodKeyboardFunction() override {}
// ExtensionFunction:
bool RunSync() override;
};
class VirtualKeyboardPrivateLockKeyboardFunction
: public SyncExtensionFunction {
public:
......
......@@ -1137,6 +1137,7 @@ enum HistogramValue {
SYSTEM_DISPLAY_ENABLEUNIFIEDDESKTOP,
BROWSINGDATA_REMOVECACHESTORAGE,
VIRTUALKEYBOARDPRIVATE_SETKEYBOARDSTATE,
VIRTUALKEYBOARDPRIVATE_SETHOTRODKEYBOARD,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -105,6 +105,17 @@
}
]
},
{
"name": "setHotrodKeyboard",
"type": "function",
"description": "Sets the state of the hotrod virtual keyboard. This API should only be used by hotrod.",
"parameters": [
{
"type": "boolean",
"name": "enable"
}
]
},
{
"name": "lockKeyboard",
"type": "function",
......
......@@ -58974,6 +58974,7 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1076" label="SYSTEM_DISPLAY_ENABLEUNIFIEDDESKTOP"/>
<int value="1077" label="BROWSINGDATA_REMOVECACHESTORAGE"/>
<int value="1078" label="VIRTUALKEYBOARDPRIVATE_SETKEYBOARDSTATE"/>
<int value="1079" label="VIRTUALKEYBOARDPRIVATE_SETHOTRODKEYBOARD"/>
</enum>
<enum name="ExtensionInstallCause" type="int">
......@@ -50,6 +50,8 @@ base::LazyInstance<base::Time> g_keyboard_load_time_start =
bool g_accessibility_keyboard_enabled = false;
bool g_hotrod_keyboard_enabled = false;
base::LazyInstance<GURL> g_override_content_url = LAZY_INSTANCE_INITIALIZER;
bool g_touch_keyboard_enabled = false;
......@@ -84,6 +86,14 @@ bool GetAccessibilityKeyboardEnabled() {
return g_accessibility_keyboard_enabled;
}
void SetHotrodKeyboardEnabled(bool enabled) {
g_hotrod_keyboard_enabled = enabled;
}
bool GetHotrodKeyboardEnabled() {
return g_hotrod_keyboard_enabled;
}
void SetTouchKeyboardEnabled(bool enabled) {
g_touch_keyboard_enabled = enabled;
}
......
......@@ -74,6 +74,12 @@ KEYBOARD_EXPORT void SetAccessibilityKeyboardEnabled(bool enabled);
// Gets the state of the a11y onscreen keyboard.
KEYBOARD_EXPORT bool GetAccessibilityKeyboardEnabled();
// Sets the state of the hotrod onscreen keyboard.
KEYBOARD_EXPORT void SetHotrodKeyboardEnabled(bool enabled);
// Gets the state of the hotrod onscreen keyboard.
KEYBOARD_EXPORT bool GetHotrodKeyboardEnabled();
// Sets the state of the touch onscreen keyboard.
KEYBOARD_EXPORT void SetTouchKeyboardEnabled(bool enabled);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment