nsRangeStore-allowonstack
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 159 969d8d4050b8b7ebfb082c860b4a16df41348d52
permissions -rw-r--r--
State as of now

Allow nsRangeStore to be used on the stack. This is ugly because of write barriers, which I'm ignoring for the moment. TODO: figure these out!

diff --git a/editor/libeditor/base/nsSelectionState.cpp b/editor/libeditor/base/nsSelectionState.cpp
--- a/editor/libeditor/base/nsSelectionState.cpp
+++ b/editor/libeditor/base/nsSelectionState.cpp
@@ -273,9 +273,9 @@ nsRangeUpdater::SelAdjCreateNode(nsIDOMN
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if ((item->startNode.get() == aParent) && (item->startOffset > aPosition))
+    if ((item->startNode == aParent) && (item->startOffset > aPosition))
       item->startOffset++;
-    if ((item->endNode.get() == aParent) && (item->endOffset > aPosition))
+    if ((item->endNode == aParent) && (item->endOffset > aPosition))
       item->endOffset++;
   }
   return NS_OK;
@@ -309,9 +309,9 @@ nsRangeUpdater::SelAdjDeleteNode(nsIDOMN
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if ((item->startNode.get() == parent) && (item->startOffset > offset))
+    if ((item->startNode == parent) && (item->startOffset > offset))
       item->startOffset--;
-    if ((item->endNode.get() == parent) && (item->endOffset > offset))
+    if ((item->endNode == parent) && (item->endOffset > offset))
       item->endOffset--;
       
     // check for range endpoints that are in aNode
@@ -371,7 +371,7 @@ nsRangeUpdater::SelAdjSplitNode(nsIDOMNo
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if (item->startNode.get() == aOldRightNode)
+    if (item->startNode == aOldRightNode)
     {
       if (item->startOffset > aOffset)
       {
@@ -382,7 +382,7 @@ nsRangeUpdater::SelAdjSplitNode(nsIDOMNo
         item->startNode = aNewLeftNode;
       }
     }
-    if (item->endNode.get() == aOldRightNode)
+    if (item->endNode == aOldRightNode)
     {
       if (item->endOffset > aOffset)
       {
@@ -417,7 +417,7 @@ nsRangeUpdater::SelAdjJoinNodes(nsIDOMNo
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if (item->startNode.get() == aParent)
+    if (item->startNode == aParent)
     {
       // adjust start point in aParent
       if (item->startOffset > aOffset)
@@ -431,18 +431,18 @@ nsRangeUpdater::SelAdjJoinNodes(nsIDOMNo
         item->startOffset = aOldLeftNodeLength;
       }
     }
-    else if (item->startNode.get() == aRightNode)
+    else if (item->startNode == aRightNode)
     {
       // adjust start point in aRightNode
       item->startOffset += aOldLeftNodeLength;
     }
-    else if (item->startNode.get() == aLeftNode)
+    else if (item->startNode == aLeftNode)
     {
       // adjust start point in aLeftNode
       item->startNode = aRightNode;
     }
 
-    if (item->endNode.get() == aParent)
+    if (item->endNode == aParent)
     {
       // adjust end point in aParent
       if (item->endOffset > aOffset)
@@ -456,12 +456,12 @@ nsRangeUpdater::SelAdjJoinNodes(nsIDOMNo
         item->endOffset = aOldLeftNodeLength;
       }
     }
-    else if (item->endNode.get() == aRightNode)
+    else if (item->endNode == aRightNode)
     {
       // adjust end point in aRightNode
        item->endOffset += aOldLeftNodeLength;
     }
-    else if (item->endNode.get() == aLeftNode)
+    else if (item->endNode == aLeftNode)
     {
       // adjust end point in aLeftNode
       item->endNode = aRightNode;
@@ -489,9 +489,9 @@ nsRangeUpdater::SelAdjInsertText(nsIDOMC
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if ((item->startNode.get() == node) && (item->startOffset > aOffset))
+    if ((item->startNode == node) && (item->startOffset > aOffset))
       item->startOffset += len;
-    if ((item->endNode.get() == node) && (item->endOffset > aOffset))
+    if ((item->endNode == node) && (item->endOffset > aOffset))
       item->endOffset += len;
   }
   return NS_OK;
@@ -514,12 +514,12 @@ nsRangeUpdater::SelAdjDeleteText(nsIDOMC
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if ((item->startNode.get() == node) && (item->startOffset > aOffset))
+    if ((item->startNode == node) && (item->startOffset > aOffset))
     {
       item->startOffset -= aLength;
       if (item->startOffset < 0) item->startOffset = 0;
     }
-    if ((item->endNode.get() == node) && (item->endOffset > aOffset))
+    if ((item->endNode == node) && (item->endOffset > aOffset))
     {
       item->endOffset -= aLength;
       if (item->endOffset < 0) item->endOffset = 0;
@@ -555,9 +555,9 @@ nsRangeUpdater::DidReplaceContainer(nsID
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if (item->startNode.get() == aOriginalNode)
+    if (item->startNode == aOriginalNode)
       item->startNode = aNewNode;
-    if (item->endNode.get() == aOriginalNode)
+    if (item->endNode == aOriginalNode)
       item->endNode = aNewNode;
   }
   return NS_OK;
@@ -590,20 +590,20 @@ nsRangeUpdater::DidRemoveContainer(nsIDO
     item = (nsRangeStore*)mArray.ElementAt(i);
     if (!item) return NS_ERROR_NULL_POINTER;
     
-    if (item->startNode.get() == aNode)
+    if (item->startNode == aNode)
     {
       item->startNode = aParent;
       item->startOffset += aOffset;
     }
-    else if ((item->startNode.get() == aParent) && (item->startOffset > aOffset))
+    else if ((item->startNode == aParent) && (item->startOffset > aOffset))
       item->startOffset += (PRInt32)aNodeOrigLen-1;
       
-    if (item->endNode.get() == aNode)
+    if (item->endNode == aNode)
     {
       item->endNode = aParent;
       item->endOffset += aOffset;
     }
-    else if ((item->endNode.get() == aParent) && (item->endOffset > aOffset))
+    else if ((item->endNode == aParent) && (item->endOffset > aOffset))
       item->endOffset += (PRInt32)aNodeOrigLen-1;
   }
   return NS_OK;
@@ -655,15 +655,15 @@ nsRangeUpdater::DidMoveNode(nsIDOMNode *
     if (!item) return NS_ERROR_NULL_POINTER;
     
     // like a delete in aOldParent
-    if ((item->startNode.get() == aOldParent) && (item->startOffset > aOldOffset))
+    if ((item->startNode == aOldParent) && (item->startOffset > aOldOffset))
       item->startOffset--;
-    if ((item->endNode.get() == aOldParent) && (item->endOffset > aOldOffset))
+    if ((item->endNode == aOldParent) && (item->endOffset > aOldOffset))
       item->endOffset--;
       
     // and like an insert in aNewParent
-    if ((item->startNode.get() == aNewParent) && (item->startOffset > aNewOffset))
+    if ((item->startNode == aNewParent) && (item->startOffset > aNewOffset))
       item->startOffset++;
-    if ((item->endNode.get() == aNewParent) && (item->endOffset > aNewOffset))
+    if ((item->endNode == aNewParent) && (item->endOffset > aNewOffset))
       item->endOffset++;
   }
   return NS_OK;
@@ -689,8 +689,8 @@ nsresult nsRangeStore::StoreRange(nsIDOM
 nsresult nsRangeStore::StoreRange(nsIDOMRange *aRange)
 {
   if (!aRange) return NS_ERROR_NULL_POINTER;
-  aRange->GetStartContainer(getter_AddRefs(startNode));
-  aRange->GetEndContainer(getter_AddRefs(endNode));
+  aRange->GetStartContainer(&startNode);
+  aRange->GetEndContainer(&endNode);
   aRange->GetStartOffset(&startOffset);
   aRange->GetEndOffset(&endOffset);
   return NS_OK;
diff --git a/editor/libeditor/base/nsSelectionState.h b/editor/libeditor/base/nsSelectionState.h
--- a/editor/libeditor/base/nsSelectionState.h
+++ b/editor/libeditor/base/nsSelectionState.h
@@ -60,9 +60,10 @@ struct nsRangeStore
   nsresult StoreRange(nsIDOMRange *aRange);
   nsresult GetRange(nsCOMPtr<nsIDOMRange> *outRange);
         
-  nsCOMPtr<nsIDOMNode> startNode;
+  // XXXwrite barriers
+  nsIDOMNode* startNode;
   PRInt32              startOffset;
-  nsCOMPtr<nsIDOMNode> endNode;
+  nsIDOMNode* endNode;
   PRInt32              endOffset;
   // DEBUG:   static PRInt32 n;
 };