Bug 1460509 - part 20: Make HTMLEditRules::MakeSureElemStartsAndEndsOnCR() and HTMLEditRules::MakeSureElemStartsOrEndsOnCR() return NS_ERROR_EDITOR_DESTROYED if they cause destroying the editor r=m_kato

MozReview-Commit-ID: I8HcvO9IB7x

--HG--
extra : rebase_source : 6ca2e3a58b84a150504c73a17bda6cc825a10176
This commit is contained in:
Masayuki Nakano 2018-05-12 11:25:23 +09:00
Родитель b591f81cf5
Коммит 5983a789e1
2 изменённых файлов: 28 добавлений и 5 удалений

Просмотреть файл

@ -9802,9 +9802,6 @@ HTMLEditRules::RemoveAlignment(nsINode& aNode,
return NS_OK;
}
// Let's insert a BR as first (resp. last) child of aNode if its
// first (resp. last) child is not a block nor a BR, and if the
// previous (resp. next) sibling is not a block nor a BR
nsresult
HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
bool aStarts)
@ -9842,6 +9839,9 @@ HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
RefPtr<Element> brElement =
HTMLEditorRef().InsertBrElementWithTransaction(SelectionRef(),
pointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -102,7 +102,17 @@ public:
nsresult GetIndentState(bool* aCanIndent, bool* aCanOutdent);
nsresult GetAlignment(bool* aMixed, nsIHTMLEditor::EAlignment* aAlign);
nsresult GetParagraphState(bool* aMixed, nsAString& outFormat);
nsresult MakeSureElemStartsAndEndsOnCR(nsINode& aNode);
/**
* MakeSureElemStartsAndEndsOnCR() inserts <br> element at start (and/or end)
* of aNode if neither:
* - first (last) editable child of aNode is a block or a <br>,
* - previous (next) sibling of aNode is block or a <br>
* - nor no previous (next) sibling of aNode.
*
* @param aNode The node which may be inserted <br> elements.
*/
MOZ_MUST_USE nsresult MakeSureElemStartsAndEndsOnCR(nsINode& aNode);
void DidCreateNode(Selection& aSelection, Element& aNewElement);
void DidInsertNode(Selection& aSelection, nsIContent& aNode);
@ -589,7 +599,20 @@ protected:
bool ListIsEmptyLine(nsTArray<OwningNonNull<nsINode>>& arrayOfNodes);
nsresult RemoveAlignment(nsINode& aNode, const nsAString& aAlignType,
bool aChildrenOnly);
nsresult MakeSureElemStartsOrEndsOnCR(nsINode& aNode, bool aStarts);
/**
* MakeSureElemStartsOrEndsOnCR() inserts <br> element at start (end) of
* aNode if neither:
* - first (last) editable child of aNode is a block or a <br>,
* - previous (next) sibling of aNode is block or a <br>
* - nor no previous (next) sibling of aNode.
*
* @param aNode The node which may be inserted <br> element.
* @param aStarts true for trying to insert <br> to the start.
* false for trying to insert <br> to the end.
*/
MOZ_MUST_USE nsresult
MakeSureElemStartsOrEndsOnCR(nsINode& aNode, bool aStarts);
/**
* AlignBlock() resets align attribute, text-align property, etc first.