summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine.cc100
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine.h19
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc54
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_interface.cc51
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_interface.h262
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_unittest.cc32
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager_impl.cc5
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager_impl.h14
-rw-r--r--chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc1
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_engine.cc30
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_engine.h10
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_manager.cc3
-rw-r--r--chrome/browser/chromeos/input_method/mock_input_method_manager.h7
-rw-r--r--chrome/browser/chromeos/preferences_unittest.cc2
-rw-r--r--chrome/browser/extensions/api/input_ime/input_ime_api.cc179
-rw-r--r--chrome/browser/extensions/api/input_ime/input_ime_api.h33
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
-rw-r--r--ui/base/ime/BUILD.gn2
-rw-r--r--ui/base/ime/chromeos/input_method_manager.h4
-rw-r--r--ui/base/ime/chromeos/mock_ime_engine_handler.cc79
-rw-r--r--ui/base/ime/chromeos/mock_ime_engine_handler.h51
-rw-r--r--ui/base/ime/ime_engine_handler_interface.cc43
-rw-r--r--ui/base/ime/ime_engine_handler_interface.h188
-rw-r--r--ui/base/ime/ime_engine_observer.h78
-rw-r--r--ui/base/ime/input_method_chromeos.cc6
-rw-r--r--ui/base/ime/ui_base_ime.gyp2
26 files changed, 680 insertions, 577 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_engine.cc b/chrome/browser/chromeos/input_method/input_method_engine.cc
index 66b7508..e417e36 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine.cc
@@ -53,8 +53,8 @@ void UpdateComposition(const ui::CompositionText& composition_text,
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (input_context)
- input_context->UpdateCompositionText(
- composition_text, cursor_pos, is_visible);
+ input_context->UpdateCompositionText(composition_text, cursor_pos,
+ is_visible);
}
// Returns the length of characters of a UTF-8 string with unknown string
@@ -82,9 +82,8 @@ std::string GetKeyFromEvent(const ui::KeyEvent& event) {
return code.substr(5);
if (code == "Escape")
return "Esc";
- if (code == "Backspace" || code == "Tab" ||
- code == "Enter" || code == "CapsLock" ||
- code == "Power")
+ if (code == "Backspace" || code == "Tab" || code == "Enter" ||
+ code == "CapsLock" || code == "Power")
return code;
// Cases for media keys.
switch (event.key_code()) {
@@ -124,8 +123,7 @@ std::string GetKeyFromEvent(const ui::KeyEvent& event) {
uint16 ch = 0;
// Ctrl+? cases, gets key value for Ctrl is not down.
if (event.flags() & ui::EF_CONTROL_DOWN) {
- ui::KeyEvent event_no_ctrl(event.type(),
- event.key_code(),
+ ui::KeyEvent event_no_ctrl(event.type(), event.key_code(),
event.flags() ^ ui::EF_CONTROL_DOWN);
ch = event_no_ctrl.GetCharacter();
} else {
@@ -167,13 +165,11 @@ InputMethodEngine::InputMethodEngine()
sent_key_event_(NULL),
profile_(NULL) {}
-InputMethodEngine::~InputMethodEngine() {
-}
+InputMethodEngine::~InputMethodEngine() {}
-void InputMethodEngine::Initialize(
- scoped_ptr<InputMethodEngineInterface::Observer> observer,
- const char* extension_id,
- Profile* profile) {
+void InputMethodEngine::Initialize(scoped_ptr<ui::IMEEngineObserver> observer,
+ const char* extension_id,
+ Profile* profile) {
DCHECK(observer) << "Observer must not be null.";
// TODO(komatsu): It is probably better to set observer out of Initialize.
@@ -240,8 +236,7 @@ bool InputMethodEngine::SetComposition(
return true;
}
-bool InputMethodEngine::ClearComposition(int context_id,
- std::string* error) {
+bool InputMethodEngine::ClearComposition(int context_id, std::string* error) {
if (!IsActive()) {
*error = kErrorNotActive;
return false;
@@ -257,7 +252,8 @@ bool InputMethodEngine::ClearComposition(int context_id,
return true;
}
-bool InputMethodEngine::CommitText(int context_id, const char* text,
+bool InputMethodEngine::CommitText(int context_id,
+ const char* text,
std::string* error) {
if (!IsActive()) {
// TODO: Commit the text anyways.
@@ -305,9 +301,9 @@ bool InputMethodEngine::SendKeyEvents(
key_code = ui::DomKeycodeToKeyboardCode(event.code);
int flags = ui::EF_NONE;
- flags |= event.alt_key ? ui::EF_ALT_DOWN : ui::EF_NONE;
- flags |= event.ctrl_key ? ui::EF_CONTROL_DOWN : ui::EF_NONE;
- flags |= event.shift_key ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
+ flags |= event.alt_key ? ui::EF_ALT_DOWN : ui::EF_NONE;
+ flags |= event.ctrl_key ? ui::EF_CONTROL_DOWN : ui::EF_NONE;
+ flags |= event.shift_key ? ui::EF_SHIFT_DOWN : ui::EF_NONE;
flags |= event.caps_lock ? ui::EF_CAPS_LOCK_DOWN : ui::EF_NONE;
ui::KeyEvent ui_event(
@@ -332,7 +328,7 @@ InputMethodEngine::GetCandidateWindowProperty() const {
void InputMethodEngine::SetCandidateWindowProperty(
const CandidateWindowProperty& property) {
- // Type conversion from InputMethodEngineInterface::CandidateWindowProperty to
+ // Type conversion from IMEEngineHandlerInterface::CandidateWindowProperty to
// CandidateWindow::CandidateWindowProperty defined in chromeos/ime/.
ui::CandidateWindow::CandidateWindowProperty dest_property;
dest_property.page_size = property.page_size;
@@ -412,7 +408,8 @@ bool InputMethodEngine::SetCandidates(
return true;
}
-bool InputMethodEngine::SetCursorPosition(int context_id, int candidate_id,
+bool InputMethodEngine::SetCursorPosition(int context_id,
+ int candidate_id,
std::string* error) {
if (!IsActive()) {
*error = kErrorNotActive;
@@ -455,9 +452,8 @@ bool InputMethodEngine::UpdateMenuItems(
menu_item_list.push_back(property);
}
- ui::ime::InputMethodMenuManager::GetInstance()->
- SetCurrentInputMethodMenuItemList(
- menu_item_list);
+ ui::ime::InputMethodMenuManager::GetInstance()
+ ->SetCurrentInputMethodMenuItemList(menu_item_list);
return true;
}
@@ -490,7 +486,7 @@ bool InputMethodEngine::DeleteSurroundingText(int context_id,
void InputMethodEngine::HideInputView() {
keyboard::KeyboardController* keyboard_controller =
- keyboard::KeyboardController::GetInstance();
+ keyboard::KeyboardController::GetInstance();
if (keyboard_controller) {
keyboard_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_MANUAL);
@@ -527,40 +523,9 @@ void InputMethodEngine::FocusIn(
context_id_ = next_context_id_;
++next_context_id_;
- InputMethodEngineInterface::InputContext context;
- context.id = context_id_;
- switch (current_input_type_) {
- case ui::TEXT_INPUT_TYPE_SEARCH:
- context.type = "search";
- break;
- case ui::TEXT_INPUT_TYPE_TELEPHONE:
- context.type = "tel";
- break;
- case ui::TEXT_INPUT_TYPE_URL:
- context.type = "url";
- break;
- case ui::TEXT_INPUT_TYPE_EMAIL:
- context.type = "email";
- break;
- case ui::TEXT_INPUT_TYPE_NUMBER:
- context.type = "number";
- break;
- case ui::TEXT_INPUT_TYPE_PASSWORD:
- context.type = "password";
- break;
- default:
- context.type = "text";
- break;
- }
-
- context.auto_correct =
- !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
- context.auto_complete =
- !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCOMPLETE_OFF);
- context.spell_check =
- !(input_context.flags & ui::TEXT_INPUT_FLAG_SPELLCHECK_OFF);
-
- observer_->OnFocus(context);
+ observer_->OnFocus(ui::IMEEngineHandlerInterface::InputContext(
+ context_id_, input_context.type, input_context.mode,
+ input_context.flags));
}
void InputMethodEngine::FocusOut() {
@@ -616,15 +581,11 @@ bool InputMethodEngine::IsInterestedInKeyEvent() const {
return observer_->IsInterestedInKeyEvent();
}
-void InputMethodEngine::ProcessKeyEvent(
- const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) {
+void InputMethodEngine::ProcessKeyEvent(const ui::KeyEvent& key_event,
+ KeyEventDoneCallback& callback) {
if (!CheckProfile())
return;
- KeyEventDoneCallback* handler = new KeyEventDoneCallback();
- *handler = callback;
-
KeyboardEvent ext_event;
GetExtensionKeyboardEventFromKeyEvent(key_event, &ext_event);
@@ -635,10 +596,7 @@ void InputMethodEngine::ProcessKeyEvent(
if (&key_event == sent_key_event_)
ext_event.extension_id = extension_id_;
- observer_->OnKeyEvent(
- active_component_id_,
- ext_event,
- reinterpret_cast<input_method::KeyEventHandle*>(handler));
+ observer_->OnKeyEvent(active_component_id_, ext_event, callback);
}
void InputMethodEngine::CandidateClicked(uint32 index) {
@@ -649,8 +607,8 @@ void InputMethodEngine::CandidateClicked(uint32 index) {
}
// Only left button click is supported at this moment.
- observer_->OnCandidateClicked(
- active_component_id_, candidate_ids_.at(index), MOUSE_BUTTON_LEFT);
+ observer_->OnCandidateClicked(active_component_id_, candidate_ids_.at(index),
+ ui::IMEEngineObserver::MOUSE_BUTTON_LEFT);
}
void InputMethodEngine::SetSurroundingText(const std::string& text,
diff --git a/chrome/browser/chromeos/input_method/input_method_engine.h b/chrome/browser/chromeos/input_method/input_method_engine.h
index 9977042..72e9461 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine.h
+++ b/chrome/browser/chromeos/input_method/input_method_engine.h
@@ -9,8 +9,9 @@
#include <string>
#include <vector>
#include "base/time/time.h"
-#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "ui/base/ime/chromeos/input_method_descriptor.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
+#include "ui/base/ime/ime_engine_observer.h"
#include "url/gurl.h"
class Profile;
@@ -18,6 +19,8 @@ class Profile;
namespace ui {
class CandidateWindow;
struct CompositionText;
+class IMEEngineHandlerInterface;
+class IMEEngineObserver;
class KeyEvent;
namespace ime {
@@ -27,21 +30,17 @@ struct InputMethodMenuItem;
namespace chromeos {
-namespace input_method {
-struct KeyEventHandle;
-} // namespace input_method
-
-class InputMethodEngine : public InputMethodEngineInterface {
+class InputMethodEngine : public ui::IMEEngineHandlerInterface {
public:
InputMethodEngine();
~InputMethodEngine() override;
- void Initialize(scoped_ptr<InputMethodEngineInterface::Observer> observer,
+ void Initialize(scoped_ptr<ui::IMEEngineObserver> observer,
const char* extension_id,
Profile* profile);
- // InputMethodEngineInterface overrides.
+ // IMEEngineHandlerInterface overrides.
const std::string& GetActiveComponentId() const override;
bool SetComposition(int context_id,
const char* text,
@@ -83,7 +82,7 @@ class InputMethodEngine : public InputMethodEngineInterface {
void PropertyActivate(const std::string& property_name) override;
void Reset() override;
void ProcessKeyEvent(const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) override;
+ KeyEventDoneCallback& callback) override;
void CandidateClicked(uint32 index) override;
void SetSurroundingText(const std::string& text,
uint32 cursor_pos,
@@ -120,7 +119,7 @@ class InputMethodEngine : public InputMethodEngineInterface {
std::string extension_id_;
// The observer object recieving events for this IME.
- scoped_ptr<InputMethodEngineInterface::Observer> observer_;
+ scoped_ptr<ui::IMEEngineObserver> observer_;
// The current preedit text, and it's cursor position.
scoped_ptr<ui::CompositionText> composition_text_;
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc b/chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc
index d242d93..fc0d68c 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine_browsertests.cc
@@ -185,9 +185,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
KeyEventDoneCallback callback(false); // EchoBackIME doesn't consume keys.
ExtensionTestMessageListener keyevent_listener("onKeyEvent", false);
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
ASSERT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -269,9 +269,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::KeyEvent key_event(
ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::KEY_A, ui::EF_NONE);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -287,9 +287,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_CONTROL_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -305,9 +305,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_ALT_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -323,9 +323,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_SHIFT_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -341,9 +341,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_CAPS_LOCK_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -359,9 +359,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -377,9 +377,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
ui::VKEY_A,
ui::DomCode::KEY_A,
ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
@@ -425,9 +425,9 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
kMediaKeyCases[i].keycode,
ui::KeycodeConverter::CodeStringToDomCode(kMediaKeyCases[i].code),
ui::EF_NONE);
- engine_handler->ProcessKeyEvent(key_event,
- base::Bind(&KeyEventDoneCallback::Run,
- base::Unretained(&callback)));
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback keyevent_callback =
+ base::Bind(&KeyEventDoneCallback::Run, base::Unretained(&callback));
+ engine_handler->ProcessKeyEvent(key_event, keyevent_callback);
ASSERT_TRUE(keyevent_listener.WaitUntilSatisfied());
EXPECT_TRUE(keyevent_listener.was_satisfied());
callback.WaitUntilCalled();
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_interface.cc b/chrome/browser/chromeos/input_method/input_method_engine_interface.cc
deleted file mode 100644
index 102ef15..0000000
--- a/chrome/browser/chromeos/input_method/input_method_engine_interface.cc
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2013 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_method_engine_interface.h"
-
-namespace chromeos {
-
-InputMethodEngineInterface::KeyboardEvent::KeyboardEvent()
- : alt_key(false),
- ctrl_key(false),
- shift_key(false),
- caps_lock(false) {
-}
-
-InputMethodEngineInterface::KeyboardEvent::~KeyboardEvent() {
-}
-
-InputMethodEngineInterface::MenuItem::MenuItem() {
-}
-
-InputMethodEngineInterface::MenuItem::~MenuItem() {
-}
-
-InputMethodEngineInterface::Candidate::Candidate() {
-}
-
-InputMethodEngineInterface::Candidate::~Candidate() {
-}
-
-namespace {
-// The default entry number of a page in CandidateWindowProperty.
-const int kDefaultPageSize = 9;
-} // namespace
-
-// When the default values are changed, please modify
-// CandidateWindow::CandidateWindowProperty defined in chromeos/ime/ too.
-InputMethodEngineInterface::CandidateWindowProperty::CandidateWindowProperty()
- : page_size(kDefaultPageSize),
- is_cursor_visible(true),
- is_vertical(false),
- show_window_at_composition(false) {
-}
-
-InputMethodEngineInterface::CandidateWindowProperty::~CandidateWindowProperty()
-{
-}
-
-InputMethodEngineInterface::Observer::~Observer() {
-}
-} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_interface.h b/chrome/browser/chromeos/input_method/input_method_engine_interface.h
deleted file mode 100644
index 5120831..0000000
--- a/chrome/browser/chromeos/input_method/input_method_engine_interface.h
+++ /dev/null
@@ -1,262 +0,0 @@
-// Copyright 2013 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_METHOD_ENGINE_INTERFACE_H_
-#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
-
-#include <string>
-#include <vector>
-
-#include "ui/base/ime/ime_engine_handler_interface.h"
-
-class GURL;
-
-namespace chromeos {
-
-namespace input_method {
-class InputMethodDescriptor;
-struct KeyEventHandle;
-} // namespace input_method
-
-// InputMethodEngine is used to translate from the Chrome IME API to the native
-// API.
-class InputMethodEngineInterface : public ui::IMEEngineHandlerInterface {
- public:
- struct KeyboardEvent {
- KeyboardEvent();
- virtual ~KeyboardEvent();
-
- std::string type;
- std::string key;
- std::string code;
- int key_code; // only used by on-screen keyboards.
- std::string extension_id;
- bool alt_key;
- bool ctrl_key;
- bool shift_key;
- bool caps_lock;
- };
-
- enum {
- MENU_ITEM_MODIFIED_LABEL = 0x0001,
- MENU_ITEM_MODIFIED_STYLE = 0x0002,
- MENU_ITEM_MODIFIED_VISIBLE = 0x0004,
- MENU_ITEM_MODIFIED_ENABLED = 0x0008,
- MENU_ITEM_MODIFIED_CHECKED = 0x0010,
- MENU_ITEM_MODIFIED_ICON = 0x0020,
- };
-
- enum MenuItemStyle {
- MENU_ITEM_STYLE_NONE,
- MENU_ITEM_STYLE_CHECK,
- MENU_ITEM_STYLE_RADIO,
- MENU_ITEM_STYLE_SEPARATOR,
- };
-
- enum MouseButtonEvent {
- MOUSE_BUTTON_LEFT,
- MOUSE_BUTTON_RIGHT,
- MOUSE_BUTTON_MIDDLE,
- };
-
- enum SegmentStyle {
- SEGMENT_STYLE_UNDERLINE,
- SEGMENT_STYLE_DOUBLE_UNDERLINE,
- SEGMENT_STYLE_NO_UNDERLINE,
- };
-
- enum CandidateWindowPosition {
- WINDOW_POS_CURSOR,
- WINDOW_POS_COMPOSITTION,
- };
-
- struct MenuItem {
- MenuItem();
- virtual ~MenuItem();
-
- std::string id;
- std::string label;
- MenuItemStyle style;
- bool visible;
- bool enabled;
- bool checked;
-
- unsigned int modified;
- std::vector<MenuItem> children;
- };
-
- struct InputContext {
- int id;
- std::string type;
- bool auto_correct;
- bool auto_complete;
- bool spell_check;
- };
-
- struct UsageEntry {
- std::string title;
- std::string body;
- };
-
- struct Candidate {
- Candidate();
- virtual ~Candidate();
-
- std::string value;
- int id;
- std::string label;
- std::string annotation;
- UsageEntry usage;
- std::vector<Candidate> candidates;
- };
-
- struct CandidateWindowProperty {
- CandidateWindowProperty();
- virtual ~CandidateWindowProperty();
- int page_size;
- bool is_cursor_visible;
- bool is_vertical;
- bool show_window_at_composition;
-
- // Auxiliary text is typically displayed in the footer of the candidate
- // window.
- std::string auxiliary_text;
- bool is_auxiliary_text_visible;
- };
-
- struct SegmentInfo {
- int start;
- int end;
- SegmentStyle style;
- };
-
- class Observer {
- public:
- virtual ~Observer();
-
- // Called when the IME becomes the active IME.
- virtual void OnActivate(const std::string& engine_id) = 0;
-
- // Called when the IME is no longer active.
- virtual void OnDeactivated(const std::string& engine_id) = 0;
-
- // Called when a text field gains focus, and will be sending key events.
- virtual void OnFocus(const InputContext& context) = 0;
-
- // Called when a text field loses focus, and will no longer generate events.
- virtual void OnBlur(int context_id) = 0;
-
- // Called when an InputContext's properties change while it is focused.
- virtual void OnInputContextUpdate(const InputContext& context) = 0;
-
- // Returns whether the observer is interested in key events.
- virtual bool IsInterestedInKeyEvent() const = 0;
-
- // Called when the user pressed a key with a text field focused.
- virtual void OnKeyEvent(const std::string& engine_id,
- const KeyboardEvent& event,
- input_method::KeyEventHandle* key_data) = 0;
-
- // Called when the user clicks on an item in the candidate list.
- virtual void OnCandidateClicked(const std::string& engine_id,
- int candidate_id,
- MouseButtonEvent button) = 0;
-
- // Called when a menu item for this IME is interacted with.
- virtual void OnMenuItemActivated(const std::string& engine_id,
- const std::string& menu_id) = 0;
-
- // Called when a surrounding text is changed.
- virtual void OnSurroundingTextChanged(const std::string& engine_id,
- const std::string& text,
- int cursor_pos,
- int anchor_pos,
- int offset_pos) = 0;
-
- // Called when composition bounds are changed.
- virtual void OnCompositionBoundsChanged(
- const std::vector<gfx::Rect>& bounds) = 0;
-
- // Called when Chrome terminates on-going text input session.
- virtual void OnReset(const std::string& engine_id) = 0;
- };
-
- ~InputMethodEngineInterface() override {}
-
- // Set the current composition and associated properties.
- virtual bool SetComposition(int context_id,
- const char* text,
- int selection_start,
- int selection_end,
- int cursor,
- const std::vector<SegmentInfo>& segments,
- std::string* error) = 0;
-
- // Clear the current composition.
- virtual bool ClearComposition(int context_id, std::string* error) = 0;
-
- // Commit the specified text to the specified context. Fails if the context
- // is not focused.
- virtual bool CommitText(int context_id, const char* text,
- std::string* error) = 0;
-
- // Send the sequence of key events.
- virtual bool SendKeyEvents(int context_id,
- const std::vector<KeyboardEvent>& events) = 0;
-
- // This function returns the current property of the candidate window.
- // The caller can use the returned value as the default property and
- // modify some of specified items.
- virtual const CandidateWindowProperty&
- GetCandidateWindowProperty() const = 0;
-
- // Change the property of the candidate window and repaint the candidate
- // window widget.
- virtual void SetCandidateWindowProperty(
- const CandidateWindowProperty& property) = 0;
-
- // Show or hide the candidate window.
- virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0;
-
- // Set the list of entries displayed in the candidate window.
- virtual bool SetCandidates(int context_id,
- const std::vector<Candidate>& candidates,
- std::string* error) = 0;
-
- // Set the position of the cursor in the candidate window.
- virtual bool SetCursorPosition(int context_id, int candidate_id,
- std::string* error) = 0;
-
- // Set the list of items that appears in the language menu when this IME is
- // active.
- virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0;
-
- // Update the state of the menu items.
- virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0;
-
- // Returns true if this IME is active, false if not.
- virtual bool IsActive() const = 0;
-
- // Returns the current active input_component id.
- virtual const std::string& GetActiveComponentId() const = 0;
-
- // Deletes |number_of_chars| unicode characters as the basis of |offset| from
- // the surrounding text. The |offset| is relative position based on current
- // caret.
- // NOTE: Currently we are falling back to backspace forwarding workaround,
- // because delete_surrounding_text is not supported in Chrome. So this
- // function is restricted for only preceding text.
- // TODO(nona): Support full spec delete surrounding text.
- virtual bool DeleteSurroundingText(int context_id,
- int offset,
- size_t number_of_chars,
- std::string* error) = 0;
-
- // Hides the input view window (from API call).
- virtual void HideInputView() = 0;
-};
-
-} // namespace chromeos
-
-#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_ENGINE_INTERFACE_H_
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_unittest.cc b/chrome/browser/chromeos/input_method/input_method_engine_unittest.cc
index 75b919c..51127ed 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine_unittest.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine_unittest.cc
@@ -9,7 +9,6 @@
#include "base/test/histogram_tester.h"
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
#include "chrome/browser/chromeos/input_method/input_method_engine.h"
-#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,6 +16,8 @@
#include "ui/base/ime/chromeos/mock_component_extension_ime_manager_delegate.h"
#include "ui/base/ime/chromeos/mock_ime_input_context_handler.h"
#include "ui/base/ime/ime_bridge.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
+#include "ui/base/ime/ime_engine_observer.h"
#include "ui/base/ime/text_input_flags.h"
#include "ui/gfx/geometry/rect.h"
@@ -65,7 +66,7 @@ void InitInputMethod() {
InitializeForTesting(manager);
}
-class TestObserver : public InputMethodEngineInterface::Observer {
+class TestObserver : public ui::IMEEngineObserver {
public:
TestObserver() : calls_bitmap_(NONE) {}
~TestObserver() override {}
@@ -77,20 +78,20 @@ class TestObserver : public InputMethodEngineInterface::Observer {
calls_bitmap_ |= DEACTIVATED;
}
void OnFocus(
- const InputMethodEngineInterface::InputContext& context) override {
+ const ui::IMEEngineHandlerInterface::InputContext& context) override {
calls_bitmap_ |= ONFOCUS;
}
void OnBlur(int context_id) override { calls_bitmap_ |= ONBLUR; }
bool IsInterestedInKeyEvent() const override { return true; }
- void OnKeyEvent(const std::string& engine_id,
- const InputMethodEngineInterface::KeyboardEvent& event,
- input_method::KeyEventHandle* key_data) override {}
- void OnInputContextUpdate(
- const InputMethodEngineInterface::InputContext& context) override {}
- void OnCandidateClicked(
+ void OnKeyEvent(
const std::string& engine_id,
- int candidate_id,
- InputMethodEngineInterface::MouseButtonEvent button) override {}
+ const ui::IMEEngineHandlerInterface::KeyboardEvent& event,
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) override {}
+ void OnInputContextUpdate(
+ const ui::IMEEngineHandlerInterface::InputContext& context) override {}
+ void OnCandidateClicked(const std::string& engine_id,
+ int candidate_id,
+ MouseButtonEvent button) override {}
void OnMenuItemActivated(const std::string& engine_id,
const std::string& menu_id) override {}
void OnSurroundingTextChanged(const std::string& engine_id,
@@ -116,7 +117,7 @@ class TestObserver : public InputMethodEngineInterface::Observer {
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
-class InputMethodEngineTest : public testing::Test {
+class InputMethodEngineTest : public testing::Test {
public:
InputMethodEngineTest() : observer_(NULL), input_view_("inputview.html") {
languages_.push_back("en-US");
@@ -137,7 +138,7 @@ class InputMethodEngineTest : public testing::Test {
void CreateEngine(bool whitelisted) {
engine_.reset(new InputMethodEngine());
observer_ = new TestObserver();
- scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_);
+ scoped_ptr<ui::IMEEngineObserver> observer_ptr(observer_);
engine_->Initialize(observer_ptr.Pass(),
whitelisted ? kTestExtensionId : kTestExtensionId2,
ProfileManager::GetActiveUserProfile());
@@ -240,7 +241,7 @@ TEST_F(InputMethodEngineTest, TestHistograms) {
CreateEngine(true);
FocusIn(ui::TEXT_INPUT_TYPE_TEXT);
engine_->Enable(kTestImeComponentId);
- std::vector<InputMethodEngineInterface::SegmentInfo> segments;
+ std::vector<ui::IMEEngineHandlerInterface::SegmentInfo> segments;
int context = engine_->GetCotextIdForTesting();
std::string error;
base::HistogramTester histograms;
@@ -264,8 +265,7 @@ TEST_F(InputMethodEngineTest, TestCompositionBoundsChanged) {
std::vector<gfx::Rect> rects;
rects.push_back(gfx::Rect());
engine_->SetCompositionBounds(rects);
- EXPECT_EQ(ONCOMPOSITIONBOUNDSCHANGED,
- observer_->GetCallsBitmapAndReset());
+ EXPECT_EQ(ONCOMPOSITIONBOUNDSCHANGED, observer_->GetCallsBitmapAndReset());
}
} // namespace input_method
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
index 4eaf669..7f75d6b 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
@@ -23,7 +23,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/input_method/candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/component_extension_ime_manager_impl.h"
-#include "chrome/browser/chromeos/input_method/input_method_engine.h"
#include "chrome/browser/chromeos/input_method/input_method_switch_recorder.h"
#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
@@ -446,7 +445,7 @@ bool InputMethodManagerImpl::StateImpl::MethodAwaitsExtensionLoad(
void InputMethodManagerImpl::StateImpl::AddInputMethodExtension(
const std::string& extension_id,
const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* engine) {
+ ui::IMEEngineHandlerInterface* engine) {
if (manager_->ui_session_ == STATE_TERMINATING)
return;
@@ -975,7 +974,7 @@ void InputMethodManagerImpl::ChangeInputMethodInternal(
if (notify_menu) {
// Clear property list. Property list would be updated by
- // extension IMEs via InputMethodEngine::(Set|Update)MenuItems.
+ // extension IMEs via IMEEngineHandlerInterface::(Set|Update)MenuItems.
// If the current input method is a keyboard layout, empty
// properties are sufficient.
const ui::ime::InputMethodMenuItemList empty_menu_item_list;
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
index 7b11c0d..8860afc 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h
@@ -17,6 +17,11 @@
#include "chrome/browser/profiles/profile.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/ime/chromeos/input_method_whitelist.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
+
+namespace ui {
+class IMEEngineHandlerInterface;
+} // namespace ui
namespace chromeos {
class ComponentExtensionIMEManager;
@@ -71,9 +76,10 @@ class InputMethodManagerImpl : public InputMethodManager,
// InputMethodManager::State overrides.
scoped_refptr<InputMethodManager::State> Clone() const override;
- void AddInputMethodExtension(const std::string& extension_id,
- const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) override;
+ void AddInputMethodExtension(
+ const std::string& extension_id,
+ const InputMethodDescriptors& descriptors,
+ ui::IMEEngineHandlerInterface* instance) override;
void RemoveInputMethodExtension(const std::string& extension_id) override;
void ChangeInputMethod(const std::string& input_method_id,
bool show_message) override;
@@ -254,7 +260,7 @@ class InputMethodManagerImpl : public InputMethodManager,
bool enable_extension_loading_;
// The engine map from extension_id to an engine.
- typedef std::map<std::string, InputMethodEngineInterface*> EngineMap;
+ typedef std::map<std::string, ui::IMEEngineHandlerInterface*> EngineMap;
typedef std::map<Profile*, EngineMap, ProfileCompare> ProfileEngineMap;
ProfileEngineMap engine_map_;
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc
index 2b021b5..a91a3fe 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc
@@ -14,7 +14,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
-#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/chromeos/input_method/mock_candidate_window_controller.h"
#include "chrome/browser/chromeos/input_method/mock_input_method_engine.h"
#include "chrome/browser/profiles/profile_manager.h"
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_engine.cc b/chrome/browser/chromeos/input_method/mock_input_method_engine.cc
index 852a095..203527f 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_engine.cc
+++ b/chrome/browser/chromeos/input_method/mock_input_method_engine.cc
@@ -1,3 +1,4 @@
+
// Copyright 2014 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.
@@ -28,7 +29,7 @@ bool MockInputMethodEngine::SetComposition(
}
bool MockInputMethodEngine::ClearComposition(int context_id,
- std::string* error) {
+ std::string* error) {
return true;
}
@@ -50,8 +51,7 @@ MockInputMethodEngine::GetCandidateWindowProperty() const {
}
void MockInputMethodEngine::SetCandidateWindowProperty(
- const CandidateWindowProperty& property) {
-}
+ const CandidateWindowProperty& property) {}
bool MockInputMethodEngine::SetCandidateWindowVisible(bool visible,
std::string* error) {
@@ -91,15 +91,12 @@ bool MockInputMethodEngine::DeleteSurroundingText(int context_id,
return true;
}
-void MockInputMethodEngine::HideInputView() {
-}
+void MockInputMethodEngine::HideInputView() {}
void MockInputMethodEngine::FocusIn(
- const IMEEngineHandlerInterface::InputContext& input_context) {
-}
+ const IMEEngineHandlerInterface::InputContext& input_context) {}
-void MockInputMethodEngine::FocusOut() {
-}
+void MockInputMethodEngine::FocusOut() {}
void MockInputMethodEngine::Enable(const std::string& component_id) {
active_component_id_ = component_id;
@@ -113,20 +110,16 @@ void MockInputMethodEngine::PropertyActivate(const std::string& property_name) {
last_activated_property_ = property_name;
}
-void MockInputMethodEngine::Reset() {
-}
+void MockInputMethodEngine::Reset() {}
bool MockInputMethodEngine::IsInterestedInKeyEvent() const {
return true;
}
-void MockInputMethodEngine::ProcessKeyEvent(
- const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) {
-}
+void MockInputMethodEngine::ProcessKeyEvent(const ui::KeyEvent& key_event,
+ KeyEventDoneCallback& callback) {}
-void MockInputMethodEngine::CandidateClicked(uint32 index) {
-}
+void MockInputMethodEngine::CandidateClicked(uint32 index) {}
void MockInputMethodEngine::SetSurroundingText(const std::string& text,
uint32 cursor_pos,
@@ -134,7 +127,6 @@ void MockInputMethodEngine::SetSurroundingText(const std::string& text,
uint32 offset_pos) {}
void MockInputMethodEngine::SetCompositionBounds(
- const std::vector<gfx::Rect>& bounds) {
-}
+ const std::vector<gfx::Rect>& bounds) {}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_engine.h b/chrome/browser/chromeos/input_method/mock_input_method_engine.h
index 5151d39..2aa3952 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_engine.h
+++ b/chrome/browser/chromeos/input_method/mock_input_method_engine.h
@@ -8,10 +8,11 @@
#include <string>
#include <vector>
-#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "ui/base/ime/chromeos/input_method_descriptor.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
namespace ui {
+class IMEEngineHandlerInterface;
class KeyEvent;
namespace ime {
@@ -25,15 +26,14 @@ class CompositionText;
namespace input_method {
class CandidateWindow;
-struct KeyEventHandle;
}
-class MockInputMethodEngine : public InputMethodEngineInterface {
+class MockInputMethodEngine : public ui::IMEEngineHandlerInterface {
public:
MockInputMethodEngine();
~MockInputMethodEngine() override;
- // InputMethodEngineInterface overrides.
+ // IMEEngineHandlerInterface overrides.
const std::string& GetActiveComponentId() const override;
bool SetComposition(int context_id,
const char* text,
@@ -76,7 +76,7 @@ class MockInputMethodEngine : public InputMethodEngineInterface {
void Reset() override;
bool IsInterestedInKeyEvent() const override;
void ProcessKeyEvent(const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) override;
+ KeyEventDoneCallback& callback) override;
void CandidateClicked(uint32 index) override;
void SetSurroundingText(const std::string& text,
uint32 cursor_pos,
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
index 7254bf9..ef233ac 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
+++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc
@@ -116,8 +116,7 @@ void MockInputMethodManager::ActivateInputMethodMenuItem(
void MockInputMethodManager::State::AddInputMethodExtension(
const std::string& extension_id,
const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) {
-}
+ ui::IMEEngineHandlerInterface* instance) {}
void MockInputMethodManager::State::RemoveInputMethodExtension(
const std::string& extension_id) {
diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.h b/chrome/browser/chromeos/input_method/mock_input_method_manager.h
index 7673045..3a41db1 100644
--- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h
+++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h
@@ -23,9 +23,10 @@ class MockInputMethodManager : public InputMethodManager {
explicit State(MockInputMethodManager* manager);
scoped_refptr<InputMethodManager::State> Clone() const override;
- void AddInputMethodExtension(const std::string& extension_id,
- const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) override;
+ void AddInputMethodExtension(
+ const std::string& extension_id,
+ const InputMethodDescriptors& descriptors,
+ ui::IMEEngineHandlerInterface* instance) override;
void RemoveInputMethodExtension(const std::string& extension_id) override;
void ChangeInputMethod(const std::string& input_method_id,
bool show_message) override;
diff --git a/chrome/browser/chromeos/preferences_unittest.cc b/chrome/browser/chromeos/preferences_unittest.cc
index 8893663..af11c91 100644
--- a/chrome/browser/chromeos/preferences_unittest.cc
+++ b/chrome/browser/chromeos/preferences_unittest.cc
@@ -100,7 +100,7 @@ class MyMockInputMethodManager : public MockInputMethodManager {
void AddInputMethodExtension(
const std::string& id,
const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) override {
+ ui::IMEEngineHandlerInterface* instance) override {
InputMethodDescriptor descriptor(
id, std::string(), std::string(), std::vector<std::string>(),
std::vector<std::string>(), false, GURL(), GURL());
diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.cc b/chrome/browser/extensions/api/input_ime/input_ime_api.cc
index 8b0de98..d357cd4 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api.cc
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api.cc
@@ -24,6 +24,8 @@
#include "ui/base/ime/chromeos/component_extension_ime_manager.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
+#include "ui/base/ime/text_input_flags.h"
namespace input_ime = extensions::api::input_ime;
namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled;
@@ -40,7 +42,7 @@ namespace SetCandidateWindowProperties =
namespace CommitText = extensions::api::input_ime::CommitText;
namespace ClearComposition = extensions::api::input_ime::ClearComposition;
namespace SetComposition = extensions::api::input_ime::SetComposition;
-using chromeos::InputMethodEngineInterface;
+using ui::IMEEngineHandlerInterface;
namespace {
@@ -51,41 +53,33 @@ const char kOnCompositionBoundsChangedEventName[] =
"inputMethodPrivate.onCompositionBoundsChanged";
void SetMenuItemToMenu(const input_ime::MenuItem& input,
- InputMethodEngineInterface::MenuItem* out) {
+ IMEEngineHandlerInterface::MenuItem* out) {
out->modified = 0;
out->id = input.id;
if (input.label) {
- out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_LABEL;
+ out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_LABEL;
out->label = *input.label;
}
if (input.style != input_ime::MENU_ITEM_STYLE_NONE) {
- out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_STYLE;
- out->style = static_cast<InputMethodEngineInterface::MenuItemStyle>(
- input.style);
+ out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_STYLE;
+ out->style =
+ static_cast<IMEEngineHandlerInterface::MenuItemStyle>(input.style);
}
if (input.visible)
- out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_VISIBLE;
+ out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_VISIBLE;
out->visible = input.visible ? *input.visible : true;
if (input.checked)
- out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_CHECKED;
+ out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_CHECKED;
out->checked = input.checked ? *input.checked : false;
if (input.enabled)
- out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_ENABLED;
+ out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_ENABLED;
out->enabled = input.enabled ? *input.enabled : true;
}
-void CallbackKeyEventHandle(chromeos::input_method::KeyEventHandle* key_data,
- bool handled) {
- base::Callback<void(bool consumed)>* callback =
- reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data);
- callback->Run(handled);
- delete callback;
-}
-
extensions::InputImeEventRouter* GetInputImeEventRouter(Profile* profile) {
if (profile->HasOffTheRecordProfile())
profile = profile->GetOffTheRecordProfile();
@@ -96,7 +90,7 @@ extensions::InputImeEventRouter* GetInputImeEventRouter(Profile* profile) {
} // namespace
namespace chromeos {
-class ImeObserver : public InputMethodEngineInterface::Observer {
+class ImeObserver : public ui::IMEEngineObserver {
public:
explicit ImeObserver(const std::string& extension_id, Profile* profile)
: extension_id_(extension_id), profile_(profile) {}
@@ -129,16 +123,17 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
}
void OnFocus(
- const InputMethodEngineInterface::InputContext& context) override {
+ const IMEEngineHandlerInterface::InputContext& context) override {
if (extension_id_.empty() || !HasListener(input_ime::OnFocus::kEventName))
return;
input_ime::InputContext context_value;
context_value.context_id = context.id;
- context_value.type = input_ime::ParseInputContextType(context.type);
- context_value.auto_correct = context.auto_correct;
- context_value.auto_complete = context.auto_complete;
- context_value.spell_check = context.spell_check;
+ context_value.type =
+ input_ime::ParseInputContextType(ConvertInputContextType(context));
+ context_value.auto_correct = ConvertInputContextAutoCorrect(context);
+ context_value.auto_complete = ConvertInputContextAutoComplete(context);
+ context_value.spell_check = ConvertInputContextSpellCheck(context);
scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value));
@@ -157,14 +152,15 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
}
void OnInputContextUpdate(
- const InputMethodEngineInterface::InputContext& context) override {
+ const IMEEngineHandlerInterface::InputContext& context) override {
if (extension_id_.empty() ||
!HasListener(input_ime::OnInputContextUpdate::kEventName))
return;
input_ime::InputContext context_value;
context_value.context_id = context.id;
- context_value.type = input_ime::ParseInputContextType(context.type);
+ context_value.type =
+ input_ime::ParseInputContextType(ConvertInputContextType(context));
scoped_ptr<base::ListValue> args(
input_ime::OnInputContextUpdate::Create(context_value));
@@ -178,9 +174,10 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
return ShouldForwardKeyEvent();
}
- void OnKeyEvent(const std::string& component_id,
- const InputMethodEngineInterface::KeyboardEvent& event,
- chromeos::input_method::KeyEventHandle* key_data) override {
+ void OnKeyEvent(
+ const std::string& component_id,
+ const IMEEngineHandlerInterface::KeyboardEvent& event,
+ IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) override {
if (extension_id_.empty())
return;
@@ -189,7 +186,7 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
if (!ShouldForwardKeyEvent()) {
// Continue processing the key event so that the physical keyboard can
// still work.
- CallbackKeyEventHandle(key_data, false);
+ key_data.Run(false);
return;
}
@@ -218,22 +215,22 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
void OnCandidateClicked(
const std::string& component_id,
int candidate_id,
- InputMethodEngineInterface::MouseButtonEvent button) override {
+ ui::IMEEngineObserver::MouseButtonEvent button) override {
if (extension_id_.empty() ||
!HasListener(input_ime::OnCandidateClicked::kEventName))
return;
input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE;
switch (button) {
- case InputMethodEngineInterface::MOUSE_BUTTON_MIDDLE:
+ case ui::IMEEngineObserver::MOUSE_BUTTON_MIDDLE:
button_enum = input_ime::MOUSE_BUTTON_MIDDLE;
break;
- case InputMethodEngineInterface::MOUSE_BUTTON_RIGHT:
+ case ui::IMEEngineObserver::MOUSE_BUTTON_RIGHT:
button_enum = input_ime::MOUSE_BUTTON_RIGHT;
break;
- case InputMethodEngineInterface::MOUSE_BUTTON_LEFT:
+ case ui::IMEEngineObserver::MOUSE_BUTTON_LEFT:
// Default to left.
default:
button_enum = input_ime::MOUSE_BUTTON_LEFT;
@@ -327,6 +324,50 @@ class ImeObserver : public InputMethodEngineInterface::Observer {
input_ime::OnReset::kEventName, args.Pass());
}
+ std::string ConvertInputContextType(
+ ui::IMEEngineHandlerInterface::InputContext input_context) {
+ std::string input_context_type = "text";
+ switch (input_context.type) {
+ case ui::TEXT_INPUT_TYPE_SEARCH:
+ input_context_type = "search";
+ break;
+ case ui::TEXT_INPUT_TYPE_TELEPHONE:
+ input_context_type = "tel";
+ break;
+ case ui::TEXT_INPUT_TYPE_URL:
+ input_context_type = "url";
+ break;
+ case ui::TEXT_INPUT_TYPE_EMAIL:
+ input_context_type = "email";
+ break;
+ case ui::TEXT_INPUT_TYPE_NUMBER:
+ input_context_type = "number";
+ break;
+ case ui::TEXT_INPUT_TYPE_PASSWORD:
+ input_context_type = "password";
+ break;
+ default:
+ input_context_type = "text";
+ break;
+ }
+ return input_context_type;
+ }
+
+ bool ConvertInputContextAutoCorrect(
+ ui::IMEEngineHandlerInterface::InputContext input_context) {
+ return !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
+ }
+
+ bool ConvertInputContextAutoComplete(
+ ui::IMEEngineHandlerInterface::InputContext input_context) {
+ return !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCOMPLETE_OFF);
+ }
+
+ bool ConvertInputContextSpellCheck(
+ ui::IMEEngineHandlerInterface::InputContext input_context) {
+ return !(input_context.flags & ui::TEXT_INPUT_FLAG_SPELLCHECK_OFF);
+ }
+
private:
void DispatchEventToExtension(
extensions::events::HistogramValue histogram_value,
@@ -488,7 +529,7 @@ bool InputImeEventRouter::RegisterImeExtension(
}
}
- scoped_ptr<chromeos::InputMethodEngineInterface::Observer> observer(
+ scoped_ptr<ui::IMEEngineObserver> observer(
new chromeos::ImeObserver(extension_id, profile_));
chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine();
engine->Initialize(observer.Pass(), extension_id.c_str(), profile_);
@@ -501,7 +542,7 @@ bool InputImeEventRouter::RegisterImeExtension(
}
void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) {
- std::map<std::string, InputMethodEngineInterface*>::iterator it =
+ std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
engine_map_.find(extension_id);
if (it != engine_map_.end()) {
chromeos::input_method::InputMethodManager::Get()
@@ -512,19 +553,19 @@ void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) {
}
}
-InputMethodEngineInterface* InputImeEventRouter::GetEngine(
+IMEEngineHandlerInterface* InputImeEventRouter::GetEngine(
const std::string& extension_id,
const std::string& component_id) {
- std::map<std::string, InputMethodEngineInterface*>::iterator it =
+ std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
engine_map_.find(extension_id);
if (it != engine_map_.end())
return it->second;
return NULL;
}
-InputMethodEngineInterface* InputImeEventRouter::GetActiveEngine(
+IMEEngineHandlerInterface* InputImeEventRouter::GetActiveEngine(
const std::string& extension_id) {
- std::map<std::string, InputMethodEngineInterface*>::iterator it =
+ std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
engine_map_.find(extension_id);
if (it != engine_map_.end() && it->second->IsActive())
return it->second;
@@ -542,15 +583,13 @@ void InputImeEventRouter::OnKeyEventHandled(
}
std::string component_id = request->second.first;
- chromeos::input_method::KeyEventHandle* key_data = request->second.second;
+ (request->second.second).Run(handled);
request_map_.erase(request);
-
- CallbackKeyEventHandle(key_data, handled);
}
std::string InputImeEventRouter::AddRequest(
const std::string& component_id,
- chromeos::input_method::KeyEventHandle* key_data) {
+ IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) {
std::string request_id = base::IntToString(next_request_id_);
++next_request_id_;
@@ -560,7 +599,7 @@ std::string InputImeEventRouter::AddRequest(
}
bool InputImeSetCompositionFunction::RunSync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -571,7 +610,7 @@ bool InputImeSetCompositionFunction::RunSync() {
scoped_ptr<SetComposition::Params> parent_params(
SetComposition::Params::Create(*args_));
const SetComposition::Params::Parameters& params = parent_params->parameters;
- std::vector<InputMethodEngineInterface::SegmentInfo> segments;
+ std::vector<IMEEngineHandlerInterface::SegmentInfo> segments;
if (params.segments) {
const std::vector<linked_ptr<
SetComposition::Params::Parameters::SegmentsType> >&
@@ -580,20 +619,20 @@ bool InputImeSetCompositionFunction::RunSync() {
EXTENSION_FUNCTION_VALIDATE(
segments_args[i]->style !=
input_ime::UNDERLINE_STYLE_NONE);
- segments.push_back(InputMethodEngineInterface::SegmentInfo());
+ segments.push_back(IMEEngineHandlerInterface::SegmentInfo());
segments.back().start = segments_args[i]->start;
segments.back().end = segments_args[i]->end;
if (segments_args[i]->style ==
input_ime::UNDERLINE_STYLE_UNDERLINE) {
segments.back().style =
- InputMethodEngineInterface::SEGMENT_STYLE_UNDERLINE;
+ IMEEngineHandlerInterface::SEGMENT_STYLE_UNDERLINE;
} else if (segments_args[i]->style ==
input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) {
segments.back().style =
- InputMethodEngineInterface::SEGMENT_STYLE_DOUBLE_UNDERLINE;
+ IMEEngineHandlerInterface::SEGMENT_STYLE_DOUBLE_UNDERLINE;
} else {
segments.back().style =
- InputMethodEngineInterface::SEGMENT_STYLE_NO_UNDERLINE;
+ IMEEngineHandlerInterface::SEGMENT_STYLE_NO_UNDERLINE;
}
}
}
@@ -611,7 +650,7 @@ bool InputImeSetCompositionFunction::RunSync() {
}
bool InputImeClearCompositionFunction::RunSync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -630,7 +669,7 @@ bool InputImeClearCompositionFunction::RunSync() {
}
bool InputImeCommitTextFunction::RunSync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -649,7 +688,7 @@ bool InputImeCommitTextFunction::RunSync() {
}
bool InputImeHideInputViewFunction::RunAsync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -664,7 +703,7 @@ bool InputImeSendKeyEventsFunction::RunAsync() {
SendKeyEvents::Params::Create(*args_));
const SendKeyEvents::Params::Parameters& params =
parent_params->parameters;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -674,10 +713,10 @@ bool InputImeSendKeyEventsFunction::RunAsync() {
const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data =
params.key_data;
- std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out;
+ std::vector<IMEEngineHandlerInterface::KeyboardEvent> key_data_out;
for (size_t i = 0; i < key_data.size(); ++i) {
- chromeos::InputMethodEngineInterface::KeyboardEvent event;
+ IMEEngineHandlerInterface::KeyboardEvent event;
event.type = input_ime::ToString(key_data[i]->type);
event.key = key_data[i]->key;
event.code = key_data[i]->code;
@@ -703,7 +742,7 @@ bool InputImeSetCandidateWindowPropertiesFunction::RunSync() {
const SetCandidateWindowProperties::Params::Parameters&
params = parent_params->parameters;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetEngine(extension_id(), params.engine_id);
if (!engine) {
@@ -720,8 +759,8 @@ bool InputImeSetCandidateWindowPropertiesFunction::RunSync() {
return true;
}
- InputMethodEngineInterface::CandidateWindowProperty properties_out =
- engine->GetCandidateWindowProperty();
+ IMEEngineHandlerInterface::CandidateWindowProperty properties_out =
+ engine->GetCandidateWindowProperty();
bool modified = false;
if (properties.cursor_visible) {
@@ -768,7 +807,7 @@ bool InputImeSetCandidateWindowPropertiesFunction::RunSync() {
}
bool InputImeSetCandidatesFunction::RunSync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -781,12 +820,12 @@ bool InputImeSetCandidatesFunction::RunSync() {
const SetCandidates::Params::Parameters& params =
parent_params->parameters;
- std::vector<InputMethodEngineInterface::Candidate> candidates_out;
+ std::vector<IMEEngineHandlerInterface::Candidate> candidates_out;
const std::vector<linked_ptr<
SetCandidates::Params::Parameters::CandidatesType> >& candidates_in =
params.candidates;
for (size_t i = 0; i < candidates_in.size(); ++i) {
- candidates_out.push_back(InputMethodEngineInterface::Candidate());
+ candidates_out.push_back(IMEEngineHandlerInterface::Candidate());
candidates_out.back().value = candidates_in[i]->candidate;
candidates_out.back().id = candidates_in[i]->id;
if (candidates_in[i]->label)
@@ -805,7 +844,7 @@ bool InputImeSetCandidatesFunction::RunSync() {
}
bool InputImeSetCursorPositionFunction::RunSync() {
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetActiveEngine(extension_id());
if (!engine) {
@@ -830,7 +869,7 @@ bool InputImeSetMenuItemsFunction::RunSync() {
const SetMenuItems::Params::Parameters& params =
parent_params->parameters;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetEngine(extension_id(), params.engine_id);
if (!engine) {
@@ -839,10 +878,10 @@ bool InputImeSetMenuItemsFunction::RunSync() {
}
const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items;
- std::vector<InputMethodEngineInterface::MenuItem> items_out;
+ std::vector<IMEEngineHandlerInterface::MenuItem> items_out;
for (size_t i = 0; i < items.size(); ++i) {
- items_out.push_back(InputMethodEngineInterface::MenuItem());
+ items_out.push_back(IMEEngineHandlerInterface::MenuItem());
SetMenuItemToMenu(*items[i], &items_out.back());
}
@@ -857,7 +896,7 @@ bool InputImeUpdateMenuItemsFunction::RunSync() {
const UpdateMenuItems::Params::Parameters& params =
parent_params->parameters;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetEngine(extension_id(), params.engine_id);
if (!engine) {
@@ -866,10 +905,10 @@ bool InputImeUpdateMenuItemsFunction::RunSync() {
}
const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items;
- std::vector<InputMethodEngineInterface::MenuItem> items_out;
+ std::vector<IMEEngineHandlerInterface::MenuItem> items_out;
for (size_t i = 0; i < items.size(); ++i) {
- items_out.push_back(InputMethodEngineInterface::MenuItem());
+ items_out.push_back(IMEEngineHandlerInterface::MenuItem());
SetMenuItemToMenu(*items[i], &items_out.back());
}
@@ -884,7 +923,7 @@ bool InputImeDeleteSurroundingTextFunction::RunSync() {
const DeleteSurroundingText::Params::Parameters& params =
parent_params->parameters;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
->GetEngine(extension_id(), params.engine_id);
if (!engine) {
@@ -950,7 +989,7 @@ void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {
if (!details.browser_context)
return;
- InputMethodEngineInterface* engine =
+ IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(
Profile::FromBrowserContext(details.browser_context))
->GetActiveEngine(details.extension_id);
diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.h b/chrome/browser/extensions/api/input_ime/input_ime_api.h
index de640b1..031a359 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api.h
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api.h
@@ -12,7 +12,6 @@
#include "base/memory/singleton.h"
#include "base/scoped_observer.h"
#include "base/values.h"
-#include "chrome/browser/chromeos/input_method/input_method_engine_interface.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
@@ -20,13 +19,15 @@
#include "extensions/browser/extension_function.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h"
+#include "ui/base/ime/ime_engine_handler_interface.h"
+#include "ui/base/ime/ime_engine_observer.h"
class Profile;
-namespace chromeos {
-class InputMethodEngineInterface;
-class ImeObserver;
-} // namespace chromeos
+namespace ui {
+class IMEEngineHandlerInterface;
+class IMEEngineObserver;
+} // namespace ui
namespace extensions {
class ExtensionRegistry;
@@ -42,27 +43,29 @@ class InputImeEventRouter {
const std::vector<extensions::InputComponentInfo>& input_components);
void UnregisterAllImes(const std::string& extension_id);
- chromeos::InputMethodEngineInterface* GetEngine(
- const std::string& extension_id,
- const std::string& component_id);
- chromeos::InputMethodEngineInterface* GetActiveEngine(
+ ui::IMEEngineHandlerInterface* GetEngine(const std::string& extension_id,
+ const std::string& component_id);
+ ui::IMEEngineHandlerInterface* GetActiveEngine(
const std::string& extension_id);
-
// Called when a key event was handled.
void OnKeyEventHandled(const std::string& extension_id,
const std::string& request_id,
bool handled);
- std::string AddRequest(const std::string& component_id,
- chromeos::input_method::KeyEventHandle* key_data);
+ std::string AddRequest(
+ const std::string& component_id,
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback& key_data);
private:
- typedef std::map<std::string, std::pair<std::string,
- chromeos::input_method::KeyEventHandle*> > RequestMap;
+ typedef std::map<
+ std::string,
+ std::pair<std::string,
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback>>
+ RequestMap;
// The engine map from extension_id to an engine.
- std::map<std::string, chromeos::InputMethodEngineInterface*> engine_map_;
+ std::map<std::string, ui::IMEEngineHandlerInterface*> engine_map_;
unsigned int next_request_id_;
RequestMap request_map_;
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index f0d5bd6..aadff08 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -347,8 +347,6 @@
'browser/chromeos/input_method/input_method_delegate_impl.h',
'browser/chromeos/input_method/input_method_engine.cc',
'browser/chromeos/input_method/input_method_engine.h',
- 'browser/chromeos/input_method/input_method_engine_interface.cc',
- 'browser/chromeos/input_method/input_method_engine_interface.h',
'browser/chromeos/input_method/input_method_manager_impl.cc',
'browser/chromeos/input_method/input_method_manager_impl.h',
'browser/chromeos/input_method/input_method_persistence.cc',
diff --git a/ui/base/ime/BUILD.gn b/ui/base/ime/BUILD.gn
index 78f9c55..9169679 100644
--- a/ui/base/ime/BUILD.gn
+++ b/ui/base/ime/BUILD.gn
@@ -51,7 +51,9 @@ component("ime") {
"composition_underline.h",
"ime_bridge.cc",
"ime_bridge.h",
+ "ime_engine_handler_interface.cc",
"ime_engine_handler_interface.h",
+ "ime_engine_observer.h",
"ime_input_context_handler_interface.h",
"infolist_entry.cc",
"infolist_entry.h",
diff --git a/ui/base/ime/chromeos/input_method_manager.h b/ui/base/ime/chromeos/input_method_manager.h
index 0b903df..2f992ce 100644
--- a/ui/base/ime/chromeos/input_method_manager.h
+++ b/ui/base/ime/chromeos/input_method_manager.h
@@ -18,6 +18,7 @@ class Profile;
namespace ui {
class Accelerator;
+class IMEEngineHandlerInterface;
} // namespace ui
namespace user_manager {
@@ -26,7 +27,6 @@ class User;
namespace chromeos {
class ComponentExtensionIMEManager;
-class InputMethodEngineInterface;
namespace input_method {
class InputMethodUtil;
class ImeKeyboard;
@@ -77,7 +77,7 @@ class UI_BASE_IME_EXPORT InputMethodManager {
virtual void AddInputMethodExtension(
const std::string& extension_id,
const InputMethodDescriptors& descriptors,
- InputMethodEngineInterface* instance) = 0;
+ ui::IMEEngineHandlerInterface* instance) = 0;
// Removes an input method extension.
virtual void RemoveInputMethodExtension(
diff --git a/ui/base/ime/chromeos/mock_ime_engine_handler.cc b/ui/base/ime/chromeos/mock_ime_engine_handler.cc
index 3455b65..49dd4d4 100644
--- a/ui/base/ime/chromeos/mock_ime_engine_handler.cc
+++ b/ui/base/ime/chromeos/mock_ime_engine_handler.cc
@@ -53,9 +53,8 @@ bool MockIMEEngineHandler::IsInterestedInKeyEvent() const {
return true;
}
-void MockIMEEngineHandler::ProcessKeyEvent(
- const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) {
+void MockIMEEngineHandler::ProcessKeyEvent(const ui::KeyEvent& key_event,
+ KeyEventDoneCallback& callback) {
++process_key_event_call_count_;
last_processed_key_event_.reset(new ui::KeyEvent(key_event));
last_passed_callback_ = callback;
@@ -78,4 +77,78 @@ void MockIMEEngineHandler::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {
}
+bool MockIMEEngineHandler::SetComposition(
+ int context_id,
+ const char* text,
+ int selection_start,
+ int selection_end,
+ int cursor,
+ const std::vector<SegmentInfo>& segments,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::ClearComposition(int context_id,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::CommitText(int context_id,
+ const char* text,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::SendKeyEvents(
+ int context_id,
+ const std::vector<KeyboardEvent>& events) {
+ return false;
+}
+
+bool MockIMEEngineHandler::IsActive() const {
+ return false;
+}
+
+const std::string& MockIMEEngineHandler::GetActiveComponentId() const {
+ return active_component_id_;
+}
+
+bool MockIMEEngineHandler::DeleteSurroundingText(int context_id,
+ int offset,
+ size_t number_of_chars,
+ std::string* error) {
+ return false;
+}
+
+const MockIMEEngineHandler::CandidateWindowProperty&
+MockIMEEngineHandler::GetCandidateWindowProperty() const {
+ return candidate_window_property_;
+}
+
+bool MockIMEEngineHandler::SetCandidateWindowVisible(bool visible,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::SetCandidates(
+ int context_id,
+ const std::vector<Candidate>& candidates,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::SetCursorPosition(int context_id,
+ int candidate_id,
+ std::string* error) {
+ return false;
+}
+
+bool MockIMEEngineHandler::SetMenuItems(const std::vector<MenuItem>& items) {
+ return false;
+}
+
+bool MockIMEEngineHandler::UpdateMenuItems(const std::vector<MenuItem>& items) {
+ return false;
+}
+
} // namespace chromeos
diff --git a/ui/base/ime/chromeos/mock_ime_engine_handler.h b/ui/base/ime/chromeos/mock_ime_engine_handler.h
index 539c98f..d212fc5 100644
--- a/ui/base/ime/chromeos/mock_ime_engine_handler.h
+++ b/ui/base/ime/chromeos/mock_ime_engine_handler.h
@@ -25,7 +25,7 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler
void Reset() override;
bool IsInterestedInKeyEvent() const override;
void ProcessKeyEvent(const ui::KeyEvent& key_event,
- const KeyEventDoneCallback& callback) override;
+ KeyEventDoneCallback& callback) override;
void CandidateClicked(uint32 index) override;
void SetSurroundingText(const std::string& text,
uint32 cursor_pos,
@@ -71,6 +71,53 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler
return last_passed_callback_;
}
+ bool SetComposition(int context_id,
+ const char* text,
+ int selection_start,
+ int selection_end,
+ int cursor,
+ const std::vector<SegmentInfo>& segments,
+ std::string* error) override;
+
+ bool ClearComposition(int context_id, std::string* error) override;
+
+ bool CommitText(int context_id,
+ const char* text,
+ std::string* error) override;
+
+ bool SendKeyEvents(int context_id,
+ const std::vector<KeyboardEvent>& events) override;
+
+ bool IsActive() const override;
+
+ const std::string& GetActiveComponentId() const override;
+
+ bool DeleteSurroundingText(int context_id,
+ int offset,
+ size_t number_of_chars,
+ std::string* error) override;
+
+ const CandidateWindowProperty& GetCandidateWindowProperty() const override;
+
+ void SetCandidateWindowProperty(
+ const CandidateWindowProperty& property) override {}
+
+ bool SetCandidateWindowVisible(bool visible, std::string* error) override;
+
+ bool SetCandidates(int context_id,
+ const std::vector<Candidate>& candidates,
+ std::string* error) override;
+
+ bool SetCursorPosition(int context_id,
+ int candidate_id,
+ std::string* error) override;
+
+ bool SetMenuItems(const std::vector<MenuItem>& items) override;
+
+ bool UpdateMenuItems(const std::vector<MenuItem>& items) override;
+
+ void HideInputView() override {}
+
private:
int focus_in_call_count_;
int focus_out_call_count_;
@@ -84,6 +131,8 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler
uint32 last_set_surrounding_anchor_pos_;
scoped_ptr<ui::KeyEvent> last_processed_key_event_;
KeyEventDoneCallback last_passed_callback_;
+ std::string active_component_id_;
+ CandidateWindowProperty candidate_window_property_;
};
} // namespace chromeos
diff --git a/ui/base/ime/ime_engine_handler_interface.cc b/ui/base/ime/ime_engine_handler_interface.cc
new file mode 100644
index 0000000..ac45526
--- /dev/null
+++ b/ui/base/ime/ime_engine_handler_interface.cc
@@ -0,0 +1,43 @@
+// Copyright 2015 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 "ui/base/ime/ime_engine_handler_interface.h"
+
+namespace ui {
+
+IMEEngineHandlerInterface::KeyboardEvent::KeyboardEvent()
+ : alt_key(false), ctrl_key(false), shift_key(false), caps_lock(false) {}
+
+IMEEngineHandlerInterface::KeyboardEvent::~KeyboardEvent() {}
+
+// ChromeOS only APIs.
+#if defined(OS_CHROMEOS)
+
+IMEEngineHandlerInterface::MenuItem::MenuItem() {}
+
+IMEEngineHandlerInterface::MenuItem::~MenuItem() {}
+
+IMEEngineHandlerInterface::Candidate::Candidate() {}
+
+IMEEngineHandlerInterface::Candidate::~Candidate() {}
+
+namespace {
+// The default entry number of a page in CandidateWindowProperty.
+const int kDefaultPageSize = 9;
+} // namespace
+
+// When the default values are changed, please modify
+// CandidateWindow::CandidateWindowProperty defined in chromeos/ime/ too.
+IMEEngineHandlerInterface::CandidateWindowProperty::CandidateWindowProperty()
+ : page_size(kDefaultPageSize),
+ is_cursor_visible(true),
+ is_vertical(false),
+ show_window_at_composition(false) {}
+
+IMEEngineHandlerInterface::CandidateWindowProperty::~CandidateWindowProperty() {
+}
+
+#endif
+
+} // namespace ui
diff --git a/ui/base/ime/ime_engine_handler_interface.h b/ui/base/ime/ime_engine_handler_interface.h
index 04a6bea..9a27873 100644
--- a/ui/base/ime/ime_engine_handler_interface.h
+++ b/ui/base/ime/ime_engine_handler_interface.h
@@ -30,9 +30,13 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
// A type of each member is based on the html spec, but InputContext can be
// used to specify about a non html text field like Omnibox.
struct InputContext {
+ InputContext() {}
InputContext(TextInputType type_, TextInputMode mode_, int flags_)
: type(type_), mode(mode_), flags(flags_) {}
-
+ InputContext(int id_, TextInputType type_, TextInputMode mode_, int flags_)
+ : id(id_), type(type_), mode(mode_), flags(flags_) {}
+ // An attribute of the context id which used for ChromeOS only.
+ int id;
// An attribute of the field defined at
// http://www.w3.org/TR/html401/interact/forms.html#input-control-types.
TextInputType type;
@@ -46,6 +50,33 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
int flags;
};
+ struct KeyboardEvent {
+ KeyboardEvent();
+ virtual ~KeyboardEvent();
+
+ std::string type;
+ std::string key;
+ std::string code;
+ int key_code; // only used by on-screen keyboards.
+ std::string extension_id;
+ bool alt_key;
+ bool ctrl_key;
+ bool shift_key;
+ bool caps_lock;
+ };
+
+ enum SegmentStyle {
+ SEGMENT_STYLE_UNDERLINE,
+ SEGMENT_STYLE_DOUBLE_UNDERLINE,
+ SEGMENT_STYLE_NO_UNDERLINE,
+ };
+
+ struct SegmentInfo {
+ int start;
+ int end;
+ SegmentStyle style;
+ };
+
virtual ~IMEEngineHandlerInterface() {}
// Called when the Chrome input field get the focus.
@@ -69,11 +100,7 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
// Called when the key event is received.
// Actual implementation must call |callback| after key event handling.
virtual void ProcessKeyEvent(const KeyEvent& key_event,
- const KeyEventDoneCallback& callback) = 0;
-
- // Called when the candidate in lookup table is clicked. The |index| is 0
- // based candidate index in lookup table.
- virtual void CandidateClicked(uint32 index) = 0;
+ KeyEventDoneCallback& callback) = 0;
// Called when a new surrounding text is set. The |text| is surrounding text
// and |cursor_pos| is 0 based index of cursor position in |text|. If there is
@@ -92,6 +119,155 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
// If not, InputMethodChromeOS won't feed it with key events.
virtual bool IsInterestedInKeyEvent() const = 0;
+ // Set the current composition and associated properties.
+ virtual bool SetComposition(int context_id,
+ const char* text,
+ int selection_start,
+ int selection_end,
+ int cursor,
+ const std::vector<SegmentInfo>& segments,
+ std::string* error) = 0;
+
+ // Clear the current composition.
+ virtual bool ClearComposition(int context_id, std::string* error) = 0;
+
+ // Commit the specified text to the specified context. Fails if the context
+ // is not focused.
+ virtual bool CommitText(int context_id,
+ const char* text,
+ std::string* error) = 0;
+
+ // Send the sequence of key events.
+ virtual bool SendKeyEvents(int context_id,
+ const std::vector<KeyboardEvent>& events) = 0;
+
+ // Returns true if this IME is active, false if not.
+ virtual bool IsActive() const = 0;
+
+ // Returns the current active input_component id.
+ virtual const std::string& GetActiveComponentId() const = 0;
+
+ // Deletes |number_of_chars| unicode characters as the basis of |offset| from
+ // the surrounding text. The |offset| is relative position based on current
+ // caret.
+ // NOTE: Currently we are falling back to backspace forwarding workaround,
+ // because delete_surrounding_text is not supported in Chrome. So this
+ // function is restricted for only preceding text.
+ // TODO(nona): Support full spec delete surrounding text.
+ virtual bool DeleteSurroundingText(int context_id,
+ int offset,
+ size_t number_of_chars,
+ std::string* error) = 0;
+
+// ChromeOS only APIs.
+#if defined(OS_CHROMEOS)
+
+ enum {
+ MENU_ITEM_MODIFIED_LABEL = 0x0001,
+ MENU_ITEM_MODIFIED_STYLE = 0x0002,
+ MENU_ITEM_MODIFIED_VISIBLE = 0x0004,
+ MENU_ITEM_MODIFIED_ENABLED = 0x0008,
+ MENU_ITEM_MODIFIED_CHECKED = 0x0010,
+ MENU_ITEM_MODIFIED_ICON = 0x0020,
+ };
+
+ enum MenuItemStyle {
+ MENU_ITEM_STYLE_NONE,
+ MENU_ITEM_STYLE_CHECK,
+ MENU_ITEM_STYLE_RADIO,
+ MENU_ITEM_STYLE_SEPARATOR,
+ };
+
+ enum CandidateWindowPosition {
+ WINDOW_POS_CURSOR,
+ WINDOW_POS_COMPOSITTION,
+ };
+
+ struct MenuItem {
+ MenuItem();
+ virtual ~MenuItem();
+
+ std::string id;
+ std::string label;
+ MenuItemStyle style;
+ bool visible;
+ bool enabled;
+ bool checked;
+
+ unsigned int modified;
+ std::vector<MenuItem> children;
+ };
+
+ struct UsageEntry {
+ std::string title;
+ std::string body;
+ };
+
+ struct Candidate {
+ Candidate();
+ virtual ~Candidate();
+
+ std::string value;
+ int id;
+ std::string label;
+ std::string annotation;
+ UsageEntry usage;
+ std::vector<Candidate> candidates;
+ };
+
+ struct CandidateWindowProperty {
+ CandidateWindowProperty();
+ virtual ~CandidateWindowProperty();
+ int page_size;
+ bool is_cursor_visible;
+ bool is_vertical;
+ bool show_window_at_composition;
+
+ // Auxiliary text is typically displayed in the footer of the candidate
+ // window.
+ std::string auxiliary_text;
+ bool is_auxiliary_text_visible;
+ };
+
+ // Called when the candidate in lookup table is clicked. The |index| is 0
+ // based candidate index in lookup table.
+ virtual void CandidateClicked(uint32 index) = 0;
+
+ // This function returns the current property of the candidate window.
+ // The caller can use the returned value as the default property and
+ // modify some of specified items.
+ virtual const CandidateWindowProperty& GetCandidateWindowProperty() const = 0;
+
+ // Change the property of the candidate window and repaint the candidate
+ // window widget.
+ virtual void SetCandidateWindowProperty(
+ const CandidateWindowProperty& property) = 0;
+
+ // Show or hide the candidate window.
+ virtual bool SetCandidateWindowVisible(bool visible, std::string* error) = 0;
+
+ // Set the list of entries displayed in the candidate window.
+ virtual bool SetCandidates(int context_id,
+ const std::vector<Candidate>& candidates,
+ std::string* error) = 0;
+
+ // Set the position of the cursor in the candidate window.
+ virtual bool SetCursorPosition(int context_id,
+ int candidate_id,
+ std::string* error) = 0;
+
+ // Set the list of items that appears in the language menu when this IME is
+ // active.
+ virtual bool SetMenuItems(const std::vector<MenuItem>& items) = 0;
+
+ // Update the state of the menu items.
+ virtual bool UpdateMenuItems(const std::vector<MenuItem>& items) = 0;
+
+ // Hides the input view window (from API call).
+ virtual void HideInputView() = 0;
+
+#endif
+
protected:
IMEEngineHandlerInterface() {}
};
diff --git a/ui/base/ime/ime_engine_observer.h b/ui/base/ime/ime_engine_observer.h
new file mode 100644
index 0000000..39ded6c
--- /dev/null
+++ b/ui/base/ime/ime_engine_observer.h
@@ -0,0 +1,78 @@
+// Copyright 2015 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 UI_BASE_IME_IME_ENGINE_OBSERVER_H_
+#define UI_BASE_IME_IME_ENGINE_OBSERVER_H_
+
+#include "ui/base/ime/ime_engine_handler_interface.h"
+
+namespace ui {
+
+class IMEEngineObserver {
+ public:
+ virtual ~IMEEngineObserver() {}
+
+ // Called when a text field gains focus, and will be sending key events.
+ virtual void OnFocus(
+ const IMEEngineHandlerInterface::InputContext& context) = 0;
+
+ // Called when a text field loses focus, and will no longer generate events.
+ virtual void OnBlur(int context_id) = 0;
+
+ // Called when the user pressed a key with a text field focused.
+ virtual void OnKeyEvent(
+ const std::string& engine_id,
+ const IMEEngineHandlerInterface::KeyboardEvent& event,
+ IMEEngineHandlerInterface::KeyEventDoneCallback& key_data) = 0;
+
+ // Called when Chrome terminates on-going text input session.
+ virtual void OnReset(const std::string& engine_id) = 0;
+
+ // Called when the IME is no longer active.
+ virtual void OnDeactivated(const std::string& engine_id) = 0;
+
+ // Called when composition bounds are changed.
+ virtual void OnCompositionBoundsChanged(
+ const std::vector<gfx::Rect>& bounds) = 0;
+
+// ChromeOS only APIs.
+#if defined(OS_CHROMEOS)
+
+ enum MouseButtonEvent {
+ MOUSE_BUTTON_LEFT,
+ MOUSE_BUTTON_RIGHT,
+ MOUSE_BUTTON_MIDDLE,
+ };
+
+ // Called when the IME becomes the active IME.
+ virtual void OnActivate(const std::string& engine_id) = 0;
+
+ // Called when an InputContext's properties change while it is focused.
+ virtual void OnInputContextUpdate(
+ const IMEEngineHandlerInterface::InputContext& context) = 0;
+
+ // Returns whether the observer is interested in key events.
+ virtual bool IsInterestedInKeyEvent() const = 0;
+
+ // Called when the user clicks on an item in the candidate list.
+ virtual void OnCandidateClicked(const std::string& engine_id,
+ int candidate_id,
+ MouseButtonEvent button) = 0;
+
+ // Called when a menu item for this IME is interacted with.
+ virtual void OnMenuItemActivated(const std::string& engine_id,
+ const std::string& menu_id) = 0;
+
+ // Called when a surrounding text is changed.
+ virtual void OnSurroundingTextChanged(const std::string& engine_id,
+ const std::string& text,
+ int cursor_pos,
+ int anchor_pos,
+ int offset_pos) = 0;
+#endif
+};
+
+} // namespace ui
+
+#endif // UI_BASE_IME_IME_ENGINE_OBSERVER_H_
diff --git a/ui/base/ime/input_method_chromeos.cc b/ui/base/ime/input_method_chromeos.cc
index f5b2bc2..fc5b3a1 100644
--- a/ui/base/ime/input_method_chromeos.cc
+++ b/ui/base/ime/input_method_chromeos.cc
@@ -138,12 +138,12 @@ void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) {
handling_key_event_ = true;
if (GetEngine()->IsInterestedInKeyEvent()) {
- GetEngine()->ProcessKeyEvent(
- *event,
+ ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback =
base::Bind(&InputMethodChromeOS::ProcessKeyEventDone,
weak_ptr_factory_.GetWeakPtr(),
// Pass the ownership of the new copied event.
- base::Owned(new ui::KeyEvent(*event))));
+ base::Owned(new ui::KeyEvent(*event)));
+ GetEngine()->ProcessKeyEvent(*event, callback);
} else {
ProcessKeyEventDone(event, false);
}
diff --git a/ui/base/ime/ui_base_ime.gyp b/ui/base/ime/ui_base_ime.gyp
index 3b5b137..22c3e72 100644
--- a/ui/base/ime/ui_base_ime.gyp
+++ b/ui/base/ime/ui_base_ime.gyp
@@ -73,7 +73,9 @@
'composition_underline.h',
'ime_bridge.cc',
'ime_bridge.h',
+ 'ime_engine_handler_interface.cc',
'ime_engine_handler_interface.h',
+ 'ime_engine_observer.h',
'ime_input_context_handler_interface.h',
'infolist_entry.cc',
'infolist_entry.h',