mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
Bug 1460509 - part 56: Make HTMLEditRules::AlignBlockContents() return NS_ERROR_EDITOR_DESTROYED if it causes destroying the editor r=m_kato
MozReview-Commit-ID: Jn4m4uTdLtW --HG-- extra : rebase_source : dcaa6a6ebfb34965053680b12fbaa0236ac604a6
This commit is contained in:
parent
bfe1ba2a3d
commit
7fd1c21f25
@ -5952,9 +5952,6 @@ HTMLEditRules::AlignInnerBlocks(nsINode& aNode,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AlignBlockContents() aligns contents of a block element.
|
||||
*/
|
||||
nsresult
|
||||
HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
const nsAString& aAlignType)
|
||||
@ -5972,9 +5969,17 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) {
|
||||
// the cell already has a div containing all of its content: just
|
||||
// act on this div.
|
||||
return HTMLEditorRef().SetAttributeOrEquivalent(firstChild->AsElement(),
|
||||
nsGkAtoms::align,
|
||||
aAlignType, false);
|
||||
nsresult rv =
|
||||
HTMLEditorRef().SetAttributeOrEquivalent(firstChild->AsElement(),
|
||||
nsGkAtoms::align,
|
||||
aAlignType, false);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// else we need to put in a div, set the alignment, and toss in all the
|
||||
@ -5982,6 +5987,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
EditorRawDOMPoint atStartOfNode(&aNode, 0);
|
||||
RefPtr<Element> divElem =
|
||||
HTMLEditorRef().CreateNodeWithTransaction(*nsGkAtoms::div, atStartOfNode);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(!divElem)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@ -5989,6 +5997,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
nsresult rv =
|
||||
HTMLEditorRef().SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
|
||||
aAlignType, false);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -5997,6 +6008,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
nsresult rv =
|
||||
HTMLEditorRef().MoveNodeWithTransaction(*lastChild,
|
||||
EditorRawDOMPoint(divElem, 0));
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -402,7 +402,21 @@ protected:
|
||||
MOZ_MUST_USE nsresult DidAbsolutePosition();
|
||||
|
||||
nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
|
||||
nsresult AlignBlockContents(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
|
||||
* to aAlignType.
|
||||
* @param aAlignType New value of align attribute of <div> which
|
||||
* is only child of aNode.
|
||||
*/
|
||||
MOZ_MUST_USE nsresult
|
||||
AlignBlockContents(nsINode& aNode, const nsAString& aAlignType);
|
||||
|
||||
nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
|
||||
nsINode* aNode);
|
||||
nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
|
||||
|
Loading…
Reference in New Issue
Block a user