Bug 1466910 - 7. Don't coalesce notifyIMEContext calls; r?esawin draft
authorJim Chen <nchen@mozilla.com>
Tue, 19 Jun 2018 16:31:35 -0400
changeset 808553 92fcee67cc58ea48f3fae9d309d3b36dbcc7ef46
parent 808552 0b9366828e1c422ecfa70cf12ff30f761308d51e
child 808554 a4d7b253f78415c40ce09b6ef74ef29d22fb5d65
push id113421
push userbmo:nchen@mozilla.com
push dateTue, 19 Jun 2018 22:59:14 +0000
reviewersesawin
bugs1466910
milestone62.0a1
Bug 1466910 - 7. Don't coalesce notifyIMEContext calls; r?esawin Right now we coalesce notifyIMEContext calls but only for legacy reasons. With the current code we don't want to coalesce calls, in order to be properly notified of blurring and focusing. MozReview-Commit-ID: 6N2jhyyBKui
widget/android/GeckoEditableSupport.cpp
widget/android/GeckoEditableSupport.h
--- a/widget/android/GeckoEditableSupport.cpp
+++ b/widget/android/GeckoEditableSupport.cpp
@@ -1394,39 +1394,35 @@ GeckoEditableSupport::SetInputContext(co
 
     if (mInputContext.mIMEState.mEnabled != IMEState::DISABLED &&
         aAction.UserMightRequestOpenVKB()) {
         // Don't reset keyboard when we should simply open the vkb
         mEditable->NotifyIME(EditableListener::NOTIFY_IME_OPEN_VKB);
         return;
     }
 
-    if (mIMEUpdatingContext) {
-        return;
-    }
-    mIMEUpdatingContext = true;
-
-    RefPtr<GeckoEditableSupport> self(this);
     const bool inPrivateBrowsing = mInputContext.mInPrivateBrowsing;
-    const bool isUserAction = aAction.IsHandlingUserInput() || aContext.mHasHandledUserInput;
+    const bool isUserAction =
+            aAction.IsHandlingUserInput() || aContext.mHasHandledUserInput;
     const int32_t flags =
             (inPrivateBrowsing ? EditableListener::IME_FLAG_PRIVATE_BROWSING : 0) |
             (isUserAction ? EditableListener::IME_FLAG_USER_ACTION : 0);
 
-    nsAppShell::PostEvent([this, self, flags] {
+    // Post an event to keep calls in order relative to NotifyIME.
+    nsAppShell::PostEvent([this, self = RefPtr<GeckoEditableSupport>(this),
+                           flags, context = mInputContext] {
         nsCOMPtr<nsIWidget> widget = GetWidget();
 
-        mIMEUpdatingContext = false;
         if (!widget || widget->Destroyed()) {
             return;
         }
-        mEditable->NotifyIMEContext(mInputContext.mIMEState.mEnabled,
-                                    mInputContext.mHTMLInputType,
-                                    mInputContext.mHTMLInputInputmode,
-                                    mInputContext.mActionHint,
+        mEditable->NotifyIMEContext(context.mIMEState.mEnabled,
+                                    context.mHTMLInputType,
+                                    context.mHTMLInputInputmode,
+                                    context.mActionHint,
                                     flags);
     });
 }
 
 InputContext
 GeckoEditableSupport::GetInputContext()
 {
     InputContext context = mInputContext;
--- a/widget/android/GeckoEditableSupport.h
+++ b/widget/android/GeckoEditableSupport.h
@@ -97,17 +97,16 @@ class GeckoEditableSupport final
     java::GeckoEditableChild::GlobalRef mEditable;
     bool mEditableAttached;
     InputContext mInputContext;
     AutoTArray<UniquePtr<mozilla::WidgetEvent>, 4> mIMEKeyEvents;
     AutoTArray<IMETextChange, 4> mIMETextChanges;
     RefPtr<TextRangeArray> mIMERanges;
     int32_t mIMEMaskEventsCount; // Mask events when > 0.
     int32_t mIMEFocusCount; // We are focused when > 0.
-    bool mIMEUpdatingContext;
     bool mIMESelectionChanged;
     bool mIMETextChangedDuringFlush;
     bool mIMEMonitorCursor;
 
     static bool sDispatchKeyEventsInCompositionForAnyApps;
 
     void ObservePrefs();
 
@@ -177,17 +176,16 @@ public:
                          java::GeckoEditableChild::Param aEditableChild)
         : mIsRemote(!aWindow)
         , mWindow(aPtr, aWindow)
         , mEditable(aEditableChild)
         , mEditableAttached(!mIsRemote)
         , mIMERanges(new TextRangeArray())
         , mIMEMaskEventsCount(1) // Mask IME events since there's no focus yet
         , mIMEFocusCount(0)
-        , mIMEUpdatingContext(false)
         , mIMESelectionChanged(false)
         , mIMETextChangedDuringFlush(false)
         , mIMEMonitorCursor(false)
     {
         ObservePrefs();
     }
 
     // Constructor for content process GeckoEditableChild.