summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 06:45:53 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-15 06:45:53 +0000
commitdc7b094a338c6c521f918f478e993f0f74bbea0d (patch)
tree14b873b4d90182e0a01dec280ae76b0d54e96235
parentc033c4d76336017a17a77ae6100941761ae64693 (diff)
downloadchromium_src-dc7b094a338c6c521f918f478e993f0f74bbea0d.zip
chromium_src-dc7b094a338c6c521f918f478e993f0f74bbea0d.tar.gz
chromium_src-dc7b094a338c6c521f918f478e993f0f74bbea0d.tar.bz2
Remove use of libcros from InputMethodLibrary.
BUG=chromium-os:16238 TEST==confirm that input methods work as before on the netbook. Also confirm that the chrome builds and works on the desktop as before. Review URL: http://codereview.chromium.org/7003086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89142 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.cc6
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.h10
-rw-r--r--chrome/browser/chromeos/cros/input_method_library.cc377
-rw-r--r--chrome/browser/chromeos/cros/input_method_library.h34
-rw-r--r--chrome/browser/chromeos/cros/mock_input_method_library.h20
-rw-r--r--chrome/browser/chromeos/input_method/ibus_controller.cc532
-rw-r--r--chrome/browser/chromeos/input_method/ibus_controller.h248
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.cc58
-rw-r--r--chrome/browser/chromeos/input_method/input_method_util.h10
-rw-r--r--chrome/browser/chromeos/login/screen_locker.cc12
-rw-r--r--chrome/browser/chromeos/preferences.cc16
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.cc38
-rw-r--r--chrome/browser/chromeos/status/input_method_menu.h22
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_button.cc2
-rw-r--r--chrome/browser/chromeos/status/input_method_menu_unittest.cc2
-rw-r--r--chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc2
-rw-r--r--chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc31
-rw-r--r--chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h4
-rw-r--r--chrome/browser/ui/webui/options/language_options_handler_unittest.cc25
-rw-r--r--chrome/chrome_browser.gypi7
20 files changed, 728 insertions, 728 deletions
diff --git a/chrome/browser/chromeos/cros/cros_mock.cc b/chrome/browser/chromeos/cros/cros_mock.cc
index 694ffcda..73d9c5e 100644
--- a/chrome/browser/chromeos/cros/cros_mock.cc
+++ b/chrome/browser/chromeos/cros/cros_mock.cc
@@ -402,8 +402,10 @@ void CrosMock::TearDownMocks() {
test_api()->SetTouchpadLibrary(NULL, false);
}
-InputMethodDescriptors* CrosMock::CreateInputMethodDescriptors() {
- InputMethodDescriptors* descriptors = new InputMethodDescriptors;
+input_method::InputMethodDescriptors*
+CrosMock::CreateInputMethodDescriptors() {
+ input_method::InputMethodDescriptors* descriptors =
+ new input_method::InputMethodDescriptors;
descriptors->push_back(
input_method::GetFallbackInputMethodDescriptor());
return descriptors;
diff --git a/chrome/browser/chromeos/cros/cros_mock.h b/chrome/browser/chromeos/cros/cros_mock.h
index 96293b9..4cc2ecf 100644
--- a/chrome/browser/chromeos/cros/cros_mock.h
+++ b/chrome/browser/chromeos/cros/cros_mock.h
@@ -7,8 +7,8 @@
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/chromeos/input_method/ibus_controller.h"
#include "chrome/test/in_process_browser_test.h"
-#include "third_party/cros/chromeos_input_method.h"
namespace chromeos {
@@ -83,7 +83,7 @@ class CrosMock {
// Creates input method descriptors. This is a helper function for
// SetInputMethodLibraryStatusAreaExpectations().
- static InputMethodDescriptors* CreateInputMethodDescriptors();
+ static input_method::InputMethodDescriptors* CreateInputMethodDescriptors();
// TestApi gives access to CrosLibrary private members.
chromeos::CrosLibrary::TestApi* test_api();
@@ -100,9 +100,9 @@ class CrosMock {
MockSpeechSynthesisLibrary* mock_speech_synthesis_library_;
MockTouchpadLibrary* mock_touchpad_library_;
- ImePropertyList ime_properties_;
- InputMethodDescriptor current_input_method_;
- InputMethodDescriptor previous_input_method_;
+ input_method::ImePropertyList ime_properties_;
+ input_method::InputMethodDescriptor current_input_method_;
+ input_method::InputMethodDescriptor previous_input_method_;
WifiNetworkVector wifi_networks_;
CellularNetworkVector cellular_networks_;
VirtualNetworkVector virtual_networks_;
diff --git a/chrome/browser/chromeos/cros/input_method_library.cc b/chrome/browser/chromeos/cros/input_method_library.cc
index 58f8f47..1ba6253 100644
--- a/chrome/browser/chromeos/cros/input_method_library.cc
+++ b/chrome/browser/chromeos/cros/input_method_library.cc
@@ -35,10 +35,11 @@ const char kIBusDaemonPath[] = "/usr/bin/ibus-daemon";
// Finds a property which has |new_prop.key| from |prop_list|, and replaces the
// property with |new_prop|. Returns true if such a property is found.
-bool FindAndUpdateProperty(const chromeos::ImeProperty& new_prop,
- chromeos::ImePropertyList* prop_list) {
+bool FindAndUpdateProperty(
+ const chromeos::input_method::ImeProperty& new_prop,
+ chromeos::input_method::ImePropertyList* prop_list) {
for (size_t i = 0; i < prop_list->size(); ++i) {
- chromeos::ImeProperty& prop = prop_list->at(i);
+ chromeos::input_method::ImeProperty& prop = prop_list->at(i);
if (prop.key == new_prop.key) {
const int saved_id = prop.selection_item_id;
// Update the list except the radio id. As written in
@@ -57,10 +58,11 @@ namespace chromeos {
// The production implementation of InputMethodLibrary.
class InputMethodLibraryImpl : public InputMethodLibrary,
- public NotificationObserver {
+ public NotificationObserver,
+ public input_method::IBusController::Observer {
public:
InputMethodLibraryImpl()
- : input_method_status_connection_(NULL),
+ : ibus_controller_(NULL),
should_launch_ime_(false),
ime_connected_(false),
defer_ime_startup_(false),
@@ -93,44 +95,40 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
bool Init() {
DCHECK(!initialized_successfully_) << "Already initialized";
- if (!CrosLibrary::Get()->EnsureLoaded())
- return false;
- input_method_status_connection_ = chromeos::MonitorInputMethodStatus(
- this,
- &InputMethodChangedHandler,
- &RegisterPropertiesHandler,
- &UpdatePropertyHandler,
- &ConnectionChangeHandler);
- if (!input_method_status_connection_)
- return false;
+ ibus_controller_ = input_method::IBusController::Create();
+ // The observer should be added before Connect() so we can capture the
+ // initial connection change.
+ ibus_controller_->AddObserver(this);
+ ibus_controller_->Connect();
initialized_successfully_ = true;
return true;
}
virtual ~InputMethodLibraryImpl() {
+ ibus_controller_->RemoveObserver(this);
}
- virtual void AddObserver(Observer* observer) {
+ virtual void AddObserver(InputMethodLibrary::Observer* observer) {
if (!observers_.size()) {
observer->FirstObserverIsAdded(this);
}
observers_.AddObserver(observer);
}
- virtual void RemoveObserver(Observer* observer) {
+ virtual void RemoveObserver(InputMethodLibrary::Observer* observer) {
observers_.RemoveObserver(observer);
}
- virtual InputMethodDescriptors* GetActiveInputMethods() {
- chromeos::InputMethodDescriptors* result =
- new chromeos::InputMethodDescriptors;
+ virtual input_method::InputMethodDescriptors* GetActiveInputMethods() {
+ input_method::InputMethodDescriptors* result =
+ new input_method::InputMethodDescriptors;
// Build the active input method descriptors from the active input
// methods cache |active_input_method_ids_|.
for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
const std::string& input_method_id = active_input_method_ids_[i];
- const InputMethodDescriptor* descriptor =
- chromeos::input_method::GetInputMethodDescriptorFromId(
+ const input_method::InputMethodDescriptor* descriptor =
+ input_method::GetInputMethodDescriptorFromId(
input_method_id);
if (descriptor) {
result->push_back(*descriptor);
@@ -148,21 +146,23 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
}
virtual size_t GetNumActiveInputMethods() {
- scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods());
+ scoped_ptr<input_method::InputMethodDescriptors> input_methods(
+ GetActiveInputMethods());
return input_methods->size();
}
- virtual InputMethodDescriptors* GetSupportedInputMethods() {
+ virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() {
if (!initialized_successfully_) {
// If initialization was failed, return the fallback input method,
// as this function is guaranteed to return at least one descriptor.
- InputMethodDescriptors* result = new InputMethodDescriptors;
+ input_method::InputMethodDescriptors* result =
+ new input_method::InputMethodDescriptors;
result->push_back(input_method::GetFallbackInputMethodDescriptor());
return result;
}
// This never returns NULL.
- return chromeos::GetSupportedInputMethodDescriptors();
+ return input_method::GetSupportedInputMethodDescriptors();
}
virtual void ChangeInputMethod(const std::string& input_method_id) {
@@ -173,7 +173,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// If the input method daemon is not running and the specified input
// method is a keyboard layout, switch the keyboard directly.
if (ibus_daemon_process_handle_ == base::kNullProcessHandle &&
- chromeos::input_method::IsKeyboardLayout(input_method_id)) {
+ input_method::IsKeyboardLayout(input_method_id)) {
// We shouldn't use SetCurrentKeyboardLayoutByName() here. See
// comments at ChangeCurrentInputMethod() for details.
ChangeCurrentInputMethodFromId(input_method_id);
@@ -197,13 +197,13 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
return;
DCHECK(!key.empty());
- chromeos::SetImePropertyActivated(
- input_method_status_connection_, key.c_str(), activated);
+ ibus_controller_->SetImePropertyActivated(key, activated);
}
virtual bool InputMethodIsActivated(const std::string& input_method_id) {
- scoped_ptr<InputMethodDescriptors> active_input_method_descriptors(
- GetActiveInputMethods());
+ scoped_ptr<input_method::InputMethodDescriptors>
+ active_input_method_descriptors(
+ GetActiveInputMethods());
for (size_t i = 0; i < active_input_method_descriptors->size(); ++i) {
if (active_input_method_descriptors->at(i).id == input_method_id) {
return true;
@@ -214,7 +214,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
virtual bool SetImeConfig(const std::string& section,
const std::string& config_name,
- const ImeConfigValue& value) {
+ const input_method::ImeConfigValue& value) {
// If the config change is for preload engines, update the active
// input methods cache |active_input_method_ids_| here. We need to
// update the cache before actually flushing the config. since we need
@@ -224,7 +224,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// screen before the input method starts.
if (section == language_prefs::kGeneralSectionName &&
config_name == language_prefs::kPreloadEnginesConfigName &&
- value.type == ImeConfigValue::kValueTypeStringList) {
+ value.type == input_method::ImeConfigValue::kValueTypeStringList) {
active_input_method_ids_ = value.string_list_value;
}
@@ -245,21 +245,21 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
return pending_config_requests_.empty();
}
- virtual InputMethodDescriptor previous_input_method() const {
+ virtual input_method::InputMethodDescriptor previous_input_method() const {
if (previous_input_method_.id.empty()) {
return input_method::GetFallbackInputMethodDescriptor();
}
return previous_input_method_;
}
- virtual InputMethodDescriptor current_input_method() const {
+ virtual input_method::InputMethodDescriptor current_input_method() const {
if (current_input_method_.id.empty()) {
return input_method::GetFallbackInputMethodDescriptor();
}
return current_input_method_;
}
- virtual const ImePropertyList& current_ime_properties() const {
+ virtual const input_method::ImePropertyList& current_ime_properties() const {
return current_ime_properties_;
}
@@ -267,20 +267,21 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
if (!initialized_successfully_)
return "";
- return chromeos::GetKeyboardOverlayId(input_method_id);
+ return input_method::GetKeyboardOverlayId(input_method_id);
}
- virtual void SendHandwritingStroke(const HandwritingStroke& stroke) {
+ virtual void SendHandwritingStroke(
+ const input_method::HandwritingStroke& stroke) {
if (!initialized_successfully_)
return;
- chromeos::SendHandwritingStroke(input_method_status_connection_, stroke);
+ ibus_controller_->SendHandwritingStroke(stroke);
}
virtual void CancelHandwritingStrokes(int stroke_count) {
if (!initialized_successfully_)
return;
// TODO(yusukes): Rename the libcros function to CancelHandwritingStrokes.
- chromeos::CancelHandwriting(input_method_status_connection_, stroke_count);
+ ibus_controller_->CancelHandwriting(stroke_count);
}
private:
@@ -288,10 +289,10 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// element string list that contains an input method ID of a keyboard
// layout.
bool ContainOnlyOneKeyboardLayout(
- const ImeConfigValue& value) {
- return (value.type == ImeConfigValue::kValueTypeStringList &&
+ const input_method::ImeConfigValue& value) {
+ return (value.type == input_method::ImeConfigValue::kValueTypeStringList &&
value.string_list_value.size() == 1 &&
- chromeos::input_method::IsKeyboardLayout(
+ input_method::IsKeyboardLayout(
value.string_list_value[0]));
}
@@ -302,10 +303,10 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// "previous_engine"). |value| is the configuration value to be set.
void MaybeStartInputMethodDaemon(const std::string& section,
const std::string& config_name,
- const ImeConfigValue& value) {
+ const input_method::ImeConfigValue& value) {
if (section == language_prefs::kGeneralSectionName &&
config_name == language_prefs::kPreloadEnginesConfigName &&
- value.type == ImeConfigValue::kValueTypeStringList &&
+ value.type == input_method::ImeConfigValue::kValueTypeStringList &&
!value.string_list_value.empty()) {
// If there is only one input method which is a keyboard layout,
// we don't start the input method processes. When
@@ -356,7 +357,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// See also: MaybeStartInputMethodDaemon().
void MaybeStopInputMethodDaemon(const std::string& section,
const std::string& config_name,
- const ImeConfigValue& value) {
+ const input_method::ImeConfigValue& value) {
// If there is only one input method which is a keyboard layout,
// and |enable_auto_ime_shutdown_| is true, we'll stop the input
// method daemon.
@@ -370,9 +371,10 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// Change the keyboard layout per input method configuration being
// updated, if necessary. See also: MaybeStartInputMethodDaemon().
- void MaybeChangeCurrentKeyboardLayout(const std::string& section,
- const std::string& config_name,
- const ImeConfigValue& value) {
+ void MaybeChangeCurrentKeyboardLayout(
+ const std::string& section,
+ const std::string& config_name,
+ const input_method::ImeConfigValue& value) {
// If there is only one input method which is a keyboard layout, we'll
// change the keyboard layout per the only one input method now
@@ -402,7 +404,8 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// synced with cloud) and kLanguagePreloadEngines (synced with cloud) are
// mismatched. e.g. the former is 'xkb:us::eng' and the latter (on the
// sync server) is 'xkb:jp::jpn,mozc'.
- scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods());
+ scoped_ptr<input_method::InputMethodDescriptors> input_methods(
+ GetActiveInputMethods());
DCHECK(!input_methods->empty());
if (!input_methods->empty()) {
input_method_id_to_switch = input_methods->at(0).id;
@@ -412,8 +415,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
}
}
- if (chromeos::ChangeInputMethod(input_method_status_connection_,
- input_method_id_to_switch.c_str())) {
+ if (ibus_controller_->ChangeInputMethod(input_method_id_to_switch)) {
return true;
}
@@ -435,7 +437,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
while (iter != pending_config_requests_.end()) {
const std::string& section = iter->first.first;
const std::string& config_name = iter->first.second;
- ImeConfigValue& value = iter->second;
+ input_method::ImeConfigValue& value = iter->second;
if (config_name == language_prefs::kPreloadEnginesConfigName &&
!tentative_current_input_method_id_.empty()) {
@@ -469,10 +471,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
tentative_current_input_method_id_.erase();
}
- if (chromeos::SetImeConfig(input_method_status_connection_,
- section.c_str(),
- config_name.c_str(),
- value)) {
+ if (ibus_controller_->SetImeConfig(section, config_name, value)) {
// Check if it's a change in active input methods.
if (config_name == language_prefs::kPreloadEnginesConfigName) {
active_input_methods_are_changed = true;
@@ -514,18 +513,16 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// ibus-daemon, and observers are notified. See
// InputMethodChangedHandler() for details.
const size_t num_active_input_methods = GetNumActiveInputMethods();
- FOR_EACH_OBSERVER(Observer, observers_,
+ FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_,
ActiveInputMethodsChanged(this,
current_input_method_,
num_active_input_methods));
}
}
- // Called when the input method is changed in the IBus daemon
- // (ex. "global-engine-changed" is delivered from the IBus daemon).
- static void InputMethodChangedHandler(
- void* object,
- const chromeos::InputMethodDescriptor& current_input_method) {
+ // IBusController override.
+ virtual void OnCurrentInputMethodChanged(
+ const input_method::InputMethodDescriptor& current_input_method) {
// The handler is called when the input method method change is
// notified via a DBus connection. Since the DBus notificatiosn are
// handled in the UI thread, we can assume that this function always
@@ -535,62 +532,51 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
return;
}
- InputMethodLibraryImpl* input_method_library =
- static_cast<InputMethodLibraryImpl*>(object);
- input_method_library->ChangeCurrentInputMethod(current_input_method);
+ ChangeCurrentInputMethod(current_input_method);
}
- // Called when properties are registered in the IBus daemon.
- static void RegisterPropertiesHandler(
- void* object, const ImePropertyList& prop_list) {
+ // IBusController override.
+ virtual void OnRegisterImeProperties(
+ const input_method::ImePropertyList& prop_list) {
// See comments in InputMethodChangedHandler.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
LOG(ERROR) << "Not on UI thread";
return;
}
- InputMethodLibraryImpl* input_method_library =
- static_cast<InputMethodLibraryImpl*>(object);
- input_method_library->RegisterProperties(prop_list);
+ RegisterProperties(prop_list);
}
- // Called when properties are updated in the IBus daemon.
- static void UpdatePropertyHandler(
- void* object, const ImePropertyList& prop_list) {
+ // IBusController override.
+ virtual void OnUpdateImeProperty(
+ const input_method::ImePropertyList& prop_list) {
// See comments in InputMethodChangedHandler.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
LOG(ERROR) << "Not on UI thread";
return;
}
- InputMethodLibraryImpl* input_method_library =
- static_cast<InputMethodLibraryImpl*>(object);
- input_method_library->UpdateProperty(prop_list);
+ UpdateProperty(prop_list);
}
- // Called when 1) connection to ibus-daemon and ibus-memconf are established
- // or 2) connection to ibus-daemon is terminated.
- static void ConnectionChangeHandler(void* object, bool connected) {
+ // IBusController override.
+ virtual void OnConnectionChange(bool connected) {
// See comments in InputMethodChangedHandler.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
LOG(ERROR) << "Not on UI thread";
return;
}
- InputMethodLibraryImpl* input_method_library =
- static_cast<InputMethodLibraryImpl*>(object);
- input_method_library->ime_connected_ = connected;
+ ime_connected_ = connected;
if (connected) {
- input_method_library->pending_config_requests_.clear();
- input_method_library->pending_config_requests_.insert(
- input_method_library->current_config_values_.begin(),
- input_method_library->current_config_values_.end());
- input_method_library->FlushImeConfig();
-
- input_method_library->ChangeInputMethod(
- input_method_library->previous_input_method().id);
- input_method_library->ChangeInputMethod(
- input_method_library->current_input_method().id);
+ pending_config_requests_.clear();
+ pending_config_requests_.insert(
+ current_config_values_.begin(),
+ current_config_values_.end());
+ FlushImeConfig();
+
+ ChangeInputMethod(previous_input_method().id);
+ ChangeInputMethod(current_input_method().id);
}
}
@@ -599,7 +585,8 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// and notifies observers about the change (that will update the
// preferences), hence this function should always be used even if you
// just need to change the current keyboard layout.
- void ChangeCurrentInputMethod(const InputMethodDescriptor& new_input_method) {
+ void ChangeCurrentInputMethod(const input_method::InputMethodDescriptor&
+ new_input_method) {
if (current_input_method_.id != new_input_method.id) {
previous_input_method_ = current_input_method_;
current_input_method_ = new_input_method;
@@ -615,8 +602,8 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// observer to do so. Otherwise, we'll end up updating preferences many
// times when many observers are attached (ex. many windows are opened),
// which is unnecessary and expensive.
- ObserverListBase<Observer>::Iterator it(observers_);
- Observer* first_observer = it.GetNext();
+ ObserverListBase<InputMethodLibrary::Observer>::Iterator it(observers_);
+ InputMethodLibrary::Observer* first_observer = it.GetNext();
if (first_observer) {
first_observer->PreferenceUpdateNeeded(this,
previous_input_method_,
@@ -628,7 +615,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// For now, we have to do this every time to keep indicators updated. See
// comments near the FOR_EACH_OBSERVER call in FlushImeConfig() for details.
const size_t num_active_input_methods = GetNumActiveInputMethods();
- FOR_EACH_OBSERVER(Observer, observers_,
+ FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_,
InputMethodChanged(this,
current_input_method_,
num_active_input_methods));
@@ -637,8 +624,8 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// Changes the current input method from the given input method ID.
// This function is just a wrapper of ChangeCurrentInputMethod().
void ChangeCurrentInputMethodFromId(const std::string& input_method_id) {
- const chromeos::InputMethodDescriptor* descriptor =
- chromeos::input_method::GetInputMethodDescriptorFromId(
+ const input_method::InputMethodDescriptor* descriptor =
+ input_method::GetInputMethodDescriptorFromId(
input_method_id);
if (descriptor) {
ChangeCurrentInputMethod(*descriptor);
@@ -648,12 +635,12 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
}
// Registers the properties used by the current input method.
- void RegisterProperties(const ImePropertyList& prop_list) {
+ void RegisterProperties(const input_method::ImePropertyList& prop_list) {
// |prop_list| might be empty. This means "clear all properties."
current_ime_properties_ = prop_list;
// Update input method menu
- FOR_EACH_OBSERVER(Observer, observers_,
+ FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_,
PropertyListChanged(this,
current_ime_properties_));
}
@@ -667,13 +654,13 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
}
// Updates the properties used by the current input method.
- void UpdateProperty(const ImePropertyList& prop_list) {
+ void UpdateProperty(const input_method::ImePropertyList& prop_list) {
for (size_t i = 0; i < prop_list.size(); ++i) {
FindAndUpdateProperty(prop_list[i], &current_ime_properties_);
}
// Update input method menu
- FOR_EACH_OBSERVER(Observer, observers_,
+ FOR_EACH_OBSERVER(InputMethodLibrary::Observer, observers_,
PropertyListChanged(this,
current_ime_properties_));
}
@@ -774,7 +761,7 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
should_launch_ime_ = false;
if (ibus_daemon_process_handle_ != base::kNullProcessHandle) {
const base::ProcessId pid = base::GetProcId(ibus_daemon_process_handle_);
- if (!chromeos::StopInputMethodProcess(input_method_status_connection_)) {
+ if (!ibus_controller_->StopInputMethodProcess()) {
LOG(ERROR) << "StopInputMethodProcess IPC failed. Sending SIGTERM to "
<< "PID " << pid;
base::KillProcess(ibus_daemon_process_handle_, -1, false /* wait */);
@@ -809,19 +796,20 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
// A reference to the language api, to allow callbacks when the input method
// status changes.
- InputMethodStatusConnection* input_method_status_connection_;
- ObserverList<Observer> observers_;
+ input_method::IBusController* ibus_controller_;
+ ObserverList<InputMethodLibrary::Observer> observers_;
// The input method which was/is selected.
- InputMethodDescriptor previous_input_method_;
- InputMethodDescriptor current_input_method_;
+ input_method::InputMethodDescriptor previous_input_method_;
+ input_method::InputMethodDescriptor current_input_method_;
// The input method properties which the current input method uses. The list
// might be empty when no input method is used.
- ImePropertyList current_ime_properties_;
+ input_method::ImePropertyList current_ime_properties_;
typedef std::pair<std::string, std::string> ConfigKeyType;
- typedef std::map<ConfigKeyType, ImeConfigValue> InputMethodConfigRequests;
+ typedef std::map<ConfigKeyType,
+ input_method::ImeConfigValue> InputMethodConfigRequests;
// SetImeConfig requests that are not yet completed.
// Use a map to queue config requests, so we only send the last request for
// the same config key (i.e. we'll discard ealier requests for the same
@@ -873,8 +861,6 @@ class InputMethodLibraryImpl : public InputMethodLibrary,
DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryImpl);
};
-InputMethodLibraryImpl::Observer::~Observer() {}
-
// The stub implementation of InputMethodLibrary. Used for testing.
class InputMethodLibraryStubImpl : public InputMethodLibrary {
public:
@@ -887,17 +873,18 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
virtual void AddObserver(Observer* observer) {}
virtual void RemoveObserver(Observer* observer) {}
- virtual InputMethodDescriptors* GetActiveInputMethods() {
+ virtual input_method::InputMethodDescriptors* GetActiveInputMethods() {
return GetInputMethodDescriptorsForTesting();
}
virtual size_t GetNumActiveInputMethods() {
- scoped_ptr<InputMethodDescriptors> descriptors(GetActiveInputMethods());
+ scoped_ptr<input_method::InputMethodDescriptors> descriptors(
+ GetActiveInputMethods());
return descriptors->size();
}
- virtual InputMethodDescriptors* GetSupportedInputMethods() {
+ virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() {
return GetInputMethodDescriptorsForTesting();
}
@@ -911,19 +898,19 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
virtual bool SetImeConfig(const std::string& section,
const std::string& config_name,
- const ImeConfigValue& value) {
+ const input_method::ImeConfigValue& value) {
return false;
}
- virtual InputMethodDescriptor previous_input_method() const {
+ virtual input_method::InputMethodDescriptor previous_input_method() const {
return previous_input_method_;
}
- virtual InputMethodDescriptor current_input_method() const {
+ virtual input_method::InputMethodDescriptor current_input_method() const {
return current_input_method_;
}
- virtual const ImePropertyList& current_ime_properties() const {
+ virtual const input_method::ImePropertyList& current_ime_properties() const {
return current_ime_properties_;
}
@@ -941,7 +928,8 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
iter->second : "";
}
- virtual void SendHandwritingStroke(const HandwritingStroke& stroke) {}
+ virtual void SendHandwritingStroke(
+ const input_method::HandwritingStroke& stroke) {}
virtual void CancelHandwritingStrokes(int stroke_count) {}
private:
@@ -949,160 +937,161 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
// Gets input method descriptors for testing. Shouldn't be used for
// production.
- InputMethodDescriptors* GetInputMethodDescriptorsForTesting() {
- InputMethodDescriptors* descriptions = new InputMethodDescriptors;
+ input_method::InputMethodDescriptors* GetInputMethodDescriptorsForTesting() {
+ input_method::InputMethodDescriptors* descriptions =
+ new input_method::InputMethodDescriptors;
// The list is created from output of gen_engines.py in libcros.
// % SHARE=/build/x86-generic/usr/share python gen_engines.py
// $SHARE/chromeos-assets/input_methods/whitelist.txt
// $SHARE/ibus/component/{chewing,hangul,m17n,mozc,pinyin,xkb-layouts}.xml
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:nl::nld", "Netherlands", "nl", "nl", "nld"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:be::nld", "Belgium", "be", "be", "nld"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:fr::fra", "France", "fr", "fr", "fra"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:be::fra", "Belgium", "be", "be", "fra"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ca::fra", "Canada", "ca", "ca", "fra"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ch:fr:fra", "Switzerland - French", "ch(fr)", "ch(fr)", "fra"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:de::ger", "Germany", "de", "de", "ger"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:de:neo:ger", "Germany - Neo 2", "de(neo)", "de(neo)", "ger"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:be::ger", "Belgium", "be", "be", "ger"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ch::ger", "Switzerland", "ch", "ch", "ger"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"mozc", "Mozc (US keyboard layout)", "us", "us", "ja"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"mozc-jp", "Mozc (Japanese keyboard layout)", "jp", "jp", "ja"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"mozc-dv",
"Mozc (US Dvorak keyboard layout)", "us(dvorak)", "us(dvorak)", "ja"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:jp::jpn", "Japan", "jp", "jp", "jpn"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ru::rus", "Russia", "ru", "ru", "rus"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ru:phonetic:rus",
"Russia - Phonetic", "ru(phonetic)", "ru(phonetic)", "rus"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:th:kesmanee", "kesmanee (m17n)", "us", "us", "th"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:th:pattachote", "pattachote (m17n)", "us", "us", "th"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:th:tis820", "tis820 (m17n)", "us", "us", "th"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"mozc-chewing", "Mozc Chewing (Chewing)", "us", "us", "zh_TW"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:zh:cangjie", "cangjie (m17n)", "us", "us", "zh"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:zh:quick", "quick (m17n)", "us", "us", "zh"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:vi:tcvn", "tcvn (m17n)", "us", "us", "vi"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:vi:telex", "telex (m17n)", "us", "us", "vi"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:vi:viqr", "viqr (m17n)", "us", "us", "vi"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:vi:vni", "vni (m17n)", "us", "us", "vi"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:us::eng", "USA", "us", "us", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:us:intl:eng",
"USA - International (with dead keys)", "us(intl)", "us(intl)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:us:altgr-intl:eng", "USA - International (AltGr dead keys)",
"us(altgr-intl)", "us(altgr-intl)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:us:dvorak:eng",
"USA - Dvorak", "us(dvorak)", "us(dvorak)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:us:colemak:eng",
"USA - Colemak", "us(colemak)", "us(colemak)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"hangul", "Korean", "kr(kr104)", "kr(kr104)", "ko"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"pinyin", "Pinyin", "us", "us", "zh"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"pinyin-dv", "Pinyin (for US Dvorak keyboard)",
"us(dvorak)", "us(dvorak)", "zh"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:ar:kbd", "kbd (m17n)", "us", "us", "ar"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:hi:itrans", "itrans (m17n)", "us", "us", "hi"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"m17n:fa:isiri", "isiri (m17n)", "us", "us", "fa"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:br::por", "Brazil", "br", "br", "por"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:bg::bul", "Bulgaria", "bg", "bg", "bul"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:bg:phonetic:bul", "Bulgaria - Traditional phonetic",
"bg(phonetic)", "bg(phonetic)", "bul"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ca:eng:eng", "Canada - English", "ca(eng)", "ca(eng)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:cz::cze", "Czechia", "cz", "cz", "cze"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ee::est", "Estonia", "ee", "ee", "est"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:es::spa", "Spain", "es", "es", "spa"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:es:cat:cat", "Spain - Catalan variant with middle-dot L",
"es(cat)", "es(cat)", "cat"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:dk::dan", "Denmark", "dk", "dk", "dan"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:gr::gre", "Greece", "gr", "gr", "gre"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:il::heb", "Israel", "il", "il", "heb"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:kr:kr104:kor", "Korea, Republic of - 101/104 key Compatible",
"kr(kr104)", "kr(kr104)", "kor"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:latam::spa", "Latin American", "latam", "latam", "spa"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:lt::lit", "Lithuania", "lt", "lt", "lit"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:lv:apostrophe:lav", "Latvia - Apostrophe (') variant",
"lv(apostrophe)", "lv(apostrophe)", "lav"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:hr::scr", "Croatia", "hr", "hr", "scr"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:gb:extd:eng", "United Kingdom - Extended - Winkeys",
"gb(extd)", "gb(extd)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:gb:dvorak:eng", "United Kingdom - Dvorak",
"gb(dvorak)", "gb(dvorak)", "eng"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:fi::fin", "Finland", "fi", "fi", "fin"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:hu::hun", "Hungary", "hu", "hu", "hun"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:it::ita", "Italy", "it", "it", "ita"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:no::nob", "Norway", "no", "no", "nob"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:pl::pol", "Poland", "pl", "pl", "pol"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:pt::por", "Portugal", "pt", "pt", "por"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ro::rum", "Romania", "ro", "ro", "rum"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:se::swe", "Sweden", "se", "se", "swe"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:sk::slo", "Slovakia", "sk", "sk", "slo"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:si::slv", "Slovenia", "si", "si", "slv"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:rs::srp", "Serbia", "rs", "rs", "srp"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:tr::tur", "Turkey", "tr", "tr", "tur"));
- descriptions->push_back(InputMethodDescriptor(
+ descriptions->push_back(input_method::InputMethodDescriptor(
"xkb:ua::ukr", "Ukraine", "ua", "ua", "ukr"));
return descriptions;
}
@@ -1183,9 +1172,9 @@ class InputMethodLibraryStubImpl : public InputMethodLibrary {
return keyboard_overlay_map;
}
- InputMethodDescriptor previous_input_method_;
- InputMethodDescriptor current_input_method_;
- ImePropertyList current_ime_properties_;
+ input_method::InputMethodDescriptor previous_input_method_;
+ input_method::InputMethodDescriptor current_input_method_;
+ input_method::ImePropertyList current_ime_properties_;
scoped_ptr<KeyboardOverlayMap> keyboard_overlay_map_;
DISALLOW_COPY_AND_ASSIGN(InputMethodLibraryStubImpl);
diff --git a/chrome/browser/chromeos/cros/input_method_library.h b/chrome/browser/chromeos/cros/input_method_library.h
index 5bf175a..2123251 100644
--- a/chrome/browser/chromeos/cros/input_method_library.h
+++ b/chrome/browser/chromeos/cros/input_method_library.h
@@ -1,6 +1,9 @@
// Copyright (c) 2011 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.
+//
+// TODO(satorux): Move this from 'cros' directory to 'input_method'
+// directory.
#ifndef CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_
#define CHROME_BROWSER_CHROMEOS_CROS_INPUT_METHOD_LIBRARY_H_
@@ -12,7 +15,7 @@
#include "base/observer_list.h"
#include "base/time.h"
#include "base/timer.h"
-#include "third_party/cros/chromeos_input_method.h"
+#include "chrome/browser/chromeos/input_method/ibus_controller.h"
namespace chromeos {
@@ -24,29 +27,30 @@ class InputMethodLibrary {
public:
class Observer {
public:
- virtual ~Observer() = 0;
+ virtual ~Observer() {}
+
// Called when the current input method is changed.
virtual void InputMethodChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) = 0;
// Called when the active input methods are changed.
virtual void ActiveInputMethodsChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) = 0;
// Called when the preferences have to be updated.
virtual void PreferenceUpdateNeeded(
InputMethodLibrary* obj,
- const InputMethodDescriptor& previous_input_method,
- const InputMethodDescriptor& current_input_method) = 0;
+ const input_method::InputMethodDescriptor& previous_input_method,
+ const input_method::InputMethodDescriptor& current_input_method) = 0;
// Called when the list of properties is changed.
virtual void PropertyListChanged(
InputMethodLibrary* obj,
- const ImePropertyList& current_ime_properties) = 0;
+ const input_method::ImePropertyList& current_ime_properties) = 0;
// Called by AddObserver() when the first observer is added.
virtual void FirstObserverIsAdded(InputMethodLibrary* obj) = 0;
@@ -61,7 +65,7 @@ class InputMethodLibrary {
// Returns the list of input methods we can select (i.e. active). If the cros
// library is not found or IBus/DBus daemon is not alive, this function
// returns a fallback input method list (and never returns NULL).
- virtual InputMethodDescriptors* GetActiveInputMethods() = 0;
+ virtual input_method::InputMethodDescriptors* GetActiveInputMethods() = 0;
// Returns the number of active input methods.
virtual size_t GetNumActiveInputMethods() = 0;
@@ -69,7 +73,7 @@ class InputMethodLibrary {
// Returns the list of input methods we support, including ones not active.
// If the cros library is not found or IBus/DBus daemon is not alive, this
// function returns a fallback input method list (and never returns NULL).
- virtual InputMethodDescriptors* GetSupportedInputMethods() = 0;
+ virtual input_method::InputMethodDescriptors* GetSupportedInputMethods() = 0;
// Changes the current input method to |input_method_id|.
virtual void ChangeInputMethod(const std::string& input_method_id) = 0;
@@ -98,7 +102,7 @@ class InputMethodLibrary {
// function. See also http://crosbug.com/5217.
virtual bool SetImeConfig(const std::string& section,
const std::string& config_name,
- const ImeConfigValue& value) = 0;
+ const input_method::ImeConfigValue& value) = 0;
// Returns the keyboard overlay ID corresponding to |input_method_id|.
// Returns an empty string if there is no corresponding keyboard overlay ID.
@@ -123,16 +127,18 @@ class InputMethodLibrary {
// Sends a handwriting stroke to libcros. See chromeos::SendHandwritingStroke
// for details.
- virtual void SendHandwritingStroke(const HandwritingStroke& stroke) = 0;
+ virtual void SendHandwritingStroke(
+ const input_method::HandwritingStroke& stroke) = 0;
// Clears last N handwriting strokes in libcros. See
// chromeos::CancelHandwriting for details.
virtual void CancelHandwritingStrokes(int stroke_count) = 0;
- virtual InputMethodDescriptor previous_input_method() const = 0;
- virtual InputMethodDescriptor current_input_method() const = 0;
+ virtual input_method::InputMethodDescriptor previous_input_method() const = 0;
+ virtual input_method::InputMethodDescriptor current_input_method() const = 0;
- virtual const ImePropertyList& current_ime_properties() const = 0;
+ virtual const input_method::ImePropertyList& current_ime_properties()
+ const = 0;
// Factory function, creates a new instance and returns ownership.
// For normal usage, access the singleton via CrosLibrary::Get().
diff --git a/chrome/browser/chromeos/cros/mock_input_method_library.h b/chrome/browser/chromeos/cros/mock_input_method_library.h
index 1bc5aa8..ae74dd4 100644
--- a/chrome/browser/chromeos/cros/mock_input_method_library.h
+++ b/chrome/browser/chromeos/cros/mock_input_method_library.h
@@ -21,23 +21,29 @@ class MockInputMethodLibrary : public InputMethodLibrary {
MOCK_METHOD1(AddObserver, void(Observer*));
MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD0(GetActiveInputMethods, InputMethodDescriptors*(void));
+ MOCK_METHOD0(GetActiveInputMethods,
+ input_method::InputMethodDescriptors*(void));
MOCK_METHOD0(GetNumActiveInputMethods, size_t(void));
- MOCK_METHOD0(GetSupportedInputMethods, InputMethodDescriptors*(void));
+ MOCK_METHOD0(GetSupportedInputMethods,
+ input_method::InputMethodDescriptors*(void));
MOCK_METHOD1(ChangeInputMethod, void(const std::string&));
MOCK_METHOD2(SetImePropertyActivated, void(const std::string&, bool));
MOCK_METHOD1(InputMethodIsActivated, bool(const std::string&));
MOCK_METHOD3(SetImeConfig, bool(const std::string&, const std::string&,
- const ImeConfigValue&));
- MOCK_CONST_METHOD0(previous_input_method, InputMethodDescriptor(void));
- MOCK_CONST_METHOD0(current_input_method, InputMethodDescriptor(void));
- MOCK_CONST_METHOD0(current_ime_properties, const ImePropertyList&(void));
+ const input_method::ImeConfigValue&));
+ MOCK_CONST_METHOD0(previous_input_method,
+ input_method::InputMethodDescriptor(void));
+ MOCK_CONST_METHOD0(current_input_method,
+ input_method::InputMethodDescriptor(void));
+ MOCK_CONST_METHOD0(current_ime_properties,
+ const input_method::ImePropertyList&(void));
MOCK_METHOD1(GetKeyboardOverlayId, std::string(const std::string&));
MOCK_METHOD0(StartInputMethodDaemon, bool(void));
MOCK_METHOD0(StopInputMethodDaemon, void(void));
MOCK_METHOD1(SetDeferImeStartup, void(bool));
MOCK_METHOD1(SetEnableAutoImeShutdown, void(bool));
- MOCK_METHOD1(SendHandwritingStroke, void(const HandwritingStroke&));
+ MOCK_METHOD1(SendHandwritingStroke,
+ void(const input_method::HandwritingStroke&));
MOCK_METHOD1(CancelHandwritingStrokes, void(int));
};
diff --git a/chrome/browser/chromeos/input_method/ibus_controller.cc b/chrome/browser/chromeos/input_method/ibus_controller.cc
index c2018aa..ce15c80 100644
--- a/chrome/browser/chromeos/input_method/ibus_controller.cc
+++ b/chrome/browser/chromeos/input_method/ibus_controller.cc
@@ -1,14 +1,12 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 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_input_method.h"
-
-#include "chromeos_input_method_ui.h"
-#include "chromeos_input_method_whitelist.h"
-#include "chromeos_keyboard_overlay_map.h"
+#include "chrome/browser/chromeos/input_method/ibus_controller.h"
+#if defined(HAVE_IBUS)
#include <ibus.h>
+#endif
#include <algorithm> // for std::reverse.
#include <cstdio>
@@ -18,11 +16,45 @@
#include <stack>
#include <utility>
+#if defined(HAVE_IBUS)
+// TODO(satorux): Move these to Chrome tree.
+#include <cros/chromeos_input_method_whitelist.h>
+#include <cros/ibus_input_methods.h>
+#else
+const char* kInputMethodIdsWhitelist[] = {
+ "xkb:us::eng",
+};
+const char* kXkbLayoutsWhitelist[] = {
+ "us",
+};
+#endif // defined(HAVE_IBUS)
+
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
-#include "ibus_input_methods.h"
+#include "base/observer_list.h"
namespace chromeos {
+namespace input_method {
+
+// TODO(satorux): The function is used via
+// InputMethodLibrary::GetSupportedInputMethodDescriptors(). The
+// indirection is unnecessary once we get rid of libcros. We should
+// refactor the two functions.
+InputMethodDescriptors* GetSupportedInputMethodDescriptors() {
+ InputMethodDescriptors* input_methods = new InputMethodDescriptors;
+#if defined(HAVE_IBUS)
+ for (size_t i = 0; i < arraysize(chromeos::kIBusEngines); ++i) {
+ if (InputMethodIdIsWhitelisted(chromeos::kIBusEngines[i].name)) {
+ input_methods->push_back(CreateInputMethodDescriptor(
+ chromeos::kIBusEngines[i].name,
+ chromeos::kIBusEngines[i].longname,
+ chromeos::kIBusEngines[i].layout,
+ chromeos::kIBusEngines[i].language));
+ }
+ }
+#endif // defined(HAVE_IBUS)
+ return input_methods;
+}
// Returns true if |input_method_id| is whitelisted.
bool InputMethodIdIsWhitelisted(const std::string& input_method_id) {
@@ -80,6 +112,9 @@ InputMethodDescriptor CreateInputMethodDescriptor(
language_code);
}
+#if defined(HAVE_IBUS)
+const char kPanelObjectKey[] = "panel-object";
+
namespace {
// Also defined in chrome/browser/chromeos/language_preferences.h (Chrome tree).
@@ -149,7 +184,7 @@ void AddInputMethodNames(const GList* engines, InputMethodDescriptors* out) {
longname,
layout,
language));
- DLOG(INFO) << name << " (preloaded)";
+ VLOG(1) << name << " (preloaded)";
}
}
}
@@ -196,7 +231,7 @@ bool ConvertProperty(IBusProperty* ibus_prop,
}
if ((!has_sub_props) && (ibus_prop->type == PROP_TYPE_MENU)) {
// This is usually not an error. ibus-daemon sometimes sends empty props.
- DLOG(INFO) << "Property list is empty";
+ VLOG(1) << "Property list is empty";
return false;
}
if (ibus_prop->type == PROP_TYPE_SEPARATOR ||
@@ -439,45 +474,21 @@ std::string PrintPropList(IBusPropList *prop_list, int tree_level) {
} // namespace
-// A singleton class that holds IBus connections.
-class InputMethodStatusConnection {
+// The real implementation of the IBusController.
+class IBusControllerImpl : public IBusController {
public:
- // Returns a singleton object of the class. If the singleton object is already
- // initialized, the arguments are ignored.
- // Warning: you can call the callback functions only in the ibus callback
- // functions like FocusIn(). See http://crosbug.com/5217#c9 for details.
- static InputMethodStatusConnection* GetConnection(
- void* language_library,
- LanguageCurrentInputMethodMonitorFunction current_input_method_changed,
- LanguageRegisterImePropertiesFunction register_ime_properties,
- LanguageUpdateImePropertyFunction update_ime_property,
- LanguageConnectionChangeMonitorFunction connection_change_handler) {
- DCHECK(language_library);
- DCHECK(current_input_method_changed),
- DCHECK(register_ime_properties);
- DCHECK(update_ime_property);
-
- InputMethodStatusConnection* object = GetInstance();
- if (!object->language_library_) {
- object->language_library_ = language_library;
- object->current_input_method_changed_ = current_input_method_changed;
- object->register_ime_properties_= register_ime_properties;
- object->update_ime_property_ = update_ime_property;
- object->connection_change_handler_ = connection_change_handler;
- object->MaybeRestoreConnections();
- } else if (object->language_library_ != language_library) {
- LOG(ERROR) << "Unknown language_library is passed";
- }
- return object;
+ // TODO(satorux,yusukes): Remove use of singleton here.
+ static IBusControllerImpl* GetInstance() {
+ return Singleton<IBusControllerImpl,
+ LeakySingletonTraits<IBusControllerImpl> >::get();
}
- static InputMethodStatusConnection* GetInstance() {
- return Singleton<InputMethodStatusConnection,
- LeakySingletonTraits<InputMethodStatusConnection> >::get();
+ virtual void Connect() {
+ MaybeRestoreConnections();
}
- // Called by cros API ChromeOSStopInputMethodProcess().
- bool StopInputMethodProcess() {
+ // IBusController override.
+ virtual bool StopInputMethodProcess() {
if (!IBusConnectionsAreAlive()) {
LOG(ERROR) << "StopInputMethodProcess: IBus connection is not alive";
return false;
@@ -500,13 +511,14 @@ class InputMethodStatusConnection {
return true;
}
- // Called by cros API ChromeOS(Activate|Deactive)ImeProperty().
- void SetImePropertyActivated(const char* key, bool activated) {
+ // IBusController override.
+ virtual void SetImePropertyActivated(const std::string& key,
+ bool activated) {
if (!IBusConnectionsAreAlive()) {
LOG(ERROR) << "SetImePropertyActivated: IBus connection is not alive";
return;
}
- if (!key || (key[0] == '\0')) {
+ if (key.empty()) {
return;
}
if (input_context_path_.empty()) {
@@ -520,7 +532,8 @@ class InputMethodStatusConnection {
}
// Activate the property *asynchronously*.
ibus_input_context_property_activate(
- context, key, (activated ? PROP_STATE_CHECKED : PROP_STATE_UNCHECKED));
+ context, key.c_str(),
+ (activated ? PROP_STATE_CHECKED : PROP_STATE_UNCHECKED));
// We don't have to call ibus_proxy_destroy(context) explicitly here,
// i.e. we can just call g_object_unref(context), since g_object_unref can
@@ -530,13 +543,13 @@ class InputMethodStatusConnection {
g_object_unref(context);
}
- // Called by cros API ChromeOSChangeInputMethod().
- bool ChangeInputMethod(const char* name) {
+ // IBusController override.
+ virtual bool ChangeInputMethod(const std::string& name) {
if (!IBusConnectionsAreAlive()) {
LOG(ERROR) << "ChangeInputMethod: IBus connection is not alive";
return false;
}
- if (!name) {
+ if (name.empty()) {
return false;
}
if (!InputMethodIdIsWhitelisted(name)) {
@@ -551,11 +564,11 @@ class InputMethodStatusConnection {
// until a text area is focused. Therefore, we have to clear the old input
// method properties here to keep the input method switcher status
// consistent.
- RegisterProperties(NULL);
+ DoRegisterProperties(NULL);
// Change the global engine *asynchronously*.
ibus_bus_set_global_engine_async(ibus_,
- name,
+ name.c_str(),
-1, // use the default ibus timeout
NULL, // cancellable
NULL, // callback
@@ -563,14 +576,10 @@ class InputMethodStatusConnection {
return true;
}
- // Updates a configuration of ibus-daemon or IBus engines with |value|.
- // Returns true if the configuration is successfully updated.
- //
- // For more information, please read a comment for SetImeConfig() function
- // in chromeos_language.h.
- bool SetImeConfig(const std::string& section,
- const std::string& config_name,
- const ImeConfigValue& value) {
+ // IBusController override.
+ virtual bool SetImeConfig(const std::string& section,
+ const std::string& config_name,
+ const ImeConfigValue& value) {
// See comments in GetImeConfig() where ibus_config_get_value() is used.
if (!IBusConnectionsAreAlive()) {
LOG(ERROR) << "SetImeConfig: IBus connection is not alive";
@@ -633,13 +642,14 @@ class InputMethodStatusConnection {
// (takes ownership of) the variable.
if (is_preload_engines) {
- DLOG(INFO) << "SetImeConfig: " << section << "/" << config_name
- << ": " << value.ToString();
+ VLOG(1) << "SetImeConfig: " << section << "/" << config_name
+ << ": " << value.ToString();
}
return true;
}
- void SendHandwritingStroke(const HandwritingStroke& stroke) {
+ // IBusController override.
+ virtual void SendHandwritingStroke(const HandwritingStroke& stroke) {
if (stroke.size() < 2) {
LOG(WARNING) << "Empty stroke data or a single dot is passed.";
return;
@@ -661,7 +671,8 @@ class InputMethodStatusConnection {
g_object_unref(context);
}
- void CancelHandwriting(int n_strokes) {
+ // IBusController override.
+ virtual void CancelHandwriting(int n_strokes) {
IBusInputContext* context = GetInputContext(input_context_path_, ibus_);
if (!context) {
return;
@@ -670,19 +681,73 @@ class InputMethodStatusConnection {
g_object_unref(context);
}
+ // IBusController override.
+ virtual void AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+ }
+
+ // IBusController override.
+ virtual void RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+ }
+
private:
- friend struct DefaultSingletonTraits<InputMethodStatusConnection>;
- InputMethodStatusConnection()
- : current_input_method_changed_(NULL),
- register_ime_properties_(NULL),
- update_ime_property_(NULL),
- connection_change_handler_(NULL),
- language_library_(NULL),
- ibus_(NULL),
+ // Functions that end with Thunk are used to deal with glib callbacks.
+ //
+ // Note that we cannot use CHROMEG_CALLBACK_0() here as we'll define
+ // IBusBusConnected() inline. If we are to define the function outside
+ // of the class definition, we should use CHROMEG_CALLBACK_0() here.
+ //
+ // CHROMEG_CALLBACK_0(Impl,
+ // void, IBusBusConnected, IBusBus*);
+ static void IBusBusConnectedThunk(IBusBus* sender, gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->IBusBusConnected(sender);
+ }
+ static void IBusBusDisconnectedThunk(IBusBus* sender, gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->IBusBusDisconnected(sender);
+ }
+ static void IBusBusGlobalEngineChangedThunk(IBusBus* sender,
+ const gchar* engine_name,
+ gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->IBusBusGlobalEngineChanged(sender, engine_name);
+ }
+ static void IBusBusNameOwnerChangedThunk(IBusBus* sender,
+ const gchar* name,
+ const gchar* old_name,
+ const gchar* new_name,
+ gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->IBusBusNameOwnerChanged(sender, name, old_name, new_name);
+ }
+ static void FocusInThunk(IBusPanelService* sender,
+ const gchar* input_context_path,
+ gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->FocusIn(sender, input_context_path);
+ }
+ static void RegisterPropertiesThunk(IBusPanelService* sender,
+ IBusPropList* prop_list,
+ gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->RegisterProperties(sender, prop_list);
+ }
+ static void UpdatePropertyThunk(IBusPanelService* sender,
+ IBusProperty* ibus_prop,
+ gpointer userdata) {
+ return reinterpret_cast<IBusControllerImpl*>(userdata)
+ ->UpdateProperty(sender, ibus_prop);
+ }
+
+ friend struct DefaultSingletonTraits<IBusControllerImpl>;
+ IBusControllerImpl()
+ : ibus_(NULL),
ibus_config_(NULL) {
}
- ~InputMethodStatusConnection() {
+ ~IBusControllerImpl() {
// Since the class is used as a leaky singleton, this destructor is never
// called. However, if you would delete an instance of this class, you have
// to disconnect all signals so the handler functions will not be called
@@ -717,10 +782,8 @@ class InputMethodStatusConnection {
MaybeRestoreIBusConfig();
if (IBusConnectionsAreAlive()) {
ConnectPanelServiceSignals();
- if (connection_change_handler_) {
- LOG(INFO) << "Notifying Chrome that IBus is ready.";
- connection_change_handler_(language_library_, true);
- }
+ VLOG(1) << "Notifying Chrome that IBus is ready.";
+ FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(true));
}
}
@@ -750,7 +813,7 @@ class InputMethodStatusConnection {
ibus_bus_set_watch_ibus_signal(ibus_, TRUE);
if (ibus_bus_is_connected(ibus_)) {
- LOG(INFO) << "IBus connection is ready.";
+ VLOG(1) << "IBus connection is ready.";
}
}
@@ -767,8 +830,8 @@ class InputMethodStatusConnection {
if (!ibus_config_) {
GDBusConnection* ibus_connection = ibus_bus_get_connection(ibus_);
if (!ibus_connection) {
- LOG(INFO) << "Couldn't create an ibus config object since "
- << "IBus connection is not ready.";
+ VLOG(1) << "Couldn't create an ibus config object since "
+ << "IBus connection is not ready.";
return;
}
const gboolean disconnected
@@ -797,7 +860,7 @@ class InputMethodStatusConnection {
// libcros to detect the delivery of the "destroy" glib signal the
// |ibus_config_| object.
g_object_ref(ibus_config_);
- LOG(INFO) << "ibus_config_ is ready.";
+ VLOG(1) << "ibus_config_ is ready.";
}
}
@@ -816,20 +879,9 @@ class InputMethodStatusConnection {
}
}
- // Handles "FocusIn" signal from chromeos_input_method_ui.
- void FocusIn(const char* input_context_path) {
- if (!input_context_path) {
- LOG(ERROR) << "NULL context passed";
- } else {
- DLOG(INFO) << "FocusIn: " << input_context_path;
- }
- // Remember the current ic path.
- input_context_path_ = Or(input_context_path, "");
- }
-
// Handles "RegisterProperties" signal from chromeos_input_method_ui.
- void RegisterProperties(IBusPropList* ibus_prop_list) {
- DLOG(INFO) << "RegisterProperties" << (ibus_prop_list ? "" : " (clear)");
+ void DoRegisterProperties(IBusPropList* ibus_prop_list) {
+ VLOG(1) << "RegisterProperties" << (ibus_prop_list ? "" : " (clear)");
ImePropertyList prop_list; // our representation.
if (ibus_prop_list) {
@@ -838,33 +890,14 @@ class InputMethodStatusConnection {
// here to dump |ibus_prop_list|.
if (!FlattenPropertyList(ibus_prop_list, &prop_list)) {
// Clear properties on errors.
- RegisterProperties(NULL);
+ DoRegisterProperties(NULL);
return;
}
}
+ VLOG(1) << "RegisterProperties" << (ibus_prop_list ? "" : " (clear)");
// Notify the change.
- register_ime_properties_(language_library_, prop_list);
- }
-
- // Handles "UpdateProperty" signal from chromeos_input_method_ui.
- void UpdateProperty(IBusProperty* ibus_prop) {
- DLOG(INFO) << "UpdateProperty";
- DCHECK(ibus_prop);
-
- // You can call
- // LOG(INFO) << "\n" << PrintProp(ibus_prop, 0);
- // here to dump |ibus_prop|.
-
- ImePropertyList prop_list; // our representation.
- if (!FlattenProperty(ibus_prop, &prop_list)) {
- // Don't update the UI on errors.
- LOG(ERROR) << "Malformed properties are detected";
- return;
- }
- // Notify the change.
- if (!prop_list.empty()) {
- update_ime_property_(language_library_, prop_list);
- }
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnRegisterImeProperties(prop_list));
}
// Retrieves input method status and notifies them to the UI.
@@ -895,11 +928,12 @@ class InputMethodStatusConnection {
engine_info->layout,
engine_info->language);
- DLOG(INFO) << "Updating the UI. ID:" << current_input_method.id
- << ", keyboard_layout:" << current_input_method.keyboard_layout;
+ VLOG(1) << "Updating the UI. ID:" << current_input_method.id
+ << ", keyboard_layout:" << current_input_method.keyboard_layout;
// Notify the change to update UI.
- current_input_method_changed_(language_library_, current_input_method);
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnCurrentInputMethodChanged(current_input_method));
}
// Installs gobject signal handlers to |ibus_|.
@@ -914,20 +948,20 @@ class InputMethodStatusConnection {
// to |ibus_|, and the callback in this file use the attached object.
g_signal_connect_after(ibus_,
"connected",
- G_CALLBACK(IBusBusConnectedCallback),
+ G_CALLBACK(IBusBusConnectedThunk),
this);
g_signal_connect(ibus_,
"disconnected",
- G_CALLBACK(IBusBusDisconnectedCallback),
+ G_CALLBACK(IBusBusDisconnectedThunk),
this);
g_signal_connect(ibus_,
"global-engine-changed",
- G_CALLBACK(IBusBusGlobalEngineChangedCallback),
+ G_CALLBACK(IBusBusGlobalEngineChangedThunk),
this);
g_signal_connect(ibus_,
"name-owner-changed",
- G_CALLBACK(IBusBusNameOwnerChangedCallback),
+ G_CALLBACK(IBusBusNameOwnerChangedThunk),
this);
}
@@ -948,69 +982,54 @@ class InputMethodStatusConnection {
g_signal_connect(ibus_panel_service,
"focus-in",
- G_CALLBACK(FocusInCallback),
+ G_CALLBACK(FocusInThunk),
this);
g_signal_connect(ibus_panel_service,
"register-properties",
- G_CALLBACK(RegisterPropertiesCallback),
+ G_CALLBACK(RegisterPropertiesThunk),
this);
g_signal_connect(ibus_panel_service,
"update-property",
- G_CALLBACK(UpdatePropertyCallback),
+ G_CALLBACK(UpdatePropertyThunk),
this);
}
// Handles "connected" signal from ibus-daemon.
- static void IBusBusConnectedCallback(IBusBus* bus, gpointer user_data) {
+ void IBusBusConnected(IBusBus* bus) {
LOG(WARNING) << "IBus connection is recovered.";
- // ibus-daemon might be restarted, or the daemon was not running when Chrome
- // started. Anyway, since |ibus_| connection is now ready, it's possible to
- // create |ibus_config_| object by calling MaybeRestoreConnections().
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
- self->MaybeRestoreConnections();
+ MaybeRestoreConnections();
}
// Handles "disconnected" signal from ibus-daemon.
- static void IBusBusDisconnectedCallback(IBusBus* bus, gpointer user_data) {
+ void IBusBusDisconnected(IBusBus* bus) {
LOG(WARNING) << "IBus connection is terminated.";
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
// ibus-daemon might be terminated. Since |ibus_| object will automatically
// connect to the daemon if it restarts, we don't have to set NULL on ibus_.
// Call MaybeDestroyIBusConfig() to set |ibus_config_| to NULL temporarily.
- self->MaybeDestroyIBusConfig();
- if (self->connection_change_handler_) {
- LOG(INFO) << "Notifying Chrome that IBus is terminated.";
- self->connection_change_handler_(self->language_library_, false);
- }
+ MaybeDestroyIBusConfig();
+ VLOG(1) << "Notifying Chrome that IBus is terminated.";
+ FOR_EACH_OBSERVER(Observer, observers_, OnConnectionChange(false));
}
// Handles "global-engine-changed" signal from ibus-daemon.
- static void IBusBusGlobalEngineChangedCallback(
- IBusBus* bus, const gchar* engine_name, gpointer user_data) {
+ void IBusBusGlobalEngineChanged(IBusBus* bus, const gchar* engine_name) {
DCHECK(engine_name);
- DLOG(INFO) << "Global engine is changed to " << engine_name;
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
- self->UpdateUI(engine_name);
+ VLOG(1) << "Global engine is changed to " << engine_name;
+ UpdateUI(engine_name);
}
// Handles "name-owner-changed" signal from ibus-daemon. The signal is sent
// to libcros when an IBus component such as ibus-memconf, ibus-engine-*, ..
// is started.
- static void IBusBusNameOwnerChangedCallback(
- IBusBus* bus,
- const gchar* name, const gchar* old_name, const gchar* new_name,
- gpointer user_data) {
+ void IBusBusNameOwnerChanged(IBusBus* bus,
+ const gchar* name,
+ const gchar* old_name,
+ const gchar* new_name) {
DCHECK(name);
DCHECK(old_name);
DCHECK(new_name);
- DLOG(INFO) << "Name owner is changed: name=" << name
- << ", old_name=" << old_name << ", new_name=" << new_name;
+ VLOG(1) << "Name owner is changed: name=" << name
+ << ", old_name=" << old_name << ", new_name=" << new_name;
if (name != std::string("org.freedesktop.IBus.Config")) {
// Not a signal for ibus-memconf.
@@ -1023,52 +1042,57 @@ class InputMethodStatusConnection {
LOG(WARNING) << "Unexpected name owner change: name=" << name
<< ", old_name=" << old_name << ", new_name=" << new_name;
// TODO(yusukes): it might be nice to set |ibus_config_| to NULL and call
- // |connection_change_handler_| with false here to allow Chrome to
+ // |OnConnectionChange| with false here to allow Chrome to
// recover all input method configurations when ibus-memconf is
// automatically restarted by ibus-daemon. Though ibus-memconf is pretty
// stable and unlikely crashes.
return;
}
- LOG(INFO) << "IBus config daemon is started. Recovering ibus_config_";
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
+ VLOG(1) << "IBus config daemon is started. Recovering ibus_config_";
// Try to recover |ibus_config_|. If the |ibus_config_| object is
- // successfully created, |connection_change_handler_| will be called to
+ // successfully created, |OnConnectionChange| will be called to
// notify Chrome that IBus is ready.
- self->MaybeRestoreConnections();
+ MaybeRestoreConnections();
}
// Handles "FocusIn" signal from chromeos_input_method_ui.
- static void FocusInCallback(IBusPanelService* panel,
- const gchar* path,
- gpointer user_data) {
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
- self->FocusIn(path);
+ void FocusIn(IBusPanelService* panel, const gchar* input_context_path) {
+ if (!input_context_path) {
+ LOG(ERROR) << "NULL context passed";
+ } else {
+ VLOG(1) << "FocusIn: " << input_context_path;
+ }
+ // Remember the current ic path.
+ input_context_path_ = Or(input_context_path, "");
}
// Handles "RegisterProperties" signal from chromeos_input_method_ui.
- static void RegisterPropertiesCallback(IBusPanelService* panel,
- IBusPropList* prop_list,
- gpointer user_data) {
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
- self->RegisterProperties(prop_list);
+ void RegisterProperties(IBusPanelService* panel, IBusPropList* prop_list) {
+ DoRegisterProperties(prop_list);
}
// Handles "UpdateProperty" signal from chromeos_input_method_ui.
- static void UpdatePropertyCallback(IBusPanelService* panel,
- IBusProperty* ibus_prop,
- gpointer user_data) {
- g_return_if_fail(user_data);
- InputMethodStatusConnection* self
- = static_cast<InputMethodStatusConnection*>(user_data);
- self->UpdateProperty(ibus_prop);
+ void UpdateProperty(IBusPanelService* panel, IBusProperty* ibus_prop) {
+ VLOG(1) << "UpdateProperty";
+ DCHECK(ibus_prop);
+
+ // You can call
+ // LOG(INFO) << "\n" << PrintProp(ibus_prop, 0);
+ // here to dump |ibus_prop|.
+
+ ImePropertyList prop_list; // our representation.
+ if (!FlattenProperty(ibus_prop, &prop_list)) {
+ // Don't update the UI on errors.
+ LOG(ERROR) << "Malformed properties are detected";
+ return;
+ }
+ // Notify the change.
+ if (!prop_list.empty()) {
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnUpdateImeProperty(prop_list));
+ }
}
// A callback function that will be called when ibus_config_set_value_async()
@@ -1097,17 +1121,6 @@ class InputMethodStatusConnection {
g_object_unref(config);
}
- // A function pointers which point LanguageLibrary::XXXHandler functions.
- // The functions are used when libcros receives signals from ibus-daemon.
- LanguageCurrentInputMethodMonitorFunction current_input_method_changed_;
- LanguageRegisterImePropertiesFunction register_ime_properties_;
- LanguageUpdateImePropertyFunction update_ime_property_;
- LanguageConnectionChangeMonitorFunction connection_change_handler_;
-
- // Points to a chromeos::LanguageLibrary object. |language_library_| is used
- // as the first argument of the monitor functions above.
- void* language_library_;
-
// Connection to the ibus-daemon via IBus API. These objects are used to
// call ibus-daemon's API (e.g. activate input methods, set config, ...)
IBusBus* ibus_;
@@ -1115,103 +1128,66 @@ class InputMethodStatusConnection {
// Current input context path.
std::string input_context_path_;
+
+ ObserverList<Observer> observers_;
};
+#endif // defined(HAVE_IBUS)
+
+// The stub implementation is used if IBus is not present.
//
-// cros APIs
-//
+// Note that this class is intentionally built even if HAVE_IBUS is
+// defined so that we can easily tell build breakage when we change the
+// IBusControllerImpl but forget to update the stub implementation.
+class IBusControllerStubImpl : public IBusController {
+ public:
+ IBusControllerStubImpl() {
+ }
-// The function will be bound to chromeos::MonitorInputMethodStatus with dlsym()
-// in load.cc so it needs to be in the C linkage, so the symbol name does not
-// get mangled.
-extern "C"
-InputMethodStatusConnection* ChromeOSMonitorInputMethodStatus(
- void* language_library,
- LanguageCurrentInputMethodMonitorFunction current_input_method_changed,
- LanguageRegisterImePropertiesFunction register_ime_properties,
- LanguageUpdateImePropertyFunction update_ime_property,
- LanguageConnectionChangeMonitorFunction connection_changed) {
- DLOG(INFO) << "MonitorInputMethodStatus";
- return InputMethodStatusConnection::GetConnection(
- language_library,
- current_input_method_changed,
- register_ime_properties,
- update_ime_property,
- connection_changed);
-}
+ virtual void Connect() {
+ };
-extern "C"
-bool ChromeOSStopInputMethodProcess(InputMethodStatusConnection* connection) {
- g_return_val_if_fail(connection, false);
- return connection->StopInputMethodProcess();
-}
+ virtual void AddObserver(Observer* observer) {
+ }
-extern "C"
-InputMethodDescriptors* ChromeOSGetSupportedInputMethodDescriptors() {
- InputMethodDescriptors* input_methods = new InputMethodDescriptors;
- for (size_t i = 0; i < arraysize(chromeos::kIBusEngines); ++i) {
- if (InputMethodIdIsWhitelisted(chromeos::kIBusEngines[i].name)) {
- input_methods->push_back(chromeos::CreateInputMethodDescriptor(
- chromeos::kIBusEngines[i].name,
- chromeos::kIBusEngines[i].longname,
- chromeos::kIBusEngines[i].layout,
- chromeos::kIBusEngines[i].language));
- }
+ virtual void RemoveObserver(Observer* observer) {
}
- return input_methods;
-}
-extern "C"
-void ChromeOSSetImePropertyActivated(
- InputMethodStatusConnection* connection, const char* key, bool activated) {
- DLOG(INFO) << "SetImePropertyeActivated: " << key << ": " << activated;
- DCHECK(key);
- g_return_if_fail(connection);
- connection->SetImePropertyActivated(key, activated);
-}
+ virtual bool StopInputMethodProcess() {
+ return true;
+ }
-extern "C"
-bool ChromeOSChangeInputMethod(
- InputMethodStatusConnection* connection, const char* name) {
- DCHECK(name);
- DLOG(INFO) << "ChangeInputMethod: " << name;
- g_return_val_if_fail(connection, false);
- return connection->ChangeInputMethod(name);
-}
+ virtual bool ChangeInputMethod(const std::string& name) {
+ return true;
+ }
-extern "C"
-bool ChromeOSSetImeConfig(InputMethodStatusConnection* connection,
- const char* section,
- const char* config_name,
- const ImeConfigValue& value) {
- DCHECK(section);
- DCHECK(config_name);
- g_return_val_if_fail(connection, FALSE);
- return connection->SetImeConfig(section, config_name, value);
-}
+ virtual void SetImePropertyActivated(const std::string& key,
+ bool activated) {
+ }
-extern "C"
-std::string ChromeOSGetKeyboardOverlayId(const std::string& input_method_id) {
- for (size_t i = 0; i < arraysize(kKeyboardOverlayMap); ++i) {
- if (kKeyboardOverlayMap[i].input_method_id == input_method_id) {
- return kKeyboardOverlayMap[i].keyboard_overlay_id;
- }
+ virtual bool SetImeConfig(const std::string& section,
+ const std::string& config_name,
+ const ImeConfigValue& value) {
+ return true;
}
- return "";
-}
-extern "C"
-void ChromeOSSendHandwritingStroke(InputMethodStatusConnection* connection,
- const HandwritingStroke& stroke) {
- g_return_if_fail(connection);
- connection->SendHandwritingStroke(stroke);
+ virtual void SendHandwritingStroke(const HandwritingStroke& stroke) {
+ }
+
+ virtual void CancelHandwriting(int n_strokes) {
+ }
+};
+
+IBusController* IBusController::Create() {
+#if defined(HAVE_IBUS)
+ return IBusControllerImpl::GetInstance();
+#else
+ return new IBusControllerStubImpl;
+#endif
}
-extern "C"
-void ChromeOSCancelHandwriting(InputMethodStatusConnection* connection,
- int n_strokes) {
- g_return_if_fail(connection);
- connection->CancelHandwriting(n_strokes);
+IBusController::~IBusController() {
}
+} // namespace input_method
} // namespace chromeos
diff --git a/chrome/browser/chromeos/input_method/ibus_controller.h b/chrome/browser/chromeos/input_method/ibus_controller.h
index 741319d..49aac00 100644
--- a/chrome/browser/chromeos/input_method/ibus_controller.h
+++ b/chrome/browser/chromeos/input_method/ibus_controller.h
@@ -1,20 +1,21 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 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_INPUT_METHOD_H_
-#define CHROMEOS_INPUT_METHOD_H_
+#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_
+#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_
#include <sstream>
#include <string>
#include <utility>
#include <vector>
-#include <base/basictypes.h>
-#include <base/logging.h> // DCHECK
-#include <base/string_split.h>
+#include "base/basictypes.h"
+#include "base/logging.h" // DCHECK
+#include "base/string_split.h"
namespace chromeos {
+namespace input_method {
// A structure which represents an input method. All methods in this class have
// to be in chromeos_input_method.h since Chrome also creates an instance of
@@ -189,122 +190,126 @@ struct ImeConfigValue {
std::vector<std::string> string_list_value;
};
-// A monitor function which is called when current input method is changed by a
-// user.
-typedef void(*LanguageCurrentInputMethodMonitorFunction)(
- void* language_library, const InputMethodDescriptor& current_input_method);
-
-// A monitor function which is called when "RegisterProperties" signal is sent
-// from ibus-daemon. The signal contains a list of properties for a specific
-// input method engine. For example, Japanese input method might have the
-// following properties:
-//
-// ----------------------------------
-// key: InputMode.Hiragana
-// label: Hiragana
-// is_selection_item: true
-// is_selection_item_checked: true
-// selection_item_id: 1
-// ----------------------------------
-// key: InputMode.Katakana
-// label: Katakana
-// is_selection_item: true
-// is_selection_item_checked: false
-// selection_item_id: 1
-// ----------------------------------
-// ...
-// ----------------------------------
-typedef void(*LanguageRegisterImePropertiesFunction)(
- void* language_library, const ImePropertyList& prop_list);
-
-// A monitor function which is called when "UpdateProperty" signal is sent
-// from ibus-daemon. The signal contains one or more properties which is updated
-// recently. Keys the signal contains are a subset of keys registered by the
-// "RegisterProperties" signal above. For example,
-// Japanese input method might send the following properties:
-//
-// ----------------------------------
-// key: InputMode.Hiragana
-// label: Hiragana
-// is_selection_item: true
-// is_selection_item_checked: false
-// selection_item_id: ...
-// ----------------------------------
-// key: InputMode.Katakana
-// label: Katakana
-// is_selection_item: true
-// is_selection_item_checked: true
-// selection_item_id: ...
-// ----------------------------------
-//
-// Note: Please do not use selection_item_ids in |prop_list|. Dummy values are
-// filled in the field.
-typedef void(*LanguageUpdateImePropertyFunction)(
- void* language_library, const ImePropertyList& prop_list);
-
-// A monitor function which is called when ibus connects or disconnects.
-typedef void(*LanguageConnectionChangeMonitorFunction)(
- void* language_library, bool connected);
-
-// Establishes IBus connection to the ibus-daemon. LanguageXXXFunction functions
-// will be called when status of input method engines is changed.
-class InputMethodStatusConnection;
-extern InputMethodStatusConnection* (*MonitorInputMethodStatus)(
- void* language_library,
- LanguageCurrentInputMethodMonitorFunction current_input_method,
- LanguageRegisterImePropertiesFunction register_ime_properties,
- LanguageUpdateImePropertyFunction update_ime_property,
- LanguageConnectionChangeMonitorFunction connection_changed);
-
-// Stops ibus-daemon. Returns true on success.
-extern bool (*StopInputMethodProcess)(InputMethodStatusConnection* connection);
-
-// Gets all input method engines that are supported, including ones not active.
-// Caller has to delete the returned list. This function never returns NULL.
-extern InputMethodDescriptors* (*GetSupportedInputMethodDescriptors)();
-
-// Changes the current input method engine to |name|. Returns true on success.
-// Examples of names: "pinyin", "m17n:ar:kbd", "xkb:us:dvorak:eng".
-extern bool (*ChangeInputMethod)(
- InputMethodStatusConnection* connection, const char* name);
-
-// Sets whether the input method property specified by |key| is activated.
-// If |activated| is true, activates the property. If |activated| is false,
-// deactivates the property.
-// TODO(yusukes): "SetInputMethodPropertyActivated" might be better?
-extern void (*SetImePropertyActivated)(InputMethodStatusConnection* connection,
- const char* key,
- bool activated);
-
-// Sets a configuration of ibus-daemon or IBus engines to |value|.
-// Returns true if the configuration is successfully set.
-//
-// To set 'panel/custom_font', |section| should be "panel", and
-// |config_name| should be "custom_font".
-// TODO(yusukes): "SetInputMethodConfig" might be better?
-extern bool (*SetImeConfig)(InputMethodStatusConnection* connection,
- const char* section,
- const char* config_name,
- const ImeConfigValue& value);
-
-// Returns the keyboard overlay ID corresponding to |input_method_id|.
-// Returns an empty string if there is no corresponding keyboard overlay ID.
-extern std::string (*GetKeyboardOverlayId)(
- const std::string& input_method_id);
-
-// Sends a handwriting stroke to ibus-daemon. The std::pair contains x and y
-// coordinates. (0.0, 0.0) represents the top-left corner of a handwriting area,
-// and (1.0, 1.0) does the bottom-right. For example, the second stroke for ロ
-// (Katakana character Ro) would be something like [(0,0), (1,0), (1,1)].
-// stroke.size() should always be >= 2 (i.e. a single dot is not allowed).
typedef std::vector<std::pair<double, double> > HandwritingStroke;
-extern void (*SendHandwritingStroke)(
- InputMethodStatusConnection* connection, const HandwritingStroke& stroke);
-// Clears the last N handwriting strokes. Pass zero for clearing all strokes.
-// TODO(yusukes): Currently ibus-daemon only accepts 0 for |n_strokes|.
-extern void (*CancelHandwriting)(InputMethodStatusConnection* connection,
- int n_strokes);
+// IBusController is used to interact with the IBus daemon.
+class IBusController {
+ public:
+ class Observer {
+ public:
+ virtual ~Observer() {}
+
+ // Called when current input method is changed by a user.
+ virtual void OnCurrentInputMethodChanged(
+ const InputMethodDescriptor& current_input_method) = 0;
+
+ // Called when "RegisterProperties" signal is sent from
+ // ibus-daemon. The signal contains a list of properties for a
+ // specific input method engine. For example, Japanese input method
+ // might have the following properties:
+ //
+ // ----------------------------------
+ // key: InputMode.Hiragana
+ // label: Hiragana
+ // is_selection_item: true
+ // is_selection_item_checked: true
+ // selection_item_id: 1
+ // ----------------------------------
+ // key: InputMode.Katakana
+ // label: Katakana
+ // is_selection_item: true
+ // is_selection_item_checked: false
+ // selection_item_id: 1
+ // ----------------------------------
+ // ...
+ // ----------------------------------
+ virtual void OnRegisterImeProperties(const ImePropertyList& prop_list) = 0;
+
+ // Called when "UpdateProperty" signal is sent from ibus-daemon. The
+ // signal contains one or more properties which is updated
+ // recently. Keys the signal contains are a subset of keys registered
+ // by the "RegisterProperties" signal above. For example, Japanese
+ // input method might send the following properties:
+ //
+ // ----------------------------------
+ // key: InputMode.Hiragana
+ // label: Hiragana
+ // is_selection_item: true
+ // is_selection_item_checked: false
+ // selection_item_id: ...
+ // ----------------------------------
+ // key: InputMode.Katakana
+ // label: Katakana
+ // is_selection_item: true
+ // is_selection_item_checked: true
+ // selection_item_id: ...
+ // ----------------------------------
+ //
+ // Note: Please do not use selection_item_ids in |prop_list|. Dummy
+ // values are filled in the field.
+ virtual void OnUpdateImeProperty(const ImePropertyList& prop_list) = 0;
+
+ // Called when ibus connects or disconnects.
+ virtual void OnConnectionChange(bool connected) = 0;
+ };
+
+ // Creates an instance of the class. The constructor is unused.
+ static IBusController* Create();
+
+ virtual ~IBusController();
+
+ // Connects to the IBus daemon.
+ virtual void Connect() = 0;
+
+ // Adds and removes observers for IBus UI notifications. Clients must be
+ // sure to remove the observer before they go away. To capture the
+ // initial connection change, you should add an observer before calling
+ // Connect().
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
+ // Stops ibus-daemon. Returns true on success.
+ virtual bool StopInputMethodProcess() = 0;
+
+ // Changes the current input method engine to |name|. Returns true on
+ // success. Examples of names: "pinyin", "m17n:ar:kbd",
+ // "xkb:us:dvorak:eng".
+ virtual bool ChangeInputMethod(const std::string& name) = 0;
+
+ // Sets whether the input method property specified by |key| is activated.
+ // If |activated| is true, activates the property. If |activated| is false,
+ // deactivates the property.
+ // TODO(yusukes): "SetInputMethodPropertyActivated" might be better?
+ virtual void SetImePropertyActivated(const std::string& key,
+ bool activated) = 0;
+
+ // Sets a configuration of ibus-daemon or IBus engines to |value|.
+ // Returns true if the configuration is successfully set.
+ //
+ // To set 'panel/custom_font', |section| should be "panel", and
+ // |config_name| should be "custom_font".
+ // TODO(yusukes): "SetInputMethodConfig" might be better?
+ virtual bool SetImeConfig(const std::string& section,
+ const std::string& config_name,
+ const ImeConfigValue& value) = 0;
+
+ // Sends a handwriting stroke to ibus-daemon. The std::pair contains x
+ // and y coordinates. (0.0, 0.0) represents the top-left corner of a
+ // handwriting area, and (1.0, 1.0) does the bottom-right. For example,
+ // the second stroke for U+30ED (Katakana character Ro) would be
+ // something like [(0,0), (1,0), (1,1)]. stroke.size() should always be
+ // >= 2 (i.e. a single dot is not allowed).
+ virtual void SendHandwritingStroke(const HandwritingStroke& stroke) = 0;
+
+ // Clears the last N handwriting strokes. Pass zero for clearing all strokes.
+ // TODO(yusukes): Currently ibus-daemon only accepts 0 for |n_strokes|.
+ virtual void CancelHandwriting(int n_strokes) = 0;
+};
+
+// Gets all input method engines that are supported, including ones not
+// active. Caller has to delete the returned list. This function never
+// returns NULL.
+InputMethodDescriptors* GetSupportedInputMethodDescriptors();
//
// FUNCTIONS BELOW ARE ONLY FOR UNIT TESTS. DO NOT USE THEM.
@@ -317,6 +322,7 @@ InputMethodDescriptor CreateInputMethodDescriptor(
const std::string& raw_layout,
const std::string& language_code);
+} // namespace input_method
} // namespace chromeos
-#endif // CHROMEOS_INPUT_METHOD_H_
+#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_CONTROLLER_H_
diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc
index fdb1f89..9054905 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.cc
+++ b/chrome/browser/chromeos/input_method/input_method_util.cc
@@ -27,12 +27,20 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_collator.h"
+#if defined(HAVE_IBUS)
+// TODO(satorux): Move these to Chrome tree.
+#include <cros/chromeos_keyboard_overlay_map.h>
+#endif
+
+namespace chromeos {
+namespace input_method {
+
namespace {
// Map from language code to associated input method IDs, etc.
typedef std::multimap<std::string, std::string> LanguageCodeToIdsMap;
// Map from input method ID to associated input method descriptor.
-typedef std::map<std::string, chromeos::InputMethodDescriptor>
+typedef std::map<std::string, InputMethodDescriptor>
InputMethodIdToDescriptorMap;
// Map from layout name to associated overlay ID
typedef std::map<std::string, std::string> InputMethodNameToOverlayIdMap;
@@ -49,9 +57,9 @@ struct IdMaps {
}
void ReloadMaps() {
- chromeos::InputMethodLibrary* library =
- chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
- scoped_ptr<chromeos::InputMethodDescriptors> supported_input_methods(
+ InputMethodLibrary* library =
+ CrosLibrary::Get()->GetInputMethodLibrary();
+ scoped_ptr<InputMethodDescriptors> supported_input_methods(
library->GetSupportedInputMethods());
if (supported_input_methods->size() <= 1) {
LOG(ERROR) << "GetSupportedInputMethods returned a fallback ID";
@@ -65,12 +73,10 @@ struct IdMaps {
name_to_overlay_id->clear();
for (size_t i = 0; i < supported_input_methods->size(); ++i) {
- const chromeos::InputMethodDescriptor& input_method =
+ const InputMethodDescriptor& input_method =
supported_input_methods->at(i);
const std::string language_code =
- chromeos::input_method::GetLanguageCodeFromDescriptor(input_method);
- const std::string keyboard_overlay_id =
- library->GetKeyboardOverlayId(input_method.id);
+ GetLanguageCodeFromDescriptor(input_method);
language_code_to_ids->insert(
std::make_pair(language_code, input_method.id));
// Remember the pairs.
@@ -78,12 +84,9 @@ struct IdMaps {
std::make_pair(input_method.id, language_code));
id_to_descriptor->insert(
std::make_pair(input_method.id, input_method));
- name_to_overlay_id->insert(
- std::make_pair(input_method.keyboard_layout, keyboard_overlay_id));
}
// Go through the languages listed in kExtraLanguages.
- using chromeos::input_method::kExtraLanguages;
for (size_t i = 0; i < arraysize(kExtraLanguages); ++i) {
const char* language_code = kExtraLanguages[i].language_code;
const char* input_method_id = kExtraLanguages[i].input_method_id;
@@ -92,13 +95,9 @@ struct IdMaps {
// If the associated input method descriptor is found, add the
// language code and the input method.
if (iter != id_to_descriptor->end()) {
- const chromeos::InputMethodDescriptor& input_method = iter->second;
- const std::string keyboard_overlay_id =
- library->GetKeyboardOverlayId(input_method.id);
+ const InputMethodDescriptor& input_method = iter->second;
language_code_to_ids->insert(
std::make_pair(language_code, input_method.id));
- name_to_overlay_id->insert(
- std::make_pair(input_method.keyboard_layout, keyboard_overlay_id));
}
}
}
@@ -292,9 +291,9 @@ struct CompareLanguageCodesByLanguageName
// list is short (about 40 at most).
bool operator()(const std::string& s1, const std::string& s2) const {
const string16 key1 =
- chromeos::input_method::GetLanguageDisplayNameFromCode(s1);
+ GetLanguageDisplayNameFromCode(s1);
const string16 key2 =
- chromeos::input_method::GetLanguageDisplayNameFromCode(s2);
+ GetLanguageDisplayNameFromCode(s2);
return l10n_util::StringComparator<string16>(collator_)(key1, key2);
}
@@ -366,9 +365,6 @@ bool GetLocalizedString(const std::string& english_string,
} // namespace
-namespace chromeos {
-namespace input_method {
-
std::wstring GetString(const std::string& english_string,
const std::string& input_method_id) {
string16 localized_string;
@@ -503,11 +499,15 @@ std::string GetKeyboardLayoutName(const std::string& input_method_id) {
"" : iter->second.keyboard_layout;
}
-std::string GetKeyboardOverlayId(const std::string& input_method_name) {
- std::map<std::string, std::string>::const_iterator iter
- = IdMaps::GetInstance()->name_to_overlay_id->find(input_method_name);
- return (iter == IdMaps::GetInstance()->name_to_overlay_id->end()) ?
- "" : iter->second;
+std::string GetKeyboardOverlayId(const std::string& input_method_id) {
+#if defined(HAVE_IBUS)
+ for (size_t i = 0; i < arraysize(kKeyboardOverlayMap); ++i) {
+ if (kKeyboardOverlayMap[i].input_method_id == input_method_id) {
+ return kKeyboardOverlayMap[i].keyboard_overlay_id;
+ }
+ }
+#endif // defined(HAVE_IBUS)
+ return "";
}
std::string GetInputMethodDisplayNameFromId(
@@ -518,7 +518,7 @@ std::string GetInputMethodDisplayNameFromId(
"" : GetStringUTF8(iter->second.display_name, input_method_id);
}
-const chromeos::InputMethodDescriptor* GetInputMethodDescriptorFromId(
+const InputMethodDescriptor* GetInputMethodDescriptorFromId(
const std::string& input_method_id) {
InputMethodIdToDescriptorMap::const_iterator iter
= IdMaps::GetInstance()->id_to_descriptor->find(input_method_id);
@@ -608,8 +608,8 @@ void GetFirstLoginInputMethodIds(
std::string most_popular_id;
std::vector<std::string> input_method_ids;
// This returns the input methods sorted by popularity.
- input_method::GetInputMethodIdsFromLanguageCode(
- language_code, input_method::kAllInputMethods, &input_method_ids);
+ GetInputMethodIdsFromLanguageCode(
+ language_code, kAllInputMethods, &input_method_ids);
for (size_t i = 0; i < input_method_ids.size(); ++i) {
const std::string& input_method_id = input_method_ids[i];
// Pick the first one.
diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h
index 3c243bf..a9c63b6 100644
--- a/chrome/browser/chromeos/input_method/input_method_util.h
+++ b/chrome/browser/chromeos/input_method/input_method_util.h
@@ -86,10 +86,10 @@ std::string GetKeyboardLayoutName(const std::string& input_method_id);
//
// Examples:
//
-// "us" => "en_US"
-// "us(dvorak)" => "en_US_dvorak"
-// "gb" => "en_GB"
-std::string GetKeyboardOverlayId(const std::string& input_method_name);
+// "xkb:us::eng" => "en_US"
+// "xkb:us:dvorak:eng" => "en_US_dvorak"
+// "xkb:gb::eng" => "en_GB"
+std::string GetKeyboardOverlayId(const std::string& input_method_id);
// Converts an input method ID to a language code of the IME. Returns "Eng"
// when |input_method_id| is unknown.
@@ -107,7 +107,7 @@ std::string GetInputMethodDisplayNameFromId(const std::string& input_method_id);
// when |input_method_id| is unknown.
// Example: "pinyin" => { id: "pinyin", display_name: "Pinyin",
// keyboard_layout: "us", language_code: "zh" }
-const chromeos::InputMethodDescriptor* GetInputMethodDescriptorFromId(
+const InputMethodDescriptor* GetInputMethodDescriptorFromId(
const std::string& input_method_id);
// Converts a language code to a language display name, using the
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc
index 0e4f68de..f4dfc28 100644
--- a/chrome/browser/chromeos/login/screen_locker.cc
+++ b/chrome/browser/chromeos/login/screen_locker.cc
@@ -120,8 +120,8 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
saved_previous_input_method_id_ = library->previous_input_method().id;
saved_current_input_method_id_ = library->current_input_method().id;
- scoped_ptr<chromeos::InputMethodDescriptors> active_input_method_list(
- library->GetActiveInputMethods());
+ scoped_ptr<chromeos::input_method::InputMethodDescriptors>
+ active_input_method_list(library->GetActiveInputMethods());
const std::string hardware_keyboard_id =
chromeos::input_method::GetHardwareInputMethodId();
@@ -130,8 +130,8 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
// keyboard on the screen locker.
bool should_add_hardware_keyboard = true;
- chromeos::ImeConfigValue value;
- value.type = chromeos::ImeConfigValue::kValueTypeStringList;
+ chromeos::input_method::ImeConfigValue value;
+ value.type = chromeos::input_method::ImeConfigValue::kValueTypeStringList;
for (size_t i = 0; i < active_input_method_list->size(); ++i) {
const std::string& input_method_id = active_input_method_list->at(i).id;
saved_active_input_method_list_.push_back(input_method_id);
@@ -162,8 +162,8 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer,
chromeos::InputMethodLibrary* library =
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
- chromeos::ImeConfigValue value;
- value.type = chromeos::ImeConfigValue::kValueTypeStringList;
+ chromeos::input_method::ImeConfigValue value;
+ value.type = chromeos::input_method::ImeConfigValue::kValueTypeStringList;
value.string_list_value = saved_active_input_method_list_;
library->SetEnableAutoImeShutdown(true);
library->SetImeConfig(
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 67011bd..8a4ae82 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -445,8 +445,8 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) {
void Preferences::SetLanguageConfigBoolean(const char* section,
const char* name,
bool value) {
- ImeConfigValue config;
- config.type = ImeConfigValue::kValueTypeBool;
+ input_method::ImeConfigValue config;
+ config.type = input_method::ImeConfigValue::kValueTypeBool;
config.bool_value = value;
CrosLibrary::Get()->GetInputMethodLibrary()->
SetImeConfig(section, name, config);
@@ -455,8 +455,8 @@ void Preferences::SetLanguageConfigBoolean(const char* section,
void Preferences::SetLanguageConfigInteger(const char* section,
const char* name,
int value) {
- ImeConfigValue config;
- config.type = ImeConfigValue::kValueTypeInt;
+ input_method::ImeConfigValue config;
+ config.type = input_method::ImeConfigValue::kValueTypeInt;
config.int_value = value;
CrosLibrary::Get()->GetInputMethodLibrary()->
SetImeConfig(section, name, config);
@@ -465,8 +465,8 @@ void Preferences::SetLanguageConfigInteger(const char* section,
void Preferences::SetLanguageConfigString(const char* section,
const char* name,
const std::string& value) {
- ImeConfigValue config;
- config.type = ImeConfigValue::kValueTypeString;
+ input_method::ImeConfigValue config;
+ config.type = input_method::ImeConfigValue::kValueTypeString;
config.string_value = value;
CrosLibrary::Get()->GetInputMethodLibrary()->
SetImeConfig(section, name, config);
@@ -476,8 +476,8 @@ void Preferences::SetLanguageConfigStringList(
const char* section,
const char* name,
const std::vector<std::string>& values) {
- ImeConfigValue config;
- config.type = ImeConfigValue::kValueTypeStringList;
+ input_method::ImeConfigValue config;
+ config.type = input_method::ImeConfigValue::kValueTypeStringList;
for (size_t i = 0; i < values.size(); ++i)
config.string_list_value.push_back(values[i]);
diff --git a/chrome/browser/chromeos/status/input_method_menu.cc b/chrome/browser/chromeos/status/input_method_menu.cc
index 3fc9cff..3cff93e 100644
--- a/chrome/browser/chromeos/status/input_method_menu.cc
+++ b/chrome/browser/chromeos/status/input_method_menu.cc
@@ -191,14 +191,14 @@ bool InputMethodMenu::IsItemCheckedAt(int index) const {
DCHECK(input_method_descriptors_.get());
if (IndexIsInInputMethodList(index)) {
- const InputMethodDescriptor& input_method
+ const input_method::InputMethodDescriptor& input_method
= input_method_descriptors_->at(index);
return input_method == CrosLibrary::Get()->GetInputMethodLibrary()->
current_input_method();
}
if (GetPropertyIndex(index, &index)) {
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
return property_list.at(index).is_selection_item_checked;
}
@@ -216,7 +216,7 @@ int InputMethodMenu::GetGroupIdAt(int index) const {
}
if (GetPropertyIndex(index, &index)) {
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
return property_list.at(index).selection_item_id;
}
@@ -283,7 +283,7 @@ ui::MenuModel::ItemType InputMethodMenu::GetTypeAt(int index) const {
}
if (GetPropertyIndex(index, &index)) {
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
if (property_list.at(index).is_selection_item) {
return ui::MenuModel::TYPE_RADIO;
@@ -309,7 +309,8 @@ string16 InputMethodMenu::GetLabelAt(int index) const {
name = GetTextForMenu(input_method_descriptors_->at(index));
} else if (GetPropertyIndex(index, &index)) {
InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary();
- const ImePropertyList& property_list = library->current_ime_properties();
+ const input_method::ImePropertyList& property_list =
+ library->current_ime_properties();
const std::string& input_method_id = library->current_input_method().id;
return input_method::GetStringUTF16(
property_list.at(index).label, input_method_id);
@@ -329,7 +330,7 @@ void InputMethodMenu::ActivatedAt(int index) {
if (IndexIsInInputMethodList(index)) {
// Inter-IME switching.
- const InputMethodDescriptor& input_method
+ const input_method::InputMethodDescriptor& input_method
= input_method_descriptors_->at(index);
CrosLibrary::Get()->GetInputMethodLibrary()->ChangeInputMethod(
input_method.id);
@@ -340,7 +341,7 @@ void InputMethodMenu::ActivatedAt(int index) {
if (GetPropertyIndex(index, &index)) {
// Intra-IME switching (e.g. Japanese-Hiragana to Japanese-Katakana).
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
const std::string key = property_list.at(index).key;
if (property_list.at(index).is_selection_item) {
@@ -402,15 +403,15 @@ void InputMethodMenu::RunMenu(views::View* source, const gfx::Point& pt) {
void InputMethodMenu::InputMethodChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) {
UpdateUIFromInputMethod(current_input_method, num_active_input_methods);
}
void InputMethodMenu::PreferenceUpdateNeeded(
InputMethodLibrary* obj,
- const InputMethodDescriptor& previous_input_method,
- const InputMethodDescriptor& current_input_method) {
+ const input_method::InputMethodDescriptor& previous_input_method,
+ const input_method::InputMethodDescriptor& current_input_method) {
if (screen_mode_ == StatusAreaHost::kBrowserMode) {
if (pref_service_) { // make sure we're not in unit tests.
// Sometimes (e.g. initial boot) |previous_input_method.id| is empty.
@@ -429,7 +430,7 @@ void InputMethodMenu::PreferenceUpdateNeeded(
void InputMethodMenu::PropertyListChanged(
InputMethodLibrary* obj,
- const ImePropertyList& current_ime_properties) {
+ const input_method::ImePropertyList& current_ime_properties) {
// Usual order of notifications of input method change is:
// 1. RegisterProperties(empty)
// 2. RegisterProperties(list-of-new-properties)
@@ -444,7 +445,8 @@ void InputMethodMenu::PropertyListChanged(
// awkward clear-then-register behavior.
if (!current_ime_properties.empty()) {
InputMethodLibrary* library = CrosLibrary::Get()->GetInputMethodLibrary();
- const InputMethodDescriptor& input_method = library->current_input_method();
+ const input_method::InputMethodDescriptor& input_method =
+ library->current_input_method();
size_t num_active_input_methods = library->GetNumActiveInputMethods();
UpdateUIFromInputMethod(input_method, num_active_input_methods);
}
@@ -487,7 +489,7 @@ void InputMethodMenu::PrepareMenuModel() {
void InputMethodMenu::ActiveInputMethodsChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods) {
// Update the icon if active input methods are changed. See also
// comments in UpdateUI() in input_method_menu_button.cc.
@@ -495,7 +497,7 @@ void InputMethodMenu::ActiveInputMethodsChanged(
}
void InputMethodMenu::UpdateUIFromInputMethod(
- const InputMethodDescriptor& input_method,
+ const input_method::InputMethodDescriptor& input_method,
size_t num_active_input_methods) {
const std::wstring name = GetTextForIndicator(input_method);
const std::wstring tooltip = GetTextForMenu(input_method);
@@ -519,7 +521,7 @@ void InputMethodMenu::RebuildModel() {
need_separator = true;
}
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
if (!property_list.empty()) {
if (need_separator) {
@@ -569,7 +571,7 @@ bool InputMethodMenu::GetPropertyIndex(int index, int* property_index) const {
if ((model_->GetTypeAt(index) == ui::MenuModel::TYPE_RADIO) &&
(model_->GetCommandIdAt(index) == COMMAND_ID_IME_PROPERTIES)) {
const int tmp_property_index = model_->GetGroupIdAt(index);
- const ImePropertyList& property_list
+ const input_method::ImePropertyList& property_list
= CrosLibrary::Get()->GetInputMethodLibrary()->current_ime_properties();
if (tmp_property_index < static_cast<int>(property_list.size())) {
*property_index = tmp_property_index;
@@ -591,7 +593,7 @@ bool InputMethodMenu::IndexPointsToConfigureImeMenuItem(int index) const {
}
std::wstring InputMethodMenu::GetTextForIndicator(
- const InputMethodDescriptor& input_method) {
+ const input_method::InputMethodDescriptor& input_method) {
// For the status area, we use two-letter, upper-case language code like
// "US" and "JP".
std::wstring text;
@@ -642,7 +644,7 @@ std::wstring InputMethodMenu::GetTextForIndicator(
}
std::wstring InputMethodMenu::GetTextForMenu(
- const InputMethodDescriptor& input_method) {
+ const input_method::InputMethodDescriptor& input_method) {
// We don't show language here. Name of keyboard layout or input method
// usually imply (or explicitly include) its language.
diff --git a/chrome/browser/chromeos/status/input_method_menu.h b/chrome/browser/chromeos/status/input_method_menu.h
index b19acb2..19ae8a2 100644
--- a/chrome/browser/chromeos/status/input_method_menu.h
+++ b/chrome/browser/chromeos/status/input_method_menu.h
@@ -72,19 +72,19 @@ class InputMethodMenu : public views::ViewMenuDelegate,
// InputMethodLibrary::Observer implementation.
virtual void InputMethodChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods);
virtual void ActiveInputMethodsChanged(
InputMethodLibrary* obj,
- const InputMethodDescriptor& current_input_method,
+ const input_method::InputMethodDescriptor& current_input_method,
size_t num_active_input_methods);
virtual void PreferenceUpdateNeeded(
InputMethodLibrary* obj,
- const InputMethodDescriptor& previous_input_method,
- const InputMethodDescriptor& current_input_method);
+ const input_method::InputMethodDescriptor& previous_input_method,
+ const input_method::InputMethodDescriptor& current_input_method);
virtual void PropertyListChanged(
InputMethodLibrary* obj,
- const ImePropertyList& current_ime_properties);
+ const input_method::ImePropertyList& current_ime_properties);
virtual void FirstObserverIsAdded(InputMethodLibrary* obj);
// NotificationObserver implementation.
@@ -109,11 +109,12 @@ class InputMethodMenu : public views::ViewMenuDelegate,
// Returns a string for the indicator on top right corner of the Chrome
// window. The method is public for unit tests.
static std::wstring GetTextForIndicator(
- const InputMethodDescriptor& input_method);
+ const input_method::InputMethodDescriptor& input_method);
// Returns a string for the drop-down menu and the tooltip for the indicator.
// The method is public for unit tests.
- static std::wstring GetTextForMenu(const InputMethodDescriptor& input_method);
+ static std::wstring GetTextForMenu(
+ const input_method::InputMethodDescriptor& input_method);
protected:
// Prepares menu: saves user metrics and rebuilds.
@@ -137,8 +138,9 @@ class InputMethodMenu : public views::ViewMenuDelegate,
virtual void OpenConfigUI() = 0;
// Parses |input_method| and then calls UpdateUI().
- void UpdateUIFromInputMethod(const InputMethodDescriptor& input_method,
- size_t num_active_input_methods);
+ void UpdateUIFromInputMethod(
+ const input_method::InputMethodDescriptor& input_method,
+ size_t num_active_input_methods);
// Rebuilds |model_|. This function should be called whenever
// |input_method_descriptors_| is updated, or ImePropertiesChanged() is
@@ -158,7 +160,7 @@ class InputMethodMenu : public views::ViewMenuDelegate,
bool IndexPointsToConfigureImeMenuItem(int index) const;
// The current input method list.
- scoped_ptr<InputMethodDescriptors> input_method_descriptors_;
+ scoped_ptr<input_method::InputMethodDescriptors> input_method_descriptors_;
// Objects for reading/writing the Chrome prefs.
StringPrefMember previous_input_method_pref_;
diff --git a/chrome/browser/chromeos/status/input_method_menu_button.cc b/chrome/browser/chromeos/status/input_method_menu_button.cc
index c9502f5..47f139a 100644
--- a/chrome/browser/chromeos/status/input_method_menu_button.cc
+++ b/chrome/browser/chromeos/status/input_method_menu_button.cc
@@ -159,7 +159,7 @@ bool InputMethodMenuButton::ShouldSupportConfigUI() {
void InputMethodMenuButton::UpdateUIFromCurrentInputMethod() {
chromeos::InputMethodLibrary* input_method_library =
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
- const InputMethodDescriptor& input_method =
+ const input_method::InputMethodDescriptor& input_method =
input_method_library->current_input_method();
const std::wstring name = InputMethodMenu::GetTextForIndicator(input_method);
const std::wstring tooltip = InputMethodMenu::GetTextForMenu(input_method);
diff --git a/chrome/browser/chromeos/status/input_method_menu_unittest.cc b/chrome/browser/chromeos/status/input_method_menu_unittest.cc
index b80aae3..ac24453 100644
--- a/chrome/browser/chromeos/status/input_method_menu_unittest.cc
+++ b/chrome/browser/chromeos/status/input_method_menu_unittest.cc
@@ -10,6 +10,8 @@
namespace chromeos {
+using input_method::InputMethodDescriptor;
+
TEST(InputMethodMenuTest, GetTextForIndicatorTest) {
ScopedStubCrosEnabler enabler;
// Test normal cases. Two-letter language code should be returned.
diff --git a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
index 878cb18..88c857a 100644
--- a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
@@ -319,7 +319,7 @@ void KeyboardOverlayHandler::RegisterMessages() {
void KeyboardOverlayHandler::GetKeyboardOverlayId(const ListValue* args) {
chromeos::InputMethodLibrary* library =
chromeos::CrosLibrary::Get()->GetInputMethodLibrary();
- const chromeos::InputMethodDescriptor& descriptor =
+ const chromeos::input_method::InputMethodDescriptor& descriptor =
library->current_input_method();
const std::string keyboard_overlay_id =
library->GetKeyboardOverlayId(descriptor.id);
diff --git a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc
index 4b04d74a..8e24098 100644
--- a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.cc
@@ -61,7 +61,7 @@ void CrosLanguageOptionsHandler::GetLocalizedValues(
// GetSupportedInputMethods() never return NULL.
InputMethodLibrary *im_library =
CrosLibrary::Get()->GetInputMethodLibrary();
- scoped_ptr<chromeos::InputMethodDescriptors> descriptors(
+ scoped_ptr<input_method::InputMethodDescriptors> descriptors(
im_library->GetSupportedInputMethods());
localized_strings->Set("languageList", GetLanguageList(*descriptors));
localized_strings->Set("inputMethodList", GetInputMethodList(*descriptors));
@@ -84,15 +84,16 @@ void CrosLanguageOptionsHandler::RegisterMessages() {
}
ListValue* CrosLanguageOptionsHandler::GetInputMethodList(
- const chromeos::InputMethodDescriptors& descriptors) {
+ const input_method::InputMethodDescriptors& descriptors) {
ListValue* input_method_list = new ListValue();
for (size_t i = 0; i < descriptors.size(); ++i) {
- const chromeos::InputMethodDescriptor& descriptor = descriptors[i];
+ const input_method::InputMethodDescriptor& descriptor =
+ descriptors[i];
const std::string language_code =
- chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor);
+ input_method::GetLanguageCodeFromDescriptor(descriptor);
const std::string display_name =
- chromeos::input_method::GetInputMethodDisplayNameFromId(descriptor.id);
+ input_method::GetInputMethodDisplayNameFromId(descriptor.id);
DictionaryValue* dictionary = new DictionaryValue();
dictionary->SetString("id", descriptor.id);
@@ -104,12 +105,12 @@ ListValue* CrosLanguageOptionsHandler::GetInputMethodList(
language_codes->SetBoolean(language_code, true);
// Check kExtraLanguages to see if there are languages associated with
// this input method. If these are present, add these.
- for (size_t j = 0; j < arraysize(chromeos::input_method::kExtraLanguages);
+ for (size_t j = 0; j < arraysize(input_method::kExtraLanguages);
++j) {
const std::string extra_input_method_id =
- chromeos::input_method::kExtraLanguages[j].input_method_id;
+ input_method::kExtraLanguages[j].input_method_id;
const std::string extra_language_code =
- chromeos::input_method::kExtraLanguages[j].language_code;
+ input_method::kExtraLanguages[j].language_code;
if (extra_input_method_id == descriptor.id) {
language_codes->SetBoolean(extra_language_code, true);
}
@@ -123,20 +124,20 @@ ListValue* CrosLanguageOptionsHandler::GetInputMethodList(
}
ListValue* CrosLanguageOptionsHandler::GetLanguageList(
- const chromeos::InputMethodDescriptors& descriptors) {
+ const input_method::InputMethodDescriptors& descriptors) {
std::set<std::string> language_codes;
// Collect the language codes from the supported input methods.
for (size_t i = 0; i < descriptors.size(); ++i) {
- const chromeos::InputMethodDescriptor& descriptor = descriptors[i];
+ const input_method::InputMethodDescriptor& descriptor = descriptors[i];
const std::string language_code =
- chromeos::input_method::GetLanguageCodeFromDescriptor(descriptor);
+ input_method::GetLanguageCodeFromDescriptor(descriptor);
language_codes.insert(language_code);
}
// Collect the language codes from kExtraLanguages.
- for (size_t i = 0; i < arraysize(chromeos::input_method::kExtraLanguages);
+ for (size_t i = 0; i < arraysize(input_method::kExtraLanguages);
++i) {
const char* language_code =
- chromeos::input_method::kExtraLanguages[i].language_code;
+ input_method::kExtraLanguages[i].language_code;
language_codes.insert(language_code);
}
@@ -154,9 +155,9 @@ ListValue* CrosLanguageOptionsHandler::GetLanguageList(
for (std::set<std::string>::const_iterator iter = language_codes.begin();
iter != language_codes.end(); ++iter) {
const string16 display_name =
- chromeos::input_method::GetLanguageDisplayNameFromCode(*iter);
+ input_method::GetLanguageDisplayNameFromCode(*iter);
const string16 native_display_name =
- chromeos::input_method::GetLanguageNativeDisplayNameFromCode(*iter);
+ input_method::GetLanguageNativeDisplayNameFromCode(*iter);
display_names.push_back(display_name);
language_map[display_name] =
std::make_pair(*iter, native_display_name);
diff --git a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h
index c8635f6..0501514 100644
--- a/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h
+++ b/chrome/browser/ui/webui/options/chromeos/cros_language_options_handler.h
@@ -34,14 +34,14 @@ class CrosLanguageOptionsHandler : public LanguageOptionsHandlerCommon {
// Note that true in languageCodeSet does not mean anything. We just use
// the dictionary as a set.
static ListValue* GetInputMethodList(
- const chromeos::InputMethodDescriptors& descriptors);
+ const input_method::InputMethodDescriptors& descriptors);
// Gets the list of languages from the given input descriptors.
// The return value will look like:
// [{'code': 'fi', 'displayName': 'Finnish', 'nativeDisplayName': 'suomi'},
// ...]
static ListValue* GetLanguageList(
- const chromeos::InputMethodDescriptors& descriptors);
+ const input_method::InputMethodDescriptors& descriptors);
private:
// LanguageOptionsHandlerCommon implementation.
diff --git a/chrome/browser/ui/webui/options/language_options_handler_unittest.cc b/chrome/browser/ui/webui/options/language_options_handler_unittest.cc
index d7a9d7c..c426911 100644
--- a/chrome/browser/ui/webui/options/language_options_handler_unittest.cc
+++ b/chrome/browser/ui/webui/options/language_options_handler_unittest.cc
@@ -17,20 +17,21 @@
#endif // defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS)
-static chromeos::InputMethodDescriptors CreateInputMethodDescriptors() {
- chromeos::InputMethodDescriptors descriptors;
+
+using chromeos::input_method::InputMethodDescriptor;
+using chromeos::input_method::InputMethodDescriptors;
+
+static InputMethodDescriptors CreateInputMethodDescriptors() {
+ InputMethodDescriptors descriptors;
descriptors.push_back(
- chromeos::InputMethodDescriptor("xkb:us::eng", "USA",
- "us", "us", "eng"));
+ InputMethodDescriptor("xkb:us::eng", "USA", "us", "us", "eng"));
descriptors.push_back(
- chromeos::InputMethodDescriptor("xkb:fr::fra", "France",
- "fr", "fr", "fra"));
+ InputMethodDescriptor("xkb:fr::fra", "France", "fr", "fr", "fra"));
descriptors.push_back(
- chromeos::InputMethodDescriptor("xkb:be::fra", "Belgium",
- "be", "be", "fr"));
+ InputMethodDescriptor("xkb:be::fra", "Belgium", "be", "be", "fr"));
descriptors.push_back(
- chromeos::InputMethodDescriptor("mozc", "Mozc (US keyboard layout)",
- "us", "us", "ja"));
+ InputMethodDescriptor("mozc", "Mozc (US keyboard layout)",
+ "us", "us", "ja"));
return descriptors;
}
@@ -44,7 +45,7 @@ TEST(LanguageOptionsHandlerTest, GetInputMethodList) {
chromeos::CrosLibrary::Get()->GetTestApi()->SetInputMethodLibrary(NULL,
false);
- chromeos::InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
+ InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
scoped_ptr<ListValue> list(
chromeos::CrosLanguageOptionsHandler::GetInputMethodList(descriptors));
ASSERT_EQ(4U, list->GetSize());
@@ -98,7 +99,7 @@ TEST(LanguageOptionsHandlerTest, GetInputMethodList) {
}
TEST(LanguageOptionsHandlerTest, GetLanguageList) {
- chromeos::InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
+ InputMethodDescriptors descriptors = CreateInputMethodDescriptors();
scoped_ptr<ListValue> list(
chromeos::CrosLanguageOptionsHandler::GetLanguageList(descriptors));
ASSERT_EQ(7U, list->GetSize());
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 851d569..ee55189 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -443,6 +443,8 @@
'browser/chromeos/gview_request_interceptor.h',
'browser/chromeos/input_method/candidate_window.cc',
'browser/chromeos/input_method/candidate_window.h',
+ 'browser/chromeos/input_method/ibus_controller.cc',
+ 'browser/chromeos/input_method/ibus_controller.h',
'browser/chromeos/input_method/input_method_util.cc',
'browser/chromeos/input_method/input_method_util.h',
'browser/chromeos/input_method/virtual_keyboard_selector.cc',
@@ -3632,6 +3634,11 @@
'browser/upgrade_detector_impl.h',
],
}],
+ ['use_ibus==1', {
+ 'dependencies': [
+ '../build/linux/system.gyp:ibus',
+ ],
+ }],
['use_cups==1', {
'dependencies': [
'../printing/printing.gyp:cups',