Bug 1297414 - Support <div> separator in ReturnIn(Header|ListItem); r=masayuki
MozReview-Commit-ID: EkvFpyTmXDc
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -6313,16 +6313,26 @@ HTMLEditRules::IsInListItem(nsINode* aNo
if (HTMLEditUtils::IsListItem(parent)) {
return parent;
}
parent = parent->GetParentElement();
}
return nullptr;
}
+nsIAtom&
+HTMLEditRules::DefaultParagraphSeparator()
+{
+ MOZ_ASSERT(mHTMLEditor);
+ if (!mHTMLEditor) {
+ return *nsGkAtoms::div;
+ }
+ return ParagraphSeparatorElement(mHTMLEditor->GetDefaultParagraphSeparator());
+}
+
/**
* ReturnInHeader: do the right thing for returns pressed in headers
*/
nsresult
HTMLEditRules::ReturnInHeader(Selection& aSelection,
Element& aHeader,
nsINode& aNode,
int32_t aOffset)
@@ -6368,18 +6378,22 @@ HTMLEditRules::ReturnInHeader(Selection&
// break after the header.
nsCOMPtr<nsIContent> sibling =
htmlEditor->GetNextHTMLSibling(headerParent, offset + 1);
if (!sibling || !sibling->IsHTMLElement(nsGkAtoms::br)) {
ClearCachedStyles();
htmlEditor->mTypeInState->ClearAllProps();
// Create a paragraph
+ nsIAtom& paraAtom = DefaultParagraphSeparator();
+ // We want a wrapper element even if we separate with <br>
nsCOMPtr<Element> pNode =
- htmlEditor->CreateNode(nsGkAtoms::p, headerParent, offset + 1);
+ htmlEditor->CreateNode(¶Atom == nsGkAtoms::br ? nsGkAtoms::p
+ : ¶Atom,
+ headerParent, offset + 1);
NS_ENSURE_STATE(pNode);
// Append a <br> to it
nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
NS_ENSURE_STATE(brNode);
// Set selection to before the break
rv = aSelection.Collapse(pNode, 0);
@@ -6636,18 +6650,22 @@ HTMLEditRules::ReturnInListItem(Selectio
rv = aSelection.Collapse(&aListItem, 0);
NS_ENSURE_SUCCESS(rv, rv);
} else {
// Otherwise kill this item
rv = htmlEditor->DeleteNode(&aListItem);
NS_ENSURE_SUCCESS(rv, rv);
// Time to insert a paragraph
+ nsIAtom& paraAtom = DefaultParagraphSeparator();
+ // We want a wrapper even if we separate with <br>
nsCOMPtr<Element> pNode =
- htmlEditor->CreateNode(nsGkAtoms::p, listParent, offset + 1);
+ htmlEditor->CreateNode(¶Atom == nsGkAtoms::br ? nsGkAtoms::p
+ : ¶Atom,
+ listParent, offset + 1);
NS_ENSURE_STATE(pNode);
// Append a <br> to it
nsCOMPtr<Element> brNode = htmlEditor->CreateBR(pNode, 0);
NS_ENSURE_STATE(brNode);
// Set selection to before the break
rv = aSelection.Collapse(pNode, 0);
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -268,16 +268,17 @@ protected:
nsresult GetFormatString(nsIDOMNode* aNode, nsAString &outFormat);
enum class Lists { no, yes };
enum class Tables { no, yes };
void GetInnerContent(nsINode& aNode,
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
int32_t* aIndex, Lists aLists = Lists::yes,
Tables aTables = Tables::yes);
Element* IsInListItem(nsINode* aNode);
+ nsIAtom& DefaultParagraphSeparator();
nsresult ReturnInHeader(Selection& aSelection, Element& aHeader,
nsINode& aNode, int32_t aOffset);
nsresult ReturnInParagraph(Selection* aSelection, nsIDOMNode* aHeader,
nsIDOMNode* aTextNode, int32_t aOffset,
bool* aCancel, bool* aHandled);
nsresult SplitParagraph(nsIDOMNode* aPara,
nsIContent* aBRNode,
Selection* aSelection,
--- a/testing/web-platform/meta/editing/run/insertparagraph.html.ini
+++ b/testing/web-platform/meta/editing/run/insertparagraph.html.ini
@@ -31,52 +31,31 @@
expected: FAIL
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<table><tr><td>[foo\]</table>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<table><tr><td>[foo\]</table>" compare innerHTML]
expected: FAIL
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<ol><li>[foo\]<li>bar</ol>" compare innerHTML]
- expected: FAIL
-
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<span>foo[\]</span>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<span>foo[\]</span>" compare innerHTML]
expected: FAIL
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<h1>foo[\]</h1>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<h1>foo[\]<br></h1>" compare innerHTML]
- expected: FAIL
-
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<script>foo[\]bar</script>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<div style=display:none>foo[\]bar</div>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<div style=display:none>foo[\]bar</div>baz" compare innerHTML]
expected: FAIL
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<ol><li>{}<br></li></ol>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<ol><li>foo<li>{}<br></ol>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<dl><dt>foo<dd>{}<br></dl>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<dl><dt>{}<br><dd>bar</dl>" compare innerHTML]
- expected: FAIL
-
[[["insertparagraph",""\]\] "<dl><dt>foo<dd>bar<dl><dt>{}<br><dd>baz</dl></dl>" compare innerHTML]
expected: FAIL
[[["insertparagraph",""\]\] "<dl><dt>foo<dd>bar<dl><dt>baz<dd>{}<br></dl></dl>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo</p>{}<br>" compare innerHTML]
expected: FAIL
@@ -103,19 +82,16 @@
expected: FAIL
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<h1>foo</h1>{}<br><h2>bar</h2>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<h1>foo</h1>{}<br><h2>bar</h2>" compare innerHTML]
expected: FAIL
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo</p><h1>[bar\]</h1><p>baz</p>" compare innerHTML]
- expected: FAIL
-
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo</p>{<h1>bar</h1>}<p>baz</p>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>foo</p>{<h1>bar</h1>}<p>baz</p>" compare innerHTML]
expected: FAIL
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<table><tr><td>foo[\]bar</table>" compare innerHTML]
expected: FAIL
@@ -364,20 +340,8 @@
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<div style=display:none>foo[\]bar</div>baz" compare innerHTML]
expected: FAIL
[[["insertparagraph",""\]\] "<listing>foo[\]bar</listing>" compare innerHTML]
expected: FAIL
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "foo<ol><li>{}<br></li></ol>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<ol><li>{}<br></li></ol>foo" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<ol><li>{}<br><li>bar</ol>" compare innerHTML]
- expected: FAIL
-
- [[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<dl><dt>{}<br></dt></dl>" compare innerHTML]
- expected: FAIL
-