Bug 1248459 - Don't query out-of-bounds selection; r=masayuki
authorJim Chen <nchen@mozilla.com>
Thu, 03 Mar 2016 13:10:07 -0500
changeset 324936 8be0c24081c6ea4b7fc6c33b484ee73df64850d9
parent 324935 e49424ca0ddf8ad7e957db8e9a391aadda81f890
child 324937 9993092fc9c8387bd13b028ab0906a5d2873cbab
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1248459
milestone47.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 1248459 - Don't query out-of-bounds selection; r=masayuki During a query selection event, fail if the selection is outside of the editor's root content. This can happen if the placeholder text in an input field is somehow selected. The placeholder is in a separate element outside of the root content. Also fix a bug in test_imestate, where the selection was not properly reset at the start of a test.
dom/events/ContentEventHandler.cpp
widget/tests/test_imestate.html
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1118,16 +1118,25 @@ static nsresult GetFrameForTextRect(nsIN
 nsresult
 ContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
+  nsINode* const startNode = mFirstSelectedRange->GetStartParent();
+  nsINode* const endNode = mFirstSelectedRange->GetEndParent();
+
+  // Make sure the selection is within the root content range.
+  if (!nsContentUtils::ContentIsDescendantOf(startNode, mRootContent) ||
+      !nsContentUtils::ContentIsDescendantOf(endNode, mRootContent)) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
                "The reply string must be empty");
 
   LineBreakType lineBreakType = GetLineBreakType(aEvent);
   rv = GetFlatTextLengthBefore(mFirstSelectedRange,
                                &aEvent->mReply.mOffset, lineBreakType);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/widget/tests/test_imestate.html
+++ b/widget/tests/test_imestate.html
@@ -1247,16 +1247,19 @@ 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 }
         ]