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 @@
'<!(<(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', {
'use_ibus%': 1,
}, {
......
......@@ -14,6 +14,7 @@
#include <X11/Xutil.h>
#endif
#include "base/command_line.h"
#include "base/basictypes.h"
#include "base/i18n/char_iterator.h"
#include "base/logging.h"
......@@ -31,6 +32,9 @@
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.
int ViewsFlagsFromIBusState(guint32 state) {
return (state & IBUS_LOCK_MASK ? ui::EF_CAPS_LOCK_DOWN : 0) |
......@@ -126,6 +130,9 @@ void ExtractCompositionTextFromIBusPreedit(IBusText* text,
}
}
// A switch to enable InputMethodIBus
const char kEnableInputMethodIBusSwitch[] = "enable-inputmethod-ibus";
} // namespace
namespace views {
......@@ -409,6 +416,22 @@ bool InputMethodIBus::IsActive() {
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() {
ConfirmCompositionText();
}
......
......@@ -41,6 +41,14 @@ class InputMethodIBus : public InputMethodBase {
virtual base::i18n::TextDirection GetInputTextDirection() 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:
// A class to hold all data related to a key event being processed by the
// input method but still has no result back yet.
......
......@@ -431,6 +431,8 @@
'sources/': [
['exclude', 'focus/accelerator_handler_gtk.cc'],
['exclude', 'controls/menu/native_menu_gtk.cc'],
['exclude', 'ime/input_method_gtk.cc'],
['exclude', 'ime/input_method_gtk.h'],
],
'conditions': [
['"<!@(<(pkg-config) --atleast-version=2.0 inputproto || echo $?)"!=""', {
......@@ -440,25 +442,16 @@
['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!': [
'ime/input_method_ibus.cc',
'ime/input_method_ibus.h',
}],
['use_ibus==1', {
'dependencies': [
'../build/linux/system.gyp:ibus',
],
}, { # else: use_ibus != 1
'sources/': [
['exclude', 'ime/input_method_ibus.cc'],
['exclude', 'ime/input_method_ibus.h'],
],
}],
['OS=="win"', {
......
......@@ -44,9 +44,10 @@
#endif
#endif
#if defined(TOUCH_UI) && defined(HAVE_IBUS)
#if defined(HAVE_IBUS)
#include "views/ime/input_method_ibus.h"
#else
#endif
#if !defined(TOUCH_UI)
#include "views/ime/input_method_gtk.h"
#endif
......@@ -619,11 +620,14 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
// already created at this point.
// TODO(suzhe): Always enable input method when we start to use
// RenderWidgetHostViewViews in normal ChromeOS.
#if defined(TOUCH_UI) && defined(HAVE_IBUS)
if (!child_) {
if (!child_ && NativeTextfieldViews::IsTextfieldViewsEnabled()) {
#if defined(TOUCH_UI)
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
if (!child_ && NativeTextfieldViews::IsTextfieldViewsEnabled()) {
input_method_.reset(new InputMethodGtk(this));
#endif
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