Bug 1388647 - Part 1: IMEStateManager::OnChangeFocusInternal() shouldn't request to commit composition with sFocusedIMETabParent. r=m_kato, a=lizzard
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 09 Aug 2017 18:04:28 +0900
changeset 423662 498cc4ec01ce7c942419c8fd535caa77cdfc55e9
parent 423661 e8eb71b4df6f142cfaaf532f5d9347bf0c153115
child 423663 d5e6ccaef326591a59a2afb37c450ba3a0ae6409
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, lizzard
bugs1388647
milestone56.0
Bug 1388647 - Part 1: IMEStateManager::OnChangeFocusInternal() shouldn't request to commit composition with sFocusedIMETabParent. r=m_kato, a=lizzard When a remote process has focus and it loses focus, IMEStateManager::OnChangeFocusInternal() sends NOTIFY_IME_OF_BLUR via IMEStateManager::NotifyIMEOfBlurForChildProcess(). Therefore, sFocusedIMETabParent and sFocusedIMEWidget are set to nullptr here. So, if a window becomes active, REQUEST_IME_TO_COMMIT_COMPOSITION in IMEStateManager::OnChangeFocusInternal() won't work because IMEStateManager::NotifyIME() ignores the request because of coming from wrong process. Therefore, IMEStateManager::OnChangeFocusInternal() needs to send REQUEST_TO_COMMIT_COMPOSITION with proper process information which is only stored by TextComposition instance. MozReview-Commit-ID: KNEvOoQtK1E
dom/events/IMEStateManager.cpp
--- a/dom/events/IMEStateManager.cpp
+++ b/dom/events/IMEStateManager.cpp
@@ -472,21 +472,34 @@ IMEStateManager::OnChangeFocusInternal(n
 
   nsCOMPtr<nsIWidget> oldWidget = sWidget;
   nsCOMPtr<nsIWidget> newWidget =
     aPresContext ? aPresContext->GetRootWidget() : nullptr;
   bool focusActuallyChanging =
     (sContent != aContent || sPresContext != aPresContext ||
      oldWidget != newWidget || sActiveTabParent != newTabParent);
 
-  if (oldWidget && focusActuallyChanging) {
-    // If we're deactivating, we shouldn't commit composition forcibly because
-    // the user may want to continue the composition.
-    if (aPresContext) {
-      NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, oldWidget, sFocusedIMETabParent);
+  // If old widget has composition, we may need to commit composition since
+  // a native IME context is shared on all editors on some widgets or all
+  // widgets (it depends on platforms).
+  if (oldWidget && focusActuallyChanging && sTextCompositions) {
+    RefPtr<TextComposition> composition =
+      sTextCompositions->GetCompositionFor(oldWidget);
+    if (composition) {
+      // However, don't commit the composition if we're being inactivated
+      // but the composition should be kept even during deactive.
+      if (aPresContext ||
+          !sFocusedIMEWidget->IMENotificationRequestsRef().
+           WantDuringDeactive()) {
+        MOZ_LOG(sISMLog, LogLevel::Info,
+          ("  OnChangeFocusInternal(), requesting to commit composition to "
+           "the (previous) focused widget"));
+        NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, oldWidget,
+                  composition->GetTabParent());
+      }
     }
   }
 
   if (sActiveIMEContentObserver) {
     // If there is active IMEContentObserver, it means that focused content was
     // in this process.  So, if a tab parent gets focus, it means that the
     // focused editor in this process is being blurred.
     if (newTabParent) {