Bug 1260651 part.49 Rename nsTextEditRules to mozilla::TextEditRules (and also their file names) r=mccr8
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 09 Jul 2016 11:34:41 +0900
changeset 346482 157268e908256b59493e8074f0b277e54aa09c65
parent 346481 9796a9cfbce6acc6bd9a01ff1454737d66d6c83b
child 346483 fb2d027f7f6c62b688ab0ce845fd6ff11b277aa7
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1260651
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1260651 part.49 Rename nsTextEditRules to mozilla::TextEditRules (and also their file names) r=mccr8 MozReview-Commit-ID: DzNeLcT1r1e
dom/html/nsTextEditorState.cpp
editor/libeditor/DeleteNodeTransaction.cpp
editor/libeditor/DeleteTextTransaction.cpp
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/SelectionState.cpp
editor/libeditor/SelectionState.h
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditRulesBidi.cpp
editor/libeditor/TextEditUtils.h
editor/libeditor/WSRunObject.cpp
editor/libeditor/moz.build
editor/libeditor/nsEditor.h
editor/libeditor/nsEditorEventListener.cpp
editor/libeditor/nsHTMLAbsPosition.cpp
editor/libeditor/nsHTMLDataTransfer.cpp
editor/libeditor/nsHTMLEditor.h
editor/libeditor/nsHTMLEditorStyle.cpp
editor/libeditor/nsPlaintextDataTransfer.cpp
editor/libeditor/nsPlaintextEditor.cpp
editor/libeditor/nsPlaintextEditor.h
editor/libeditor/nsTextEditRules.cpp
editor/libeditor/nsTextEditRules.h
editor/libeditor/nsTextEditRulesBidi.cpp
layout/forms/nsTextControlFrame.cpp
layout/xul/tree/nsTreeBodyFrame.cpp
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -30,18 +30,18 @@
 #include "nsIEditorIMESupport.h"
 #include "nsIEditorObserver.h"
 #include "nsIWidget.h"
 #include "nsIDocumentEncoder.h"
 #include "nsISelectionPrivate.h"
 #include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIEditor.h"
-#include "nsTextEditRules.h"
 #include "mozilla/dom/Selection.h"
+#include "mozilla/TextEditRules.h"
 #include "mozilla/EventListenerManager.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsTextNode.h"
 #include "nsIController.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/HTMLInputElement.h"
--- a/editor/libeditor/DeleteNodeTransaction.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -1,15 +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 "DeleteNodeTransaction.h"
-#include "SelectionState.h" // RangeUpdater
+#include "mozilla/SelectionState.h" // RangeUpdater
 #include "nsDebug.h"
 #include "nsEditor.h"
 #include "nsError.h"
 #include "nsAString.h"
 
 namespace mozilla {
 
 DeleteNodeTransaction::DeleteNodeTransaction()
--- a/editor/libeditor/DeleteTextTransaction.cpp
+++ b/editor/libeditor/DeleteTextTransaction.cpp
@@ -1,16 +1,16 @@
 /* -*- 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/SelectionState.h"
 #include "mozilla/dom/Selection.h"
 #include "nsDebug.h"
 #include "nsEditor.h"
 #include "nsError.h"
 #include "nsIEditor.h"
 #include "nsISupportsImpl.h"
 #include "nsAString.h"
 
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -212,36 +212,36 @@ HTMLEditRules::~HTMLEditRules()
   // In some cases, we have already been removed by
   // ~nsHTMLEditor, in which case we will get a null pointer here
   // which we ignore.  But this allows us to add the ability to
   // switch rule sets on the fly if we want.
   if (mHTMLEditor)
     mHTMLEditor->RemoveEditActionListener(this);
 }
 
-NS_IMPL_ADDREF_INHERITED(HTMLEditRules, nsTextEditRules)
-NS_IMPL_RELEASE_INHERITED(HTMLEditRules, nsTextEditRules)
+NS_IMPL_ADDREF_INHERITED(HTMLEditRules, TextEditRules)
+NS_IMPL_RELEASE_INHERITED(HTMLEditRules, TextEditRules)
 NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLEditRules)
   NS_INTERFACE_TABLE_INHERITED(HTMLEditRules, nsIEditActionListener)
-NS_INTERFACE_TABLE_TAIL_INHERITING(nsTextEditRules)
-
-NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLEditRules, nsTextEditRules,
+NS_INTERFACE_TABLE_TAIL_INHERITING(TextEditRules)
+
+NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLEditRules, TextEditRules,
                                    mDocChangeRange, mUtilRange, mNewBlock,
                                    mRangeItem)
 
 NS_IMETHODIMP
 HTMLEditRules::Init(nsPlaintextEditor* aTextEditor)
 {
   InitFields();
 
   mHTMLEditor = static_cast<nsHTMLEditor*>(aTextEditor);
   nsresult res;
 
   // call through to base class Init
-  res = nsTextEditRules::Init(aTextEditor);
+  res = TextEditRules::Init(aTextEditor);
   NS_ENSURE_SUCCESS(res, res);
 
   // cache any prefs we care about
   static const char kPrefName[] =
     "editor.html.typing.returnInEmptyListItemClosesList";
   nsAdoptingCString returnInEmptyLIKillsList =
     Preferences::GetCString(kPrefName);
 
@@ -256,17 +256,17 @@ HTMLEditRules::Init(nsPlaintextEditor* a
   }
 
   NS_ENSURE_STATE(node);
 
   mUtilRange = new nsRange(node);
 
   // set up mDocChangeRange to be whole doc
   // temporarily turn off rules sniffing
-  nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this);
+  nsAutoLockRulesSniffing lockIt(static_cast<TextEditRules*>(this));
   if (!mDocChangeRange) {
     mDocChangeRange = new nsRange(node);
   }
 
   if (node->IsElement()) {
     ErrorResult rv;
     mDocChangeRange->SelectNode(*node, rv);
     NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
@@ -281,17 +281,17 @@ HTMLEditRules::Init(nsPlaintextEditor* a
 
 NS_IMETHODIMP
 HTMLEditRules::DetachEditor()
 {
   if (mHTMLEditor) {
     mHTMLEditor->RemoveEditActionListener(this);
   }
   mHTMLEditor = nullptr;
-  return nsTextEditRules::DetachEditor();
+  return TextEditRules::DetachEditor();
 }
 
 NS_IMETHODIMP
 HTMLEditRules::BeforeEdit(EditAction action,
                           nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) {
     return NS_OK;
@@ -570,17 +570,17 @@ HTMLEditRules::WillDoAction(Selection* a
   // my kingdom for dynamic cast
   nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
 
   // Deal with actions for which we don't need to check whether the selection is
   // editable.
   if (info->action == EditAction::outputText ||
       info->action == EditAction::undo ||
       info->action == EditAction::redo) {
-    return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
+    return TextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
   }
 
   // Nothing to do if there's no selection to act on
   if (!aSelection) {
     return NS_OK;
   }
   NS_ENSURE_TRUE(aSelection->RangeCount(), NS_OK);
 
@@ -647,18 +647,18 @@ HTMLEditRules::WillDoAction(Selection* a
     case EditAction::insertElement:
       WillInsert(*aSelection, aCancel);
       return NS_OK;
     case EditAction::decreaseZIndex:
       return WillRelativeChangeZIndex(aSelection, -1, aCancel, aHandled);
     case EditAction::increaseZIndex:
       return WillRelativeChangeZIndex(aSelection, 1, aCancel, aHandled);
     default:
-      return nsTextEditRules::WillDoAction(aSelection, aInfo,
-                                           aCancel, aHandled);
+      return TextEditRules::WillDoAction(aSelection, aInfo,
+                                         aCancel, aHandled);
   }
 }
 
 NS_IMETHODIMP
 HTMLEditRules::DidDoAction(Selection* aSelection,
                            nsRulesInfo* aInfo,
                            nsresult aResult)
 {
@@ -675,18 +675,18 @@ HTMLEditRules::DidDoAction(Selection* aS
     case EditAction::align:
       return DidMakeBasicBlock(aSelection, aInfo, aResult);
     case EditAction::setAbsolutePosition: {
       nsresult rv = DidMakeBasicBlock(aSelection, aInfo, aResult);
       NS_ENSURE_SUCCESS(rv, rv);
       return DidAbsolutePosition();
     }
     default:
-      // pass thru to nsTextEditRules
-      return nsTextEditRules::DidDoAction(aSelection, aInfo, aResult);
+      // pass through to TextEditRules
+      return TextEditRules::DidDoAction(aSelection, aInfo, aResult);
   }
 }
 
 nsresult
 HTMLEditRules::GetListState(bool* aMixed,
                             bool* aOL,
                             bool* aUL,
                             bool* aDL)
@@ -1165,17 +1165,17 @@ HTMLEditRules::GetFormatString(nsIDOMNod
 }
 
 void
 HTMLEditRules::WillInsert(Selection& aSelection,
                           bool* aCancel)
 {
   MOZ_ASSERT(aCancel);
 
-  nsTextEditRules::WillInsert(aSelection, aCancel);
+  TextEditRules::WillInsert(aSelection, aCancel);
 
   NS_ENSURE_TRUE_VOID(mHTMLEditor);
   nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
 
   // Adjust selection to prevent insertion after a moz-BR.  This next only
   // works for collapsed selections right now, because selection is a pain to
   // work with when not collapsed.  (no good way to extend start or end of
   // selection), so we ignore those types of selections.
@@ -2933,17 +2933,17 @@ HTMLEditRules::DidDeleteSelection(Select
         nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(parent, offset);
         NS_ENSURE_STATE(brNode);
         aSelection->Collapse(parent, offset);
       }
     }
   }
 
   // call through to base class
-  return nsTextEditRules::DidDeleteSelection(aSelection, aDir, aResult);
+  return TextEditRules::DidDeleteSelection(aSelection, aDir, aResult);
 }
 
 nsresult
 HTMLEditRules::WillMakeList(Selection* aSelection,
                             const nsAString* aListType,
                             bool aEntireList,
                             const nsAString* aBulletType,
                             bool* aCancel,
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -1,26 +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 HTMLEditRules_h
 #define HTMLEditRules_h
 
-#include "SelectionState.h"
 #include "TypeInState.h"
+#include "mozilla/SelectionState.h"
+#include "mozilla/TextEditRules.h"
 #include "nsCOMPtr.h"
 #include "nsEditor.h"
 #include "nsIEditActionListener.h"
 #include "nsIEditor.h"
 #include "nsIHTMLEditor.h"
 #include "nsISupportsImpl.h"
 #include "nsTArray.h"
-#include "nsTextEditRules.h"
 #include "nscore.h"
 
 class nsHTMLEditor;
 class nsIAtom;
 class nsIDOMCharacterData;
 class nsIDOMDocument;
 class nsIDOMElement;
 class nsIDOMNode;
@@ -61,22 +61,22 @@ struct StyleCache final : public PropIte
   ~StyleCache()
   {
     MOZ_COUNT_DTOR(StyleCache);
   }
 };
 
 #define SIZE_STYLE_TABLE 19
 
-class HTMLEditRules : public nsTextEditRules
+class HTMLEditRules : public TextEditRules
                     , public nsIEditActionListener
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLEditRules, nsTextEditRules)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLEditRules, TextEditRules)
 
   HTMLEditRules();
 
   // nsIEditRules methods
   NS_IMETHOD Init(nsPlaintextEditor* aTextEditor) override;
   NS_IMETHOD DetachEditor() override;
   NS_IMETHOD BeforeEdit(EditAction action,
                         nsIEditor::EDirection aDirection) override;
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -1,14 +1,14 @@
 /* -*- 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 "SelectionState.h"
+#include "mozilla/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
--- a/editor/libeditor/SelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -1,15 +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/. */
 
-#ifndef SelectionState_h
-#define SelectionState_h
+#ifndef mozilla_SelectionState_h
+#define mozilla_SelectionState_h
 
 #include "nsCOMPtr.h"
 #include "nsIDOMNode.h"
 #include "nsINode.h"
 #include "nsTArray.h"
 #include "nscore.h"
 
 class nsCycleCollectionTraversalCallback;
@@ -349,9 +349,9 @@ public:
   ~AutoMoveNodeSelNotify()
   {
     mRangeUpdater.DidMoveNode(mOldParent, mOldOffset, mNewParent, mNewOffset);
   }
 };
 
 } // namespace mozilla
 
