зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1377989 - part5: Rename mStartParent of nsRange and similar members of similar objects to mStartContainer r=smaug
MozReview-Commit-ID: 5QJahMKnKEJ --HG-- extra : rebase_source : 0b4aee62fcd70574b3dc44e05392b2a8d6ff6ee5
This commit is contained in:
Родитель
e54f65d40e
Коммит
4ff0c2334b
|
@ -21,7 +21,7 @@ using namespace mozilla::dom;
|
|||
SelectionChangeListener::RawRangeData::RawRangeData(const nsRange* aRange)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
mStartParent = aRange->GetStartContainer(rv);
|
||||
mStartContainer = aRange->GetStartContainer(rv);
|
||||
rv.SuppressException();
|
||||
mEndParent = aRange->GetEndContainer(rv);
|
||||
rv.SuppressException();
|
||||
|
@ -35,7 +35,7 @@ bool
|
|||
SelectionChangeListener::RawRangeData::Equals(const nsRange* aRange)
|
||||
{
|
||||
mozilla::ErrorResult rv;
|
||||
bool eq = mStartParent == aRange->GetStartContainer(rv);
|
||||
bool eq = mStartContainer == aRange->GetStartContainer(rv);
|
||||
rv.SuppressException();
|
||||
eq = eq && mEndParent == aRange->GetEndContainer(rv);
|
||||
rv.SuppressException();
|
||||
|
@ -52,7 +52,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|||
const char* aName,
|
||||
uint32_t aFlags = 0)
|
||||
{
|
||||
ImplCycleCollectionTraverse(aCallback, aField.mStartParent, "mStartParent", aFlags);
|
||||
ImplCycleCollectionTraverse(aCallback, aField.mStartContainer,
|
||||
"mStartContainer", aFlags);
|
||||
ImplCycleCollectionTraverse(aCallback, aField.mEndParent, "mEndParent", aFlags);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
// could potentially break the comparison logic. In reality, this is extremely
|
||||
// unlikely to occur (potentially impossible), but these nsCOMPtrs are safer.
|
||||
// They are never dereferenced.
|
||||
nsCOMPtr<nsINode> mStartParent;
|
||||
nsCOMPtr<nsINode> mStartContainer;
|
||||
nsCOMPtr<nsINode> mEndParent;
|
||||
|
||||
// XXX These are int32_ts on nsRange, but uint32_ts in the return value
|
||||
|
|
|
@ -337,7 +337,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsRange)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStartContainer)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRoot)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelection)
|
||||
|
@ -460,7 +460,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
++mEndOffset;
|
||||
mEndOffsetWasIncremented = true;
|
||||
}
|
||||
if (parentNode == mStartParent && mStartOffset > 0 &&
|
||||
if (parentNode == mStartContainer && mStartOffset > 0 &&
|
||||
(index != -1 ? index : parentNode->IndexOf(aContent)) + 1 == mStartOffset) {
|
||||
++mStartOffset;
|
||||
mStartOffsetWasIncremented = true;
|
||||
|
@ -476,7 +476,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
|
||||
// If the changed node contains our start boundary and the change starts
|
||||
// before the boundary we'll need to adjust the offset.
|
||||
if (aContent == mStartParent &&
|
||||
if (aContent == mStartContainer &&
|
||||
aInfo->mChangeStart < static_cast<uint32_t>(mStartOffset)) {
|
||||
if (aInfo->mDetails) {
|
||||
// splitText(), aInfo->mDetails->mNextSibling is the new text node
|
||||
|
@ -491,12 +491,12 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
newRoot = IsValidBoundary(newStartNode);
|
||||
}
|
||||
|
||||
bool isCommonAncestor = IsInSelection() && mStartParent == mEndParent;
|
||||
bool isCommonAncestor = IsInSelection() && mStartContainer == mEndParent;
|
||||
if (isCommonAncestor) {
|
||||
UnregisterCommonAncestor(mStartParent);
|
||||
UnregisterCommonAncestor(mStartContainer);
|
||||
RegisterCommonAncestor(newStartNode);
|
||||
}
|
||||
if (mStartParent->IsDescendantOfCommonAncestorForRangeInSelection()) {
|
||||
if (mStartContainer->IsDescendantOfCommonAncestorForRangeInSelection()) {
|
||||
newStartNode->SetDescendantOfCommonAncestorForRangeInSelection();
|
||||
}
|
||||
} else {
|
||||
|
@ -524,11 +524,11 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
newEndOffset = static_cast<uint32_t>(mEndOffset) - aInfo->mChangeStart;
|
||||
newEndNode = aInfo->mDetails->mNextSibling;
|
||||
|
||||
bool isCommonAncestor = IsInSelection() && mStartParent == mEndParent;
|
||||
bool isCommonAncestor = IsInSelection() && mStartContainer == mEndParent;
|
||||
if (isCommonAncestor && !newStartNode) {
|
||||
// The split occurs inside the range.
|
||||
UnregisterCommonAncestor(mStartParent);
|
||||
RegisterCommonAncestor(mStartParent->GetParentNode());
|
||||
UnregisterCommonAncestor(mStartContainer);
|
||||
RegisterCommonAncestor(mStartContainer->GetParentNode());
|
||||
newEndNode->SetDescendantOfCommonAncestorForRangeInSelection();
|
||||
} else if (mEndParent->IsDescendantOfCommonAncestorForRangeInSelection()) {
|
||||
newEndNode->SetDescendantOfCommonAncestorForRangeInSelection();
|
||||
|
@ -546,7 +546,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// normalize(), aInfo->mDetails->mNextSibling is the merged text node
|
||||
// that will be removed
|
||||
nsIContent* removed = aInfo->mDetails->mNextSibling;
|
||||
if (removed == mStartParent) {
|
||||
if (removed == mStartContainer) {
|
||||
newStartOffset = static_cast<uint32_t>(mStartOffset) + aInfo->mChangeStart;
|
||||
newStartNode = aContent;
|
||||
if (MOZ_UNLIKELY(removed == mRoot)) {
|
||||
|
@ -567,7 +567,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
// the boundary. (The m*Offset > 0 check is an optimization - a boundary
|
||||
// point before the first child is never affected by normalize().)
|
||||
nsINode* parentNode = aContent->GetParentNode();
|
||||
if (parentNode == mStartParent && mStartOffset > 0 &&
|
||||
if (parentNode == mStartContainer && mStartOffset > 0 &&
|
||||
uint32_t(mStartOffset) < parentNode->GetChildCount() &&
|
||||
removed == parentNode->GetChildAt(mStartOffset)) {
|
||||
newStartNode = aContent;
|
||||
|
@ -583,7 +583,7 @@ nsRange::CharacterDataChanged(nsIDocument* aDocument,
|
|||
|
||||
if (newStartNode || newEndNode) {
|
||||
if (!newStartNode) {
|
||||
newStartNode = mStartParent;
|
||||
newStartNode = mStartContainer;
|
||||
newStartOffset = mStartOffset;
|
||||
}
|
||||
if (!newEndNode) {
|
||||
|
@ -639,7 +639,7 @@ nsRange::ContentInserted(nsIDocument* aDocument,
|
|||
nsINode* container = NODE_FROM(aContainer, aDocument);
|
||||
|
||||
// Adjust position if a sibling was inserted.
|
||||
if (container == mStartParent && aIndexInContainer < mStartOffset &&
|
||||
if (container == mStartContainer && aIndexInContainer < mStartOffset &&
|
||||
!mStartOffsetWasIncremented) {
|
||||
++mStartOffset;
|
||||
}
|
||||
|
@ -683,13 +683,14 @@ nsRange::ContentRemoved(nsIDocument* aDocument,
|
|||
bool didCheckStartParentDescendant = false;
|
||||
|
||||
// Adjust position if a sibling was removed...
|
||||
if (container == mStartParent) {
|
||||
if (container == mStartContainer) {
|
||||
if (aIndexInContainer < mStartOffset) {
|
||||
--mStartOffset;
|
||||
}
|
||||
} else { // ...or gravitate if an ancestor was removed.
|
||||
didCheckStartParentDescendant = true;
|
||||
gravitateStart = nsContentUtils::ContentIsDescendantOf(mStartParent, aChild);
|
||||
gravitateStart =
|
||||
nsContentUtils::ContentIsDescendantOf(mStartContainer, aChild);
|
||||
}
|
||||
|
||||
// Do same thing for end boundry.
|
||||
|
@ -697,14 +698,14 @@ nsRange::ContentRemoved(nsIDocument* aDocument,
|
|||
if (aIndexInContainer < mEndOffset) {
|
||||
--mEndOffset;
|
||||
}
|
||||
} else if (didCheckStartParentDescendant && mStartParent == mEndParent) {
|
||||
} else if (didCheckStartParentDescendant && mStartContainer == mEndParent) {
|
||||
gravitateEnd = gravitateStart;
|
||||
} else {
|
||||
gravitateEnd = nsContentUtils::ContentIsDescendantOf(mEndParent, aChild);
|
||||
}
|
||||
|
||||
if (gravitateStart || gravitateEnd) {
|
||||
DoSetRange(gravitateStart ? container : mStartParent.get(),
|
||||
DoSetRange(gravitateStart ? container : mStartContainer.get(),
|
||||
gravitateStart ? aIndexInContainer : mStartOffset,
|
||||
gravitateEnd ? container : mEndParent.get(),
|
||||
gravitateEnd ? aIndexInContainer : mEndOffset,
|
||||
|
@ -724,7 +725,7 @@ nsRange::ParentChainChanged(nsIContent *aContent)
|
|||
mAssertNextInsertOrAppendIndex == -1,
|
||||
"splitText failed to notify insert/append?");
|
||||
NS_ASSERTION(mRoot == aContent, "Wrong ParentChainChanged notification?");
|
||||
nsINode* newRoot = IsValidBoundary(mStartParent);
|
||||
nsINode* newRoot = IsValidBoundary(mStartContainer);
|
||||
NS_ASSERTION(newRoot, "No valid boundary or root found!");
|
||||
if (newRoot != IsValidBoundary(mEndParent)) {
|
||||
// Sometimes ordering involved in cycle collection can lead to our
|
||||
|
@ -741,7 +742,7 @@ nsRange::ParentChainChanged(nsIContent *aContent)
|
|||
}
|
||||
// This is safe without holding a strong ref to self as long as the change
|
||||
// of mRoot is the last thing in DoSetRange.
|
||||
DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, newRoot);
|
||||
DoSetRange(mStartContainer, mStartOffset, mEndParent, mEndOffset, newRoot);
|
||||
}
|
||||
|
||||
/******************************************************
|
||||
|
@ -812,7 +813,8 @@ nsRange::ComparePoint(nsINode& aParent, uint32_t aOffset, ErrorResult& aRv)
|
|||
|
||||
int32_t cmp;
|
||||
if ((cmp = nsContentUtils::ComparePoints(&aParent, aOffset,
|
||||
mStartParent, mStartOffset)) <= 0) {
|
||||
mStartContainer,
|
||||
mStartOffset)) <= 0) {
|
||||
|
||||
return cmp;
|
||||
}
|
||||
|
@ -860,7 +862,7 @@ nsRange::IntersectsNode(nsINode& aNode, ErrorResult& aRv)
|
|||
// Steps 6-7.
|
||||
// Note: if disconnected is true, ComparePoints returns 1.
|
||||
bool disconnected = false;
|
||||
bool result = nsContentUtils::ComparePoints(mStartParent, mStartOffset,
|
||||
bool result = nsContentUtils::ComparePoints(mStartContainer, mStartOffset,
|
||||
parent, nodeIndex + 1,
|
||||
&disconnected) < 0 &&
|
||||
nsContentUtils::ComparePoints(parent, nodeIndex,
|
||||
|
@ -920,14 +922,15 @@ nsRange::DoSetRange(nsINode* aStartN, int32_t aStartOffset,
|
|||
aRoot->AddMutationObserver(this);
|
||||
}
|
||||
}
|
||||
bool checkCommonAncestor = (mStartParent != aStartN || mEndParent != aEndN) &&
|
||||
IsInSelection() && !aNotInsertedYet;
|
||||
bool checkCommonAncestor =
|
||||
(mStartContainer != aStartN || mEndParent != aEndN) &&
|
||||
IsInSelection() && !aNotInsertedYet;
|
||||
nsINode* oldCommonAncestor = checkCommonAncestor ? GetCommonAncestor() : nullptr;
|
||||
mStartParent = aStartN;
|
||||
mStartContainer = aStartN;
|
||||
mStartOffset = aStartOffset;
|
||||
mEndParent = aEndN;
|
||||
mEndOffset = aEndOffset;
|
||||
mIsPositioned = !!mStartParent;
|
||||
mIsPositioned = !!mStartContainer;
|
||||
if (checkCommonAncestor) {
|
||||
nsINode* newCommonAncestor = GetCommonAncestor();
|
||||
if (newCommonAncestor != oldCommonAncestor) {
|
||||
|
@ -997,7 +1000,7 @@ nsINode*
|
|||
nsRange::GetCommonAncestor() const
|
||||
{
|
||||
return mIsPositioned ?
|
||||
nsContentUtils::GetCommonAncestor(mStartParent, mEndParent) :
|
||||
nsContentUtils::GetCommonAncestor(mStartContainer, mEndParent) :
|
||||
nullptr;
|
||||
}
|
||||
|
||||
|
@ -1017,7 +1020,7 @@ nsRange::GetStartContainer(nsIDOMNode** aStartParent)
|
|||
if (!mIsPositioned)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
return CallQueryInterface(mStartParent, aStartParent);
|
||||
return CallQueryInterface(mStartContainer, aStartParent);
|
||||
}
|
||||
|
||||
nsINode*
|
||||
|
@ -1028,7 +1031,7 @@ nsRange::GetStartContainer(ErrorResult& aRv) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return mStartParent;
|
||||
return mStartContainer;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1114,7 +1117,7 @@ nsRange::GetCommonAncestorContainer(ErrorResult& aRv) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return nsContentUtils::GetCommonAncestor(mStartParent, mEndParent);
|
||||
return nsContentUtils::GetCommonAncestor(mStartContainer, mEndParent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -1367,14 +1370,14 @@ nsRange::SetEnd(nsINode* aParent, int32_t aOffset)
|
|||
// Collapse if not positioned yet, if positioned in another doc or
|
||||
// if the new end is before start.
|
||||
if (!mIsPositioned || newRoot != mRoot ||
|
||||
nsContentUtils::ComparePoints(mStartParent, mStartOffset,
|
||||
nsContentUtils::ComparePoints(mStartContainer, mStartOffset,
|
||||
aParent, aOffset) == 1) {
|
||||
DoSetRange(aParent, aOffset, aParent, aOffset, newRoot);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DoSetRange(mStartParent, mStartOffset, aParent, aOffset, mRoot);
|
||||
DoSetRange(mStartContainer, mStartOffset, aParent, aOffset, mRoot);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1516,10 +1519,12 @@ nsRange::Collapse(bool aToStart)
|
|||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
AutoInvalidateSelection atEndOfBlock(this);
|
||||
if (aToStart)
|
||||
DoSetRange(mStartParent, mStartOffset, mStartParent, mStartOffset, mRoot);
|
||||
else
|
||||
if (aToStart) {
|
||||
DoSetRange(mStartContainer, mStartOffset,
|
||||
mStartContainer, mStartOffset, mRoot);
|
||||
} else {
|
||||
DoSetRange(mEndParent, mEndOffset, mEndParent, mEndOffset, mRoot);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2005,7 +2010,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
*aFragment = nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = mStartParent->OwnerDoc();
|
||||
nsCOMPtr<nsIDocument> doc = mStartContainer->OwnerDoc();
|
||||
|
||||
ErrorResult res;
|
||||
nsCOMPtr<nsINode> commonAncestor = GetCommonAncestorContainer(res);
|
||||
|
@ -2024,7 +2029,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
// Save the range end points locally to avoid interference
|
||||
// of Range gravity during our edits!
|
||||
|
||||
nsCOMPtr<nsINode> startContainer = mStartParent;
|
||||
nsCOMPtr<nsINode> startContainer = mStartContainer;
|
||||
int32_t startOffset = mStartOffset;
|
||||
nsCOMPtr<nsINode> endContainer = mEndParent;
|
||||
int32_t endOffset = mEndOffset;
|
||||
|
@ -2328,7 +2333,7 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange,
|
|||
|
||||
switch (aHow) {
|
||||
case nsIDOMRange::START_TO_START:
|
||||
ourNode = mStartParent;
|
||||
ourNode = mStartContainer;
|
||||
ourOffset = mStartOffset;
|
||||
otherNode = aOtherRange.GetStartContainer();
|
||||
otherOffset = aOtherRange.StartOffset();
|
||||
|
@ -2340,7 +2345,7 @@ nsRange::CompareBoundaryPoints(uint16_t aHow, nsRange& aOtherRange,
|
|||
otherOffset = aOtherRange.StartOffset();
|
||||
break;
|
||||
case nsIDOMRange::END_TO_START:
|
||||
ourNode = mStartParent;
|
||||
ourNode = mStartContainer;
|
||||
ourOffset = mStartOffset;
|
||||
otherNode = aOtherRange.GetEndContainer();
|
||||
otherOffset = aOtherRange.EndOffset();
|
||||
|
@ -2430,7 +2435,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
|||
nsCOMPtr<nsINode> commonAncestor = GetCommonAncestorContainer(aRv);
|
||||
MOZ_ASSERT(!aRv.Failed(), "GetCommonAncestorContainer() shouldn't fail!");
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = mStartParent->OwnerDoc();
|
||||
nsCOMPtr<nsIDocument> doc = mStartContainer->OwnerDoc();
|
||||
NS_ASSERTION(doc, "CloneContents needs a document to continue.");
|
||||
if (!doc) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
|
@ -2479,7 +2484,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
|||
nsCOMPtr<nsINode> node = iter.GetCurrentNode();
|
||||
bool deepClone = !node->IsElement() ||
|
||||
(!(node == mEndParent && mEndOffset == 0) &&
|
||||
!(node == mStartParent &&
|
||||
!(node == mStartContainer &&
|
||||
mStartOffset ==
|
||||
int32_t(node->AsElement()->GetChildCount())));
|
||||
|
||||
|
@ -2520,8 +2525,7 @@ nsRange::CloneContents(ErrorResult& aRv)
|
|||
}
|
||||
}
|
||||
|
||||
if (node == mStartParent)
|
||||
{
|
||||
if (node == mStartContainer) {
|
||||
// We don't need any data before mStartOffset, so just
|
||||
// delete it!
|
||||
|
||||
|
@ -2635,7 +2639,8 @@ nsRange::CloneRange() const
|
|||
|
||||
range->SetMaySpanAnonymousSubtrees(mMaySpanAnonymousSubtrees);
|
||||
|
||||
range->DoSetRange(mStartParent, mStartOffset, mEndParent, mEndOffset, mRoot);
|
||||
range->DoSetRange(mStartContainer, mStartOffset,
|
||||
mEndParent, mEndOffset, mRoot);
|
||||
|
||||
return range.forget();
|
||||
}
|
||||
|
@ -2789,10 +2794,10 @@ nsRange::SurroundContents(nsINode& aNewParent, ErrorResult& aRv)
|
|||
}
|
||||
// INVALID_STATE_ERROR: Raised if the Range partially selects a non-text
|
||||
// node.
|
||||
if (mStartParent != mEndParent) {
|
||||
bool startIsText = mStartParent->IsNodeOfType(nsINode::eTEXT);
|
||||
if (mStartContainer != mEndParent) {
|
||||
bool startIsText = mStartContainer->IsNodeOfType(nsINode::eTEXT);
|
||||
bool endIsText = mEndParent->IsNodeOfType(nsINode::eTEXT);
|
||||
nsINode* startGrandParent = mStartParent->GetParentNode();
|
||||
nsINode* startGrandParent = mStartContainer->GetParentNode();
|
||||
nsINode* endGrandParent = mEndParent->GetParentNode();
|
||||
if (!((startIsText && endIsText &&
|
||||
startGrandParent &&
|
||||
|
@ -2802,7 +2807,7 @@ nsRange::SurroundContents(nsINode& aNewParent, ErrorResult& aRv)
|
|||
startGrandParent == mEndParent) ||
|
||||
(endIsText &&
|
||||
endGrandParent &&
|
||||
endGrandParent == mStartParent))) {
|
||||
endGrandParent == mStartContainer))) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
@ -2890,15 +2895,14 @@ nsRange::ToString(nsAString& aReturn)
|
|||
#endif /* DEBUG */
|
||||
|
||||
// effeciency hack for simple case
|
||||
if (mStartParent == mEndParent)
|
||||
{
|
||||
nsCOMPtr<nsIDOMText> textNode( do_QueryInterface(mStartParent) );
|
||||
if (mStartContainer == mEndParent) {
|
||||
nsCOMPtr<nsIDOMText> textNode = do_QueryInterface(mStartContainer);
|
||||
|
||||
if (textNode)
|
||||
{
|
||||
#ifdef DEBUG_range
|
||||
// If debug, dump it:
|
||||
nsCOMPtr<nsIContent> cN (do_QueryInterface(mStartParent));
|
||||
nsCOMPtr<nsIContent> cN = do_QueryInterface(mStartContainer);
|
||||
if (cN) cN->List(stdout);
|
||||
printf("End Range dump: -----------------------\n");
|
||||
#endif /* DEBUG */
|
||||
|
@ -2910,8 +2914,8 @@ nsRange::ToString(nsAString& aReturn)
|
|||
}
|
||||
}
|
||||
|
||||
/* complex case: mStartParent != mEndParent, or mStartParent not a text node
|
||||
revisit - there are potential optimizations here and also tradeoffs.
|
||||
/* complex case: mStartContainer != mEndParent, or mStartParent not a text
|
||||
node revisit - there are potential optimizations here and also tradeoffs.
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
|
||||
|
@ -2933,8 +2937,7 @@ nsRange::ToString(nsAString& aReturn)
|
|||
nsCOMPtr<nsIDOMText> textNode(do_QueryInterface(n));
|
||||
if (textNode) // if it's a text node, get the text
|
||||
{
|
||||
if (n == mStartParent) // only include text past start offset
|
||||
{
|
||||
if (n == mStartContainer) { // only include text past start offset
|
||||
uint32_t strLength;
|
||||
textNode->GetLength(&strLength);
|
||||
textNode->SubstringData(mStartOffset,strLength-mStartOffset,tempString);
|
||||
|
@ -2974,7 +2977,7 @@ nsRange::CreateContextualFragment(const nsAString& aFragment,
|
|||
nsIDOMDocumentFragment** aReturn)
|
||||
{
|
||||
if (mIsPositioned) {
|
||||
return nsContentUtils::CreateContextualFragment(mStartParent, aFragment,
|
||||
return nsContentUtils::CreateContextualFragment(mStartContainer, aFragment,
|
||||
false, aReturn);
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -2988,7 +2991,7 @@ nsRange::CreateContextualFragment(const nsAString& aFragment, ErrorResult& aRv)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
return nsContentUtils::CreateContextualFragment(mStartParent, aFragment,
|
||||
return nsContentUtils::CreateContextualFragment(mStartContainer, aFragment,
|
||||
false, aRv);
|
||||
}
|
||||
|
||||
|
@ -3183,12 +3186,12 @@ already_AddRefed<DOMRect>
|
|||
nsRange::GetBoundingClientRect(bool aClampToEdge, bool aFlushLayout)
|
||||
{
|
||||
RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
|
||||
if (!mStartParent) {
|
||||
if (!mStartContainer) {
|
||||
return rect.forget();
|
||||
}
|
||||
|
||||
nsLayoutUtils::RectAccumulator accumulator;
|
||||
CollectClientRectsAndText(&accumulator, nullptr, this, mStartParent,
|
||||
CollectClientRectsAndText(&accumulator, nullptr, this, mStartContainer,
|
||||
mStartOffset, mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
|
||||
|
||||
nsRect r = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect :
|
||||
|
@ -3207,7 +3210,7 @@ nsRange::GetClientRects(nsIDOMClientRectList** aResult)
|
|||
already_AddRefed<DOMRectList>
|
||||
nsRange::GetClientRects(bool aClampToEdge, bool aFlushLayout)
|
||||
{
|
||||
if (!mStartParent) {
|
||||
if (!mStartContainer) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -3216,7 +3219,7 @@ nsRange::GetClientRects(bool aClampToEdge, bool aFlushLayout)
|
|||
|
||||
nsLayoutUtils::RectListBuilder builder(rectList);
|
||||
|
||||
CollectClientRectsAndText(&builder, nullptr, this, mStartParent,
|
||||
CollectClientRectsAndText(&builder, nullptr, this, mStartContainer,
|
||||
mStartOffset, mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
|
||||
return rectList.forget();
|
||||
}
|
||||
|
@ -3226,7 +3229,7 @@ nsRange::GetClientRectsAndTexts(
|
|||
mozilla::dom::ClientRectsAndTexts& aResult,
|
||||
ErrorResult& aErr)
|
||||
{
|
||||
if (!mStartParent) {
|
||||
if (!mStartContainer) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -3235,7 +3238,7 @@ nsRange::GetClientRectsAndTexts(
|
|||
nsLayoutUtils::RectListBuilder builder(aResult.mRectList);
|
||||
|
||||
CollectClientRectsAndText(&builder, &aResult.mTextList, this,
|
||||
mStartParent, mStartOffset, mEndParent, mEndOffset, true, true);
|
||||
mStartContainer, mStartOffset, mEndParent, mEndOffset, true, true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -3243,18 +3246,18 @@ nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
|
|||
{
|
||||
*aResult = nullptr;
|
||||
|
||||
NS_ENSURE_TRUE(mStartParent, NS_ERROR_UNEXPECTED);
|
||||
NS_ENSURE_TRUE(mStartContainer, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsINode> startContainer = do_QueryInterface(mStartParent);
|
||||
nsCOMPtr<nsINode> startContainer = do_QueryInterface(mStartContainer);
|
||||
nsCOMPtr<nsINode> endContainer = do_QueryInterface(mEndParent);
|
||||
|
||||
// Flush out layout so our frames are up to date.
|
||||
nsIDocument* doc = mStartParent->OwnerDoc();
|
||||
nsIDocument* doc = mStartContainer->OwnerDoc();
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
||||
doc->FlushPendingNotifications(FlushType::Frames);
|
||||
|
||||
// Recheck whether we're still in the document
|
||||
NS_ENSURE_TRUE(mStartParent->IsInUncomposedDoc(), NS_ERROR_UNEXPECTED);
|
||||
NS_ENSURE_TRUE(mStartContainer->IsInUncomposedDoc(), NS_ERROR_UNEXPECTED);
|
||||
|
||||
RefPtr<nsFontFaceList> fontFaceList = new nsFontFaceList();
|
||||
|
||||
|
@ -3303,7 +3306,7 @@ nsRange::GetRegisteredCommonAncestor()
|
|||
{
|
||||
NS_ASSERTION(IsInSelection(),
|
||||
"GetRegisteredCommonAncestor only valid for range in selection");
|
||||
nsINode* ancestor = GetNextRangeCommonAncestor(mStartParent);
|
||||
nsINode* ancestor = GetNextRangeCommonAncestor(mStartContainer);
|
||||
while (ancestor) {
|
||||
RangeHashTable* ranges =
|
||||
static_cast<RangeHashTable*>(ancestor->GetProperty(nsGkAtoms::range));
|
||||
|
@ -3357,7 +3360,7 @@ nsRange::ExcludeNonSelectableNodes(nsTArray<RefPtr<nsRange>>* aOutRanges)
|
|||
{
|
||||
MOZ_ASSERT(mIsPositioned);
|
||||
MOZ_ASSERT(mEndParent);
|
||||
MOZ_ASSERT(mStartParent);
|
||||
MOZ_ASSERT(mStartContainer);
|
||||
|
||||
nsRange* range = this;
|
||||
RefPtr<nsRange> newRange;
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
|
||||
nsINode* GetStartContainer() const
|
||||
{
|
||||
return mStartParent;
|
||||
return mStartContainer;
|
||||
}
|
||||
|
||||
nsINode* GetEndContainer() const
|
||||
|
@ -213,7 +213,7 @@ public:
|
|||
|
||||
bool Collapsed() const
|
||||
{
|
||||
return mIsPositioned && mStartParent == mEndParent &&
|
||||
return mIsPositioned && mStartContainer == mEndParent &&
|
||||
mStartOffset == mEndOffset;
|
||||
}
|
||||
already_AddRefed<mozilla::dom::DocumentFragment>
|
||||
|
@ -424,7 +424,7 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIDocument> mOwner;
|
||||
nsCOMPtr<nsINode> mRoot;
|
||||
nsCOMPtr<nsINode> mStartParent;
|
||||
nsCOMPtr<nsINode> mStartContainer;
|
||||
nsCOMPtr<nsINode> mEndParent;
|
||||
RefPtr<mozilla::dom::Selection> mSelection;
|
||||
int32_t mStartOffset;
|
||||
|
|
|
@ -2867,7 +2867,7 @@ EditorBase::CreateTxnForJoinNode(nsINode& aLeftNode,
|
|||
struct SavedRange final
|
||||
{
|
||||
RefPtr<Selection> mSelection;
|
||||
nsCOMPtr<nsINode> mStartNode;
|
||||
nsCOMPtr<nsINode> mStartContainer;
|
||||
nsCOMPtr<nsINode> mEndNode;
|
||||
int32_t mStartOffset;
|
||||
int32_t mEndOffset;
|
||||
|
@ -2894,7 +2894,7 @@ EditorBase::SplitNodeImpl(nsIContent& aExistingRightNode,
|
|||
for (uint32_t j = 0; j < range.mSelection->RangeCount(); ++j) {
|
||||
RefPtr<nsRange> r = range.mSelection->GetRangeAt(j);
|
||||
MOZ_ASSERT(r->IsPositioned());
|
||||
range.mStartNode = r->GetStartContainer();
|
||||
range.mStartContainer = r->GetStartContainer();
|
||||
range.mStartOffset = r->StartOffset();
|
||||
range.mEndNode = r->GetEndContainer();
|
||||
range.mEndOffset = r->EndOffset();
|
||||
|
@ -2974,9 +2974,9 @@ EditorBase::SplitNodeImpl(nsIContent& aExistingRightNode,
|
|||
}
|
||||
|
||||
// Split the selection into existing node and new node.
|
||||
if (range.mStartNode == &aExistingRightNode) {
|
||||
if (range.mStartContainer == &aExistingRightNode) {
|
||||
if (range.mStartOffset < aOffset) {
|
||||
range.mStartNode = &aNewLeftNode;
|
||||
range.mStartContainer = &aNewLeftNode;
|
||||
} else {
|
||||
range.mStartOffset -= aOffset;
|
||||
}
|
||||
|
@ -2991,7 +2991,8 @@ EditorBase::SplitNodeImpl(nsIContent& aExistingRightNode,
|
|||
}
|
||||
|
||||
RefPtr<nsRange> newRange;
|
||||
nsresult rv = nsRange::CreateRange(range.mStartNode, range.mStartOffset,
|
||||
nsresult rv = nsRange::CreateRange(range.mStartContainer,
|
||||
range.mStartOffset,
|
||||
range.mEndNode, range.mEndOffset,
|
||||
getter_AddRefs(newRange));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -3041,7 +3042,7 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
|||
for (uint32_t j = 0; j < range.mSelection->RangeCount(); ++j) {
|
||||
RefPtr<nsRange> r = range.mSelection->GetRangeAt(j);
|
||||
MOZ_ASSERT(r->IsPositioned());
|
||||
range.mStartNode = r->GetStartContainer();
|
||||
range.mStartContainer = r->GetStartContainer();
|
||||
range.mStartOffset = r->StartOffset();
|
||||
range.mEndNode = r->GetEndContainer();
|
||||
range.mEndOffset = r->EndOffset();
|
||||
|
@ -3049,11 +3050,11 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
|||
// If selection endpoint is between the nodes, remember it as being
|
||||
// in the one that is going away instead. This simplifies later selection
|
||||
// adjustment logic at end of this method.
|
||||
if (range.mStartNode) {
|
||||
if (range.mStartNode == parent &&
|
||||
if (range.mStartContainer) {
|
||||
if (range.mStartContainer == parent &&
|
||||
joinOffset < range.mStartOffset &&
|
||||
range.mStartOffset <= keepOffset) {
|
||||
range.mStartNode = aNodeToJoin;
|
||||
range.mStartContainer = aNodeToJoin;
|
||||
range.mStartOffset = firstNodeLength;
|
||||
}
|
||||
if (range.mEndNode == parent &&
|
||||
|
@ -3125,9 +3126,9 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
|||
}
|
||||
|
||||
// Check to see if we joined nodes where selection starts.
|
||||
if (range.mStartNode == aNodeToJoin) {
|
||||
range.mStartNode = aNodeToKeep;
|
||||
} else if (range.mStartNode == aNodeToKeep) {
|
||||
if (range.mStartContainer == aNodeToJoin) {
|
||||
range.mStartContainer = aNodeToKeep;
|
||||
} else if (range.mStartContainer == aNodeToKeep) {
|
||||
range.mStartOffset += firstNodeLength;
|
||||
}
|
||||
|
||||
|
@ -3139,7 +3140,8 @@ EditorBase::JoinNodesImpl(nsINode* aNodeToKeep,
|
|||
}
|
||||
|
||||
RefPtr<nsRange> newRange;
|
||||
nsresult rv = nsRange::CreateRange(range.mStartNode, range.mStartOffset,
|
||||
nsresult rv = nsRange::CreateRange(range.mStartContainer,
|
||||
range.mStartOffset,
|
||||
range.mEndNode, range.mEndOffset,
|
||||
getter_AddRefs(newRange));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
|
|
@ -350,11 +350,11 @@ HTMLEditRules::BeforeEdit(EditAction action,
|
|||
if (NS_WARN_IF(!selection) || !selection->RangeCount()) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mRangeItem->startNode = selection->GetRangeAt(0)->GetStartContainer();
|
||||
mRangeItem->startOffset = selection->GetRangeAt(0)->StartOffset();
|
||||
mRangeItem->mStartContainer = selection->GetRangeAt(0)->GetStartContainer();
|
||||
mRangeItem->mStartOffset = selection->GetRangeAt(0)->StartOffset();
|
||||
mRangeItem->endNode = selection->GetRangeAt(0)->GetEndContainer();
|
||||
mRangeItem->endOffset = selection->GetRangeAt(0)->EndOffset();
|
||||
nsCOMPtr<nsINode> selStartNode = mRangeItem->startNode;
|
||||
nsCOMPtr<nsINode> selStartNode = mRangeItem->mStartContainer;
|
||||
nsCOMPtr<nsINode> selEndNode = mRangeItem->endNode;
|
||||
|
||||
// Register with range updater to track this as we perturb the doc
|
||||
|
@ -517,13 +517,13 @@ HTMLEditRules::AfterEditInner(EditAction action,
|
|||
|
||||
// also do this for original selection endpoints.
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
NS_ENSURE_STATE(mRangeItem->startNode);
|
||||
NS_ENSURE_STATE(mRangeItem->mStartContainer);
|
||||
NS_ENSURE_STATE(mRangeItem->endNode);
|
||||
WSRunObject(mHTMLEditor, mRangeItem->startNode,
|
||||
mRangeItem->startOffset).AdjustWhitespace();
|
||||
WSRunObject(mHTMLEditor, mRangeItem->mStartContainer,
|
||||
mRangeItem->mStartOffset).AdjustWhitespace();
|
||||
// we only need to handle old selection endpoint if it was different from start
|
||||
if (mRangeItem->startNode != mRangeItem->endNode ||
|
||||
mRangeItem->startOffset != mRangeItem->endOffset) {
|
||||
if (mRangeItem->mStartContainer != mRangeItem->endNode ||
|
||||
mRangeItem->mStartOffset != mRangeItem->endOffset) {
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
WSRunObject(mHTMLEditor, mRangeItem->endNode,
|
||||
mRangeItem->endOffset).AdjustWhitespace();
|
||||
|
@ -563,11 +563,12 @@ HTMLEditRules::AfterEditInner(EditAction action,
|
|||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
|
||||
nsresult rv =
|
||||
mHTMLEditor->HandleInlineSpellCheck(action, selection,
|
||||
GetAsDOMNode(mRangeItem->startNode),
|
||||
mRangeItem->startOffset,
|
||||
rangeStartParent, rangeStartOffset,
|
||||
rangeEndParent, rangeEndOffset);
|
||||
mHTMLEditor->HandleInlineSpellCheck(
|
||||
action, selection,
|
||||
GetAsDOMNode(mRangeItem->mStartContainer),
|
||||
mRangeItem->mStartOffset,
|
||||
rangeStartParent, rangeStartOffset,
|
||||
rangeEndParent, rangeEndOffset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// detect empty doc
|
||||
|
@ -6114,7 +6115,8 @@ HTMLEditRules::GetParagraphFormatNodes(
|
|||
nsresult
|
||||
HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& item)
|
||||
{
|
||||
bool isCollapsed = ((item.startNode == item.endNode) && (item.startOffset == item.endOffset));
|
||||
bool isCollapsed = item.mStartContainer == item.endNode &&
|
||||
item.mStartOffset == item.endOffset;
|
||||
|
||||
nsCOMPtr<nsIContent> endInline = GetHighestInlineParent(*item.endNode);
|
||||
|
||||
|
@ -6133,19 +6135,21 @@ HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& item)
|
|||
item.endOffset = resultEndOffset;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> startInline = GetHighestInlineParent(*item.startNode);
|
||||
nsCOMPtr<nsIContent> startInline =
|
||||
GetHighestInlineParent(*item.mStartContainer);
|
||||
|
||||
if (startInline) {
|
||||
nsCOMPtr<nsINode> resultStartNode = startInline->GetParentNode();
|
||||
NS_ENSURE_STATE(mHTMLEditor);
|
||||
int32_t resultStartOffset =
|
||||
mHTMLEditor->SplitNodeDeep(*startInline, *item.startNode->AsContent(),
|
||||
item.startOffset,
|
||||
mHTMLEditor->SplitNodeDeep(*startInline,
|
||||
*item.mStartContainer->AsContent(),
|
||||
item.mStartOffset,
|
||||
EditorBase::EmptyContainers::no);
|
||||
NS_ENSURE_TRUE(resultStartOffset != -1, NS_ERROR_FAILURE);
|
||||
// reset range
|
||||
item.startNode = resultStartNode;
|
||||
item.startOffset = resultStartOffset;
|
||||
item.mStartContainer = resultStartNode;
|
||||
item.mStartOffset = resultStartOffset;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -232,8 +232,8 @@ RangeUpdater::SelAdjCreateNode(nsINode* aParent,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == aParent && item->startOffset > aPosition) {
|
||||
item->startOffset++;
|
||||
if (item->mStartContainer == aParent && item->mStartOffset > aPosition) {
|
||||
item->mStartOffset++;
|
||||
}
|
||||
if (item->endNode == aParent && item->endOffset > aPosition) {
|
||||
item->endOffset++;
|
||||
|
@ -270,17 +270,17 @@ RangeUpdater::SelAdjDeleteNode(nsINode* aNode)
|
|||
RangeItem* item = mArray[i];
|
||||
MOZ_ASSERT(item);
|
||||
|
||||
if (item->startNode == parent && item->startOffset > offset) {
|
||||
item->startOffset--;
|
||||
if (item->mStartContainer == parent && item->mStartOffset > offset) {
|
||||
item->mStartOffset--;
|
||||
}
|
||||
if (item->endNode == parent && item->endOffset > offset) {
|
||||
item->endOffset--;
|
||||
}
|
||||
|
||||
// check for range endpoints that are in aNode
|
||||
if (item->startNode == aNode) {
|
||||
item->startNode = parent;
|
||||
item->startOffset = offset;
|
||||
if (item->mStartContainer == aNode) {
|
||||
item->mStartContainer = parent;
|
||||
item->mStartOffset = offset;
|
||||
}
|
||||
if (item->endNode == aNode) {
|
||||
item->endNode = parent;
|
||||
|
@ -289,10 +289,10 @@ RangeUpdater::SelAdjDeleteNode(nsINode* aNode)
|
|||
|
||||
// check for range endpoints that are in descendants of aNode
|
||||
nsCOMPtr<nsINode> oldStart;
|
||||
if (EditorUtils::IsDescendantOf(item->startNode, aNode)) {
|
||||
oldStart = item->startNode; // save for efficiency hack below.
|
||||
item->startNode = parent;
|
||||
item->startOffset = offset;
|
||||
if (EditorUtils::IsDescendantOf(item->mStartContainer, aNode)) {
|
||||
oldStart = item->mStartContainer; // save for efficiency hack below.
|
||||
item->mStartContainer = parent;
|
||||
item->mStartOffset = offset;
|
||||
}
|
||||
|
||||
// avoid having to call IsDescendantOf() for common case of range startnode == range endnode.
|
||||
|
@ -331,11 +331,11 @@ RangeUpdater::SelAdjSplitNode(nsIContent& aOldRightNode,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == &aOldRightNode) {
|
||||
if (item->startOffset > aOffset) {
|
||||
item->startOffset -= aOffset;
|
||||
if (item->mStartContainer == &aOldRightNode) {
|
||||
if (item->mStartOffset > aOffset) {
|
||||
item->mStartOffset -= aOffset;
|
||||
} else {
|
||||
item->startNode = aNewLeftNode;
|
||||
item->mStartContainer = aNewLeftNode;
|
||||
}
|
||||
}
|
||||
if (item->endNode == &aOldRightNode) {
|
||||
|
@ -369,21 +369,21 @@ RangeUpdater::SelAdjJoinNodes(nsINode& aLeftNode,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == &aParent) {
|
||||
if (item->mStartContainer == &aParent) {
|
||||
// adjust start point in aParent
|
||||
if (item->startOffset > aOffset) {
|
||||
item->startOffset--;
|
||||
} else if (item->startOffset == aOffset) {
|
||||
if (item->mStartOffset > aOffset) {
|
||||
item->mStartOffset--;
|
||||
} else if (item->mStartOffset == aOffset) {
|
||||
// join keeps right hand node
|
||||
item->startNode = &aRightNode;
|
||||
item->startOffset = aOldLeftNodeLength;
|
||||
item->mStartContainer = &aRightNode;
|
||||
item->mStartOffset = aOldLeftNodeLength;
|
||||
}
|
||||
} else if (item->startNode == &aRightNode) {
|
||||
} else if (item->mStartContainer == &aRightNode) {
|
||||
// adjust start point in aRightNode
|
||||
item->startOffset += aOldLeftNodeLength;
|
||||
} else if (item->startNode == &aLeftNode) {
|
||||
item->mStartOffset += aOldLeftNodeLength;
|
||||
} else if (item->mStartContainer == &aLeftNode) {
|
||||
// adjust start point in aLeftNode
|
||||
item->startNode = &aRightNode;
|
||||
item->mStartContainer = &aRightNode;
|
||||
}
|
||||
|
||||
if (item->endNode == &aParent) {
|
||||
|
@ -427,8 +427,8 @@ RangeUpdater::SelAdjInsertText(Text& aTextNode,
|
|||
RangeItem* item = mArray[i];
|
||||
MOZ_ASSERT(item);
|
||||
|
||||
if (item->startNode == &aTextNode && item->startOffset > aOffset) {
|
||||
item->startOffset += len;
|
||||
if (item->mStartContainer == &aTextNode && item->mStartOffset > aOffset) {
|
||||
item->mStartOffset += len;
|
||||
}
|
||||
if (item->endNode == &aTextNode && item->endOffset > aOffset) {
|
||||
item->endOffset += len;
|
||||
|
@ -457,10 +457,10 @@ RangeUpdater::SelAdjDeleteText(nsIContent* aTextNode,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == aTextNode && item->startOffset > aOffset) {
|
||||
item->startOffset -= aLength;
|
||||
if (item->startOffset < 0) {
|
||||
item->startOffset = 0;
|
||||
if (item->mStartContainer == aTextNode && item->mStartOffset > aOffset) {
|
||||
item->mStartOffset -= aLength;
|
||||
if (item->mStartOffset < 0) {
|
||||
item->mStartOffset = 0;
|
||||
}
|
||||
}
|
||||
if (item->endNode == aTextNode && item->endOffset > aOffset) {
|
||||
|
@ -509,8 +509,8 @@ RangeUpdater::DidReplaceContainer(Element* aOriginalNode,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == aOriginalNode) {
|
||||
item->startNode = aNewNode;
|
||||
if (item->mStartContainer == aOriginalNode) {
|
||||
item->mStartContainer = aNewNode;
|
||||
}
|
||||
if (item->endNode == aOriginalNode) {
|
||||
item->endNode = aNewNode;
|
||||
|
@ -548,11 +548,12 @@ RangeUpdater::DidRemoveContainer(nsINode* aNode,
|
|||
RangeItem* item = mArray[i];
|
||||
NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
|
||||
|
||||
if (item->startNode == aNode) {
|
||||
item->startNode = aParent;
|
||||
item->startOffset += aOffset;
|
||||
} else if (item->startNode == aParent && item->startOffset > aOffset) {
|
||||
item->startOffset += (int32_t)aNodeOrigLen - 1;
|
||||
if (item->mStartContainer == aNode) {
|
||||
item->mStartContainer = aParent;
|
||||
item->mStartOffset += aOffset;
|
||||
} else if (item->mStartContainer == aParent &&
|
||||
item->mStartOffset > aOffset) {
|
||||
item->mStartOffset += (int32_t)aNodeOrigLen - 1;
|
||||
}
|
||||
|
||||
if (item->endNode == aNode) {
|
||||
|
@ -614,16 +615,18 @@ RangeUpdater::DidMoveNode(nsINode* aOldParent, int32_t aOldOffset,
|
|||
NS_ENSURE_TRUE_VOID(item);
|
||||
|
||||
// like a delete in aOldParent
|
||||
if (item->startNode == aOldParent && item->startOffset > aOldOffset) {
|
||||
item->startOffset--;
|
||||
if (item->mStartContainer == aOldParent &&
|
||||
item->mStartOffset > aOldOffset) {
|
||||
item->mStartOffset--;
|
||||
}
|
||||
if (item->endNode == aOldParent && item->endOffset > aOldOffset) {
|
||||
item->endOffset--;
|
||||
}
|
||||
|
||||
// and like an insert in aNewParent
|
||||
if (item->startNode == aNewParent && item->startOffset > aNewOffset) {
|
||||
item->startOffset++;
|
||||
if (item->mStartContainer == aNewParent &&
|
||||
item->mStartOffset > aNewOffset) {
|
||||
item->mStartOffset++;
|
||||
}
|
||||
if (item->endNode == aNewParent && item->endOffset > aNewOffset) {
|
||||
item->endOffset++;
|
||||
|
@ -645,7 +648,7 @@ RangeItem::~RangeItem()
|
|||
{
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(RangeItem, startNode, endNode)
|
||||
NS_IMPL_CYCLE_COLLECTION(RangeItem, mStartContainer, endNode)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(RangeItem, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(RangeItem, Release)
|
||||
|
||||
|
@ -653,8 +656,8 @@ void
|
|||
RangeItem::StoreRange(nsRange* aRange)
|
||||
{
|
||||
MOZ_ASSERT(aRange);
|
||||
startNode = aRange->GetStartContainer();
|
||||
startOffset = aRange->StartOffset();
|
||||
mStartContainer = aRange->GetStartContainer();
|
||||
mStartOffset = aRange->StartOffset();
|
||||
endNode = aRange->GetEndContainer();
|
||||
endOffset = aRange->EndOffset();
|
||||
}
|
||||
|
@ -662,8 +665,8 @@ RangeItem::StoreRange(nsRange* aRange)
|
|||
already_AddRefed<nsRange>
|
||||
RangeItem::GetRange()
|
||||
{
|
||||
RefPtr<nsRange> range = new nsRange(startNode);
|
||||
if (NS_FAILED(range->SetStartAndEnd(startNode, startOffset,
|
||||
RefPtr<nsRange> range = new nsRange(mStartContainer);
|
||||
if (NS_FAILED(range->SetStartAndEnd(mStartContainer, mStartOffset,
|
||||
endNode, endOffset))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ public:
|
|||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(RangeItem)
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(RangeItem)
|
||||
|
||||
nsCOMPtr<nsINode> startNode;
|
||||
int32_t startOffset;
|
||||
nsCOMPtr<nsINode> mStartContainer;
|
||||
int32_t mStartOffset;
|
||||
nsCOMPtr<nsINode> endNode;
|
||||
int32_t endOffset;
|
||||
};
|
||||
|
@ -191,9 +191,9 @@ public:
|
|||
, mOffset(aOffset)
|
||||
{
|
||||
mRangeItem = new RangeItem();
|
||||
mRangeItem->startNode = *mNode;
|
||||
mRangeItem->mStartContainer = *mNode;
|
||||
mRangeItem->endNode = *mNode;
|
||||
mRangeItem->startOffset = *mOffset;
|
||||
mRangeItem->mStartOffset = *mOffset;
|
||||
mRangeItem->endOffset = *mOffset;
|
||||
mRangeUpdater.RegisterRangeItem(mRangeItem);
|
||||
}
|
||||
|
@ -206,9 +206,9 @@ public:
|
|||
, mOffset(aOffset)
|
||||
{
|
||||
mRangeItem = new RangeItem();
|
||||
mRangeItem->startNode = do_QueryInterface(*mDOMNode);
|
||||
mRangeItem->mStartContainer = do_QueryInterface(*mDOMNode);
|
||||
mRangeItem->endNode = do_QueryInterface(*mDOMNode);
|
||||
mRangeItem->startOffset = *mOffset;
|
||||
mRangeItem->mStartOffset = *mOffset;
|
||||
mRangeItem->endOffset = *mOffset;
|
||||
mRangeUpdater.RegisterRangeItem(mRangeItem);
|
||||
}
|
||||
|
@ -217,11 +217,11 @@ public:
|
|||
{
|
||||
mRangeUpdater.DropRangeItem(mRangeItem);
|
||||
if (mNode) {
|
||||
*mNode = mRangeItem->startNode;
|
||||
*mNode = mRangeItem->mStartContainer;
|
||||
} else {
|
||||
*mDOMNode = GetAsDOMNode(mRangeItem->startNode);
|
||||
*mDOMNode = GetAsDOMNode(mRangeItem->mStartContainer);
|
||||
}
|
||||
*mOffset = mRangeItem->startOffset;
|
||||
*mOffset = mRangeItem->mStartOffset;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче