Bug 1260651 part.37 Rename nsSelectionState to mozilla::SelectionState (and their file names too) r=mccr8 draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 07 Jul 2016 18:15:53 +0900
changeset 385869 0473bb93cfb9c722b66e2ec50739e3c2d9ce1251
parent 385868 426242e99cc2134436e7d5f85919c0f0fda0dc9d
child 385870 452d5f1a9e4325fc03862190c347d07ee527dc94
push id22587
push usermasayuki@d-toybox.com
push dateSat, 09 Jul 2016 06:59:31 +0000
reviewersmccr8
bugs1260651
milestone50.0a1
Bug 1260651 part.37 Rename nsSelectionState to mozilla::SelectionState (and their file names too) r=mccr8 Note that this fixes some new bustage of nsHTMLEditor. nbsp is conflict with nsWSRunObject.cpp's same name constant. Therefore, I moved it into nsHTMLEditor and rename it to kNBSP. And including some missing header files. MozReview-Commit-ID: hwL8BIbSMQ
editor/libeditor/DeleteNodeTransaction.cpp
editor/libeditor/DeleteTextTransaction.cpp
editor/libeditor/PlaceholderTransaction.cpp
editor/libeditor/PlaceholderTransaction.h
editor/libeditor/SelectionState.cpp
editor/libeditor/SelectionState.h
editor/libeditor/moz.build
editor/libeditor/nsEditor.cpp
editor/libeditor/nsEditor.h
editor/libeditor/nsHTMLDataTransfer.cpp
editor/libeditor/nsHTMLEditRules.h
editor/libeditor/nsHTMLEditor.cpp
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
editor/libeditor/nsIAbsorbingTransaction.h
editor/libeditor/nsPlaintextDataTransfer.cpp
editor/libeditor/nsSelectionState.cpp
editor/libeditor/nsSelectionState.h
editor/libeditor/nsWSRunObject.cpp
--- a/editor/libeditor/DeleteNodeTransaction.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -1,18 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "DeleteNodeTransaction.h"
+#include "SelectionState.h" // nsRangeUpdater
 #include "nsDebug.h"
 #include "nsEditor.h"
 #include "nsError.h"
