Bug 1254629 - Let query events fail when content root is wrong; r=masayuki
☠☠ backed out by 2fa9f00493a9 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Fri, 11 Mar 2016 13:47:22 -0500
changeset 339593 fd7564bd9998e88960bcdaca6df3dff2160e459f
parent 339592 ef38f6f97d2f1cdad49149d48bf9989432f1f7c5
child 339594 302353ddf84f0b78847b305583a1cbe713503718
push id12762
push userbmo:rail@mozilla.com
push dateFri, 11 Mar 2016 19:47:45 +0000
reviewersmasayuki
bugs1254629
milestone48.0a1
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,20 @@ 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 (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 +1256,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 }
         ]