Bug 932168 - Use simple IME context when focus field has focus (partially backing out a patch for bug 906072). r=karlt, a=lsblakk
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 29 Oct 2013 18:04:59 +0900
changeset 166444 70ec1d8504b89220cee314c1d33a638c0a4cde00
parent 166443 f142a6919b5cc23dcc74cf59352556c58fc1abb7
child 166445 724a412d965d256f5bf506c44b2b812b4b6ec437
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt, lsblakk
bugs932168, 906072
milestone27.0a2
Bug 932168 - Use simple IME context when focus field has focus (partially backing out a patch for bug 906072). r=karlt, a=lsblakk
widget/gtk/nsGtkIMModule.cpp
--- a/widget/gtk/nsGtkIMModule.cpp
+++ b/widget/gtk/nsGtkIMModule.cpp
@@ -60,16 +60,17 @@ GetEnabledStateName(uint32_t aState)
 }
 #endif
 
 nsGtkIMModule* nsGtkIMModule::sLastFocusedModule = nullptr;
 
 nsGtkIMModule::nsGtkIMModule(nsWindow* aOwnerWindow) :
     mOwnerWindow(aOwnerWindow), mLastFocusedWindow(nullptr),
     mContext(nullptr),
+    mSimpleContext(nullptr),
     mDummyContext(nullptr),
     mCompositionStart(UINT32_MAX), mProcessingKeyEvent(nullptr),
     mCompositionState(eCompositionState_NotComposing),
     mIsIMFocused(false), mIgnoreNativeCompositionEvent(false)
 {
 #ifdef PR_LOGGING
     if (!gGtkIMLog) {
         gGtkIMLog = PR_NewLogModule("nsGtkIMModuleWidgets");
@@ -109,16 +110,38 @@ nsGtkIMModule::Init()
                      this);
     g_signal_connect(mContext, "preedit_start",
                      G_CALLBACK(nsGtkIMModule::OnStartCompositionCallback),
                      this);
     g_signal_connect(mContext, "preedit_end",
                      G_CALLBACK(nsGtkIMModule::OnEndCompositionCallback),
                      this);
 
+    // Simple context
+    mSimpleContext = gtk_im_context_simple_new();
+    gtk_im_context_set_client_window(mSimpleContext, gdkWindow);
+    g_signal_connect(mSimpleContext, "preedit_changed",
+                     G_CALLBACK(&nsGtkIMModule::OnChangeCompositionCallback),
+                     this);
+    g_signal_connect(mSimpleContext, "retrieve_surrounding",
+                     G_CALLBACK(&nsGtkIMModule::OnRetrieveSurroundingCallback),
+                     this);
+    g_signal_connect(mSimpleContext, "delete_surrounding",
+                     G_CALLBACK(&nsGtkIMModule::OnDeleteSurroundingCallback),
+                     this);
+    g_signal_connect(mSimpleContext, "commit",
+                     G_CALLBACK(&nsGtkIMModule::OnCommitCompositionCallback),
+                     this);
+    g_signal_connect(mSimpleContext, "preedit_start",
+                     G_CALLBACK(nsGtkIMModule::OnStartCompositionCallback),
+                     this);
+    g_signal_connect(mSimpleContext, "preedit_end",
+                     G_CALLBACK(nsGtkIMModule::OnEndCompositionCallback),
+                     this);
+
     // Dummy context
     mDummyContext = gtk_im_multicontext_new();
     gtk_im_context_set_client_window(mDummyContext, gdkWindow);
 }
 
 nsGtkIMModule::~nsGtkIMModule()
 {
     if (this == sLastFocusedModule) {
@@ -163,16 +186,22 @@ nsGtkIMModule::OnDestroyWindow(nsWindow*
      */
     if (mContext) {
         PrepareToDestroyContext(mContext);
         gtk_im_context_set_client_window(mContext, nullptr);
         g_object_unref(mContext);
         mContext = nullptr;
     }
 
+    if (mSimpleContext) {
+        gtk_im_context_set_client_window(mSimpleContext, nullptr);
+        g_object_unref(mSimpleContext);
+        mSimpleContext = nullptr;
+    }
+
     if (mDummyContext) {
         // mContext and mDummyContext have the same slaveType and signal_data
         // so no need for another workaround_gtk_im_display_closed.
         gtk_im_context_set_client_window(mDummyContext, nullptr);
         g_object_unref(mDummyContext);
         mDummyContext = nullptr;
     }
 
@@ -543,25 +572,26 @@ nsGtkIMModule::IsVirtualKeyboardOpened()
 }
 
 GtkIMContext*
 nsGtkIMModule::GetContext()
 {
     if (IsEnabled()) {
         return mContext;
     }
-
+    if (mInputContext.mIMEState.mEnabled == IMEState::PASSWORD) {
+        return mSimpleContext;
+    }
     return mDummyContext;
 }
 
 bool
 nsGtkIMModule::IsEnabled()
 {
     return mInputContext.mIMEState.mEnabled == IMEState::ENABLED ||
-           mInputContext.mIMEState.mEnabled == IMEState::PASSWORD ||
            mInputContext.mIMEState.mEnabled == IMEState::PLUGIN;
 }
 
 bool
 nsGtkIMModule::IsEditable()
 {
     return mInputContext.mIMEState.mEnabled == IMEState::ENABLED ||
            mInputContext.mIMEState.mEnabled == IMEState::PLUGIN ||