Merge the last PGO-green inbound changeset to m-c
authorRyan VanderMeulen <ryanvm@gmail.com>
Sun, 10 Jun 2012 18:21:22 -0400
changeset 101126 efa1dbf0da74f41b5ed22b38bec4ac1adff7b518
parent 101118 f6242d0169f094942e3831baefce30c552dd91a7 (current diff)
parent 101125 b7d5ee4528c82a4aa5f299f66a7f20b9f8c71946 (diff)
child 101128 34bad8144361f2c0f77befa2ab80de762ff63f08
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone16.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge the last PGO-green inbound changeset to m-c
content/base/src/nsContentUtils.cpp
content/base/src/nsDOMFileReader.cpp
content/base/src/nsXMLHttpRequest.cpp
dom/base/DOMRequest.cpp
editor/libeditor/base/nsEditor.cpp
editor/libeditor/html/nsHTMLDataTransfer.cpp
layout/base/nsPresShell.cpp
layout/forms/nsTextControlFrame.cpp
layout/generic/nsTypedSelection.h
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -876,99 +876,25 @@ Accessible::GetDeepestChildAtPoint(PRInt
 
   NS_IF_ADDREF(*aAccessible = ChildAtPoint(aX, aY, eDeepestChild));
   return NS_OK;
 }
 
 void
 Accessible::GetBoundsRect(nsRect& aTotalBounds, nsIFrame** aBoundingFrame)
 {
-/*
- * This method is used to determine the bounds of a content node.
- * Because HTML wraps and links are not always rectangular, this
- * method uses the following algorithm:
- *
- * 1) Start with an empty rectangle
- * 2) Add the rect for the primary frame from for the DOM node.
- * 3) For each next frame at the same depth with the same DOM node, add that rect to total
- * 4) If that frame is an inline frame, search deeper at that point in the tree, adding all rects
- */
-
-  // Initialization area
-  *aBoundingFrame = nsnull;
-  nsIFrame* firstFrame = GetFrame();
-  if (!firstFrame)
-    return;
-
-  // Find common relative parent
-  // This is an ancestor frame that will incompass all frames for this content node.
-  // We need the relative parent so we can get absolute screen coordinates
-  nsIFrame *ancestorFrame = firstFrame;
-
-  while (ancestorFrame) {  
-    *aBoundingFrame = ancestorFrame;
-    // If any other frame type, we only need to deal with the primary frame
-    // Otherwise, there may be more frames attached to the same content node
-    if (ancestorFrame->GetType() != nsGkAtoms::inlineFrame &&
-        ancestorFrame->GetType() != nsGkAtoms::textFrame)
-      break;
-    ancestorFrame = ancestorFrame->GetParent();
-  }
-
-  nsIFrame *iterFrame = firstFrame;
-  nsCOMPtr<nsIContent> firstContent(mContent);
-  nsIContent* iterContent = firstContent;
-  PRInt32 depth = 0;
-
-  // Look only at frames below this depth, or at this depth (if we're still on the content node we started with)
-  while (iterContent == firstContent || depth > 0) {
-    // Coordinates will come back relative to parent frame
-    nsRect currFrameBounds = iterFrame->GetRect();
-    
-    // Make this frame's bounds relative to common parent frame
-    currFrameBounds +=
-      iterFrame->GetParent()->GetOffsetToExternal(*aBoundingFrame);
-
-    // Add this frame's bounds to total
-    aTotalBounds.UnionRect(aTotalBounds, currFrameBounds);
-
-    nsIFrame *iterNextFrame = nsnull;
-
-    if (iterFrame->GetType() == nsGkAtoms::inlineFrame) {
-      // Only do deeper bounds search if we're on an inline frame
-      // Inline frames can contain larger frames inside of them
-      iterNextFrame = iterFrame->GetFirstPrincipalChild();
-    }
-
-    if (iterNextFrame) 
-      ++depth;  // Child was found in code above this: We are going deeper in this iteration of the loop
-    else {  
-      // Use next sibling if it exists, or go back up the tree to get the first next-in-flow or next-sibling 
-      // within our search
-      while (iterFrame) {
-        iterNextFrame = iterFrame->GetNextContinuation();
-        if (!iterNextFrame)
-          iterNextFrame = iterFrame->GetNextSibling();
-        if (iterNextFrame || --depth < 0) 
-          break;
-        iterFrame = iterFrame->GetParent();
-      }
-    }
-
-    // Get ready for the next round of our loop
-    iterFrame = iterNextFrame;
-    if (iterFrame == nsnull)
-      break;
-    iterContent = nsnull;
-    if (depth == 0)
-      iterContent = iterFrame->GetContent();
+  nsIFrame* frame = GetFrame();
+  if (frame) {
+    *aBoundingFrame = nsLayoutUtils::GetContainingBlockForClientRect(frame);
+    aTotalBounds = nsLayoutUtils::
+      GetAllInFlowRectsUnion(frame, *aBoundingFrame,
+                             nsLayoutUtils::RECTS_ACCOUNT_FOR_TRANSFORMS);
   }
 }
 
-
 /* void getBounds (out long x, out long y, out long width, out long height); */
 NS_IMETHODIMP
 Accessible::GetBounds(PRInt32* aX, PRInt32* aY,
                       PRInt32* aWidth, PRInt32* aHeight)
 {
   NS_ENSURE_ARG_POINTER(aX);
   *aX = 0;
   NS_ENSURE_ARG_POINTER(aY);
--- 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
@@ -137,17 +137,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"
@@ -6853,17 +6853,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/base/src/nsDOMFileReader.cpp
+++ b/content/base/src/nsDOMFileReader.cpp
@@ -76,20 +76,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(load)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(loadstart)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(loadend)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsDOMFileReader,
                                                nsDOMEventTargetHelper)
-  if(tmp->mResultArrayBuffer) {
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mResultArrayBuffer,
-                                               "mResultArrayBuffer")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mResultArrayBuffer)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 DOMCI_DATA(FileReader, nsDOMFileReader)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMFileReader)
   NS_INTERFACE_MAP_ENTRY(nsIDOMFileReader)
   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -666,24 +666,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannelEventSink)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgressEventSink)
 
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mUpload)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsXMLHttpRequest,
                                                nsXHREventTarget)
-  if(tmp->mResultArrayBuffer) {
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mResultArrayBuffer,
-                                               "mResultArrayBuffer")
-  }
-  if (JSVAL_IS_GCTHING(tmp->mResultJSON)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mResultJSON);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResultJSON")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mResultArrayBuffer)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResultJSON)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 DOMCI_DATA(XMLHttpRequest, nsXMLHttpRequest)
 
 // QueryInterface implementation for nsXMLHttpRequest
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsXMLHttpRequest)
   NS_INTERFACE_MAP_ENTRY(nsIXMLHttpRequest)
   NS_INTERFACE_MAP_ENTRY(nsIJSXMLHttpRequest)
--- a/content/canvas/src/ImageData.cpp
+++ b/content/canvas/src/ImageData.cpp
@@ -23,17 +23,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsIDOMImageData)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ImageData)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(ImageData)
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ImageData)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mData, "mData")
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mData)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ImageData)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ImageData)
   tmp->DropData();
--- a/content/events/src/nsDOMMessageEvent.cpp
+++ b/content/events/src/nsDOMMessageEvent.cpp
@@ -17,20 +17,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMMessageEvent, nsDOMEvent)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSource)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMMessageEvent)
-  if (JSVAL_IS_GCTHING(tmp->mData)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mData);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mData")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mData)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 DOMCI_DATA(MessageEvent, nsDOMMessageEvent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMMessageEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMessageEvent)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MessageEvent)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
--- 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/DOMRequest.cpp
+++ b/dom/base/DOMRequest.cpp
@@ -46,20 +46,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mError)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(DOMRequest,
                                                nsDOMEventTargetHelper)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
   // nsDOMEventTargetHelper does it for us.
-  if (JSVAL_IS_GCTHING(tmp->mResult)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mResult);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResult")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResult)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMRequest)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMRequest)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMRequest)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(DOMRequest, nsDOMEventTargetHelper)
--- 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/dom/indexedDB/IDBCursor.cpp
+++ b/dom/indexedDB/IDBCursor.cpp
@@ -24,28 +24,27 @@
 #include "TransactionThreadPool.h"
 
 #include "ipc/IndexedDBChild.h"
 #include "ipc/IndexedDBParent.h"
 
 #include "IndexedDatabaseInlines.h"
 
 USING_INDEXEDDB_NAMESPACE
