Bug 750053 - Part b: Stop using nsISelection::GetIsCollapsed in editor/libeditor; r=ehsan
authorMs2ger <ms2ger@gmail.com>
Fri, 18 May 2012 10:29:39 +0200
changeset 94690 137ec8d18fe8dbb7824670e7f9555c0af3388519
parent 94689 ba0cffcf1f6ee293ae88d9479a0f30fa0470d6ea
child 94691 cc1d6d86db46ac3fa16a402b5ef6ea796ac1025e
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersehsan
bugs750053
milestone15.0a1
Bug 750053 - Part b: Stop using nsISelection::GetIsCollapsed in editor/libeditor; r=ehsan
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditorCommands.cpp
editor/libeditor/base/nsEditorEventListener.cpp
editor/libeditor/html/TypeInState.cpp
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditorEventListener.cpp
editor/libeditor/html/nsHTMLEditorStyle.cpp
editor/libeditor/text/nsPlaintextDataTransfer.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -4449,42 +4449,34 @@ NS_IMETHODIMP
 nsEditor::DeleteSelectionAndPrepareToCreateNode(nsCOMPtr<nsIDOMNode> &parentSelectedNode, PRInt32& offsetOfNewNode)
 {
   nsresult result=NS_ERROR_NOT_INITIALIZED;
   nsCOMPtr<nsISelection> selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
-  bool collapsed;
-  result = selection->GetIsCollapsed(&collapsed);
-  if (NS_SUCCEEDED(result) && !collapsed) 
-  {
+  if (!selection->Collapsed()) {
     result = DeleteSelection(nsIEditor::eNone);
     if (NS_FAILED(result)) {
       return result;
     }
     // get the new selection
     result = GetSelection(getter_AddRefs(selection));
     if (NS_FAILED(result)) {
       return result;
     }
 
     nsCOMPtr<nsIDOMNode> selectedNode;
     selection->GetAnchorNode(getter_AddRefs(selectedNode));
     // no selection is ok.
     // if there is a selection, it must be collapsed
-    if (selectedNode)
-    {
-      bool testCollapsed = false;
-      selection->GetIsCollapsed(&testCollapsed);
-      if (!testCollapsed) {
-        result = selection->CollapseToEnd();
-        NS_ENSURE_SUCCESS(result, result);
-      }
+    if (selectedNode && !selection->Collapsed()) {
+      result = selection->CollapseToEnd();
+      NS_ENSURE_SUCCESS(result, result);
     }
   }
   // split the selected node
   PRInt32 offsetOfSelectedNode;
   result = selection->GetAnchorNode(getter_AddRefs(parentSelectedNode));
   if (NS_SUCCEEDED(result) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetOfSelectedNode)) && parentSelectedNode)
   {
     nsCOMPtr<nsIDOMNode> selectedNode;
@@ -4737,19 +4729,17 @@ nsEditor::CreateTxnForDeleteSelection(ns
   GetSelectionController(getter_AddRefs(selCon));
   NS_ENSURE_TRUE(selCon, NS_ERROR_NOT_INITIALIZED);
   nsCOMPtr<nsISelection> selection;
   nsresult result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
                                          getter_AddRefs(selection));
   if ((NS_SUCCEEDED(result)) && selection)
   {
     // Check whether the selection is collapsed and we should do nothing:
-    bool isCollapsed;
-    result = (selection->GetIsCollapsed(&isCollapsed));
-    if (NS_SUCCEEDED(result) && isCollapsed && aAction == eNone)
+    if (selection->Collapsed() && aAction == eNone)
       return NS_OK;
 
     // allocate the out-param transaction
     aggTxn = new EditAggregateTxn();
 
     nsCOMPtr<nsISelectionPrivate>selPrivate(do_QueryInterface(selection));
     nsCOMPtr<nsIEnumerator> enumerator;
     result = selPrivate->GetEnumerator(getter_AddRefs(enumerator));
@@ -4757,16 +4747,17 @@ nsEditor::CreateTxnForDeleteSelection(ns
     {
       for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
       {
         nsCOMPtr<nsISupports> currentItem;
         result = enumerator->CurrentItem(getter_AddRefs(currentItem));
         if ((NS_SUCCEEDED(result)) && (currentItem))
         {
           nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
+          bool isCollapsed;
           range->GetCollapsed(&isCollapsed);
           if (!isCollapsed)
           {
             nsRefPtr<DeleteRangeTxn> txn = new DeleteRangeTxn();
             if (txn)
             {
               txn->Init(this, range, &mRangeUpdater);
               aggTxn->AppendChild(txn);
--- a/editor/libeditor/base/nsEditorCommands.cpp
+++ b/editor/libeditor/base/nsEditorCommands.cpp
@@ -276,22 +276,18 @@ NS_IMETHODIMP
 nsCutOrDeleteCommand::DoCommand(const char *aCommandName,
                                 nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (editor)
   {
     nsCOMPtr<nsISelection> selection;
     nsresult rv = editor->GetSelection(getter_AddRefs(selection));
-    if (NS_SUCCEEDED(rv) && selection)
-    {
-      bool isCollapsed;
-      rv = selection->GetIsCollapsed(&isCollapsed);
-      if (NS_SUCCEEDED(rv) && isCollapsed)
-        return editor->DeleteSelection(nsIEditor::eNext);
+    if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
+      return editor->DeleteSelection(nsIEditor::eNext);
     }
     return editor->Cut();
   }
     
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP 
@@ -374,22 +370,18 @@ NS_IMETHODIMP
 nsCopyOrDeleteCommand::DoCommand(const char *aCommandName,
                                  nsISupports *aCommandRefCon)
 {
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
   if (editor)
   {
     nsCOMPtr<nsISelection> selection;
     nsresult rv = editor->GetSelection(getter_AddRefs(selection));
-    if (NS_SUCCEEDED(rv) && selection)
-    {
-      bool isCollapsed;
-      rv = selection->GetIsCollapsed(&isCollapsed);
-      if (NS_SUCCEEDED(rv) && isCollapsed)
-        return editor->DeleteSelection(nsIEditor::eNextWord);
+    if (NS_SUCCEEDED(rv) && selection && selection->Collapsed()) {
+      return editor->DeleteSelection(nsIEditor::eNextWord);
     }
     return editor->Copy();
   }
     
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP 
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -805,23 +805,18 @@ nsEditorEventListener::CanDrop(nsIDOMDra
   NS_ENSURE_SUCCESS(rv, false);
   if (domdoc == sourceDoc)      // source and dest are the same document; disallow drops within the selection
   {
     nsCOMPtr<nsISelection> selection;
     rv = mEditor->GetSelection(getter_AddRefs(selection));
     if (NS_FAILED(rv) || !selection)
       return false;
     
-    bool isCollapsed;
-    rv = selection->GetIsCollapsed(&isCollapsed);
-    NS_ENSURE_SUCCESS(rv, false);
-  
     // Don't bother if collapsed - can always drop
-    if (!isCollapsed)
-    {
+    if (!selection->Collapsed()) {
       nsCOMPtr<nsIDOMNode> parent;
       rv = aEvent->GetRangeParent(getter_AddRefs(parent));
       if (NS_FAILED(rv) || !parent) return false;
 
       PRInt32 offset = 0;
       rv = aEvent->GetRangeOffset(&offset);
       NS_ENSURE_SUCCESS(rv, false);
 
--- a/editor/libeditor/html/TypeInState.cpp
+++ b/editor/libeditor/html/TypeInState.cpp
@@ -72,53 +72,42 @@ TypeInState::~TypeInState()
 
   Reset();
 }
 
 nsresult TypeInState::UpdateSelState(nsISelection *aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   
-  bool isCollapsed = false;
-  nsresult result = aSelection->GetIsCollapsed(&isCollapsed);
-
-  NS_ENSURE_SUCCESS(result, result);
+  if (!aSelection->Collapsed()) {
+    return NS_OK;
+  }
 
-  if (isCollapsed)
-  {
-    result = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(mLastSelectionContainer), &mLastSelectionOffset);
-  }
-  return result;
+  return nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(mLastSelectionContainer), &mLastSelectionOffset);
 }
 
 
 NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection, PRInt16)
 {
   // XXX: Selection currently generates bogus selection changed notifications
   // XXX: (bug 140303). It can notify us when the selection hasn't actually
   // XXX: changed, and it notifies us more than once for the same change.
   // XXX:
   // XXX: The following code attempts to work around the bogus notifications,
   // XXX: and should probably be removed once bug 140303 is fixed.
   // XXX:
   // XXX: This code temporarily fixes the problem where clicking the mouse in
   // XXX: the same location clears the type-in-state.
 
-  if (aSelection)
-  {
-    bool isCollapsed = false;
-    nsresult result = aSelection->GetIsCollapsed(&isCollapsed);
+  if (aSelection) {
+    PRInt32 rangeCount = 0;
+    nsresult result = aSelection->GetRangeCount(&rangeCount);
     NS_ENSURE_SUCCESS(result, result);
 
-    PRInt32 rangeCount = 0;
-    result = aSelection->GetRangeCount(&rangeCount);
-    NS_ENSURE_SUCCESS(result, result);
-
-    if (isCollapsed && rangeCount)
-    {
+    if (aSelection->Collapsed() && rangeCount) {
       nsCOMPtr<nsIDOMNode> selNode;
       PRInt32 selOffset = 0;
 
       result = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
 
       NS_ENSURE_SUCCESS(result, result);
 
       if (selNode && selNode == mLastSelectionContainer && selOffset == mLastSelectionOffset)
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -194,23 +194,18 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTML(con
   rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel) {
     return NS_OK; // rules canceled the operation
   }
 
   if (!handled)
   {
-    bool isCollapsed;
-    rv = selection->GetIsCollapsed(&isCollapsed);
-    NS_ENSURE_SUCCESS(rv, rv);
-
     // Delete Selection, but only if it isn't collapsed, see bug #106269
-    if (!isCollapsed) 
-    {
+    if (!selection->Collapsed()) {
       rv = DeleteSelection(eNone);
       NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // Get the first range in the selection, for context:
     nsCOMPtr<nsIDOMRange> range;
     rv = selection->GetRangeAt(0, getter_AddRefs(range));
     NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -806,23 +806,18 @@ nsHTMLEditRules::GetAlignment(bool *aMix
 
   PRInt32 offset, rootOffset;
   res = nsEditor::GetNodeLocation(rootElem, address_of(parent), &rootOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
 
   // is the selection collapsed?
-  bool bCollapsed;
-  res = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIDOMNode> nodeToExamine;
-  nsCOMPtr<nsISupports> isupports;
-  if (bCollapsed)
-  {
+  if (selection->Collapsed()) {
     // if it is, we want to look at 'parent' and its ancestors
     // for divs with alignment on them
     nodeToExamine = parent;
   }
   else if (mHTMLEditor->IsTextNode(parent)) 
   {
     // if we are in a text node, then that is the node of interest
     nodeToExamine = parent;
@@ -1221,20 +1216,17 @@ nsHTMLEditRules::WillInsert(nsISelection
   nsresult res = nsTextEditRules::WillInsert(aSelection, aCancel);
   NS_ENSURE_SUCCESS(res, res); 
   
   // Adjust selection to prevent insertion after a moz-BR.
   // this next only works for collapsed selections right now,
   // because selection is a pain to work with when not collapsed.
   // (no good way to extend start or end of selection), so we ignore
   // those types of selections.
-  bool bCollapsed;
-  res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) {
+  if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // if we are after a mozBR in the same block, then move selection
   // to be before it
   nsCOMPtr<nsIDOMNode> selNode, priorNode;
   PRInt32 selOffset;
   // get the (collapsed) selection location
@@ -1304,21 +1296,17 @@ nsHTMLEditRules::WillInsertText(nsEditor
   // initialize out param
   *aCancel = false;
   *aHandled = true;
   nsresult res;
   nsCOMPtr<nsIDOMNode> selNode;
   PRInt32 selOffset;
 
   // if the selection isn't collapsed, delete it.
-  bool bCollapsed;
-  res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed)
-  {
+  if (!aSelection->Collapsed()) {
     res = mHTMLEditor->DeleteSelection(nsIEditor::eNone);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   res = WillInsert(aSelection, aCancel);
   NS_ENSURE_SUCCESS(res, res);
   // initialize out param
   // we want to ignore result of WillInsert()
@@ -1513,20 +1501,18 @@ nsHTMLEditRules::WillInsertBreak(nsISele
   if (!aSelection || !aCancel || !aHandled) {
     return NS_ERROR_NULL_POINTER;
   }
   // initialize out params
   *aCancel = false;
   *aHandled = false;
 
   // if the selection isn't collapsed, delete it.
-  bool bCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) {
+  nsresult res = NS_OK;
+  if (!aSelection->Collapsed()) {
     res = mHTMLEditor->DeleteSelection(nsIEditor::eNone);
     NS_ENSURE_SUCCESS(res, res);
   }
 
   res = WillInsert(aSelection, aCancel);
   NS_ENSURE_SUCCESS(res, res);
 
   // initialize out param
@@ -1843,43 +1829,38 @@ nsHTMLEditRules::WillDeleteSelection(nsI
   
   // if there is only bogus content, cancel the operation
   if (mBogusNode) 
   {
     *aCancel = true;
     return NS_OK;
   }
 
-  nsresult res = NS_OK;
-  bool bCollapsed, join = false;
-  res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
+  bool bCollapsed = aSelection->Collapsed(), join = false;
 
   // origCollapsed is used later to determine whether we should join 
   // blocks. We don't really care about bCollapsed because it will be 
   // modified by ExtendSelectionForDelete later. JoinBlocks should 
   // happen if the original selection is collapsed and the cursor is 
   // at the end of a block element, in which case ExtendSelectionForDelete 
   // would always make the selection not collapsed.
   bool origCollapsed = bCollapsed;
   nsCOMPtr<nsIDOMNode> startNode, selNode;
   PRInt32 startOffset, selOffset;
   
   // first check for table selection mode.  If so,
   // hand off to table editor.
-  {
-    nsCOMPtr<nsIDOMElement> cell;
-    res = mHTMLEditor->GetFirstSelectedCell(nsnull, getter_AddRefs(cell));
-    if (NS_SUCCEEDED(res) && cell)
-    {
-      res = mHTMLEditor->DeleteTableCellContents();
-      *aHandled = true;
-      return res;
-    }
-  }
+  nsCOMPtr<nsIDOMElement> cell;
+  nsresult res = mHTMLEditor->GetFirstSelectedCell(nsnull, getter_AddRefs(cell));
+  if (NS_SUCCEEDED(res) && cell) {
+    res = mHTMLEditor->DeleteTableCellContents();
+    *aHandled = true;
+    return res;
+  }
+  cell = NULL;
 
   res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
   if (bCollapsed)
   {
     // if we are inside an empty block, delete it.
@@ -1902,18 +1883,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI
     if (aAction == nsIEditor::eNone)
       return NS_OK;
 
     // ExtendSelectionForDelete() may have changed the selection, update it
     res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
     NS_ENSURE_SUCCESS(res, res);
     NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
     
-    res = aSelection->GetIsCollapsed(&bCollapsed);
-    NS_ENSURE_SUCCESS(res, res);
+    bCollapsed = aSelection->Collapsed();
   }
 
   if (bCollapsed)
   {
     // what's in the direction we are deleting?
     nsWSRunObject wsObj(mHTMLEditor, startNode, startOffset);
     nsCOMPtr<nsIDOMNode> visNode;
     PRInt32 visOffset;
@@ -3483,26 +3463,23 @@ nsHTMLEditRules::WillMakeBasicBlock(nsIS
 }
 
 nsresult 
 nsHTMLEditRules::DidMakeBasicBlock(nsISelection *aSelection,
                                    nsRulesInfo *aInfo, nsresult aResult)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // check for empty block.  if so, put a moz br in it.
-  bool isCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&isCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!isCollapsed) {
+  if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
-  res = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset);
+  nsresult res = nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   res = InsertMozBRIfNeeded(parent);
   return res;
 }
 
 nsresult
 nsHTMLEditRules::WillIndent(nsISelection *aSelection, bool *aCancel, bool * aHandled)
 {
@@ -3533,22 +3510,18 @@ nsHTMLEditRules::WillCSSIndent(nsISelect
   NS_ENSURE_SUCCESS(res, res);
   nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor);
   nsCOMArray<nsIDOMRange>  arrayOfRanges;
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   
   // short circuit: detect case of collapsed selection inside an <li>.
   // just sublist that <li>.  This prevents bug 97797.
   
-  bool bCollapsed;
   nsCOMPtr<nsIDOMNode> liNode;
-  res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (bCollapsed) 
-  {
+  if (aSelection->Collapsed()) {
     nsCOMPtr<nsIDOMNode> node, block;
     PRInt32 offset;
     nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
     NS_ENSURE_SUCCESS(res, res);
     if (IsBlockNode(node)) 
       block = node;
     else
       block = mHTMLEditor->GetBlockNodeParent(node);
@@ -4190,22 +4163,18 @@ nsHTMLEditRules::WillOutdent(nsISelectio
                                curBlockQuoteIsIndentedWithCSS,
                                address_of(rememberedLeftBQ),
                                address_of(rememberedRightBQ));
       NS_ENSURE_SUCCESS(res, res);
     }
   }
   // make sure selection didn't stick to last piece of content in old bq
   // (only a problem for collapsed selections)
-  if (rememberedLeftBQ || rememberedRightBQ)
-  {
-    bool bCollapsed;
-    res = aSelection->GetIsCollapsed(&bCollapsed);
-    if (bCollapsed)
-    {
+  if (rememberedLeftBQ || rememberedRightBQ) {
+    if (aSelection->Collapsed()) {
       // push selection past end of rememberedLeftBQ
       nsCOMPtr<nsIDOMNode> sNode;
       PRInt32 sOffset;
       mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(sNode), &sOffset);
       if (rememberedLeftBQ &&
           ((sNode == rememberedLeftBQ) || nsEditorUtils::IsDescendantOf(sNode, rememberedLeftBQ)))
       {
         // selection is inside rememberedLeftBQ - push it past it.
@@ -4218,16 +4187,17 @@ nsHTMLEditRules::WillOutdent(nsISelectio
       if (rememberedRightBQ &&
           ((sNode == rememberedRightBQ) || nsEditorUtils::IsDescendantOf(sNode, rememberedRightBQ)))
       {
         // selection is inside rememberedRightBQ - push it before it.
         nsEditor::GetNodeLocation(rememberedRightBQ, address_of(sNode), &sOffset);
         aSelection->Collapse(sNode, sOffset);
       }
     }
+    return NS_OK;
   }
   return res;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // RemovePartOfBlock:  split aBlock and move aStartChild to aEndChild out
 //                     of aBlock.  return left side of block (if any) in
@@ -5078,23 +5048,22 @@ nsHTMLEditRules::GetInnerContent(nsIDOMN
 // that have all their children selected.
 //                  
 nsresult
 nsHTMLEditRules::ExpandSelectionForDeletion(nsISelection *aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   
   // don't need to touch collapsed selections
-  bool bCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (bCollapsed) return res;
+  if (aSelection->Collapsed()) {
+    return NS_OK;
+  }
 
   PRInt32 rangeCount;
-  res = aSelection->GetRangeCount(&rangeCount);
+  nsresult res = aSelection->GetRangeCount(&rangeCount);
   NS_ENSURE_SUCCESS(res, res);
   
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (rangeCount != 1) return NS_OK;
   
   // find current sel start and end
   nsCOMPtr<nsIDOMRange> range;
   res = aSelection->GetRangeAt(0, getter_AddRefs(range));
@@ -5320,23 +5289,22 @@ nsHTMLEditRules::CreateMozDiv(nsIDOMNode
 //    block operations to determine what nodes to act on.
 //                       
 nsresult 
 nsHTMLEditRules::NormalizeSelection(nsISelection *inSelection)
 {
   NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
 
   // don't need to touch collapsed selections
-  bool bCollapsed;
-  nsresult res = inSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (bCollapsed) return res;
+  if (inSelection->Collapsed()) {
+    return NS_OK;
+  }
 
   PRInt32 rangeCount;
-  res = inSelection->GetRangeCount(&rangeCount);
+  nsresult res = inSelection->GetRangeCount(&rangeCount);
   NS_ENSURE_SUCCESS(res, res);
   
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (rangeCount != 1) return NS_OK;
   
   nsCOMPtr<nsIDOMRange> range;
   res = inSelection->GetRangeAt(0, getter_AddRefs(range));
   NS_ENSURE_SUCCESS(res, res);
@@ -7569,27 +7537,24 @@ nsHTMLEditRules::AdjustWhitespace(nsISel
   // ask whitespace object to tweak nbsp's
   return nsWSRunObject(mHTMLEditor, selNode, selOffset).AdjustWhitespace();
 }
 
 nsresult 
 nsHTMLEditRules::PinSelectionToNewBlock(nsISelection *aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
-  bool bCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) {
+  if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, temp;
   PRInt32 selOffset;
-  res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
+  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   temp = selNode;
   
   // use ranges and sRangeHelper to compare sel point to new block
   nsRefPtr<nsRange> range = new nsRange();
   res = range->SetStart(selNode, selOffset);
   NS_ENSURE_SUCCESS(res, res);
   res = range->SetEnd(selNode, selOffset);
@@ -7643,27 +7608,24 @@ nsHTMLEditRules::PinSelectionToNewBlock(
 nsresult 
 nsHTMLEditRules::CheckInterlinePosition(nsISelection *aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection(aSelection);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   // if the selection isn't collapsed, do nothing.
-  bool bCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) {
+  if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, node;
   PRInt32 selOffset;
-  res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
+  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
 
   // First, let's check to see if we are after a <br>.  We take care of this
   // special-case first so that we don't accidentally fall through into one
   // of the other conditionals.
   mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, address_of(node), true);
   if (node && nsTextEditUtils::IsBreak(node))
   {
@@ -7691,27 +7653,24 @@ nsHTMLEditRules::AdjustSelection(nsISele
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelection> selection(aSelection);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
  
   // if the selection isn't collapsed, do nothing.
   // moose: one thing to do instead is check for the case of
   // only a single break selected, and collapse it.  Good thing?  Beats me.
-  bool bCollapsed;
-  nsresult res = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed) {
+  if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
   nsCOMPtr<nsIDOMNode> selNode, temp;
   PRInt32 selOffset;
-  res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
+  nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   temp = selNode;
   
   // are we in an editable node?
   while (!mHTMLEditor->IsEditable(selNode))
   {
     // scan up the tree until we find an editable place to be
     res = nsEditor::GetNodeLocation(temp, address_of(selNode), &selOffset);
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -2022,27 +2022,21 @@ nsHTMLEditor::GetCSSBackgroundColorState
   // get selection location
   nsCOMPtr<nsIDOMNode> parent;
   PRInt32 offset;
   res = GetStartNodeAndOffset(selection, getter_AddRefs(parent), &offset);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
 
   // is the selection collapsed?
-  bool bCollapsed;
-  res = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
   nsCOMPtr<nsIDOMNode> nodeToExamine;
-  if (bCollapsed || IsTextNode(parent))
-  {
+  if (selection->Collapsed() || IsTextNode(parent)) {
     // we want to look at the parent and ancestors
     nodeToExamine = parent;
-  }
-  else
-  {
+  } else {
     // otherwise we want to look at the first editable node after
     // {parent,offset} and its ancestors for divs with alignment on them
     nodeToExamine = GetChildAt(parent, offset);
     //GetNextNode(parent, offset, true, address_of(nodeToExamine));
   }
   
   NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
 
@@ -2233,23 +2227,20 @@ nsHTMLEditor::MakeOrChangeList(const nsA
   ruleInfo.entireList = entireList;
   ruleInfo.bulletType = &aBulletType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
-    bool isCollapsed;
-    res = selection->GetIsCollapsed(&isCollapsed);
-    NS_ENSURE_SUCCESS(res, res);
+    bool isCollapsed = selection->Collapsed();
 
     nsCOMPtr<nsIDOMNode> node;
     PRInt32 offset;
-  
     res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset);
     if (!node) res = NS_ERROR_FAILURE;
     NS_ENSURE_SUCCESS(res, res);
   
     if (isCollapsed)
     {
       // have to find a place to put the list
       nsCOMPtr<nsIDOMNode> parent = node;
@@ -2377,23 +2368,20 @@ nsHTMLEditor::InsertBasicBlock(const nsA
   nsTextRulesInfo ruleInfo(kOpMakeBasicBlock);
   ruleInfo.blockType = &aBlockType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
     // Find out if the selection is collapsed:
-    bool isCollapsed;
-    res = selection->GetIsCollapsed(&isCollapsed);
-    NS_ENSURE_SUCCESS(res, res);
+    bool isCollapsed = selection->Collapsed();
 
     nsCOMPtr<nsIDOMNode> node;
     PRInt32 offset;
-  
     res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset);
     if (!node) res = NS_ERROR_FAILURE;
     NS_ENSURE_SUCCESS(res, res);
   
     if (isCollapsed)
     {
       // have to find a place to put the block
       nsCOMPtr<nsIDOMNode> parent = node;
@@ -2458,19 +2446,17 @@ nsHTMLEditor::Indent(const nsAString& aI
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
   
   if (!handled)
   {
     // Do default - insert a blockquote node if selection collapsed
     nsCOMPtr<nsIDOMNode> node;
     PRInt32 offset;
-    bool isCollapsed;
-    res = selection->GetIsCollapsed(&isCollapsed);
-    NS_ENSURE_SUCCESS(res, res);
+    bool isCollapsed = selection->Collapsed();
 
     res = GetStartNodeAndOffset(selection, getter_AddRefs(node), &offset);
     if (!node) res = NS_ERROR_FAILURE;
     NS_ENSURE_SUCCESS(res, res);
   
     if (aIndent.EqualsLiteral("indent"))
     {
       if (isCollapsed)
@@ -2675,19 +2661,17 @@ nsHTMLEditor::GetSelectedElement(const n
   // First look for a single element in selection
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
   bool bNodeFound = false;
-  res=NS_ERROR_NOT_INITIALIZED;
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
+  bool isCollapsed = selection->Collapsed();
 
   nsAutoString domTagName;
   nsAutoString TagName(aTagName);
   ToLowerCase(TagName);
   // Empty string indicates we should match any element tag
   bool anyTag = (TagName.IsEmpty());
   bool isLinkTag = IsLinkTag(TagName);
   bool isNamedAnchorTag = IsNamedAnchorTag(TagName);
@@ -2957,92 +2941,80 @@ nsHTMLEditor::CreateElementWithDefaults(
   }
 
   return res;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
 {
-  nsresult res=NS_ERROR_NULL_POINTER;
-  nsCOMPtr<nsISelection> selection;
-
-  NS_ENSURE_TRUE(aAnchorElement, NS_ERROR_NULL_POINTER); 
-
+  NS_ENSURE_TRUE(aAnchorElement, NS_ERROR_NULL_POINTER);
 
   // We must have a real selection
-  res = GetSelection(getter_AddRefs(selection));
+  nsCOMPtr<nsISelection> selection;
+  nsresult res = GetSelection(getter_AddRefs(selection));
   if (!selection)
   {
     res = NS_ERROR_NULL_POINTER;
   }
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
-  bool isCollapsed;
-  res = selection->GetIsCollapsed(&isCollapsed);
-  if (NS_FAILED(res))
-    isCollapsed = true;
-  
-  if (isCollapsed)
-  {
-    printf("InsertLinkAroundSelection called but there is no selection!!!\n");     
-    res = NS_OK;
-  } else {
-    // Be sure we were given an anchor element
-    nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aAnchorElement);
-    if (anchor)
-    {
-      nsAutoString href;
-      res = anchor->GetHref(href);
+  if (selection->Collapsed()) {
+    NS_WARNING("InsertLinkAroundSelection called but there is no selection!!!");
+    return NS_OK;
+  }
+
+  // Be sure we were given an anchor element
+  nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aAnchorElement);
+  if (!anchor) {
+    return NS_OK;
+  }
+
+  nsAutoString href;
+  res = anchor->GetHref(href);
+  NS_ENSURE_SUCCESS(res, res);
+  if (href.IsEmpty()) {
+    return NS_OK;
+  }
+
+  nsAutoEditBatch beginBatching(this);
+
+  // Set all attributes found on the supplied anchor element
+  nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
+  aAnchorElement->GetAttributes(getter_AddRefs(attrMap));
+  NS_ENSURE_TRUE(attrMap, NS_ERROR_FAILURE);
+
+  PRUint32 count;
+  attrMap->GetLength(&count);
+  nsAutoString name, value;
+
+  for (PRUint32 i = 0; i < count; ++i) {
+    nsCOMPtr<nsIDOMNode> attrNode;
+    res = attrMap->Item(i, getter_AddRefs(attrNode));
+    NS_ENSURE_SUCCESS(res, res);
+
+    nsCOMPtr<nsIDOMAttr> attribute = do_QueryInterface(attrNode);
+    if (attribute) {
+      // We must clear the string buffers
+      //   because GetName, GetValue appends to previous string!
+      name.Truncate();
+      value.Truncate();
+
+      res = attribute->GetName(name);
       NS_ENSURE_SUCCESS(res, res);
-      if (!href.IsEmpty())      
-      {
-        nsAutoEditBatch beginBatching(this);
-
-        // Set all attributes found on the supplied anchor element
-        nsCOMPtr<nsIDOMNamedNodeMap> attrMap;
-        aAnchorElement->GetAttributes(getter_AddRefs(attrMap));
-        NS_ENSURE_TRUE(attrMap, NS_ERROR_FAILURE);
-
-        PRUint32 count, i;
-        attrMap->GetLength(&count);
-        nsAutoString name, value;
-
-        for (i = 0; i < count; i++)
-        {
-          nsCOMPtr<nsIDOMNode> attrNode;
-          res = attrMap->Item(i, getter_AddRefs(attrNode));
-          NS_ENSURE_SUCCESS(res, res);
-
-          if (attrNode)
-          {
-            nsCOMPtr<nsIDOMAttr> attribute = do_QueryInterface(attrNode);
-            if (attribute)
-            {
-              // We must clear the string buffers
-              //   because GetName, GetValue appends to previous string!
-              name.Truncate();
-              value.Truncate();
-
-              res = attribute->GetName(name);
-              NS_ENSURE_SUCCESS(res, res);
-
-              res = attribute->GetValue(value);
-              NS_ENSURE_SUCCESS(res, res);
-
-              res = SetInlineProperty(nsEditProperty::a, name, value);
-              NS_ENSURE_SUCCESS(res, res);
-            }
-          }
-        }
-      }
+
+      res = attribute->GetValue(value);
+      NS_ENSURE_SUCCESS(res, res);
+
+      res = SetInlineProperty(nsEditProperty::a, name, value);
+      NS_ENSURE_SUCCESS(res, res);
     }
   }
-  return res;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLEditor::SetHTMLBackgroundColor(const nsAString& aColor)
 {
   NS_PRECONDITION(mDocWeak, "Missing Editor DOM Document");
   
   // Find a selected or enclosing table element to set background on
@@ -4915,18 +4887,17 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
 
   nsresult res;
   nsCOMPtr<nsISelection>selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
+  bool isCollapsed = selection->Collapsed();
 
   nsAutoEditBatch batchIt(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
   nsAutoSelectionReset selectionResetter(selection, this);
   nsAutoTxnsConserveSelection dontSpazMySelection(this);
   
   bool cancel, handled;
   nsTextRulesInfo ruleInfo(kOpSetTextProperty);
@@ -5275,27 +5246,22 @@ nsHTMLEditor::EndUpdateViewBatch()
 NS_IMETHODIMP
 nsHTMLEditor::GetSelectionContainer(nsIDOMElement ** aReturn)
 {
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   // if we don't get the selection, just skip this
   if (NS_FAILED(res) || !selection) return res;
 
-  bool bCollapsed;
-  res = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-
   nsCOMPtr<nsIDOMNode> focusNode;
 
-  if (bCollapsed) {
+  if (selection->Collapsed()) {
     res = selection->GetFocusNode(getter_AddRefs(focusNode));
     NS_ENSURE_SUCCESS(res, res);
-  }
-  else {
+  } else {
 
     PRInt32 rangeCount;
     res = selection->GetRangeCount(&rangeCount);
     NS_ENSURE_SUCCESS(res, res);
 
     if (rangeCount == 1) {
 
       nsCOMPtr<nsIDOMRange> range;
--- a/editor/libeditor/html/nsHTMLEditorEventListener.cpp
+++ b/editor/libeditor/html/nsHTMLEditorEventListener.cpp
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
@@ -159,40 +159,33 @@ nsHTMLEditorEventListener::MouseDown(nsI
     NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE);
 
     PRInt32 offset = 0;
     res = mouseEvent->GetRangeOffset(&offset);
     NS_ENSURE_SUCCESS(res, res);
 
     // Detect if mouse point is within current selection for context click
     bool nodeIsInSelection = false;
-    if (isContextClick)
-    {
-      bool isCollapsed;
-      selection->GetIsCollapsed(&isCollapsed);
-      if (!isCollapsed)
-      {
-        PRInt32 rangeCount;
-        res = selection->GetRangeCount(&rangeCount);
-        NS_ENSURE_SUCCESS(res, res);
+    if (isContextClick && !selection->Collapsed()) {
+      PRInt32 rangeCount;
+      res = selection->GetRangeCount(&rangeCount);
+      NS_ENSURE_SUCCESS(res, res);
+
+      for (PRInt32 i = 0; i < rangeCount; i++) {
+        nsCOMPtr<nsIDOMRange> range;
 
-        for (PRInt32 i = 0; i < rangeCount; i++)
-        {
-          nsCOMPtr<nsIDOMRange> range;
+        res = selection->GetRangeAt(i, getter_AddRefs(range));
+        if (NS_FAILED(res) || !range)
+          continue;//don't bail yet, iterate through them all
 
-          res = selection->GetRangeAt(i, getter_AddRefs(range));
-          if (NS_FAILED(res) || !range) 
-            continue;//don't bail yet, iterate through them all
+        res = range->IsPointInRange(parent, offset, &nodeIsInSelection);
 
-          res = range->IsPointInRange(parent, offset, &nodeIsInSelection);
-
-          // Done when we find a range that we are in
-          if (nodeIsInSelection)
-            break;
-        }
+        // Done when we find a range that we are in
+        if (nodeIsInSelection)
+          break;
       }
     }
     nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
     if (node && !nodeIsInSelection)
     {
       if (!element)
       {
         if (isContextClick)
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -123,19 +123,17 @@ nsHTMLEditor::SetInlineProperty(nsIAtom 
   ForceCompositionEnd();
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
-  if (isCollapsed) {
+  if (selection->Collapsed()) {
     // manipulating text attributes on a collapsed selection only sets state
     // for the next text insertion
     mTypeInState->SetProp(aProperty, aAttribute, aValue);
     return NS_OK;
   }
 
   nsAutoEditBatch batchIt(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
@@ -1004,18 +1002,17 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
   bool first = true;
 
   nsCOMPtr<nsISelection> selection;
   result = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
+  bool isCollapsed = selection->Collapsed();
   nsCOMPtr<nsIDOMNode> collapsedNode;
   nsCOMPtr<nsIEnumerator> enumerator;
   result = selPriv->GetEnumerator(getter_AddRefs(enumerator));
   NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(enumerator, NS_ERROR_NULL_POINTER);
 
   enumerator->First(); 
   nsCOMPtr<nsISupports> currentItem;
@@ -1254,21 +1251,18 @@ nsresult nsHTMLEditor::RemoveInlinePrope
 
   nsresult res;
   nsCOMPtr<nsISelection>selection;
   res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
 
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
-
   bool useCSS = IsCSSEnabled();
-  if (isCollapsed) {
+  if (selection->Collapsed()) {
     // manipulating text attributes on a collapsed selection only sets state for the next text insertion
 
     // For links, aProperty uses "href", use "a" instead
     if (aProperty == nsEditProperty::href ||
         aProperty == nsEditProperty::name)
       aProperty = nsEditProperty::a;
 
     if (aProperty) {
@@ -1451,23 +1445,18 @@ nsHTMLEditor::RelativeFontChange( PRInt3
 
   // Get the selection 
   nsCOMPtr<nsISelection>selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));  
   // Is the selection collapsed?
-  bool bCollapsed;
-  res = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  
   // if it's collapsed set typing state
-  if (bCollapsed)
-  {
+  if (selection->Collapsed()) {
     nsCOMPtr<nsIAtom> atom;
     if (aSizeChange==1) atom = nsEditProperty::big;
     else                atom = nsEditProperty::small;
 
     // Let's see in what kind of element the selection is
     PRInt32 offset;
     nsCOMPtr<nsIDOMNode> selectedNode;
     res = GetStartNodeAndOffset(selection, getter_AddRefs(selectedNode), &offset);
--- a/editor/libeditor/text/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/text/nsPlaintextDataTransfer.cpp
@@ -230,19 +230,17 @@ nsresult nsPlaintextEditor::InsertFromDr
   rv = uiEvent->GetRangeOffset(&newSelectionOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISelection> selection;
   rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
-  bool isCollapsed;
-  rv = selection->GetIsCollapsed(&isCollapsed);
-  NS_ENSURE_SUCCESS(rv, rv);
+  bool isCollapsed = selection->Collapsed();
 
   nsCOMPtr<nsIDOMNode> sourceNode;
   dataTransfer->GetMozSourceNode(getter_AddRefs(sourceNode));
 
   nsCOMPtr<nsIDOMDocument> srcdomdoc;
   if (sourceNode) {
     sourceNode->GetOwnerDocument(getter_AddRefs(srcdomdoc));
     NS_ENSURE_TRUE(sourceNode, NS_ERROR_FAILURE);
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -543,24 +543,22 @@ nsPlaintextEditor::InsertBR(nsCOMPtr<nsI
   *outBRNode = nsnull;
 
   // calling it text insertion to trigger moz br treatment by rules
   nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
 
   nsCOMPtr<nsISelection> selection;
   nsresult res = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(res, res);
-  bool bCollapsed;
-  res = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(res, res);
-  if (!bCollapsed)
-  {
+
+  if (!selection->Collapsed()) {
     res = DeleteSelection(nsIEditor::eNone);
     NS_ENSURE_SUCCESS(res, res);
   }
+
   nsCOMPtr<nsIDOMNode> selNode;
   PRInt32 selOffset;
   res = GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(res, res);
   
   res = CreateBR(selNode, selOffset, outBRNode);
   NS_ENSURE_SUCCESS(res, res);
     
@@ -659,21 +657,19 @@ nsPlaintextEditor::GetTextSelectionOffse
 
   return NS_OK;
 }
 
 nsresult
 nsPlaintextEditor::ExtendSelectionForDelete(nsISelection *aSelection,
                                             nsIEditor::EDirection *aAction)
 {
-  nsresult result;
+  nsresult result = NS_OK;
 
-  bool bCollapsed;
-  result = aSelection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(result, result);
+  bool bCollapsed = aSelection->Collapsed();
 
   if (*aAction == eNextWord || *aAction == ePreviousWord
       || (*aAction == eNext && bCollapsed)
       || (*aAction == ePrevious && bCollapsed)
       || *aAction == eToBeginningOfLine || *aAction == eToEndOfLine)
   {
     nsCOMPtr<nsISelectionController> selCont;
     GetSelectionController(getter_AddRefs(selCont));
@@ -760,20 +756,17 @@ NS_IMETHODIMP nsPlaintextEditor::DeleteS
   NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // If there is an existing selection when an extended delete is requested,
   //  platforms that use "caret-style" caret positioning collapse the
   //  selection to the  start and then create a new selection.
   //  Platforms that use "selection-style" caret positioning just delete the
   //  existing selection without extending it.
-  bool bCollapsed;
-  result  = selection->GetIsCollapsed(&bCollapsed);
-  NS_ENSURE_SUCCESS(result, result);
-  if (!bCollapsed &&
+  if (!selection->Collapsed() &&
       (aAction == eNextWord || aAction == ePreviousWord ||
        aAction == eToBeginningOfLine || aAction == eToEndOfLine))
   {
     if (mCaretStyle == 1)
     {
       result = selection->CollapseToStart();
       NS_ENSURE_SUCCESS(result, result);
     }
@@ -1255,19 +1248,17 @@ nsPlaintextEditor::Redo(PRUint32 aCount)
 
 bool
 nsPlaintextEditor::CanCutOrCopy()
 {
   nsCOMPtr<nsISelection> selection;
   if (NS_FAILED(GetSelection(getter_AddRefs(selection))))
     return false;
 
-  bool isCollapsed;
-  selection->GetIsCollapsed(&isCollapsed);
-  return !isCollapsed;
+  return !selection->Collapsed();
 }
 
 bool
 nsPlaintextEditor::FireClipboardEvent(PRInt32 aType)
 {
   if (aType == NS_PASTE)
     ForceCompositionEnd();
 
@@ -1564,18 +1555,17 @@ nsPlaintextEditor::SharedOutputString(PR
                                       bool* aIsCollapsed,
                                       nsAString& aResult)
 {
   nsCOMPtr<nsISelection> selection;
   nsresult rv = GetSelection(getter_AddRefs(selection));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
 
-  rv = selection->GetIsCollapsed(aIsCollapsed);
-  NS_ENSURE_SUCCESS(rv, rv);
+  *aIsCollapsed = selection->Collapsed();
 
   if (!*aIsCollapsed)
     aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
   // If the selection isn't collapsed, we'll use the whole document.
 
   return OutputToString(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
 }