Commit 48d76d3d authored by Leo Zhang's avatar Leo Zhang Committed by Commit Bot

Detect the text input host for better input experience.

Provide some basic info of the host of the focused text field to system
IME via private extension API. With these information, IME will identify
some known faulty clients then demote its input.ime APIs (even disable
advanced features) to make the typing on these client works basically.

Context for the CL:
Due to some faulty implementation of their text operations in some
clients' text field (e.g. Terminal for Linux, Text app, Android app...)
in ChromeOS, they don't work not properly with predefined ChromeOS IME
APIs (e.g. chrome.input.ime.deleteSurroundingText, setComposingRange...).

Therefore, typing on these client are always difficult with unexpected
results. Detailed example can be found in the bugs attached.

Tested=Some popular cases in local VM and Kevin device in skylib.

Bug: b/162183648,b/163645900
Change-Id: Ib43e9ccba7e9620b7189153d956ef685f80fb29d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405046
Commit-Queue: Leo Zhang <googleo@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807764}
parent f42d0095
......@@ -1371,6 +1371,8 @@ source_set("chromeos") {
"input_method/emoji_suggester.h",
"input_method/ime_service_connector.cc",
"input_method/ime_service_connector.h",
"input_method/input_host_helper.cc",
"input_method/input_host_helper.h",
"input_method/input_method_configuration.cc",
"input_method/input_method_configuration.h",
"input_method/input_method_delegate_impl.cc",
......
......@@ -23,6 +23,11 @@ specific_include_rules = {
"+ash/wm/window_util.h",
],
# Detect text input client host.
"input_host_helper\.cc": [
"+ash/wm/window_util.h",
],
# TODO(erikwright): Bring this list to zero.
# Do not add to the list of temporarily-allowed dependencies below,
# and please do not introduce more #includes of these files.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/input_method/input_host_helper.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
namespace chromeos {
namespace input_host_helper {
void PopulateInputHost(InputAssociatedHost* host) {
aura::Window* window = ash::window_util::GetActiveWindow();
if (window) {
// TODO(crbug/163645900): Get app_type via aura::client::kAppType.
const std::string* key = window->GetProperty(ash::kAppIDKey);
if (key) {
host->app_key = *key;
}
}
}
} // namespace input_host_helper
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_HOST_HELPER_H_
#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_HOST_HELPER_H_
#include <string>
#include "ash/public/cpp/app_types.h"
namespace chromeos {
namespace input_host_helper {
struct InputAssociatedHost {
// Type of app associated with this text field.
ash::AppType app_type;
// Key of app associated with this text field.
std::string app_key;
};
void PopulateInputHost(InputAssociatedHost* host);
} // namespace input_host_helper
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_HOST_HELPER_H_
......@@ -14,6 +14,7 @@
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/chromeos/input_method/assistive_window_properties.h"
#include "chrome/browser/chromeos/input_method/input_host_helper.h"
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
#include "chrome/browser/chromeos/input_method/native_input_method_engine.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h"
......@@ -299,6 +300,12 @@ class ImeObserverChromeOS : public ui::ImeObserver {
input_context.focus_reason = input_method_private::ParseFocusReason(
ConvertInputContextFocusReason(context));
// Populate app key for private OnFocus.
// TODO(b/163645900): Add app type later.
chromeos::input_host_helper::InputAssociatedHost host;
chromeos::input_host_helper::PopulateInputHost(&host);
input_context.app_key = std::make_unique<std::string>(host.app_key);
std::unique_ptr<base::ListValue> args(
input_method_private::OnFocus::Create(input_context));
......
......@@ -77,7 +77,8 @@
"spellCheck": {"type": "boolean", "description": "Whether the text field wants spell-check."},
"shouldDoLearning": {"type": "boolean", "description": "Whether text entered into the text field should be used to improve typing suggestions for the user."},
"focusReason": {"$ref": "FocusReason", "description": "How the text field was focused"},
"hasBeenPassword": {"type": "boolean", "description": "Whether the text field has ever been a password field."}
"hasBeenPassword": {"type": "boolean", "description": "Whether the text field has ever been a password field."},
"appKey": {"type": "string", "optional": true, "description": "Key of the app associated with this text field if any."}
}
},
{
......
......@@ -105,7 +105,8 @@ chrome.inputMethodPrivate.AutoCapitalizeType = {
* spellCheck: boolean,
* shouldDoLearning: boolean,
* focusReason: !chrome.inputMethodPrivate.FocusReason,
* hasBeenPassword: boolean
* hasBeenPassword: boolean,
* appKey: (string|undefined)
* }}
*/
chrome.inputMethodPrivate.InputContext;
......
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