-#include "nsSelectionState.h" // nsRangeUpdater
 #include "nsAString.h"
 
 namespace mozilla {
 
 DeleteNodeTransaction::DeleteNodeTransaction()
   : mEditor(nullptr)
   , mRangeUpdater(nullptr)
 {
--- a/editor/libeditor/DeleteTextTransaction.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -1,22 +1,22 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "DeleteTextTransaction.h"
+#include "SelectionState.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/Selection.h"
 #include "nsDebug.h"
 #include "nsEditor.h"
 #include "nsError.h"
 #include "nsIEditor.h"
 #include "nsISupportsImpl.h"
-#include "nsSelectionState.h"
 #include "nsAString.h"
 
 namespace mozilla {
 
 using namespace dom;
 
 DeleteTextTransaction::DeleteTextTransaction(
                          nsEditor& aEditor,
--- a/editor/libeditor/PlaceholderTransaction.cpp
+++ b/editor/libeditor/PlaceholderTransaction.cpp
@@ -51,17 +51,17 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END_INHERITING(EditAggregateTransaction)
 
 NS_IMPL_ADDREF_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
 NS_IMPL_RELEASE_INHERITED(PlaceholderTransaction, EditAggregateTransaction)
 
 NS_IMETHODIMP
 PlaceholderTransaction::Init(nsIAtom* aName,
-                             nsSelectionState* aSelState,
+                             SelectionState* aSelState,
                              nsEditor* aEditor)
 {
   NS_ENSURE_TRUE(aEditor && aSelState, NS_ERROR_NULL_POINTER);
 
   mName = aName;
   mStartSel = aSelState;
   mEditor = aEditor;
   return NS_OK;
@@ -212,17 +212,17 @@ PlaceholderTransaction::GetTxnDescriptio
 
 NS_IMETHODIMP
 PlaceholderTransaction::GetTxnName(nsIAtom** aName)
 {
   return GetName(aName);
 }
 
 NS_IMETHODIMP
-PlaceholderTransaction::StartSelectionEquals(nsSelectionState* aSelState,
+PlaceholderTransaction::StartSelectionEquals(SelectionState* aSelState,
                                              bool* aResult)
 {
   // determine if starting selection matches the given selection state.
   // note that we only care about collapsed selections.
   NS_ENSURE_TRUE(aResult && aSelState, NS_ERROR_NULL_POINTER);
   if (!mStartSel->IsCollapsed() || !aSelState->IsCollapsed())
   {
     *aResult = false;
--- a/editor/libeditor/PlaceholderTransaction.h
+++ b/editor/libeditor/PlaceholderTransaction.h
@@ -41,22 +41,22 @@ public:
 
   NS_DECL_EDITTRANSACTIONBASE
 
   NS_IMETHOD RedoTransaction() override;
   NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override;
 
 // ------------ nsIAbsorbingTransaction -----------------------
 
-  NS_IMETHOD Init(nsIAtom* aName, nsSelectionState* aSelState,
+  NS_IMETHOD Init(nsIAtom* aName, SelectionState* aSelState,
                   nsEditor* aEditor) override;
 
   NS_IMETHOD GetTxnName(nsIAtom** aName) override;
 
-  NS_IMETHOD StartSelectionEquals(nsSelectionState* aSelState,
+  NS_IMETHOD StartSelectionEquals(SelectionState* aSelState,
                                   bool* aResult) override;
 
   NS_IMETHOD EndPlaceHolderBatch() override;
 
   NS_IMETHOD ForwardEndBatchTo(
                nsIAbsorbingTransaction* aForwardingAddress) override;
 
   NS_IMETHOD Commit() override;
@@ -75,18 +75,18 @@ protected:
   bool mCommitted;
 
   // These next two members store the state of the selection in a safe way.
   // Selection at the start of the transaction is stored, as is the selection
   // at the end.  This is so that UndoTransaction() and RedoTransaction() can
   // restore the selection properly.
 
   // Use a pointer because this is constructed before we exist.
-  nsAutoPtr<nsSelectionState> mStartSel;
-  nsSelectionState mEndSel;
+  nsAutoPtr<SelectionState> mStartSel;
+  SelectionState mEndSel;
 
   // The editor for this transaction.
   nsEditor* mEditor;
 };
 
 } // namespace mozilla
 
 #endif // #ifndef PlaceholderTransaction_h
rename from editor/libeditor/nsSelectionState.cpp
rename to editor/libeditor/SelectionState.cpp
--- a/editor/libeditor/nsSelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -1,46 +1,51 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
-#include "nsSelectionState.h"
+#include "SelectionState.h"
 
 #include "EditorUtils.h"                // for EditorUtils
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/dom/Selection.h"      // for Selection
 #include "nsAString.h"                  // for nsAString_internal::Length
 #include "nsCycleCollectionParticipant.h"
 #include "nsDebug.h"                    // for NS_ENSURE_TRUE, etc
 #include "nsEditor.h"                   // for nsEditor
 #include "nsError.h"                    // for NS_OK, etc
 #include "nsIContent.h"                 // for nsIContent
 #include "nsIDOMCharacterData.h"        // for nsIDOMCharacterData
 #include "nsIDOMNode.h"                 // for nsIDOMNode
 #include "nsISupportsImpl.h"            // for nsRange::Release
 #include "nsRange.h"                    // for nsRange
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
 
-/***************************************************************************
- * class for recording selection info.  stores selection as collection of
+/******************************************************************************
+ * mozilla::SelectionState
+ *
+ * Class for recording selection info.  Stores selection as collection of
  * { {startnode, startoffset} , {endnode, endoffset} } tuples.  Can't store
  * ranges since dom gravity will possibly change the ranges.
- */
-nsSelectionState::nsSelectionState() : mArray(){}
+ ******************************************************************************/
+SelectionState::SelectionState()
+{
+}
 
-nsSelectionState::~nsSelectionState()
+SelectionState::~SelectionState()
 {
   MakeEmpty();
 }
 
 void
-nsSelectionState::SaveSelection(Selection* aSel)
+SelectionState::SaveSelection(Selection* aSel)
 {
   MOZ_ASSERT(aSel);
   int32_t arrayCount = mArray.Length();
   int32_t rangeCount = aSel->RangeCount();
 
   // if we need more items in the array, new them
   if (arrayCount < rangeCount) {
     for (int32_t i = arrayCount; i < rangeCount; i++) {
@@ -56,17 +61,17 @@ nsSelectionState::SaveSelection(Selectio
 
   // now store the selection ranges
   for (int32_t i = 0; i < rangeCount; i++) {
     mArray[i]->StoreRange(aSel->GetRangeAt(i));
   }
 }
 
 nsresult
-nsSelectionState::RestoreSelection(Selection* aSel)
+SelectionState::RestoreSelection(Selection* aSel)
 {
   NS_ENSURE_TRUE(aSel, NS_ERROR_NULL_POINTER);
   nsresult res;
   uint32_t i, arrayCount = mArray.Length();
 
   // clear out selection
   aSel->RemoveAllRanges();
 
@@ -79,28 +84,28 @@ nsSelectionState::RestoreSelection(Selec
     res = aSel->AddRange(range);
     if(NS_FAILED(res)) return res;
 
   }
   return NS_OK;
 }
 
 bool
-nsSelectionState::IsCollapsed()
+SelectionState::IsCollapsed()
 {
   if (1 != mArray.Length()) return false;
   RefPtr<nsRange> range = mArray[0]->GetRange();
   NS_ENSURE_TRUE(range, false);
   bool bIsCollapsed = false;
   range->GetCollapsed(&bIsCollapsed);
   return bIsCollapsed;
 }
 
 bool
-nsSelectionState::IsEqual(nsSelectionState *aSelState)
+SelectionState::IsEqual(SelectionState* aSelState)
 {
   NS_ENSURE_TRUE(aSelState, false);
   uint32_t i, myCount = mArray.Length(), itsCount = aSelState->mArray.Length();
   if (myCount != itsCount) return false;
   if (myCount < 1) return false;
 
   for (i=0; i<myCount; i++)
   {
@@ -115,28 +120,33 @@ nsSelectionState::IsEqual(nsSelectionSta
     rv = myRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, itsRange, &compResult);
     if (NS_FAILED(rv) || compResult) return false;
   }
   // if we got here, they are equal
   return true;
 }
 
 void
-nsSelectionState::MakeEmpty()
+SelectionState::MakeEmpty()
 {
   // free any items in the array
   mArray.Clear();
 }
 
 bool
-nsSelectionState::IsEmpty()
+SelectionState::IsEmpty()
 {
   return mArray.IsEmpty();
 }
 
+} // namespace mozilla
+
+using namespace mozilla;
+using namespace mozilla::dom;
+
 /***************************************************************************
  * nsRangeUpdater:  class for updating nsRanges in response to editor actions.
  */
 
 nsRangeUpdater::nsRangeUpdater() : mArray(), mLock(false) {}
 
 nsRangeUpdater::~nsRangeUpdater()
 {
@@ -158,31 +168,31 @@ nsRangeUpdater::RegisterRangeItem(nsRang
 void
 nsRangeUpdater::DropRangeItem(nsRangeStore *aRangeItem)
 {
   if (!aRangeItem) return;
   mArray.RemoveElement(aRangeItem);
 }
 
 nsresult
-nsRangeUpdater::RegisterSelectionState(nsSelectionState &aSelState)
+nsRangeUpdater::RegisterSelectionState(SelectionState& aSelState)
 {
   uint32_t i, theCount = aSelState.mArray.Length();
   if (theCount < 1) return NS_ERROR_FAILURE;
 
   for (i=0; i<theCount; i++)
   {
     RegisterRangeItem(aSelState.mArray[i]);
   }
 
   return NS_OK;
 }
 
 nsresult
-nsRangeUpdater::DropSelectionState(nsSelectionState &aSelState)
+nsRangeUpdater::DropSelectionState(SelectionState& aSelState)
 {
   uint32_t i, theCount = aSelState.mArray.Length();
   if (theCount < 1) return NS_ERROR_FAILURE;
 
   for (i=0; i<theCount; i++)
   {
     DropRangeItem(aSelState.mArray[i]);
   }
@@ -622,17 +632,17 @@ nsRangeUpdater::DidMoveNode(nsINode* aOl
       item->endOffset++;
     }
   }
 }
 
 
 
 /***************************************************************************
- * helper class for nsSelectionState.  nsRangeStore stores range endpoints.
+ * helper class for SelectionState.  nsRangeStore stores range endpoints.
  */
 
 nsRangeStore::nsRangeStore()
 {
 }
 nsRangeStore::~nsRangeStore()
 {
 }
rename from editor/libeditor/nsSelectionState.h
rename to editor/libeditor/SelectionState.h
--- a/editor/libeditor/nsSelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -1,25 +1,26 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 __selectionstate_h__
-#define __selectionstate_h__
+#ifndef SelectionState_h
+#define SelectionState_h
 
 #include "nsCOMPtr.h"
 #include "nsIDOMNode.h"
 #include "nsINode.h"
 #include "nsTArray.h"
 #include "nscore.h"
 
 class nsCycleCollectionTraversalCallback;
 class nsIDOMCharacterData;
 class nsRange;
+class nsRangeUpdater;
 namespace mozilla {
 namespace dom {
 class Selection;
 class Text;
 } // namespace dom
 } // namespace mozilla
 
 /***************************************************************************
@@ -45,66 +46,69 @@ public:
   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsRangeStore)
 
   nsCOMPtr<nsINode> startNode;
   int32_t           startOffset;
   nsCOMPtr<nsINode> endNode;
   int32_t           endOffset;
 };
 
-class nsSelectionState
+namespace mozilla {
+
+class SelectionState final
 {
-  public:
-
-    nsSelectionState();
-    ~nsSelectionState();
+public:
+  SelectionState();
+  ~SelectionState();
 
-    void     SaveSelection(mozilla::dom::Selection *aSel);
-    nsresult RestoreSelection(mozilla::dom::Selection* aSel);
-    bool     IsCollapsed();
-    bool     IsEqual(nsSelectionState *aSelState);
-    void     MakeEmpty();
-    bool     IsEmpty();
-  private:
-    nsTArray<RefPtr<nsRangeStore> > mArray;
+  void SaveSelection(dom::Selection *aSel);
+  nsresult RestoreSelection(dom::Selection* aSel);
+  bool IsCollapsed();
+  bool IsEqual(SelectionState *aSelState);
+  void MakeEmpty();
+  bool IsEmpty();
+private:
+  nsTArray<RefPtr<nsRangeStore>> mArray;
 
-    friend class nsRangeUpdater;
-    friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
-                                            nsSelectionState&,
-                                            const char*,
-                                            uint32_t);
-    friend void ImplCycleCollectionUnlink(nsSelectionState&);
+  friend class nsRangeUpdater;
+  friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
+                                          SelectionState&,
+                                          const char*,
+                                          uint32_t);
+  friend void ImplCycleCollectionUnlink(SelectionState&);
 };
 
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
-                            nsSelectionState& aField,
+                            SelectionState& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
   ImplCycleCollectionTraverse(aCallback, aField.mArray, aName, aFlags);
 }
 
 inline void
-ImplCycleCollectionUnlink(nsSelectionState& aField)
+ImplCycleCollectionUnlink(SelectionState& aField)
 {
   ImplCycleCollectionUnlink(aField.mArray);
 }
 
+} // namespace mozilla
+
 class nsRangeUpdater
 {
   public:
 
     nsRangeUpdater();
     ~nsRangeUpdater();
 
     void RegisterRangeItem(nsRangeStore *aRangeItem);
     void DropRangeItem(nsRangeStore *aRangeItem);
-    nsresult RegisterSelectionState(nsSelectionState &aSelState);
-    nsresult DropSelectionState(nsSelectionState &aSelState);
+    nsresult RegisterSelectionState(mozilla::SelectionState& aSelState);
+    nsresult DropSelectionState(mozilla::SelectionState& aSelState);
 
     // editor selection gravity routines.  Note that we can't always depend on
     // DOM Range gravity to do what we want to the "real" selection.  For instance,
     // if you move a node, that corresponds to deleting it and reinserting it.
     // DOM Range gravity will promote the selection out of the node on deletion,
     // which is not what you want if you know you are reinserting it.
     nsresult SelAdjCreateNode(nsINode* aParent, int32_t aPosition);
     nsresult SelAdjCreateNode(nsIDOMNode *aParent, int32_t aPosition);
@@ -160,17 +164,17 @@ ImplCycleCollectionTraverse(nsCycleColle
 
 inline void
 ImplCycleCollectionUnlink(nsRangeUpdater& aField)
 {
   ImplCycleCollectionUnlink(aField.mArray);
 }
 
 /***************************************************************************
- * helper class for using nsSelectionState.  stack based class for doing
+ * helper class for using SelectionState.  stack based class for doing
  * preservation of dom points across editor actions
  */
 
 class MOZ_STACK_CLASS nsAutoTrackDOMPoint
 {
   private:
     nsRangeUpdater &mRU;
     // Allow tracking either nsIDOMNode or nsINode until nsIDOMNode is gone
@@ -219,17 +223,17 @@ class MOZ_STACK_CLASS nsAutoTrackDOMPoin
       }
       *mOffset = mRangeItem->startOffset;
     }
 };
 
 
 
 /******************************************************************************
- * another helper class for nsSelectionState.  stack based class for doing
+ * another helper class for SelectionState.  stack based class for doing
  * Will/DidReplaceContainer()
  */
 
 namespace mozilla {
 namespace dom {
 class MOZ_STACK_CLASS AutoReplaceContainerSelNotify
 {
   private:
@@ -254,17 +258,17 @@ class MOZ_STACK_CLASS AutoReplaceContain
     }
 };
 
 } // namespace dom
 } // namespace mozilla
 
 
 /***************************************************************************
- * another helper class for nsSelectionState.  stack based class for doing
+ * another helper class for SelectionState.  stack based class for doing
  * Will/DidRemoveContainer()
  */
 
 class MOZ_STACK_CLASS nsAutoRemoveContainerSelNotify
 {
   private:
     nsRangeUpdater &mRU;
     nsIDOMNode *mNode;
@@ -289,17 +293,17 @@ class MOZ_STACK_CLASS nsAutoRemoveContai
 
     ~nsAutoRemoveContainerSelNotify()
     {
       mRU.DidRemoveContainer(mNode, mParent, mOffset, mNodeOrigLen);
     }
 };
 
 /***************************************************************************
- * another helper class for nsSelectionState.  stack based class for doing
+ * another helper class for SelectionState.  stack based class for doing
  * Will/DidInsertContainer()
  */
 
 class MOZ_STACK_CLASS nsAutoInsertContainerSelNotify
 {
   private:
     nsRangeUpdater &mRU;
 
@@ -313,17 +317,17 @@ class MOZ_STACK_CLASS nsAutoInsertContai
     ~nsAutoInsertContainerSelNotify()
     {
       mRU.DidInsertContainer();
     }
 };
 
 
 /***************************************************************************
- * another helper class for nsSelectionState.  stack based class for doing
+ * another helper class for SelectionState.  stack based class for doing
  * Will/DidMoveNode()
  */
 
 class MOZ_STACK_CLASS nsAutoMoveNodeSelNotify
 {
   private:
     nsRangeUpdater &mRU;
     nsINode* mOldParent;
@@ -349,11 +353,9 @@ class MOZ_STACK_CLASS nsAutoMoveNodeSelN
     }
 
     ~nsAutoMoveNodeSelNotify()
     {
       mRU.DidMoveNode(mOldParent, mOldOffset, mNewParent, mNewOffset);
     }
 };
 
-#endif
-
-
+#endif // #ifndef SelectionState_h
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -45,22 +45,22 @@ UNIFIED_SOURCES += [
     'nsHTMLEditorEventListener.cpp',
     'nsHTMLEditorStyle.cpp',
     'nsHTMLEditRules.cpp',
     'nsHTMLInlineTableEditor.cpp',
     'nsHTMLObjectResizer.cpp',
     'nsHTMLURIRefObject.cpp',
     'nsPlaintextDataTransfer.cpp',
     'nsPlaintextEditor.cpp',
-    'nsSelectionState.cpp',
     'nsTableEditor.cpp',
     'nsTextEditRules.cpp',
     'nsTextEditRulesBidi.cpp',
     'nsWSRunObject.cpp',
     'PlaceholderTransaction.cpp',
+    'SelectionState.cpp',
     'SetDocumentTitleTransaction.cpp',
     'SplitNodeTransaction.cpp',
     'StyleSheetTransactions.cpp',
     'TextEditorTest.cpp',
     'TextEditUtils.cpp',
     'TypeInState.cpp',
 ]
 
--- a/editor/libeditor/nsEditor.cpp
+++ b/editor/libeditor/nsEditor.cpp
@@ -922,17 +922,17 @@ nsEditor::BeginPlaceHolderTransaction(ns
   {
     NotifyEditorObservers(eNotifyEditorObserversOfBefore);
     // time to turn on the batch
     BeginUpdateViewBatch();
     mPlaceHolderTxn = nullptr;
     mPlaceHolderName = aName;
     RefPtr<Selection> selection = GetSelection();
     if (selection) {
-      mSelState = new nsSelectionState();
+      mSelState = new SelectionState();
       mSelState->SaveSelection(selection);
     }
   }
   mPlaceHolderBatch++;
 
   return NS_OK;
 }
 
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -1,33 +1,33 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 __editor_h__
 #define __editor_h__
 
+#include "SelectionState.h"             // for nsRangeUpdater, etc
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc.
 #include "mozilla/OwningNonNull.h"      // for OwningNonNull
 #include "mozilla/StyleSheetHandle.h"   // for StyleSheetHandle
 #include "mozilla/dom/Text.h"
 #include "nsCOMPtr.h"                   // for already_AddRefed, nsCOMPtr
 #include "nsCycleCollectionParticipant.h"
 #include "nsGkAtoms.h"
 #include "nsIEditor.h"                  // for nsIEditor::EDirection, etc
 #include "nsIEditorIMESupport.h"        // for NS_DECL_NSIEDITORIMESUPPORT, etc
 #include "nsIObserver.h"                // for NS_DECL_NSIOBSERVER, etc
 #include "nsIPhonetic.h"                // for NS_DECL_NSIPHONETIC, etc
 #include "nsIPlaintextEditor.h"         // for nsIPlaintextEditor, etc
 #include "nsISelectionController.h"     // for nsISelectionController constants
 #include "nsISupportsImpl.h"            // for nsEditor::Release, etc
 #include "nsIWeakReferenceUtils.h"      // for nsWeakPtr
 #include "nsLiteralString.h"            // for NS_LITERAL_STRING
-#include "nsSelectionState.h"           // for nsRangeUpdater, etc
 #include "nsString.h"                   // for nsCString
 #include "nsWeakReference.h"            // for nsSupportsWeakReference
 #include "nscore.h"                     // for nsresult, nsAString, etc
 
 class nsIAtom;
 class nsIContent;
 class nsIDOMDocument;
 class nsIDOMEvent;
@@ -845,32 +845,33 @@ protected:
   nsCOMPtr<Element> mRootElement; // cached root node
   RefPtr<Text>    mIMETextNode; // current IME text node
   nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; // The form field as an event receiver
   nsCOMPtr<nsIDOMEventListener> mEventListener;
   nsWeakPtr        mSelConWeak;          // weak reference to the nsISelectionController
   nsWeakPtr        mPlaceHolderTxn;      // weak reference to placeholder for begin/end batch purposes
   nsWeakPtr        mDocWeak;             // weak reference to the nsIDOMDocument
   nsIAtom          *mPlaceHolderName;    // name of placeholder transaction
-  nsSelectionState *mSelState;           // saved selection state for placeholder txn batching
+  // Saved selection state for placeholder transaction batching.
+  mozilla::SelectionState* mSelState;
   nsString         *mPhonetic;
   // IME composition this is not null between compositionstart and
   // compositionend.
   RefPtr<mozilla::TextComposition> mComposition;
 
   // various listeners
   // Listens to all low level actions on the doc
   nsTArray<OwningNonNull<nsIEditActionListener>> mActionListeners;
   // Just notify once per high level change
   nsTArray<OwningNonNull<nsIEditorObserver>> mEditorObservers;
   // Listen to overall doc state (dirty or not, just created, etc)
   nsTArray<OwningNonNull<nsIDocumentStateListener>> mDocStateListeners;
 
-  // cached selection for AutoSelectionRestorer
-  nsSelectionState  mSavedSel;
+  // Cached selection for AutoSelectionRestorer.
+  mozilla::SelectionState mSavedSel;
   nsRangeUpdater    mRangeUpdater;       // utility class object for maintaining preserved ranges
 
   uint32_t          mModCount;     // number of modifications (for undo/redo stack)
   uint32_t          mFlags;        // behavior flags. See nsIPlaintextEditor.idl for the flags we use.
 
   int32_t           mUpdateCount;
 
   int32_t           mPlaceHolderBatch;   // nesting count for batching
--- a/editor/libeditor/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/nsHTMLDataTransfer.cpp
@@ -3,16 +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/. */
 
 #include <string.h>
 
 #include "EditorUtils.h"
 #include "HTMLEditUtils.h"
+#include "SelectionState.h"
 #include "TextEditUtils.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/DOMStringList.h"
 #include "mozilla/OwningNonNull.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Base64.h"
 #include "mozilla/BasicEvents.h"
@@ -67,17 +68,16 @@
 #include "nsIURI.h"
 #include "nsIVariant.h"
 #include "nsLinebreakConverter.h"
 #include "nsLiteralString.h"
 #include "nsNetUtil.h"
 #include "nsPlaintextEditor.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
-#include "nsSelectionState.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nsStringIterator.h"
 #include "nsSubstringTuple.h"
 #include "nsTextEditRules.h"
 #include "nsTreeSanitizer.h"
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -1,24 +1,24 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 nsHTMLEditRules_h__
 #define nsHTMLEditRules_h__
 
+#include "SelectionState.h"
 #include "TypeInState.h"
 #include "nsCOMPtr.h"
 #include "nsEditor.h"
 #include "nsIEditActionListener.h"
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
 #include "nsISupportsImpl.h"
-#include "nsSelectionState.h"
 #include "nsTArray.h"
 #include "nsTextEditRules.h"
 #include "nscore.h"
 
 class nsHTMLEditor;
 class nsIAtom;
 class nsIDOMCharacterData;
 class nsIDOMDocument;
--- a/editor/libeditor/nsHTMLEditor.cpp
+++ b/editor/libeditor/nsHTMLEditor.cpp
@@ -63,16 +63,17 @@
 #include "nsGkAtoms.h"
 #include "nsIWidget.h"
 
 #include "nsIFrame.h"
 #include "nsIParserService.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/Event.h"
 #include "mozilla/dom/EventTarget.h"
 #include "mozilla/dom/HTMLBodyElement.h"
 #include "nsTextFragment.h"
 #include "nsContentList.h"
 #include "mozilla/StyleSheetHandle.h"
 #include "mozilla/StyleSheetHandleInlines.h"
 
 using namespace mozilla;
@@ -874,18 +875,16 @@ Element*
 nsHTMLEditor::GetBlock(nsINode& aNode)
 {
   if (NodeIsBlockStatic(&aNode)) {
     return aNode.AsElement();
   }
   return GetBlockNodeParent(&aNode);
 }
 
-static const char16_t nbsp = 160;
-
 ///////////////////////////////////////////////////////////////////////////////
 // IsNextCharInNodeWhitespace: checks the adjacent content in the same node to
 //                             see if following selection is whitespace or nbsp
 void
 nsHTMLEditor::IsNextCharInNodeWhitespace(nsIContent* aContent,
                                          int32_t aOffset,
                                          bool* outIsSpace,
                                          bool* outIsNBSP,
@@ -900,17 +899,17 @@ nsHTMLEditor::IsNextCharInNodeWhitespace
     *outNode = nullptr;
     *outOffset = -1;
   }
 
   if (aContent->IsNodeOfType(nsINode::eTEXT) &&
       (uint32_t)aOffset < aContent->Length()) {
     char16_t ch = aContent->GetText()->CharAt(aOffset);
     *outIsSpace = nsCRT::IsAsciiSpace(ch);
-    *outIsNBSP = (ch == nbsp);
+    *outIsNBSP = (ch == kNBSP);
     if (outNode && outOffset) {
       NS_IF_ADDREF(*outNode = aContent);
       // yes, this is _past_ the character
       *outOffset = aOffset + 1;
     }
   }
 }
 
@@ -933,17 +932,17 @@ nsHTMLEditor::IsPrevCharInNodeWhitespace
   if (outNode && outOffset) {
     *outNode = nullptr;
     *outOffset = -1;
   }
 
   if (aContent->IsNodeOfType(nsINode::eTEXT) && aOffset > 0) {
     char16_t ch = aContent->GetText()->CharAt(aOffset - 1);
     *outIsSpace = nsCRT::IsAsciiSpace(ch);
-    *outIsNBSP = (ch == nbsp);
+    *outIsNBSP = (ch == kNBSP);
     if (outNode && outOffset) {
       NS_IF_ADDREF(*outNode = aContent);
       *outOffset = aOffset - 1;
     }
   }
 }
 
 
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -25,33 +25,33 @@
 #include "nsHTMLCSSUtils.h"
 
 #include "nsHTMLObjectResizer.h"
 #include "nsIHTMLAbsPosEditor.h"
 #include "nsIHTMLInlineTableEditor.h"
 #include "nsIHTMLObjectResizeListener.h"
 #include "nsIHTMLObjectResizer.h"
 
+#include "nsIContentFilter.h"
 #include "nsIDocumentObserver.h"
 
 #include "nsPoint.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "nsAttrName.h"
 #include "nsStubMutationObserver.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/StyleSheetHandle.h"
 
 class nsDocumentFragment;
 class nsIDOMKeyEvent;
 class nsITransferable;
 class nsIClipboard;
-class nsIContentFilter;
 class nsILinkHandler;
 class nsTableWrapperFrame;
 class nsIDOMRange;
 class nsRange;
 
 namespace mozilla {
 class TypeInState;
 struct PropItem;
@@ -76,16 +76,18 @@ class nsHTMLEditor final : public nsPlai
                            public nsITableEditor,
                            public nsIHTMLInlineTableEditor,
                            public nsIEditorStyleSheets,
                            public nsICSSLoaderObserver,
                            public nsStubMutationObserver
 {
   typedef enum {eNoOp, eReplaceParent=1, eInsertParent=2} BlockTransformationType;
 
+  const char16_t kNBSP = 160;
+
 public:
 
   enum ResizingRequestID
   {
     kX      = 0,
     kY      = 1,
     kWidth  = 2,
     kHeight = 3
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 #include "EditorUtils.h"
 #include "HTMLEditUtils.h"
+#include "SelectionState.h"
 #include "TextEditUtils.h"
 #include "TypeInState.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsAttrName.h"
@@ -29,17 +30,16 @@
 #include "nsIEditor.h"
 #include "nsIEditorIMESupport.h"
 #include "nsNameSpaceManager.h"
 #include "nsINode.h"
 #include "nsISupportsImpl.h"
 #include "nsLiteralString.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
-#include "nsSelectionState.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nsTArray.h"
 #include "nsTextEditRules.h"
 #include "nsUnicharUtils.h"
 #include "nscore.h"
 
 class nsISupports;
--- a/editor/libeditor/nsIAbsorbingTransaction.h
+++ b/editor/libeditor/nsIAbsorbingTransaction.h
@@ -14,36 +14,40 @@ Transaction interface to outside world
 
 #define NS_IABSORBINGTRANSACTION_IID \
 { /* a6cf9116-15b3-11d2-932e-00805f8add32 */ \
     0xa6cf9116, \
     0x15b3, \
     0x11d2, \
     {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
 
-class nsSelectionState;
 class nsIAtom;
 
+namespace mozilla {
+class SelectionState;
+} // namespace mozilla
+
 /**
  * A transaction interface mixin - for transactions that can support.
  * the placeholder absorbtion idiom.
  */
 class nsIAbsorbingTransaction  : public nsISupports{
 public:
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IABSORBINGTRANSACTION_IID)
 
-  NS_IMETHOD Init(nsIAtom* aName, nsSelectionState* aSelState,
+  NS_IMETHOD Init(nsIAtom* aName, mozilla::SelectionState* aSelState,
                   nsEditor* aEditor) = 0;
 
   NS_IMETHOD EndPlaceHolderBatch()=0;
 
   NS_IMETHOD GetTxnName(nsIAtom **aName)=0;
 
-  NS_IMETHOD StartSelectionEquals(nsSelectionState *aSelState, bool *aResult)=0;
+  NS_IMETHOD StartSelectionEquals(mozilla::SelectionState* aSelState,
+                                  bool* aResult) = 0;
 
   NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress)=0;
 
   NS_IMETHOD Commit()=0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIAbsorbingTransaction,
                               NS_IABSORBINGTRANSACTION_IID)
--- a/editor/libeditor/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/nsPlaintextDataTransfer.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "EditorUtils.h"
+#include "SelectionState.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/dom/Selection.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
@@ -34,17 +35,16 @@
 #include "nsIFormControl.h"
 #include "nsIPlaintextEditor.h"
 #include "nsISupportsPrimitives.h"
 #include "nsITransferable.h"
 #include "nsIVariant.h"
 #include "nsLiteralString.h"
 #include "nsPlaintextEditor.h"
 #include "nsRange.h"
-#include "nsSelectionState.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsXPCOM.h"
 #include "nscore.h"
 
 class nsILoadContext;
 class nsISupports;
 
--- a/editor/libeditor/nsWSRunObject.cpp
+++ b/editor/libeditor/nsWSRunObject.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsWSRunObject.h"
 
 #include "EditorUtils.h"
+#include "SelectionState.h"
 #include "TextEditUtils.h"
 
 #include "mozilla/OwningNonNull.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Casting.h"
 #include "mozilla/mozalloc.h"
 
 #include "nsAString.h"
@@ -19,17 +20,16 @@
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsHTMLEditor.h"
 #include "nsIContent.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMNode.h"
 #include "nsISupportsImpl.h"
 #include "nsRange.h"
-#include "nsSelectionState.h"
 #include "nsString.h"
 #include "nsTextFragment.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 const char16_t nbsp = 160;