mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +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
|
nsresult
|
||||||
HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||||
const nsAString& aAlignType)
|
const nsAString& aAlignType)
|
||||||
@ -5972,9 +5969,17 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
|||||||
if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) {
|
if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) {
|
||||||
// the cell already has a div containing all of its content: just
|
// the cell already has a div containing all of its content: just
|
||||||
// act on this div.
|
// act on this div.
|
||||||
return HTMLEditorRef().SetAttributeOrEquivalent(firstChild->AsElement(),
|
nsresult rv =
|
||||||
nsGkAtoms::align,
|
HTMLEditorRef().SetAttributeOrEquivalent(firstChild->AsElement(),
|
||||||
aAlignType, false);
|
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
|
// 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);
|
EditorRawDOMPoint atStartOfNode(&aNode, 0);
|
||||||
RefPtr<Element> divElem =
|
RefPtr<Element> divElem =
|
||||||
HTMLEditorRef().CreateNodeWithTransaction(*nsGkAtoms::div, atStartOfNode);
|
HTMLEditorRef().CreateNodeWithTransaction(*nsGkAtoms::div, atStartOfNode);
|
||||||
|
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||||
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
|
}
|
||||||
if (NS_WARN_IF(!divElem)) {
|
if (NS_WARN_IF(!divElem)) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@ -5989,6 +5997,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
|||||||
nsresult rv =
|
nsresult rv =
|
||||||
HTMLEditorRef().SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
|
HTMLEditorRef().SetAttributeOrEquivalent(divElem, nsGkAtoms::align,
|
||||||
aAlignType, false);
|
aAlignType, false);
|
||||||
|
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||||
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
|
}
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -5997,6 +6008,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
|||||||
nsresult rv =
|
nsresult rv =
|
||||||
HTMLEditorRef().MoveNodeWithTransaction(*lastChild,
|
HTMLEditorRef().MoveNodeWithTransaction(*lastChild,
|
||||||
EditorRawDOMPoint(divElem, 0));
|
EditorRawDOMPoint(divElem, 0));
|
||||||
|
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||||
|
return NS_ERROR_EDITOR_DESTROYED;
|
||||||
|
}
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,21 @@ protected:
|
|||||||
MOZ_MUST_USE nsresult DidAbsolutePosition();
|
MOZ_MUST_USE nsresult DidAbsolutePosition();
|
||||||
|
|
||||||
nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
|
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,
|
nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
|
||||||
nsINode* aNode);
|
nsINode* aNode);
|
||||||
nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
|
nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
|
||||||
|
Loading…
Reference in New Issue
Block a user