mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1588688 - part 7-5: Clean up HTMLEditor::CreateListOfNodesToPaste()
r=m_kato
`HTMLEditor::CreateListOfNodesToPaste()` can be static and it does not need to take `DocumentFragment` as an argument if the range is always specified. For avoiding 2 input path to specify a range, we should make it take only range boundaries and array of nodes to return the collected nodes. Differential Revision: https://phabricator.services.mozilla.com/D61978 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
321d07ccd2
commit
817ac3e98e
@ -3935,10 +3935,24 @@ class HTMLEditor final : public TextEditor,
|
||||
nsresult ParseFragment(const nsAString& aStr, nsAtom* aContextLocalName,
|
||||
Document* aTargetDoc,
|
||||
dom::DocumentFragment** aFragment, bool aTrustedInput);
|
||||
void CreateListOfNodesToPaste(dom::DocumentFragment& aFragment,
|
||||
nsTArray<OwningNonNull<nsINode>>& outNodeList,
|
||||
nsINode* aStartContainer, int32_t aStartOffset,
|
||||
nsINode* aEndContainer, int32_t aEndOffset);
|
||||
/**
|
||||
* CollectTopMostChildNodesCompletelyInRange() collects topmost child nodes
|
||||
* which are completely in the given range.
|
||||
* For example, if the range points a node with its container node, the
|
||||
* result is only the node (meaning does not include its descendants).
|
||||
* If the range starts start of a node and ends end of it, and if the node
|
||||
* does not have children, returns no nodes, otherwise, if the node has
|
||||
* some children, the result includes its all children (not including their
|
||||
* descendants).
|
||||
*
|
||||
* @param aStartPoint Start point of the range.
|
||||
* @param aEndPoint End point of the range.
|
||||
* @param aOutArrayOfNodes [Out] Topmost children which are completely in
|
||||
* the range.
|
||||
*/
|
||||
static void CollectTopMostChildNodesCompletelyInRange(
|
||||
const EditorRawDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
|
||||
|
||||
/**
|
||||
* CollectListAndTableRelatedElementsAt() collects list elements and
|
||||
|
@ -241,11 +241,19 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
|
||||
// we need to recalculate various things based on potentially new offsets
|
||||
// this is work to be completed at a later date (probably by jfrancis)
|
||||
|
||||
// make a list of what nodes in docFrag we need to move
|
||||
AutoTArray<OwningNonNull<nsINode>, 64> nodeList;
|
||||
CreateListOfNodesToPaste(*fragmentAsNode->AsDocumentFragment(), nodeList,
|
||||
streamStartParent, streamStartOffset,
|
||||
streamEndParent, streamEndOffset);
|
||||
// If we have stream start point information, lets use it and end point.
|
||||
// Otherwise, we should make a range all over the document fragment.
|
||||
EditorRawDOMPoint streamStartPoint =
|
||||
streamStartParent
|
||||
? EditorRawDOMPoint(streamStartParent, streamStartOffset)
|
||||
: EditorRawDOMPoint(fragmentAsNode, 0);
|
||||
EditorRawDOMPoint streamEndPoint =
|
||||
streamStartParent ? EditorRawDOMPoint(streamEndParent, streamEndOffset)
|
||||
: EditorRawDOMPoint::AtEndOf(*fragmentAsNode);
|
||||
HTMLEditor::CollectTopMostChildNodesCompletelyInRange(
|
||||
EditorRawDOMPoint(streamStartParent, streamStartOffset),
|
||||
EditorRawDOMPoint(streamEndParent, streamEndOffset), nodeList);
|
||||
|
||||
if (nodeList.IsEmpty()) {
|
||||
// We aren't inserting anything, but if aDoDeleteSelection is set, we do
|
||||
@ -2714,32 +2722,24 @@ nsresult HTMLEditor::ParseFragment(const nsAString& aFragStr,
|
||||
return rv;
|
||||
}
|
||||
|
||||
void HTMLEditor::CreateListOfNodesToPaste(
|
||||
DocumentFragment& aFragment, nsTArray<OwningNonNull<nsINode>>& outNodeList,
|
||||
nsINode* aStartContainer, int32_t aStartOffset, nsINode* aEndContainer,
|
||||
int32_t aEndOffset) {
|
||||
// If no info was provided about the boundary between context and stream,
|
||||
// then assume all is stream.
|
||||
if (!aStartContainer) {
|
||||
aStartContainer = &aFragment;
|
||||
aStartOffset = 0;
|
||||
aEndContainer = &aFragment;
|
||||
aEndOffset = aFragment.Length();
|
||||
}
|
||||
// static
|
||||
void HTMLEditor::CollectTopMostChildNodesCompletelyInRange(
|
||||
const EditorRawDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint,
|
||||
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes) {
|
||||
MOZ_ASSERT(aStartPoint.IsSetAndValid());
|
||||
MOZ_ASSERT(aEndPoint.IsSetAndValid());
|
||||
|
||||
RefPtr<nsRange> docFragRange = nsRange::Create(
|
||||
aStartContainer, aStartOffset, aEndContainer, aEndOffset, IgnoreErrors());
|
||||
if (NS_WARN_IF(!docFragRange)) {
|
||||
MOZ_ASSERT(docFragRange);
|
||||
RefPtr<nsRange> range =
|
||||
nsRange::Create(aStartPoint.ToRawRangeBoundary(),
|
||||
aEndPoint.ToRawRangeBoundary(), IgnoreErrors());
|
||||
if (NS_WARN_IF(!range)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now use a subtree iterator over the range to create a list of nodes
|
||||
DOMSubtreeIterator iter;
|
||||
if (NS_WARN_IF(NS_FAILED(iter.Init(*docFragRange)))) {
|
||||
if (NS_WARN_IF(NS_FAILED(iter.Init(*range)))) {
|
||||
return;
|
||||
}
|
||||
iter.AppendAllNodesToArray(outNodeList);
|
||||
iter.AppendAllNodesToArray(aOutArrayOfNodes);
|
||||
}
|
||||
|
||||
// static
|
||||
|
Loading…
Reference in New Issue
Block a user