Fix to make InputMethodIBus usable on every ChromeOS device (even without TouchUI)

Add switch "--enable-inputmethod-ibus" to enable InputMethodIBus on ChromeOS
Modify gyp files to link IBus

BUG=chromium-os:15566
TEST=manually

Review URL: http://codereview.chromium.org/7004029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86390 0039d316-1c4b-4281-b951-d872f2087c98
parent f8fa8fb9
...@@ -564,7 +564,7 @@ ...@@ -564,7 +564,7 @@
'<!(<(DEPTH)/tools/clang/scripts/plugin_flags.sh)', '<!(<(DEPTH)/tools/clang/scripts/plugin_flags.sh)',
}], }],
# Set 1 to enable ibus support. Currently it is only supported in touchui. # Set use_ibus to 1 to enable ibus support.
['touchui==1 and chromeos==1', { ['touchui==1 and chromeos==1', {
'use_ibus%': 1, 'use_ibus%': 1,
}, { }, {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#endif #endif
#include "base/command_line.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/i18n/char_iterator.h" #include "base/i18n/char_iterator.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -31,6 +32,9 @@ ...@@ -31,6 +32,9 @@
namespace { namespace {
// A global flag to switch the InputMethod implementation to InputMethodIBus
bool inputmethod_ibus_enabled = false;
// Converts ibus key state flags to Views event flags. // Converts ibus key state flags to Views event flags.
int ViewsFlagsFromIBusState(guint32 state) { int ViewsFlagsFromIBusState(guint32 state) {
return (state & IBUS_LOCK_MASK ? ui::EF_CAPS_LOCK_DOWN : 0) | return (state & IBUS_LOCK_MASK ? ui::EF_CAPS_LOCK_DOWN : 0) |
...@@ -126,6 +130,9 @@ void ExtractCompositionTextFromIBusPreedit(IBusText* text, ...@@ -126,6 +130,9 @@ void ExtractCompositionTextFromIBusPreedit(IBusText* text,
} }
} }
// A switch to enable InputMethodIBus
const char kEnableInputMethodIBusSwitch[] = "enable-inputmethod-ibus";
} // namespace } // namespace
namespace views { namespace views {
...@@ -409,6 +416,22 @@ bool InputMethodIBus::IsActive() { ...@@ -409,6 +416,22 @@ bool InputMethodIBus::IsActive() {
return context_ != NULL; return context_ != NULL;
} }
// static
bool InputMethodIBus::IsInputMethodIBusEnabled() {
#if defined(TOUCH_UI)
return true;
#else
return inputmethod_ibus_enabled ||
CommandLine::ForCurrentProcess()->HasSwitch(
kEnableInputMethodIBusSwitch);
#endif
}
// static
void InputMethodIBus::SetEnableInputMethodIBus(bool enabled) {
inputmethod_ibus_enabled = enabled;
}
void InputMethodIBus::FocusedViewWillChange() { void InputMethodIBus::FocusedViewWillChange() {
ConfirmCompositionText(); ConfirmCompositionText();
} }
......
...@@ -41,6 +41,14 @@ class InputMethodIBus : public InputMethodBase { ...@@ -41,6 +41,14 @@ class InputMethodIBus : public InputMethodBase {
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE; virtual bool IsActive() OVERRIDE;
// Returns true when
// 1) built with GYP_DEFINES="touchui=1" or,
// 2) enabled by SetEnabledInputMethodIBus or,
// 3) enabled by command line flag "--enable-inputmethod-ibus"
static bool IsInputMethodIBusEnabled();
// Enable/Disable InputMethodIBus
static void SetEnableInputMethodIBus(bool enabled);
private: private:
// A class to hold all data related to a key event being processed by the // A class to hold all data related to a key event being processed by the
// input method but still has no result back yet. // input method but still has no result back yet.
......
...@@ -431,6 +431,8 @@ ...@@ -431,6 +431,8 @@
'sources/': [ 'sources/': [
['exclude', 'focus/accelerator_handler_gtk.cc'], ['exclude', 'focus/accelerator_handler_gtk.cc'],
['exclude', 'controls/menu/native_menu_gtk.cc'], ['exclude', 'controls/menu/native_menu_gtk.cc'],
['exclude', 'ime/input_method_gtk.cc'],
['exclude', 'ime/input_method_gtk.h'],
], ],
'conditions': [ 'conditions': [
['"<!@(<(pkg-config) --atleast-version=2.0 inputproto || echo $?)"!=""', { ['"<!@(<(pkg-config) --atleast-version=2.0 inputproto || echo $?)"!=""', {
...@@ -440,25 +442,16 @@ ...@@ -440,25 +442,16 @@
['exclude', 'touchui/touch_factory.h'], ['exclude', 'touchui/touch_factory.h'],
], ],
}], }],
['use_ibus==1', {
'dependencies': [
'../build/linux/system.gyp:ibus',
],
'sources/': [
['exclude', 'ime/input_method_gtk.cc'],
['exclude', 'ime/input_method_gtk.h'],
],
}, { # else: use_ibus != 1
'sources/': [
['exclude', 'ime/input_method_ibus.cc'],
['exclude', 'ime/input_method_ibus.h'],
],
}],
], ],
}, { # else: touchui != 1 }],
'sources!': [ ['use_ibus==1', {
'ime/input_method_ibus.cc', 'dependencies': [
'ime/input_method_ibus.h', '../build/linux/system.gyp:ibus',
],
}, { # else: use_ibus != 1
'sources/': [
['exclude', 'ime/input_method_ibus.cc'],
['exclude', 'ime/input_method_ibus.h'],
], ],
}], }],
['OS=="win"', { ['OS=="win"', {
......
...@@ -44,9 +44,10 @@ ...@@ -44,9 +44,10 @@
#endif #endif
#endif #endif
#if defined(TOUCH_UI) && defined(HAVE_IBUS) #if defined(HAVE_IBUS)
#include "views/ime/input_method_ibus.h" #include "views/ime/input_method_ibus.h"
#else #endif
#if !defined(TOUCH_UI)
#include "views/ime/input_method_gtk.h" #include "views/ime/input_method_gtk.h"
#endif #endif
...@@ -619,11 +620,14 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) { ...@@ -619,11 +620,14 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
// already created at this point. // already created at this point.
// TODO(suzhe): Always enable input method when we start to use // TODO(suzhe): Always enable input method when we start to use
// RenderWidgetHostViewViews in normal ChromeOS. // RenderWidgetHostViewViews in normal ChromeOS.
#if defined(TOUCH_UI) && defined(HAVE_IBUS) if (!child_ && NativeTextfieldViews::IsTextfieldViewsEnabled()) {
if (!child_) { #if defined(TOUCH_UI)
input_method_.reset(new InputMethodIBus(this)); input_method_.reset(new InputMethodIBus(this));
#elif defined(HAVE_IBUS)
input_method_.reset(InputMethodIBus::IsInputMethodIBusEnabled() ?
static_cast<InputMethod*>(new InputMethodIBus(this)) :
static_cast<InputMethod*>(new InputMethodGtk(this)));
#else #else
if (!child_ && NativeTextfieldViews::IsTextfieldViewsEnabled()) {
input_method_.reset(new InputMethodGtk(this)); input_method_.reset(new InputMethodGtk(this));
#endif #endif
input_method_->Init(GetWidget()); input_method_->Init(GetWidget());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment