Bug 1083098 Allow to handle GTK composition events if given IM context is same as one of our own IM contexts for cleaning up composition state which is being committed asynchronously r=karlt

This commit is contained in:
Masayuki Nakano 2014-10-24 02:17:15 +09:00
parent 079038b58c
commit 02e8cdd26f
2 changed files with 34 additions and 7 deletions

View File

@ -582,6 +582,17 @@ nsGtkIMModule::GetContext()
return mDummyContext;
}
bool
nsGtkIMModule::IsValidContext(GtkIMContext* aContext) const
{
if (!aContext) {
return false;
}
return aContext == mContext ||
aContext == mSimpleContext ||
aContext == mDummyContext;
}
bool
nsGtkIMModule::IsEnabled()
{
@ -725,7 +736,9 @@ nsGtkIMModule::OnEndCompositionNative(GtkIMContext *aContext)
this, aContext));
// See bug 472635, we should do nothing if IM context doesn't match.
if (GetContext() != aContext) {
// Note that if this is called after focus move, the context may different
// from the result of GetContext().
if (!IsValidContext(aContext)) {
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
(" FAILED, given context doesn't match, GetContext()=%p",
GetContext()));
@ -757,7 +770,9 @@ nsGtkIMModule::OnChangeCompositionNative(GtkIMContext *aContext)
this, aContext));
// See bug 472635, we should do nothing if IM context doesn't match.
if (GetContext() != aContext) {
// Note that if this is called after focus move, the context may different
// from the result of GetContext().
if (!IsValidContext(aContext)) {
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
(" FAILED, given context doesn't match, GetContext()=%p",
GetContext()));
@ -765,7 +780,7 @@ nsGtkIMModule::OnChangeCompositionNative(GtkIMContext *aContext)
}
nsAutoString compositionString;
GetCompositionString(compositionString);
GetCompositionString(aContext, compositionString);
if (!IsComposing() && compositionString.IsEmpty()) {
mDispatchedCompositionString.Truncate();
return; // Don't start the composition with empty string.
@ -927,12 +942,13 @@ nsGtkIMModule::CommitCompositionBy(const nsAString& aString)
}
void
nsGtkIMModule::GetCompositionString(nsAString &aCompositionString)
nsGtkIMModule::GetCompositionString(GtkIMContext* aContext,
nsAString& aCompositionString)
{
gchar *preedit_string;
gint cursor_pos;
PangoAttrList *feedback_list;
gtk_im_context_get_preedit_string(GetContext(), &preedit_string,
gtk_im_context_get_preedit_string(aContext, &preedit_string,
&feedback_list, &cursor_pos);
if (preedit_string && *preedit_string) {
CopyUTF8toUTF16(preedit_string, aCompositionString);
@ -1572,7 +1588,7 @@ nsGtkIMModule::DeleteText(const int32_t aOffset, const uint32_t aNChars)
}
nsAutoString compositionString;
GetCompositionString(compositionString);
GetCompositionString(GetContext(), compositionString);
if (!DispatchCompositionChangeEvent(compositionString, true)) {
PR_LOG(gGtkIMLog, PR_LOG_ALWAYS,
(" FAILED, restoring composition string"));

View File

@ -164,6 +164,16 @@ protected:
eCompositionState_CompositionChangeEventDispatched);
}
/**
* Checks if aContext is valid context for handling composition.
*
* @param aContext An IM context which is specified by native
* composition events.
* @return true if the context is valid context for
* handling composition. Otherwise, false.
*/
bool IsValidContext(GtkIMContext* aContext) const;
#ifdef PR_LOGGING
const char* GetCompositionStateName()
{
@ -264,7 +274,8 @@ protected:
void ResetIME();
// Gets the current composition string by the native APIs.
void GetCompositionString(nsAString &aCompositionString);
void GetCompositionString(GtkIMContext* aContext,
nsAString& aCompositionString);
// Generates our text range array from current composition string.
already_AddRefed<mozilla::TextRangeArray> CreateTextRangeArray();