Bug 1717178 - part 6: Get rid of nsIHTMLEditor.setCaretAfterElement() because of unused r=m_kato

Depends on D118801

Differential Revision: https://phabricator.services.mozilla.com/D118802
This commit is contained in:
Masayuki Nakano 2021-06-28 12:08:51 +00:00
parent 3e099ba376
commit 5017e990c8
4 changed files with 0 additions and 181 deletions

View File

@ -1933,23 +1933,6 @@ nsresult HTMLEditor::SelectContentInternal(nsIContent& aContentToSelect) {
return error.StealNSResult();
}
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
HTMLEditor::SetCaretAfterElement(Element* aElement) {
if (NS_WARN_IF(!aElement)) {
return NS_ERROR_INVALID_ARG;
}
AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing);
if (NS_WARN_IF(!editActionData.CanHandle())) {
return NS_ERROR_NOT_INITIALIZED;
}
nsresult rv = CollapseSelectionAfter(*aElement);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HTMLEditor::CollapseSelectionAfter() failed");
return rv;
}
nsresult HTMLEditor::CollapseSelectionAfter(Element& aElement) {
MOZ_ASSERT(IsEditActionDataAvailable());

View File

@ -278,7 +278,6 @@ skip-if = headless
[test_nsIHTMLEditor_removeInlineProperty.html]
[test_nsIHTMLEditor_selectElement.html]
[test_nsIHTMLEditor_setBackgroundColor.html]
[test_nsIHTMLEditor_setCaretAfterElement.html]
[test_nsIHTMLObjectResizer_hideResizers.html]
[test_nsITableEditor_deleteTableCell.html]
[test_nsITableEditor_deleteTableCellContents.html]

View File

@ -1,149 +0,0 @@
<!DOCTYPE>
<html>
<head>
<title>Test for nsIHTMLEditor.setCaretAfterElement()</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().setCaretAfterElement(editor.firstChild.firstChild);
ok(false, "nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is not an element");
} catch (e) {
ok(true, `nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is not an element: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.firstChild.nextSibling);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #1");
is(selection.anchorNode, editor.firstChild,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <b> element in the first paragraph");
is(selection.anchorOffset, 2,
"nsIHTMLEditor.setCaretAfterElement() should set anchor offset to the index of <b> element + 1 in the first paragraph");
} catch (e) {
ok(false, `nsIHTMLEditor.setCaretAfterElement() shouldn't throw exception when selecting an element in focused editor #1: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.firstChild.nextSibling.nextSibling);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #2");
is(selection.anchorNode, editor.firstChild,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <i> element in the first paragraph");
is(selection.anchorOffset, 3,
"nsIHTMLEditor.setCaretAfterElement() should set anchor offset to the index of <i> element + 1 in the first paragraph");
} catch (e) {
ok(false, `nsIHTMLEditor.setCaretAfterElement() shouldn't throw exception when selecting an element in focused editor #2: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.nextSibling.firstChild);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #3");
is(selection.anchorNode, editor.firstChild.nextSibling,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <b> element in the second paragraph");
is(selection.anchorOffset, 1,
"nsIHTMLEditor.setCaretAfterElement() should set anchor offset to the index of <b> element + 1 in the second paragraph");
} catch (e) {
ok(false, `nsIHTMLEditor.setCaretAfterElement() shouldn't throw exception when selecting an element in focused editor #3: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor);
ok(false, "nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is the editing host");
} catch (e) {
ok(true, `nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is the editing host: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor.parentElement);
ok(false, "nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is outside of the editing host");
} catch (e) {
ok(true, `nsIHTMLEditor.setCaretAfterElement() should throw an exception if given node is outside of the editing host: ${e}`);
}
selection.removeAllRanges();
editor.blur();
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.nextSibling.firstChild);
ok(false, "nsIHTMLEditor.setCaretAfterElement() should throw an exception if there is no active editing host");
} catch (e) {
ok(true, `nsIHTMLEditor.setCaretAfterElement() should throw an exception if there is no active editing host: ${e}`);
}
editor.focus();
editor.firstChild.firstChild.nextSibling.nextSibling.setAttribute("contenteditable", "false");
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.firstChild.nextSibling.nextSibling);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #4");
is(selection.anchorNode, editor.firstChild,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <i contenteditable=\"false\"> element in the first paragraph");
is(selection.anchorOffset, 3,
"nsIHTMLEditor.setCaretAfterElement() should set anchor offset to the index of <i contenteditable=\"false\"> element + 1 in the first paragraph");
} catch (e) {
ok(false, `nsIHTMLEditor.setCaretAfterElement() shouldn't throw exception when selecting an element in focused editor #4: ${e}`);
}
editor.focus();
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.firstChild.nextSibling);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #5");
is(selection.anchorNode, editor.firstChild,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <b> element in the first paragraph");
is(selection.anchorOffset, 2,
"nsIHTMLEditor.setCaretAfterElement() should set anchor offset to the index of <b> element in the first paragraph");
} catch (e) {
ok(false, `nsIHTMLEditor.setCaretAfterElement() shouldn't throw exception when selecting an element in focused editor #5: ${e}`);
}
editor.focus();
editor.firstChild.nextSibling.setAttribute("contenteditable", "false");
try {
getHTMLEditor().setCaretAfterElement(editor.firstChild.nextSibling.firstChild.nextSibling);
ok(selection.isCollapsed,
"nsIHTMLEditor.setCaretAfterElement() should collapse Selection #6");
is(selection.anchorNode, editor.firstChild.nextSibling,
"nsIHTMLEditor.setCaretAfterElement() should set anchor node to parent of <i> element in the second paragraph which is not editable");
is(selection.anchorOffset, 2,
"nsIHTMLEditor.setCaretAfterElement() 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 #6: ${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>

View File

@ -154,20 +154,6 @@ interface nsIHTMLEditor : nsISupports
[can_run_script]
void selectElement(in Element aElement);
/**
* Create a collapsed selection just after aElement
*
* XXX could we parameterize SelectElement(before/select/after>?
*
* The selection is set to parent-of-aElement with an
* offset 1 greater than aElement's offset
* but it enforces the HTML 4.0 DTD "CanContain" rules, so it should
* be useful for other elements.
*
* @param aElement An element in the document
*/
void setCaretAfterElement(in Element aElement);
/**
* getParagraphState returns what block tag paragraph format is in
* the selection.