Bug 1460509 - part 57: Mark HTMLEditRules::AlignInnerBlocks() as MOZ_MUST_USE since it may cause destroying the editor r?m_kato
MozReview-Commit-ID: 8hBJPn1shZu
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -5867,20 +5867,25 @@ HTMLEditRules::WillAlign(const nsAString
if (useCSS) {
HTMLEditorRef().mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
curNode->AsElement(), nullptr,
nsGkAtoms::align, &aAlignType, false);
curDiv = nullptr;
continue;
}
if (HTMLEditUtils::IsList(atCurNode.GetContainer())) {
- // If we don't use CSS, add a contraint to list element: they have to
- // be inside another list, i.e., >= second level of nesting
+ // If we don't use CSS, add a content to list element: they have to
+ // be inside another list, i.e., >= second level of nesting.
+ // XXX AlignInnerBlocks() handles list item elements and table cells.
+ // Is it intentional to change alignment of nested other type
+ // descendants too?
rv = AlignInnerBlocks(*curNode, aAlignType);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
curDiv = nullptr;
continue;
}
// Clear out curDiv so that we don't put nodes after this one into it
}
// Need to make a div to put things in if we haven't already, or if this
// node doesn't go in div we used earlier.
@@ -5919,20 +5924,16 @@ HTMLEditRules::WillAlign(const nsAString
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}
-
-/**
- * AlignInnerBlocks() aligns inside table cells or list items.
- */
nsresult
HTMLEditRules::AlignInnerBlocks(nsINode& aNode,
const nsAString& aAlignType)
{
MOZ_ASSERT(IsEditorDataAvailable());
// Gather list of table cells or list items
nsTArray<OwningNonNull<nsINode>> nodeArray;
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -396,17 +396,26 @@ protected:
* Called if nobody handles the edit action to make an element absolute
* positioned.
* This method actually changes the element which is computed by
* WillAbsolutePosition() to absolute positioned.
* Therefore, this might cause destroying the HTML editor.
*/
MOZ_MUST_USE nsresult DidAbsolutePosition();
- nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
+ /**
+ * AlignInnerBlocks() calls AlignBlockContents() for every list item element
+ * and table cell element in aNode.
+ *
+ * @param aNode The node whose descendants should be aligned
+ * to aAlignType.
+ * @param aAlignType New value of align attribute of <div>.
+ */
+ MOZ_MUST_USE nsresult
+ AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
/**
* AlignBlockContents() sets align attribute of <div> element which is
* only child of aNode to aAlignType. If aNode has 2 or more children or
* does not have a <div> element has only child, inserts a <div> element
* into aNode and move all children of aNode into the new <div> element.
*
* @param aNode The node whose contents should be aligned