+using namespace mozilla::dom::indexedDB::ipc;
 
 MOZ_STATIC_ASSERT(sizeof(size_t) >= sizeof(IDBCursor::Direction),
                   "Relying on conversion between size_t and "
                   "IDBCursor::Direction");
 
 namespace {
 
 class CursorHelper : public AsyncConnectionHelper
 {
 public:
-  typedef ipc::CursorRequestParams CursorRequestParams;
-
   CursorHelper(IDBCursor* aCursor)
   : AsyncConnectionHelper(aCursor->Transaction(), aCursor->Request()),
     mCursor(aCursor), mActor(nsnull)
   {
     NS_ASSERTION(aCursor, "Null cursor!");
   }
 
   virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
@@ -452,32 +451,20 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBCursor)
   NS_ASSERTION(tmp->mHaveCachedKey || JSVAL_IS_VOID(tmp->mCachedKey),
                "Should have a cached key");
   NS_ASSERTION(tmp->mHaveCachedPrimaryKey ||
                JSVAL_IS_VOID(tmp->mCachedPrimaryKey),
                "Should have a cached primary key");
   NS_ASSERTION(tmp->mHaveCachedValue || JSVAL_IS_VOID(tmp->mCachedValue),
                "Should have a cached value");
-  if (tmp->mScriptOwner) {
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mScriptOwner,
-                                               "mScriptOwner")
-  }
-  if (JSVAL_IS_GCTHING(tmp->mCachedKey)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedKey);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedKey")
-  }
-  if (JSVAL_IS_GCTHING(tmp->mCachedPrimaryKey)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedPrimaryKey);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedPrimaryKey")
-  }
-  if (JSVAL_IS_GCTHING(tmp->mCachedValue)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedValue);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedValue")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedKey)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedPrimaryKey)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedValue)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
   // Don't unlink mObjectStore, mIndex, or mTransaction!
   if (tmp->mRooted) {
     NS_DROP_JS_OBJECTS(tmp, IDBCursor);
     tmp->mScriptOwner = nsnull;
     tmp->mCachedKey = JSVAL_VOID;
@@ -884,17 +871,17 @@ ContinueHelper::GetSuccessResult(JSConte
   }
 
   return NS_OK;
 }
 
 nsresult
 ContinueHelper::PackArgumentsForParentProcess(CursorRequestParams& aParams)
 {
-  ipc::ContinueParams params;
+  ContinueParams params;
 
   params.key() = mCursor->mContinueToKey;
   params.count() = uint32_t(mCount);
 
   aParams = params;
   return NS_OK;
 }
 