-#endif // #ifndef SelectionState_h
+#endif // #ifndef mozilla_SelectionState_h
rename from editor/libeditor/nsTextEditRules.cpp
rename to editor/libeditor/TextEditRules.cpp
--- a/editor/libeditor/nsTextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -1,23 +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/. */
 
-#include "nsTextEditRules.h"
+#include "mozilla/TextEditRules.h"
 
 #include "EditorUtils.h"
 #include "TextEditUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/dom/Selection.h"
 #include "mozilla/TextComposition.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/NodeIterator.h"
+#include "mozilla/dom/Selection.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsEditor.h"
@@ -32,50 +33,51 @@
 #include "nsIDOMNodeIterator.h"
 #include "nsIDOMNodeList.h"
 #include "nsIDOMText.h"
 #include "nsNameSpaceManager.h"
 #include "nsINode.h"
 #include "nsIPlaintextEditor.h"
 #include "nsISupportsBase.h"
 #include "nsLiteralString.h"
-#include "mozilla/dom/NodeIterator.h"
+#include "nsPlaintextEditor.h"
 #include "nsUnicharUtils.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
 
 #define CANCEL_OPERATION_IF_READONLY_OR_DISABLED \
   if (IsReadonly() || IsDisabled()) \
   {                     \
     *aCancel = true; \
     return NS_OK;       \
   };
 
-
 /********************************************************
- *  Constructor/Destructor
+ * mozilla::TextEditRules
  ********************************************************/
 
-nsTextEditRules::nsTextEditRules()
+TextEditRules::TextEditRules()
   : mEditor(nullptr)
   , mPasswordIMEIndex(0)
   , mCachedSelectionOffset(0)
   , mActionNesting(0)
   , mLockRulesSniffing(false)
   , mDidExplicitlySetInterline(false)
   , mDeleteBidiImmediately(false)
+  , mTheAction(EditAction::none)
   , mLastStart(0)
   , mLastLength(0)
 {
   InitFields();
 }
 
 void
-nsTextEditRules::InitFields()
+TextEditRules::InitFields()
 {
   mEditor = nullptr;
   mPasswordText.Truncate();
   mPasswordIMEText.Truncate();
   mPasswordIMEIndex = 0;
   mBogusNode = nullptr;
   mCachedSelectionNode = nullptr;
   mCachedSelectionOffset = 0;
@@ -84,51 +86,46 @@ nsTextEditRules::InitFields()
   mDidExplicitlySetInterline = false;
   mDeleteBidiImmediately = false;
   mTheAction = EditAction::none;
   mTimer = nullptr;
   mLastStart = 0;
   mLastLength = 0;
 }
 
-nsTextEditRules::~nsTextEditRules()
+TextEditRules::~TextEditRules()
 {
    // do NOT delete mEditor here.  We do not hold a ref count to mEditor.  mEditor owns our lifespan.
 
   if (mTimer)
     mTimer->Cancel();
 }
 
-/********************************************************
- *  XPCOM Cruft
- ********************************************************/
+NS_IMPL_CYCLE_COLLECTION(TextEditRules, mBogusNode, mCachedSelectionNode)
 
-NS_IMPL_CYCLE_COLLECTION(nsTextEditRules, mBogusNode, mCachedSelectionNode)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTextEditRules)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextEditRules)
   NS_INTERFACE_MAP_ENTRY(nsIEditRules)
   NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditRules)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTextEditRules)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTextEditRules)
-
-/********************************************************
- *  Public methods
- ********************************************************/
+NS_IMPL_CYCLE_COLLECTING_ADDREF(TextEditRules)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(TextEditRules)
 
 NS_IMETHODIMP
