Bug 762862 - Rename nsTypedSelection to mozilla::Selection; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Fri, 08 Jun 2012 17:20:55 +0300
changeset 99037 dcd70e227b9619b7865696843293bb351df27461
parent 99036 d425c0c8b55922fdc4a85c992354fa7fff3c29d8
child 99038 f0bdbbca7380aa10d69a3a2a5c66bc03a5891b3f
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs762862
milestone16.0a1
Bug 762862 - Rename nsTypedSelection to mozilla::Selection; r=ehsan
accessible/src/generic/HyperTextAccessible.cpp
content/base/public/nsContentUtils.h
content/base/src/nsContentUtils.cpp
content/html/content/src/nsTextEditorState.cpp
dom/base/nsFocusManager.cpp
editor/libeditor/base/nsEditRules.h
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditor.h
editor/libeditor/html/nsHTMLAbsPosition.cpp
editor/libeditor/html/nsHTMLDataTransfer.cpp
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/nsHTMLEditRules.h
editor/libeditor/html/nsHTMLEditor.cpp
editor/libeditor/html/nsHTMLEditorStyle.cpp
editor/libeditor/text/nsPlaintextEditor.cpp
editor/libeditor/text/nsTextEditRules.cpp
editor/libeditor/text/nsTextEditRules.h
layout/base/nsPresShell.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/Makefile.in
layout/generic/Selection.h
layout/generic/nsFrameSelection.h
layout/generic/nsSelection.cpp
layout/generic/nsTextFrame.h
layout/generic/nsTypedSelection.h
--- a/accessible/src/generic/HyperTextAccessible.cpp
+++ b/accessible/src/generic/HyperTextAccessible.cpp
@@ -26,17 +26,17 @@
 #include "nsFrameSelection.h"
 #include "nsILineIterator.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIPlaintextEditor.h"
 #include "nsIScrollableFrame.h"
 #include "nsISelectionPrivate.h"
 #include "nsIServiceManager.h"
 #include "nsTextFragment.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "gfxSkipChars.h"
 
 using namespace mozilla::a11y;
 
 ////////////////////////////////////////////////////////////////////////////////
 // HyperTextAccessible
 ////////////////////////////////////////////////////////////////////////////////
 
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -112,20 +112,21 @@ class nsIMIMEHeaderParam;
 class nsIObserver;
 class nsPresContext;
 class nsIChannel;
 class nsAutoScriptBlockerSuppressNodeRemoved;
 struct nsIntMargin;
 class nsPIDOMWindow;
 class nsIDocumentLoaderFactory;
 class nsIDOMHTMLInputElement;
-class nsTypedSelection;
 
 namespace mozilla {
 
+class Selection;
+
 namespace layers {
   class LayerManager;
 } // namespace layers
 
 namespace dom {
 class Element;
 } // namespace dom
 
@@ -2035,17 +2036,17 @@ public:
    * The selection's anchor and focus must both be in the root node passed or a
    * descendant.
    *
    * @param aSelection      Selection to check
    * @param aRoot           Root <input> or <textarea> element
    * @param aOutStartOffset Output start offset
    * @param aOutEndOffset   Output end offset
    */
-  static void GetSelectionInTextControl(nsTypedSelection* aSelection,
+  static void GetSelectionInTextControl(mozilla::Selection* aSelection,
                                         Element* aRoot,
                                         PRInt32& aOutStartOffset,
                                         PRInt32& aOutEndOffset);
   
 private:
   static bool InitializeEventTable();
 
   static nsresult EnsureStringBundle(PropertiesFile aFile);
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -138,17 +138,17 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
 #include "nsTextEditorState.h"
 #include "nsIPluginHost.h"
 #include "nsICategoryManager.h"
 #include "nsIViewManager.h"
 #include "nsEventStateManager.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsParserConstants.h"
 #include "nsIWebNavigation.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 
 #ifdef IBMBIDI
 #include "nsIBidiKeyboard.h"
 #endif
 #include "nsCycleCollectionParticipant.h"
 
 // for ReportToConsole
 #include "nsIStringBundle.h"
@@ -6862,17 +6862,17 @@ nsContentUtils::IsOnPrefWhitelist(nsPIDO
     }
   }
   *aAllowed = allowed;
   return NS_OK;
 }
 
 // static
 void
-nsContentUtils::GetSelectionInTextControl(nsTypedSelection* aSelection,
+nsContentUtils::GetSelectionInTextControl(Selection* aSelection,
                                           Element* aRoot,
                                           PRInt32& aOutStartOffset,
                                           PRInt32& aOutEndOffset)
 {
   MOZ_ASSERT(aSelection && aRoot);
 
   if (!aSelection->GetRangeCount()) {
     // Nothing selected
--- a/content/html/content/src/nsTextEditorState.cpp
+++ b/content/html/content/src/nsTextEditorState.cpp
@@ -28,20 +28,21 @@
 #include "nsIEditorObserver.h"
 #include "nsINativeKeyBindings.h"
 #include "nsIDocumentEncoder.h"
 #include "nsISelectionPrivate.h"
 #include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIEditor.h"
 #include "nsTextEditRules.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "nsEventListenerManager.h"
 #include "nsContentUtils.h"
 
+using namespace mozilla;
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID);
 
 static nsINativeKeyBindings *sNativeInputBindings = nsnull;
 static nsINativeKeyBindings *sNativeTextAreaBindings = nsnull;
 
 class RestoreSelectionState : public nsRunnable {
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -39,17 +39,17 @@
 #include "nsEventDispatcher.h"
 #include "nsEventStateManager.h"
 #include "nsIMEStateManager.h"
 #include "nsIWebNavigation.h"
 #include "nsCaret.h"
 #include "nsIBaseWindow.h"
 #include "nsIViewManager.h"
 #include "nsFrameSelection.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "nsXULPopupManager.h"
 #include "nsIDOMNodeFilter.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsIPrincipal.h"
 #include "mozAutoDocUpdate.h"
 #include "nsFrameLoader.h"
 #include "nsIObserverService.h"
 #include "nsIScriptError.h"
--- a/editor/libeditor/base/nsEditRules.h
+++ b/editor/libeditor/base/nsEditRules.h
@@ -41,17 +41,17 @@ public:
 //NOTE: Use   NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsIEditRules
 
   NS_IMETHOD Init(nsPlaintextEditor *aEditor)=0;
   NS_IMETHOD DetachEditor()=0;
   NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
                         nsIEditor::EDirection aDirection) = 0;
   NS_IMETHOD AfterEdit(nsEditor::OperationID action,
                        nsIEditor::EDirection aDirection) = 0;
-  NS_IMETHOD WillDoAction(nsTypedSelection* aSelection, nsRulesInfo* aInfo,
+  NS_IMETHOD WillDoAction(mozilla::Selection* aSelection, nsRulesInfo* aInfo,
                           bool* aCancel, bool* aHandled) = 0;
   NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
   NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty)=0;
   NS_IMETHOD DocumentModified()=0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIEditRules, NS_IEDITRULES_IID)
 
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -593,18 +593,18 @@ nsEditor::GetSelection(nsISelection **aS
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   *aSelection = nsnull;
   nsCOMPtr<nsISelectionController> selcon;
   GetSelectionController(getter_AddRefs(selcon));
   NS_ENSURE_TRUE(selcon, NS_ERROR_NOT_INITIALIZED);
   return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection);  // does an addref
 }
 
-nsTypedSelection*
-nsEditor::GetTypedSelection()
+Selection*
+nsEditor::GetSelection()
 {
   nsCOMPtr<nsISelection> sel;
   nsresult res = GetSelection(getter_AddRefs(sel));
   NS_ENSURE_SUCCESS(res, nsnull);
 
   nsCOMPtr<nsISelectionPrivate> selPrivate = do_QueryInterface(sel);
   NS_ENSURE_TRUE(selPrivate, nsnull);
 
--- a/editor/libeditor/base/nsEditor.h
+++ b/editor/libeditor/base/nsEditor.h
@@ -11,18 +11,17 @@
 
 #include "nsIEditor.h"
 #include "nsIPlaintextEditor.h"
 #include "nsIEditorIMESupport.h"
 #include "nsIPhonetic.h"
 
 #include "nsIAtom.h"
 #include "nsIDOMDocument.h"
-#include "nsISelection.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "nsIDOMCharacterData.h"
 #include "nsIPrivateTextRange.h"
 #include "nsITransactionManager.h"
 #include "nsIComponentManager.h"
 #include "nsCOMArray.h"
 #include "nsIEditActionListener.h"
 #include "nsIEditorObserver.h"
 #include "nsIDocumentStateListener.h"
@@ -590,17 +589,17 @@ public:
   static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset);
   static nsCOMPtr<nsIDOMNode> GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode, PRInt32 aOffset);
 
   static nsresult GetStartNodeAndOffset(nsISelection *aSelection, nsIDOMNode **outStartNode, PRInt32 *outStartOffset);
   static nsresult GetEndNodeAndOffset(nsISelection *aSelection, nsIDOMNode **outEndNode, PRInt32 *outEndOffset);
 #if DEBUG_JOE
   static void DumpNode(nsIDOMNode *aNode, PRInt32 indent=0);
 #endif
-  nsTypedSelection* GetTypedSelection();
+  mozilla::Selection* GetSelection();
 
   // Helpers to add a node to the selection. 
   // Used by table cell selection methods
   nsresult CreateRange(nsIDOMNode *aStartParent, PRInt32 aStartOffset,
                        nsIDOMNode *aEndParent, PRInt32 aEndOffset,
                        nsIDOMRange **aRange);
 
   // Creates a range with just the supplied node and appends that to the selection
--- a/editor/libeditor/html/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/html/nsHTMLAbsPosition.cpp
@@ -41,17 +41,17 @@ nsHTMLEditor::AbsolutePositionSelection(
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this,
                                  aEnabled ? kOpSetAbsolutePosition :
                                             kOpRemoveAbsolutePosition,
                                  nsIEditor::eNext);
   
   // the line below does not match the code; should it be removed?
   // Find out if the selection is collapsed:
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(aEnabled ? kOpSetAbsolutePosition :
                                       kOpRemoveAbsolutePosition);
   bool cancel, handled;
   nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (NS_FAILED(res) || cancel)
     return res;
@@ -154,17 +154,17 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this,
                                  (aChange < 0) ? kOpDecreaseZIndex :
                                                  kOpIncreaseZIndex,
                                  nsIEditor::eNext);
   
   // brade: can we get rid of this comment?
   // Find out if the selection is collapsed:
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(aChange < 0 ? kOpDecreaseZIndex :
                                          kOpIncreaseZIndex);
   bool cancel, handled;
   nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
   
