Bug 1554843 - Make PuppetWidget::NotifyIMEOfFocusChange() notify TextEventDispatcher of IME notification requests change. r=m_kato, a=jcristau
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 29 May 2019 12:23:22 +0000
changeset 537034 8165ade66edf77295dd97e5e2f7a69532bab2bcf
parent 537033 492b330e047c1d1e502a9267e27068c15c3cbbef
child 537035 382204429011c89910e360eb3f889b371c020cd5
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, jcristau
bugs1554843
milestone68.0
Bug 1554843 - Make PuppetWidget::NotifyIMEOfFocusChange() notify TextEventDispatcher of IME notification requests change. r=m_kato, a=jcristau When user moves focus to an editable content in a content process, it posts IME-focus notification to the main process. Then, when the main process prepares IME/keyboard handling in editable content, it posts back IME notification requests to the content process. Then, the content process's `PuppetWidget` modifies its IME notification requests, but **not** modifying cache of IME notification requests in its `TextEventDispatcher`. Therefore, `IMEContentObserver` keep referring older IME notification requests which are initialized without IME-focus. Note that `IMEContentObserver` caches the *reference* of cached IME notification requests in `TextEventDispatcher`. So, we need to refresh only the cache of IME notification requests in `TextEventDispatcher`. Differential Revision: https://phabricator.services.mozilla.com/D32821
widget/PuppetWidget.cpp
widget/TextEventDispatcher.h
--- a/widget/PuppetWidget.cpp
+++ b/widget/PuppetWidget.cpp
@@ -784,16 +784,20 @@ nsresult PuppetWidget::NotifyIMEOfFocusC
   mIMENotificationRequestsOfParent =
       IMENotificationRequests(IMENotificationRequests::NOTIFY_ALL);
   RefPtr<PuppetWidget> self = this;
   mBrowserChild->SendNotifyIMEFocus(mContentCache, aIMENotification)
       ->Then(
           mBrowserChild->TabGroup()->EventTargetFor(TaskCategory::UI), __func__,
           [self](IMENotificationRequests&& aRequests) {
             self->mIMENotificationRequestsOfParent = aRequests;
+            if (TextEventDispatcher* dispatcher =
+                    self->GetTextEventDispatcher()) {
+              dispatcher->OnWidgetChangeIMENotificationRequests(self);
+            }
           },
           [self](mozilla::ipc::ResponseRejectReason&& aReason) {
             NS_WARNING("SendNotifyIMEFocus got rejected.");
           });
 
   return NS_OK;
 }
 
--- a/widget/TextEventDispatcher.h
+++ b/widget/TextEventDispatcher.h
@@ -80,16 +80,28 @@ class TextEventDispatcher final {
 
   nsIWidget* GetWidget() const { return mWidget; }
 
   const IMENotificationRequests& IMENotificationRequestsRef() const {
     return mIMENotificationRequests;
   }
 
   /**
+   * OnWidgetChangeIMENotificationRequests() is called when aWidget's
+   * IMENotificationRequest is maybe modified by unusual path.  E.g.,
+   * modified in an async path.
+   */
+  void OnWidgetChangeIMENotificationRequests(nsIWidget* aWidget) {
+    MOZ_ASSERT(aWidget);
+    if (mWidget == aWidget) {
+      UpdateNotificationRequests();
+    }
+  }
+
+  /**
    * GetState() returns current state of this class.
    *
    * @return        NS_OK: Fine to compose text.
    *                NS_ERROR_NOT_INITIALIZED: BeginInputTransaction() or
    *                                          BeginInputTransactionForTests()
    *                                          should be called.
    *                NS_ERROR_NOT_AVAILABLE: The widget isn't available for
    *                                        composition.