Bug 1143197 part.2 Assume that composition is committed if a call of gtk_im_context_reset() causes composition string becomes empty r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 20 Mar 2015 01:52:25 +0900
changeset 263328 512d9627cc547e541f0e8c8a85fcf161a1a98c8d
parent 263327 f974fcf50cedaa6a03282f3bb2cc20b496a3f192
child 263329 79ab363969377e90ead61da164b3617163f5ee18
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1143197
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1143197 part.2 Assume that composition is committed if a call of gtk_im_context_reset() causes composition string becomes empty r=m_kato
widget/gtk/nsGtkIMModule.cpp
--- a/widget/gtk/nsGtkIMModule.cpp
+++ b/widget/gtk/nsGtkIMModule.cpp
@@ -433,17 +433,49 @@ nsGtkIMModule::ResetIME()
 
     GtkIMContext* activeContext = GetActiveContext();
     if (MOZ_UNLIKELY(!activeContext)) {
         PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
             ("    FAILED, there are no context"));
         return;
     }
 
+    nsRefPtr<nsGtkIMModule> kungFuDeathGrip(this);
+    nsRefPtr<nsWindow> lastFocusedWindow(mLastFocusedWindow);
+
     gtk_im_context_reset(activeContext);
+
+    // The last focused window might have been destroyed by a DOM event handler
+    // which was called by us during a call of gtk_im_context_reset().
+    if (!lastFocusedWindow ||
+        NS_WARN_IF(lastFocusedWindow != mLastFocusedWindow) ||
+        lastFocusedWindow->Destroyed()) {
+        return;
+    }
+
+    nsAutoString compositionString;
+    GetCompositionString(activeContext, compositionString);
+
+    PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
+        ("GtkIMModule(%p): ResetIME() called gtk_im_context_reset(), "
+         "activeContext=%p, mCompositionState=%s, compositionString=%s, "
+         "mIsIMFocused=%s",
+         this, activeContext, GetCompositionStateName(),
+         NS_ConvertUTF16toUTF8(compositionString).get(),
+         GetBoolName(mIsIMFocused)));
+
+    // XXX IIIMF (ATOK X3 which is one of the Language Engine of it is still
+    //     used in Japan!) sends only "preedit_changed" signal with empty
+    //     composition string synchronously.  Therefore, if composition string
+    //     is now empty string, we should assume that the IME won't send
+    //     "commit" signal.
+    if (IsComposing() && compositionString.IsEmpty()) {
+        // WARNING: The widget might have been gone after this.
+        DispatchCompositionCommitEvent(activeContext, &EmptyString());
+    }
 }
 
 nsresult
 nsGtkIMModule::EndIMEComposition(nsWindow* aCaller)
 {
     if (MOZ_UNLIKELY(IsDestroyed())) {
         return NS_OK;
     }