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

Cleans up some useless methods in IMEEngineHandlerInterface.

This cl doesn't change any behaviors.

Bug: 937167
Change-Id: I35be2c76784d38c651f0e3d21a12e07a96b5e1af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1498253
Commit-Queue: Shu Chen <shuchen@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637589}
parent e5a1e57a
...@@ -73,6 +73,43 @@ InputMethodEngine::InputMethodEngine() ...@@ -73,6 +73,43 @@ InputMethodEngine::InputMethodEngine()
InputMethodEngine::~InputMethodEngine() {} InputMethodEngine::~InputMethodEngine() {}
void InputMethodEngine::Enable(const std::string& component_id) {
InputMethodEngineBase::Enable(component_id);
EnableInputView();
}
bool InputMethodEngine::IsActive() const {
return !active_component_id_.empty();
}
void InputMethodEngine::PropertyActivate(const std::string& property_name) {
observer_->OnMenuItemActivated(active_component_id_, property_name);
}
void InputMethodEngine::CandidateClicked(uint32_t index) {
if (index > candidate_ids_.size()) {
return;
}
// Only left button click is supported at this moment.
observer_->OnCandidateClicked(active_component_id_, candidate_ids_.at(index),
InputMethodEngineBase::MOUSE_BUTTON_LEFT);
}
void InputMethodEngine::SetMirroringEnabled(bool mirroring_enabled) {
if (mirroring_enabled != is_mirroring_) {
is_mirroring_ = mirroring_enabled;
observer_->OnScreenProjectionChanged(is_mirroring_ || is_casting_);
}
}
void InputMethodEngine::SetCastingEnabled(bool casting_enabled) {
if (casting_enabled != is_casting_) {
is_casting_ = casting_enabled;
observer_->OnScreenProjectionChanged(is_mirroring_ || is_casting_);
}
}
const InputMethodEngine::CandidateWindowProperty& const InputMethodEngine::CandidateWindowProperty&
InputMethodEngine::GetCandidateWindowProperty() const { InputMethodEngine::GetCandidateWindowProperty() const {
return candidate_window_property_; return candidate_window_property_;
...@@ -214,30 +251,56 @@ bool InputMethodEngine::UpdateMenuItems( ...@@ -214,30 +251,56 @@ bool InputMethodEngine::UpdateMenuItems(
return true; return true;
} }
bool InputMethodEngine::IsActive() const {
return !active_component_id_.empty();
}
void InputMethodEngine::HideInputView() { void InputMethodEngine::HideInputView() {
auto* keyboard_client = ChromeKeyboardControllerClient::Get(); auto* keyboard_client = ChromeKeyboardControllerClient::Get();
if (keyboard_client->is_keyboard_enabled()) if (keyboard_client->is_keyboard_enabled())
keyboard_client->HideKeyboard(ash::mojom::HideReason::kUser); keyboard_client->HideKeyboard(ash::mojom::HideReason::kUser);
} }
void InputMethodEngine::SetMirroringEnabled(bool mirroring_enabled) { void InputMethodEngine::UpdateComposition(
if (mirroring_enabled != is_mirroring_) { const ui::CompositionText& composition_text,
is_mirroring_ = mirroring_enabled; uint32_t cursor_pos,
observer_->OnScreenProjectionChanged(is_mirroring_ || is_casting_); bool is_visible) {
} ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (input_context)
input_context->UpdateCompositionText(composition_text, cursor_pos,
is_visible);
} }
void InputMethodEngine::SetCastingEnabled(bool casting_enabled) { void InputMethodEngine::CommitTextToInputContext(int context_id,
if (casting_enabled != is_casting_) { const std::string& text) {
is_casting_ = casting_enabled; ui::IMEBridge::Get()->GetInputContextHandler()->CommitText(text);
observer_->OnScreenProjectionChanged(is_mirroring_ || is_casting_);
// Records histograms for committed characters.
if (!composition_text_->text.empty()) {
base::string16 wtext = base::UTF8ToUTF16(text);
UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", wtext.length(), 1,
25, 25);
composition_text_.reset(new ui::CompositionText());
} }
} }
bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event,
const std::string& code) {
DCHECK(event);
if (event->key_code() == ui::VKEY_UNKNOWN)
event->set_key_code(ui::DomKeycodeToKeyboardCode(code));
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (!input_context)
return false;
// Marks the simulated key event is from the Virtual Keyboard.
ui::Event::Properties properties;
properties[ui::kPropertyFromVK] = std::vector<uint8_t>();
event->SetProperties(properties);
input_context->SendKeyEvent(event);
return true;
}
void InputMethodEngine::EnableInputView() { void InputMethodEngine::EnableInputView() {
input_method::InputMethodManager::Get() input_method::InputMethodManager::Get()
->GetActiveIMEState() ->GetActiveIMEState()
...@@ -248,25 +311,6 @@ void InputMethodEngine::EnableInputView() { ...@@ -248,25 +311,6 @@ void InputMethodEngine::EnableInputView() {
} }
void InputMethodEngine::Enable(const std::string& component_id) {
InputMethodEngineBase::Enable(component_id);
EnableInputView();
}
void InputMethodEngine::PropertyActivate(const std::string& property_name) {
observer_->OnMenuItemActivated(active_component_id_, property_name);
}
void InputMethodEngine::CandidateClicked(uint32_t index) {
if (index > candidate_ids_.size()) {
return;
}
// Only left button click is supported at this moment.
observer_->OnCandidateClicked(active_component_id_, candidate_ids_.at(index),
InputMethodEngineBase::MOUSE_BUTTON_LEFT);
}
// TODO(uekawa): rename this method to a more reasonable name. // TODO(uekawa): rename this method to a more reasonable name.
void InputMethodEngine::MenuItemToProperty( void InputMethodEngine::MenuItemToProperty(
const input_method::InputMethodManager::MenuItem& item, const input_method::InputMethodManager::MenuItem& item,
...@@ -309,48 +353,4 @@ void InputMethodEngine::MenuItemToProperty( ...@@ -309,48 +353,4 @@ void InputMethodEngine::MenuItemToProperty(
// TODO(nona): Support item.children. // TODO(nona): Support item.children.
} }
void InputMethodEngine::UpdateComposition(
const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool is_visible) {
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (input_context)
input_context->UpdateCompositionText(composition_text, cursor_pos,
is_visible);
}
void InputMethodEngine::CommitTextToInputContext(int context_id,
const std::string& text) {
ui::IMEBridge::Get()->GetInputContextHandler()->CommitText(text);
// Records histograms for committed characters.
if (!composition_text_->text.empty()) {
base::string16 wtext = base::UTF8ToUTF16(text);
UMA_HISTOGRAM_CUSTOM_COUNTS("InputMethod.CommitLength", wtext.length(), 1,
25, 25);
composition_text_.reset(new ui::CompositionText());
}
}
bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event,
const std::string& code) {
DCHECK(event);
if (event->key_code() == ui::VKEY_UNKNOWN)
event->set_key_code(ui::DomKeycodeToKeyboardCode(code));
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (!input_context)
return false;
// Marks the simulated key event is from the Virtual Keyboard.
ui::Event::Properties properties;
properties[ui::kPropertyFromVK] = std::vector<uint8_t>();
event->SetProperties(properties);
input_context->SendKeyEvent(event);
return true;
}
} // namespace chromeos } // namespace chromeos
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
namespace ui { namespace ui {
class CandidateWindow; class CandidateWindow;
struct CompositionText; struct CompositionText;
class IMEEngineHandlerInterface;
class KeyEvent; class KeyEvent;
namespace ime { namespace ime {
...@@ -87,16 +86,13 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase { ...@@ -87,16 +86,13 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase {
~InputMethodEngine() override; ~InputMethodEngine() override;
// IMEEngineHandlerInterface overrides. // InputMethodEngineBase overrides.
bool SetCandidateWindowVisible(bool visible, std::string* error) override;
bool SetCursorPosition(int context_id,
int candidate_id,
std::string* error) override;
bool IsActive() const override;
void Enable(const std::string& component_id) override; void Enable(const std::string& component_id) override;
bool IsActive() const override;
// ui::IMEEngineHandlerInterface overrides.
void PropertyActivate(const std::string& property_name) override; void PropertyActivate(const std::string& property_name) override;
void CandidateClicked(uint32_t index) override; void CandidateClicked(uint32_t index) override;
void HideInputView() override;
void SetMirroringEnabled(bool mirroring_enabled) override; void SetMirroringEnabled(bool mirroring_enabled) override;
void SetCastingEnabled(bool casting_enabled) override; void SetCastingEnabled(bool casting_enabled) override;
...@@ -109,11 +105,17 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase { ...@@ -109,11 +105,17 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase {
// window widget. // window widget.
void SetCandidateWindowProperty(const CandidateWindowProperty& property); void SetCandidateWindowProperty(const CandidateWindowProperty& property);
// Show or hide the candidate window.
bool SetCandidateWindowVisible(bool visible, std::string* error);
// Set the list of entries displayed in the candidate window. // Set the list of entries displayed in the candidate window.
bool SetCandidates(int context_id, bool SetCandidates(int context_id,
const std::vector<Candidate>& candidates, const std::vector<Candidate>& candidates,
std::string* error); std::string* error);
// Set the position of the cursor in the candidate window.
bool SetCursorPosition(int context_id, int candidate_id, std::string* error);
// Set the list of items that appears in the language menu when this IME is // Set the list of items that appears in the language menu when this IME is
// active. // active.
bool SetMenuItems( bool SetMenuItems(
...@@ -123,15 +125,10 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase { ...@@ -123,15 +125,10 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase {
bool UpdateMenuItems( bool UpdateMenuItems(
const std::vector<input_method::InputMethodManager::MenuItem>& items); const std::vector<input_method::InputMethodManager::MenuItem>& items);
private: // Hides the input view window (from API call).
// Converts MenuItem to InputMethodMenuItem. void HideInputView();
void MenuItemToProperty(
const input_method::InputMethodManager::MenuItem& item,
ui::ime::InputMethodMenuItem* property);
// Enables overriding input view page to Virtual Keyboard window.
void EnableInputView();
private:
// input_method::InputMethodEngineBase: // input_method::InputMethodEngineBase:
void UpdateComposition(const ui::CompositionText& composition_text, void UpdateComposition(const ui::CompositionText& composition_text,
uint32_t cursor_pos, uint32_t cursor_pos,
...@@ -140,6 +137,14 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase { ...@@ -140,6 +137,14 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase {
const std::string& text) override; const std::string& text) override;
bool SendKeyEvent(ui::KeyEvent* event, const std::string& code) override; bool SendKeyEvent(ui::KeyEvent* event, const std::string& code) override;
// Enables overriding input view page to Virtual Keyboard window.
void EnableInputView();
// Converts MenuItem to InputMethodMenuItem.
void MenuItemToProperty(
const input_method::InputMethodManager::MenuItem& item,
ui::ime::InputMethodMenuItem* property);
// The current candidate window. // The current candidate window.
std::unique_ptr<ui::CandidateWindow> candidate_window_; std::unique_ptr<ui::CandidateWindow> candidate_window_;
......
...@@ -308,7 +308,7 @@ TEST_F(InputMethodEngineTest, TestHistograms) { ...@@ -308,7 +308,7 @@ TEST_F(InputMethodEngineTest, TestHistograms) {
FocusIn(ui::TEXT_INPUT_TYPE_TEXT); FocusIn(ui::TEXT_INPUT_TYPE_TEXT);
engine_->Enable(kTestImeComponentId); engine_->Enable(kTestImeComponentId);
std::vector<InputMethodEngineBase::SegmentInfo> segments; std::vector<InputMethodEngineBase::SegmentInfo> segments;
int context = engine_->GetCotextIdForTesting(); int context = engine_->GetContextIdForTesting();
std::string error; std::string error;
base::HistogramTester histograms; base::HistogramTester histograms;
engine_->SetComposition(context, "test", 0, 0, 0, segments, nullptr); engine_->SetComposition(context, "test", 0, 0, 0, segments, nullptr);
......
...@@ -13,49 +13,6 @@ MockInputMethodEngine::MockInputMethodEngine() {} ...@@ -13,49 +13,6 @@ MockInputMethodEngine::MockInputMethodEngine() {}
MockInputMethodEngine::~MockInputMethodEngine() {} MockInputMethodEngine::~MockInputMethodEngine() {}
const std::string& MockInputMethodEngine::GetActiveComponentId() const {
return active_component_id_;
}
bool MockInputMethodEngine::ClearComposition(int context_id,
std::string* error) {
return true;
}
bool MockInputMethodEngine::CommitText(int context_id,
const char* text,
std::string* error) {
return true;
}
bool MockInputMethodEngine::SetCandidateWindowVisible(bool visible,
std::string* error) {
return true;
}
bool MockInputMethodEngine::SetCursorPosition(int context_id,
int candidate_id,
std::string* error) {
return true;
}
bool MockInputMethodEngine::IsActive() const {
return true;
}
bool MockInputMethodEngine::DeleteSurroundingText(int context_id,
int offset,
size_t number_of_chars,
std::string* error) {
return true;
}
void MockInputMethodEngine::HideInputView() {}
void MockInputMethodEngine::SetMirroringEnabled(bool mirroring_enabled) {}
void MockInputMethodEngine::SetCastingEnabled(bool casting_enabled) {}
void MockInputMethodEngine::FocusIn( void MockInputMethodEngine::FocusIn(
const IMEEngineHandlerInterface::InputContext& input_context) {} const IMEEngineHandlerInterface::InputContext& input_context) {}
...@@ -69,10 +26,6 @@ void MockInputMethodEngine::Disable() { ...@@ -69,10 +26,6 @@ void MockInputMethodEngine::Disable() {
active_component_id_.clear(); active_component_id_.clear();
} }
void MockInputMethodEngine::PropertyActivate(const std::string& property_name) {
last_activated_property_ = property_name;
}
void MockInputMethodEngine::Reset() {} void MockInputMethodEngine::Reset() {}
bool MockInputMethodEngine::IsInterestedInKeyEvent() const { bool MockInputMethodEngine::IsInterestedInKeyEvent() const {
...@@ -82,8 +35,6 @@ bool MockInputMethodEngine::IsInterestedInKeyEvent() const { ...@@ -82,8 +35,6 @@ bool MockInputMethodEngine::IsInterestedInKeyEvent() const {
void MockInputMethodEngine::ProcessKeyEvent(const ui::KeyEvent& key_event, void MockInputMethodEngine::ProcessKeyEvent(const ui::KeyEvent& key_event,
KeyEventDoneCallback callback) {} KeyEventDoneCallback callback) {}
void MockInputMethodEngine::CandidateClicked(uint32_t index) {}
void MockInputMethodEngine::SetSurroundingText(const std::string& text, void MockInputMethodEngine::SetSurroundingText(const std::string& text,
uint32_t cursor_pos, uint32_t cursor_pos,
uint32_t anchor_pos, uint32_t anchor_pos,
...@@ -92,4 +43,18 @@ void MockInputMethodEngine::SetSurroundingText(const std::string& text, ...@@ -92,4 +43,18 @@ void MockInputMethodEngine::SetSurroundingText(const std::string& text,
void MockInputMethodEngine::SetCompositionBounds( void MockInputMethodEngine::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {} const std::vector<gfx::Rect>& bounds) {}
void MockInputMethodEngine::PropertyActivate(const std::string& property_name) {
last_activated_property_ = property_name;
}
void MockInputMethodEngine::CandidateClicked(uint32_t index) {}
void MockInputMethodEngine::SetMirroringEnabled(bool mirroring_enabled) {}
void MockInputMethodEngine::SetCastingEnabled(bool casting_enabled) {}
const std::string& MockInputMethodEngine::GetActiveComponentId() const {
return active_component_id_;
}
} // namespace chromeos } // namespace chromeos
...@@ -26,43 +26,28 @@ class MockInputMethodEngine : public ui::IMEEngineHandlerInterface { ...@@ -26,43 +26,28 @@ class MockInputMethodEngine : public ui::IMEEngineHandlerInterface {
MockInputMethodEngine(); MockInputMethodEngine();
~MockInputMethodEngine() override; ~MockInputMethodEngine() override;
// IMEEngineHandlerInterface overrides.
const std::string& GetActiveComponentId() const override;
bool ClearComposition(int context_id, std::string* error) override;
bool CommitText(int context_id,
const char* text,
std::string* error) override;
bool SetCandidateWindowVisible(bool visible, std::string* error) override;
bool SetCursorPosition(int context_id,
int candidate_id,
std::string* error) override;
bool IsActive() const override;
bool DeleteSurroundingText(int context_id,
int offset,
size_t number_of_chars,
std::string* error) override;
// IMEEngineHandlerInterface overrides. // IMEEngineHandlerInterface overrides.
void FocusIn( void FocusIn(
const IMEEngineHandlerInterface::InputContext& input_context) override; const IMEEngineHandlerInterface::InputContext& input_context) override;
void FocusOut() override; void FocusOut() override;
void Enable(const std::string& component_id) override; void Enable(const std::string& component_id) override;
void Disable() override; void Disable() override;
void PropertyActivate(const std::string& property_name) override;
void Reset() override; void Reset() override;
bool IsInterestedInKeyEvent() const override; bool IsInterestedInKeyEvent() const override;
void ProcessKeyEvent(const ui::KeyEvent& key_event, void ProcessKeyEvent(const ui::KeyEvent& key_event,
KeyEventDoneCallback callback) override; KeyEventDoneCallback callback) override;
void CandidateClicked(uint32_t index) override;
void SetSurroundingText(const std::string& text, void SetSurroundingText(const std::string& text,
uint32_t cursor_pos, uint32_t cursor_pos,
uint32_t anchor_pos, uint32_t anchor_pos,
uint32_t offset_pos) override; uint32_t offset_pos) override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override; void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
void HideInputView() override; void PropertyActivate(const std::string& property_name) override;
void CandidateClicked(uint32_t index) override;
void SetMirroringEnabled(bool mirroring_enabled) override; void SetMirroringEnabled(bool mirroring_enabled) override;
void SetCastingEnabled(bool casting_enabled) override; void SetCastingEnabled(bool casting_enabled) override;
const std::string& GetActiveComponentId() const;
std::string last_activated_property() const { std::string last_activated_property() const {
return last_activated_property_; return last_activated_property_;
} }
......
...@@ -48,6 +48,91 @@ InputMethodEngine::~InputMethodEngine() { ...@@ -48,6 +48,91 @@ InputMethodEngine::~InputMethodEngine() {
CloseImeWindows(); CloseImeWindows();
} }
void InputMethodEngine::FocusOut() {
InputMethodEngineBase::FocusOut();
if (follow_cursor_window_)
follow_cursor_window_->Hide();
}
void InputMethodEngine::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {
InputMethodEngineBase::SetCompositionBounds(bounds);
if (!bounds.empty()) {
current_cursor_bounds_ = bounds[0];
if (follow_cursor_window_)
follow_cursor_window_->FollowCursor(current_cursor_bounds_);
}
}
void InputMethodEngine::UpdateComposition(
const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool is_visible) {
composition_ = composition_text;
// Use a thin underline with text color by default.
if (composition_.ime_text_spans.empty()) {
composition_.ime_text_spans.push_back(ui::ImeTextSpan(
ui::ImeTextSpan::Type::kComposition, 0, composition_.text.length(),
ui::ImeTextSpan::Thickness::kThin, SK_ColorTRANSPARENT));
}
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
// If the IME extension is handling key event, hold the composition text
// until the key event is handled.
if (input_context && !handling_key_event_) {
input_context->UpdateCompositionText(composition_, cursor_pos, is_visible);
composition_ = ui::CompositionText();
} else {
composition_changed_ = true;
}
}
void InputMethodEngine::CommitTextToInputContext(int context_id,
const std::string& text) {
// Append the text to the buffer, as it allows committing text multiple times
// when processing a key event.
text_ += text;
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
// If the IME extension is handling key event, hold the text until the key
// event is handled.
if (input_context && !handling_key_event_) {
input_context->CommitText(text_);
text_ = "";
} else {
commit_text_changed_ = true;
}
}
bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event,
const std::string& code) {
DCHECK(event);
// input.ime.sendKeyEvents API is only allowed to work on text fields.
if (current_input_type_ == ui::TEXT_INPUT_TYPE_NONE)
return false;
if (event->key_code() == ui::VKEY_UNKNOWN)
event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code()));
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (!input_context)
return false;
// ENTER et al. keys are allowed to work only on http:, https: etc.
if (!IsValidKeyForAllPages(event)) {
if (IsSpecialPage(input_context->GetInputMethod()))
return false;
}
input_context->SendKeyEvent(event);
return true;
}
bool InputMethodEngine::IsActive() const { bool InputMethodEngine::IsActive() const {
return true; return true;
} }
...@@ -115,65 +200,6 @@ void InputMethodEngine::CloseImeWindows() { ...@@ -115,65 +200,6 @@ void InputMethodEngine::CloseImeWindows() {
normal_windows_.clear(); normal_windows_.clear();
} }
void InputMethodEngine::FocusOut() {
InputMethodEngineBase::FocusOut();
if (follow_cursor_window_)
follow_cursor_window_->Hide();
}
void InputMethodEngine::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {
InputMethodEngineBase::SetCompositionBounds(bounds);
if (!bounds.empty()) {
current_cursor_bounds_ = bounds[0];
if (follow_cursor_window_)
follow_cursor_window_->FollowCursor(current_cursor_bounds_);
}
}
void InputMethodEngine::UpdateComposition(
const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool is_visible) {
composition_ = composition_text;
// Use a thin underline with text color by default.
if (composition_.ime_text_spans.empty()) {
composition_.ime_text_spans.push_back(ui::ImeTextSpan(
ui::ImeTextSpan::Type::kComposition, 0, composition_.text.length(),
ui::ImeTextSpan::Thickness::kThin, SK_ColorTRANSPARENT));
}
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
// If the IME extension is handling key event, hold the composition text
// until the key event is handled.
if (input_context && !handling_key_event_) {
input_context->UpdateCompositionText(composition_, cursor_pos, is_visible);
composition_ = ui::CompositionText();
} else {
composition_changed_ = true;
}
}
void InputMethodEngine::CommitTextToInputContext(int context_id,
const std::string& text) {
// Append the text to the buffer, as it allows committing text multiple times
// when processing a key event.
text_ += text;
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
// If the IME extension is handling key event, hold the text until the key
// event is handled.
if (input_context && !handling_key_event_) {
input_context->CommitText(text_);
text_ = "";
} else {
commit_text_changed_ = true;
}
}
void InputMethodEngine::OnWindowDestroyed(ui::ImeWindow* ime_window) { void InputMethodEngine::OnWindowDestroyed(ui::ImeWindow* ime_window) {
if (ime_window == follow_cursor_window_) { if (ime_window == follow_cursor_window_) {
follow_cursor_window_ = nullptr; follow_cursor_window_ = nullptr;
...@@ -197,32 +223,6 @@ ui::ImeWindow* InputMethodEngine::FindWindowById(int window_id) const { ...@@ -197,32 +223,6 @@ ui::ImeWindow* InputMethodEngine::FindWindowById(int window_id) const {
return nullptr; return nullptr;
} }
bool InputMethodEngine::SendKeyEvent(ui::KeyEvent* event,
const std::string& code) {
DCHECK(event);
// input.ime.sendKeyEvents API is only allowed to work on text fields.
if (current_input_type_ == ui::TEXT_INPUT_TYPE_NONE)
return false;
if (event->key_code() == ui::VKEY_UNKNOWN)
event->set_key_code(ui::DomCodeToUsLayoutKeyboardCode(event->code()));
ui::IMEInputContextHandlerInterface* input_context =
ui::IMEBridge::Get()->GetInputContextHandler();
if (!input_context)
return false;
// ENTER et al. keys are allowed to work only on http:, https: etc.
if (!IsValidKeyForAllPages(event)) {
if (IsSpecialPage(input_context->GetInputMethod()))
return false;
}
input_context->SendKeyEvent(event);
return true;
}
bool InputMethodEngine::IsSpecialPage(ui::InputMethod* input_method) { bool InputMethodEngine::IsSpecialPage(ui::InputMethod* input_method) {
Browser* browser = chrome::FindLastActive(); Browser* browser = chrome::FindLastActive();
DCHECK(browser); DCHECK(browser);
......
...@@ -25,9 +25,18 @@ class InputMethodEngine : public InputMethodEngineBase, ...@@ -25,9 +25,18 @@ class InputMethodEngine : public InputMethodEngineBase,
~InputMethodEngine() override; ~InputMethodEngine() override;
// ui::IMEEngineHandlerInterface: // input_method::InputMethodEngineBase overrides:
void FocusOut() override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
void UpdateComposition(const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool is_visible) override;
void CommitTextToInputContext(int context_id,
const std::string& text) override;
bool SendKeyEvent(ui::KeyEvent* ui_event, const std::string& code) override;
bool IsActive() const override; bool IsActive() const override;
std::string GetExtensionId() const override;
std::string GetExtensionId() const;
// Creates and shows the IME window. // Creates and shows the IME window.
// Returns 0 for errors and |error| will contains the error message. // Returns 0 for errors and |error| will contains the error message.
...@@ -41,16 +50,6 @@ class InputMethodEngine : public InputMethodEngineBase, ...@@ -41,16 +50,6 @@ class InputMethodEngine : public InputMethodEngineBase,
void HideImeWindow(int window_id); void HideImeWindow(int window_id);
void CloseImeWindows(); void CloseImeWindows();
// input_method::InputMethodEngineBase:
void FocusOut() override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
void UpdateComposition(const ui::CompositionText& composition_text,
uint32_t cursor_pos,
bool is_visible) override;
void CommitTextToInputContext(int context_id,
const std::string& text) override;
bool SendKeyEvent(ui::KeyEvent* ui_event, const std::string& code) override;
private: private:
// ui::ImeWindowObserver: // ui::ImeWindowObserver:
void OnWindowDestroyed(ui::ImeWindow* ime_window) override; void OnWindowDestroyed(ui::ImeWindow* ime_window) override;
......
...@@ -149,17 +149,29 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { ...@@ -149,17 +149,29 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface {
uint32_t anchor_pos, uint32_t anchor_pos,
uint32_t offset_pos) override; uint32_t offset_pos) override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override; void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
bool ClearComposition(int context_id, std::string* error) override; bool IsInterestedInKeyEvent() const override;
bool CommitText(int context_id,
const char* text, // Returns the current active input_component id.
std::string* error) override; const std::string& GetActiveComponentId() const;
const std::string& GetActiveComponentId() const override;
// Clear the current composition.
bool ClearComposition(int context_id, std::string* error);
// Commit the specified text to the specified context. Fails if the context
// is not focused.
bool CommitText(int context_id, const char* text, std::string* error);
// 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.
bool DeleteSurroundingText(int context_id, bool DeleteSurroundingText(int context_id,
int offset, int offset,
size_t number_of_chars, size_t number_of_chars,
std::string* error) override; std::string* error);
int GetCotextIdForTesting() { return context_id_; }
bool IsInterestedInKeyEvent() const override;
// Send the sequence of key events. // Send the sequence of key events.
bool SendKeyEvents(int context_id, const std::vector<KeyboardEvent>& events); bool SendKeyEvents(int context_id, const std::vector<KeyboardEvent>& events);
...@@ -182,12 +194,17 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface { ...@@ -182,12 +194,17 @@ class InputMethodEngineBase : virtual public ui::IMEEngineHandlerInterface {
const std::string& component_id, const std::string& component_id,
ui::IMEEngineHandlerInterface::KeyEventDoneCallback key_data); ui::IMEEngineHandlerInterface::KeyEventDoneCallback key_data);
int GetContextIdForTesting() const { return context_id_; }
// Get the composition bounds. // Get the composition bounds.
const std::vector<gfx::Rect>& composition_bounds() const { const std::vector<gfx::Rect>& composition_bounds() const {
return composition_bounds_; return composition_bounds_;
} }
protected: protected:
// Returns true if this IME is active, false if not.
virtual bool IsActive() const = 0;
// Notifies InputContextHandler that the composition is changed. // Notifies InputContextHandler that the composition is changed.
virtual void UpdateComposition(const ui::CompositionText& composition_text, virtual void UpdateComposition(const ui::CompositionText& composition_text,
uint32_t cursor_pos, uint32_t cursor_pos,
......
...@@ -42,10 +42,6 @@ void MockIMEEngineHandler::Enable(const std::string& component_id) { ...@@ -42,10 +42,6 @@ void MockIMEEngineHandler::Enable(const std::string& component_id) {
void MockIMEEngineHandler::Disable() { void MockIMEEngineHandler::Disable() {
} }
void MockIMEEngineHandler::PropertyActivate(const std::string& property_name) {
last_activated_property_ = property_name;
}
void MockIMEEngineHandler::Reset() { void MockIMEEngineHandler::Reset() {
++reset_call_count_; ++reset_call_count_;
} }
...@@ -61,6 +57,13 @@ void MockIMEEngineHandler::ProcessKeyEvent(const ui::KeyEvent& key_event, ...@@ -61,6 +57,13 @@ void MockIMEEngineHandler::ProcessKeyEvent(const ui::KeyEvent& key_event,
last_passed_callback_ = std::move(callback); last_passed_callback_ = std::move(callback);
} }
void MockIMEEngineHandler::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {}
void MockIMEEngineHandler::PropertyActivate(const std::string& property_name) {
last_activated_property_ = property_name;
}
void MockIMEEngineHandler::CandidateClicked(uint32_t index) {} void MockIMEEngineHandler::CandidateClicked(uint32_t index) {}
void MockIMEEngineHandler::SetSurroundingText(const std::string& text, void MockIMEEngineHandler::SetSurroundingText(const std::string& text,
...@@ -73,49 +76,12 @@ void MockIMEEngineHandler::SetSurroundingText(const std::string& text, ...@@ -73,49 +76,12 @@ void MockIMEEngineHandler::SetSurroundingText(const std::string& text,
last_set_surrounding_anchor_pos_ = anchor_pos; last_set_surrounding_anchor_pos_ = anchor_pos;
} }
void MockIMEEngineHandler::SetCompositionBounds(
const std::vector<gfx::Rect>& bounds) {
}
void MockIMEEngineHandler::SetMirroringEnabled(bool mirroring_enabled) {} void MockIMEEngineHandler::SetMirroringEnabled(bool mirroring_enabled) {}
void MockIMEEngineHandler::SetCastingEnabled(bool casting_enabled) {} void MockIMEEngineHandler::SetCastingEnabled(bool casting_enabled) {}
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::IsActive() const {
return false;
}
const std::string& MockIMEEngineHandler::GetActiveComponentId() const { const std::string& MockIMEEngineHandler::GetActiveComponentId() const {
return active_component_id_; return active_component_id_;
} }
bool MockIMEEngineHandler::DeleteSurroundingText(int context_id,
int offset,
size_t number_of_chars,
std::string* error) {
return false;
}
bool MockIMEEngineHandler::SetCandidateWindowVisible(bool visible,
std::string* error) {
return false;
}
bool MockIMEEngineHandler::SetCursorPosition(int context_id,
int candidate_id,
std::string* error) {
return false;
}
} // namespace chromeos } // namespace chromeos
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <vector>
#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/ime_engine_handler_interface.h"
#include "ui/base/ime/ui_base_ime_export.h" #include "ui/base/ime/ui_base_ime_export.h"
...@@ -24,20 +25,22 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler ...@@ -24,20 +25,22 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler
void FocusOut() override; void FocusOut() override;
void Enable(const std::string& component_id) override; void Enable(const std::string& component_id) override;
void Disable() override; void Disable() override;
void PropertyActivate(const std::string& property_name) override;
void Reset() override; void Reset() override;
bool IsInterestedInKeyEvent() const override; bool IsInterestedInKeyEvent() const override;
void ProcessKeyEvent(const ui::KeyEvent& key_event, void ProcessKeyEvent(const ui::KeyEvent& key_event,
KeyEventDoneCallback callback) override; KeyEventDoneCallback callback) override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
void PropertyActivate(const std::string& property_name) override;
void CandidateClicked(uint32_t index) override; void CandidateClicked(uint32_t index) override;
void SetSurroundingText(const std::string& text, void SetSurroundingText(const std::string& text,
uint32_t cursor_pos, uint32_t cursor_pos,
uint32_t anchor_pos, uint32_t anchor_pos,
uint32_t offset_pos) override; uint32_t offset_pos) override;
void SetCompositionBounds(const std::vector<gfx::Rect>& bounds) override;
void SetMirroringEnabled(bool mirroring_enabled) override; void SetMirroringEnabled(bool mirroring_enabled) override;
void SetCastingEnabled(bool casting_enabled) override; void SetCastingEnabled(bool casting_enabled) override;
const std::string& GetActiveComponentId() const;
int focus_in_call_count() const { return focus_in_call_count_; } int focus_in_call_count() const { return focus_in_call_count_; }
int focus_out_call_count() const { return focus_out_call_count_; } int focus_out_call_count() const { return focus_out_call_count_; }
int reset_call_count() const { return reset_call_count_; } int reset_call_count() const { return reset_call_count_; }
...@@ -76,29 +79,6 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler ...@@ -76,29 +79,6 @@ class UI_BASE_IME_EXPORT MockIMEEngineHandler
return std::move(last_passed_callback_); return std::move(last_passed_callback_);
} }
bool ClearComposition(int context_id, std::string* error) override;
bool CommitText(int context_id,
const char* text,
std::string* error) 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;
bool SetCandidateWindowVisible(bool visible, std::string* error) override;
bool SetCursorPosition(int context_id,
int candidate_id,
std::string* error) override;
void HideInputView() override {}
private: private:
int focus_in_call_count_; int focus_in_call_count_;
int focus_out_call_count_; int focus_out_call_count_;
......
...@@ -117,32 +117,6 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface { ...@@ -117,32 +117,6 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
// If not, InputMethodChromeOS won't feed it with key events. // If not, InputMethodChromeOS won't feed it with key events.
virtual bool IsInterestedInKeyEvent() const = 0; virtual bool IsInterestedInKeyEvent() const = 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;
// 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;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Called when a property is activated or changed. // Called when a property is activated or changed.
...@@ -152,24 +126,10 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface { ...@@ -152,24 +126,10 @@ class UI_BASE_IME_EXPORT IMEEngineHandlerInterface {
// based candidate index in lookup table. // based candidate index in lookup table.
virtual void CandidateClicked(uint32_t index) = 0; virtual void CandidateClicked(uint32_t index) = 0;
// Show or hide the candidate window.
virtual bool SetCandidateWindowVisible(bool visible, 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;
// Hides the input view window (from API call).
virtual void HideInputView() = 0;
// Sets the mirroring/casting enable states. // Sets the mirroring/casting enable states.
virtual void SetMirroringEnabled(bool mirroring_enabled) = 0; virtual void SetMirroringEnabled(bool mirroring_enabled) = 0;
virtual void SetCastingEnabled(bool casting_enabled) = 0; virtual void SetCastingEnabled(bool casting_enabled) = 0;
#elif defined(OS_LINUX) || defined(OS_WIN)
// Get the id of the IME extension.
virtual std::string GetExtensionId() const = 0;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
protected: protected:
IMEEngineHandlerInterface() {} IMEEngineHandlerInterface() {}
......
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