Bug 1254629 - Let query events fail when content root is wrong; r=masayuki
☠☠ backed out by 9de09b9ee931 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Wed, 16 Mar 2016 02:16:56 -0400
changeset 328791 0359d3b3dc55c9ad7078f961dbc77afbf0494fb7
parent 328790 6c77fea3aeb0a3c74b15e481b30b68e3fbf947dd
child 328792 79a0959fe96a51a6ad006b66a9da409e7a81715e
push id1146
push userCallek@gmail.com
push dateMon, 25 Jul 2016 16:35:44 +0000
treeherdermozilla-release@a55778f9cd5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1254629
milestone48.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 1254629 - Let query events fail when content root is wrong; r=masayuki Make query events fail (including when caching selection) if the queried content root is different from what we expected. Also, introduce a fix-up to the selection fix in test_imestate.html.
dom/events/IMEContentObserver.cpp
widget/tests/test_imestate.html
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -735,20 +735,21 @@ IMEContentObserver::HandleQueryContentEv
   MOZ_LOG(sIMECOLog, LogLevel::Debug,
     ("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
      "mMessage=%s })", this, ToChar(aEvent->mMessage)));
 
   AutoRestore<bool> handling(mIsHandlingQueryContentEvent);
   mIsHandlingQueryContentEvent = true;
   ContentEventHandler handler(GetPresContext());
   nsresult rv = handler.HandleQueryContentEvent(aEvent);
-  if (aEvent->mSucceeded) {
-    // We need to guarantee that mRootContent should be always same value for
-    // the observing editor.
-    aEvent->mReply.mContentsRoot = mRootContent;
+
+  if (!IsInitializedWithPlugin() &&
+      NS_WARN_IF(aEvent->mReply.mContentsRoot != mRootContent)) {
+    // Focus has changed unexpectedly, so make the query fail.
+    aEvent->mSucceeded = false;
   }
   return rv;
 }
 
 bool
 IMEContentObserver::OnMouseButtonEvent(nsPresContext* aPresContext,
                                        WidgetMouseEvent* aMouseEvent)
 {
@@ -1256,17 +1257,18 @@ IMEContentObserver::UpdateSelectionCache
 
   mSelectionData.ClearSelectionData();
 
   // XXX Cannot we cache some information for reducing the cost to compute
   //     selection offset and writing mode?
   WidgetQueryContentEvent selection(true, eQuerySelectedText, mWidget);
   ContentEventHandler handler(GetPresContext());
   handler.OnQuerySelectedText(&selection);
-  if (NS_WARN_IF(!selection.mSucceeded)) {
+  if (NS_WARN_IF(!selection.mSucceeded) ||
+      NS_WARN_IF(selection.mReply.mContentsRoot != mRootContent)) {
     return false;
   }
 
   mFocusedWidget = selection.mReply.mFocusedWidget;
   mSelectionData.mOffset = selection.mReply.mOffset;
   *mSelectionData.mString = selection.mReply.mString;
   mSelectionData.SetWritingMode(selection.GetWritingMode());
   mSelectionData.mReversed = selection.mReply.mReversed;
--- a/widget/tests/test_imestate.html
+++ b/widget/tests/test_imestate.html
@@ -1227,16 +1227,19 @@ function runEditorFlagChangeTests()
   if (!kIMEEnabledSupported) {
     return;
   }
 
   var description = "runEditorFlagChangeTests: ";
 
   var container = document.getElementById("display");
 
+  // Reset selection from previous tests.
+  window.getSelection().collapse(container, 0);
+
   // the editor has focus directly.
   container.setAttribute("contenteditable", "true");
   container.focus();
 
   is(gFM.focusedElement, container,
      description + "The editor doesn't get focus");
   is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
      description + "IME isn't enabled on HTML editor");
@@ -1247,19 +1250,16 @@ function runEditorFlagChangeTests()
   var editor =
     window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
       getInterface(Components.interfaces.nsIWebNavigation).
       QueryInterface(Components.interfaces.nsIDocShell).editor;
   var editorIMESupport =
     editor.QueryInterface(Components.interfaces.nsIEditorIMESupport);
   var flags = editor.flags;
 
-  // Reset selection from previous tests.
-  editor.selection.collapse(container, 0);
-
   // input characters
   synthesizeCompositionChange(
     { "composition":
       { "string": "\u3078\u3093\u3057\u3093",
         "clauses":
         [
           { "length": 4, "attr": COMPOSITION_ATTR_RAW_CLAUSE }
         ]