Bug 1554843 - Make PuppetWidget::NotifyIMEOfFocusChange() notify TextEventDispatcher of IME notification requests change r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 29 May 2019 12:23:22 +0000
changeset 476046 0553541318c4d5b7aba2a9b195470db9dc5c782e
parent 476045 9ed7d3559da8d71429ffd43d21155cf66918f15b
child 476047 7f30c1db8835cf11237b51835ca26522f8d0c06d
push id36083
push usernerli@mozilla.com
push dateWed, 29 May 2019 15:58:28 +0000
treeherdermozilla-central@2bb77ed1fcc5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1554843
milestone69.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 1554843 - Make PuppetWidget::NotifyIMEOfFocusChange() notify TextEventDispatcher of IME notification requests change r=m_kato 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.