Bug 865537. Part 1: Add nsRange::SetEnableGravitationOnElementRemoval to suppress 'gravitation' behavior on node removal. r=smaug

--HG--
extra : rebase_source : 3823c3a0400c80b6f22021f22195f73febd5d85e
This commit is contained in:
Robert O'Callahan 2013-06-07 16:26:28 +12:00
parent 54857756c2
commit 8c99c9f5e0
2 changed files with 21 additions and 0 deletions

View File

@ -662,6 +662,11 @@ nsRange::ContentRemoved(nsIDocument* aDocument,
gravitateEnd = true;
}
if (!mEnableGravitationOnElementRemoval) {
// Do not gravitate.
return;
}
if (gravitateStart || gravitateEnd) {
DoSetRange(gravitateStart ? container : mStartParent.get(),
gravitateStart ? aIndexInContainer : mStartOffset,

View File

@ -48,6 +48,7 @@ public:
, mInSelection(false)
, mStartOffsetWasIncremented(false)
, mEndOffsetWasIncremented(false)
, mEnableGravitationOnElementRemoval(true)
#ifdef DEBUG
, mAssertNextInsertOrAppendIndex(-1)
, mAssertNextInsertOrAppendNode(nullptr)
@ -72,6 +73,20 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsRange, nsIDOMRange)
/**
* The DOM Range spec requires that when a node is removed from its parent,
* and the node's subtree contains the start or end point of a range, that
* start or end point is moved up to where the node was removed from its
* parent.
* For some internal uses of Ranges it's useful to disable that behavior,
* so that a range of children within a single parent is preserved even if
* that parent is removed from the document tree.
*/
void SetEnableGravitationOnElementRemoval(bool aEnable)
{
mEnableGravitationOnElementRemoval = aEnable;
}
// nsIDOMRange interface
NS_DECL_NSIDOMRANGE
@ -299,6 +314,7 @@ protected:
bool mInSelection;
bool mStartOffsetWasIncremented;
bool mEndOffsetWasIncremented;
bool mEnableGravitationOnElementRemoval;
#ifdef DEBUG
int32_t mAssertNextInsertOrAppendIndex;
nsINode* mAssertNextInsertOrAppendNode;