Commit 5b113d2d authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

arc: ime: Support auto capitalization.

This CL maps Android's EditorInfo.TYPE_TEXT_FLAG_CAP_* to Chrome's
ui::TextInputFlags::TEXT_INPUT_FLAG_AUTOCAPITALIZE_*.

Based on the value, when user types on Android apps with Chrome IME,
the first letter of each sentence / each word, or all letters will be
capitalized by the IME.

ARC++ side change: ag/5477541 (WIP)

TEST=manual
BUG=b/111818971

Change-Id: I26f5f2b03297ec811160132a917057a4fb212815
Reviewed-on: https://chromium-review.googlesource.com/c/1328636Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609572}
parent e237c084
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Next MinVersion: 11
// Next MinVersion: 12
module arc.mojom;
......@@ -24,6 +24,15 @@ enum TextInputType {
DATETIME,
};
// Maps to ui::TextInputFlags in ui/base/ime/text_input_flags.h.
// Some flags are still missing here because they're not yet supported in ARC++
// IME.
const int32 TEXT_INPUT_FLAG_NONE = 0;
const int32 TEXT_INPUT_FLAG_AUTOCAPITALIZE_NONE = 64; // 1 << 6
const int32 TEXT_INPUT_FLAG_AUTOCAPITALIZE_CHARACTERS = 128; // 1 << 7
const int32 TEXT_INPUT_FLAG_AUTOCAPITALIZE_WORDS = 256; // 1 << 8
const int32 TEXT_INPUT_FLAG_AUTOCAPITALIZE_SENTENCES = 512; // 1 << 9
// Represents a single segment of text currently composed by IME.
struct CompositionSegment {
// Start offset of the segment in UTF-16 index.
......@@ -37,9 +46,11 @@ struct CompositionSegment {
// Next method ID: 6
interface ImeHost {
// Notifies Chrome that the text input focus is changed.
// Each bit of the bitmask |flags| corresponds to TEXT_INPUT_FLAG_*.
OnTextInputTypeChanged@0(
TextInputType type,
[MinVersion=10] bool is_personalized_learning_allowed);
[MinVersion=10] bool is_personalized_learning_allowed,
[MinVersion=11] int32 flags);
// Notifies Chrome that the cursor poisition has changed.
//
......
......@@ -29,9 +29,9 @@ class ArcImeBridge {
// Received IPCs are deserialized and passed to this delegate.
class Delegate {
public:
virtual void OnTextInputTypeChanged(
ui::TextInputType type,
bool is_personalized_learning_allowed) = 0;
virtual void OnTextInputTypeChanged(ui::TextInputType type,
bool is_personalized_learning_allowed,
int flags) = 0;
virtual void OnCursorRectChanged(const gfx::Rect& rect,
bool is_screen_cooridnates) = 0;
virtual void OnCancelComposition() = 0;
......
......@@ -13,6 +13,7 @@
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"
......@@ -35,6 +36,17 @@ std::vector<mojom::CompositionSegmentPtr> ConvertSegments(
return segments;
}
// Converts mojom::TEXT_INPUT_FLAG_* to ui::TextInputFlags.
int ConvertTextInputFlags(int32_t flags) {
if (flags & mojom::TEXT_INPUT_FLAG_AUTOCAPITALIZE_NONE)
return ui::TextInputFlags::TEXT_INPUT_FLAG_AUTOCAPITALIZE_NONE;
if (flags & mojom::TEXT_INPUT_FLAG_AUTOCAPITALIZE_CHARACTERS)
return ui::TextInputFlags::TEXT_INPUT_FLAG_AUTOCAPITALIZE_CHARACTERS;
if (flags & mojom::TEXT_INPUT_FLAG_AUTOCAPITALIZE_WORDS)
return ui::TextInputFlags::TEXT_INPUT_FLAG_AUTOCAPITALIZE_WORDS;
return ui::TextInputFlags::TEXT_INPUT_FLAG_NONE;
}
} // namespace
ArcImeBridgeImpl::ArcImeBridgeImpl(Delegate* delegate,
......@@ -99,8 +111,10 @@ void ArcImeBridgeImpl::SendOnKeyboardAppearanceChanging(
void ArcImeBridgeImpl::OnTextInputTypeChanged(
ui::TextInputType type,
bool is_personalized_learning_allowed) {
delegate_->OnTextInputTypeChanged(type, is_personalized_learning_allowed);
bool is_personalized_learning_allowed,
int32_t flags) {
delegate_->OnTextInputTypeChanged(type, is_personalized_learning_allowed,
ConvertTextInputFlags(flags));
}
void ArcImeBridgeImpl::OnCursorRectChanged(const gfx::Rect& rect,
......
......@@ -39,7 +39,8 @@ class ArcImeBridgeImpl : public ArcImeBridge, public mojom::ImeHost {
// mojom::ImeHost overrides:
void OnTextInputTypeChanged(ui::TextInputType type,
bool is_personalized_learning_allowed) override;
bool is_personalized_learning_allowed,
int32_t flags) override;
void OnCursorRectChanged(const gfx::Rect& rect,
bool screen_coordinates) override;
void OnCancelComposition() override;
......
......@@ -19,6 +19,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
......@@ -140,6 +141,7 @@ ArcImeService::ArcImeService(content::BrowserContext* context,
: ime_bridge_(new ArcImeBridgeImpl(this, bridge_service)),
arc_window_delegate_(new ArcWindowDelegateImpl(this)),
ime_type_(ui::TEXT_INPUT_TYPE_NONE),
ime_flags_(ui::TEXT_INPUT_FLAG_NONE),
is_personalized_learning_allowed_(false),
has_composition_text_(false) {
if (aura::Env::HasInstance())
......@@ -260,13 +262,16 @@ void ArcImeService::OnWindowFocused(aura::Window* gained_focus,
void ArcImeService::OnTextInputTypeChanged(
ui::TextInputType type,
bool is_personalized_learning_allowed) {
bool is_personalized_learning_allowed,
int flags) {
if (ime_type_ == type &&
is_personalized_learning_allowed_ == is_personalized_learning_allowed) {
is_personalized_learning_allowed_ == is_personalized_learning_allowed &&
ime_flags_ == flags) {
return;
}
ime_type_ = type;
is_personalized_learning_allowed_ = is_personalized_learning_allowed;
ime_flags_ = flags;
ui::InputMethod* const input_method = GetInputMethod();
if (input_method)
......@@ -471,7 +476,7 @@ void ArcImeService::ExtendSelectionAndDelete(size_t before, size_t after) {
}
int ArcImeService::GetTextInputFlags() const {
return ui::TEXT_INPUT_FLAG_NONE;
return ime_flags_;
}
bool ArcImeService::CanComposeInline() const {
......
......@@ -14,7 +14,6 @@
#include "ui/aura/env_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/keyboard/keyboard_controller_observer.h"
......@@ -87,7 +86,8 @@ class ArcImeService : public KeyedService,
// Overridden from ArcImeBridge::Delegate:
void OnTextInputTypeChanged(ui::TextInputType type,
bool is_personalized_learning_allowed) override;
bool is_personalized_learning_allowed,
int flags) override;
void OnCursorRectChanged(const gfx::Rect& rect,
bool is_screen_coordinates) override;
void OnCancelComposition() override;
......@@ -165,6 +165,8 @@ class ArcImeService : public KeyedService,
std::unique_ptr<ArcImeBridge> ime_bridge_;
std::unique_ptr<ArcWindowDelegate> arc_window_delegate_;
ui::TextInputType ime_type_;
// The flag is the bit map of ui::TextInputFlags.
int ime_flags_;
bool is_personalized_learning_allowed_;
gfx::Rect cursor_rect_;
bool has_composition_text_;
......
......@@ -11,12 +11,14 @@
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/common/ime.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/base/ime/composition_text.h"
#include "ui/base/ime/dummy_input_method.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/keyboard_codes.h"
......@@ -235,11 +237,13 @@ TEST_F(ArcImeServiceTest, HasCompositionText) {
TEST_F(ArcImeServiceTest, ShowVirtualKeyboardIfEnabled) {
instance_->OnWindowFocused(arc_win_.get(), nullptr);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE, false);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE, false,
mojom::TEXT_INPUT_FLAG_NONE);
ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed());
// Text input type change does not imply the show ime request.
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true,
mojom::TEXT_INPUT_FLAG_NONE);
EXPECT_EQ(0, fake_input_method_->count_show_ime_if_needed());
instance_->ShowVirtualKeyboardIfEnabled();
......@@ -258,12 +262,14 @@ TEST_F(ArcImeServiceTest, InsertChar) {
instance_->OnWindowFocused(arc_win_.get(), nullptr);
// When text input type is NONE, the event is not forwarded.
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE, false);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE, false,
mojom::TEXT_INPUT_FLAG_NONE);
instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, ui::DomCode::NONE, 0));
EXPECT_EQ(0, fake_arc_ime_bridge_->count_send_insert_text());
// When the bridge is accepting text inputs, forward the event.
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true,
mojom::TEXT_INPUT_FLAG_NONE);
instance_->InsertChar(ui::KeyEvent('a', ui::VKEY_A, ui::DomCode::NONE, 0));
EXPECT_EQ(1, fake_arc_ime_bridge_->count_send_insert_text());
}
......@@ -402,15 +408,18 @@ TEST_F(ArcImeServiceTest, ShouldDoLearning) {
instance_->OnWindowFocused(arc_win_.get(), nullptr);
ASSERT_NE(ui::TEXT_INPUT_TYPE_TEXT, instance_->GetTextInputType());
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, true,
mojom::TEXT_INPUT_FLAG_NONE);
EXPECT_TRUE(instance_->ShouldDoLearning());
EXPECT_EQ(1, fake_input_method_->count_on_text_input_type_changed());
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, false);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT, false,
mojom::TEXT_INPUT_FLAG_NONE);
EXPECT_FALSE(instance_->ShouldDoLearning());
EXPECT_EQ(2, fake_input_method_->count_on_text_input_type_changed());
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_URL, false);
instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_URL, false,
mojom::TEXT_INPUT_FLAG_NONE);
EXPECT_FALSE(instance_->ShouldDoLearning());
EXPECT_EQ(3, fake_input_method_->count_on_text_input_type_changed());
}
......
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