diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 000e979d7ca4..e65c46882ad4 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -1730,52 +1730,28 @@ HTMLEditor::InsertNodeIntoProperAncestorWithTransaction( NS_IMETHODIMP HTMLEditor::SelectElement(Element* aElement) -{ - if (NS_WARN_IF(!aElement)) { - return NS_ERROR_INVALID_ARG; - } - RefPtr 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; + if (!IsDescendantOfEditorRoot(aElement)) { + return NS_ERROR_NULL_POINTER; } - nsINode* parent = aContentToSelect.GetParentNode(); + RefPtr selection = GetSelection(); + 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; + nsresult rv = selection->Collapse(parent, offsetInParent); + if (NS_SUCCEEDED(rv)) { + // then extend it to just after + rv = selection->Extend(parent, offsetInParent + 1); } - // then extend it to just after - rv = aSelection.Extend(parent, offsetInParent + 1); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - return NS_OK; + return rv; } NS_IMETHODIMP diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index bb496e580cb5..19f9382746ae 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -771,17 +771,6 @@ protected: // Shouldn't be used by friend classes 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 diff --git a/editor/libeditor/HTMLTableEditor.cpp b/editor/libeditor/HTMLTableEditor.cpp index cd17dbcf5b72..146925f2064a 100644 --- a/editor/libeditor/HTMLTableEditor.cpp +++ b/editor/libeditor/HTMLTableEditor.cpp @@ -3075,9 +3075,7 @@ HTMLEditor::SetSelectionAfterTableEdit(Element* aTable, if (cell) { if (aSelected) { // Reselect the cell - DebugOnly rv = SelectContentInternal(*selection, *cell); - NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), - "Failed to select the cell"); + SelectElement(cell); return; } diff --git a/editor/libeditor/tests/mochitest.ini b/editor/libeditor/tests/mochitest.ini index 2ba947e49258..4f3236079771 100644 --- a/editor/libeditor/tests/mochitest.ini +++ b/editor/libeditor/tests/mochitest.ini @@ -281,7 +281,6 @@ skip-if = android_version == '24' [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] diff --git a/editor/libeditor/tests/test_nsIHTMLEditor_selectElement.html b/editor/libeditor/tests/test_nsIHTMLEditor_selectElement.html deleted file mode 100644 index 1ac21635eadc..000000000000 --- a/editor/libeditor/tests/test_nsIHTMLEditor_selectElement.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - Test for nsIHTMLEditor.selectElement() - - - - -
-
-
-
-
- - - - -