Bug 658143 - Part 1: Changes nsCOMPtr<nsFrameSelection> to nsRefPtr. r=roc
authorCraig Topper <craig.topper@gmail.com>
Wed, 18 May 2011 20:10:49 -0700
changeset 69739 af460fe4ec780823677add8cce3a8dfc0448d9ce
parent 69738 48588658ad9a0a28da92aa061a4025a97aba40dc
child 69740 d4dc048d429f94e60937ff773faa26bcd022f807
push id20092
push userdgottwald@mozilla.com
push dateFri, 20 May 2011 09:22:21 +0000
treeherdermozilla-central@0bbb1318a394 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs658143
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 658143 - Part 1: Changes nsCOMPtr<nsFrameSelection> to nsRefPtr. r=roc
accessible/src/html/nsHyperTextAccessible.cpp
content/base/src/nsGenericElement.cpp
content/events/src/nsContentEventHandler.cpp
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsTextEditorState.cpp
dom/base/nsFocusManager.cpp
dom/base/nsGlobalWindow.cpp
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/text/nsTextEditRules.cpp
editor/libeditor/text/nsTextEditRulesBidi.cpp
layout/base/nsCaret.cpp
layout/base/nsPresShell.cpp
layout/generic/nsFrame.cpp
layout/generic/nsObjectFrame.cpp
layout/svg/base/src/nsSVGGlyphFrame.cpp
layout/tables/nsTableCellFrame.cpp
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -911,17 +911,17 @@ nsresult nsHyperTextAccessible::GetTextH
       // otherwise screen readers will announce the wrong line as the user presses up or down arrow and land
       // at the end of a line.
       nsCOMPtr<nsISelection> domSel;
       nsresult rv = GetSelections(nsISelectionController::SELECTION_NORMAL,
                                   nsnull, getter_AddRefs(domSel));
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSel));
-      nsCOMPtr<nsFrameSelection> frameSelection;
+      nsRefPtr<nsFrameSelection> frameSelection;
       rv = privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (frameSelection->GetHint() == nsFrameSelection::HINTLEFT) {
         -- aOffset;  // We are at the start of a line
       }
     }
   }
@@ -1675,17 +1675,17 @@ PRInt32 nsHyperTextAccessible::GetCaretL
 {
   // Provide the line number for the caret, relative to the
   // currently focused node. Use a 1-based index
   nsCOMPtr<nsISelection> domSel;
   GetSelections(nsISelectionController::SELECTION_NORMAL, nsnull,
                 getter_AddRefs(domSel));
   nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(domSel));
   NS_ENSURE_TRUE(privateSelection, -1);
-  nsCOMPtr<nsFrameSelection> frameSelection;
+  nsRefPtr<nsFrameSelection> frameSelection;
   privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
   NS_ENSURE_TRUE(frameSelection, -1);
 
   nsCOMPtr<nsIDOMNode> caretNode;
   domSel->GetFocusNode(getter_AddRefs(caretNode));
   nsCOMPtr<nsIContent> caretContent = do_QueryInterface(caretNode);
   if (!caretContent || !nsCoreUtils::IsAncestorOf(GetNode(), caretContent))
     return -1;
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -385,17 +385,17 @@ nsINode::GetSelectionRootContent(nsIPres
                  GetRootForContentSubtree(static_cast<nsIContent*>(this));
       }
       // If the document isn't editable but this is editable, this is in
       // contenteditable.  Use the editing host element for selection root.
       return static_cast<nsIContent*>(this)->GetEditingHost();
     }
   }
 
