diff options
author | komatsu@chromium.org <komatsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 07:48:51 +0000 |
---|---|---|
committer | komatsu@chromium.org <komatsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-18 07:48:51 +0000 |
commit | aaab1b2e687581eba5bef560a23dbe134c308cf2 (patch) | |
tree | 3c3ff9b18cd48d8fe131d5470df7f986a99d2457 | |
parent | 912fac9057ff2db03a8a3928ea1c285c6724022a (diff) | |
download | chromium_src-aaab1b2e687581eba5bef560a23dbe134c308cf2.zip chromium_src-aaab1b2e687581eba5bef560a23dbe134c308cf2.tar.gz chromium_src-aaab1b2e687581eba5bef560a23dbe134c308cf2.tar.bz2 |
Delete IBusEngineService.
This patch focuses on the deletion of IBusEngineService keeping the logic as-is.
BUG=275262
Review URL: https://codereview.chromium.org/70053003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235648 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/input_method/input_method_engine_ibus.cc | 71 | ||||
-rw-r--r-- | chrome/browser/chromeos/input_method/input_method_engine_ibus.h | 11 | ||||
-rw-r--r-- | chromeos/chromeos.gyp | 4 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_engine_service.cc | 90 | ||||
-rw-r--r-- | chromeos/dbus/ibus/ibus_engine_service.h | 73 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_engine_service.cc | 79 | ||||
-rw-r--r-- | chromeos/dbus/ibus/mock_ibus_engine_service.h | 94 |
7 files changed, 34 insertions, 388 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc b/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc index f617855..c7046bc 100644 --- a/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc +++ b/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc @@ -8,13 +8,13 @@ #include <X11/keysymdef.h> #include <map> +#include "base/bind.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/ibus/ibus_engine_service.h" #include "chromeos/dbus/ibus/ibus_text.h" #include "chromeos/ime/candidate_window.h" #include "chromeos/ime/component_extension_ime_manager.h" @@ -35,14 +35,33 @@ const uint32 kIBusCtrlKeyMask = 1 << 2; const uint32 kIBusShiftKeyMask = 1 << 0; const uint32 kIBusCapsLockMask = 1 << 1; const uint32 kIBusKeyReleaseMask = 1 << 30; + +// Notifies InputContextHandler that the preedit is changed. +void UpdatePreedit(const IBusText& ibus_text, + uint32 cursor_pos, + bool is_visible) { + IBusInputContextHandlerInterface* input_context = + IBusBridge::Get()->GetInputContextHandler(); + if (input_context) + input_context->UpdatePreeditText(ibus_text, cursor_pos, is_visible); +} + +// Notifies CandidateWindowHandler that the auxilary text is changed. +// Auxilary text is usually footer text. +void UpdateAuxiliaryText(const IBusText& ibus_text, bool is_visible) { + IBusPanelCandidateWindowHandlerInterface* candidate_window = + IBusBridge::Get()->GetCandidateWindowHandler(); + if (candidate_window) + candidate_window->UpdateAuxiliaryText(ibus_text.text(), is_visible); } +} // namespace + InputMethodEngineIBus::InputMethodEngineIBus() : focused_(false), active_(false), context_id_(0), next_context_id_(1), - is_create_engine_handler_called_(false), aux_text_(new IBusText()), aux_text_visible_(false), observer_(NULL), @@ -57,10 +76,8 @@ InputMethodEngineIBus::~InputMethodEngineIBus() { // Do not unset engine before removing input method extension, above // function may call reset function of engine object. - if (is_create_engine_handler_called_) { - GetCurrentService()->UnsetEngine(this); - ibus_engine_service_.reset(); - } + if (IBusBridge::Get()->GetEngineHandler() == this) + IBusBridge::Get()->SetEngineHandler(NULL); } void InputMethodEngineIBus::Initialize( @@ -152,11 +169,7 @@ bool InputMethodEngineIBus::SetComposition( } // TODO(nona): Makes focus out mode configuable, if necessary. - GetCurrentService()->UpdatePreedit( - *preedit_text_.get(), - preedit_cursor_, - true, - IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT); + UpdatePreedit(*preedit_text_, preedit_cursor_, true); return true; } @@ -173,11 +186,7 @@ bool InputMethodEngineIBus::ClearComposition(int context_id, preedit_cursor_ = 0; preedit_text_.reset(new IBusText()); - GetCurrentService()->UpdatePreedit( - *preedit_text_.get(), - 0, - false, - IBusEngineService::IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT); + UpdatePreedit(*preedit_text_, preedit_cursor_, false); return true; } @@ -244,9 +253,7 @@ void InputMethodEngineIBus::SetCandidateWindowAuxText(const char* text) { aux_text_->set_text(text); if (active_) { // Should not show auxiliary text if the whole window visibility is false. - GetCurrentService()->UpdateAuxiliaryText( - *aux_text_.get(), - window_visible_ && aux_text_visible_); + UpdateAuxiliaryText(*aux_text_, window_visible_ && aux_text_visible_); } } @@ -254,9 +261,7 @@ void InputMethodEngineIBus::SetCandidateWindowAuxTextVisible(bool visible) { aux_text_visible_ = visible; if (active_) { // Should not show auxiliary text if the whole window visibility is false. - GetCurrentService()->UpdateAuxiliaryText( - *aux_text_.get(), - window_visible_ && aux_text_visible_); + UpdateAuxiliaryText(*aux_text_, window_visible_ && aux_text_visible_); } } @@ -381,7 +386,12 @@ bool InputMethodEngineIBus::DeleteSurroundingText(int context_id, return false; // Currently we can only support preceding text. // TODO(nona): Return false if there is ongoing composition. - GetCurrentService()->DeleteSurroundingText(offset, number_of_chars); + + IBusInputContextHandlerInterface* input_context = + IBusBridge::Get()->GetInputContextHandler(); + if (input_context) + input_context->DeleteSurroundingText(offset, number_of_chars); + return true; } @@ -431,10 +441,6 @@ void InputMethodEngineIBus::Enable() { active_ = true; observer_->OnActivate(engine_id_); FocusIn(ibus::TEXT_INPUT_TYPE_TEXT); - - // Calls RequireSurroundingText once here to notify ibus-daemon to send - // surrounding text to this engine. - GetCurrentService()->RequireSurroundingText(); } void InputMethodEngineIBus::Disable() { @@ -522,12 +528,6 @@ void InputMethodEngineIBus::SetSurroundingText(const std::string& text, static_cast<int>(anchor_pos)); } -IBusEngineService* InputMethodEngineIBus::GetCurrentService() { - if (!ibus_engine_service_) - ibus_engine_service_.reset(IBusEngineService::Create()); - return ibus_engine_service_.get(); -} - void InputMethodEngineIBus::MenuItemToProperty( const MenuItem& item, input_method::InputMethodProperty* property) { @@ -584,10 +584,7 @@ void InputMethodEngineIBus::RegisterComponent() { } void InputMethodEngineIBus::CreateEngineHandler() { - GetCurrentService()->UnsetEngine(this); - ibus_engine_service_.reset(); - GetCurrentService()->SetEngine(this); - is_create_engine_handler_called_ = true; + IBusBridge::Get()->SetEngineHandler(this); } } // namespace chromeos diff --git a/chrome/browser/chromeos/input_method/input_method_engine_ibus.h b/chrome/browser/chromeos/input_method/input_method_engine_ibus.h index d7a4a31..bd9c81b 100644 --- a/chrome/browser/chromeos/input_method/input_method_engine_ibus.h +++ b/chrome/browser/chromeos/input_method/input_method_engine_ibus.h @@ -17,8 +17,6 @@ namespace chromeos { class IBusText; -class IBusEngineService; - namespace input_method { class CandidateWindow; struct KeyEventHandle; @@ -113,10 +111,6 @@ class InputMethodEngineIBus : public InputMethodEngine, // corresponding engine id. void CreateEngineHandler(); - // Returns current IBusEngineService, if there is no available service, this - // function returns NULL. - IBusEngineService* GetCurrentService(); - // True if the current context has focus. bool focused_; @@ -135,9 +129,6 @@ class InputMethodEngineIBus : public InputMethodEngine, // This IME ID in ibus. std::string ibus_id_; - // Flag whether CreateEngineHandler is called or not. - bool is_create_engine_handler_called_; - // The current auxialy text and it's visiblity. scoped_ptr<IBusText> aux_text_; bool aux_text_visible_; @@ -164,8 +155,6 @@ class InputMethodEngineIBus : public InputMethodEngine, // Mapping of candidate id to index. std::map<int, int> candidate_indexes_; - scoped_ptr<IBusEngineService> ibus_engine_service_; - // Used for making callbacks. base::WeakPtrFactory<InputMethodEngineIBus> weak_ptr_factory_; }; diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index ea679d2..3e6f8e2 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -170,8 +170,6 @@ 'dbus/shill_stub_helper.cc', 'dbus/shill_stub_helper.h', 'dbus/ibus/ibus_constants.h', - 'dbus/ibus/ibus_engine_service.cc', - 'dbus/ibus/ibus_engine_service.h', 'dbus/ibus/ibus_object.cc', 'dbus/ibus/ibus_object.h', 'dbus/ibus/ibus_text.cc', @@ -433,8 +431,6 @@ 'dbus/fake_shill_manager_client.h', 'dbus/fake_update_engine_client.cc', 'dbus/fake_update_engine_client.h', - 'dbus/ibus/mock_ibus_engine_service.cc', - 'dbus/ibus/mock_ibus_engine_service.h', 'ime/fake_input_method_delegate.cc', 'ime/fake_input_method_delegate.h', 'ime/mock_ibus_daemon_controller.cc', diff --git a/chromeos/dbus/ibus/ibus_engine_service.cc b/chromeos/dbus/ibus/ibus_engine_service.cc deleted file mode 100644 index 596fb8d..0000000 --- a/chromeos/dbus/ibus/ibus_engine_service.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2012 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 "chromeos/dbus/ibus/ibus_engine_service.h" - -#include <string> -#include "base/bind.h" -#include "base/callback.h" -#include "chromeos/dbus/ibus/ibus_constants.h" -#include "chromeos/dbus/ibus/ibus_text.h" -#include "chromeos/ime/ibus_bridge.h" - -namespace chromeos { -// An implementation of IBusEngineService without ibus-daemon interaction. -// Currently this class is used only on linux desktop. -// TODO(nona): Use this on ChromeOS device once crbug.com/171351 is fixed. -class IBusEngineServiceDaemonlessImpl : public IBusEngineService { - public: - IBusEngineServiceDaemonlessImpl() {} - virtual ~IBusEngineServiceDaemonlessImpl() {} - - // IBusEngineService override. - virtual void SetEngine(IBusEngineHandlerInterface* handler) OVERRIDE { - IBusBridge::Get()->SetEngineHandler(handler); - } - - // IBusEngineService override. - virtual void UnsetEngine(IBusEngineHandlerInterface* handler) OVERRIDE { - if (IBusBridge::Get()->GetEngineHandler() == handler) - IBusBridge::Get()->SetEngineHandler(NULL); - } - - // IBusEngineService override. - virtual void UpdatePreedit(const IBusText& ibus_text, - uint32 cursor_pos, - bool is_visible, - IBusEnginePreeditFocusOutMode mode) OVERRIDE { - IBusInputContextHandlerInterface* input_context = - IBusBridge::Get()->GetInputContextHandler(); - if (input_context) - input_context->UpdatePreeditText(ibus_text, cursor_pos, is_visible); - } - - // IBusEngineService override. - virtual void UpdateAuxiliaryText(const IBusText& ibus_text, - bool is_visible) OVERRIDE { - IBusPanelCandidateWindowHandlerInterface* candidate_window = - IBusBridge::Get()->GetCandidateWindowHandler(); - if (candidate_window) - candidate_window->UpdateAuxiliaryText(ibus_text.text(), is_visible); - } - - // IBusEngineService override. - virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode, - uint32 state) OVERRIDE { - IBusInputContextHandlerInterface* input_context = - IBusBridge::Get()->GetInputContextHandler(); - if (input_context) - input_context->ForwardKeyEvent(keyval, keycode, state); - } - - // IBusEngineService override. - virtual void RequireSurroundingText() OVERRIDE { - // Do nothing. - } - - // IBusEngineService override. - virtual void DeleteSurroundingText(int32 offset, uint32 length) OVERRIDE { - IBusInputContextHandlerInterface* input_context = - IBusBridge::Get()->GetInputContextHandler(); - if (input_context) - input_context->DeleteSurroundingText(offset, length); - } - private: - DISALLOW_COPY_AND_ASSIGN(IBusEngineServiceDaemonlessImpl); -}; - -IBusEngineService::IBusEngineService() { -} - -IBusEngineService::~IBusEngineService() { -} - -// static -IBusEngineService* IBusEngineService::Create() { - return new IBusEngineServiceDaemonlessImpl(); -} - -} // namespace chromeos diff --git a/chromeos/dbus/ibus/ibus_engine_service.h b/chromeos/dbus/ibus/ibus_engine_service.h deleted file mode 100644 index 1b2dab9..0000000 --- a/chromeos/dbus/ibus/ibus_engine_service.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2012 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 CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_ -#define CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_ - -#include <string> -#include "base/bind.h" -#include "base/callback.h" -#include "base/memory/scoped_vector.h" -#include "chromeos/chromeos_export.h" -#include "chromeos/dbus/dbus_client_implementation_type.h" -#include "chromeos/dbus/ibus/ibus_constants.h" - -namespace chromeos { - -class IBusText; -class IBusEngineHandlerInterface; - -// A class to make the actual DBus method call handling for IBusEngine service. -// The exported method call is used by ibus-demon to process key event, because -// Chrome works engine service if the extension IME is enabled. This class is -// managed by DBusThreadManager. -class CHROMEOS_EXPORT IBusEngineService { - public: - // Following value should be same in - // http://ibus.googlecode.com/svn/docs/ibus-1.4/ibus-ibustypes.html#IBusPreeditFocusMode - enum IBusEnginePreeditFocusOutMode { - IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_CLEAR = 0, - IBUS_ENGINE_PREEEDIT_FOCUS_OUT_MODE_COMMIT = 1, - }; - - virtual ~IBusEngineService(); - - // Sets a new IBus engine handler and old handler will be overridden. - // This class doesn't take the ownership of |handler|. - virtual void SetEngine(IBusEngineHandlerInterface* handler) = 0; - - // Unsets the IBus engine handler if |handler| equals to current engine - // handler. - virtual void UnsetEngine(IBusEngineHandlerInterface* handler) = 0; - - // Emits UpdatePreedit signal. - virtual void UpdatePreedit(const IBusText& ibus_text, - uint32 cursor_pos, - bool is_visible, - IBusEnginePreeditFocusOutMode mode) = 0; - // Emits UpdateAuxiliaryText signal. - virtual void UpdateAuxiliaryText(const IBusText& ibus_text, - bool is_visible) = 0; - // Emits ForwardKeyEvent signal. - virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode, uint32 state) = 0; - // Emits RequireSurroundingText signal. - virtual void RequireSurroundingText() = 0; - // Emits DeleteSurroundingText signal. - virtual void DeleteSurroundingText(int32 offset, uint32 length) = 0; - - // Factory function, creates a new instance and returns ownership. - // For normal usage, access the singleton via DBusThreadManager::Get(). - static CHROMEOS_EXPORT IBusEngineService* Create(); - - protected: - // Create() should be used instead. - IBusEngineService(); - - private: - DISALLOW_COPY_AND_ASSIGN(IBusEngineService); -}; - -} // namespace chromeos - -#endif // CHROMEOS_DBUS_IBUS_IBUS_ENGINE_SERVICE_H_ diff --git a/chromeos/dbus/ibus/mock_ibus_engine_service.cc b/chromeos/dbus/ibus/mock_ibus_engine_service.cc deleted file mode 100644 index 4c93662..0000000 --- a/chromeos/dbus/ibus/mock_ibus_engine_service.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2012 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 "chromeos/dbus/ibus/mock_ibus_engine_service.h" - -#include "chromeos/dbus/ibus/ibus_text.h" - -namespace chromeos { - -MockIBusEngineService::MockIBusEngineService() - : update_preedit_call_count_(0), - update_auxiliary_text_call_count_(0), - forward_key_event_call_count_(0), - delete_surrounding_text_call_count_(0), - last_update_preedit_arg_(new UpdatePreeditArg()), - last_update_aux_text_arg_(new UpdateAuxiliaryTextArg()), - last_delete_surrounding_text_arg_(new DeleteSurroundingTextArg()), - current_engine_(NULL) { -} - -MockIBusEngineService::~MockIBusEngineService() { -} - -void MockIBusEngineService::SetEngine(IBusEngineHandlerInterface* handler) { - current_engine_ = handler; -} - -void MockIBusEngineService::UnsetEngine(IBusEngineHandlerInterface* handler) { - current_engine_ = NULL; -} - -void MockIBusEngineService::UpdatePreedit(const IBusText& ibus_text, - uint32 cursor_pos, - bool is_visible, - IBusEnginePreeditFocusOutMode mode) { - ++update_preedit_call_count_; - last_update_preedit_arg_->ibus_text.CopyFrom(ibus_text); - last_update_preedit_arg_->cursor_pos = cursor_pos; - last_update_preedit_arg_->is_visible = is_visible; -} - -void MockIBusEngineService::UpdateAuxiliaryText(const IBusText& ibus_text, - bool is_visible) { - ++update_auxiliary_text_call_count_; - last_update_aux_text_arg_->ibus_text.CopyFrom(ibus_text); - last_update_aux_text_arg_->is_visible = is_visible; -} - -void MockIBusEngineService::ForwardKeyEvent(uint32 keyval, - uint32 keycode, - uint32 state) { - ++forward_key_event_call_count_; -} - -void MockIBusEngineService::RequireSurroundingText() { -} - -void MockIBusEngineService::DeleteSurroundingText(int32 offset,uint32 length) { - ++delete_surrounding_text_call_count_; - last_delete_surrounding_text_arg_->offset = offset; - last_delete_surrounding_text_arg_->length = length; -} - -IBusEngineHandlerInterface* MockIBusEngineService::GetEngine() const { - return current_engine_; -} - -void MockIBusEngineService::Clear() { - update_preedit_call_count_ = 0; - update_auxiliary_text_call_count_ = 0; - forward_key_event_call_count_ = 0; - delete_surrounding_text_call_count_ = 0; - last_update_preedit_arg_.reset(new UpdatePreeditArg()); - last_update_aux_text_arg_.reset(new UpdateAuxiliaryTextArg()); - last_delete_surrounding_text_arg_.reset(new DeleteSurroundingTextArg()); -} - -} // namespace chromeos diff --git a/chromeos/dbus/ibus/mock_ibus_engine_service.h b/chromeos/dbus/ibus/mock_ibus_engine_service.h deleted file mode 100644 index 5d33246c..0000000 --- a/chromeos/dbus/ibus/mock_ibus_engine_service.h +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2012 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 CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_ -#define CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_ - -#include <string> -#include "chromeos/dbus/ibus/ibus_engine_service.h" -#include "chromeos/dbus/ibus/ibus_text.h" - -namespace chromeos { - -class IBusText; - -class MockIBusEngineService : public IBusEngineService { - public: - - struct UpdatePreeditArg { - UpdatePreeditArg() : is_visible(false) {} - IBusText ibus_text; - uint32 cursor_pos; - bool is_visible; - }; - - struct UpdateAuxiliaryTextArg { - UpdateAuxiliaryTextArg() : is_visible(false) {} - IBusText ibus_text; - bool is_visible; - }; - - struct DeleteSurroundingTextArg { - int32 offset; - uint32 length; - }; - - MockIBusEngineService(); - virtual ~MockIBusEngineService(); - - // IBusEngineService overrides. - virtual void SetEngine(IBusEngineHandlerInterface* handler) OVERRIDE; - virtual void UnsetEngine(IBusEngineHandlerInterface* handler) OVERRIDE; - virtual void UpdatePreedit(const IBusText& ibus_text, - uint32 cursor_pos, - bool is_visible, - IBusEnginePreeditFocusOutMode mode) OVERRIDE; - virtual void UpdateAuxiliaryText(const IBusText& ibus_text, - bool is_visible) OVERRIDE; - virtual void ForwardKeyEvent(uint32 keyval, uint32 keycode, - uint32 state) OVERRIDE; - virtual void RequireSurroundingText() OVERRIDE; - virtual void DeleteSurroundingText(int32 offset, uint32 length) OVERRIDE; - - IBusEngineHandlerInterface* GetEngine() const; - - void Clear(); - - int update_preedit_call_count() const { return update_preedit_call_count_; } - const UpdatePreeditArg& last_update_preedit_arg() const { - return *last_update_preedit_arg_.get(); - } - - int update_auxiliary_text_call_count() const { - return update_auxiliary_text_call_count_; - } - const UpdateAuxiliaryTextArg& last_update_aux_text_arg() const { - return *last_update_aux_text_arg_.get(); - } - - int delete_surrounding_text_call_count() const { - return delete_surrounding_text_call_count_; - } - const DeleteSurroundingTextArg& last_delete_surrounding_text_arg() const { - return *last_delete_surrounding_text_arg_.get(); - } - - private: - int update_preedit_call_count_; - int update_auxiliary_text_call_count_; - int forward_key_event_call_count_; - int delete_surrounding_text_call_count_; - - scoped_ptr<UpdatePreeditArg> last_update_preedit_arg_; - scoped_ptr<UpdateAuxiliaryTextArg> last_update_aux_text_arg_; - scoped_ptr<DeleteSurroundingTextArg> last_delete_surrounding_text_arg_; - - IBusEngineHandlerInterface* current_engine_; - - DISALLOW_COPY_AND_ASSIGN(MockIBusEngineService); -}; - -} // namespace chromeos - -#endif // CHROMEOS_DBUS_IBUS_MOCK_IBUS_ENGINE_SERVICE_H_ |