Bug 1643721: part 7) Move `mCommonInclusiveAncestors` to `RangeSerializer`. r=masayuki

Preparation for moving `SerializeRangeToString` to `RangeSerializer`.

Differential Revision: https://phabricator.services.mozilla.com/D79118
This commit is contained in:
Mirko Brodesser 2020-06-12 08:54:23 +00:00
Родитель 9b5aaa3706
Коммит 01d1a49b83
1 изменённых файлов: 25 добавлений и 22 удалений

Просмотреть файл

@ -336,10 +336,6 @@ class nsDocumentEncoder : public nsIDocumentEncoder {
// Multiple of the flags defined in nsIDocumentEncoder.idl. // Multiple of the flags defined in nsIDocumentEncoder.idl.
uint32_t mFlags; uint32_t mFlags;
uint32_t mWrapColumn; uint32_t mWrapColumn;
/**
* https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor.
*/
AutoTArray<nsINode*, 8> mCommonInclusiveAncestors;
// Whether the serializer cares about being notified to scan elements to // Whether the serializer cares about being notified to scan elements to
// keep track of whether they are preformatted. This stores the out // keep track of whether they are preformatted. This stores the out
// argument of nsIContentSerializer::Init(). // argument of nsIContentSerializer::Init().
@ -434,6 +430,11 @@ class nsDocumentEncoder : public nsIDocumentEncoder {
*/ */
nsCOMPtr<nsINode> mClosestCommonInclusiveAncestorOfRange; nsCOMPtr<nsINode> mClosestCommonInclusiveAncestorOfRange;
/**
* https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor.
*/
AutoTArray<nsINode*, 8> mCommonInclusiveAncestors;
int32_t mStartRootIndex; int32_t mStartRootIndex;
int32_t mEndRootIndex; int32_t mEndRootIndex;
bool mHaltRangeHint; bool mHaltRangeHint;
@ -562,11 +563,12 @@ nsresult nsDocumentEncoder::SerializeSelection() {
!ParentIsTR(content)) { !ParentIsTR(content)) {
if (!prevNode) { if (!prevNode) {
// Went from a non-<tr> to a <tr> // Went from a non-<tr> to a <tr>
mCommonInclusiveAncestors.Clear(); mRangeSerializer.mCommonInclusiveAncestors.Clear();
nsContentUtils::GetInclusiveAncestors(node->GetParentNode(), nsContentUtils::GetInclusiveAncestors(
mCommonInclusiveAncestors); node->GetParentNode(),
mRangeSerializer.mCommonInclusiveAncestors);
rv = mRangeContextSerializer.SerializeRangeContextStart( rv = mRangeContextSerializer.SerializeRangeContextStart(
mCommonInclusiveAncestors); mRangeSerializer.mCommonInclusiveAncestors);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// Don't let SerializeRangeToString serialize the context again // Don't let SerializeRangeToString serialize the context again
mRangeContextSerializer.mDisableContextSerialize = true; mRangeContextSerializer.mDisableContextSerialize = true;
@ -581,9 +583,10 @@ nsresult nsDocumentEncoder::SerializeSelection() {
// `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext`
// too. Update it here to mimic the old behavior. // too. Update it here to mimic the old behavior.
mCommonInclusiveAncestors.Clear(); mRangeSerializer.mCommonInclusiveAncestors.Clear();
nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), nsContentUtils::GetInclusiveAncestors(
mCommonInclusiveAncestors); prevNode->GetParentNode(),
mRangeSerializer.mCommonInclusiveAncestors);
rv = mRangeContextSerializer.SerializeRangeContextEnd(); rv = mRangeContextSerializer.SerializeRangeContextEnd();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -606,9 +609,9 @@ nsresult nsDocumentEncoder::SerializeSelection() {
// `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext` // `mCommonInclusiveAncestors` is used in `EncodeToStringWithContext`
// too. Update it here to mimic the old behavior. // too. Update it here to mimic the old behavior.
mCommonInclusiveAncestors.Clear(); mRangeSerializer.mCommonInclusiveAncestors.Clear();
nsContentUtils::GetInclusiveAncestors(prevNode->GetParentNode(), nsContentUtils::GetInclusiveAncestors(
mCommonInclusiveAncestors); prevNode->GetParentNode(), mRangeSerializer.mCommonInclusiveAncestors);
rv = mRangeContextSerializer.SerializeRangeContextEnd(); rv = mRangeContextSerializer.SerializeRangeContextEnd();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1160,7 +1163,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) {
int32_t endOffset = aRange->EndOffset(); int32_t endOffset = aRange->EndOffset();
mRangeSerializer.mContextInfoDepth = {}; mRangeSerializer.mContextInfoDepth = {};
mCommonInclusiveAncestors.Clear(); mRangeSerializer.mCommonInclusiveAncestors.Clear();
mRangeSerializer.mRangeBoundariesInclusiveAncestorsAndOffsets = {}; mRangeSerializer.mRangeBoundariesInclusiveAncestorsAndOffsets = {};
auto& inclusiveAncestorsOfStart = auto& inclusiveAncestorsOfStart =
@ -1178,7 +1181,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) {
nsContentUtils::GetInclusiveAncestors( nsContentUtils::GetInclusiveAncestors(
mRangeSerializer.mClosestCommonInclusiveAncestorOfRange, mRangeSerializer.mClosestCommonInclusiveAncestorOfRange,
mCommonInclusiveAncestors); mRangeSerializer.mCommonInclusiveAncestors);
nsContentUtils::GetInclusiveAncestorsAndOffsets( nsContentUtils::GetInclusiveAncestorsAndOffsets(
startContainer, startOffset, &inclusiveAncestorsOfStart, startContainer, startOffset, &inclusiveAncestorsOfStart,
&inclusiveAncestorsOffsetsOfStart); &inclusiveAncestorsOffsetsOfStart);
@ -1196,7 +1199,7 @@ nsresult nsDocumentEncoder::SerializeRangeToString(const nsRange* aRange) {
nsresult rv = NS_OK; nsresult rv = NS_OK;
rv = mRangeContextSerializer.SerializeRangeContextStart( rv = mRangeContextSerializer.SerializeRangeContextStart(
mCommonInclusiveAncestors); mRangeSerializer.mCommonInclusiveAncestors);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (startContainer == endContainer && IsTextNode(startContainer)) { if (startContainer == endContainer && IsTextNode(startContainer)) {
@ -1577,15 +1580,15 @@ nsHTMLCopyEncoder::EncodeToStringWithContext(nsAString& aContextString,
&mNeedsPreformatScanning, aContextString); &mNeedsPreformatScanning, aContextString);
// leaf of ancestors might be text node. If so discard it. // 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; int32_t i;
nsCOMPtr<nsINode> node; nsCOMPtr<nsINode> node;
if (count > 0) { if (count > 0) {
node = mCommonInclusiveAncestors.ElementAt(0); node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(0);
} }
if (node && IsTextNode(node)) { if (node && IsTextNode(node)) {
mCommonInclusiveAncestors.RemoveElementAt(0); mRangeSerializer.mCommonInclusiveAncestors.RemoveElementAt(0);
if (mRangeSerializer.mContextInfoDepth.mStart) { if (mRangeSerializer.mContextInfoDepth.mStart) {
--mRangeSerializer.mContextInfoDepth.mStart; --mRangeSerializer.mContextInfoDepth.mStart;
} }
@ -1597,13 +1600,13 @@ nsHTMLCopyEncoder::EncodeToStringWithContext(nsAString& aContextString,
i = count; i = count;
while (i > 0) { while (i > 0) {
node = mCommonInclusiveAncestors.ElementAt(--i); node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(--i);
rv = mNodeSerializer.SerializeNodeStart(*node, 0, -1); rv = mNodeSerializer.SerializeNodeStart(*node, 0, -1);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
// i = 0; guaranteed by above // i = 0; guaranteed by above
while (i < count) { while (i < count) {
node = mCommonInclusiveAncestors.ElementAt(i++); node = mRangeSerializer.mCommonInclusiveAncestors.ElementAt(i++);
rv = mNodeSerializer.SerializeNodeEnd(*node); rv = mNodeSerializer.SerializeNodeEnd(*node);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }