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.
uint32_t mFlags;
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
// keep track of whether they are preformatted. This stores the out
// argument of nsIContentSerializer::Init().
@ -434,6 +430,11 @@ class nsDocumentEncoder : public nsIDocumentEncoder {
*/
nsCOMPtr<nsINode> mClosestCommonInclusiveAncestorOfRange;
/**
* https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor.
*/
AutoTArray<nsINode*, 8> mCommonInclusiveAncestors;
int32_t mStartRootIndex;
int32_t mEndRootIndex;
bool mHaltRangeHint;
@ -562,11 +563,12 @@ nsresult nsDocumentEncoder::SerializeSelection() {
!ParentIsTR(content)) {
if (!prevNode) {
// Went from a non-<tr> to a <tr>
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<nsINode> 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);
}