From af080de362c44960fd21362a9fb8c4be81855ec7 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Mon, 28 Apr 2014 18:40:28 +0300 Subject: [PATCH] Bug 1003808 part 4 - Clean up nsAutoTrackDOMPoint; r=ehsan --- editor/libeditor/base/nsSelectionState.h | 43 ++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/editor/libeditor/base/nsSelectionState.h b/editor/libeditor/base/nsSelectionState.h index bade710083f2..d93f5f9b9fd4 100644 --- a/editor/libeditor/base/nsSelectionState.h +++ b/editor/libeditor/base/nsSelectionState.h @@ -143,27 +143,50 @@ class MOZ_STACK_CLASS nsAutoTrackDOMPoint { private: nsRangeUpdater &mRU; - nsCOMPtr *mNode; - int32_t *mOffset; + // Allow tracking either nsIDOMNode or nsINode until nsIDOMNode is gone + nsCOMPtr* mNode; + nsCOMPtr* mDOMNode; + int32_t* mOffset; nsRefPtr mRangeItem; public: - nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater, nsCOMPtr *aNode, int32_t *aOffset) : - mRU(aRangeUpdater) - ,mNode(aNode) - ,mOffset(aOffset) + nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater, + nsCOMPtr* aNode, int32_t* aOffset) + : mRU(aRangeUpdater) + , mNode(aNode) + , mDOMNode(nullptr) + , mOffset(aOffset) { mRangeItem = new nsRangeStore(); - mRangeItem->startNode = do_QueryInterface(*mNode); - mRangeItem->endNode = do_QueryInterface(*mNode); + mRangeItem->startNode = *mNode; + mRangeItem->endNode = *mNode; mRangeItem->startOffset = *mOffset; mRangeItem->endOffset = *mOffset; mRU.RegisterRangeItem(mRangeItem); } - + + nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater, + nsCOMPtr* aNode, int32_t* aOffset) + : mRU(aRangeUpdater) + , mNode(nullptr) + , mDOMNode(aNode) + , mOffset(aOffset) + { + mRangeItem = new nsRangeStore(); + mRangeItem->startNode = do_QueryInterface(*mDOMNode); + mRangeItem->endNode = do_QueryInterface(*mDOMNode); + mRangeItem->startOffset = *mOffset; + mRangeItem->endOffset = *mOffset; + mRU.RegisterRangeItem(mRangeItem); + } + ~nsAutoTrackDOMPoint() { mRU.DropRangeItem(mRangeItem); - *mNode = GetAsDOMNode(mRangeItem->startNode); + if (mNode) { + *mNode = mRangeItem->startNode; + } else { + *mDOMNode = GetAsDOMNode(mRangeItem->startNode); + } *mOffset = mRangeItem->startOffset; } };