-nsTextEditRules::Init(nsPlaintextEditor *aEditor)
+TextEditRules::Init(nsPlaintextEditor* aTextEditor)
 {
-  if (!aEditor) { return NS_ERROR_NULL_POINTER; }
+  if (!aTextEditor) {
+    return NS_ERROR_NULL_POINTER;
+  }
 
   InitFields();
 
-  mEditor = aEditor;  // we hold a non-refcounted reference back to our editor
+  // We hold a non-refcounted reference back to our editor.
+  mEditor = aTextEditor;
   RefPtr<Selection> selection = mEditor->GetSelection();
   NS_WARN_IF_FALSE(selection, "editor cannot get selection");
 
   // Put in a magic br if needed. This method handles null selection,
   // which should never happen anyway
   nsresult res = CreateBogusNodeIfNeeded(selection);
   NS_ENSURE_SUCCESS(res, res);
 
@@ -151,37 +148,37 @@ nsTextEditRules::Init(nsPlaintextEditor 
 
   mDeleteBidiImmediately =
     Preferences::GetBool("bidi.edit.delete_immediately", false);
 
   return res;
 }
 
 NS_IMETHODIMP
-nsTextEditRules::SetInitialValue(const nsAString& aValue)
+TextEditRules::SetInitialValue(const nsAString& aValue)
 {
   if (IsPasswordEditor()) {
     mPasswordText = aValue;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTextEditRules::DetachEditor()
+TextEditRules::DetachEditor()
 {
   if (mTimer)
     mTimer->Cancel();
 
   mEditor = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTextEditRules::BeforeEdit(EditAction action,
-                            nsIEditor::EDirection aDirection)
+TextEditRules::BeforeEdit(EditAction action,
+                          nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) return NS_OK;
 
   nsAutoLockRulesSniffing lockIt(this);
   mDidExplicitlySetInterline = false;
   if (!mActionNesting)
   {
     // let rules remember the top level action
@@ -195,20 +192,19 @@ nsTextEditRules::BeforeEdit(EditAction a
   NS_ENSURE_STATE(selection);
 
   selection->GetAnchorNode(getter_AddRefs(mCachedSelectionNode));
   selection->GetAnchorOffset(&mCachedSelectionOffset);
 
   return NS_OK;
 }
 
-
 NS_IMETHODIMP
-nsTextEditRules::AfterEdit(EditAction action,
-                           nsIEditor::EDirection aDirection)
+TextEditRules::AfterEdit(EditAction action,
+                         nsIEditor::EDirection aDirection)
 {
   if (mLockRulesSniffing) return NS_OK;
 
   nsAutoLockRulesSniffing lockIt(this);
 
   NS_PRECONDITION(mActionNesting>0, "bad action nesting!");
   nsresult res = NS_OK;
   if (!--mActionNesting)
@@ -237,22 +233,21 @@ nsTextEditRules::AfterEdit(EditAction ac
     NS_ENSURE_SUCCESS(res, res);
 
     // 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(Selection* aSelection,
-                              nsRulesInfo* aInfo,
-                              bool* aCancel,
-                              bool* aHandled)
+TextEditRules::WillDoAction(Selection* aSelection,
+                            nsRulesInfo* aInfo,
+                            bool* aCancel,
+                            bool* aHandled)
 {
   // null selection is legal
   MOZ_ASSERT(aInfo && aCancel && aHandled);
 
   *aCancel = false;
   *aHandled = false;
 
   // my kingdom for dynamic cast
@@ -287,18 +282,19 @@ nsTextEditRules::WillDoAction(Selection*
       WillInsert(*aSelection, aCancel);
       return NS_OK;
     default:
       return NS_ERROR_FAILURE;
   }
 }
 
 NS_IMETHODIMP
-nsTextEditRules::DidDoAction(Selection* aSelection,
-                             nsRulesInfo *aInfo, nsresult aResult)
+TextEditRules::DidDoAction(Selection* aSelection,
+                           nsRulesInfo* aInfo,
+                           nsresult aResult)
 {
   NS_ENSURE_STATE(mEditor);
   // don't let any txns in here move the selection around behind our back.
   // Note that this won't prevent explicit selection setting from working.
   AutoTransactionsConserveSelection dontSpazMySelection(mEditor);
 
   NS_ENSURE_TRUE(aSelection && aInfo, NS_ERROR_NULL_POINTER);
 
@@ -325,33 +321,27 @@ nsTextEditRules::DidDoAction(Selection* 
     case EditAction::outputText:
       return DidOutputText(aSelection, aResult);
     default:
       // Don't fail on transactions we don't handle here!
       return NS_OK;
   }
 }
 
-
 NS_IMETHODIMP
-nsTextEditRules::DocumentIsEmpty(bool *aDocumentIsEmpty)
+TextEditRules::DocumentIsEmpty(bool* aDocumentIsEmpty)
 {
   NS_ENSURE_TRUE(aDocumentIsEmpty, NS_ERROR_NULL_POINTER);
 
   *aDocumentIsEmpty = (mBogusNode != nullptr);
   return NS_OK;
 }
 
-/********************************************************
- *  Protected methods
- ********************************************************/
-
-
 void
-nsTextEditRules::WillInsert(Selection& aSelection, bool* aCancel)
+TextEditRules::WillInsert(Selection& aSelection, bool* aCancel)
 {
   MOZ_ASSERT(aCancel);
 
   if (IsReadonly() || IsDisabled()) {
     *aCancel = true;
     return;
   }
 
@@ -362,26 +352,27 @@ nsTextEditRules::WillInsert(Selection& a
   if (mBogusNode) {
     NS_ENSURE_TRUE_VOID(mEditor);
     mEditor->DeleteNode(mBogusNode);
     mBogusNode = nullptr;
   }
 }
 
 nsresult
-nsTextEditRules::DidInsert(Selection* aSelection, nsresult aResult)
+TextEditRules::DidInsert(Selection* aSelection,
+                         nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::WillInsertBreak(Selection* aSelection,
-                                 bool *aCancel,
-                                 bool *aHandled,
-                                 int32_t aMaxLength)
+TextEditRules::WillInsertBreak(Selection* aSelection,
+                               bool* aCancel,
+                               bool* aHandled,
+                               int32_t aMaxLength)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   *aHandled = false;
   if (IsSingleLineEditor()) {
     *aCancel = true;
   }
   else
@@ -417,35 +408,36 @@ nsTextEditRules::WillInsertBreak(Selecti
     // we want to ignore result of WillInsert()
     *aCancel = false;
 
   }
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidInsertBreak(Selection* aSelection, nsresult aResult)
+TextEditRules::DidInsertBreak(Selection* aSelection,
+                              nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection)
+TextEditRules::CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection)
 {
   // we only need to execute the stuff below if we are a plaintext editor.
   // html editors have a different mechanism for putting in mozBR's
   // (because there are a bunch more places you have to worry about it in html)
   if (!IsPlaintextEditor()) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mEditor);
 
   // If there is no selection ranges, we should set to the end of the editor.
-  // This is usually performed in nsTextEditRules::Init(), however, if the
+  // This is usually performed in TextEditRules::Init(), however, if the
   // editor is reframed, this may be called by AfterEdit().
   if (!aSelection->RangeCount()) {
     mEditor->EndOfDocument();
   }
 
   // if we are at the end of the textarea, we need to set the
   // selection to stick to the mozBR at the end of the textarea.
   int32_t selOffset;
@@ -513,18 +505,18 @@ GetTextNode(Selection* selection, nsEdit
                  "password length not equal to number of asterisks");  \
   }
 #else
 #define ASSERT_PASSWORD_LENGTHS_EQUAL()
 #endif
 
 // static
 void
-nsTextEditRules::HandleNewLines(nsString &aString,
-                                int32_t aNewlineHandling)
+TextEditRules::HandleNewLines(nsString& aString,
+                              int32_t aNewlineHandling)
 {
   if (aNewlineHandling < 0) {
     int32_t caretStyle;
     nsPlaintextEditor::GetDefaultEditorPrefs(aNewlineHandling, caretStyle);
   }
 
   switch(aNewlineHandling)
   {
@@ -584,23 +576,23 @@ nsTextEditRules::HandleNewLines(nsString
   case nsIPlaintextEditor::eNewlinesPasteIntact:
     // even if we're pasting newlines, don't paste leading/trailing ones
     aString.Trim(CRLF, true, true);
     break;
   }
 }
 
 nsresult
-nsTextEditRules::WillInsertText(EditAction aAction,
-                                Selection* aSelection,
-                                bool            *aCancel,
-                                bool            *aHandled,
-                                const nsAString *inString,
-                                nsAString *outString,
-                                int32_t          aMaxLength)
+TextEditRules::WillInsertText(EditAction aAction,
+                              Selection* aSelection,
+                              bool* aCancel,
+                              bool* aHandled,
+                              const nsAString* inString,
+                              nsAString* outString,
+                              int32_t aMaxLength)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
 
   if (inString->IsEmpty() && aAction != EditAction::insertIMEText) {
     // HACK: this is a fix for bug 19395
     // I can't outlaw all empty insertions
     // because IME transaction depend on them
     // There is more work to do to make the
@@ -765,68 +757,73 @@ nsTextEditRules::WillInsertText(EditActi
       aSelection->Collapse(curNode, curOffset);
     }
   }
   ASSERT_PASSWORD_LENGTHS_EQUAL()
   return res;
 }
 
 nsresult
-nsTextEditRules::DidInsertText(Selection* aSelection, nsresult aResult)
+TextEditRules::DidInsertText(Selection* aSelection,
+                             nsresult aResult)
 {
   return DidInsert(aSelection, aResult);
 }
 
 
 
 nsresult
-nsTextEditRules::WillSetTextProperty(Selection* aSelection, bool* aCancel,
-                                     bool* aHandled)
+TextEditRules::WillSetTextProperty(Selection* aSelection,
+                                   bool* aCancel,
+                                   bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled)
     { return NS_ERROR_NULL_POINTER; }
 
   // XXX: should probably return a success value other than NS_OK that means "not allowed"
   if (IsPlaintextEditor()) {
     *aCancel = true;
   }
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidSetTextProperty(Selection* aSelection, nsresult aResult)
+TextEditRules::DidSetTextProperty(Selection* aSelection,
+                                  nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::WillRemoveTextProperty(Selection* aSelection, bool* aCancel,
-                                        bool* aHandled)
+TextEditRules::WillRemoveTextProperty(Selection* aSelection,
+                                      bool* aCancel,
+                                      bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled)
     { return NS_ERROR_NULL_POINTER; }
 
   // XXX: should probably return a success value other than NS_OK that means "not allowed"
   if (IsPlaintextEditor()) {
     *aCancel = true;
   }
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidRemoveTextProperty(Selection* aSelection, nsresult aResult)
+TextEditRules::DidRemoveTextProperty(Selection* aSelection,
+                                     nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::WillDeleteSelection(Selection* aSelection,
-                                     nsIEditor::EDirection aCollapsedAction,
-                                     bool *aCancel,
-                                     bool *aHandled)
+TextEditRules::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
   *aCancel = false;
   *aHandled = false;
 
@@ -913,19 +910,19 @@ nsTextEditRules::WillDeleteSelection(Sel
   NS_ENSURE_SUCCESS(res, res);
 
   *aHandled = true;
   ASSERT_PASSWORD_LENGTHS_EQUAL()
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidDeleteSelection(Selection* aSelection,
-                                    nsIEditor::EDirection aCollapsedAction,
-                                    nsresult aResult)
+TextEditRules::DidDeleteSelection(Selection* aSelection,
+                                  nsIEditor::EDirection aCollapsedAction,
+                                  nsresult aResult)
 {
   nsCOMPtr<nsIDOMNode> startNode;
   int32_t startOffset;
   NS_ENSURE_STATE(mEditor);
   nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
 
@@ -949,33 +946,38 @@ nsTextEditRules::DidDeleteSelection(Sele
     // We prevent the caret from sticking on the left of prior BR
     // (i.e. the end of previous line) after this deletion.  Bug 92124
     res = aSelection->SetInterlinePosition(true);
   }
   return res;
 }
 
 nsresult
-nsTextEditRules::WillUndo(Selection* aSelection, bool* aCancel, bool* aHandled)
+TextEditRules::WillUndo(Selection* aSelection,
+                        bool* aCancel,
+                        bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   // initialize out param
   *aCancel = false;
   *aHandled = false;
   return NS_OK;
 }
 
-/* the idea here is to see if the magic empty node has suddenly reappeared as the result of the undo.
- * if it has, set our state so we remember it.
- * There is a tradeoff between doing here and at redo, or doing it everywhere else that might care.
- * Since undo and redo are relatively rare, it makes sense to take the (small) performance hit here.
+/**
+ * The idea here is to see if the magic empty node has suddenly reappeared as
+ * the result of the undo.  If it has, set our state so we remember it.
+ * There is a tradeoff between doing here and at redo, or doing it everywhere
+ * else that might care.  Since undo and redo are relatively rare, it makes
+ * sense to take the (small) performance hit here.
  */
 nsresult
-nsTextEditRules::DidUndo(Selection* aSelection, nsresult aResult)
+TextEditRules::DidUndo(Selection* aSelection,
+                       nsresult aResult)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // If aResult is an error, we return it.
   NS_ENSURE_SUCCESS(aResult, aResult);
 
   NS_ENSURE_STATE(mEditor);
   dom::Element* theRoot = mEditor->GetRoot();
   NS_ENSURE_TRUE(theRoot, NS_ERROR_FAILURE);
@@ -984,28 +986,31 @@ nsTextEditRules::DidUndo(Selection* aSel
     mBogusNode = do_QueryInterface(node);
   } else {
     mBogusNode = nullptr;
   }
   return aResult;
 }
 
 nsresult
-nsTextEditRules::WillRedo(Selection* aSelection, bool* aCancel, bool* aHandled)
+TextEditRules::WillRedo(Selection* aSelection,
+                        bool* aCancel,
+                        bool* aHandled)
 {
   if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   // initialize out param
   *aCancel = false;
   *aHandled = false;
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidRedo(Selection* aSelection, nsresult aResult)
+TextEditRules::DidRedo(Selection* aSelection,
+                       nsresult aResult)
 {
   nsresult res = aResult;  // if aResult is an error, we return it.
   if (!aSelection) { return NS_ERROR_NULL_POINTER; }
   if (NS_SUCCEEDED(res))
   {
     NS_ENSURE_STATE(mEditor);
     nsCOMPtr<nsIDOMElement> theRoot = do_QueryInterface(mEditor->GetRoot());
     NS_ENSURE_TRUE(theRoot, NS_ERROR_FAILURE);
@@ -1035,21 +1040,21 @@ nsTextEditRules::DidRedo(Selection* aSel
         mBogusNode = nullptr;
       }
     }
   }
   return res;
 }
 
 nsresult
-nsTextEditRules::WillOutputText(Selection* aSelection,
-                                const nsAString  *aOutputFormat,
-                                nsAString *aOutString,
-                                bool     *aCancel,
-                                bool     *aHandled)
+TextEditRules::WillOutputText(Selection* aSelection,
+                              const nsAString* aOutputFormat,
+                              nsAString* aOutString,
+                              bool* aCancel,
+                              bool* aHandled)
 {
   // null selection ok
   if (!aOutString || !aOutputFormat || !aCancel || !aHandled)
     { return NS_ERROR_NULL_POINTER; }
 
   // initialize out param
   *aCancel = false;
   *aHandled = false;
@@ -1068,23 +1073,24 @@ nsTextEditRules::WillOutputText(Selectio
       aOutString->Truncate();
       *aHandled = true;
     }
   }
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::DidOutputText(Selection* aSelection, nsresult aResult)
+TextEditRules::DidOutputText(Selection* aSelection,
+                             nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::RemoveRedundantTrailingBR()
+TextEditRules::RemoveRedundantTrailingBR()
 {
   // If the bogus node exists, we have no work to do
   if (mBogusNode)
     return NS_OK;
 
   // Likewise, nothing to be done if we could never have inserted a trailing br
   if (IsSingleLineEditor())
     return NS_OK;
@@ -1119,17 +1125,17 @@ nsTextEditRules::RemoveRedundantTrailing
 
   // give it the bogus node attribute
   elem->SetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom,
                 kMOZEditorBogusNodeValue, false);
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::CreateTrailingBRIfNeeded()
+TextEditRules::CreateTrailingBRIfNeeded()
 {
   // but only if we aren't a single line edit field
   if (IsSingleLineEditor()) {
     return NS_OK;
   }
 
   NS_ENSURE_STATE(mEditor);
   dom::Element* body = mEditor->GetRoot();
@@ -1154,17 +1160,17 @@ nsTextEditRules::CreateTrailingBRIfNeede
   // Morph it back to a mozBR
   lastChild->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
   lastChild->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                      NS_LITERAL_STRING("_moz"), true);
   return NS_OK;
 }
 
 nsresult
-nsTextEditRules::CreateBogusNodeIfNeeded(Selection* aSelection)
+TextEditRules::CreateBogusNodeIfNeeded(Selection* aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(mEditor, NS_ERROR_NULL_POINTER);
 
   if (mBogusNode) {
     // Let's not create more than one, ok?
     return NS_OK;
   }
@@ -1216,21 +1222,21 @@ nsTextEditRules::CreateBogusNodeIfNeeded
 
   // Set selection.
   aSelection->CollapseNative(body, 0);
   return NS_OK;
 }
 
 
 nsresult
-nsTextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
-                                           const nsAString  *aInString,
-                                           nsAString  *aOutString,
-                                           int32_t          aMaxLength,
-                                           bool *aTruncated)
+TextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
+                                         const nsAString* aInString,
+                                         nsAString* aOutString,
+                                         int32_t aMaxLength,
+                                         bool* aTruncated)
 {
   if (!aSelection || !aInString || !aOutString) {return NS_ERROR_NULL_POINTER;}
 
   nsresult res = NS_OK;
   if (!aOutString->Assign(*aInString, mozilla::fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   if (aTruncated) {
@@ -1297,52 +1303,56 @@ nsTextEditRules::TruncateInsertionIfNeed
         }
       }
     }
   }
   return res;
 }
 
 void
-nsTextEditRules::ResetIMETextPWBuf()
+TextEditRules::ResetIMETextPWBuf()
 {
   mPasswordIMEText.Truncate();
 }
 
 void
-nsTextEditRules::RemoveIMETextFromPWBuf(int32_t &aStart, nsAString *aIMEString)
+TextEditRules::RemoveIMETextFromPWBuf(int32_t& aStart,
+                                      nsAString* aIMEString)
 {
   MOZ_ASSERT(aIMEString);
 
   // initialize PasswordIME
   if (mPasswordIMEText.IsEmpty()) {
     mPasswordIMEIndex = aStart;
   }
   else {
     // manage the password buffer
     mPasswordText.Cut(mPasswordIMEIndex, mPasswordIMEText.Length());
     aStart = mPasswordIMEIndex;
   }
 
   mPasswordIMEText.Assign(*aIMEString);
 }
 
-NS_IMETHODIMP nsTextEditRules::Notify(nsITimer *)
+NS_IMETHODIMP
+TextEditRules::Notify(nsITimer* aTimer)
 {
   MOZ_ASSERT(mTimer);
 
   // Check whether our text editor's password flag was changed before this
   // "hide password character" timer actually fires.
   nsresult res = IsPasswordEditor() ? HideLastPWInput() : NS_OK;
   ASSERT_PASSWORD_LENGTHS_EQUAL();
   mLastLength = 0;
   return res;
 }
 
-nsresult nsTextEditRules::HideLastPWInput() {
+nsresult
+TextEditRules::HideLastPWInput()
+{
   if (!mLastLength) {
     // Special case, we're trying to replace a range that no longer exists
     return NS_OK;
   }
 
   nsAutoString hiddenText;
   FillBufWithPWChars(&hiddenText, mLastLength);
 
@@ -1363,36 +1373,37 @@ nsresult nsTextEditRules::HideLastPWInpu
   selection->Collapse(selNode, start);
   if (start != end)
     selection->Extend(selNode, end);
   return NS_OK;
 }
 
 // static
 void
-nsTextEditRules::FillBufWithPWChars(nsAString *aOutString, int32_t aLength)
+TextEditRules::FillBufWithPWChars(nsAString* aOutString,
+                                  int32_t aLength)
 {
   MOZ_ASSERT(aOutString);
 
   // change the output to the platform password character
   char16_t passwordChar = LookAndFeel::GetPasswordCharacter();
 
   int32_t i;
   aOutString->Truncate();
   for (i=0; i < aLength; i++)
     aOutString->Append(passwordChar);
 }
 
-
-///////////////////////////////////////////////////////////////////////////
-// CreateMozBR: put a BR node with moz attribute at {aNode, aOffset}
-//
+/**
+ * CreateMozBR() puts a BR node with moz attribute at {inParent, inOffset}.
+ */
 nsresult
-nsTextEditRules::CreateMozBR(nsIDOMNode* inParent, int32_t inOffset,
-                             nsIDOMNode** outBRNode)
+TextEditRules::CreateMozBR(nsIDOMNode* inParent,
+                           int32_t inOffset,
+                           nsIDOMNode** outBRNode)
 {
   NS_ENSURE_TRUE(inParent, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIDOMNode> brNode;
   NS_ENSURE_STATE(mEditor);
   nsresult res = mEditor->CreateBR(inParent, inOffset, address_of(brNode));
   NS_ENSURE_SUCCESS(res, res);
 
@@ -1405,12 +1416,55 @@ nsTextEditRules::CreateMozBR(nsIDOMNode*
 
   if (outBRNode) {
     brNode.forget(outBRNode);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsTextEditRules::DocumentModified()
+TextEditRules::DocumentModified()
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
+
+bool
+TextEditRules::IsPasswordEditor() const
+{
+  return mEditor ? mEditor->IsPasswordEditor() : false;
+}
+
+bool
+TextEditRules::IsSingleLineEditor() const
+{
+  return mEditor ? mEditor->IsSingleLineEditor() : false;
+}
+
+bool
+TextEditRules::IsPlaintextEditor() const
+{
+  return mEditor ? mEditor->IsPlaintextEditor() : false;
+}
+
+bool
+TextEditRules::IsReadonly() const
+{
+  return mEditor ? mEditor->IsReadonly() : false;
+}
+
+bool
+TextEditRules::IsDisabled() const
+{
+  return mEditor ? mEditor->IsDisabled() : false;
+}
+bool
+TextEditRules::IsMailEditor() const
+{
+  return mEditor ? mEditor->IsMailEditor() : false;
+}
+
+bool
+TextEditRules::DontEchoPassword() const
+{
+  return mEditor ? mEditor->DontEchoPassword() : false;
+}
+
+} // namespace mozilla
rename from editor/libeditor/nsTextEditRules.h
rename to editor/libeditor/TextEditRules.h
--- a/editor/libeditor/nsTextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -1,77 +1,81 @@
 /* -*- 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 nsTextEditRules_h__
-#define nsTextEditRules_h__
+#ifndef mozilla_TextEditRules_h
+#define mozilla_TextEditRules_h
 
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsEditRules.h"
 #include "nsEditor.h"
 #include "nsIEditor.h"
 #include "nsISupportsImpl.h"
 #include "nsITimer.h"
-#include "nsPlaintextEditor.h"
 #include "nsString.h"
 #include "nscore.h"
 
+class nsAutoLockRulesSniffing;
 class nsIDOMElement;
 class nsIDOMNode;
+class nsPlaintextEditor;
+
 namespace mozilla {
+
 namespace dom {
 class Selection;
 } // namespace dom
-} // namespace mozilla
 
-/** Object that encapsulates HTML text-specific editing rules.
-  *
-  * To be a good citizen, edit rules must live by these restrictions:
-  * 1. All data manipulation is through the editor.
-  *    Content nodes in the document tree must <B>not</B> be manipulated directly.
-  *    Content nodes in document fragments that are not part of the document itself
-  *    may be manipulated at will.  Operations on document fragments must <B>not</B>
-  *    go through the editor.
-  * 2. Selection must not be explicitly set by the rule method.
-  *    Any manipulation of Selection must be done by the editor.
-  */
-class nsTextEditRules : public nsIEditRules, public nsITimerCallback
+/**
+ * Object that encapsulates HTML text-specific editing rules.
+ *
+ * To be a good citizen, edit rules must live by these restrictions:
+ * 1. All data manipulation is through the editor.
+ *    Content nodes in the document tree must <B>not</B> be manipulated
+ *    directly.  Content nodes in document fragments that are not part of the
+ *    document itself may be manipulated at will.  Operations on document
+ *    fragments must <B>not</B> go through the editor.
+ * 2. Selection must not be explicitly set by the rule method.
+ *    Any manipulation of Selection must be done by the editor.
+ */
+class TextEditRules : public nsIEditRules
+                    , public nsITimerCallback
 {
 public:
-  typedef mozilla::dom::Element       Element;
-  typedef mozilla::dom::Selection     Selection;
-  typedef mozilla::dom::Text          Text;
-  template<typename T> using OwningNonNull = mozilla::OwningNonNull<T>;
+  typedef dom::Element Element;
+  typedef dom::Selection Selection;
+  typedef dom::Text Text;
+  template<typename T> using OwningNonNull = OwningNonNull<T>;
 
   NS_DECL_NSITIMERCALLBACK
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsTextEditRules, nsIEditRules)
+  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TextEditRules, nsIEditRules)
 
-  nsTextEditRules();
+  TextEditRules();
 
   // nsIEditRules methods
-  NS_IMETHOD Init(nsPlaintextEditor *aEditor) override;
+  NS_IMETHOD Init(nsPlaintextEditor* aTextEditor) override;
   NS_IMETHOD SetInitialValue(const nsAString& aValue) override;
   NS_IMETHOD DetachEditor() override;
   NS_IMETHOD BeforeEdit(EditAction action,
                         nsIEditor::EDirection aDirection) override;
   NS_IMETHOD AfterEdit(EditAction action,
                        nsIEditor::EDirection aDirection) override;
   NS_IMETHOD WillDoAction(Selection* aSelection, nsRulesInfo* aInfo,
                           bool* aCancel, bool* aHandled) override;
   NS_IMETHOD DidDoAction(Selection* aSelection, nsRulesInfo* aInfo,
                          nsresult aResult) override;
-  NS_IMETHOD DocumentIsEmpty(bool *aDocumentIsEmpty) override;
+  NS_IMETHOD DocumentIsEmpty(bool* aDocumentIsEmpty) override;
   NS_IMETHOD DocumentModified() override;
 
 protected:
-  virtual ~nsTextEditRules();
+  virtual ~TextEditRules();
 
 public:
   void ResetIMETextPWBuf();
 
   /**
    * Handles the newline characters either according to aNewLineHandling
    * or to the default system prefs if aNewLineHandling is negative.
    *
@@ -88,56 +92,56 @@ public:
    *        * nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace:
    *          collapse newlines and surrounding whitespace characters and
    *          remove them from the string.
    *        * nsIPlaintextEditor::eNewlinesPasteIntact:
    *          only remove the leading and trailing newlines.
    *        * nsIPlaintextEditor::eNewlinesPasteToFirst or any other value:
    *          remove the first newline and all characters following it.
    */
-  static void HandleNewLines(nsString &aString, int32_t aNewLineHandling);
+  static void HandleNewLines(nsString& aString, int32_t aNewLineHandling);
 
   /**
    * Prepare a string buffer for being displayed as the contents of a password
    * field.  This function uses the platform-specific character for representing
    * characters entered into password fields.
    *
    * @param aOutString the output string.  When this function returns,
    *        aOutString will contain aLength password characters.
    * @param aLength the number of password characters that aOutString should
    *        contain.
    */
-  static void FillBufWithPWChars(nsAString *aOutString, int32_t aLength);
+  static void FillBufWithPWChars(nsAString* aOutString, int32_t aLength);
 
 protected:
 
   void InitFields();
 
-  // nsTextEditRules implementation methods
-  nsresult WillInsertText(  EditAction aAction,
-                            Selection* aSelection,
-                            bool            *aCancel,
-                            bool            *aHandled,
-                            const nsAString *inString,
-                            nsAString       *outString,
-                            int32_t          aMaxLength);
+  // TextEditRules implementation methods
+  nsresult WillInsertText(EditAction aAction,
+                          Selection* aSelection,
+                          bool* aCancel,
+                          bool* aHandled,
+                          const nsAString* inString,
+                          nsAString* outString,
+                          int32_t aMaxLength);
   nsresult DidInsertText(Selection* aSelection, nsresult aResult);
-  nsresult GetTopEnclosingPre(nsIDOMNode *aNode, nsIDOMNode** aOutPreNode);
+  nsresult GetTopEnclosingPre(nsIDOMNode* aNode, nsIDOMNode** aOutPreNode);
 
   nsresult WillInsertBreak(Selection* aSelection, bool* aCancel,
-                           bool *aHandled, int32_t aMaxLength);
+                           bool* aHandled, int32_t aMaxLength);
   nsresult DidInsertBreak(Selection* aSelection, nsresult aResult);
 
   void WillInsert(Selection& aSelection, bool* aCancel);
   nsresult DidInsert(Selection* aSelection, nsresult aResult);
 
   nsresult WillDeleteSelection(Selection* aSelection,
                                nsIEditor::EDirection aCollapsedAction,
-                               bool *aCancel,
-                               bool *aHandled);
+                               bool* aCancel,
+                               bool* aHandled);
   nsresult DidDeleteSelection(Selection* aSelection,
                               nsIEditor::EDirection aCollapsedAction,
                               nsresult aResult);
 
   nsresult WillSetTextProperty(Selection* aSelection, bool* aCancel,
                                bool* aHandled);
   nsresult DidSetTextProperty(Selection* aSelection, nsresult aResult);
 
@@ -146,123 +150,115 @@ protected:
   nsresult DidRemoveTextProperty(Selection* aSelection, nsresult aResult);
 
   nsresult WillUndo(Selection* aSelection, bool* aCancel, bool* aHandled);
   nsresult DidUndo(Selection* aSelection, nsresult aResult);
 
   nsresult WillRedo(Selection* aSelection, bool* aCancel, bool* aHandled);
   nsresult DidRedo(Selection* aSelection, nsresult aResult);
 
-  /** called prior to nsIEditor::OutputToString
-    * @param aSelection
-    * @param aInFormat  the format requested for the output, a MIME type
-    * @param aOutText   the string to use for output, if aCancel is set to true
-    * @param aOutCancel if set to true, the caller should cancel the operation
-    *                   and use aOutText as the result.
-    */
+  /**
+   * Called prior to nsIEditor::OutputToString.
+   * @param aSelection
+   * @param aInFormat  The format requested for the output, a MIME type.
+   * @param aOutText   The string to use for output, if aCancel is set to true.
+   * @param aOutCancel If set to true, the caller should cancel the operation
+   *                   and use aOutText as the result.
+   */
   nsresult WillOutputText(Selection* aSelection,
-                          const nsAString  *aInFormat,
-                          nsAString *aOutText,
-                          bool     *aOutCancel,
-                          bool *aHandled);
+                          const nsAString* aInFormat,
+                          nsAString* aOutText,
+                          bool* aOutCancel,
+                          bool* aHandled);
 
   nsresult DidOutputText(Selection* aSelection, nsresult aResult);
 
-
-  // helper functions
-
-  /** check for and replace a redundant trailing break */
+  /**
+   * Check for and replace a redundant trailing break.
+   */
   nsresult RemoveRedundantTrailingBR();
 
-  /** creates a trailing break in the text doc if there is not one already */
+  /**
+   * 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 */
+  /**
+   * Creates a bogus text node if the document has no editable content.
+   */
   nsresult CreateBogusNodeIfNeeded(Selection* aSelection);
 
-  /** returns a truncated insertion string if insertion would place us
-      over aMaxLength */
-  nsresult TruncateInsertionIfNeeded(Selection*  aSelection,
-                                     const nsAString          *aInString,
-                                     nsAString                *aOutString,
-                                     int32_t                   aMaxLength,
-                                     bool                     *aTruncated);
+  /**
+   * Returns a truncated insertion string if insertion would place us over
+   * aMaxLength
+   */
+  nsresult TruncateInsertionIfNeeded(Selection* aSelection,
+                                     const nsAString* aInString,
+                                     nsAString* aOutString,
+                                     int32_t aMaxLength,
+                                     bool* aTruncated);
 
-  /** Remove IME composition text from password buffer */
-  void RemoveIMETextFromPWBuf(int32_t &aStart, nsAString *aIMEString);
+  /**
+   * Remove IME composition text from password buffer.
+   */
+  void RemoveIMETextFromPWBuf(int32_t& aStart, nsAString* aIMEString);
 
   nsresult CreateMozBR(nsIDOMNode* inParent, int32_t inOffset,
                        nsIDOMNode** outBRNode = nullptr);
 
   void UndefineCaretBidiLevel(Selection* aSelection);
 
   nsresult CheckBidiLevelForDeletion(Selection* aSelection,
-                                     nsIDOMNode           *aSelNode,
-                                     int32_t               aSelOffset,
+                                     nsIDOMNode* aSelNode,
+                                     int32_t aSelOffset,
                                      nsIEditor::EDirection aAction,
-                                     bool                 *aCancel);
+                                     bool* aCancel);
 
   nsresult HideLastPWInput();
 
   nsresult CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection);
 
-  bool IsPasswordEditor() const
-  {
-    return mEditor ? mEditor->IsPasswordEditor() : false;
-  }
-  bool IsSingleLineEditor() const
-  {
-    return mEditor ? mEditor->IsSingleLineEditor() : false;
-  }
-  bool IsPlaintextEditor() const
-  {
-    return mEditor ? mEditor->IsPlaintextEditor() : false;
-  }
-  bool IsReadonly() const
-  {
-    return mEditor ? mEditor->IsReadonly() : false;
-  }
-  bool IsDisabled() const
-  {
-    return mEditor ? mEditor->IsDisabled() : false;
-  }
-  bool IsMailEditor() const
-  {
-    return mEditor ? mEditor->IsMailEditor() : false;
-  }
-  bool DontEchoPassword() const
-  {
-    return mEditor ? mEditor->DontEchoPassword() : false;
-  }
+  bool IsPasswordEditor() const;
+  bool IsSingleLineEditor() const;
+  bool IsPlaintextEditor() const;
+  bool IsReadonly() const;
+  bool IsDisabled() const;
+  bool IsMailEditor() const;
+  bool DontEchoPassword() const;
 
-  // data members
-  nsPlaintextEditor   *mEditor;        // note that we do not refcount the editor
-  nsString             mPasswordText;  // a buffer we use to store the real value of password editors
-  nsString             mPasswordIMEText;  // a buffer we use to track the IME composition string
-  uint32_t             mPasswordIMEIndex;
-  nsCOMPtr<nsIDOMNode> mBogusNode;     // magic node acts as placeholder in empty doc
-  nsCOMPtr<nsIDOMNode> mCachedSelectionNode;    // cached selected node
-  int32_t              mCachedSelectionOffset;  // cached selected offset
-  uint32_t             mActionNesting;
-  bool                 mLockRulesSniffing;
-  bool                 mDidExplicitlySetInterline;
-  bool                 mDeleteBidiImmediately; // in bidirectional text, delete
-                                               // characters not visually
-                                               // adjacent to the caret without
-                                               // moving the caret first.
-  EditAction mTheAction;     // the top level editor action
-  nsCOMPtr<nsITimer>   mTimer;
-  uint32_t             mLastStart, mLastLength;
+  // Note that we do not refcount the editor.
+  nsPlaintextEditor* mEditor;
+  // A buffer we use to store the real value of password editors.
+  nsString mPasswordText;
+  // A buffer we use to track the IME composition string.
+  nsString mPasswordIMEText;
+  uint32_t mPasswordIMEIndex;
+  // Magic node acts as placeholder in empty doc.
+  nsCOMPtr<nsIDOMNode> mBogusNode;
+  // Cached selected node.
+  nsCOMPtr<nsIDOMNode> mCachedSelectionNode;
+  // Cached selected offset.
+  int32_t mCachedSelectionOffset;
+  uint32_t mActionNesting;
+  bool mLockRulesSniffing;
+  bool mDidExplicitlySetInterline;
+  // In bidirectional text, delete characters not visually adjacent to the
+  // caret without moving the caret first.
+  bool mDeleteBidiImmediately;
+  // The top level editor action.
+  EditAction mTheAction;
+  nsCOMPtr<nsITimer> mTimer;
+  uint32_t mLastStart;
+  uint32_t mLastLength;
 
   // friends
   friend class nsAutoLockRulesSniffing;
-
 };
 
-
+} // namespace mozilla
 
 class nsTextRulesInfo : public nsRulesInfo
 {
  public:
 
   explicit nsTextRulesInfo(EditAction aAction) :
     nsRulesInfo(aAction),
     inString(0),
@@ -311,23 +307,23 @@ class nsTextRulesInfo : public nsRulesIn
  * stack based helper class for StartOperation()/EndOperation() sandwich.
  * this class sets a bool letting us know to ignore any rules sniffing
  * that tries to occur reentrantly.
  */
 class nsAutoLockRulesSniffing
 {
   public:
 
-  explicit nsAutoLockRulesSniffing(nsTextEditRules *rules) : mRules(rules)
+  explicit nsAutoLockRulesSniffing(mozilla::TextEditRules *rules) : mRules(rules)
                  {if (mRules) mRules->mLockRulesSniffing = true;}
   ~nsAutoLockRulesSniffing()
                  {if (mRules) mRules->mLockRulesSniffing = false;}
 
   protected:
-  nsTextEditRules *mRules;
+  mozilla::TextEditRules *mRules;
 };
 
 
 
 /***************************************************************************
  * stack based helper class for turning on/off the edit listener.
  */
 class nsAutoLockListener
@@ -350,9 +346,9 @@ public:
     }
   }
 
 protected:
   bool *mEnabled;
   bool mOldState;
 };
 
