Bug 806996 part.4 Make sure to recreate nsTextStateManager instance in OnFocusInEditor() and UpdateIMEState() if the focused editor isn't being managed r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 09 Nov 2012 17:40:39 +0900
changeset 112791 c6e3a6eeb3c1d80fcc8faa4ca410e5bb3ac6c259
parent 112790 e89844b9bd7c82d941548f9564f69a86dd7e8e70
child 112792 73a92a915ce3597d7be08e7b748d32fb34f61825
push id17778
push usermasayuki@d-toybox.com
push dateFri, 09 Nov 2012 08:40:54 +0000
treeherdermozilla-inbound@927017027942 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs806996
milestone19.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 806996 part.4 Make sure to recreate nsTextStateManager instance in OnFocusInEditor() and UpdateIMEState() if the focused editor isn't being managed r=smaug
content/events/src/nsIMEStateManager.cpp
--- a/content/events/src/nsIMEStateManager.cpp
+++ b/content/events/src/nsIMEStateManager.cpp
@@ -349,16 +349,25 @@ nsIMEStateManager::OnClickInEditor(nsPre
 void
 nsIMEStateManager::OnFocusInEditor(nsPresContext* aPresContext,
                                    nsIContent* aContent)
 {
   if (sPresContext != aPresContext || sContent != aContent) {
     return;
   }
 
+  // If the nsTextStateManager instance isn't managing the editor actually,
+  // we need to recreate the instance.
+  if (sTextStateObserver) {
+    if (sTextStateObserver->IsManaging(aPresContext, aContent)) {
+      return;
+    }
+    DestroyTextStateManager();
+  }
+
   CreateTextStateManager();
 }
 
 void
 nsIMEStateManager::UpdateIMEState(const IMEState &aNewIMEState,
                                   nsIContent* aContent)
 {
   if (!sPresContext) {
@@ -366,32 +375,44 @@ nsIMEStateManager::UpdateIMEState(const 
     return;
   }
   nsCOMPtr<nsIWidget> widget = sPresContext->GetNearestWidget();
   if (!widget) {
     NS_WARNING("focused widget is not found");
     return;
   }
 
-  // Don't update IME state when enabled state isn't actually changed.
-  InputContext context = widget->GetInputContext();
-  if (context.mIMEState.mEnabled == aNewIMEState.mEnabled) {
-    return;
+  // If the nsTextStateManager instance isn't managing the editor's current
+  // editable root content, the editor frame might be reframed.  We should
+  // recreate the instance at that time.
+  bool createTextStateManager =
+    (!sTextStateObserver ||
+     !sTextStateObserver->IsManaging(sPresContext, aContent));
+
+  bool updateIMEState =
+    (widget->GetInputContext().mIMEState.mEnabled != aNewIMEState.mEnabled);
+
+  if (updateIMEState) {
+    // commit current composition before modifying IME state.
+    NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, widget);
   }
 
-  // commit current composition
-  NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, widget);
-
-  DestroyTextStateManager();
+  if (createTextStateManager) {
+    DestroyTextStateManager();
+  }
 
-  InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
-                            InputContextAction::FOCUS_NOT_CHANGED);
-  SetIMEState(aNewIMEState, aContent, widget, action);
+  if (updateIMEState) {
+    InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
+                              InputContextAction::FOCUS_NOT_CHANGED);
+    SetIMEState(aNewIMEState, aContent, widget, action);
+  }
 
-  CreateTextStateManager();
+  if (createTextStateManager) {
+    CreateTextStateManager();
+  }
 }
 
 IMEState
 nsIMEStateManager::GetNewIMEState(nsPresContext* aPresContext,
                                   nsIContent*    aContent)
 {
   // On Printing or Print Preview, we don't need IME.
   if (aPresContext->Type() == nsPresContext::eContext_PrintPreview ||