Commit f134fb09 authored by Shu Chen's avatar Shu Chen Committed by Commit Bot

Expose the "autocapitalize" attribute of the text input field to the IME extension.

Bug: 786434
Change-Id: I7f18cf55c99c61ad398015430818626aedd4da1e
Reviewed-on: https://chromium-review.googlesource.com/1098739Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Shu Chen <shuchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567531}
parent 37dc659c
......@@ -9,7 +9,6 @@
#include "base/lazy_instance.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/common/extensions/api/input_ime.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/extension_registry.h"
......@@ -57,6 +56,7 @@ void ImeObserver::OnFocus(
input_ime::ParseInputContextType(ConvertInputContextType(context));
context_value.auto_correct = ConvertInputContextAutoCorrect(context);
context_value.auto_complete = ConvertInputContextAutoComplete(context);
context_value.auto_capitalize = ConvertInputContextAutoCapitalize(context);
context_value.spell_check = ConvertInputContextSpellCheck(context);
context_value.should_do_learning = context.should_do_learning;
......@@ -236,6 +236,18 @@ bool ImeObserver::ConvertInputContextAutoComplete(
return !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCOMPLETE_OFF);
}
input_ime::AutoCapitalizeType ImeObserver::ConvertInputContextAutoCapitalize(
ui::IMEEngineHandlerInterface::InputContext input_context) {
if (input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCAPITALIZE_NONE)
return input_ime::AUTO_CAPITALIZE_TYPE_NONE;
if (input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCAPITALIZE_CHARACTERS)
return input_ime::AUTO_CAPITALIZE_TYPE_CHARACTERS;
if (input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCAPITALIZE_WORDS)
return input_ime::AUTO_CAPITALIZE_TYPE_WORDS;
// The default value is "sentences".
return input_ime::AUTO_CAPITALIZE_TYPE_SENTENCES;
}
bool ImeObserver::ConvertInputContextSpellCheck(
ui::IMEEngineHandlerInterface::InputContext input_context) {
return !(input_context.flags & ui::TEXT_INPUT_FLAG_SPELLCHECK_OFF);
......
......@@ -16,6 +16,7 @@
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/input_method/input_method_engine_base.h"
#include "chrome/common/extensions/api/input_ime.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -89,6 +90,9 @@ class ImeObserver : public input_method::InputMethodEngineBase::Observer {
IMEEngineHandlerInterface::InputContext input_context);
virtual bool ConvertInputContextAutoComplete(
IMEEngineHandlerInterface::InputContext input_context);
virtual extensions::api::input_ime::AutoCapitalizeType
ConvertInputContextAutoCapitalize(
IMEEngineHandlerInterface::InputContext input_context);
virtual bool ConvertInputContextSpellCheck(
IMEEngineHandlerInterface::InputContext input_context);
......
......@@ -316,6 +316,13 @@ class ImeObserverChromeOS : public ui::ImeObserver {
return ImeObserver::ConvertInputContextAutoComplete(input_context);
}
input_ime::AutoCapitalizeType ConvertInputContextAutoCapitalize(
ui::IMEEngineHandlerInterface::InputContext input_context) override {
if (!keyboard::GetKeyboardConfig().auto_capitalize)
return input_ime::AUTO_CAPITALIZE_TYPE_NONE;
return ImeObserver::ConvertInputContextAutoCapitalize(input_context);
}
bool ConvertInputContextSpellCheck(
ui::IMEEngineHandlerInterface::InputContext input_context) override {
if (!keyboard::GetKeyboardConfig().spell_check)
......
......@@ -35,6 +35,12 @@
"description": "Type of value this text field edits, (Text, Number, URL, etc)",
"enum": ["text", "search", "tel", "url", "email", "number", "password"]
},
{
"id": "AutoCapitalizeType",
"type": "string",
"description": "The auto-capitalize type of the text field.",
"enum": ["characters", "words", "sentences"]
},
{
"id": "InputContext",
"type": "object",
......@@ -44,6 +50,7 @@
"type": {"$ref": "InputContextType", "description": "Type of value this text field edits, (Text, Number, URL, etc)"},
"autoCorrect": {"type": "boolean", "description": "Whether the text field wants auto-correct."},
"autoComplete": {"type": "boolean", "description": "Whether the text field wants auto-complete."},
"autoCapitalize": {"$ref": "AutoCapitalizeType", "description": "The auto-capitalize type of the text field."},
"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."}
}
......
......@@ -20,6 +20,7 @@ namespace keyboard {
struct KeyboardConfig {
bool auto_complete = true;
bool auto_correct = true;
bool auto_capitalize = true;
bool handwriting = true;
bool spell_check = true;
// It denotes the preferred value, and can be true even if there is no actual
......@@ -28,8 +29,10 @@ struct KeyboardConfig {
bool operator==(const keyboard::KeyboardConfig& rhs) const {
return auto_complete == rhs.auto_complete &&
auto_correct == rhs.auto_correct && handwriting == rhs.handwriting &&
spell_check == rhs.spell_check && voice_input == rhs.voice_input;
auto_correct == rhs.auto_correct &&
auto_capitalize == rhs.auto_capitalize &&
handwriting == rhs.handwriting && spell_check == rhs.spell_check &&
voice_input == rhs.voice_input;
}
};
......
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