--- a/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -148,17 +148,17 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTML(con
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // force IME commit; set up rules sniffing and batching
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpLoadHTML, nsIEditor::eNext);
 
   // Get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection);
 
   nsTextRulesInfo ruleInfo(kOpLoadHTML);
   bool cancel, handled;
   nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel) {
     return NS_OK; // rules canceled the operation
@@ -245,17 +245,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
 
   // force IME commit; set up rules sniffing and batching
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpHTMLPaste, nsIEditor::eNext);
 
   // Get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection);
 
   // create a dom document fragment that represents the structure to paste
   nsCOMPtr<nsIDOMNode> fragmentAsNode, streamStartParent, streamEndParent;
   PRInt32 streamStartOffset = 0, streamEndOffset = 0;
 
   nsresult rv = CreateDOMFragmentFromPaste(aInputString, aContextStr, aInfoStr,
                                            address_of(fragmentAsNode),
@@ -1725,17 +1725,17 @@ NS_IMETHODIMP nsHTMLEditor::PasteAsQuota
 
 NS_IMETHODIMP nsHTMLEditor::PasteAsCitedQuotation(const nsAString & aCitation,
                                                   PRInt32 aSelectionType)
 {
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
   // get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(kOpInsertElement);
   bool cancel, handled;
   nsresult rv = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   NS_ENSURE_SUCCESS(rv, rv);
   if (cancel || handled) {
@@ -1922,17 +1922,17 @@ nsHTMLEditor::InsertAsPlaintextQuotation
                                          bool aAddCites,
                                          nsIDOMNode **aNodeInserted)
 {
   if (mWrapToWindow)
     return nsPlaintextEditor::InsertAsQuotation(aQuotedText, aNodeInserted);
 
   nsCOMPtr<nsIDOMNode> newNode;
   // get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(kOpInsertElement);
   bool cancel, handled;
@@ -2014,17 +2014,17 @@ nsHTMLEditor::InsertAsCitedQuotation(con
   {
     NS_ASSERTION(!aInsertHTML, "InsertAsCitedQuotation: trying to insert html into plaintext editor");
     return InsertAsPlaintextQuotation(aQuotedText, true, aNodeInserted);
   }
 
   nsCOMPtr<nsIDOMNode> newNode;
 
   // get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertQuotation, nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(kOpInsertElement);
   bool cancel, handled;
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -510,17 +510,17 @@ nsHTMLEditRules::AfterEditInner(nsEditor
     res = CheckInterlinePosition(selection);
   }
   
   return res;
 }
 
 
 NS_IMETHODIMP
-nsHTMLEditRules::WillDoAction(nsTypedSelection* aSelection,
+nsHTMLEditRules::WillDoAction(Selection* aSelection,
                               nsRulesInfo* aInfo,
                               bool* aCancel,
                               bool* aHandled)
 {
   MOZ_ASSERT(aInfo && aCancel && aHandled);
 
   *aCancel = false;
   *aHandled = false;
@@ -1232,17 +1232,17 @@ nsHTMLEditRules::WillInsert(nsISelection
     NS_ENSURE_SUCCESS(res, res);
   }
 
   return NS_OK;
 }    
 
 nsresult
 nsHTMLEditRules::WillInsertText(nsEditor::OperationID aAction,
-                                nsTypedSelection* aSelection,
+                                Selection*       aSelection,
                                 bool            *aCancel,
                                 bool            *aHandled,
                                 const nsAString *inString,
                                 nsAString       *outString,
                                 PRInt32          aMaxLength)
 {  
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
 
@@ -1458,17 +1458,17 @@ nsHTMLEditRules::WillLoadHTML(nsISelecti
     mEditor->DeleteNode(mBogusNode);
     mBogusNode = nsnull;
   }
 
   return NS_OK;
 }
 
 nsresult
-nsHTMLEditRules::WillInsertBreak(nsTypedSelection* aSelection,
+nsHTMLEditRules::WillInsertBreak(Selection* aSelection,
                                  bool* aCancel, bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) {
     return NS_ERROR_NULL_POINTER;
   }
   // initialize out params
   *aCancel = false;
   *aHandled = false;
@@ -1774,17 +1774,17 @@ nsHTMLEditRules::SplitMailCites(nsISelec
     }
     *aHandled = true;
   }
   return NS_OK;
 }
 
 
 nsresult
-nsHTMLEditRules::WillDeleteSelection(nsTypedSelection* aSelection,
+nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
                                      nsIEditor::EDirection aAction,
                                      nsIEditor::EStripWrappers aStripWrappers,
                                      bool* aCancel,
                                      bool* aHandled)
 {
   MOZ_ASSERT(aStripWrappers == nsIEditor::eStrip ||
              aStripWrappers == nsIEditor::eNoStrip);
 
@@ -7239,17 +7239,17 @@ nsHTMLEditRules::ReapplyCachedStyles()
   // The idea here is to examine our cached list of styles and see if any have
   // been removed.  If so, add typeinstate for them, so that they will be
   // reinserted when new content is added.
 
   // remember if we are in css mode
   bool useCSS = mHTMLEditor->IsCSSEnabled();
 
   // get selection point; if it doesn't exist, we have nothing to do
-  nsRefPtr<nsTypedSelection> selection = mHTMLEditor->GetTypedSelection();
+  nsRefPtr<Selection> selection = mHTMLEditor->GetSelection();
   MOZ_ASSERT(selection);
   if (!selection->GetRangeCount()) {
     // Nothing to do
     return NS_OK;
   }
   nsCOMPtr<nsIContent> selNode =
     do_QueryInterface(selection->GetRangeAt(0)->GetStartParent());
   if (!selNode) {
--- a/editor/libeditor/html/nsHTMLEditRules.h
+++ b/editor/libeditor/html/nsHTMLEditRules.h
@@ -55,17 +55,17 @@ public:
 
   // nsIEditRules methods
   NS_IMETHOD Init(nsPlaintextEditor *aEditor);
   NS_IMETHOD DetachEditor();
   NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
                         nsIEditor::EDirection aDirection);
   NS_IMETHOD AfterEdit(nsEditor::OperationID action,
                        nsIEditor::EDirection aDirection);
-  NS_IMETHOD WillDoAction(nsTypedSelection* aSelection, nsRulesInfo* aInfo,
+  NS_IMETHOD WillDoAction(mozilla::Selection* aSelection, nsRulesInfo* aInfo,
                           bool* aCancel, bool* aHandled);
   NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
   NS_IMETHOD DocumentModified();
 
   nsresult GetListState(bool *aMixed, bool *aOL, bool *aUL, bool *aDL);
   nsresult GetListItemState(bool *aMixed, bool *aLI, bool *aDT, bool *aDD);
   nsresult GetIndentState(bool *aCanIndent, bool *aCanOutdent);
   nsresult GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign);
@@ -103,29 +103,29 @@ protected:
   {
     kBeforeBlock,
     kBlockEnd
   };
 
   // nsHTMLEditRules implementation methods
   nsresult WillInsert(nsISelection *aSelection, bool *aCancel);
   nsresult WillInsertText(  nsEditor::OperationID aAction,
-                            nsTypedSelection* aSelection,
+                            mozilla::Selection* aSelection,
                             bool            *aCancel,
                             bool            *aHandled,
                             const nsAString *inString,
                             nsAString       *outString,
                             PRInt32          aMaxLength);
   nsresult WillLoadHTML(nsISelection *aSelection, bool *aCancel);
-  nsresult WillInsertBreak(nsTypedSelection* aSelection,
+  nsresult WillInsertBreak(mozilla::Selection* aSelection,
                            bool* aCancel, bool* aHandled);
   nsresult StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelection *aSelection);
   nsresult DidInsertBreak(nsISelection *aSelection, nsresult aResult);
   nsresult SplitMailCites(nsISelection *aSelection, bool aPlaintext, bool *aHandled);
-  nsresult WillDeleteSelection(nsTypedSelection* aSelection,
+  nsresult WillDeleteSelection(mozilla::Selection* aSelection,
                                nsIEditor::EDirection aAction,
                                nsIEditor::EStripWrappers aStripWrappers,
                                bool* aCancel, bool* aHandled);
   nsresult DidDeleteSelection(nsISelection *aSelection, 
                               nsIEditor::EDirection aDir, 
                               nsresult aResult);
   nsresult InsertBRIfNeeded(nsISelection *aSelection);
   nsresult GetGoodSelPointForNode(nsIDOMNode *aNode, nsIEditor::EDirection aAction, 
--- a/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/editor/libeditor/html/nsHTMLEditor.cpp
@@ -1689,17 +1689,17 @@ nsHTMLEditor::InsertElementAtSelection(n
   NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER);
   
   nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
   
   ForceCompositionEnd();
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
 
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return NS_ERROR_FAILURE;
   }
 
   // hand off to the rules system, see if it has anything to say about this
   bool cancel, handled;
   nsTextRulesInfo ruleInfo(kOpInsertElement);
   ruleInfo.insertElement = aElement;
@@ -2174,17 +2174,17 @@ nsHTMLEditor::MakeOrChangeList(const nsA
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   bool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeList, nsIEditor::eNext);
   
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(kOpMakeList);
   ruleInfo.blockType = &aListType;
   ruleInfo.entireList = entireList;
   ruleInfo.bulletType = &aBulletType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
@@ -2250,17 +2250,17 @@ nsHTMLEditor::RemoveList(const nsAString
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   bool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpRemoveList, nsIEditor::eNext);
   
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(kOpRemoveList);
   if (aListType.LowerCaseEqualsLiteral("ol"))
     ruleInfo.bOrdered = true;
   else  ruleInfo.bOrdered = false;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
@@ -2281,17 +2281,17 @@ nsHTMLEditor::MakeDefinitionItem(const n
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   bool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeDefListItem, nsIEditor::eNext);
   
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(kOpMakeDefListItem);
   ruleInfo.blockType = &aItemType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
@@ -2312,17 +2312,17 @@ nsHTMLEditor::InsertBasicBlock(const nsA
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   bool cancel, handled;
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpMakeBasicBlock, nsIEditor::eNext);
   
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(kOpMakeBasicBlock);
   ruleInfo.blockType = &aBlockType;
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
 
   if (!handled)
   {
@@ -2386,17 +2386,17 @@ nsHTMLEditor::Indent(const nsAString& aI
   if (aIndent.LowerCaseEqualsLiteral("outdent"))
   {
     opID = kOpOutdent;
   }
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
   
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsTextRulesInfo ruleInfo(opID);
   res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || (NS_FAILED(res))) return res;
   
   if (!handled)
   {
@@ -2463,17 +2463,17 @@ nsHTMLEditor::Align(const nsAString& aAl
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpAlign, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMNode> node;
   bool cancel, handled;
   
   // Find out if the selection is collapsed:
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsTextRulesInfo ruleInfo(kOpAlign);
   ruleInfo.alignType = &aAlignType;
   nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   if (cancel || NS_FAILED(res))
     return res;
   
   res = mRules->DidDoAction(selection, &ruleInfo, res);
@@ -3384,24 +3384,24 @@ nsHTMLEditor::DeleteSelectionImpl(EDirec
   nsresult res = nsEditor::DeleteSelectionImpl(aAction, aStripWrappers);
   NS_ENSURE_SUCCESS(res, res);
 
   // If we weren't asked to strip any wrappers, we're done.
   if (aStripWrappers == eNoStrip) {
     return NS_OK;
   }
 
-  nsRefPtr<nsTypedSelection> typedSel = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   // Just checking that the selection itself is collapsed doesn't seem to work
   // right in the multi-range case
-  NS_ENSURE_STATE(typedSel);
-  NS_ENSURE_STATE(typedSel->GetAnchorFocusRange());
-  NS_ENSURE_STATE(typedSel->GetAnchorFocusRange()->Collapsed());
-
-  nsCOMPtr<nsIContent> content = do_QueryInterface(typedSel->GetAnchorNode());
+  NS_ENSURE_STATE(selection);
+  NS_ENSURE_STATE(selection->GetAnchorFocusRange());
+  NS_ENSURE_STATE(selection->GetAnchorFocusRange()->Collapsed());
+
+  nsCOMPtr<nsIContent> content = do_QueryInterface(selection->GetAnchorNode());
   NS_ENSURE_STATE(content);
 
   // Don't strip wrappers if this is the only wrapper in the block.  Then we'll
   // add a <br> later, so it won't be an empty wrapper in the end.
   nsCOMPtr<nsIContent> blockParent = content;
   while (blockParent && !IsBlockNode(blockParent)) {
     blockParent = blockParent->GetParent();
   }
@@ -4882,17 +4882,17 @@ NS_IMETHODIMP
 nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor)
 {
   if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
   ForceCompositionEnd();
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
 
   bool isCollapsed = selection->Collapsed();
 
   nsAutoEditBatch batchIt(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertElement, nsIEditor::eNext);
   nsAutoSelectionReset selectionResetter(selection, this);
   nsAutoTxnsConserveSelection dontSpazMySelection(this);
   
--- a/editor/libeditor/html/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp
@@ -83,17 +83,17 @@ nsHTMLEditor::SetInlineProperty(nsIAtom 
   if (!aProperty) {
     return NS_ERROR_NULL_POINTER;
   }
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
   ForceCompositionEnd();
 
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   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;
   }
@@ -1328,17 +1328,17 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInline
 
 nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAString *aAttribute)
 {
   MOZ_ASSERT_IF(aProperty, aAttribute);
   NS_ENSURE_TRUE(mRules, NS_ERROR_NOT_INITIALIZED);
   ForceCompositionEnd();
 
   nsresult res;
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   bool useCSS = IsCSSEnabled();
   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 ||
--- a/editor/libeditor/text/nsPlaintextEditor.cpp
+++ b/editor/libeditor/text/nsPlaintextEditor.cpp
@@ -625,17 +625,17 @@ nsPlaintextEditor::DeleteSelection(EDire
 
   HandlingTrustedAction trusted(this, aAction != eNone);
 
   // delete placeholder txns merge.
   nsAutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
   nsAutoRules beginRulesSniffing(this, kOpDeleteSelection, aAction);
 
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   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.
   if (!selection->Collapsed() &&
@@ -683,17 +683,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertT
   if (mInIMEMode) 
   {
     opID = kOpInsertIMEText;
   }
   nsAutoPlaceHolderBatch batch(this, nsnull); 
   nsAutoRules beginRulesSniffing(this, opID, nsIEditor::eNext);
 
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsAutoString resultString;
   // XXX can we trust instring to outlive ruleInfo,
   // XXX and ruleInfo not to refer to instring in its dtor?
   //nsAutoString instring(aStringToInsert);
   nsTextRulesInfo ruleInfo(opID);
   ruleInfo.inString = &aStringToInsert;
   ruleInfo.outString = &resultString;
@@ -720,17 +720,17 @@ NS_IMETHODIMP nsPlaintextEditor::InsertL
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertBreak, nsIEditor::eNext);
 
   // pre-process
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   // Batching the selection and moving nodes out from under the caret causes
   // caret turds. Ask the shell to invalidate the caret now to avoid the turds.
   nsCOMPtr<nsIPresShell> shell = GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
   shell->MaybeInvalidateCaretPosition();
 
@@ -1068,17 +1068,17 @@ nsPlaintextEditor::Undo(PRUint32 aCount)
 
   nsAutoUpdateViewBatch beginViewBatching(this);
 
   ForceCompositionEnd();
 
   nsAutoRules beginRulesSniffing(this, kOpUndo, nsIEditor::eNone);
 
   nsTextRulesInfo ruleInfo(kOpUndo);
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
   nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   
   if (!cancel && NS_SUCCEEDED(result))
   {
     result = nsEditor::Undo(aCount);
     result = mRules->DidDoAction(selection, &ruleInfo, result);
   } 
@@ -1097,17 +1097,17 @@ nsPlaintextEditor::Redo(PRUint32 aCount)
 
   nsAutoUpdateViewBatch beginViewBatching(this);
 
   ForceCompositionEnd();
 
   nsAutoRules beginRulesSniffing(this, kOpRedo, nsIEditor::eNone);
 
   nsTextRulesInfo ruleInfo(kOpRedo);
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
   nsresult result = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
   
   if (!cancel && NS_SUCCEEDED(result))
   {
     result = nsEditor::Redo(aCount);
     result = mRules->DidDoAction(selection, &ruleInfo, result);
   } 
@@ -1371,17 +1371,17 @@ nsPlaintextEditor::InsertAsQuotation(con
   NS_ENSURE_SUCCESS(rv, rv);
 
   // It's best to put a blank line after the quoted text so that mails
   // written without thinking won't be so ugly.
   if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != PRUnichar('\n')))
     quotedStuff.Append(PRUnichar('\n'));
 
   // get selection
-  nsRefPtr<nsTypedSelection> selection = GetTypedSelection();
+  nsRefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
   nsAutoEditBatch beginBatching(this);
   nsAutoRules beginRulesSniffing(this, kOpInsertText, nsIEditor::eNext);
 
   // give rules a chance to handle or cancel
   nsTextRulesInfo ruleInfo(kOpInsertElement);
   bool cancel, handled;
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -205,17 +205,17 @@ nsTextEditRules::AfterEdit(nsEditor::Ope
     // collapse the selection to the trailing BR if it's at the end of our text node
     CollapseSelectionToTrailingBRIfNeeded(selection);
   }
   return res;
 }
 
 
 NS_IMETHODIMP
-nsTextEditRules::WillDoAction(nsTypedSelection* aSelection,
+nsTextEditRules::WillDoAction(Selection* aSelection,
                               nsRulesInfo* aInfo,
                               bool* aCancel,
                               bool* aHandled)
 {
   // null selection is legal
   MOZ_ASSERT(aInfo && aCancel && aHandled);
 
   *aCancel = false;
@@ -329,17 +329,17 @@ nsTextEditRules::WillInsert(nsISelection
 
 nsresult
 nsTextEditRules::DidInsert(nsISelection *aSelection, nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::WillInsertBreak(nsTypedSelection* aSelection,
+nsTextEditRules::WillInsertBreak(Selection* aSelection,
                                  bool *aCancel,
                                  bool *aHandled,
                                  PRInt32 aMaxLength)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   *aHandled = false;
   if (IsSingleLineEditor()) {
@@ -536,17 +536,17 @@ nsTextEditRules::HandleNewLines(nsString
     // even if we're pasting newlines, don't paste leading/trailing ones
     aString.Trim(CRLF, true, true);
     break;
   }
 }
 
 nsresult
 nsTextEditRules::WillInsertText(nsEditor::OperationID aAction,
-                                nsTypedSelection* aSelection,
+                                Selection* aSelection,
                                 bool            *aCancel,
                                 bool            *aHandled,
                                 const nsAString *inString,
                                 nsAString *outString,
                                 PRInt32          aMaxLength)
 {  
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
 
@@ -748,17 +748,17 @@ nsTextEditRules::WillRemoveTextProperty(
 
 nsresult
 nsTextEditRules::DidRemoveTextProperty(nsISelection *aSelection, nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::WillDeleteSelection(nsTypedSelection* aSelection,
+nsTextEditRules::WillDeleteSelection(Selection* aSelection,
                                      nsIEditor::EDirection aCollapsedAction, 
                                      bool *aCancel,
                                      bool *aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
 
   // initialize out param
@@ -1133,17 +1133,17 @@ nsTextEditRules::CreateBogusNodeIfNeeded
 
   // Set selection.
   aSelection->CollapseNative(body, 0);
   return NS_OK;
 }
 
 
 nsresult
-nsTextEditRules::TruncateInsertionIfNeeded(nsTypedSelection* aSelection,
+nsTextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
                                            const nsAString  *aInString,
                                            nsAString  *aOutString,
                                            PRInt32          aMaxLength,
                                            bool *aTruncated)
 {
   if (!aSelection || !aInString || !aOutString) {return NS_ERROR_NULL_POINTER;}
   
   nsresult res = NS_OK;
@@ -1235,17 +1235,17 @@ nsresult nsTextEditRules::HideLastPWInpu
   if (!mLastLength) {
     // Special case, we're trying to replace a range that no longer exists
     return NS_OK;
   }
 
   nsAutoString hiddenText;
   FillBufWithPWChars(&hiddenText, mLastLength);
 
-  nsRefPtr<nsTypedSelection> selection = mEditor->GetTypedSelection();
+  nsRefPtr<Selection> selection = mEditor->GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   PRInt32 start, end;
   nsContentUtils::GetSelectionInTextControl(selection, mEditor->GetRoot(),
                                             start, end);
 
   nsCOMPtr<nsIDOMNode> selNode = GetTextNode(selection, mEditor);
   NS_ENSURE_TRUE(selNode, NS_OK);
   
--- a/editor/libeditor/text/nsTextEditRules.h
+++ b/editor/libeditor/text/nsTextEditRules.h
@@ -37,17 +37,17 @@ public:
 
   // nsIEditRules methods
   NS_IMETHOD Init(nsPlaintextEditor *aEditor);
   NS_IMETHOD DetachEditor();
   NS_IMETHOD BeforeEdit(nsEditor::OperationID action,
                         nsIEditor::EDirection aDirection);
   NS_IMETHOD AfterEdit(nsEditor::OperationID action,
                        nsIEditor::EDirection aDirection);
-  NS_IMETHOD WillDoAction(nsTypedSelection* aSelection, nsRulesInfo* aInfo,
+  NS_IMETHOD WillDoAction(mozilla::Selection* aSelection, nsRulesInfo* aInfo,
                           bool* aCancel, bool* aHandled);
   NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
   NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty);
   NS_IMETHOD DocumentModified();
 
 public:
   void ResetIMETextPWBuf();
 
@@ -86,33 +86,33 @@ public:
    *        contain.
    */
   static void FillBufWithPWChars(nsAString *aOutString, PRInt32 aLength);
 
 protected:
 
   // nsTextEditRules implementation methods
   nsresult WillInsertText(  nsEditor::OperationID aAction,
-                            nsTypedSelection* aSelection,
+                            mozilla::Selection* aSelection,
                             bool            *aCancel,
                             bool            *aHandled,
                             const nsAString *inString,
                             nsAString       *outString,
                             PRInt32          aMaxLength);
   nsresult DidInsertText(nsISelection *aSelection, nsresult aResult);
   nsresult GetTopEnclosingPre(nsIDOMNode *aNode, nsIDOMNode** aOutPreNode);
 
-  nsresult WillInsertBreak(nsTypedSelection* aSelection, bool* aCancel,
+  nsresult WillInsertBreak(mozilla::Selection* aSelection, bool* aCancel,
                            bool *aHandled, PRInt32 aMaxLength);
   nsresult DidInsertBreak(nsISelection *aSelection, nsresult aResult);
 
   nsresult WillInsert(nsISelection *aSelection, bool *aCancel);
   nsresult DidInsert(nsISelection *aSelection, nsresult aResult);
 
-  nsresult WillDeleteSelection(nsTypedSelection* aSelection,
+  nsresult WillDeleteSelection(mozilla::Selection* aSelection,
                                nsIEditor::EDirection aCollapsedAction, 
                                bool *aCancel,
                                bool *aHandled);
   nsresult DidDeleteSelection(nsISelection *aSelection, 
                               nsIEditor::EDirection aCollapsedAction, 
                               nsresult aResult);
 
   nsresult WillSetTextProperty(nsISelection *aSelection, bool *aCancel, bool *aHandled);
@@ -151,17 +151,17 @@ protected:
   /** creates a trailing break in the text doc if there is not one already */
   nsresult CreateTrailingBRIfNeeded();
   
  /** creates a bogus text node if the document has no editable content */
   nsresult CreateBogusNodeIfNeeded(nsISelection *aSelection);
 
   /** returns a truncated insertion string if insertion would place us
       over aMaxLength */
-  nsresult TruncateInsertionIfNeeded(nsTypedSelection*         aSelection,
+  nsresult TruncateInsertionIfNeeded(mozilla::Selection*       aSelection,
                                      const nsAString          *aInString,
                                      nsAString                *aOutString,
                                      PRInt32                   aMaxLength,
                                      bool                     *aTruncated);
 
   /** Remove IME composition text from password buffer */
   void RemoveIMETextFromPWBuf(PRInt32 &aStart, nsAString *aIMEString);
 
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -48,17 +48,17 @@
 #include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsHashtable.h"
 #include "nsContainerFrame.h"
 #include "nsDOMEvent.h"
 #include "nsHTMLParts.h"
 #include "nsISelection.h"
 #include "nsISelectionPrivate.h"
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 #include "nsLayoutCID.h"
 #include "nsGkAtoms.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMElement.h"
 #include "nsRange.h"
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -73,16 +73,18 @@
 #include "nsFocusManager.h"
 #include "nsTextEditRules.h"
 #include "nsPresState.h"
 
 #include "mozilla/FunctionTimer.h"
 
 #define DEFAULT_COLUMN_WIDTH 20
 
+using namespace mozilla;
+
 nsIFrame*
 NS_NewTextControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsTextControlFrame(aPresShell, aContext);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsTextControlFrame)
 
@@ -1060,17 +1062,17 @@ nsTextControlFrame::GetSelectionRange(PR
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
   nsCOMPtr<nsISelectionPrivate> selPriv = do_QueryInterface(selection);
   NS_ENSURE_TRUE(selPriv, NS_ERROR_FAILURE);
   nsRefPtr<nsFrameSelection> frameSel;
   rv = selPriv->GetFrameSelection(getter_AddRefs(frameSel));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(frameSel, NS_ERROR_FAILURE);
-  nsRefPtr<nsTypedSelection> typedSel =
+  nsRefPtr<Selection> typedSel =
     frameSel->GetSelection(nsISelectionController::SELECTION_NORMAL);
   NS_ENSURE_TRUE(typedSel, NS_ERROR_FAILURE);
 
   if (aDirection) {
     nsDirection direction = typedSel->GetSelectionDirection();
     if (direction == eDirNext) {
       *aDirection = eForward;
     } else if (direction == eDirPrevious) {
--- a/layout/generic/Makefile.in
+++ b/layout/generic/Makefile.in
@@ -29,26 +29,30 @@ EXPORTS		= \
 		nsIFrameUtil.h \
 		nsILineIterator.h \
 		nsIObjectFrame.h \
 		nsIPageSequenceFrame.h \
 		nsIScrollableFrame.h \
 		nsIStatefulFrame.h \
 		nsFrameSelection.h \
 		nsSubDocumentFrame.h \
-		nsTypedSelection.h \
+		Selection.h \
 		nsObjectFrame.h \
 		$(NULL)
 
-EXPORTS_NAMESPACES = mozilla/layout
+EXPORTS_NAMESPACES = mozilla/layout mozilla
 
 EXPORTS_mozilla/layout = \
 		FrameChildList.h \
 		$(NULL)
 
+EXPORTS_mozilla = \
+		Selection.h \
+		$(NULL)
+
 CPPSRCS		= \
 		FrameChildList.cpp \
 		nsAbsoluteContainingBlock.cpp \
 		nsBRFrame.cpp \
 		nsBlockFrame.cpp \
 		nsBlockReflowContext.cpp \
 		nsBlockReflowState.cpp \
 		nsBulletFrame.cpp \
rename from layout/generic/nsTypedSelection.h
rename to layout/generic/Selection.h
--- a/layout/generic/nsTypedSelection.h
+++ b/layout/generic/Selection.h
@@ -1,56 +1,58 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef nsTypedSelection_h
-#define nsTypedSelection_h
+#ifndef mozilla_Selection_h__
+#define mozilla_Selection_h__
 
 #include "nsIWeakReference.h"
 
 #include "nsISelection.h"
 #include "nsISelectionController.h"
 #include "nsISelectionPrivate.h"
 #include "nsRange.h"
 
 struct CachedOffsetForFrame;
 class nsAutoScrollTimer;
 class nsIContentIterator;
 class nsIFrame;
 struct SelectionDetails;
+class nsSelectionIterator;
 
 struct RangeData
 {
   RangeData(nsRange* aRange)
     : mRange(aRange)
   {}
 
   nsRefPtr<nsRange> mRange;
   nsTextRangeStyle mTextRangeStyle;
 };
 
-// Note, the ownership of nsTypedSelection depends on which way the object is
-// created. When nsFrameSelection has created nsTypedSelection,
-// addreffing/releasing nsTypedSelection object is aggregated to
-// nsFrameSelection. Otherwise normal addref/release is used.
-// This ensures that nsFrameSelection is never deleted before its
-// nsTypedSelections.
-class nsTypedSelection : public nsISelectionPrivate,
-                         public nsSupportsWeakReference
+// Note, the ownership of mozilla::Selection depends on which way the object is
+// created. When nsFrameSelection has created Selection, addreffing/releasing
+// the Selection object is aggregated to nsFrameSelection. Otherwise normal
+// addref/release is used.  This ensures that nsFrameSelection is never deleted
+// before its Selections.
+namespace mozilla {
+
+class Selection : public nsISelectionPrivate,
+                  public nsSupportsWeakReference
 {
 public:
-  nsTypedSelection();
-  nsTypedSelection(nsFrameSelection *aList);
-  virtual ~nsTypedSelection();
+  Selection();
+  Selection(nsFrameSelection *aList);
+  virtual ~Selection();
   
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTypedSelection, nsISelectionPrivate)
+  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(Selection, nsISelectionPrivate)
   NS_DECL_NSISELECTION
   NS_DECL_NSISELECTIONPRIVATE
 
   // utility methods for scrolling the selection into view
   nsresult      GetPresContext(nsPresContext **aPresContext);
   nsresult      GetPresShell(nsIPresShell **aPresShell);
   // Returns a rect containing the selection region, and frame that that
   // position is relative to. For SELECTION_ANCHOR_REGION or
@@ -122,51 +124,51 @@ public:
   // Note: StartAutoScrollTimer might destroy arbitrary frames etc.
   nsresult     StartAutoScrollTimer(nsIFrame *aFrame,
                                     nsPoint& aPoint,
                                     PRUint32 aDelay);
 
   nsresult     StopAutoScrollTimer();
 
 private:
-  friend class nsAutoScrollTimer;
+  friend class ::nsAutoScrollTimer;
 
   // Note: DoAutoScroll might destroy arbitrary frames etc.
   nsresult DoAutoScroll(nsIFrame *aFrame, nsPoint& aPoint);
 
 public:
   SelectionType GetType(){return mType;}
   void          SetType(SelectionType aType){mType = aType;}
 
   nsresult     NotifySelectionListeners();
 
 private:
-  friend class nsSelectionIterator;
+  friend class ::nsSelectionIterator;
 
   class ScrollSelectionIntoViewEvent;
   friend class ScrollSelectionIntoViewEvent;
 
   class ScrollSelectionIntoViewEvent : public nsRunnable {
   public:
     NS_DECL_NSIRUNNABLE
-    ScrollSelectionIntoViewEvent(nsTypedSelection *aTypedSelection,
+    ScrollSelectionIntoViewEvent(Selection* aSelection,
                                  SelectionRegion aRegion,
                                  nsIPresShell::ScrollAxis aVertical,
                                  nsIPresShell::ScrollAxis aHorizontal,
                                  bool aFirstAncestorOnly)
-      : mTypedSelection(aTypedSelection),
+      : mSelection(aSelection),
         mRegion(aRegion),
         mVerticalScroll(aVertical),
         mHorizontalScroll(aHorizontal),
         mFirstAncestorOnly(aFirstAncestorOnly) {
-      NS_ASSERTION(aTypedSelection, "null parameter");
+      NS_ASSERTION(aSelection, "null parameter");
     }
-    void Revoke() { mTypedSelection = nsnull; }
+    void Revoke() { mSelection = nsnull; }
   private:
-    nsTypedSelection *mTypedSelection;
+    Selection *mSelection;
     SelectionRegion mRegion;
     nsIPresShell::ScrollAxis mVerticalScroll;
     nsIPresShell::ScrollAxis mHorizontalScroll;
     bool mFirstAncestorOnly;
   };
 
   void setAnchorFocusRange(PRInt32 aIndex); // pass in index into mRanges;
                                             // negative value clears
@@ -213,9 +215,11 @@ private:
   nsRefPtr<nsAutoScrollTimer> mAutoScrollTimer;
   nsCOMArray<nsISelectionListener> mSelectionListeners;
   nsRevocableEventPtr<ScrollSelectionIntoViewEvent> mScrollEvent;
   CachedOffsetForFrame *mCachedOffsetForFrame;
   nsDirection mDirection;
   SelectionType mType;
 };
 
-#endif // nsTypedSelection_h
+} // namespace mozilla
+
+#endif // mozilla_Selection_h__
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -168,17 +168,19 @@ struct nsPrevNextBidiLevels
     mLevelAfter = aLevelAfter;
   }
   nsIFrame* mFrameBefore;
   nsIFrame* mFrameAfter;
   PRUint8 mLevelBefore;
   PRUint8 mLevelAfter;
 };
 
-class nsTypedSelection;
+namespace mozilla {
+class Selection;
+}
 class nsIScrollableFrame;
 
 /**
  * Methods which are marked with *unsafe* should be handled with special care.
  * They may cause nsFrameSelection to be deleted, if strong pointer isn't used,
  * or they may cause other objects to be deleted.
  */
 
@@ -346,17 +348,17 @@ public:
    */
   bool GetTableCellSelection() const { return mSelectingTableCellMode != 0; }
   void ClearTableCellSelection() { mSelectingTableCellMode = 0; }
 
   /** GetSelection
    * no query interface for selection. must use this method now.
    * @param aSelectionType enum value defined in nsISelection for the seleciton you want.
    */
-  nsTypedSelection* GetSelection(SelectionType aType) const;
+  mozilla::Selection* GetSelection(SelectionType aType) const;
 
   /**
    * ScrollSelectionIntoView scrolls a region of the selection,
    * so that it is visible in the scrolled view.
    *
    * @param aType the selection to scroll into view.
    * @param aRegion the region inside the selection to scroll into view.
    * @param aFlags the scroll flags.  Valid bits include:
@@ -613,17 +615,17 @@ private:
   void    PostReason(PRInt16 aReason) { mSelectionChangeReason = aReason; }
   PRInt16 PopReason()
   {
     PRInt16 retval = mSelectionChangeReason;
     mSelectionChangeReason = 0;
     return retval;
   }
 
-  friend class nsTypedSelection; 
+  friend class mozilla::Selection;
 #ifdef DEBUG
   void printSelection();       // for debugging
 #endif /* DEBUG */
 
   void ResizeBuffer(PRUint32 aNewBufSize);
 /*HELPER METHODS*/
   nsresult     MoveCaret(PRUint32 aKeycode, bool aContinueSelection,
                          nsSelectionAmount aAmount);
@@ -640,17 +642,17 @@ private:
   PRUint32     GetBatching() const {return mBatching; }
   bool         GetNotifyFrames() const { return mNotifyFrames; }
   void         SetDirty(bool aDirty=true){if (mBatching) mChangesDuringBatching = aDirty;}
 
   // nsFrameSelection may get deleted when calling this,
   // so remember to use nsCOMPtr when needed.
   nsresult     NotifySelectionListeners(SelectionType aType);     // add parameters to say collapsed etc?
 
-  nsRefPtr<nsTypedSelection> mDomSelections[nsISelectionController::NUM_SELECTIONTYPES];
+  nsRefPtr<mozilla::Selection> mDomSelections[nsISelectionController::NUM_SELECTIONTYPES];
 
   // Table selection support.
   // Interfaces that let us get info based on cellmap locations
   nsITableLayout* GetTableLayout(nsIContent *aTableContent) const;
   nsITableCellLayout* GetCellLayout(nsIContent *aCellContent) const;
 
   nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode);
   nsresult SelectRowOrColumn(nsIContent *aCellContent, PRUint32 aTarget);
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Implementation of selection: nsISelection,nsISelectionPrivate and nsFrameSelection
  */
 
-#include "nsTypedSelection.h"
+#include "mozilla/Selection.h"
 
 #include "mozilla/Attributes.h"
 
 #include "nsCOMPtr.h"
 #include "nsWeakReference.h"
 #include "nsIFactory.h"
 #include "nsIEnumerator.h"
 #include "nsString.h"
@@ -158,25 +158,25 @@ see the nsIEnumerator for more details*/
 
   NS_DECL_NSIBIDIRECTIONALENUMERATOR
 
 /*END nsIEnumerator interfaces*/
 /*BEGIN Helper Methods*/
   nsRange* CurrentItem();
 /*END Helper Methods*/
 private:
-  friend class nsTypedSelection;
+  friend class mozilla::Selection;
 
   //lame lame lame if delete from document goes away then get rid of this unless its debug
   friend class nsFrameSelection;
 
-  nsSelectionIterator(nsTypedSelection *);
+  nsSelectionIterator(Selection*);
   virtual ~nsSelectionIterator();
   PRInt32     mIndex;
-  nsTypedSelection *mDomSelection;
+  Selection* mDomSelection;
   SelectionType mType;
 };
 
 class nsAutoScrollTimer : public nsITimerCallback
 {
 public:
 
   NS_DECL_ISUPPORTS
@@ -222,17 +222,17 @@ public:
       mTimer->Cancel();
       mTimer = 0;
     }
 
     mContent = nsnull;
     return NS_OK;
   }
 
-  nsresult Init(nsFrameSelection *aFrameSelection, nsTypedSelection *aSelection)
+  nsresult Init(nsFrameSelection* aFrameSelection, Selection* aSelection)
   {
     mFrameSelection = aFrameSelection;
     mSelection = aSelection;
     return NS_OK;
   }
 
   nsresult SetDelay(PRUint32 aDelay)
   {
@@ -258,30 +258,30 @@ public:
 
       NS_ASSERTION(frame->PresContext() == mPresContext, "document mismatch?");
       mSelection->DoAutoScroll(frame, pt);
     }
     return NS_OK;
   }
 private:
   nsFrameSelection *mFrameSelection;
-  nsTypedSelection *mSelection;
+  Selection* mSelection;
   nsPresContext *mPresContext;
   // relative to mPresContext's root frame
   nsPoint mPoint;
   nsCOMPtr<nsITimer> mTimer;
   nsCOMPtr<nsIContent> mContent;
   PRUint32 mDelay;
 };
 
 NS_IMPL_ISUPPORTS1(nsAutoScrollTimer, nsITimerCallback)
 
 nsresult NS_NewDomSelection(nsISelection **aDomSelection)
 {
-  nsTypedSelection *rlist = new nsTypedSelection;
+  Selection* rlist = new Selection;
   *aDomSelection = (nsISelection *)rlist;
   NS_ADDREF(rlist);
   return NS_OK;
 }
 
 static PRInt8
 GetIndexFromSelectionType(SelectionType aType)
 {
@@ -360,17 +360,17 @@ NS_IMPL_RELEASE(nsSelectionIterator)
 NS_INTERFACE_MAP_BEGIN(nsSelectionIterator)
   NS_INTERFACE_MAP_ENTRY(nsIEnumerator)
   NS_INTERFACE_MAP_ENTRY(nsIBidirectionalEnumerator)
 NS_INTERFACE_MAP_END_AGGREGATED(mDomSelection)
 
 
 ///////////BEGIN nsSelectionIterator methods
 
-nsSelectionIterator::nsSelectionIterator(nsTypedSelection *aList)
+nsSelectionIterator::nsSelectionIterator(Selection* aList)
 :mIndex(0)
 {
   if (!aList)
   {
     NS_NOTREACHED("nsFrameSelection");
     return;
   }
   mDomSelection = aList;
@@ -470,17 +470,17 @@ nsSelectionIterator::IsDone()
 
 
 ////////////BEGIN nsFrameSelection methods
 
 nsFrameSelection::nsFrameSelection()
 {
   PRInt32 i;
   for (i = 0;i<nsISelectionController::NUM_SELECTIONTYPES;i++){
-    mDomSelections[i] = new nsTypedSelection(this);
+    mDomSelections[i] = new Selection(this);
     mDomSelections[i]->SetType(GetSelectionTypeFromIndex(i));
   }
   mBatching = 0;
   mChangesDuringBatching = false;
   mNotifyFrames = true;
   mLimiter = nsnull; //no default limiter.
   mAncestorLimiter = nsnull;
   
@@ -897,17 +897,17 @@ nsFrameSelection::MoveCaret(PRUint32    
   nsPresContext *context = mShell->GetPresContext();
   if (!context)
     return NS_ERROR_FAILURE;
 
   bool isCollapsed;
   nscoord desiredX = 0; //we must keep this around and revalidate it when its just UP/DOWN
 
   PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
-  nsRefPtr<nsTypedSelection> sel = mDomSelections[index];
+  nsRefPtr<Selection> sel = mDomSelections[index];
   if (!sel)
     return NS_ERROR_NULL_POINTER;
 
   nsresult result = sel->GetIsCollapsed(&isCollapsed);
   if (NS_FAILED(result))
     return result;
   if (aKeycode == nsIDOMKeyEvent::DOM_VK_UP ||
       aKeycode == nsIDOMKeyEvent::DOM_VK_DOWN)
@@ -1082,17 +1082,17 @@ nsFrameSelection::MoveCaret(PRUint32    
 }
 
 //END nsFrameSelection methods
 
 
 //BEGIN nsFrameSelection methods
 
 NS_IMETHODIMP
-nsTypedSelection::ToString(nsAString& aReturn)
+Selection::ToString(nsAString& aReturn)
 {
   // We need Flush_Style here to make sure frames have been created for
   // the selected content.  Use mFrameSelection->GetShell() which returns
   // null if the Selection has been disconnected (the shell is Destroyed).
   nsCOMPtr<nsIPresShell> shell =
     mFrameSelection ? mFrameSelection->GetShell() : nsnull;
   if (!shell) {
     aReturn.Truncate();
@@ -1101,18 +1101,18 @@ nsTypedSelection::ToString(nsAString& aR
   shell->FlushPendingNotifications(Flush_Style);
 
   return ToStringWithFormat("text/plain",
                             nsIDocumentEncoder::SkipInvisibleContent,
                             0, aReturn);
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags,
-                                     PRInt32 aWrapCol, nsAString& aReturn)
+Selection::ToStringWithFormat(const char* aFormatType, PRUint32 aFlags,
+                              PRInt32 aWrapCol, nsAString& aReturn)
 {
   nsresult rv = NS_OK;
   nsCAutoString formatType( NS_DOC_ENCODER_CONTRACTID_BASE );
   formatType.Append(aFormatType);
   nsCOMPtr<nsIDocumentEncoder> encoder =
            do_CreateInstance(formatType.get(), &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1138,32 +1138,32 @@ nsTypedSelection::ToStringWithFormat(con
   encoder->SetSelection(this);
   if (aWrapCol != 0)
     encoder->SetWrapColumn(aWrapCol);
 
   return encoder->EncodeToString(aReturn);
 }
 
 NS_IMETHODIMP
-nsTypedSelection::SetInterlinePosition(bool aHintRight)
+Selection::SetInterlinePosition(bool aHintRight)
 {
   if (!mFrameSelection)
     return NS_ERROR_NOT_INITIALIZED; // Can't do selection
   nsFrameSelection::HINT hint;
   if (aHintRight)
     hint = nsFrameSelection::HINTRIGHT;
   else
     hint = nsFrameSelection::HINTLEFT;
   mFrameSelection->SetHint(hint);
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetInterlinePosition(bool *aHintRight)
+Selection::GetInterlinePosition(bool* aHintRight)
 {
   if (!mFrameSelection)
     return NS_ERROR_NOT_INITIALIZED; // Can't do selection
   *aHintRight = (mFrameSelection->GetHint() == nsFrameSelection::HINTRIGHT);
   return NS_OK;
 }
 
 nsPrevNextBidiLevels
@@ -1717,17 +1717,17 @@ nsFrameSelection::SetMouseDownState(bool
   if (!mMouseDownState)
   {
     mDragSelectingCells = false;
     PostReason(nsISelectionListener::MOUSEUP_REASON);
     NotifySelectionListeners(nsISelectionController::SELECTION_NORMAL); //notify that reason is mouse up please.
   }
 }
 
-nsTypedSelection*
+Selection*
 nsFrameSelection::GetSelection(SelectionType aType) const
 {
   PRInt8 index = GetIndexFromSelectionType(aType);
   if (index < 0)
     return nsnull;
 
   return mDomSelections[index];
 }
@@ -1740,21 +1740,21 @@ nsFrameSelection::ScrollSelectionIntoVie
   PRInt8 index = GetIndexFromSelectionType(aType);
   if (index < 0)
     return NS_ERROR_INVALID_ARG;
 
   if (!mDomSelections[index])
     return NS_ERROR_NULL_POINTER;
 
   nsIPresShell::ScrollAxis verticalScroll = nsIPresShell::ScrollAxis();
-  PRInt32 flags = nsTypedSelection::SCROLL_DO_FLUSH;
+  PRInt32 flags = Selection::SCROLL_DO_FLUSH;
   if (aFlags & nsISelectionController::SCROLL_SYNCHRONOUS) {
-    flags |= nsTypedSelection::SCROLL_SYNCHRONOUS;
+    flags |= Selection::SCROLL_SYNCHRONOUS;
   } else if (aFlags & nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY) {
-    flags |= nsTypedSelection::SCROLL_FIRST_ANCESTOR_ONLY;
+    flags |= Selection::SCROLL_FIRST_ANCESTOR_ONLY;
   }
   if (aFlags & nsISelectionController::SCROLL_CENTER_VERTICALLY) {
     verticalScroll = nsIPresShell::ScrollAxis(
       nsIPresShell::SCROLL_CENTER, nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE);
   }
 
   // After ScrollSelectionIntoView(), the pending notifications might be
   // flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
@@ -2869,17 +2869,19 @@ nsFrameSelection::SelectCellElement(nsIC
 
   // Get child offset
   PRInt32 offset = parent->IndexOf(aCellElement);
 
   return CreateAndAddRange(parent, offset);
 }
 
 nsresult
-nsTypedSelection::getTableCellLocationFromRange(nsRange *aRange, PRInt32 *aSelectionType, PRInt32 *aRow, PRInt32 *aCol)
+Selection::getTableCellLocationFromRange(nsRange* aRange,
+                                         PRInt32* aSelectionType,
+                                         PRInt32* aRow, PRInt32* aCol)
 {
   if (!aRange || !aSelectionType || !aRow || !aCol)
     return NS_ERROR_NULL_POINTER;
 
   *aSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
   *aRow = 0;
   *aCol = 0;
 
@@ -2911,18 +2913,18 @@ nsTypedSelection::getTableCellLocationFr
     return result;
   if (!cellLayout)
     return NS_ERROR_FAILURE;
 
   return cellLayout->GetCellIndexes(*aRow, *aCol);
 }
 
 nsresult
-nsTypedSelection::addTableCellRange(nsRange *aRange, bool *aDidAddRange,
-                                    PRInt32 *aOutIndex)
+Selection::addTableCellRange(nsRange* aRange, bool* aDidAddRange,
+                             PRInt32* aOutIndex)
 {  
   if (!aDidAddRange || !aOutIndex)
     return NS_ERROR_NULL_POINTER;
 
   *aDidAddRange = false;
   *aOutIndex = -1;
 
   if (!mFrameSelection)
@@ -2952,18 +2954,18 @@ nsTypedSelection::addTableCellRange(nsRa
     mFrameSelection->mSelectingTableCellMode = tableMode;
 
   *aDidAddRange = true;
   return AddItem(aRange, aOutIndex);
 }
 
 //TODO: Figure out TABLESELECTION_COLUMN and TABLESELECTION_ALLCELLS
 nsresult
-nsTypedSelection::GetTableSelectionType(nsIDOMRange* aDOMRange,
-                                        PRInt32* aTableSelectionType)
+Selection::GetTableSelectionType(nsIDOMRange* aDOMRange,
+                                 PRInt32* aTableSelectionType)
 {
   if (!aDOMRange || !aTableSelectionType)
     return NS_ERROR_NULL_POINTER;
   nsRange* range = static_cast<nsRange*>(aDOMRange);
   
   *aTableSelectionType = nsISelectionPrivate::TABLESELECTION_NONE;
  
   // Must have access to frame selection to get cell info
@@ -3134,36 +3136,36 @@ nsFrameSelection::DisconnectFromPresShel
 }
 
 //END nsISelection interface implementations
 
 #if 0
 #pragma mark -
 #endif
 
-// nsTypedSelection implementation
+// mozilla::Selection implementation
 
 // note: this can return a nil anchor node
 
-nsTypedSelection::nsTypedSelection()
+Selection::Selection()
   : mCachedOffsetForFrame(nsnull)
   , mDirection(eDirNext)
   , mType(nsISelectionController::SELECTION_NORMAL)
 {
 }
 
-nsTypedSelection::nsTypedSelection(nsFrameSelection *aList)
+Selection::Selection(nsFrameSelection* aList)
   : mFrameSelection(aList)
   , mCachedOffsetForFrame(nsnull)
   , mDirection(eDirNext)
   , mType(nsISelectionController::SELECTION_NORMAL)
 {
 }
 
-nsTypedSelection::~nsTypedSelection()
+Selection::~Selection()
 {
   setAnchorFocusRange(-1);
 
   PRUint32 count = mRanges.Length();
   for (PRUint32 i = 0; i < count; ++i) {
     mRanges[i].mRange->SetInSelection(false);
   }
 
@@ -3176,152 +3178,154 @@ nsTypedSelection::~nsTypedSelection()
 
   if (mCachedOffsetForFrame) {
     delete mCachedOffsetForFrame;
     mCachedOffsetForFrame = nsnull;
   }
 }
 
 
-NS_IMPL_CYCLE_COLLECTION_CLASS(nsTypedSelection)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsTypedSelection)
+NS_IMPL_CYCLE_COLLECTION_CLASS(Selection)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Selection)
   // Unlink the selection listeners *before* we do RemoveAllRanges since
   // we don't want to notify the listeners during JS GC (they could be
   // in JS!).
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mSelectionListeners)
   tmp->RemoveAllRanges();
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFrameSelection)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTypedSelection)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Selection)
   {
     PRUint32 i, count = tmp->mRanges.Length();
     for (i = 0; i < count; ++i) {
       NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRanges[i].mRange, nsIDOMRange)
     }
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mAnchorFocusRange, nsIDOMRange)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameSelection)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mSelectionListeners)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-DOMCI_DATA(Selection, nsTypedSelection)
-
-// QueryInterface implementation for nsTypedSelection
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTypedSelection)
+DOMCI_DATA(Selection, Selection)
+
+// QueryInterface implementation for Selection
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Selection)
   NS_INTERFACE_MAP_ENTRY(nsISelection)
   NS_INTERFACE_MAP_ENTRY(nsISelectionPrivate)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelection)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Selection)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTypedSelection)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTypedSelection)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(Selection)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(Selection)
 
 NS_IMETHODIMP
-nsTypedSelection::SetPresShell(nsIPresShell *aPresShell)
+Selection::SetPresShell(nsIPresShell* aPresShell)
 {
   mPresShellWeak = do_GetWeakReference(aPresShell);
   return NS_OK;
 }
 
 
 
 NS_IMETHODIMP
-nsTypedSelection::GetAnchorNode(nsIDOMNode** aAnchorNode)
+Selection::GetAnchorNode(nsIDOMNode** aAnchorNode)
 {
   nsINode* anchorNode = GetAnchorNode();
   if (anchorNode) {
     return CallQueryInterface(anchorNode, aAnchorNode);
   }
 
   *aAnchorNode = nsnull;
   return NS_OK;
 }
 
 nsINode*
-nsTypedSelection::GetAnchorNode()
+Selection::GetAnchorNode()
 {
   if (!mAnchorFocusRange)
     return nsnull;
    
   if (GetDirection() == eDirNext) {
     return mAnchorFocusRange->GetStartParent();
   }
 
   return mAnchorFocusRange->GetEndParent();
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetAnchorOffset(PRInt32* aAnchorOffset)
+Selection::GetAnchorOffset(PRInt32* aAnchorOffset)
 {
   *aAnchorOffset = GetAnchorOffset();
   return NS_OK;
 }
 
 // note: this can return a nil focus node
 NS_IMETHODIMP
-nsTypedSelection::GetFocusNode(nsIDOMNode** aFocusNode)
+Selection::GetFocusNode(nsIDOMNode** aFocusNode)
 {
   nsINode* focusNode = GetFocusNode();
   if (focusNode) {
     return CallQueryInterface(focusNode, aFocusNode);
   }
 
   *aFocusNode = nsnull;
   return NS_OK;
 }
 
 nsINode*
-nsTypedSelection::GetFocusNode()
+Selection::GetFocusNode()
 {
   if (!mAnchorFocusRange)
     return nsnull;
 
   if (GetDirection() == eDirNext){
     return mAnchorFocusRange->GetEndParent();
   }
 
   return mAnchorFocusRange->GetStartParent();
 }
 
-NS_IMETHODIMP nsTypedSelection::GetFocusOffset(PRInt32* aFocusOffset)
+NS_IMETHODIMP
+Selection::GetFocusOffset(PRInt32* aFocusOffset)
 {
   *aFocusOffset = GetFocusOffset();
   return NS_OK;
 }
 
-void nsTypedSelection::setAnchorFocusRange(PRInt32 indx)
+void
+Selection::setAnchorFocusRange(PRInt32 indx)
 {
   if (indx >= (PRInt32)mRanges.Length())
     return;
   if (indx < 0) //release all
   {
     mAnchorFocusRange = nsnull;
   }
   else{
     mAnchorFocusRange = mRanges[indx].mRange;
   }
 }
 
 PRInt32
-nsTypedSelection::GetAnchorOffset()
+Selection::GetAnchorOffset()
 {
   if (!mAnchorFocusRange)
     return 0;
 
   if (GetDirection() == eDirNext){
     return mAnchorFocusRange->StartOffset();
   }
 
   return mAnchorFocusRange->EndOffset();
 }
 
 PRInt32
-nsTypedSelection::GetFocusOffset()
+Selection::GetFocusOffset()
 {
   if (!mAnchorFocusRange)
     return 0;
 
   if (GetDirection() == eDirNext){
     return mAnchorFocusRange->EndOffset();
   }
 
@@ -3359,27 +3363,27 @@ CompareToRangeEnd(nsINode* aCompareNode,
     *aCmp = 1;
   } else {
     *aCmp = nsContentUtils::ComparePoints(aCompareNode, aCompareOffset,
                                           end, aRange->EndOffset());
   }
   return NS_OK;
 }
 
-// nsTypedSelection::FindInsertionPoint
+// Selection::FindInsertionPoint
 //
 //    Binary searches the given sorted array of ranges for the insertion point
 //    for the given node/offset. The given comparator is used, and the index
 //    where the point should appear in the array is placed in *aInsertionPoint.
 //
 //    If there is an item in the array equal to the input point, we will return
 //    the index of this item.
 
 nsresult
-nsTypedSelection::FindInsertionPoint(
+Selection::FindInsertionPoint(
     nsTArray<RangeData>* aElementArray,
     nsINode* aPointNode, PRInt32 aPointOffset,
     nsresult (*aComparator)(nsINode*,PRInt32,nsRange*,PRInt32*),
     PRInt32* aPoint)
 {
   *aPoint = 0;
   PRInt32 beginSearch = 0;
   PRInt32 endSearch = aElementArray->Length(); // one beyond what to check
@@ -3400,26 +3404,26 @@ nsTypedSelection::FindInsertionPoint(
       beginSearch = center;
       break;
     }
   }
   *aPoint = beginSearch;
   return NS_OK;
 }
 
-// nsTypedSelection::SubtractRange
+// Selection::SubtractRange
 //
 //    A helper function that subtracts aSubtract from aRange, and adds
 //    1 or 2 RangeData objects representing the remaining non-overlapping
 //    difference to aOutput. It is assumed that the caller has checked that
 //    aRange and aSubtract do indeed overlap
 
 nsresult
-nsTypedSelection::SubtractRange(RangeData* aRange, nsRange* aSubtract,
-                                nsTArray<RangeData>* aOutput)
+Selection::SubtractRange(RangeData* aRange, nsRange* aSubtract,
+                         nsTArray<RangeData>* aOutput)
 {
   nsRange* range = aRange->mRange;
 
   // First we want to compare to the range start
   PRInt32 cmp;
   nsresult rv = CompareToRangeStart(range->GetStartParent(),
                                     range->StartOffset(),
                                     aSubtract, &cmp);
@@ -3473,17 +3477,17 @@ nsTypedSelection::SubtractRange(RangeDat
       (*aOutput)[0].mTextRangeStyle = aRange->mTextRangeStyle;
     }
   }
 
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::AddItem(nsRange *aItem, PRInt32 *aOutIndex)
+Selection::AddItem(nsRange* aItem, PRInt32* aOutIndex)
 {
   if (!aItem)
     return NS_ERROR_NULL_POINTER;
   if (!aItem->IsPositioned())
     return NS_ERROR_UNEXPECTED;
   if (aOutIndex)
     *aOutIndex = -1;
 
@@ -3582,17 +3586,17 @@ nsTypedSelection::AddItem(nsRange *aItem
     temp[i].mRange->SetInSelection(true);
   }
 
   *aOutIndex = startIndex + insertionPoint;
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::RemoveItem(nsRange *aItem)
+Selection::RemoveItem(nsRange* aItem)
 {
   if (!aItem)
     return NS_ERROR_NULL_POINTER;
 
   // Find the range's index & remove it. We could use FindInsertionPoint to
   // get O(log n) time, but that requires many expensive DOM comparisons.
   // For even several thousand items, this is probably faster because the
   // comparisons are so fast.
@@ -3608,32 +3612,32 @@ nsTypedSelection::RemoveItem(nsRange *aI
     return NS_ERROR_INVALID_ARG;
 
   mRanges.RemoveElementAt(idx);
   aItem->SetInSelection(false);
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::RemoveCollapsedRanges()
+Selection::RemoveCollapsedRanges()
 {
   PRUint32 i = 0;
   while (i < mRanges.Length()) {
     if (mRanges[i].mRange->Collapsed()) {
       nsresult rv = RemoveItem(mRanges[i].mRange);
       NS_ENSURE_SUCCESS(rv, rv);
     } else {
       ++i;
     }
   }
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::Clear(nsPresContext* aPresContext)
+Selection::Clear(nsPresContext* aPresContext)
 {
   setAnchorFocusRange(-1);
 
   for (PRUint32 i = 0; i < mRanges.Length(); ++i) {
     mRanges[i].mRange->SetInSelection(false);
     selectFrames(aPresContext, mRanges[i].mRange, false);
   }
   mRanges.Clear();
@@ -3647,17 +3651,17 @@ nsTypedSelection::Clear(nsPresContext* a
       nsISelectionController::SELECTION_ATTENTION) {
     mFrameSelection->SetDisplaySelection(nsISelectionController::SELECTION_ON);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetType(PRInt16 *aType)
+Selection::GetType(PRInt16* aType)
 {
   NS_ENSURE_ARG_POINTER(aType);
   *aType = mType;
 
   return NS_OK;
 }
 
 // RangeMatches*Point
@@ -3672,45 +3676,45 @@ RangeMatchesBeginPoint(nsRange* aRange, 
 }
 
 static inline bool
 RangeMatchesEndPoint(nsRange* aRange, nsINode* aNode, PRInt32 aOffset)
 {
   return aRange->GetEndParent() == aNode && aRange->EndOffset() == aOffset;
 }
 
-// nsTypedSelection::EqualsRangeAtPoint
+// Selection::EqualsRangeAtPoint
 //
 //    Utility method for checking equivalence of two ranges.
 
 bool
-nsTypedSelection::EqualsRangeAtPoint(
+Selection::EqualsRangeAtPoint(
     nsINode* aBeginNode, PRInt32 aBeginOffset,
     nsINode* aEndNode, PRInt32 aEndOffset,
     PRInt32 aRangeIndex)
 {
   if (aRangeIndex >=0 && aRangeIndex < (PRInt32) mRanges.Length()) {
     nsRange* range = mRanges[aRangeIndex].mRange;
     if (RangeMatchesBeginPoint(range, aBeginNode, aBeginOffset) &&
         RangeMatchesEndPoint(range, aEndNode, aEndOffset))
       return true;
   }
   return false;
 }
 
-// nsTypedSelection::GetRangesForInterval
+// Selection::GetRangesForInterval
 //
 //    XPCOM wrapper for the nsTArray version
 
 NS_IMETHODIMP
-nsTypedSelection::GetRangesForInterval(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
-                                       nsIDOMNode* aEndNode, PRInt32 aEndOffset,
-                                       bool aAllowAdjacent,
-                                       PRUint32 *aResultCount,
-                                       nsIDOMRange ***aResults)
+Selection::GetRangesForInterval(nsIDOMNode* aBeginNode, PRInt32 aBeginOffset,
+                                nsIDOMNode* aEndNode, PRInt32 aEndOffset,
+                                bool aAllowAdjacent,
+                                PRUint32* aResultCount,
+                                nsIDOMRange*** aResults)
 {
   if (!aBeginNode || ! aEndNode || ! aResultCount || ! aResults)
     return NS_ERROR_NULL_POINTER;
 
   *aResultCount = 0;
   *aResults = nsnull;
   
   nsCOMPtr<nsINode> beginNode = do_QueryInterface(aBeginNode);
@@ -3730,17 +3734,17 @@ nsTypedSelection::GetRangesForInterval(n
                          (nsMemory::Alloc(sizeof(nsIDOMRange*) * *aResultCount));
   NS_ENSURE_TRUE(*aResults, NS_ERROR_OUT_OF_MEMORY);
 
   for (PRUint32 i = 0; i < *aResultCount; i++)
     NS_ADDREF((*aResults)[i] = results[i]);
   return NS_OK;
 }
 
-// nsTypedSelection::GetRangesForIntervalArray
+// Selection::GetRangesForIntervalArray
 //
 //    Fills a nsTArray with the ranges overlapping the range specified by
 //    the given endpoints. Ranges in the selection exactly adjacent to the
 //    input range are not returned unless aAllowAdjacent is set.
 //
 //    For example, if the following ranges were in the selection
 //    (assume everything is within the same node)
 //
@@ -3751,49 +3755,47 @@ nsTypedSelection::GetRangesForInterval(n
 //    aAllowAdjacent set, all the ranges should be returned. If
 //    aAllowAdjacent was false, the ranges [2, 5] and [7, 9] only
 //    should be returned
 //
 //    Now that overlapping ranges are disallowed, there can be a maximum of
 //    2 adjacent ranges
 
 nsresult
-nsTypedSelection::GetRangesForIntervalArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
-                                            nsINode* aEndNode, PRInt32 aEndOffset,
-                                            bool aAllowAdjacent,
-                                            nsTArray<nsRange*>* aRanges)
+Selection::GetRangesForIntervalArray(nsINode* aBeginNode, PRInt32 aBeginOffset,
+                                     nsINode* aEndNode, PRInt32 aEndOffset,
+                                     bool aAllowAdjacent,
+                                     nsTArray<nsRange*>* aRanges)
 {
   aRanges->Clear();
   PRInt32 startIndex, endIndex;
   GetIndicesForInterval(aBeginNode, aBeginOffset, aEndNode, aEndOffset,
                         aAllowAdjacent, &startIndex, &endIndex);
   if (startIndex == -1 || endIndex == -1)
     return NS_OK;
 
   for (PRInt32 i = startIndex; i < endIndex; i++) {
     if (!aRanges->AppendElement(mRanges[i].mRange))
       return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
-// nsTypedSelection::GetIndicesForInterval
+// Selection::GetIndicesForInterval
 //
 //    Works on the same principle as GetRangesForIntervalArray above, however
 //    instead this returns the indices into mRanges between which the
 //    overlapping ranges lie.
 
 void
-nsTypedSelection::GetIndicesForInterval(nsINode* aBeginNode,
-                                        PRInt32 aBeginOffset,
-                                        nsINode* aEndNode, PRInt32 aEndOffset,
-                                        bool aAllowAdjacent,
-                                        PRInt32 *aStartIndex,
-                                        PRInt32 *aEndIndex)
+Selection::GetIndicesForInterval(nsINode* aBeginNode, PRInt32 aBeginOffset,
+                                 nsINode* aEndNode, PRInt32 aEndOffset,
+                                 bool aAllowAdjacent,
+                                 PRInt32* aStartIndex, PRInt32* aEndIndex)
 {
   PRInt32 startIndex;
   PRInt32 endIndex;
 
   if (!aStartIndex)
     aStartIndex = &startIndex;
   if (!aEndIndex)
     aEndIndex = &endIndex;
@@ -3901,67 +3903,18 @@ nsTypedSelection::GetIndicesForInterval(
      }
   }
 
   *aStartIndex = beginsAfterIndex;
   *aEndIndex = endsBeforeIndex;
   return;
 }
 
-//utility method to get the primary frame of node or use the offset to get frame of child node
-
-#if 0
 NS_IMETHODIMP
-nsTypedSelection::GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, PRInt32 aOffset, bool aIsEndNode, nsIFrame **aReturnFrame)
-{
-  if (!aNode || !aReturnFrame || !mFrameSelection)
-    return NS_ERROR_NULL_POINTER;
-  
-  if (aOffset < 0)
-    return NS_ERROR_FAILURE;
-
-  *aReturnFrame = 0;
-  
-  nsresult  result = NS_OK;
-  
-  nsCOMPtr<nsIDOMNode> node = aNode;
-
-  if (!node)
-    return NS_ERROR_NULL_POINTER;
-  
-  nsCOMPtr<nsIContent> content = do_QueryInterface(node, &result);
-
-  if (NS_FAILED(result))
-    return result;
-
-  if (!content)
-    return NS_ERROR_NULL_POINTER;
-  
-  if (content->IsElement())
-  {
-    if (aIsEndNode)
-      aOffset--;
-
-    if (aOffset >= 0)
-    {
-      nsIContent *child = content->GetChildAt(aOffset);
-      if (!child) //out of bounds?
-        return NS_ERROR_FAILURE;
-
-      content = child; // releases the focusnode
-    }
-  }
-  *aReturnFrame = content->GetPrimaryFrame();
-  return NS_OK;
-}
-#endif
-
-
-NS_IMETHODIMP
-nsTypedSelection::GetPrimaryFrameForAnchorNode(nsIFrame **aReturnFrame)
+Selection::GetPrimaryFrameForAnchorNode(nsIFrame** aReturnFrame)
 {
   if (!aReturnFrame)
     return NS_ERROR_NULL_POINTER;
   
   PRInt32 frameOffset = 0;
   *aReturnFrame = 0;
   nsCOMPtr<nsIContent> content = do_QueryInterface(GetAnchorNode());
   if (content && mFrameSelection)
@@ -3971,18 +3924,19 @@ nsTypedSelection::GetPrimaryFrameForAnch
                             mFrameSelection->GetHint(), &frameOffset);
     if (*aReturnFrame)
       return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetPrimaryFrameForFocusNode(nsIFrame **aReturnFrame, PRInt32 *aOffsetUsed,
-                                              bool aVisual)
+Selection::GetPrimaryFrameForFocusNode(nsIFrame** aReturnFrame,
+                                       PRInt32* aOffsetUsed,
+                                       bool aVisual)
 {
   if (!aReturnFrame)
     return NS_ERROR_NULL_POINTER;
   
   nsCOMPtr<nsIContent> content = do_QueryInterface(GetFocusNode());
   if (!content || !mFrameSelection)
     return NS_ERROR_FAILURE;
   
@@ -4012,19 +3966,19 @@ nsTypedSelection::GetPrimaryFrameForFocu
   if (!*aReturnFrame)
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
 //select all content children of aContent
 nsresult
-nsTypedSelection::SelectAllFramesForContent(nsIContentIterator *aInnerIter,
-                                  nsIContent *aContent,
-                                  bool aSelected)
+Selection::SelectAllFramesForContent(nsIContentIterator* aInnerIter,
+                                     nsIContent* aContent,
+                                     bool aSelected)
 {
   nsresult result = aInnerIter->Init(aContent);
   nsIFrame *frame;
   if (NS_SUCCEEDED(result))
   {
     // First select frame of content passed in
     frame = aContent->GetPrimaryFrame();
     if (frame && frame->GetType() == nsGkAtoms::textFrame) {
@@ -4052,17 +4006,18 @@ nsTypedSelection::SelectAllFramesForCont
     return NS_OK;
   }
 
   return NS_ERROR_FAILURE;
 }
 
 //the idea of this helper method is to select, deselect "top to bottom" traversing through the frames
 nsresult
-nsTypedSelection::selectFrames(nsPresContext* aPresContext, nsRange* aRange, bool aFlags)
+Selection::selectFrames(nsPresContext* aPresContext, nsRange* aRange,
+                        bool aFlags)
 {
   if (!mFrameSelection || !aPresContext || !aPresContext->GetPresShell()) {
     return NS_OK; // nothing to do
   }
   if (!aRange) {
     return NS_ERROR_NULL_POINTER;
   }
 
@@ -4143,17 +4098,17 @@ nsTypedSelection::selectFrames(nsPresCon
         }
       }
     }
   }
   return result;
 }
 
 
-// nsTypedSelection::LookUpSelection
+// Selection::LookUpSelection
 //
 //    This function is called when a node wants to know where the selection is
 //    over itself.
 //
 //    Usually, this is called when we already know there is a selection over
 //    the node in question, and we only need to find the boundaries of it on
 //    that node. This is when slowCheck is false--a strict test is not needed.
 //    Other times, the caller has no idea, and wants us to test everything,
@@ -4168,20 +4123,20 @@ nsTypedSelection::selectFrames(nsPresCon
 //    PERFORMANCE: a common case is that we are doing a fast check with exactly
 //    one range in the selection. In this case, this function is slower than
 //    brute force because of the overhead of checking the tree. We can optimize
 //    this case to make it faster by doing the same thing the previous version
 //    of this function did in the case of 1 range. This would also mean that
 //    the aSlowCheck flag would have meaning again.
 
 NS_IMETHODIMP
-nsTypedSelection::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset,
-                                  PRInt32 aContentLength,
-                                  SelectionDetails **aReturnDetails,
-                                  SelectionType aType, bool aSlowCheck)
+Selection::LookUpSelection(nsIContent* aContent, PRInt32 aContentOffset,
+                           PRInt32 aContentLength,
+                           SelectionDetails** aReturnDetails,
+                           SelectionType aType, bool aSlowCheck)
 {
   nsresult rv;
   if (!aContent || ! aReturnDetails)
     return NS_ERROR_NULL_POINTER;
 
   // it is common to have no ranges, to optimize that
   if (mRanges.Length() == 0)
     return NS_OK;
@@ -4248,17 +4203,17 @@ nsTypedSelection::LookUpSelection(nsICon
       details->mTextRangeStyle = rd->mTextRangeStyle;
     }
     *aReturnDetails = details;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::Repaint(nsPresContext* aPresContext)
+Selection::Repaint(nsPresContext* aPresContext)
 {
   PRInt32 arrCount = (PRInt32)mRanges.Length();
 
   if (arrCount < 1)
     return NS_OK;
 
   PRInt32 i;
   
@@ -4270,30 +4225,30 @@ nsTypedSelection::Repaint(nsPresContext*
       return rv;
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetCanCacheFrameOffset(bool *aCanCacheFrameOffset)
+Selection::GetCanCacheFrameOffset(bool* aCanCacheFrameOffset)
 { 
   NS_ENSURE_ARG_POINTER(aCanCacheFrameOffset);
 
   if (mCachedOffsetForFrame)
     *aCanCacheFrameOffset = mCachedOffsetForFrame->mCanCacheFrameOffset;
   else
     *aCanCacheFrameOffset = false;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP    
-nsTypedSelection::SetCanCacheFrameOffset(bool aCanCacheFrameOffset)
+Selection::SetCanCacheFrameOffset(bool aCanCacheFrameOffset)
 {
   if (!mCachedOffsetForFrame) {
     mCachedOffsetForFrame = new CachedOffsetForFrame;
   }
 
   mCachedOffsetForFrame->mCanCacheFrameOffset = aCanCacheFrameOffset;
 
   // clean up cached frame when turn off cache
@@ -4301,17 +4256,18 @@ nsTypedSelection::SetCanCacheFrameOffset
   if (!aCanCacheFrameOffset) {
     mCachedOffsetForFrame->mLastCaretFrame = nsnull;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP    
-nsTypedSelection::GetCachedFrameOffset(nsIFrame *aFrame, PRInt32 inOffset, nsPoint& aPoint)
+Selection::GetCachedFrameOffset(nsIFrame* aFrame, PRInt32 inOffset,
+                                nsPoint& aPoint)
 {
   if (!mCachedOffsetForFrame) {
     mCachedOffsetForFrame = new CachedOffsetForFrame;
   }
 
   nsresult rv = NS_OK;
   if (mCachedOffsetForFrame->mCanCacheFrameOffset &&
       mCachedOffsetForFrame->mLastCaretFrame &&
@@ -4332,58 +4288,57 @@ nsTypedSelection::GetCachedFrameOffset(n
        mCachedOffsetForFrame->mLastContentOffset = inOffset; 
      }
   }
 
   return rv;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetFrameSelection(nsFrameSelection **aFrameSelection) {
+Selection::GetFrameSelection(nsFrameSelection** aFrameSelection) {
   NS_ENSURE_ARG_POINTER(aFrameSelection);
   *aFrameSelection = mFrameSelection;
   NS_IF_ADDREF(*aFrameSelection);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::SetAncestorLimiter(nsIContent *aContent)
+Selection::SetAncestorLimiter(nsIContent* aContent)
 {
   if (mFrameSelection)
     mFrameSelection->SetAncestorLimiter(aContent);
   return NS_OK;
 }
 
 RangeData*
-nsTypedSelection::FindRangeData(nsIDOMRange* aRange)
+Selection::FindRangeData(nsIDOMRange* aRange)
 {
   NS_ENSURE_TRUE(aRange, nsnull);
   for (PRUint32 i = 0; i < mRanges.Length(); i++) {
     if (mRanges[i].mRange == aRange)
       return &mRanges[i];
   }
   return nsnull;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::SetTextRangeStyle(nsIDOMRange *aRange,
-                                    const nsTextRangeStyle &aTextRangeStyle)
+Selection::SetTextRangeStyle(nsIDOMRange* aRange,
+                             const nsTextRangeStyle& aTextRangeStyle)
 {
   NS_ENSURE_ARG_POINTER(aRange);
   RangeData *rd = FindRangeData(aRange);
   if (rd) {
     rd->mTextRangeStyle = aTextRangeStyle;
   }
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::StartAutoScrollTimer(nsIFrame *aFrame,
-                                       nsPoint& aPoint,
-                                       PRUint32 aDelay)
+Selection::StartAutoScrollTimer(nsIFrame* aFrame, nsPoint& aPoint,
+                                PRUint32 aDelay)
 {
   NS_PRECONDITION(aFrame, "Need a frame");
 
   nsresult result;
   if (!mFrameSelection)
     return NS_OK;//nothing to do
 
   if (!mAutoScrollTimer)
@@ -4400,26 +4355,26 @@ nsTypedSelection::StartAutoScrollTimer(n
 
   if (NS_FAILED(result))
     return result;
 
   return DoAutoScroll(aFrame, aPoint);
 }
 
 nsresult
-nsTypedSelection::StopAutoScrollTimer()
+Selection::StopAutoScrollTimer()
 {
   if (mAutoScrollTimer)
     return mAutoScrollTimer->Stop();
 
   return NS_OK; 
 }
 
 nsresult
-nsTypedSelection::DoAutoScroll(nsIFrame *aFrame, nsPoint& aPoint)
+Selection::DoAutoScroll(nsIFrame* aFrame, nsPoint& aPoint)
 {
   NS_PRECONDITION(aFrame, "Need a frame");
 
   if (mAutoScrollTimer)
     (void)mAutoScrollTimer->Stop();
 
   nsPresContext* presContext = aFrame->PresContext();
   nsRootPresContext* rootPC = presContext->GetRootPresContext();
@@ -4447,28 +4402,28 @@ nsTypedSelection::DoAutoScroll(nsIFrame 
       presContext->PresShell()->FrameManager()->GetRootFrame()->GetOffsetToCrossDoc(rootmostFrame);
     mAutoScrollTimer->Start(presContext, presContextPoint);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetEnumerator(nsIEnumerator **aIterator)
+Selection::GetEnumerator(nsIEnumerator** aIterator)
 {
   NS_ADDREF(*aIterator = new nsSelectionIterator(this));
   return NS_OK;
 }
 
 
 
 /** RemoveAllRanges zeroes the selection
  */
 NS_IMETHODIMP
-nsTypedSelection::RemoveAllRanges()
+Selection::RemoveAllRanges()
 {
   if (!mFrameSelection)
     return NS_OK;//nothing to do
   nsRefPtr<nsPresContext>  presContext;
   GetPresContext(getter_AddRefs(presContext));
 
 
   nsresult  result = Clear(presContext);
@@ -4482,17 +4437,17 @@ nsTypedSelection::RemoveAllRanges()
   // Also need to notify the frames!
   // PresShell::CharacterDataChanged should do that on DocumentChanged
 }
 
 /** AddRange adds the specified range to the selection
  *  @param aRange is the range to be added
  */
 NS_IMETHODIMP
-nsTypedSelection::AddRange(nsIDOMRange* aDOMRange)
+Selection::AddRange(nsIDOMRange* aDOMRange)
 {
   if (!aDOMRange) {
     return NS_ERROR_NULL_POINTER;
   }
   nsRange* range = static_cast<nsRange*>(aDOMRange);
 
   // This inserts a table cell range in proper document order
   // and returns NS_OK if range doesn't contain just one table cell
@@ -4519,30 +4474,30 @@ nsTypedSelection::AddRange(nsIDOMRange* 
   selectFrames(presContext, range, true);
 
   if (!mFrameSelection)
     return NS_OK;//nothing to do
 
   return mFrameSelection->NotifySelectionListeners(GetType());
 }
 
-// nsTypedSelection::RemoveRange
+// Selection::RemoveRange
 //
 //    Removes the given range from the selection. The tricky part is updating
 //    the flags on the frames that indicate whether they have a selection or
 //    not. There could be several selection ranges on the frame, and clearing
 //    the bit would cause the selection to not be drawn, even when there is
 //    another range on the frame (bug 346185).
 //
 //    We therefore find any ranges that intersect the same nodes as the range
 //    being removed, and cause them to set the selected bits back on their
 //    selected frames after we've cleared the bit from ours.
 
 nsresult
-nsTypedSelection::RemoveRange(nsIDOMRange* aDOMRange)
+Selection::RemoveRange(nsIDOMRange* aDOMRange)
 {
   if (!aDOMRange) {
     return NS_ERROR_INVALID_ARG;
   }
   nsRefPtr<nsRange> range = static_cast<nsRange*>(aDOMRange);
   
   nsresult rv = RemoveItem(range);
   if (NS_FAILED(rv))
@@ -4604,30 +4559,30 @@ nsTypedSelection::RemoveRange(nsIDOMRang
 }
 
 
 
 /*
  * Collapse sets the whole selection to be one point.
  */
 NS_IMETHODIMP
-nsTypedSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset)
+Selection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset)
 {
   nsCOMPtr<nsINode> parentNode = do_QueryInterface(aParentNode);
   return Collapse(parentNode, aOffset);
 }
 
 NS_IMETHODIMP
-nsTypedSelection::CollapseNative(nsINode* aParentNode, PRInt32 aOffset)
+Selection::CollapseNative(nsINode* aParentNode, PRInt32 aOffset)
 {
   return Collapse(aParentNode, aOffset);
 }
 
 nsresult
-nsTypedSelection::Collapse(nsINode* aParentNode, PRInt32 aOffset)
+Selection::Collapse(nsINode* aParentNode, PRInt32 aOffset)
 {
   if (!aParentNode)
     return NS_ERROR_INVALID_ARG;
   if (!mFrameSelection)
     return NS_ERROR_NOT_INITIALIZED; // Can't do selection
 
   nsCOMPtr<nsINode> kungfuDeathGrip = aParentNode;
 
@@ -4670,17 +4625,17 @@ nsTypedSelection::Collapse(nsINode* aPar
   return mFrameSelection->NotifySelectionListeners(GetType());
 }
 
 /*
  * Sets the whole selection to be one point
  * at the start of the current selection
  */
 NS_IMETHODIMP
-nsTypedSelection::CollapseToStart()
+Selection::CollapseToStart()
 {
   PRInt32 cnt;
   nsresult rv = GetRangeCount(&cnt);
   if (NS_FAILED(rv) || cnt <= 0)
     return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   // Get the first range
   nsRange* firstRange = mRanges[0].mRange;
@@ -4690,17 +4645,17 @@ nsTypedSelection::CollapseToStart()
   return Collapse(firstRange->GetStartParent(), firstRange->StartOffset());
 }
 
 /*
  * Sets the whole selection to be one point
  * at the end of the current selection
  */
 NS_IMETHODIMP
-nsTypedSelection::CollapseToEnd()
+Selection::CollapseToEnd()
 {
   PRInt32 cnt;
   nsresult rv = GetRangeCount(&cnt);
   if (NS_FAILED(rv) || cnt <= 0)
     return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   // Get the last range
   nsRange* lastRange = mRanges[cnt - 1].mRange;
@@ -4709,78 +4664,78 @@ nsTypedSelection::CollapseToEnd()
 
   return Collapse(lastRange->GetEndParent(), lastRange->EndOffset());
 }
 
 /*
  * IsCollapsed -- is the whole selection just one point, or unset?
  */
 bool
-nsTypedSelection::IsCollapsed()
+Selection::IsCollapsed()
 {
   PRUint32 cnt = mRanges.Length();
   if (cnt == 0) {
     return true;
   }
 
   if (cnt != 1) {
     return false;
   }
 
   return mRanges[0].mRange->Collapsed();
 }
 
 /* virtual */
 bool
-nsTypedSelection::Collapsed()
+Selection::Collapsed()
 {
   return IsCollapsed();
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetIsCollapsed(bool* aIsCollapsed)
+Selection::GetIsCollapsed(bool* aIsCollapsed)
 {
   NS_ENSURE_TRUE(aIsCollapsed, NS_ERROR_NULL_POINTER);
 
   *aIsCollapsed = IsCollapsed();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetRangeCount(PRInt32* aRangeCount)
+Selection::GetRangeCount(PRInt32* aRangeCount)
 {
   *aRangeCount = (PRInt32)mRanges.Length();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
+Selection::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
 {
   *aReturn = mRanges.SafeElementAt(aIndex, sEmptyData).mRange;
   if (!*aReturn) {
     return NS_ERROR_DOM_INDEX_SIZE_ERR;
   }
 
   NS_ADDREF(*aReturn);
 
   return NS_OK;
 }
 
 nsRange*
-nsTypedSelection::GetRangeAt(PRInt32 aIndex)
+Selection::GetRangeAt(PRInt32 aIndex)
 {
   return mRanges.SafeElementAt(aIndex, sEmptyData).mRange;
 }
 
 /*
 utility function
 */
 nsresult
-nsTypedSelection::SetAnchorFocusToRange(nsRange *aRange)
+Selection::SetAnchorFocusToRange(nsRange* aRange)
 {
   NS_ENSURE_STATE(mAnchorFocusRange);
 
   nsresult res = RemoveItem(mAnchorFocusRange);
   if (NS_FAILED(res))
     return res;
 
   PRInt32 aOutIndex = -1;
@@ -4788,17 +4743,17 @@ nsTypedSelection::SetAnchorFocusToRange(
   if (NS_FAILED(res))
     return res;
   setAnchorFocusRange(aOutIndex);
 
   return NS_OK;
 }
 
 void
-nsTypedSelection::ReplaceAnchorFocusRange(nsRange *aRange)
+Selection::ReplaceAnchorFocusRange(nsRange* aRange)
 {
   nsRefPtr<nsPresContext> presContext;
   GetPresContext(getter_AddRefs(presContext));
   if (presContext) {
     selectFrames(presContext, mAnchorFocusRange, false);
     SetAnchorFocusToRange(aRange);
     selectFrames(presContext, mAnchorFocusRange, true);
   }
@@ -4829,30 +4784,30 @@ 2  1  a = continue selection from 2 to 1
 */
 
 
 /*
  * Extend extends the selection away from the anchor.
  * We don't need to know the direction, because we always change the focus.
  */
 NS_IMETHODIMP
-nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
+Selection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
 {
   nsCOMPtr<nsINode> parentNode = do_QueryInterface(aParentNode);
   return Extend(parentNode, aOffset);
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ExtendNative(nsINode* aParentNode, PRInt32 aOffset)
+Selection::ExtendNative(nsINode* aParentNode, PRInt32 aOffset)
 {
   return Extend(aParentNode, aOffset);
 }
 
 nsresult
-nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
+Selection::Extend(nsINode* aParentNode, PRInt32 aOffset)
 {
   if (!aParentNode)
     return NS_ERROR_INVALID_ARG;
 
   // First, find the range containing the old focus point:
   if (!mAnchorFocusRange)
     return NS_ERROR_DOM_INVALID_STATE_ERR;
 
@@ -5058,17 +5013,17 @@ nsTypedSelection::Extend(nsINode* aParen
   else {
     printf ("Sel. Extend set to null parent.\n");
   }
 #endif
   return mFrameSelection->NotifySelectionListeners(GetType());
 }
 
 NS_IMETHODIMP
-nsTypedSelection::SelectAllChildren(nsIDOMNode* aParentNode)
+Selection::SelectAllChildren(nsIDOMNode* aParentNode)
 {
   NS_ENSURE_ARG_POINTER(aParentNode);
   nsCOMPtr<nsINode> node = do_QueryInterface(aParentNode);
 
   if (mFrameSelection)
   {
     mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON);
   }
@@ -5079,18 +5034,17 @@ nsTypedSelection::SelectAllChildren(nsID
   if (mFrameSelection)
   {
     mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON);
   }
   return Extend(node, node->GetChildCount());
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ContainsNode(nsIDOMNode* aNode, bool aAllowPartial,
-                               bool* aYes)
+Selection::ContainsNode(nsIDOMNode* aNode, bool aAllowPartial, bool* aYes)
 {
   nsresult rv;
   if (!aYes)
     return NS_ERROR_NULL_POINTER;
   *aYes = false;
 
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   if (mRanges.Length() == 0 || !node)
@@ -5137,31 +5091,31 @@ nsTypedSelection::ContainsNode(nsIDOMNod
       }
     }
   }
   return NS_OK;
 }
 
 
 nsresult
-nsTypedSelection::GetPresContext(nsPresContext **aPresContext)
+Selection::GetPresContext(nsPresContext** aPresContext)
 {
   if (!mFrameSelection)
     return NS_ERROR_FAILURE;//nothing to do
   nsIPresShell *shell = mFrameSelection->GetShell();
 
   if (!shell)
     return NS_ERROR_NULL_POINTER;
 
   NS_IF_ADDREF(*aPresContext = shell->GetPresContext());
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::GetPresShell(nsIPresShell **aPresShell)
+Selection::GetPresShell(nsIPresShell** aPresShell)
 {
   if (mPresShellWeak)
   {
     nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShellWeak);
     if (presShell)
       NS_ADDREF(*aPresShell = presShell);
     return NS_OK;
   }
@@ -5173,18 +5127,17 @@ nsTypedSelection::GetPresShell(nsIPresSh
 
   mPresShellWeak = do_GetWeakReference(shell);    // the presshell owns us, so no addref
   if (mPresShellWeak)
     NS_ADDREF(*aPresShell = shell);
   return rv;
 }
 
 nsIFrame *
-nsTypedSelection::GetSelectionAnchorGeometry(SelectionRegion aRegion,
-                                             nsRect *aRect)
+Selection::GetSelectionAnchorGeometry(SelectionRegion aRegion, nsRect* aRect)
 {
   if (!mFrameSelection)
     return nsnull;  // nothing to do
 
   NS_ENSURE_TRUE(aRect, nsnull);
 
   aRect->SetRect(0, 0, 0, 0);
 
@@ -5219,18 +5172,17 @@ nsTypedSelection::GetSelectionAnchorGeom
   // make focusRect relative to anchorFrame
   focusRect += focusFrame->GetOffsetTo(anchorFrame);
 
   aRect->UnionRectEdges(anchorRect, focusRect);
   return anchorFrame;
 }
 
 nsIFrame *
-nsTypedSelection::GetSelectionEndPointGeometry(SelectionRegion aRegion,
-                                               nsRect *aRect)
+Selection::GetSelectionEndPointGeometry(SelectionRegion aRegion, nsRect* aRect)
 {
   if (!mFrameSelection)
     return nsnull;  // nothing to do
 
   NS_ENSURE_TRUE(aRect, nsnull);
 
   aRect->SetRect(0, 0, 0, 0);
 
@@ -5296,35 +5248,35 @@ nsTypedSelection::GetSelectionEndPointGe
     aRect->x = frame->GetRect().width;
   }
   aRect->height = frame->GetRect().height;
 
   return frame;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ScrollSelectionIntoViewEvent::Run()
+Selection::ScrollSelectionIntoViewEvent::Run()
 {
-  if (!mTypedSelection)
+  if (!mSelection)
     return NS_OK;  // event revoked
 
-  PRInt32 flags = nsTypedSelection::SCROLL_DO_FLUSH |
-                  nsTypedSelection::SCROLL_SYNCHRONOUS;
+  PRInt32 flags = Selection::SCROLL_DO_FLUSH |
+                  Selection::SCROLL_SYNCHRONOUS;
   if (mFirstAncestorOnly) {
-    flags |= nsTypedSelection::SCROLL_FIRST_ANCESTOR_ONLY;
-  }
-
-  mTypedSelection->mScrollEvent.Forget();
-  mTypedSelection->ScrollIntoView(mRegion, mVerticalScroll,
-                                  mHorizontalScroll, flags);
+    flags |= Selection::SCROLL_FIRST_ANCESTOR_ONLY;
+  }
+
+  mSelection->mScrollEvent.Forget();
+  mSelection->ScrollIntoView(mRegion, mVerticalScroll,
+                             mHorizontalScroll, flags);
   return NS_OK;
 }
 
 nsresult
-nsTypedSelection::PostScrollSelectionIntoViewEvent(
+Selection::PostScrollSelectionIntoViewEvent(
                                          SelectionRegion aRegion,
                                          bool aFirstAncestorOnly,
                                          nsIPresShell::ScrollAxis aVertical,
                                          nsIPresShell::ScrollAxis aHorizontal)
 {
   // If we've already posted an event, revoke it and place a new one at the
   // end of the queue to make sure that any new pending reflow events are
   // processed before we scroll. This will insure that we scroll to the
@@ -5337,53 +5289,50 @@ nsTypedSelection::PostScrollSelectionInt
   nsresult rv = NS_DispatchToCurrentThread(ev);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mScrollEvent = ev;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ScrollIntoView(SelectionRegion aRegion,
-                                 bool aIsSynchronous,
-                                 PRInt16 aVPercent,
-                                 PRInt16 aHPercent)
+Selection::ScrollIntoView(SelectionRegion aRegion, bool aIsSynchronous,
+                          PRInt16 aVPercent, PRInt16 aHPercent)
 {
   return ScrollIntoViewInternal(aRegion,
                                 aIsSynchronous,
                                 nsIPresShell::ScrollAxis(aVPercent),
                                 nsIPresShell::ScrollAxis(aHPercent));
 }
 
 NS_IMETHODIMP
-nsTypedSelection::ScrollIntoViewInternal(SelectionRegion aRegion,
-                                         bool aIsSynchronous,
-                                         nsIPresShell::ScrollAxis aVertical,
-                                         nsIPresShell::ScrollAxis aHorizontal)
+Selection::ScrollIntoViewInternal(SelectionRegion aRegion, bool aIsSynchronous,
+                                  nsIPresShell::ScrollAxis aVertical,
+                                  nsIPresShell::ScrollAxis aHorizontal)
 {
   return ScrollIntoView(aRegion, aVertical, aHorizontal,
-                        aIsSynchronous ? nsTypedSelection::SCROLL_SYNCHRONOUS : 0);
+                        aIsSynchronous ? Selection::SCROLL_SYNCHRONOUS : 0);
 }
 
 nsresult
-nsTypedSelection::ScrollIntoView(SelectionRegion aRegion,
-                                 nsIPresShell::ScrollAxis aVertical,
-                                 nsIPresShell::ScrollAxis aHorizontal,
-                                 PRInt32 aFlags)
+Selection::ScrollIntoView(SelectionRegion aRegion,
+                          nsIPresShell::ScrollAxis aVertical,
+                          nsIPresShell::ScrollAxis aHorizontal,
+                          PRInt32 aFlags)
 {
   nsresult result;
   if (!mFrameSelection)
     return NS_OK;//nothing to do
 
   if (mFrameSelection->GetBatching())
     return NS_OK;
 
-  if (!(aFlags & nsTypedSelection::SCROLL_SYNCHRONOUS))
+  if (!(aFlags & Selection::SCROLL_SYNCHRONOUS))
     return PostScrollSelectionIntoViewEvent(aRegion,
-      !!(aFlags & nsTypedSelection::SCROLL_FIRST_ANCESTOR_ONLY),
+      !!(aFlags & Selection::SCROLL_FIRST_ANCESTOR_ONLY),
       aVertical, aHorizontal);
 
   //
   // Shut the caret off before scrolling to avoid
   // leaving caret turds on the screen!
   //
   nsCOMPtr<nsIPresShell> presShell;
   result = GetPresShell(getter_AddRefs(presShell));
@@ -5392,17 +5341,17 @@ nsTypedSelection::ScrollIntoView(Selecti
   nsRefPtr<nsCaret> caret = presShell->GetCaret();
   if (caret)
   {
     // Now that text frame character offsets are always valid (though not
     // necessarily correct), the worst that will happen if we don't flush here
     // is that some callers might scroll to the wrong place.  Those should
     // either manually flush if they're in a safe position for it or use the
     // async version of this method.
-    if (aFlags & nsTypedSelection::SCROLL_DO_FLUSH) {
+    if (aFlags & Selection::SCROLL_DO_FLUSH) {
       presShell->FlushPendingNotifications(Flush_Layout);
 
       // Reget the presshell, since it might have gone away.
       result = GetPresShell(getter_AddRefs(presShell));
       if (NS_FAILED(result) || !presShell)
         return result;
     }
 
@@ -5413,45 +5362,46 @@ nsTypedSelection::ScrollIntoView(Selecti
     //
 
     nsRect rect;
     nsIFrame* frame = GetSelectionAnchorGeometry(aRegion, &rect);
     if (!frame)
       return NS_ERROR_FAILURE;
 
     presShell->ScrollFrameRectIntoView(frame, rect, aVertical, aHorizontal,
-      (aFlags & nsTypedSelection::SCROLL_FIRST_ANCESTOR_ONLY) ? nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY: 0);
+      (aFlags & Selection::SCROLL_FIRST_ANCESTOR_ONLY) ?
+       nsIPresShell::SCROLL_FIRST_ANCESTOR_ONLY : 0);
     return NS_OK;
   }
   return result;
 }
 
 
 
 NS_IMETHODIMP
-nsTypedSelection::AddSelectionListener(nsISelectionListener* aNewListener)
+Selection::AddSelectionListener(nsISelectionListener* aNewListener)
 {
   if (!aNewListener)
     return NS_ERROR_NULL_POINTER;
   return mSelectionListeners.AppendObject(aNewListener) ? NS_OK : NS_ERROR_FAILURE;      // addrefs
 }
 
 
 
 NS_IMETHODIMP
-nsTypedSelection::RemoveSelectionListener(nsISelectionListener* aListenerToRemove)
+Selection::RemoveSelectionListener(nsISelectionListener* aListenerToRemove)
 {
   if (!aListenerToRemove )
     return NS_ERROR_NULL_POINTER;
   return mSelectionListeners.RemoveObject(aListenerToRemove) ? NS_OK : NS_ERROR_FAILURE; // releases
 }
 
 
 nsresult
-nsTypedSelection::NotifySelectionListeners()
+Selection::NotifySelectionListeners()
 {
   if (!mFrameSelection)
     return NS_OK;//nothing to do
  
   if (mFrameSelection->GetBatching()) {
     mFrameSelection->SetDirty();
     return NS_OK;
   }
@@ -5468,48 +5418,48 @@ nsTypedSelection::NotifySelectionListene
   short reason = mFrameSelection->PopReason();
   for (PRInt32 i = 0; i < cnt; i++) {
     selectionListeners[i]->NotifySelectionChanged(domdoc, this, reason);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTypedSelection::StartBatchChanges()
+Selection::StartBatchChanges()
 {
   if (mFrameSelection)
     mFrameSelection->StartBatchChanges();
 
   return NS_OK;
 }
 
 
 
 NS_IMETHODIMP
-nsTypedSelection::EndBatchChanges()
+Selection::EndBatchChanges()
 {
   if (mFrameSelection)
     mFrameSelection->EndBatchChanges();
 
   return NS_OK;
 }
 
 
 
 NS_IMETHODIMP
-nsTypedSelection::DeleteFromDocument()
+Selection::DeleteFromDocument()
 {
   if (!mFrameSelection)
     return NS_OK;//nothing to do
   return mFrameSelection->DeleteFromDocument();
 }
 
 NS_IMETHODIMP
-nsTypedSelection::Modify(const nsAString& aAlter, const nsAString& aDirection,
-                         const nsAString& aGranularity)
+Selection::Modify(const nsAString& aAlter, const nsAString& aDirection,
+                  const nsAString& aGranularity)
 {
   // Silently exit if there's no selection or no focus node.
   if (!mFrameSelection || !GetAnchorFocusRange() || !GetFocusNode()) {
     return NS_OK;
   }
 
   if (!aAlter.LowerCaseEqualsLiteral("move") &&
       !aAlter.LowerCaseEqualsLiteral("extend")) {
@@ -5618,17 +5568,17 @@ nsTypedSelection::Modify(const nsAString
   }
   return NS_OK;
 }
 
 /** SelectionLanguageChange modifies the cursor Bidi level after a change in keyboard direction
  *  @param aLangRTL is true if the new language is right-to-left or false if the new language is left-to-right
  */
 NS_IMETHODIMP
-nsTypedSelection::SelectionLanguageChange(bool aLangRTL)
+Selection::SelectionLanguageChange(bool aLangRTL)
 {
   if (!mFrameSelection)
     return NS_ERROR_NOT_INITIALIZED; // Can't do selection
   nsresult result;
   nsIFrame *focusFrame = 0;
 
   result = GetPrimaryFrameForFocusNode(&focusFrame, nsnull, false);
   if (NS_FAILED(result)) {
@@ -5699,22 +5649,22 @@ nsTypedSelection::SelectionLanguageChang
   // The caret might have moved, so invalidate the desired X position
   // for future usages of up-arrow or down-arrow
   mFrameSelection->InvalidateDesiredX();
   
   return NS_OK;
 }
 
 NS_IMETHODIMP_(nsDirection)
-nsTypedSelection::GetSelectionDirection() {
+Selection::GetSelectionDirection() {
   return mDirection;
 }
 
 NS_IMETHODIMP_(void)
-nsTypedSelection::SetSelectionDirection(nsDirection aDirection) {
+Selection::SetSelectionDirection(nsDirection aDirection) {
   mDirection = aDirection;
 }
 
 
 // nsAutoCopyListener
 
 nsAutoCopyListener* nsAutoCopyListener::sInstance = nsnull;
 
--- a/layout/generic/nsTextFrame.h
+++ b/layout/generic/nsTextFrame.h
@@ -111,17 +111,17 @@ public:
   
   virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint);
   ContentOffsets GetCharacterOffsetAtFramePoint(const nsPoint &aPoint);
 
   /**
    * This is called only on the primary text frame. It indicates that
    * the selection state of the given character range has changed.
    * Text in the range is unconditionally invalidated
-   * (nsTypedSelection::Repaint depends on this).
+   * (Selection::Repaint depends on this).
    * @param aSelected true if the selection has been added to the range,
    * false otherwise
    * @param aType the type of selection added or removed
    */
   void SetSelectedRange(PRUint32 aStart, PRUint32 aEnd, bool aSelected,
                         SelectionType aType);
 
   virtual bool PeekOffsetNoAmount(bool aForward, PRInt32* aOffset);