mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1574852 - part 18: Move HTMLEditRules::BustUpInlinesAtBRs()
to HTMLEditor
r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D42789 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
1afafb5000
commit
2271a1a433
@ -7322,8 +7322,10 @@ nsresult HTMLEditRules::GetNodesForOperation(
|
||||
HTMLEditor::NodeIsInlineStatic(node) &&
|
||||
HTMLEditorRef().IsContainer(node) && !EditorBase::IsTextNode(node)) {
|
||||
nsTArray<OwningNonNull<nsINode>> arrayOfInlines;
|
||||
nsresult rv = BustUpInlinesAtBRs(MOZ_KnownLive(*node->AsContent()),
|
||||
arrayOfInlines);
|
||||
nsresult rv =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.SplitElementsAtEveryBRElement(
|
||||
MOZ_KnownLive(*node->AsContent()), arrayOfInlines);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -7561,36 +7563,33 @@ nsresult HTMLEditor::SplitParentInlineElementsAtRangeEdges(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult HTMLEditRules::BustUpInlinesAtBRs(
|
||||
nsIContent& aNode,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes) const {
|
||||
MOZ_ASSERT(IsEditorDataAvailable());
|
||||
nsresult HTMLEditor::SplitElementsAtEveryBRElement(
|
||||
nsIContent& aMostAncestorToBeSplit,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes) {
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
// First build up a list of all the break nodes inside the inline container.
|
||||
nsTArray<OwningNonNull<nsINode>> arrayOfBreaks;
|
||||
BRNodeFunctor functor;
|
||||
DOMIterator iter(aNode);
|
||||
DOMIterator iter(aMostAncestorToBeSplit);
|
||||
iter.AppendList(functor, arrayOfBreaks);
|
||||
|
||||
// If there aren't any breaks, just put inNode itself in the array
|
||||
if (arrayOfBreaks.IsEmpty()) {
|
||||
aOutArrayOfNodes.AppendElement(aNode);
|
||||
aOutArrayOfNodes.AppendElement(aMostAncestorToBeSplit);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Else we need to bust up aNode along all the breaks
|
||||
nsCOMPtr<nsIContent> nextNode = &aNode;
|
||||
// Else we need to bust up aMostAncestorToBeSplit along all the breaks
|
||||
nsCOMPtr<nsIContent> nextContent = &aMostAncestorToBeSplit;
|
||||
for (OwningNonNull<nsINode>& brNode : arrayOfBreaks) {
|
||||
EditorDOMPoint atBrNode(brNode);
|
||||
if (NS_WARN_IF(!atBrNode.IsSet())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
SplitNodeResult splitNodeResult =
|
||||
MOZ_KnownLive(HTMLEditorRef())
|
||||
.SplitNodeDeepWithTransaction(
|
||||
*nextNode, atBrNode,
|
||||
SplitAtEdges::eAllowToCreateEmptyContainer);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
|
||||
*nextContent, atBrNode, SplitAtEdges::eAllowToCreateEmptyContainer);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(splitNodeResult.Failed())) {
|
||||
@ -7607,10 +7606,9 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
|
||||
|
||||
// Move break outside of container and also put in node list
|
||||
EditorDOMPoint atNextNode(splitNodeResult.GetNextNode());
|
||||
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
|
||||
.MoveNodeWithTransaction(
|
||||
MOZ_KnownLive(*brNode->AsContent()), atNextNode);
|
||||
if (NS_WARN_IF(!CanHandleEditAction())) {
|
||||
nsresult rv = MoveNodeWithTransaction(MOZ_KnownLive(*brNode->AsContent()),
|
||||
atNextNode);
|
||||
if (NS_WARN_IF(Destroyed())) {
|
||||
return NS_ERROR_EDITOR_DESTROYED;
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
@ -7618,11 +7616,11 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
|
||||
}
|
||||
aOutArrayOfNodes.AppendElement(*brNode);
|
||||
|
||||
nextNode = splitNodeResult.GetNextNode();
|
||||
nextContent = splitNodeResult.GetNextNode();
|
||||
}
|
||||
|
||||
// Now tack on remaining next node.
|
||||
aOutArrayOfNodes.AppendElement(*nextNode);
|
||||
aOutArrayOfNodes.AppendElement(*nextContent);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -859,22 +859,6 @@ class HTMLEditRules : public TextEditRules {
|
||||
void LookInsideDivBQandList(
|
||||
nsTArray<OwningNonNull<nsINode>>& aNodeArray) const;
|
||||
|
||||
/**
|
||||
* BustUpInlinesAtBRs() splits before all <br> elements in aNode. All <br>
|
||||
* nodes will be moved before right node at splitting its parent. Finally,
|
||||
* this returns all <br> elements, every left node and aNode with
|
||||
* aOutArrayNodes.
|
||||
*
|
||||
* @param aNode An inline container element.
|
||||
* @param aOutArrayOfNodes All found <br> elements, left nodes (may not
|
||||
* be set if <br> is at start edge of aNode) and
|
||||
* aNode itself.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
MOZ_MUST_USE nsresult
|
||||
BustUpInlinesAtBRs(nsIContent& aNode,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes) const;
|
||||
|
||||
/**
|
||||
* MakeTransitionList() detects all the transitions in the array, where a
|
||||
* transition means that adjacent nodes in the array don't have the same
|
||||
|
@ -1226,6 +1226,28 @@ class HTMLEditor final : public TextEditor,
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
|
||||
SplitParentInlineElementsAtRangeEdges(RangeItem& aRangeItem);
|
||||
|
||||
/**
|
||||
* SplitElementsAtEveryBRElement() splits before all <br> elements in
|
||||
* aMostAncestorToBeSplit. All <br> nodes will be moved before right node
|
||||
* at splitting its parent. Finally, this returns left node, first <br>
|
||||
* element, next left node, second <br> element... and right-most node.
|
||||
*
|
||||
* @param aMostAncestorToBeSplit Most-ancestor element which should
|
||||
* be split.
|
||||
* @param aOutArrayOfNodes First left node, first <br> element,
|
||||
* Second left node, second <br> element,
|
||||
* ...right-most node. So, all nodes in
|
||||
* this list should be siblings (may be
|
||||
* broken the relation by mutation event
|
||||
* listener though).
|
||||
* If first <br> element is first leaf
|
||||
* node of aMostAncestorToBeSplit,
|
||||
* starting from first <br> element.
|
||||
*/
|
||||
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult SplitElementsAtEveryBRElement(
|
||||
nsIContent& aMostAncestorToBeSplit,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
|
||||
|
||||
/**
|
||||
* CollectEditableChildren() collects child nodes of aNode (starting from
|
||||
* first editable child, but may return non-editable children after it).
|
||||
|
Loading…
Reference in New Issue
Block a user