-  nsCOMPtr<nsFrameSelection> fs = aPresShell->FrameSelection();
+  nsRefPtr<nsFrameSelection> fs = aPresShell->FrameSelection();
   nsIContent* content = fs->GetLimiter();
   if (!content) {
     content = fs->GetAncestorLimiter();
     if (!content) {
       nsIDocument* doc = aPresShell->GetDocument();
       NS_ENSURE_TRUE(doc, nsnull);
       content = doc->GetRootElement();
       if (!content)
--- a/content/events/src/nsContentEventHandler.cpp
+++ b/content/events/src/nsContentEventHandler.cpp
@@ -299,17 +299,17 @@ nsContentEventHandler::ExpandToClusterBo
   // boundaries. It's false, but no problem now, maybe.
   if (!aContent->IsNodeOfType(nsINode::eTEXT) ||
       *aXPOffset == 0 || *aXPOffset == aContent->TextLength())
     return NS_OK;
 
   NS_ASSERTION(*aXPOffset >= 0 && *aXPOffset <= aContent->TextLength(),
                "offset is out of range.");
 
-  nsCOMPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
+  nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
   PRInt32 offsetInFrame;
   nsFrameSelection::HINT hint =
     aForward ? nsFrameSelection::HINTLEFT : nsFrameSelection::HINTRIGHT;
   nsIFrame* frame = fs->GetFrameForNodeOffset(aContent, PRInt32(*aXPOffset),
                                               hint, &offsetInFrame);
   if (!frame) {
     // This content doesn't have any frames, we only can check surrogate pair...
     const nsTextFragment* text = aContent->GetText();
@@ -916,17 +916,17 @@ nsContentEventHandler::GetStartFrameAndO
   NS_ASSERTION(aRange && aFrame && aOffsetInFrame, "params are invalid");
 
   nsIContent* content = nsnull;
   nsINode* node = aRange->GetStartParent();
   if (node && node->IsNodeOfType(nsINode::eCONTENT))
     content = static_cast<nsIContent*>(node);
   NS_ASSERTION(content, "the start node doesn't have nsIContent!");
 
-  nsCOMPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
+  nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
   *aFrame = fs->GetFrameForNodeOffset(content, aRange->StartOffset(),
                                       fs->GetHint(), aOffsetInFrame);
   NS_ENSURE_TRUE((*aFrame), NS_ERROR_FAILURE);
   NS_ASSERTION((*aFrame)->GetType() == nsGkAtoms::textFrame,
                "The frame is not textframe");
   return NS_OK;
 }
 
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -1861,17 +1861,17 @@ nsEventStateManager::FireContextClick()
                          targetWidget,
                          nsMouseEvent::eReal);
       event.clickCount = 1;
       FillInEventFromGestureDown(&event);
         
       // stop selection tracking, we're in control now
       if (mCurrentTarget)
       {
-        nsCOMPtr<nsFrameSelection> frameSel =
+        nsRefPtr<nsFrameSelection> frameSel =
           mCurrentTarget->GetFrameSelection();
         
         if (frameSel && frameSel->GetMouseDownState()) {
           // note that this can cause selection changed events to fire if we're in
           // a text field, which will null out mCurrentTarget
           frameSel->SetMouseDownState(PR_FALSE);
         }
       }
@@ -1986,17 +1986,17 @@ nsEventStateManager::GenerateDragGesture
       StopTrackingDragGesture();
       return;
     }
 
     // Check if selection is tracking drag gestures, if so
     // don't interfere!
     if (mCurrentTarget)
     {
-      nsCOMPtr<nsFrameSelection> frameSel = mCurrentTarget->GetFrameSelection();
+      nsRefPtr<nsFrameSelection> frameSel = mCurrentTarget->GetFrameSelection();
       if (frameSel && frameSel->GetMouseDownState()) {
         StopTrackingDragGesture();
         return;
       }
     }
 
     // If non-native code is capturing the mouse don't start a drag.
     if (nsIPresShell::IsMouseCapturePreventingDrag()) {
@@ -3029,17 +3029,17 @@ nsEventStateManager::PostHandleEvent(nsP
         if (mCurrentTarget) {
           ret = CheckForAndDispatchClick(presContext, (nsMouseEvent*)aEvent,
                                          aStatus);
         }
       }
 
       nsIPresShell *shell = presContext->GetPresShell();
       if (shell) {
-        nsCOMPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
+        nsRefPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
         frameSelection->SetMouseDownState(PR_FALSE);
       }
     }
     break;
   case NS_MOUSE_SCROLL:
   case NS_MOUSE_PIXEL_SCROLL:
     {
       nsMouseScrollEvent *msEvent = static_cast<nsMouseScrollEvent*>(aEvent);
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -213,17 +213,17 @@ public:
   NS_IMETHOD CompleteMove(PRBool aForward, PRBool aExtend);
   NS_IMETHOD ScrollPage(PRBool aForward);
   NS_IMETHOD ScrollLine(PRBool aForward);
   NS_IMETHOD ScrollHorizontal(PRBool aLeft);
   NS_IMETHOD SelectAll(void);
   NS_IMETHOD CheckVisibility(nsIDOMNode *node, PRInt16 startOffset, PRInt16 EndOffset, PRBool *_retval);
 
 private:
-  nsCOMPtr<nsFrameSelection> mFrameSelection;
+  nsRefPtr<nsFrameSelection> mFrameSelection;
   nsCOMPtr<nsIContent>       mLimiter;
   nsIScrollableFrame        *mScrollFrame;
   nsWeakPtr mPresShellWeak;
 };
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTextInputSelectionImpl)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTextInputSelectionImpl)
 NS_INTERFACE_TABLE_HEAD(nsTextInputSelectionImpl)
