Bug 1824634 hold GtkIMContext reference a little longer than preedit-changed a=diannaS

Original Revision: https://phabricator.services.mozilla.com/D182866

Differential Revision: https://phabricator.services.mozilla.com/D183445
This commit is contained in:
Karl Tomlinson 2023-07-13 16:45:41 +00:00
parent 27ce8f6da2
commit 102909885f
2 changed files with 14 additions and 1 deletions

View file

@ -43,6 +43,7 @@ GOBJECT_TRAITS(GdkDragContext)
GOBJECT_TRAITS(GDBusMessage)
GOBJECT_TRAITS(GdkPixbuf)
GOBJECT_TRAITS(GCancellable)
GOBJECT_TRAITS(GtkIMContext)
GOBJECT_TRAITS(GUnixFDList)
#ifdef MOZ_ENABLE_DBUS

View file

@ -10,6 +10,8 @@
#include "prenv.h"
#include "IMContextWrapper.h"
#include "GRefPtr.h"
#include "nsGtkKeyUtils.h"
#include "nsWindow.h"
#include "mozilla/AutoRestore.h"
@ -1728,7 +1730,17 @@ void IMContextWrapper::OnEndCompositionNative(GtkIMContext* aContext) {
/* static */
void IMContextWrapper::OnChangeCompositionCallback(GtkIMContext* aContext,
IMContextWrapper* aModule) {
aModule->OnChangeCompositionNative(aContext);
RefPtr module = aModule;
module->OnChangeCompositionNative(aContext);
if (module->IsDestroyed()) {
// A strong reference is already held during "preedit-changed" emission,
// but _ibus_context_destroy_cb() in ibus 1.5.28 and
// _fcitx_im_context_close_im_cb() in fcitx 4.2.9.9 want their
// GtkIMContexts to live a little longer. See bug 1824634.
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [context = RefPtr{aContext}]() {}));
}
}
void IMContextWrapper::OnChangeCompositionNative(GtkIMContext* aContext) {