@@ -909,22 +896,22 @@ ContinueHelper::MaybeSendResponseToChild
     return Success_NotSent;
   }
 
   if (!mCloneReadInfo.mFileInfos.IsEmpty()) {
     NS_WARNING("No support for transferring blobs across processes yet!");
     return Error;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::ContinueResponse continueResponse;
+    ContinueResponse continueResponse;
     continueResponse.key() = mKey;
     continueResponse.objectKey() = mObjectKey;
     continueResponse.cloneInfo() = mCloneReadInfo;
     response = continueResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
@@ -937,17 +924,17 @@ ContinueHelper::MaybeSendResponseToChild
 
 nsresult
 ContinueHelper::UnpackResponseFromParentProcess(
                                             const ResponseValue& aResponseValue)
 {
   NS_ASSERTION(aResponseValue.type() == ResponseValue::TContinueResponse,
                "Bad response type!");
 
-  const ipc::ContinueResponse& response = aResponseValue.get_ContinueResponse();
+  const ContinueResponse& response = aResponseValue.get_ContinueResponse();
 
   mKey = response.key();
   mObjectKey = response.objectKey();
 
   const SerializedStructuredCloneReadInfo& cloneInfo = response.cloneInfo();
 
   NS_ASSERTION((!cloneInfo.dataLength && !cloneInfo.data) ||
                (cloneInfo.dataLength && cloneInfo.data),
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -411,20 +411,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBFactory)
   if (tmp->mOwningObject) {
     tmp->mOwningObject = nsnull;
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mWindow)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBFactory)
-  if (tmp->mOwningObject) {
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mOwningObject,
-                                               "mOwningObject")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mOwningObject)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 DOMCI_DATA(IDBFactory, IDBFactory)
 
 nsresult
 IDBFactory::OpenCommon(const nsAString& aName,
                        PRInt64 aVersion,
                        bool aDeleting,
--- a/dom/indexedDB/IDBIndex.cpp
+++ b/dom/indexedDB/IDBIndex.cpp
@@ -26,24 +26,23 @@
 #include "DatabaseInfo.h"
 
 #include "ipc/IndexedDBChild.h"
 #include "ipc/IndexedDBParent.h"
 
 #include "IndexedDatabaseInlines.h"
 
 USING_INDEXEDDB_NAMESPACE
+using namespace mozilla::dom::indexedDB::ipc;
 
 namespace {
 
 class IndexHelper : public AsyncConnectionHelper
 {
 public:
-  typedef ipc::IndexRequestParams IndexRequestParams;
-
   IndexHelper(IDBTransaction* aTransaction,
               IDBRequest* aRequest,
               IDBIndex* aIndex)
   : AsyncConnectionHelper(aTransaction, aRequest), mIndex(aIndex),
     mActor(nsnull)
   {
     NS_ASSERTION(aTransaction, "Null transaction!");
     NS_ASSERTION(aRequest, "Null request!");
@@ -369,25 +368,25 @@ IDBIndex::Create(IDBObjectStore* aObject
   index->mMultiEntry = aIndexInfo->multiEntry;
 
   if (!IndexedDatabaseManager::IsMainProcess()) {
     IndexedDBObjectStoreChild* objectStoreActor = aObjectStore->GetActorChild();
     NS_ASSERTION(objectStoreActor, "Must have an actor here!");
 
     nsAutoPtr<IndexedDBIndexChild> actor(new IndexedDBIndexChild(index));
 
-    ipc::IndexConstructorParams params;
+    IndexConstructorParams params;
 
     if (aCreating) {
-      ipc::CreateIndexParams createParams;
+      CreateIndexParams createParams;
       createParams.info() = *aIndexInfo;
       params = createParams;
     }
     else {
-      ipc::GetIndexParams getParams;
+      GetIndexParams getParams;
       getParams.name() = aIndexInfo->name;
       params = getParams;
     }
 
     objectStoreActor->SendPIndexedDBIndexConstructor(actor.forget(), params);
   }
 
   return index.forget();
@@ -1076,17 +1075,17 @@ GetKeyHelper::ReleaseMainThreadObjects()
   IndexHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 GetKeyHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
   NS_ASSERTION(mKeyRange, "This should never be null!");
 
-  ipc::GetKeyParams params;
+  GetKeyParams params;
 
   mKeyRange->ToSerializedKeyRange(params.keyRange());
 
   aParams = params;
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
@@ -1095,22 +1094,22 @@ GetKeyHelper::MaybeSendResponseToChildPr
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::GetKeyResponse getKeyResponse;
+    GetKeyResponse getKeyResponse;
     getKeyResponse.key() = mKey;
     response = getKeyResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
@@ -1198,17 +1197,17 @@ GetHelper::ReleaseMainThreadObjects()
   GetKeyHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 GetHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
   NS_ASSERTION(mKeyRange, "This should never be null!");
 
-  ipc::FIXME_Bug_521898_index::GetParams params;
+  FIXME_Bug_521898_index::GetParams params;
 
   mKeyRange->ToSerializedKeyRange(params.keyRange());
 
   aParams = params;
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
@@ -1222,24 +1221,24 @@ GetHelper::MaybeSendResponseToChildProce
     return Success_NotSent;
   }
 
   if (!mCloneReadInfo.mFileInfos.IsEmpty()) {
     NS_WARNING("No support for transferring blobs across processes yet!");
     return Error;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
     SerializedStructuredCloneReadInfo readInfo;
     readInfo = mCloneReadInfo;
-    ipc::GetResponse getResponse = readInfo;
+    GetResponse getResponse = readInfo;
     response = getResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
@@ -1372,20 +1371,20 @@ GetAllKeysHelper::GetSuccessResult(JSCon
 
   *aVal = OBJECT_TO_JSVAL(array);
   return NS_OK;
 }
 
 nsresult
 GetAllKeysHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
-  ipc::GetAllKeysParams params;
+  GetAllKeysParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_index::KeyRange keyRange;
+    FIXME_Bug_521898_index::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.limit() = mLimit;
@@ -1400,22 +1399,22 @@ GetAllKeysHelper::MaybeSendResponseToChi
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::GetAllKeysResponse getAllKeysResponse;
+    GetAllKeysResponse getAllKeysResponse;
     getAllKeysResponse.keys().AppendElements(mKeys);
     response = getAllKeysResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
@@ -1520,20 +1519,20 @@ GetAllHelper::ReleaseMainThreadObjects()
       mCloneReadInfos[index].mCloneBuffer);
   }
   GetKeyHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 GetAllHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_index::GetAllParams params;
+  FIXME_Bug_521898_index::GetAllParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_index::KeyRange keyRange;
+    FIXME_Bug_521898_index::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.limit() = mLimit;
@@ -1555,22 +1554,22 @@ GetAllHelper::MaybeSendResponseToChildPr
 
   for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
     if (!mCloneReadInfos[index].mFileInfos.IsEmpty()) {
       NS_WARNING("No support for transferring blobs across processes yet!");
       return Error;
     }
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::GetAllResponse getAllResponse;
+    GetAllResponse getAllResponse;
 
     InfallibleTArray<SerializedStructuredCloneReadInfo>& infos =
       getAllResponse.cloneInfos();
 
     infos.SetCapacity(mCloneReadInfos.Length());
 
     for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
       SerializedStructuredCloneReadInfo* info = infos.AppendElement();
@@ -1816,20 +1815,20 @@ OpenKeyCursorHelper::ReleaseMainThreadOb
   mKeyRange = nsnull;
   mCursor = nsnull;
   IndexHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 OpenKeyCursorHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
-  ipc::OpenKeyCursorParams params;
+  OpenKeyCursorParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_index::KeyRange keyRange;
+    FIXME_Bug_521898_index::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.direction() = mDirection;
@@ -1854,34 +1853,34 @@ OpenKeyCursorHelper::MaybeSendResponseTo
   if (NS_SUCCEEDED(aResultCode)) {
     nsresult rv = EnsureCursor();
     if (NS_FAILED(rv)) {
       NS_WARNING("EnsureCursor failed!");
       aResultCode = rv;
     }
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::OpenCursorResponse openCursorResponse;
+    OpenCursorResponse openCursorResponse;
 
     if (!mCursor) {
       openCursorResponse = mozilla::void_t();
     }
     else {
       IndexedDBIndexParent* indexActor = mIndex->GetActorParent();
       NS_ASSERTION(indexActor, "Must have an actor here!");
 
       IndexedDBRequestParentBase* requestActor = mRequest->GetActorParent();
       NS_ASSERTION(requestActor, "Must have an actor here!");
 
-      ipc::IndexCursorConstructorParams params;
+      IndexCursorConstructorParams params;
       params.requestParent() = requestActor;
       params.direction() = mDirection;
       params.key() = mKey;
       params.objectKey() = mObjectKey;
       params.optionalCloneInfo() = mozilla::void_t();
 
       IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(mCursor);
 
@@ -1904,30 +1903,30 @@ OpenKeyCursorHelper::MaybeSendResponseTo
 
 nsresult
 OpenKeyCursorHelper::UnpackResponseFromParentProcess(
                                             const ResponseValue& aResponseValue)
 {
   NS_ASSERTION(aResponseValue.type() == ResponseValue::TOpenCursorResponse,
                "Bad response type!");
   NS_ASSERTION(aResponseValue.get_OpenCursorResponse().type() ==
-               ipc::OpenCursorResponse::Tvoid_t ||
+               OpenCursorResponse::Tvoid_t ||
                aResponseValue.get_OpenCursorResponse().type() ==
-               ipc::OpenCursorResponse::TPIndexedDBCursorChild,
+               OpenCursorResponse::TPIndexedDBCursorChild,
                "Bad response union type!");
   NS_ASSERTION(!mCursor, "Shouldn't have this yet!");
 
-  const ipc::OpenCursorResponse& response =
+  const OpenCursorResponse& response =
     aResponseValue.get_OpenCursorResponse();
 
   switch (response.type()) {
-    case ipc::OpenCursorResponse::Tvoid_t:
+    case OpenCursorResponse::Tvoid_t:
       break;
 
-    case ipc::OpenCursorResponse::TPIndexedDBCursorChild: {
+    case OpenCursorResponse::TPIndexedDBCursorChild: {
       IndexedDBCursorChild* actor =
         static_cast<IndexedDBCursorChild*>(
           response.get_PIndexedDBCursorChild());
 
       mCursor = actor->ForgetStrongCursor();
       NS_ASSERTION(mCursor, "This should never be null!");
 
     } break;
@@ -2152,20 +2151,20 @@ OpenCursorHelper::ReleaseMainThreadObjec
   mSerializedCloneReadInfo.dataLength = 0;
 
   OpenKeyCursorHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 OpenCursorHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_index::OpenCursorParams params;
+  FIXME_Bug_521898_index::OpenCursorParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_index::KeyRange keyRange;
+    FIXME_Bug_521898_index::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.direction() = mDirection;
@@ -2195,38 +2194,38 @@ OpenCursorHelper::MaybeSendResponseToChi
   if (NS_SUCCEEDED(aResultCode)) {
     nsresult rv = EnsureCursor();
     if (NS_FAILED(rv)) {
       NS_WARNING("EnsureCursor failed!");
       aResultCode = rv;
     }
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::OpenCursorResponse openCursorResponse;
+    OpenCursorResponse openCursorResponse;
 
     if (!mCursor) {
       openCursorResponse = mozilla::void_t();
     }
     else {
       IndexedDBIndexParent* indexActor = mIndex->GetActorParent();
       NS_ASSERTION(indexActor, "Must have an actor here!");
 
       IndexedDBRequestParentBase* requestActor = mRequest->GetActorParent();
       NS_ASSERTION(requestActor, "Must have an actor here!");
 
       NS_ASSERTION(mSerializedCloneReadInfo.data &&
                    mSerializedCloneReadInfo.dataLength,
                    "Shouldn't be possible!");
 
-      ipc::IndexCursorConstructorParams params;
+      IndexCursorConstructorParams params;
       params.requestParent() = requestActor;
       params.direction() = mDirection;
       params.key() = mKey;
       params.objectKey() = mObjectKey;
       params.optionalCloneInfo() = mSerializedCloneReadInfo;
 
       IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(mCursor);
 
@@ -2323,20 +2322,20 @@ CountHelper::ReleaseMainThreadObjects()
 {
   mKeyRange = nsnull;
   IndexHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 CountHelper::PackArgumentsForParentProcess(IndexRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_index::CountParams params;
+  FIXME_Bug_521898_index::CountParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_index::KeyRange keyRange;
+    FIXME_Bug_521898_index::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   aParams = params;
@@ -2349,22 +2348,22 @@ CountHelper::MaybeSendResponseToChildPro
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::CountResponse countResponse = mCount;
+    CountResponse countResponse = mCount;
     response = countResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
--- a/dom/indexedDB/IDBKeyRange.cpp
+++ b/dom/indexedDB/IDBKeyRange.cpp
@@ -16,16 +16,17 @@
 #include "nsContentUtils.h"
 
 #include "Key.h"
 
 #include "mozilla/dom/indexedDB/PIndexedDBIndex.h"
 #include "mozilla/dom/indexedDB/PIndexedDBObjectStore.h"
 
 USING_INDEXEDDB_NAMESPACE
+using namespace mozilla::dom::indexedDB::ipc;
 
 namespace {
 
 inline
 bool
 ReturnKeyRange(JSContext* aCx,
                jsval* aVp,
                IDBKeyRange* aKeyRange)
@@ -310,24 +311,18 @@ IDBKeyRange::ToSerializedKeyRange(T& aKe
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(IDBKeyRange)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IDBKeyRange)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange)
-  if (JSVAL_IS_GCTHING(tmp->mCachedLowerVal)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedLowerVal);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedLowerVal")
-  }
-  if (JSVAL_IS_GCTHING(tmp->mCachedUpperVal)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mCachedUpperVal);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mCachedUpperVal")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedLowerVal)
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mCachedUpperVal)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange)
   if (tmp->mRooted) {
     NS_DROP_JS_OBJECTS(tmp, IDBKeyRange);
     tmp->mCachedLowerVal = JSVAL_VOID;
     tmp->mCachedUpperVal = JSVAL_VOID;
     tmp->mHaveCachedLowerVal = false;
@@ -414,22 +409,22 @@ IDBKeyRange::GetUpperOpen(bool* aUpperOp
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   *aUpperOpen = mUpperOpen;
   return NS_OK;
 }
 
 // Explicitly instantiate for all our key range types... Grumble.
 template already_AddRefed<IDBKeyRange>
-IDBKeyRange::FromSerializedKeyRange<ipc::FIXME_Bug_521898_objectstore::KeyRange>
-(const ipc::FIXME_Bug_521898_objectstore::KeyRange& aKeyRange);
+IDBKeyRange::FromSerializedKeyRange<FIXME_Bug_521898_objectstore::KeyRange>
+(const FIXME_Bug_521898_objectstore::KeyRange& aKeyRange);
 
 template already_AddRefed<IDBKeyRange>
-IDBKeyRange::FromSerializedKeyRange<ipc::FIXME_Bug_521898_index::KeyRange>
-(const ipc::FIXME_Bug_521898_index::KeyRange& aKeyRange);
+IDBKeyRange::FromSerializedKeyRange<FIXME_Bug_521898_index::KeyRange>
+(const FIXME_Bug_521898_index::KeyRange& aKeyRange);
 
 template void
-IDBKeyRange::ToSerializedKeyRange<ipc::FIXME_Bug_521898_objectstore::KeyRange>
-(ipc::FIXME_Bug_521898_objectstore::KeyRange& aKeyRange);
+IDBKeyRange::ToSerializedKeyRange<FIXME_Bug_521898_objectstore::KeyRange>
+(FIXME_Bug_521898_objectstore::KeyRange& aKeyRange);
 
 template void
-IDBKeyRange::ToSerializedKeyRange<ipc::FIXME_Bug_521898_index::KeyRange>
-(ipc::FIXME_Bug_521898_index::KeyRange& aKeyRange);
+IDBKeyRange::ToSerializedKeyRange<FIXME_Bug_521898_index::KeyRange>
+(FIXME_Bug_521898_index::KeyRange& aKeyRange);
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -41,24 +41,23 @@
 #include "ipc/IndexedDBChild.h"
 #include "ipc/IndexedDBParent.h"
 
 #include "IndexedDatabaseInlines.h"
 
 #define FILE_COPY_BUFFER_SIZE 32768
 
 USING_INDEXEDDB_NAMESPACE
+using namespace mozilla::dom::indexedDB::ipc;
 
 namespace {
 
 class ObjectStoreHelper : public AsyncConnectionHelper
 {
 public:
-  typedef ipc::ObjectStoreRequestParams ObjectStoreRequestParams;
-
   ObjectStoreHelper(IDBTransaction* aTransaction,
                     IDBRequest* aRequest,
                     IDBObjectStore* aObjectStore)
   : AsyncConnectionHelper(aTransaction, aRequest), mObjectStore(aObjectStore),
     mActor(nsnull)
   {
     NS_ASSERTION(aTransaction, "Null transaction!");
     NS_ASSERTION(aRequest, "Null request!");
@@ -672,25 +671,25 @@ IDBObjectStore::Create(IDBTransaction* a
   objectStore->mAutoIncrement = aStoreInfo->autoIncrement;
   objectStore->mDatabaseId = aDatabaseId;
   objectStore->mInfo = aStoreInfo;
 
   if (!IndexedDatabaseManager::IsMainProcess()) {
     IndexedDBTransactionChild* transactionActor = aTransaction->GetActorChild();
     NS_ASSERTION(transactionActor, "Must have an actor here!");
 
-    ipc::ObjectStoreConstructorParams params;
+    ObjectStoreConstructorParams params;
 
     if (aCreating) {
-      ipc::CreateObjectStoreParams createParams;
+      CreateObjectStoreParams createParams;
       createParams.info() = *aStoreInfo;
       params = createParams;
     }
     else {
-      ipc::GetObjectStoreParams getParams;
+      GetObjectStoreParams getParams;
       getParams.name() = aStoreInfo->name;
       params = getParams;
     }
 
     IndexedDBObjectStoreChild* actor =
       new IndexedDBObjectStoreChild(objectStore);
 
     transactionActor->SendPIndexedDBObjectStoreConstructor(actor, params);
@@ -2774,28 +2773,28 @@ AddHelper::ReleaseMainThreadObjects()
 {
   IDBObjectStore::ClearStructuredCloneBuffer(mCloneWriteInfo.mCloneBuffer);
   ObjectStoreHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 AddHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
-  ipc::AddPutParams commonParams;
+  AddPutParams commonParams;
   commonParams.cloneInfo() = mCloneWriteInfo;
   commonParams.key() = mKey;
   commonParams.indexUpdateInfos().AppendElements(mIndexUpdateInfo);
 
   if (mOverwrite) {
-    ipc::PutParams putParams;
+    PutParams putParams;
     putParams.commonParams() = commonParams;
     aParams = putParams;
   }
   else {
-    ipc::AddParams addParams;
+    AddParams addParams;
     addParams.commonParams() = commonParams;
     aParams = addParams;
   }
 
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
@@ -2804,27 +2803,27 @@ AddHelper::MaybeSendResponseToChildProce
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response =  aResultCode;
   }
   else if (mOverwrite) {
-    ipc::PutResponse putResponse;
+    PutResponse putResponse;
     putResponse.key() = mKey;
     response = putResponse;
   }
   else {
-    ipc::AddResponse addResponse;
+    AddResponse addResponse;
     addResponse.key() = mKey;
     response = addResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
@@ -2904,17 +2903,17 @@ GetHelper::ReleaseMainThreadObjects()
   ObjectStoreHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 GetHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
   NS_ASSERTION(mKeyRange, "This should never be null!");
 
-  ipc::FIXME_Bug_521898_objectstore::GetParams params;
+  FIXME_Bug_521898_objectstore::GetParams params;
 
   mKeyRange->ToSerializedKeyRange(params.keyRange());
 
   aParams = params;
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
@@ -2928,24 +2927,24 @@ GetHelper::MaybeSendResponseToChildProce
     return Success_NotSent;
   }
 
   if (!mCloneReadInfo.mFileInfos.IsEmpty()) {
     NS_WARNING("No support for transferring blobs across processes yet!");
     return Error;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
     SerializedStructuredCloneReadInfo readInfo;
     readInfo = mCloneReadInfo;
-    ipc::GetResponse getResponse = readInfo;
+    GetResponse getResponse = readInfo;
     response = getResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
@@ -3012,17 +3011,17 @@ DeleteHelper::GetSuccessResult(JSContext
   return NS_OK;
 }
 
 nsresult
 DeleteHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
   NS_ASSERTION(mKeyRange, "This should never be null!");
 
-  ipc::DeleteParams params;
+  DeleteParams params;
 
   mKeyRange->ToSerializedKeyRange(params.keyRange());
 
   aParams = params;
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
@@ -3031,22 +3030,22 @@ DeleteHelper::MaybeSendResponseToChildPr
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    response = ipc::DeleteResponse();
+    response = DeleteResponse();
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
 }
@@ -3082,37 +3081,37 @@ ClearHelper::DoDatabaseWork(mozIStorageC
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
   return NS_OK;
 }
 
 nsresult
 ClearHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
-  aParams = ipc::ClearParams();
+  aParams = ClearParams();
   return NS_OK;
 }
 
 HelperBase::ChildProcessSendResult
 ClearHelper::MaybeSendResponseToChildProcess(nsresult aResultCode)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    response = ipc::ClearResponse();
+    response = ClearResponse();
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
 }
@@ -3304,20 +3303,20 @@ OpenCursorHelper::ReleaseMainThreadObjec
 
   ObjectStoreHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 OpenCursorHelper::PackArgumentsForParentProcess(
                                               ObjectStoreRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_objectstore::OpenCursorParams params;
+  FIXME_Bug_521898_objectstore::OpenCursorParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_objectstore::KeyRange keyRange;
+    FIXME_Bug_521898_objectstore::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.direction() = mDirection;
@@ -3347,39 +3346,39 @@ OpenCursorHelper::MaybeSendResponseToChi
   if (NS_SUCCEEDED(aResultCode)) {
     nsresult rv = EnsureCursor();
     if (NS_FAILED(rv)) {
       NS_WARNING("EnsureCursor failed!");
       aResultCode = rv;
     }
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::OpenCursorResponse openCursorResponse;
+    OpenCursorResponse openCursorResponse;
 
     if (!mCursor) {
       openCursorResponse = mozilla::void_t();
     }
     else {
       IndexedDBObjectStoreParent* objectStoreActor =
         mObjectStore->GetActorParent();
       NS_ASSERTION(objectStoreActor, "Must have an actor here!");
 
       IndexedDBRequestParentBase* requestActor = mRequest->GetActorParent();
       NS_ASSERTION(requestActor, "Must have an actor here!");
 
       NS_ASSERTION(mSerializedCloneReadInfo.data &&
                    mSerializedCloneReadInfo.dataLength,
                    "Shouldn't be possible!");
 
-      ipc::ObjectStoreCursorConstructorParams params;
+      ObjectStoreCursorConstructorParams params;
       params.requestParent() = requestActor;
       params.direction() = mDirection;
       params.key() = mKey;
       params.cloneInfo() = mSerializedCloneReadInfo;
 
       IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(mCursor);
 
       if (!objectStoreActor->SendPIndexedDBCursorConstructor(cursorActor,
@@ -3402,30 +3401,30 @@ OpenCursorHelper::MaybeSendResponseToChi
 
 nsresult
 OpenCursorHelper::UnpackResponseFromParentProcess(
                                             const ResponseValue& aResponseValue)
 {
   NS_ASSERTION(aResponseValue.type() == ResponseValue::TOpenCursorResponse,
                "Bad response type!");
   NS_ASSERTION(aResponseValue.get_OpenCursorResponse().type() ==
-               ipc::OpenCursorResponse::Tvoid_t ||
+               OpenCursorResponse::Tvoid_t ||
                aResponseValue.get_OpenCursorResponse().type() ==
-               ipc::OpenCursorResponse::TPIndexedDBCursorChild,
+               OpenCursorResponse::TPIndexedDBCursorChild,
                "Bad response union type!");
   NS_ASSERTION(!mCursor, "Shouldn't have this yet!");
 
-  const ipc::OpenCursorResponse& response =
+  const OpenCursorResponse& response =
     aResponseValue.get_OpenCursorResponse();
 
   switch (response.type()) {
-    case ipc::OpenCursorResponse::Tvoid_t:
+    case OpenCursorResponse::Tvoid_t:
       break;
 
-    case ipc::OpenCursorResponse::TPIndexedDBCursorChild: {
+    case OpenCursorResponse::TPIndexedDBCursorChild: {
       IndexedDBCursorChild* actor =
         static_cast<IndexedDBCursorChild*>(
           response.get_PIndexedDBCursorChild());
 
       mCursor = actor->ForgetStrongCursor();
       NS_ASSERTION(mCursor, "This should never be null!");
 
     } break;
@@ -3745,20 +3744,20 @@ GetAllHelper::ReleaseMainThreadObjects()
       mCloneReadInfos[index].mCloneBuffer);
   }
   ObjectStoreHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 GetAllHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_objectstore::GetAllParams params;
+  FIXME_Bug_521898_objectstore::GetAllParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_objectstore::KeyRange keyRange;
+    FIXME_Bug_521898_objectstore::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   params.limit() = mLimit;
@@ -3780,22 +3779,22 @@ GetAllHelper::MaybeSendResponseToChildPr
 
   for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
     if (!mCloneReadInfos[index].mFileInfos.IsEmpty()) {
       NS_WARNING("No support for transferring blobs across processes yet!");
       return Error;
     }
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::GetAllResponse getAllResponse;
+    GetAllResponse getAllResponse;
 
     InfallibleTArray<SerializedStructuredCloneReadInfo>& infos =
       getAllResponse.cloneInfos();
 
     infos.SetCapacity(mCloneReadInfos.Length());
 
     for (PRUint32 index = 0; index < mCloneReadInfos.Length(); index++) {
       SerializedStructuredCloneReadInfo* info = infos.AppendElement();
@@ -3919,20 +3918,20 @@ CountHelper::ReleaseMainThreadObjects()
 {
   mKeyRange = nsnull;
   ObjectStoreHelper::ReleaseMainThreadObjects();
 }
 
 nsresult
 CountHelper::PackArgumentsForParentProcess(ObjectStoreRequestParams& aParams)
 {
-  ipc::FIXME_Bug_521898_objectstore::CountParams params;
+  FIXME_Bug_521898_objectstore::CountParams params;
 
   if (mKeyRange) {
-    ipc::FIXME_Bug_521898_objectstore::KeyRange keyRange;
+    FIXME_Bug_521898_objectstore::KeyRange keyRange;
     mKeyRange->ToSerializedKeyRange(keyRange);
     params.optionalKeyRange() = keyRange;
   }
   else {
     params.optionalKeyRange() = mozilla::void_t();
   }
 
   aParams = params;
@@ -3945,22 +3944,22 @@ CountHelper::MaybeSendResponseToChildPro
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
 
   IndexedDBRequestParentBase* actor = mRequest->GetActorParent();
   if (!actor) {
     return Success_NotSent;
   }
 
-  ipc::ResponseValue response;
+  ResponseValue response;
   if (NS_FAILED(aResultCode)) {
     response = aResultCode;
   }
   else {
-    ipc::CountResponse countResponse = mCount;
+    CountResponse countResponse = mCount;
     response = countResponse;
   }
 
   if (!actor->Send__delete__(actor, response)) {
     return Error;
   }
 
   return Success_Sent;
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -301,20 +301,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSource)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTransaction)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBRequest, IDBWrapperCache)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
   // nsDOMEventTargetHelper does it for us.
-  if (JSVAL_IS_GCTHING(tmp->mResultVal)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mResultVal);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResultVal")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResultVal)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBRequest)
   NS_INTERFACE_MAP_ENTRY(nsIIDBRequest)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBRequest)
 NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
 
 NS_IMPL_ADDREF_INHERITED(IDBRequest, IDBWrapperCache)
--- a/dom/indexedDB/IDBWrapperCache.cpp
+++ b/dom/indexedDB/IDBWrapperCache.cpp
@@ -24,20 +24,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
     tmp->mScriptOwner = nsnull;
   }
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(IDBWrapperCache,
                                                nsDOMEventTargetHelper)
   // Don't need NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER because
   // nsDOMEventTargetHelper does it for us.
-  if (tmp->mScriptOwner) {
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mScriptOwner,
-                                               "mScriptOwner")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mScriptOwner)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBWrapperCache)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(IDBWrapperCache, nsDOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(IDBWrapperCache, nsDOMEventTargetHelper)
 
--- a/dom/sms/src/SmsRequest.cpp
+++ b/dom/sms/src/SmsRequest.cpp
@@ -39,20 +39,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(success)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCursor)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mError)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(SmsRequest,
                                                nsDOMEventTargetHelper)
-  if (JSVAL_IS_GCTHING(tmp->mResult)) {
-    void *gcThing = JSVAL_TO_GCTHING(tmp->mResult);
-    NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(gcThing, "mResult")
-  }
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mResult)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SmsRequest)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsRequest)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMRequest)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMozSmsRequest)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsRequest)
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -190,17 +190,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   for (PRUint32 index = 0; index < tmp->mCalls.Length(); index++) {
     NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCalls[i]");
     cb.NoteXPCOMChild(tmp->mCalls[index]->ToISupports());
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(Telephony,
                                                nsDOMEventTargetHelper)
-  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->mCallsArray, "mCallsArray")
+  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCallsArray)
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(Telephony,
                                                 nsDOMEventTargetHelper)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(incoming)
   NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(callschanged)
   tmp->mCalls.Clear();
   tmp->mActiveCall = nsnull;
--- 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
@@ -592,18 +592,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
@@ -147,17 +147,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
@@ -244,17 +244,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),
@@ -1724,17 +1724,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) {
@@ -1921,17 +1921,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;
@@ -2013,17 +2013,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/nsDisplayItemTypes.h
+++ b/layout/base/nsDisplayItemTypes.h
@@ -66,16 +66,17 @@ enum Type {
   TYPE_TEXT_DECORATION,
   TYPE_TEXT_OVERFLOW,
   TYPE_TEXT_SHADOW,
   TYPE_TRANSFORM,
   TYPE_VIDEO,
   TYPE_WRAP_LIST,
   TYPE_ZOOM,
   TYPE_EXCLUDE_GLASS_FRAME,
+  TYPE_SIMPLE_SCROLL_LAYER,
 
 #if defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF)
   TYPE_REFLOW_COUNT,
 #endif
 
 #ifdef MOZ_XUL
   TYPE_XUL_EVENT_REDIRECTOR,
   TYPE_XUL_GROUP_BACKGROUND,
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -2067,25 +2067,22 @@ nsDisplayScrollLayer::BuildLayer(nsDispl
     BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
                            aContainerParameters, nsnull);
 
   // Get the already set unique ID for scrolling this content remotely.
   // Or, if not set, generate a new ID.
   nsIContent* content = mScrolledFrame->GetContent();
   ViewID scrollId = nsLayoutUtils::FindIDFor(content);
 
-  nsRect viewport = mScrollFrame->GetRect() -
-                    mScrollFrame->GetPosition() +
-                    aBuilder->ToReferenceFrame(mScrollFrame);
+  nsRect viewport =
+    nsRect(aBuilder->ToReferenceFrame(mScrollFrame), mScrollFrame->GetSize());
 
   bool usingDisplayport = false;
   nsRect displayport;
-  if (content) {
-    usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
-  }
+  usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
   RecordFrameMetrics(mScrolledFrame, mScrollFrame, layer, mVisibleRect, viewport,
                      (usingDisplayport ? &displayport : nsnull), scrollId,
                      aContainerParameters);
 
   return layer.forget();
 }
 
 bool
@@ -2228,16 +2225,81 @@ nsDisplayScrollInfoLayer::ShouldFlattenA
 {
   // Layer metadata for a particular scroll frame needs to be unique. Only
   // one nsDisplayScrollLayer (with rendered content) or one
   // nsDisplayScrollInfoLayer (with only the metadata) should survive the
   // visibility computation. 
   return RemoveScrollLayerCount() == 1;
 }
 
+nsDisplaySimpleScrollLayer::nsDisplaySimpleScrollLayer(nsDisplayListBuilder* aBuilder,
+                                                       nsIFrame* aFrame, nsDisplayList* aList)
+    : nsDisplayWrapList(aBuilder, aFrame, aList) {
+  MOZ_COUNT_CTOR(nsDisplaySimpleScrollLayer);
+}
+
+#ifdef NS_BUILD_REFCNT_LOGGING
+nsDisplaySimpleScrollLayer::~nsDisplaySimpleScrollLayer() {
+  MOZ_COUNT_DTOR(nsDisplaySimpleScrollLayer);
+}
+#endif
+
+already_AddRefed<Layer>
+nsDisplaySimpleScrollLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
+                                       LayerManager* aManager,
+                                       const ContainerParameters& aContainerParameters) {
+  nsRefPtr<ContainerLayer> layer = aBuilder->LayerBuilder()->
+    BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
+                           aContainerParameters, nsnull);
+
+  // Get the already set unique ID for scrolling this content remotely.
+  // Or, if not set, generate a new ID.
+  nsIContent* content = mFrame->PresContext()->Document()->GetRootElement();
+  ViewID scrollId = nsLayoutUtils::FindIDFor(content);
+
+  nsRect viewport = nsRect(ToReferenceFrame(), mFrame->GetSize());
+
+  bool usingDisplayport = false;
+  nsRect displayport;
+  usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
+  RecordFrameMetrics(mFrame, nsnull, layer, mVisibleRect, viewport,
+                     (usingDisplayport ? &displayport : nsnull), scrollId,
+                     aContainerParameters);
+
+  return layer.forget();
+}
+
+bool
+nsDisplaySimpleScrollLayer::ComputeVisibility(nsDisplayListBuilder* aBuilder,
+                                              nsRegion* aVisibleRegion,
+                                              const nsRect& aAllowVisibleRegionExpansion)
+{
+  nsRect displayport;
+  if (nsLayoutUtils::GetDisplayPort(mFrame->PresContext()->Document()->GetRootElement(), &displayport)) {
+    // The visible region for the children may be much bigger than the hole we
+    // are viewing the children from, so that the compositor process has enough
+    // content to asynchronously pan while content is being refreshed.
+
+    nsRegion childVisibleRegion = displayport + ToReferenceFrame();
+
+    nsRect boundedRect =
+      childVisibleRegion.GetBounds().Intersect(mList.GetBounds(aBuilder));
+    nsRect allowExpansion = boundedRect.Intersect(aAllowVisibleRegionExpansion);
+    bool visible = mList.ComputeVisibilityForSublist(
+      aBuilder, &childVisibleRegion, boundedRect, allowExpansion);
+    mVisibleRect = boundedRect;
+
+    return visible;
+
+  } else {
+    return nsDisplayWrapList::ComputeVisibility(aBuilder, aVisibleRegion,
+                                                aAllowVisibleRegionExpansion);
+  }
+}
+
 nsDisplayClip::nsDisplayClip(nsDisplayListBuilder* aBuilder,
                              nsIFrame* aFrame, nsDisplayItem* aItem,
                              const nsRect& aRect)
    : nsDisplayWrapList(aBuilder, aFrame, aItem,
        aFrame == aItem->GetUnderlyingFrame() ? aItem->ToReferenceFrame() : aBuilder->ToReferenceFrame(aFrame)),
      mClip(aRect) {
   MOZ_COUNT_CTOR(nsDisplayClip);
 }
--- a/layout/base/nsDisplayList.h
+++ b/layout/base/nsDisplayList.h
@@ -2011,16 +2011,49 @@ public:
 
   virtual bool TryMerge(nsDisplayListBuilder* aBuilder,
                           nsDisplayItem* aItem);
 
   virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder);
 };
 
 /**
+ * A display item that has no purpose but to ensure its contents get
+ * their own layer and that FrameMetrics are recorded, if the frame's
+ * document's root element has a displayport.
+ */
+class nsDisplaySimpleScrollLayer : public nsDisplayWrapList {
+public:
+  nsDisplaySimpleScrollLayer(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
+                             nsDisplayList* aList);
+#ifdef NS_BUILD_REFCNT_LOGGING
+  virtual ~nsDisplaySimpleScrollLayer();
+#endif
+
+  virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
+                                 nsRegion* aVisibleRegion,
+                                 const nsRect& aAllowVisibleRegionExpansion);
+
+  virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
+                                             LayerManager* aManager,
+                                             const ContainerParameters& aContainerParameters);
+  virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
+                                   LayerManager* aManager,
+                                   const ContainerParameters& aParameters)
+  {
+    return mozilla::LAYER_ACTIVE;
+  }
+  virtual bool TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
+  {
+    return false;
+  }
+  NS_DISPLAY_DECL_NAME("SimpleScrollLayer", TYPE_SIMPLE_SCROLL_LAYER)
+};
+
+/**
  * nsDisplayClip can clip a list of items, but we take a single item
  * initially and then later merge other items into it when we merge
  * adjacent matching nsDisplayClips
  */
 class nsDisplayClip : public nsDisplayWrapList {
 public:
   /**
    * @param aFrame the frame that should be considered the underlying
--- 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
@@ -72,16 +72,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)
 
@@ -1059,17 +1061,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/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -49,16 +49,17 @@
 #include "nsUnicharUtils.h"
 #include "nsIScrollableFrame.h"
 #include "nsIObjectLoadingContent.h"
 #include "nsLayoutUtils.h"
 #include "FrameLayerBuilder.h"
 #include "nsObjectFrame.h"
 #include "nsIServiceManager.h"
 #include "nsContentUtils.h"
+#include "nsIHTMLDocument.h"
 
 #ifdef MOZ_XUL
 #include "nsXULPopupManager.h"
 #endif
 
 // For Accessibility
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
@@ -339,16 +340,37 @@ nsSubDocumentFrame::BuildDisplayList(nsD
       // can monkey with the contents if necessary.
       PRUint32 flags = nsIPresShell::FORCE_DRAW;
       rv = presShell->AddCanvasBackgroundColorItem(
              *aBuilder, childItems, subdocRootFrame ? subdocRootFrame : this,
              bounds, NS_RGBA(0,0,0,0), flags);
     }
   }
 
+  if (subdocRootFrame && !aBuilder->IsForEventDelivery()) {
+    bool framesetUsingDisplayPort = false;
+    nsIDocument* doc = presContext->Document();
+    if (doc) {
+      nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
+      if (htmlDoc && htmlDoc->GetIsFrameset()) {
+        nsIContent* root = doc->GetRootElement();
+        if (root) {
+          framesetUsingDisplayPort = nsLayoutUtils::GetDisplayPort(root, nsnull);
+        }
+      }
+    }
+    // Frameset document's don't have a scroll frame but we still need to
+    // communicate the basic metrics of the document.
+    if (framesetUsingDisplayPort) {
+      nsDisplaySimpleScrollLayer* item =
+        new (aBuilder) nsDisplaySimpleScrollLayer(aBuilder, subdocRootFrame, &childItems);
+      childItems.AppendToTop(item);
+    }
+  }
+
   bool addedLayer = false;
 
   if (subdocRootFrame && parentAPD != subdocAPD) {
     NS_WARN_IF_FALSE(!addedLayer,
                      "Two container layers have been added. "
                       "Performance may suffer.");
     addedLayer = true;
 
--- 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);
--- a/netwerk/protocol/http/nsHttp.h
+++ b/netwerk/protocol/http/nsHttp.h
@@ -15,17 +15,17 @@
 // prlog.h, and #defines LOG in conflict with this file.
 // Solution: (as described in bug 545995)
 // 1) ensure that this file is #included before any IPDL-generated files and
 //    anything else that #includes prlog.h, so that we can make sure prlog.h
 //    sees FORCE_PR_LOG if needed.
 // 2) #include IPDL boilerplate, and then undef LOG so our LOG wins.
 // 3) nsNetModule.cpp does its own crazy stuff with #including prlog.h
 //    multiple times; allow it to define ALLOW_LATE_NSHTTP_H_INCLUDE to bypass
-//    check. 
+//    check.
 #if defined(PR_LOG) && !defined(ALLOW_LATE_NSHTTP_H_INCLUDE)
 #error "If nsHttp.h #included it must come before any IPDL-generated files or other files that #include prlog.h"
 #endif
 #include "mozilla/net/NeckoChild.h"
 #undef LOG
 
 #include "plstr.h"
 #include "prlog.h"
@@ -176,17 +176,17 @@ struct nsHttp
     // Variant on ParseInt64 that expects the input string to contain nothing
     // more than the value being parsed.
     static inline bool ParseInt64(const char *input, PRInt64 *result) {
         const char *next;
         return ParseInt64(input, &next, result) && *next == '\0';
     }
 
     // Declare all atoms
-    // 
+    //
     // The atom names and values are stored in nsHttpAtomList.h and are brought
     // to you by the magic of C preprocessing.  Add new atoms to nsHttpAtomList
     // and all support logic will be auto-generated.
     //
 #define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
 #include "nsHttpAtomList.h"
 #undef HTTP_ATOM
 };
@@ -199,14 +199,14 @@ static inline PRUint32
 PRTimeToSeconds(PRTime t_usec)
 {
     return PRUint32( t_usec / PR_USEC_PER_SEC );
 }
 
 #define NowInSeconds() PRTimeToSeconds(PR_Now())
 
 // round q-value to one decimal place; return most significant digit as uint.
-#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.05) * 10.0))
+#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.0005) * 1000.0))
 
 #define HTTP_LWS " \t"
 #define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
 
 #endif // nsHttp_h__
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -229,17 +229,17 @@ nsHttpHandler::Init()
 
     InitUserAgentComponents();
 
     // monitor some preference changes
     nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefBranch) {
         prefBranch->AddObserver(HTTP_PREF_PREFIX, this, true);
         prefBranch->AddObserver(UA_PREF_PREFIX, this, true);
-        prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true); 
+        prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true);
         prefBranch->AddObserver(NETWORK_ENABLEIDN, this, true);
         prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true);
         prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true);
         prefBranch->AddObserver(TELEMETRY_ENABLED, this, true);
 
         PrefsChanged(prefBranch, nsnull);
     }
 
@@ -285,28 +285,28 @@ nsHttpHandler::Init()
     if (NS_FAILED(rv)) return rv;
 
     mProductSub.AssignLiteral(MOZILLA_UAVERSION);
 
     // Startup the http category
     // Bring alive the objects in the http-protocol-startup category
     NS_CreateServicesFromCategory(NS_HTTP_STARTUP_CATEGORY,
                                   static_cast<nsISupports*>(static_cast<void*>(this)),
-                                  NS_HTTP_STARTUP_TOPIC);    
-    
+                                  NS_HTTP_STARTUP_TOPIC);
+
     mObserverService = mozilla::services::GetObserverService();
     if (mObserverService) {
         mObserverService->AddObserver(this, "profile-change-net-teardown", true);
         mObserverService->AddObserver(this, "profile-change-net-restore", true);
         mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
         mObserverService->AddObserver(this, "net:clear-active-logins", true);
         mObserverService->AddObserver(this, "net:prune-dead-connections", true);
         mObserverService->AddObserver(this, "net:failed-to-process-uri-content", true);
     }
- 
+
     return NS_OK;
 }
 
 nsresult
 nsHttpHandler::InitConnectionMgr()
 {
     NS_TIME_FUNCTION;
 
@@ -358,20 +358,20 @@ nsHttpHandler::AddStandardRequestHeaders
     if (NS_FAILED(rv)) return rv;
 
     // RFC2616 section 19.6.2 states that the "Connection: keep-alive"
     // and "Keep-alive" request headers should not be sent by HTTP/1.1
     // user-agents.  Otherwise, problems with proxy servers (especially
     // transparent proxies) can result.
     //
     // However, we need to send something so that we can use keepalive
-    // with HTTP/1.0 servers/proxies. We use "Proxy-Connection:" when 
+    // with HTTP/1.0 servers/proxies. We use "Proxy-Connection:" when
     // we're talking to an http proxy, and "Connection:" otherwise.
     // We no longer send the Keep-Alive request header.
-    
+
     NS_NAMED_LITERAL_CSTRING(close, "close");
     NS_NAMED_LITERAL_CSTRING(keepAlive, "keep-alive");
 
     const nsACString *connectionType = &close;
     if (caps & NS_HTTP_ALLOW_KEEPALIVE) {
         connectionType = &keepAlive;
     } else if (useProxy) {
         // Bug 92006
@@ -397,17 +397,17 @@ nsHttpHandler::IsAcceptableEncoding(cons
         return false;
 
     // HTTP 1.1 allows servers to send x-gzip and x-compress instead
     // of gzip and compress, for example.  So, we'll always strip off
     // an "x-" prefix before matching the encoding to one we claim
     // to accept.
     if (!PL_strncasecmp(enc, "x-", 2))
         enc += 2;
-    
+
     return nsHttp::FindToken(mAcceptEncodings.get(), enc, HTTP_LWS ",") != nsnull;
 }
 
 nsresult
 nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
 {
     if (!mStreamConvSvc) {
         nsresult rv;
@@ -430,34 +430,34 @@ nsHttpHandler::GetSTSService()
 nsICookieService *
 nsHttpHandler::GetCookieService()
 {
     if (!mCookieService)
         mCookieService = do_GetService(NS_COOKIESERVICE_CONTRACTID);
     return mCookieService;
 }
 
-nsresult 
+nsresult
 nsHttpHandler::GetIOService(nsIIOService** result)
 {
     NS_ADDREF(*result = mIOService);
     return NS_OK;
 }
 
 PRUint32
 nsHttpHandler::Get32BitsOfPseudoRandom()
 {
     // only confirm rand seeding on socket thread
     NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread");
 
     // rand() provides different amounts of PRNG on different platforms.
     // 15 or 31 bits are common amounts.
 
     PR_STATIC_ASSERT(RAND_MAX >= 0xfff);
-    
+
 #if RAND_MAX < 0xffffU
     return ((PRUint16) rand() << 20) |
             (((PRUint16) rand() & 0xfff) << 8) |
             ((PRUint16) rand() & 0xff);
 #elif RAND_MAX < 0xffffffffU
     return ((PRUint16) rand() << 16) | ((PRUint16) rand() & 0xffff);
 #else
     return (PRUint32) rand();
@@ -518,20 +518,20 @@ nsHttpHandler::BuildUserAgent()
     NS_ASSERTION(!mLegacyAppName.IsEmpty() &&
                  !mLegacyAppVersion.IsEmpty() &&
                  !mPlatform.IsEmpty() &&
                  !mOscpu.IsEmpty(),
                  "HTTP cannot send practical requests without this much");
 
     // preallocate to worst-case size, which should always be better
     // than if we didn't preallocate at all.
-    mUserAgent.SetCapacity(mLegacyAppName.Length() + 
-                           mLegacyAppVersion.Length() + 
+    mUserAgent.SetCapacity(mLegacyAppName.Length() +
+                           mLegacyAppVersion.Length() +
 #ifndef UA_SPARE_PLATFORM
-                           mPlatform.Length() + 
+                           mPlatform.Length() +
 #endif
                            mOscpu.Length() +
                            mMisc.Length() +
                            mProduct.Length() +
                            mProductSub.Length() +
                            mAppName.Length() +
                            mAppVersion.Length() +
                            mCompatFirefox.Length() +
@@ -667,17 +667,17 @@ nsHttpHandler::InitUserAgentComponents()
 #endif
     SInt32 majorVersion, minorVersion;
     if ((::Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
         (::Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
         mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion);
     }
 #elif defined (XP_UNIX)
     struct utsname name;
-    
+
     int ret = uname(&name);
     if (ret >= 0) {
         nsCAutoString buf;
         buf =  (char*)name.sysname;
 
         if (strcmp(name.machine, "x86_64") == 0 &&
             sizeof(void *) == sizeof(PRInt32)) {
             // We're running 32-bit code on x86_64. Make this browser
@@ -1010,17 +1010,17 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
 
     if (PREF_CHANGED(HTTP_PREF("accept.default"))) {
         nsXPIDLCString accept;
         rv = prefs->GetCharPref(HTTP_PREF("accept.default"),
                                   getter_Copies(accept));
         if (NS_SUCCEEDED(rv))
             SetAccept(accept);
     }
-    
+
     if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) {
         nsXPIDLCString acceptEncodings;
         rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"),
                                   getter_Copies(acceptEncodings));
         if (NS_SUCCEEDED(rv))
             SetAcceptEncodings(acceptEncodings);
     }
 
@@ -1063,17 +1063,17 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
 
     if (PREF_CHANGED(HTTP_PREF("assoc-req.enforce"))) {
         cVar = false;
         rv = prefs->GetBoolPref(HTTP_PREF("assoc-req.enforce"), &cVar);
         if (NS_SUCCEEDED(rv))
             mEnforceAssocReq = cVar;
     }
 
-    // enable Persistent caching for HTTPS - bug#205921    
+    // enable Persistent caching for HTTPS - bug#205921
     if (PREF_CHANGED(BROWSER_PREF("disk_cache_ssl"))) {
         cVar = false;
         rv = prefs->GetBoolPref(BROWSER_PREF("disk_cache_ssl"), &cVar);
         if (NS_SUCCEEDED(rv))
             mEnablePersistentHttpsCaching = cVar;
     }
 
     if (PREF_CHANGED(HTTP_PREF("phishy-userpass-length"))) {
@@ -1152,17 +1152,17 @@ nsHttpHandler::PrefsChanged(nsIPrefBranc
         prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES,
                                 NS_GET_IID(nsIPrefLocalizedString),
                                 getter_AddRefs(pls));
         if (pls) {
             nsXPIDLString uval;
             pls->ToString(getter_Copies(uval));
             if (uval)
                 SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get());
-        } 
+        }
     }
 
     //
     // IDN options
     //
 
     if (PREF_CHANGED(NETWORK_ENABLEIDN)) {
         bool enableIDN = false;
@@ -1270,18 +1270,18 @@ PrepareAcceptLanguages(const char *i_Acc
         char* trim;
         trim = net_FindCharInSet(token, ";" HTTP_LWS);
         if (trim != (char*)0)  // remove "; q=..." if present
             *trim = '\0';
 
         if (*token != '\0') {
             comma = n++ != 0 ? "," : ""; // delimiter if not first item
             PRUint32 u = QVAL_TO_UINT(q);
-            if (u < 10)
-                wrote = PR_snprintf(p2, available, "%s%s;q=0.%u", comma, token, u);
+            if (u < 1000)
+                wrote = PR_snprintf(p2, available, "%s%s;q=0.%03u", comma, token, u);
             else
                 wrote = PR_snprintf(p2, available, "%s%s", comma, token);
             q -= dec;
             p2 += wrote;
             available -= wrote;
             NS_ASSERTION(available > 0, "allocated string not long enough");
         }
     }
@@ -1289,34 +1289,34 @@ PrepareAcceptLanguages(const char *i_Acc
 
     o_AcceptLanguages.Assign((const char *) q_Accept);
     delete [] q_Accept;
 
     return NS_OK;
 }
 
 nsresult
-nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages) 
+nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
 {
     nsCAutoString buf;
     nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf);
     if (NS_SUCCEEDED(rv))
         mAcceptLanguages.Assign(buf);
     return rv;
 }
 
 nsresult
-nsHttpHandler::SetAccept(const char *aAccept) 
+nsHttpHandler::SetAccept(const char *aAccept)
 {
     mAccept = aAccept;
     return NS_OK;
 }
 
 nsresult
-nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings) 
+nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings)
 {
     mAcceptEncodings = aAcceptEncodings;
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler::nsISupports
 //-----------------------------------------------------------------------------
@@ -1380,24 +1380,24 @@ nsHttpHandler::NewChannel(nsIURI *uri, n
     if (!isHttp) {
         rv = uri->SchemeIs("https", &isHttps);
         if (NS_FAILED(rv)) return rv;
         if (!isHttps) {
             NS_WARNING("Invalid URI scheme");
             return NS_ERROR_UNEXPECTED;
         }
     }
-    
+
     return NewProxiedChannel(uri, nsnull, result);
 }
 
-NS_IMETHODIMP 
+NS_IMETHODIMP
 nsHttpHandler::AllowPort(PRInt32 port, const char *scheme, bool *_retval)
 {
-    // don't override anything.  
+    // don't override anything.
     *_retval = false;
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsHttpHandler::nsIProxiedProtocolHandler
 //-----------------------------------------------------------------------------
 
@@ -1405,17 +1405,17 @@ NS_IMETHODIMP
 nsHttpHandler::NewProxiedChannel(nsIURI *uri,
                                  nsIProxyInfo* givenProxyInfo,
                                  nsIChannel **result)
 {
     nsRefPtr<HttpBaseChannel> httpChannel;
 
     LOG(("nsHttpHandler::NewProxiedChannel [proxyInfo=%p]\n",
         givenProxyInfo));
-    
+
     nsCOMPtr<nsProxyInfo> proxyInfo;
     if (givenProxyInfo) {
         proxyInfo = do_QueryInterface(givenProxyInfo);
         NS_ENSURE_ARG(proxyInfo);
     }
 
     bool https;
     nsresult rv = uri->SchemeIs("https", &https);
@@ -1557,32 +1557,32 @@ nsHttpHandler::Observe(nsISupports *subj
             mConnMgr->PruneDeadConnections();
         }
     }
     else if (strcmp(topic, "net:failed-to-process-uri-content") == 0) {
         nsCOMPtr<nsIURI> uri = do_QueryInterface(subject);
         if (uri && mConnMgr)
             mConnMgr->ReportFailedToProcess(uri);
     }
-  
+
     return NS_OK;
 }
 
 // nsISpeculativeConnect
 
 NS_IMETHODIMP
 nsHttpHandler::SpeculativeConnect(nsIURI *aURI,
                                   nsIInterfaceRequestor *aCallbacks,
                                   nsIEventTarget *aTarget)
 {
     nsIStrictTransportSecurityService* stss = gHttpHandler->GetSTSService();
     bool isStsHost = false;
     if (!stss)
         return NS_OK;
-    
+
     nsCOMPtr<nsIURI> clone;
     if (NS_SUCCEEDED(stss->IsStsURI(aURI, &isStsHost)) && isStsHost) {
         if (NS_SUCCEEDED(aURI->Clone(getter_AddRefs(clone)))) {
             clone->SetScheme(NS_LITERAL_CSTRING("https"));
             aURI = clone.get();
         }
     }
 
@@ -1682,12 +1682,12 @@ nsHttpsHandler::NewChannel(nsIURI *aURI,
     if (!gHttpHandler)
       return NS_ERROR_UNEXPECTED;
     return gHttpHandler->NewChannel(aURI, _retval);
 }
 
 NS_IMETHODIMP
 nsHttpsHandler::AllowPort(PRInt32 aPort, const char *aScheme, bool *_retval)
 {
-    // don't override anything.  
+    // don't override anything.
     *_retval = false;
     return NS_OK;
 }
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_header_Accept-Language.js
@@ -0,0 +1,44 @@
+//
+//  HTTP Accept-Language header test
+//
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+var testpath = "/bug672448";
+
+function run_test() {
+  test_accepted_languages();
+}
+
+function test_accepted_languages() {
+  let channel = setupChannel(testpath);
+
+  let AcceptLanguage = channel.getRequestHeader("Accept-Language");
+
+  let acceptedLanguages = AcceptLanguage.split(",");
+
+  for( let i = 0; i < acceptedLanguages.length; i++ ) {
+    let acceptedLanguage, qualityValue;
+
+    try {
+      [_, acceptedLanguage, qualityValue] = acceptedLanguages[i].trim().match(/^([a-z0-9_-]*?)(?:;q=([0-9.]+))?$/i);
+    } catch(e) {
+      do_print("Invalid language tag or quality value: " + e);
+    }
+
+    if( i == 0 ) {
+      do_check_eq(qualityValue, undefined); // First language shouldn't have a quality value.
+    } else {
+      do_check_eq(qualityValue.length, 5); // All other languages should have quality value of the format '0.123'.
+    }
+  }
+}
+
+function setupChannel(path) {
+  let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
+  let chan = ios.newChannel("http://localhost:4444" + path, "", null);
+  chan.QueryInterface(Ci.nsIHttpChannel);
+  chan.requestMethod = "GET";
+  return chan;
+}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -1,11 +1,11 @@
 [DEFAULT]
 head = head_channels.js
-tail = 
+tail =
 
 [test_307_redirect.js]
 [test_NetUtil.js]
 [test_URIs.js]
 [test_aboutblank.js]
 [test_assoc.js]
 [test_auth_proxy.js]
 [test_authentication.js]
@@ -35,28 +35,28 @@ skip-if = os == "android"
 [test_bug411952.js]
 [test_bug412945.js]
 [test_bug414122.js]
 [test_bug427957.js]
 [test_bug429347.js]
 [test_bug455311.js]
 [test_bug455598.js]
 [test_bug468426.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_bug468594.js]
 [test_bug470716.js]
 [test_bug479413.js]
 [test_bug479485.js]
 [test_bug482601.js]
 [test_bug484684.js]
 [test_bug490095.js]
 [test_bug504014.js]
 [test_bug510359.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_bug515583.js]
 [test_bug528292.js]
 [test_bug540566.js]
 [test_bug543805.js]
 [test_bug553970.js]
 [test_bug561042.js]
 [test_bug561276.js]
@@ -64,26 +64,26 @@ skip-if = os == "android"
 [test_bug586908.js]
 [test_bug596443.js]
 [test_bug618835.js]
 [test_bug633743.js]
 [test_bug650995.js]
 [test_bug652761.js]
 [test_bug651100.js]
 # Bug 675044: test fails consistently on Android
-fail-if = os == "android"  
+fail-if = os == "android"
 [test_bug654926.js]
 # Bug 675049: test fails consistently on Android
-fail-if = os == "android"  
+fail-if = os == "android"
 [test_bug654926_doom_and_read.js]
 # Bug 675049: test fails consistently on Android
-fail-if = os == "android"  
+fail-if = os == "android"
 [test_bug654926_test_seek.js]
 # Bug 675049: test fails consistently on Android
-fail-if = os == "android"  
+fail-if = os == "android"
 [test_bug659569.js]
 [test_bug660066.js]
 [test_bug667907.js]
 [test_bug667818.js]
 [test_bug669001.js]
 [test_bug712914_secinfo_validation.js]
 [test_doomentry.js]
 [test_cacheflags.js]
@@ -94,45 +94,46 @@ fail-if = os == "android"
 [test_content_sniffer.js]
 [test_cookie_header.js]
 [test_data_protocol.js]
 [test_dns_service.js]
 [test_duplicate_headers.js]
 [test_event_sink.js]
 [test_extract_charset_from_content_type.js]
 [test_fallback_no-cache-entry_canceled.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_no-cache-entry_passing.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_redirect-to-different-origin_canceled.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_redirect-to-different-origin_passing.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_request-error_canceled.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_request-error_passing.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_response-error_canceled.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_fallback_response-error_passing.js]
-# Bug 675039: test hangs consistently on Android 
+# Bug 675039: test hangs consistently on Android
 skip-if = os == "android"
 [test_file_partial_inputstream.js]
 [test_file_protocol.js]
 [test_filestreams.js]
 [test_gre_resources.js]
 [test_gzipped_206.js]
 [test_head.js]
+[test_header_Accept-Language.js]
 [test_headers.js]
 [test_http_headers.js]
 [test_httpcancel.js]
 [test_httpsuspend.js]
 [test_idnservice.js]
 [test_localstreams.js]
 [test_mismatch_last-modified.js]
 [test_MIME_params.js]
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -1872,17 +1872,17 @@ nsWindow::GetNonClientMargins(nsIntMargi
   if (mCustomNonClient) {
     margins = mNonClientMargins;
     return NS_OK;
   }
 
   margins.top = GetSystemMetrics(SM_CYCAPTION);
   margins.bottom = GetSystemMetrics(SM_CYFRAME);
   margins.top += margins.bottom;
-  margins.left = margins.right = GetSystemMetrics(SM_CYFRAME);
+  margins.left = margins.right = GetSystemMetrics(SM_CXFRAME);
 
   return NS_OK;
 }
 
 void
 nsWindow::ResetLayout()
 {
   // This will trigger a frame changed event, triggering
--- a/xpcom/glue/nsCycleCollectionParticipant.h
+++ b/xpcom/glue/nsCycleCollectionParticipant.h
@@ -530,16 +530,22 @@ public:
 
 #define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(_object, _name)             \
   if (_object)                                                                 \
     aCallback(_object, _name, aClosure);
 
 #define NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(_field)              \
   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_CALLBACK(tmp->_field, #_field)
 
+#define NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(_field)           \
+  if (JSVAL_IS_TRACEABLE(tmp->_field)) {                                       \
+    void *gcThing = JSVAL_TO_TRACEABLE(tmp->_field);                           \
+    aCallback(gcThing, #_field, aClosure);                                     \
+  }
+
 // NB: The (void)tmp; hack in the TRACE_END macro exists to support
 // implementations that don't need to do anything in their Trace method.
 // Without this hack, some compilers warn about the unused tmp local.
 #define NS_IMPL_CYCLE_COLLECTION_TRACE_END                                     \
       (void)tmp;                                                               \
   }
 
 ///////////////////////////////////////////////////////////////////////////////