@@ -1086,17 +1086,17 @@ nsTextEditorState::BindToFrame(nsTextCon
 
   nsIContent *rootNode = GetRootNode();
 
   nsIPresShell *shell = mBoundFrame->PresContext()->GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_FAILURE);
 
   // Create selection
   nsresult rv;
-  nsCOMPtr<nsFrameSelection> frameSel;
+  nsRefPtr<nsFrameSelection> frameSel;
   frameSel = do_CreateInstance(kFrameSelectionCID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Create a SelectionController
   mSelCon = new nsTextInputSelectionImpl(frameSel, shell, rootNode);
   NS_ENSURE_TRUE(mSelCon, NS_ERROR_OUT_OF_MEMORY);
   mTextListener = new nsTextInputListener(mTextCtrlElement);
   NS_ENSURE_TRUE(mTextListener, NS_ERROR_OUT_OF_MEMORY);
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -723,17 +723,17 @@ nsFocusManager::WindowRaised(nsIDOMWindo
 
   nsCOMPtr<nsIDocShell> currentDocShell = currentWindow->GetDocShell();
 
   nsCOMPtr<nsIPresShell> presShell;
   currentDocShell->GetPresShell(getter_AddRefs(presShell));
   if (presShell) {
     // disable selection mousedown state on activation
     // XXXndeakin P3 not sure if this is necessary, but it doesn't hurt
-    nsCOMPtr<nsFrameSelection> frameSelection = presShell->FrameSelection();
+    nsRefPtr<nsFrameSelection> frameSelection = presShell->FrameSelection();
     frameSelection->SetMouseDownState(PR_FALSE);
   }
 
   Focus(currentWindow, currentFocus, 0, PR_TRUE, PR_FALSE, PR_TRUE, PR_TRUE);
 
   return NS_OK;
 }
 
@@ -2007,17 +2007,17 @@ nsFocusManager::UpdateCaret(PRBool aMove
 }
 
 void
 nsFocusManager::MoveCaretToFocus(nsIPresShell* aPresShell, nsIContent* aContent)
 {
   // domDoc is a document interface we can create a range with
   nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aPresShell->GetDocument());
   if (domDoc) {
-    nsCOMPtr<nsFrameSelection> frameSelection = aPresShell->FrameSelection();
+    nsRefPtr<nsFrameSelection> frameSelection = aPresShell->FrameSelection();
     nsCOMPtr<nsISelection> domSelection = frameSelection->
       GetSelection(nsISelectionController::SELECTION_NORMAL);
     if (domSelection) {
       nsCOMPtr<nsIDOMNode> currentFocusNode(do_QueryInterface(aContent));
       // First clear the selection. This way, if there is no currently focused
       // content, the selection will just be cleared.
       domSelection->RemoveAllRanges();
       if (currentFocusNode) {
@@ -2057,26 +2057,26 @@ nsFocusManager::SetCaretVisible(nsIPresS
   if (!caret)
     return NS_OK;
 
   PRBool caretVisible = PR_FALSE;
   caret->GetCaretVisible(&caretVisible);
   if (!aVisible && !caretVisible)
     return NS_OK;
 
-  nsCOMPtr<nsFrameSelection> frameSelection;
+  nsRefPtr<nsFrameSelection> frameSelection;
   if (aContent) {
     NS_ASSERTION(aContent->GetDocument() == aPresShell->GetDocument(),
                  "Wrong document?");
     nsIFrame *focusFrame = aContent->GetPrimaryFrame();
     if (focusFrame)
       frameSelection = focusFrame->GetFrameSelection();
   }
 
-  nsCOMPtr<nsFrameSelection> docFrameSelection = aPresShell->FrameSelection();
+  nsRefPtr<nsFrameSelection> docFrameSelection = aPresShell->FrameSelection();
 
   if (docFrameSelection && caret &&
      (frameSelection == docFrameSelection || !aContent)) {
     nsISelection* domSelection = docFrameSelection->
       GetSelection(nsISelectionController::SELECTION_NORMAL);
     if (domSelection) {
       // First, hide the caret to prevent attempting to show it in SetCaretDOMSelection
       caret->SetCaretVisible(PR_FALSE);
@@ -2107,18 +2107,17 @@ nsFocusManager::GetSelectionLocation(nsI
                                      nsIContent **aEndContent)
 {
   *aStartContent = *aEndContent = nsnull;
   nsresult rv = NS_ERROR_FAILURE;
 
   nsPresContext* presContext = aPresShell->GetPresContext();
   NS_ASSERTION(presContext, "mPresContent is null!!");
 
-  nsCOMPtr<nsFrameSelection> frameSelection;
-  frameSelection = aPresShell->FrameSelection();
+  nsRefPtr<nsFrameSelection> frameSelection = aPresShell->FrameSelection();
 
   nsCOMPtr<nsISelection> domSelection;
   if (frameSelection) {
     domSelection = frameSelection->
       GetSelection(nsISelectionController::SELECTION_NORMAL);
   }
 
   nsCOMPtr<nsIDOMNode> startNode, endNode;
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -6322,17 +6322,17 @@ nsGlobalWindow::EnterModalState()
     if (activeShell && (
         nsContentUtils::ContentIsCrossDocDescendantOf(activeShell->GetDocument(), mDoc) ||
         nsContentUtils::ContentIsCrossDocDescendantOf(mDoc, activeShell->GetDocument()))) {
       nsEventStateManager::ClearGlobalActiveContent(activeESM);
 
       activeShell->SetCapturingContent(nsnull, 0);
 
       if (activeShell) {
-        nsCOMPtr<nsFrameSelection> frameSelection = activeShell->FrameSelection();
+        nsRefPtr<nsFrameSelection> frameSelection = activeShell->FrameSelection();
         frameSelection->SetMouseDownState(PR_FALSE);
       }
     }
   }
 
   if (topWin->mModalStateDepth == 0) {
     NS_ASSERTION(!mSuspendedDoc, "Shouldn't have mSuspendedDoc here!");
 
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -407,17 +407,17 @@ nsHTMLEditRules::AfterEdit(PRInt32 actio
      */
     if (action == nsEditor::kOpInsertText
         || action == nsEditor::kOpInsertIMEText) {
 
       nsCOMPtr<nsISelection> selection;
       nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
       NS_ENSURE_SUCCESS(res, res);
       nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(selection));
-      nsCOMPtr<nsFrameSelection> frameSelection;
+      nsRefPtr<nsFrameSelection> frameSelection;
       privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
       if (frameSelection) {
         frameSelection->UndefineCaretBidiLevel();
       }
     }
 
     // Reset the contenteditable count to its previous value
     if (mRestoreContentEditableCount) {
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -239,17 +239,17 @@ nsTextEditRules::AfterEdit(PRInt32 actio
      * This is difficult, because we cannot know what the level is until after the Bidi algorithm
      * is applied to the whole paragraph.
      *
      * So we set the cursor Bidi level to UNDEFINED here, and the caret code will set it correctly later
      */
     if (action == nsEditor::kOpInsertText
         || action == nsEditor::kOpInsertIMEText) {
       nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(selection));
-      nsCOMPtr<nsFrameSelection> frameSelection;
+      nsRefPtr<nsFrameSelection> frameSelection;
       privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));      
       if (frameSelection) {
         frameSelection->UndefineCaretBidiLevel();
       }
     }
   }
   return res;
 }
--- a/editor/libeditor/text/nsTextEditRulesBidi.cpp
+++ b/editor/libeditor/text/nsTextEditRulesBidi.cpp
@@ -71,17 +71,17 @@ nsTextEditRules::CheckBidiLevelForDeleti
   NS_ENSURE_TRUE(content, NS_ERROR_NULL_POINTER);
 
   PRUint8 levelBefore;
   PRUint8 levelAfter;
 
   nsCOMPtr<nsISelectionPrivate> privateSelection(do_QueryInterface(aSelection));
   NS_ENSURE_TRUE(privateSelection, NS_ERROR_NULL_POINTER);
   
-  nsCOMPtr<nsFrameSelection> frameSelection;
+  nsRefPtr<nsFrameSelection> frameSelection;
   privateSelection->GetFrameSelection(getter_AddRefs(frameSelection));
   NS_ENSURE_TRUE(frameSelection, NS_ERROR_NULL_POINTER);
   
   nsPrevNextBidiLevels levels = frameSelection->
     GetPrevNextBidiLevels(content, aSelOffset, PR_TRUE);
     
   levelBefore = levels.mLevelBefore;
   levelAfter = levels.mLevelAfter;
--- a/layout/base/nsCaret.cpp
+++ b/layout/base/nsCaret.cpp
@@ -403,17 +403,17 @@ nsIFrame* nsCaret::GetGeometry(nsISelect
   rv = aSelection->GetFocusOffset(&focusOffset);
   if (NS_FAILED(rv))
     return nsnull;
     
   nsCOMPtr<nsIContent> contentNode = do_QueryInterface(focusNode);
   if (!contentNode)
     return nsnull;
 
-  nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
+  nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
   if (!frameSelection)
     return nsnull;
   PRUint8 bidiLevel = frameSelection->GetCaretBidiLevel();
   nsIFrame* frame;
   PRInt32 frameOffset;
   rv = GetCaretFrameForNodeOffset(contentNode, focusOffset,
                                   frameSelection->GetHint(), bidiLevel,
                                   &frame, &frameOffset);
@@ -456,17 +456,17 @@ void nsCaret::SetVisibilityDuringSelecti
   mShowDuringSelection = aVisibility;
 }
 
 nsresult nsCaret::DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset)
 {
   NS_ENSURE_ARG(aNode);
 
   PRUint8 bidiLevel;
-  nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
+  nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
   if (!frameSelection)
     return NS_ERROR_FAILURE;
   bidiLevel = frameSelection->GetCaretBidiLevel();
 
   // DrawAtPosition is used by consumers who want us to stay drawn where they
   // tell us. Setting mBlinkRate to 0 tells us to not set a timer to erase
   // ourselves, our consumer will take care of that.
   mBlinkRate = 0;
@@ -697,17 +697,17 @@ nsCaret::DrawAtPositionWithHint(nsIDOMNo
     // save stuff so we can figure out what frame we're in later.
     mLastContent = contentNode;
     mLastContentOffset = aOffset;
     mLastHint = aFrameHint;
     mLastBidiLevel = aBidiLevel;
 
     // If there has been a reflow, set the caret Bidi level to the level of the current frame
     if (aBidiLevel & BIDI_LEVEL_UNDEFINED) {
-      nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
+      nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
       if (!frameSelection)
         return PR_FALSE;
       frameSelection->SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame));
     }
 
     // Only update the caret's rect when we're not currently drawn.
     if (!UpdateCaretRects(theFrame, theFrameOffset))
       return PR_FALSE;
@@ -732,17 +732,17 @@ nsCaret::GetCaretFrameForNodeOffset(nsIC
   nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
   if (!presShell)
     return NS_ERROR_FAILURE;
 
   if (!aContentNode || !aContentNode->IsInDoc() ||
       presShell->GetDocument() != aContentNode->GetCurrentDoc())
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
+  nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
   if (!frameSelection)
     return NS_ERROR_FAILURE;
 
   nsIFrame* theFrame = nsnull;
   PRInt32   theFrameOffset = 0;
 
   theFrame = frameSelection->GetFrameForNodeOffset(aContentNode, aOffset,
                                                    aFrameHint, &theFrameOffset);
@@ -1039,17 +1039,17 @@ void nsCaret::DrawCaret(PRBool aInvalida
     // get the node and offset, which is where we want the caret to draw
     domSelection->GetFocusNode(getter_AddRefs(node));
     if (!node)
       return;
     
     if (NS_FAILED(domSelection->GetFocusOffset(&offset)))
       return;
 
-    nsCOMPtr<nsFrameSelection> frameSelection = GetFrameSelection();
+    nsRefPtr<nsFrameSelection> frameSelection = GetFrameSelection();
     if (!frameSelection)
       return;
 
     bidiLevel = frameSelection->GetCaretBidiLevel();
     mPendingDraw = PR_FALSE;
   }
   else
   {
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1120,17 +1120,17 @@ protected:
   // Hide a view if it is a popup
   void HideViewIfPopup(nsIView* aView);
 
   // Utility method to restore the root scrollframe state
   void RestoreRootScrollPosition();
 
   void MaybeReleaseCapturingContent()
   {
-    nsCOMPtr<nsFrameSelection> frameSelection = FrameSelection();
+    nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
     if (frameSelection) {
       frameSelection->SetMouseDownState(PR_FALSE);
     }
     if (gCaptureInfo.mContent &&
         gCaptureInfo.mContent->GetOwnerDoc() == mDocument) {
       SetCapturingContent(nsnull, 0);
     }
   }
@@ -5674,17 +5674,17 @@ PresShell::PaintRangePaintInfo(nsTArray<
     rc->Scale(scale, scale);
 
   // translate so that points are relative to the surface area
   rc->Translate(-aArea.TopLeft());
 
   // temporarily hide the selection so that text is drawn normally. If a
   // selection is being rendered, use that, otherwise use the presshell's
   // selection.
-  nsCOMPtr<nsFrameSelection> frameSelection;
+  nsRefPtr<nsFrameSelection> frameSelection;
   if (aSelection) {
     nsCOMPtr<nsISelectionPrivate> selpriv = do_QueryInterface(aSelection);
     selpriv->GetFrameSelection(getter_AddRefs(frameSelection));
   }
   else {
     frameSelection = FrameSelection();
   }
   PRInt16 oldDisplaySelection = frameSelection->GetDisplaySelection();
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -2212,17 +2212,17 @@ nsFrame::HandlePress(nsPresContext* aPre
 #ifdef XP_MACOSX
   if (me->isControl)
     return NS_OK;//short ciruit. hard coded for mac due to time restraints.
   PRBool control = me->isMeta;
 #else
   PRBool control = me->isControl;
 #endif
 
-  nsCOMPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection);
+  nsRefPtr<nsFrameSelection> fc = const_cast<nsFrameSelection*>(frameselection);
   if (me->clickCount >1 )
   {
     // These methods aren't const but can't actually delete anything,
     // so no need for nsWeakFrame.
     fc->SetMouseDownState(PR_TRUE);
     fc->SetMouseDoubleDown(PR_TRUE);
     return HandleMultiplePress(aPresContext, aEvent, aEventStatus, control);
   }
@@ -2482,17 +2482,17 @@ NS_IMETHODIMP nsFrame::HandleDrag(nsPres
   // other stuff might not like it.
   if (!selectable)
     return NS_OK;
   if (DisplaySelection(aPresContext) == nsISelectionController::SELECTION_OFF) {
     return NS_OK;
   }
   nsIPresShell *presShell = aPresContext->PresShell();
 
-  nsCOMPtr<nsFrameSelection> frameselection = GetFrameSelection();
+  nsRefPtr<nsFrameSelection> frameselection = GetFrameSelection();
   PRBool mouseDown = frameselection->GetMouseDownState();
   if (!mouseDown)
     return NS_OK;
 
   frameselection->StopAutoScrollTimer();
 
   // Check if we are dragging in a table cell
   nsCOMPtr<nsIContent> parentContent;
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -5306,17 +5306,17 @@ nsEventStatus nsPluginInstanceOwner::Pro
           event = &synthCarbonEvent;
         }
 #endif
         break;
       case NS_MOUSE_MOVE:
       {
         // Ignore mouse-moved events that happen as part of a dragging
         // operation that started over another frame.  See bug 525078.
-        nsCOMPtr<nsFrameSelection> frameselection = mObjectFrame->GetFrameSelection();
+        nsRefPtr<nsFrameSelection> frameselection = mObjectFrame->GetFrameSelection();
         if (!frameselection->GetMouseDownState() ||
             (nsIPresShell::GetCapturingContent() == mObjectFrame->GetContent())) {
 #ifndef NP_NO_CARBON
           if (eventModel == NPEventModelCarbon) {
             synthCarbonEvent.what = osEvt;
             event = &synthCarbonEvent;
           } else
 #endif
--- a/layout/svg/base/src/nsSVGGlyphFrame.cpp
+++ b/layout/svg/base/src/nsSVGGlyphFrame.cpp
@@ -963,30 +963,17 @@ nsSVGGlyphFrame::GetHighlight(PRUint32 *
   // The selection ranges are relative to the uncompressed text in
   // the content element. We'll need the text fragment:
   const nsTextFragment *fragment = mContent->GetText();
   NS_ASSERTION(fragment, "no text");
   
   // get the selection details 
   SelectionDetails *details = nsnull;
   {
-    nsCOMPtr<nsFrameSelection> frameSelection;
-    {
-      nsCOMPtr<nsISelectionController> controller;
-      GetSelectionController(presContext, getter_AddRefs(controller));
-      
-      if (!controller) {
-        NS_ERROR("no selection controller");
-        return NS_ERROR_FAILURE;
-      }
-      frameSelection = do_QueryInterface(controller);
-    }
-    if (!frameSelection) {
-      frameSelection = presContext->PresShell()->FrameSelection();
-    }
+    nsRefPtr<nsFrameSelection> frameSelection = presContext->PresShell()->FrameSelection();
     if (!frameSelection) {
       NS_ERROR("no frameselection interface");
       return NS_ERROR_FAILURE;
     }
 
     details = frameSelection->LookUpSelection(
       mContent, 0, fragment->GetLength(), PR_FALSE
       );
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -314,17 +314,17 @@ nsTableCellFrame::DecorateForSelection(n
                                        nsPoint aPt)
 {
   NS_ASSERTION(GetStateBits() & NS_FRAME_SELECTED_CONTENT,
                "Should only be called for selected cells");
   PRInt16 displaySelection;
   nsPresContext* presContext = PresContext();
   displaySelection = DisplaySelection(presContext);
   if (displaySelection) {
-    nsCOMPtr<nsFrameSelection> frameSelection =
+    nsRefPtr<nsFrameSelection> frameSelection =
       presContext->PresShell()->FrameSelection();
 
     if (frameSelection->GetTableCellSelection()) {
       nscolor       bordercolor;
       if (displaySelection == nsISelectionController::SELECTION_DISABLED) {
         bordercolor = NS_RGB(176,176,176);// disabled color
       }
       else {