From 01d1a49b83e3c71e906f8ed9faca61eff5cf59f8 Mon Sep 17 00:00:00 2001 From: Mirko Brodesser Date: Fri, 12 Jun 2020 08:54:23 +0000 Subject: [PATCH] Bug 1643721: part 7) Move `mCommonInclusiveAncestors` to `RangeSerializer`. r=masayuki Preparation for moving `SerializeRangeToString` to `RangeSerializer`. Differential Revision: https://phabricator.services.mozilla.com/D79118 --- dom/base/nsDocumentEncoder.cpp | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/dom/base/nsDocumentEncoder.cpp b/dom/base/nsDocumentEncoder.cpp index 95888c0c9795..c59c11abb66f 100644 --- a/dom/base/nsDocumentEncoder.cpp +++ b/dom/base/nsDocumentEncoder.cpp @@ -336,10 +336,6 @@ class nsDocumentEncoder : public nsIDocumentEncoder { // Multiple of the flags defined in nsIDocumentEncoder.idl. uint32_t mFlags; uint32_t mWrapColumn; - /** - * https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor. - */ - AutoTArray mCommonInclusiveAncestors; // Whether the serializer cares about being notified to scan elements to // keep track of whether they are preformatted. This stores the out // argument of nsIContentSerializer::Init(). @@ -434,6 +430,11 @@ class nsDocumentEncoder : public nsIDocumentEncoder { */ nsCOMPtr mClosestCommonInclusiveAncestorOfRange; + /** + * https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor. + */ + AutoTArray mCommonInclusiveAncestors; + int32_t mStartRootIndex; int32_t mEndRootIndex; bool mHaltRangeHint; @@ -562,11 +563,12 @@ nsresult nsDocumentEncoder::SerializeSelection() { !ParentIsTR(content)) { if (!prevNode) { // Went from a non- to a - mCommonInclusiveAncestors.Clear(); - nsContentUtils::GetInclusiveAncestors(node->GetParentNode(), - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors.Clear(); + nsContentUtils::GetInclusiveAncestors( + node->GetParentNode(), + mRangeSerializer.mCommonInclusiveAncestors); rv = mRangeContextSerializer.SerializeRangeContextStart( - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors); NS_ENSURE_SUCCESS(rv, rv); // Don't let SerializeRangeToString serialize the context again mRangeContextSerializer.mDisableContextSerialize = true; @@ -581,9 +583,10 @@ nsresult nsDocumentEncoder::SerializeSelection() { // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` // too. Update it here to mimic the old behavior. - mCommonInclusiveAncestors.Clear(); - nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors.Clear(); + nsContentUtils::GetInclusiveAncestors( + prevNode->GetParentNode(), + mRangeSerializer.mCommonInclusiveAncestors); rv = mRangeContextSerializer.SerializeRangeContextEnd(); NS_ENSURE_SUCCESS(rv, rv); @@ -606,9 +609,9 @@ nsresult nsDocumentEncoder::SerializeSelection() { // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` // too. Update it here to mimic the old behavior. - mCommonInclusiveAncestors.Clear(); - nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors.Clear(); + nsContentUtils::GetInclusiveAncestors( + prevNode->GetParentNode(), mRangeSerializer.mCommonInclusiveAncestors); rv = mRangeContextSerializer.SerializeRangeContextEnd(); NS_ENSURE_SUCCESS(rv, rv); @@ -1160,7 +1163,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) { int32_t endOffset = aRange->EndOffset(); mRangeSerializer.mContextInfoDepth = {}; - mCommonInclusiveAncestors.Clear(); + mRangeSerializer.mCommonInclusiveAncestors.Clear(); mRangeSerializer.mRangeBoundariesInclusiveAncestorsAndOffsets = {}; auto& inclusiveAncestorsOfStart = @@ -1178,7 +1181,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) { nsContentUtils::GetInclusiveAncestors( mRangeSerializer.mClosestCommonInclusiveAncestorOfRange, - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors); nsContentUtils::GetInclusiveAncestorsAndOffsets( startContainer, startOffset, &inclusiveAncestorsOfStart, &inclusiveAncestorsOffsetsOfStart); @@ -1196,7 +1199,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) { nsresult rv = NS_OK; rv = mRangeContextSerializer.SerializeRangeContextStart( - mCommonInclusiveAncestors); + mRangeSerializer.mCommonInclusiveAncestors); NS_ENSURE_SUCCESS(rv, rv); if (startContainer == endContainer && IsTextNode(startContainer)) { @@ -1577,15 +1580,15 @@ nsHTMLCopyEncoder::EncodeToStringWithContext(nsAString& aContextString, &mNeedsPreformatScanning, aContextString); // leaf of ancestors might be text node. If so discard it. - int32_t count = mCommonInclusiveAncestors.Length(); + int32_t count = mRangeSerializer.mCommonInclusiveAncestors.Length(); int32_t i; nsCOMPtr node; if (count > 0) { - node = mCommonInclusiveAncestors.ElementAt(0); + node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(0); } if (node && IsTextNode(node)) { - mCommonInclusiveAncestors.RemoveElementAt(0); + mRangeSerializer.mCommonInclusiveAncestors.RemoveElementAt(0); if (mRangeSerializer.mContextInfoDepth.mStart) { --mRangeSerializer.mContextInfoDepth.mStart; } @@ -1597,13 +1600,13 @@ nsHTMLCopyEncoder::EncodeToStringWithContext(nsAString& aContextString, i = count; while (i > 0) { - node = mCommonInclusiveAncestors.ElementAt(--i); + node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(--i); rv = mNodeSerializer.SerializeNodeStart(*node, 0, -1); NS_ENSURE_SUCCESS(rv, rv); } // i = 0; guaranteed by above while (i < count) { - node = mCommonInclusiveAncestors.ElementAt(i++); + node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(i++); rv = mNodeSerializer.SerializeNodeEnd(*node); NS_ENSURE_SUCCESS(rv, rv); }