Merge mozilla-central to mozilla-inbound. a=merge
authorCosmin Sabou <csabou@mozilla.com>
Wed, 15 Aug 2018 04:59:10 +0300
changeset 486698 a699096ae193a22952e1dc33950047c8aad7dc42
parent 486697 9e6ef0b94077b72e1b9bb4bb310bfb561cd94f07 (current diff)
parent 486667 8546719c58dc2310bdafb81fd64a6295c59cd10e (diff)
child 486699 c1f4543fd3fbae487bcfbb5f3bdc5b4fd7911124
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone63.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
Merge mozilla-central to mozilla-inbound. a=merge
editor/libeditor/tests/test_nsIHTMLEditor_selectElement.html
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -1726,61 +1726,37 @@ HTMLEditor::InsertNodeIntoProperAncestor
     }
   }
   return pointToInsert;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SelectElement(Element* aElement)
 {
-  if (NS_WARN_IF(!aElement)) {
-    return NS_ERROR_INVALID_ARG;
-  }
+  // Must be sure that element is contained in the document body
+  if (!IsDescendantOfEditorRoot(aElement)) {
+    return NS_ERROR_NULL_POINTER;
+  }
+
   RefPtr<Selection> selection = GetSelection();
-  if (NS_WARN_IF(!selection)) {
-    return NS_ERROR_FAILURE;
-  }
-  nsresult rv = SelectContentInternal(*selection, *aElement);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  return NS_OK;
-}
-
-nsresult
-HTMLEditor::SelectContentInternal(Selection& aSelection,
-                                  nsIContent& aContentToSelect)
-{
-  // Must be sure that element is contained in the document body
-  if (!IsDescendantOfEditorRoot(&aContentToSelect)) {
-    return NS_ERROR_FAILURE;
-  }
-
-  nsINode* parent = aContentToSelect.GetParentNode();
+  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  nsINode* parent = aElement->GetParentNode();
   if (NS_WARN_IF(!parent)) {
     return NS_ERROR_FAILURE;
   }
 
-  // Don't notify selection change at collapse.
-  AutoUpdateViewBatch notifySelectionChangeOnce(this);
-
-  // XXX Perhaps, Selection should have SelectNode(nsIContent&).
-  int32_t offsetInParent = parent->ComputeIndexOf(&aContentToSelect);
+  int32_t offsetInParent = parent->ComputeIndexOf(aElement);
 
   // Collapse selection to just before desired element,
-  nsresult rv = aSelection.Collapse(parent, offsetInParent);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  // then extend it to just after
-  rv = aSelection.Extend(parent, offsetInParent + 1);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-  return NS_OK;
+  nsresult rv = selection->Collapse(parent, offsetInParent);
+  if (NS_SUCCEEDED(rv)) {
+    // then extend it to just after
+    rv = selection->Extend(parent, offsetInParent + 1);
+  }
+  return rv;
 }
 
 NS_IMETHODIMP
 HTMLEditor::SetCaretAfterElement(Element* aElement)
 {
   // Be sure the element is contained in the document body
   if (!aElement || !IsDescendantOfEditorRoot(aElement)) {
     return NS_ERROR_NULL_POINTER;
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -767,27 +767,16 @@ protected: // Called by helper classes.
   virtual void OnEndHandlingTopLevelEditSubAction() override;
 
 protected: // Shouldn't be used by friend classes
   virtual ~HTMLEditor();
 
   virtual nsresult SelectAllInternal() override;
 
   /**
-   * SelectContentInternal() sets Selection to aContentToSelect to
-   * aContentToSelect + 1 in parent of aContentToSelect.
-   *
-   * @param aSelection          The Selection, callers have to guarantee the
-   *                            lifetime.
-   * @param aContentToSelect    The content which should be selected.
-   */
-  nsresult SelectContentInternal(Selection& aSelection,
-                                 nsIContent& aContentToSelect);
-
-  /**
    * PasteInternal() pasts text with replacing selected content.
    * This tries to dispatch ePaste event first.  If its defaultPrevent() is
    * called, this does nothing but returns NS_OK.
    *
    * @param aClipboardType  nsIClipboard::kGlobalClipboard or
    *                        nsIClipboard::kSelectionClipboard.
    */
   nsresult PasteInternal(int32_t aClipboardType);
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -3070,19 +3070,17 @@ HTMLEditor::SetSelectionAfterTableEdit(E
     nsresult rv = GetCellAt(aTable, aRow, aCol, getter_AddRefs(cell));
     if (NS_FAILED(rv)) {
       break;
     }
 
     if (cell) {
       if (aSelected) {
         // Reselect the cell
-        DebugOnly<nsresult> rv = SelectContentInternal(*selection, *cell);
-        NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
-          "Failed to select the cell");
+        SelectElement(cell);
         return;
       }
 
       // Set the caret to deepest first child
       //   but don't go into nested tables
       // TODO: Should we really be placing the caret at the END
       //  of the cell content?
       CollapseSelectionToDeepestNonTableFirstChild(selection, cell);
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -276,17 +276,16 @@ subsuite = clipboard
 skip-if = android_version == '24'
 [test_inline_style_cache.html]
 [test_inlineTableEditing.html]
 [test_insertParagraph_in_inline_editing_host.html]
 [test_keypress_untrusted_event.html]
 [test_middle_click_paste.html]
 subsuite = clipboard
 skip-if = android_version == '24'
-[test_nsIHTMLEditor_selectElement.html]
 [test_objectResizing.html]
 [test_root_element_replacement.html]
 [test_select_all_without_body.html]
 [test_spellcheck_pref.html]
 skip-if = toolkit == 'android'
 [test_undo_after_spellchecker_replaces_word.html]
 skip-if = toolkit == 'android'
 [test_undo_redo_stack_after_setting_value.html]
deleted file mode 100644
--- a/editor/libeditor/tests/test_nsIHTMLEditor_selectElement.html
+++ /dev/null
@@ -1,131 +0,0 @@
-<!DOCTYPE>
-<html>
-<head>
-  <title>Test for nsIHTMLEditor.selectElement()</title>
-  <script src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" href="/tests/SimpleTest/test.css">
-</head>
-<body>
-<div id="display">
-</div>
-<div id="content" contenteditable></div>
-<pre id="test">
-</pre>
-
-<script class="testbody" type="application/javascript">
-
-SimpleTest.waitForExplicitFinish();
-SimpleTest.waitForFocus(function() {
-  let editor = document.getElementById("content");
-  let selection = window.getSelection();
-
-  editor.innerHTML = "<p>p1<b>b1</b><i>i1</i></p><p><b>b2</b><i>i2</i>p2</p>";
-
-  editor.focus();
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.firstChild);
-    ok(false, "nsIHTMLEditor.selectElement() should throw an exception if given node is not an element");
-  } catch (e) {
-    ok(true, `nsIHTMLEditor.selectElement() should throw an exception if given node is not an element: ${e}`);
-  }
-
-  editor.focus();
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.firstChild.nextSibling);
-    is(selection.anchorNode, editor.firstChild,
-       "nsIHTMLEditor.selectElement() should set anchor node to parent of <b> element in the first paragraph");
-    is(selection.anchorOffset, 1,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <b> element in the first paragraph");
-    is(selection.focusNode, editor.firstChild,
-       "nsIHTMLEditor.selectElement() should set focus node to parent of <b> element in the first paragraph");
-    is(selection.focusOffset, 2,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <b> element + 1 in the first paragraph");
-  } catch (e) {
-    ok(false, `nsIHTMLEditor.selectElement() shouldn't throw exception when selecting an element in focused editor #1: ${e}`);
-  }
-
-  editor.focus();
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.nextSibling.firstChild);
-    is(selection.anchorNode, editor.firstChild.nextSibling,
-       "nsIHTMLEditor.selectElement() should set anchor node to parent of <b> element in the second paragraph");
-    is(selection.anchorOffset, 0,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <b> element in the second paragraph");
-    is(selection.focusNode, editor.firstChild.nextSibling,
-       "nsIHTMLEditor.selectElement() should set focus node to parent of <b> element in the second paragraph");
-    is(selection.focusOffset, 1,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <b> element + 1 in the second paragraph");
-  } catch (e) {
-    ok(false, `nsIHTMLEditor.selectElement() shouldn't throw exception when selecting an element in focused editor #2: ${e}`);
-  }
-
-  editor.focus();
-  try {
-    getHTMLEditor().selectElement(editor);
-    ok(false, "nsIHTMLEditor.selectElement() should throw an exception if given node is the editing host");
-  } catch (e) {
-    ok(true, `nsIHTMLEditor.selectElement() should throw an exception if given node is the editing host: ${e}`);
-  }
-
-  editor.focus();
-  try {
-    getHTMLEditor().selectElement(editor.parentElement);
-    ok(false, "nsIHTMLEditor.selectElement() should throw an exception if given node is outside of the editing host");
-  } catch (e) {
-    ok(true, `nsIHTMLEditor.selectElement() should throw an exception if given node is outside of the editing host: ${e}`);
-  }
-
-  selection.removeAllRanges();
-  editor.blur();
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.nextSibling.firstChild);
-    ok(false, "nsIHTMLEditor.selectElement() should throw an exception if there is no active editing host");
-  } catch (e) {
-    ok(true, `nsIHTMLEditor.selectElement() should throw an exception if there is no active editing host: ${e}`);
-  }
-
-  editor.focus();
-  editor.firstChild.firstChild.nextSibling.nextSibling.setAttribute("contenteditable", "false");
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.firstChild.nextSibling.nextSibling);
-    is(selection.anchorNode, editor.firstChild,
-       "nsIHTMLEditor.selectElement() should set anchor node to parent of <i contenteditable=\"false\"> element in the first paragraph");
-    is(selection.anchorOffset, 2,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <i contenteditable=\"false\"> element in the first paragraph");
-    is(selection.focusNode, editor.firstChild,
-       "nsIHTMLEditor.selectElement() should set focus node to parent of <i contenteditable=\"false\"> element in the first paragraph");
-    is(selection.focusOffset, 3,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <i contenteditable=\"false\"> element + 1 in the first paragraph");
-  } catch (e) {
-    ok(false, `nsIHTMLEditor.selectElement() shouldn't throw exception when selecting an element in focused editor #3: ${e}`);
-  }
-
-  editor.focus();
-  editor.firstChild.nextSibling.setAttribute("contenteditable", "false");
-  try {
-    getHTMLEditor().selectElement(editor.firstChild.nextSibling.firstChild.nextSibling);
-    is(selection.anchorNode, editor.firstChild.nextSibling,
-       "nsIHTMLEditor.selectElement() should set anchor node to parent of <i> element in the second paragraph which is not editable");
-    is(selection.anchorOffset, 1,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <i> element in the second paragraph which is not editable");
-    is(selection.focusNode, editor.firstChild.nextSibling,
-       "nsIHTMLEditor.selectElement() should set focus node to parent of <i> element in the second paragraph which is not editable");
-    is(selection.focusOffset, 2,
-       "nsIHTMLEditor.selectElement() should set anchor offset to the index of <i> element + 1 in the second paragraph which is not editable");
-  } catch (e) {
-    ok(false, `nsIHTMLEditor.selectElement() shouldn't throw exception when selecting an element in focused editor #4: ${e}`);
-  }
-
-  SimpleTest.finish();
-});
-
-function getHTMLEditor() {
-  var Ci = SpecialPowers.Ci;
-  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
-  return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsIHTMLEditor);
-}
-
-</script>
-</body>
-
-</html>