-#endif //nsTextEditRules_h__
+#endif // #ifndef mozilla_TextEditRules_h
rename from editor/libeditor/nsTextEditRulesBidi.cpp
rename to editor/libeditor/TextEditRulesBidi.cpp
--- a/editor/libeditor/nsTextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -1,38 +1,40 @@
 /* -*- 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 "mozilla/TextEditRules.h"
+
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsFrameSelection.h"
 #include "nsIContent.h"
 #include "nsIDOMNode.h"
 #include "nsIEditor.h"
 #include "nsIPresShell.h"
 #include "mozilla/dom/Selection.h"
 #include "nsISupportsImpl.h"
 #include "nsPlaintextEditor.h"
 #include "nsPresContext.h"
-#include "nsTextEditRules.h"
 #include "nscore.h"
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
 
 // Test for distance between caret and text that will be deleted
 nsresult
-nsTextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
-                                           nsIDOMNode           *aSelNode,
-                                           int32_t               aSelOffset,
-                                           nsIEditor::EDirection aAction,
-                                           bool                 *aCancel)
+TextEditRules::CheckBidiLevelForDeletion(Selection* aSelection,
+                                         nsIDOMNode* aSelNode,
+                                         int32_t aSelOffset,
+                                         nsIEditor::EDirection aAction,
+                                         bool* aCancel)
 {
   NS_ENSURE_ARG_POINTER(aCancel);
   *aCancel = false;
 
   nsCOMPtr<nsIPresShell> shell = mEditor->GetPresShell();
   NS_ENSURE_TRUE(shell, NS_ERROR_NOT_INITIALIZED);
 
   nsPresContext *context = shell->GetPresContext();
@@ -75,23 +77,25 @@ nsTextEditRules::CheckBidiLevelForDeleti
     // Set the bidi level of the caret to that of the
     // character that will be (or would have been) deleted
     frameSelection->SetCaretBidiLevel(levelOfDeletion);
   }
   return NS_OK;
 }
 
 void
-nsTextEditRules::UndefineCaretBidiLevel(Selection* aSelection)
+TextEditRules::UndefineCaretBidiLevel(Selection* aSelection)
 {
   /**
    * After inserting text the caret Bidi level must be set to the level of the
    * inserted text.This is difficult, because we cannot know what the level is
    * until after the Bidi algorithm is applied to the whole paragraph.
    *
    * So we set the caret Bidi level to UNDEFINED here, and the caret code will
    * set it correctly later
    */
   RefPtr<nsFrameSelection> frameSelection = aSelection->GetFrameSelection();
   if (frameSelection) {
     frameSelection->UndefineCaretBidiLevel();
   }
 }
+
+} // namespace mozilla
--- a/editor/libeditor/TextEditUtils.h
+++ b/editor/libeditor/TextEditUtils.h
@@ -12,17 +12,17 @@ class nsIDOMNode;
 class nsINode;
 class nsPlaintextEditor;
 
 namespace mozilla {
 
 class TextEditUtils final
 {
 public:
-  // from nsTextEditRules:
+  // from TextEditRules:
   static bool IsBody(nsIDOMNode* aNode);
   static bool IsBreak(nsIDOMNode* aNode);
   static bool IsBreak(nsINode* aNode);
   static bool IsMozBR(nsIDOMNode* aNode);
   static bool IsMozBR(nsINode* aNode);
   static bool HasMozAttr(nsIDOMNode* aNode);
 };
 
--- a/editor/libeditor/WSRunObject.cpp
+++ b/editor/libeditor/WSRunObject.cpp
@@ -1,23 +1,23 @@
 /* -*- 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 "WSRunObject.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 "mozilla/SelectionState.h"
 
 #include "nsAString.h"
 #include "nsCRT.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsHTMLEditor.h"
 #include "nsIContent.h"
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -8,18 +8,25 @@ MOCHITEST_MANIFESTS += [
     'tests/browserscope/mochitest.ini',
     'tests/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome.ini']
 
 BROWSER_CHROME_MANIFESTS += ['tests/browser.ini']
 
+EXPORTS += [
+    'nsEditor.h',
+    'nsEditRules.h',
+]
+
 EXPORTS.mozilla += [
     'EditorController.h',
+    'SelectionState.h',
+    'TextEditRules.h',
 ]
 
 UNIFIED_SOURCES += [
     'ChangeAttributeTransaction.cpp',
     'ChangeStyleTransaction.cpp',
     'CompositionTransaction.cpp',
     'CreateElementTransaction.cpp',
     'CSSEditUtils.cpp',
@@ -46,24 +53,24 @@ UNIFIED_SOURCES += [
     'nsHTMLEditor.cpp',
     'nsHTMLEditorEventListener.cpp',
     'nsHTMLEditorStyle.cpp',
     'nsHTMLInlineTableEditor.cpp',
     'nsHTMLObjectResizer.cpp',
     'nsPlaintextDataTransfer.cpp',
     'nsPlaintextEditor.cpp',
     'nsTableEditor.cpp',
-    'nsTextEditRules.cpp',
-    'nsTextEditRulesBidi.cpp',
     'PlaceholderTransaction.cpp',
     'SelectionState.cpp',
     'SetDocumentTitleTransaction.cpp',
     'SplitNodeTransaction.cpp',
     'StyleSheetTransactions.cpp',
     'TextEditorTest.cpp',
+    'TextEditRules.cpp',
+    'TextEditRulesBidi.cpp',
     'TextEditUtils.cpp',
     'TypeInState.cpp',
     'WSRunObject.cpp',
 ]
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/editor/txmgr',
--- a/editor/libeditor/nsEditor.h
+++ b/editor/libeditor/nsEditor.h
@@ -1,19 +1,19 @@
 /* -*- 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 RangeUpdater, etc
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc.
 #include "mozilla/OwningNonNull.h"      // for OwningNonNull
+#include "mozilla/SelectionState.h"     // for RangeUpdater, etc
 #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
--- a/editor/libeditor/nsEditorEventListener.cpp
+++ b/editor/libeditor/nsEditorEventListener.cpp
@@ -7,16 +7,17 @@
 #include "nsEditorEventListener.h"
 
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/EventListenerManager.h" // for EventListenerManager
 #include "mozilla/IMEStateManager.h"    // for IMEStateManager
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/TextEvents.h"         // for WidgetCompositionEvent
 #include "mozilla/dom/Element.h"        // for Element
+#include "mozilla/dom/Event.h"          // for Event
 #include "mozilla/dom/EventTarget.h"    // for EventTarget
 #include "mozilla/dom/Selection.h"
 #include "nsAString.h"
 #include "nsCaret.h"                    // for nsCaret
 #include "nsDebug.h"                    // for NS_ENSURE_TRUE, etc
 #include "nsEditor.h"                   // for nsEditor, etc
 #include "nsFocusManager.h"             // for nsFocusManager
 #include "nsGkAtoms.h"                  // for nsGkAtoms, nsGkAtoms::input
--- a/editor/libeditor/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/nsHTMLAbsPosition.cpp
@@ -38,17 +38,16 @@
 #include "nsINode.h"
 #include "nsIPresShell.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
-#include "nsTextEditRules.h"
 #include "nscore.h"
 #include <algorithm>
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define  BLACK_BG_RGB_TRIGGER 0xd0
 
--- a/editor/libeditor/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/nsHTMLDataTransfer.cpp
@@ -3,28 +3,28 @@
 /* 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 "WSRunObject.h"
 #include "mozilla/dom/DataTransfer.h"
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/DOMStringList.h"
-#include "mozilla/OwningNonNull.h"
+#include "mozilla/dom/Selection.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Base64.h"
 #include "mozilla/BasicEvents.h"
+#include "mozilla/OwningNonNull.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/dom/Selection.h"
+#include "mozilla/SelectionState.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIScriptError.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
@@ -75,17 +75,16 @@
 #include "nsRange.h"
 #include "nsReadableUtils.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"
 #include "nsXPCOM.h"
 #include "nscore.h"
 #include "nsContentUtils.h"
 
 class nsIAtom;
 class nsILoadContext;
 class nsISupports;
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -50,16 +50,17 @@ class nsITransferable;
 class nsIClipboard;
 class nsILinkHandler;
 class nsTableWrapperFrame;
 class nsIDOMRange;
 class nsRange;
 
 namespace mozilla {
 class HTMLEditRules;
+class TextEditRules;
 class TypeInState;
 class WSRunObject;
 struct PropItem;
 template<class T> class OwningNonNull;
 namespace dom {
 class DocumentFragment;
 } // namespace dom
 namespace widget {
@@ -968,22 +969,21 @@ protected:
   nsCOMPtr<nsIDOMElement> mAddRowAfterButton;
 
   void     AddMouseClickListener(nsIDOMElement * aElement);
   void     RemoveMouseClickListener(nsIDOMElement * aElement);
 
   nsCOMPtr<nsILinkHandler> mLinkHandler;
 
 public:
-
-// friends
-friend class mozilla::HTMLEditRules;
-friend class mozilla::WSRunObject;
-friend class nsTextEditRules;
-friend class nsHTMLEditorEventListener;
+  // friends
+  friend class mozilla::HTMLEditRules;
+  friend class mozilla::TextEditRules;
+  friend class mozilla::WSRunObject;
+  friend class nsHTMLEditorEventListener;
 
 private:
   // Helpers
   bool IsSimpleModifiableNode(nsIContent* aContent,
                               nsIAtom* aProperty,
                               const nsAString* aAttribute,
                               const nsAString* aValue);
   nsresult SetInlinePropertyOnNodeImpl(nsIContent& aNode,
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -1,19 +1,19 @@
 /* -*- 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/SelectionState.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsAttrName.h"
 #include "nsCOMPtr.h"
 #include "nsCaseTreatment.h"
 #include "nsComponentManagerUtils.h"
@@ -33,17 +33,16 @@
 #include "nsINode.h"
 #include "nsISupportsImpl.h"
 #include "nsLiteralString.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nsTArray.h"
-#include "nsTextEditRules.h"
 #include "nsUnicharUtils.h"
 #include "nscore.h"
 
 class nsISupports;
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
--- a/editor/libeditor/nsPlaintextDataTransfer.cpp
+++ b/editor/libeditor/nsPlaintextDataTransfer.cpp
@@ -1,17 +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 "EditorUtils.h"
-#include "SelectionState.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/MouseEvents.h"
+#include "mozilla/SelectionState.h"
 #include "mozilla/dom/Selection.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsEditor.h"
--- a/editor/libeditor/nsPlaintextEditor.cpp
+++ b/editor/libeditor/nsPlaintextEditor.cpp
@@ -5,23 +5,24 @@
 
 #include "nsPlaintextEditor.h"
 
 #include "EditorUtils.h"  // AutoEditBatch, AutoRules
 #include "InternetCiter.h"
 #include "TextEditUtils.h"
 #include "gfxFontUtils.h"
 #include "mozilla/Assertions.h"
+#include "mozilla/mozalloc.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/TextEditRules.h"
+#include "mozilla/TextComposition.h"
+#include "mozilla/TextEvents.h"
 #include "mozilla/dom/Selection.h"
 #include "mozilla/dom/Event.h"
-#include "mozilla/TextComposition.h"
-#include "mozilla/TextEvents.h"
 #include "mozilla/dom/Element.h"
-#include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsCRT.h"
 #include "nsCaret.h"
 #include "nsCharTraits.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentCID.h"
 #include "nsCopySupport.h"
 #include "nsDebug.h"
@@ -49,17 +50,16 @@
 #include "nsITransferable.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
 #include "nsSubstringTuple.h"
-#include "nsTextEditRules.h"
 #include "nsUnicharUtils.h"
 #include "nsXPCOM.h"
 
 class nsIOutputStream;
 class nsISupports;
 class nsISupportsArray;
 
 using namespace mozilla;
@@ -317,17 +317,17 @@ nsPlaintextEditor::UpdateMetaCharset(nsI
   }
   return false;
 }
 
 NS_IMETHODIMP nsPlaintextEditor::InitRules()
 {
   if (!mRules) {
     // instantiate the rules for this text editor
-    mRules = new nsTextEditRules();
+    mRules = new TextEditRules();
   }
   return mRules->Init(this);
 }
 
 
 NS_IMETHODIMP
 nsPlaintextEditor::GetIsDocumentEditable(bool *aIsDocumentEditable)
 {
@@ -827,18 +827,17 @@ nsPlaintextEditor::BeginIMEComposition(W
 {
   NS_ENSURE_TRUE(!mComposition, NS_OK);
 
   if (IsPasswordEditor()) {
     NS_ENSURE_TRUE(mRules, NS_ERROR_NULL_POINTER);
     // Protect the edit rules object from dying
     nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
 
-    nsTextEditRules *textEditRules =
-      static_cast<nsTextEditRules*>(mRules.get());
+    TextEditRules* textEditRules = static_cast<TextEditRules*>(mRules.get());
     textEditRules->ResetIMETextPWBuf();
   }
 
   return nsEditor::BeginIMEComposition(aEvent);
 }
 
 nsresult
 nsPlaintextEditor::UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent)
--- a/editor/libeditor/nsPlaintextEditor.h
+++ b/editor/libeditor/nsPlaintextEditor.h
@@ -25,16 +25,17 @@ class nsIDocumentEncoder;
 class nsIEditRules;
 class nsIOutputStream;
 class nsISelectionController;
 class nsITransferable;
 
 namespace mozilla {
 class AutoEditInitRulesTrigger;
 class HTMLEditRules;
+class TextEditRules;
 namespace dom {
 class Selection;
 } // namespace dom
 } // namespace mozilla
 
 /**
  * The text editor implementation.
  * Use to edit text document represented as a DOM tree.
@@ -223,13 +224,13 @@ protected:
   int32_t mMaxTextLength;
   int32_t mInitTriggerCounter;
   int32_t mNewlineHandling;
   int32_t mCaretStyle;
 
   // friends
   friend class mozilla::AutoEditInitRulesTrigger;
   friend class mozilla::HTMLEditRules;
-  friend class nsTextEditRules;
+  friend class mozilla::TextEditRules;
 };
 
 #endif //nsPlaintextEditor_h__
 
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -32,21 +32,21 @@
 #include <algorithm>
 #include "nsIDOMNodeList.h" //for selection setting helper func
 #include "nsIDOMRange.h" //for selection setting helper func
 #include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
 #include "nsIDOMNode.h"
 
 #include "nsIDOMText.h" //for multiline getselection
 #include "nsFocusManager.h"
-#include "nsTextEditRules.h"
 #include "nsPresState.h"
 #include "nsContentList.h"
 #include "nsAttrValueInlines.h"
 #include "mozilla/dom/Selection.h"
+#include "mozilla/TextEditRules.h"
 #include "nsContentUtils.h"
 #include "nsTextNode.h"
 #include "mozilla/StyleSetHandle.h"
 #include "mozilla/StyleSetHandleInlines.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/MathAlgorithms.h"
 #include "nsFrameSelection.h"
 
@@ -1314,17 +1314,17 @@ nsTextControlFrame::UpdateValueDisplay(b
   }
 
   if (aBeforeEditorInit && value.IsEmpty()) {
     rootNode->RemoveChildAt(0, true);
     return NS_OK;
   }
 
   if (!value.IsEmpty() && IsPasswordTextControl()) {
-    nsTextEditRules::FillBufWithPWChars(&value, value.Length());
+    TextEditRules::FillBufWithPWChars(&value, value.Length());
   }
   return textContent->SetText(value, aNotify);
 }
 
 NS_IMETHODIMP
 nsTextControlFrame::GetOwnedSelectionController(nsISelectionController** aSelCon)
 {
   NS_ENSURE_ARG_POINTER(aSelCon);
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -5,19 +5,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/gfx/2D.h"
 #include "mozilla/gfx/PathHelpers.h"
+#include "mozilla/Likely.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
-#include "mozilla/Likely.h"
+#include "mozilla/TextEditRules.h"
 
 #include "gfxUtils.h"
 #include "nsAlgorithm.h"
 #include "nsCOMPtr.h"
 #include "nsFontMetrics.h"
 #include "nsPresContext.h"
 #include "nsNameSpaceManager.h"
 
@@ -61,17 +62,16 @@
 #include "nsLayoutUtils.h"
 #include "nsIScrollableFrame.h"
 #include "nsDisplayList.h"
 #include "mozilla/dom/TreeBoxObject.h"
 #include "nsRenderingContext.h"
 #include "nsIScriptableRegion.h"
 #include <algorithm>
 #include "ScrollbarActivity.h"
-#include "../../editor/libeditor/nsTextEditRules.h"
 
 #ifdef ACCESSIBILITY
 #include "nsAccessibilityService.h"
 #include "nsIWritablePropertyBag2.h"
 #endif
 #include "nsBidiUtils.h"
 
 using namespace mozilla;
@@ -3689,17 +3689,17 @@ nsTreeBodyFrame::PaintText(int32_t      
 
   bool isRTL = StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL;
 
   // Now obtain the text for our cell.
   nsAutoString text;
   mView->GetCellText(aRowIndex, aColumn, text);
 
   if (aColumn->Type() == nsITreeColumn::TYPE_PASSWORD) {
-    nsTextEditRules::FillBufWithPWChars(&text, text.Length());
+    TextEditRules::FillBufWithPWChars(&text, text.Length());
   }
 
   // We're going to paint this text so we need to ensure bidi is enabled if
   // necessary
   CheckTextForBidi(text);
 
   DrawResult result = DrawResult::SUCCESS;