Bug 981226 Rename nsContentEventHandler to mozilla::ContentEventHandler (and clean up it) r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 11 Mar 2014 14:08:02 +0900
changeset 190117 9040a7cf26393432de57d6e01b78a3ce210bf60b
parent 190116 549d598666c218b13c1452388823ff39126f891d
child 190118 797110c218e31ea53b0bd749e018f13ef8c01d0b
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs981226
milestone30.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 981226 Rename nsContentEventHandler to mozilla::ContentEventHandler (and clean up it) r=smaug
dom/events/ContentEventHandler.cpp
dom/events/ContentEventHandler.h
dom/events/IMEContentObserver.cpp
dom/events/TextComposition.cpp
dom/events/moz.build
dom/events/nsContentEventHandler.cpp
dom/events/nsContentEventHandler.h
dom/events/nsEventStateManager.cpp
widget/tests/TestWinTSF.cpp
rename from dom/events/nsContentEventHandler.cpp
rename to dom/events/ContentEventHandler.cpp
--- a/dom/events/nsContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1,79 +1,84 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsContentEventHandler.h"
+#include "ContentEventHandler.h"
+#include "mozilla/IMEStateManager.h"
+#include "mozilla/TextEvents.h"
+#include "mozilla/dom/Element.h"
+#include "nsCaret.h"
 #include "nsCOMPtr.h"
+#include "nsContentUtils.h"
+#include "nsCopySupport.h"
 #include "nsFocusManager.h"
-#include "nsPresContext.h"
+#include "nsFrameSelection.h"
+#include "nsIContentIterator.h"
 #include "nsIPresShell.h"
 #include "nsISelection.h"
-#include "nsIDOMRange.h"
-#include "nsRange.h"
-#include "nsCaret.h"
-#include "nsCopySupport.h"
-#include "nsFrameSelection.h"
-#include "nsIFrame.h"
-#include "nsView.h"
-#include "nsIContentIterator.h"
-#include "nsTextFragment.h"
-#include "nsTextFrame.h"
 #include "nsISelectionController.h"
 #include "nsISelectionPrivate.h"
-#include "nsContentUtils.h"
-#include "nsLayoutUtils.h"
+#include "nsIDOMRange.h"
+#include "nsIFrame.h"
 #include "nsIObjectFrame.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/IMEStateManager.h"
-#include "mozilla/TextEvents.h"
+#include "nsLayoutUtils.h"
+#include "nsPresContext.h"
+#include "nsRange.h"
+#include "nsTextFragment.h"
+#include "nsTextFrame.h"
+#include "nsView.h"
+
 #include <algorithm>
 
-using namespace mozilla;
-using namespace mozilla::dom;
-using namespace mozilla::widget;
+namespace mozilla {
+
+using namespace dom;
+using namespace widget;
 
 /******************************************************************/
-/* nsContentEventHandler                                          */
+/* ContentEventHandler                                            */
 /******************************************************************/
 
-nsContentEventHandler::nsContentEventHandler(
-                              nsPresContext* aPresContext) :
-  mPresContext(aPresContext),
-  mPresShell(aPresContext->GetPresShell()), mSelection(nullptr),
-  mFirstSelectedRange(nullptr), mRootContent(nullptr)
+ContentEventHandler::ContentEventHandler(nsPresContext* aPresContext)
+  : mPresContext(aPresContext)
+  , mPresShell(aPresContext->GetPresShell())
+  , mSelection(nullptr)
+  , mFirstSelectedRange(nullptr)
+  , mRootContent(nullptr)
 {
 }
 
 nsresult
-nsContentEventHandler::InitCommon()
+ContentEventHandler::InitCommon()
 {
-  if (mSelection)
+  if (mSelection) {
     return NS_OK;
+  }
 
   NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);
 
   // If text frame which has overflowing selection underline is dirty,
   // we need to flush the pending reflow here.
   mPresShell->FlushPendingNotifications(Flush_Layout);
 
   // Flushing notifications can cause mPresShell to be destroyed (bug 577963).
   NS_ENSURE_TRUE(!mPresShell->IsDestroying(), NS_ERROR_FAILURE);
 
   nsCopySupport::GetSelectionForCopy(mPresShell->GetDocument(),
                                      getter_AddRefs(mSelection));
 
   nsCOMPtr<nsIDOMRange> firstRange;
   nsresult rv = mSelection->GetRangeAt(0, getter_AddRefs(firstRange));
   // This shell doesn't support selection.
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
   mFirstSelectedRange = static_cast<nsRange*>(firstRange.get());
 
   nsINode* startNode = mFirstSelectedRange->GetStartParent();
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
   nsINode* endNode = mFirstSelectedRange->GetEndParent();
   NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);
 
   // See bug 537041 comment 5, the range could have removed node.
@@ -83,17 +88,17 @@ nsContentEventHandler::InitCommon()
                "mFirstSelectedRange crosses the document boundary");
 
   mRootContent = startNode->GetSelectionRootContent(mPresShell);
   NS_ENSURE_TRUE(mRootContent, NS_ERROR_FAILURE);
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::Init(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::Init(WidgetQueryContentEvent* aEvent)
 {
   NS_ASSERTION(aEvent, "aEvent must not be null");
 
   nsresult rv = InitCommon();
   NS_ENSURE_SUCCESS(rv, rv);
 
   aEvent->mSucceeded = false;
 
@@ -112,51 +117,51 @@ nsContentEventHandler::Init(WidgetQueryC
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   aEvent->mReply.mFocusedWidget = frame->GetNearestWidget();
 
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::Init(WidgetSelectionEvent* aEvent)
+ContentEventHandler::Init(WidgetSelectionEvent* aEvent)
 {
   NS_ASSERTION(aEvent, "aEvent must not be null");
 
   nsresult rv = InitCommon();
   NS_ENSURE_SUCCESS(rv, rv);
 
   aEvent->mSucceeded = false;
 
   return NS_OK;
 }
 
 nsIContent*
-nsContentEventHandler::GetFocusedContent()
+ContentEventHandler::GetFocusedContent()
 {
   nsIDocument* doc = mPresShell->GetDocument();
   if (!doc) {
     return nullptr;
   }
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(doc->GetWindow());
   nsCOMPtr<nsPIDOMWindow> focusedWindow;
   return nsFocusManager::GetFocusedDescendant(window, true,
                                               getter_AddRefs(focusedWindow));
 }
 
 bool
-nsContentEventHandler::IsPlugin(nsIContent* aContent)
+ContentEventHandler::IsPlugin(nsIContent* aContent)
 {
   return aContent &&
          aContent->GetDesiredIMEState().mEnabled == IMEState::PLUGIN;
 }
 
 nsresult
-nsContentEventHandler::QueryContentRect(nsIContent* aContent,
-                                        WidgetQueryContentEvent* aEvent)
+ContentEventHandler::QueryContentRect(nsIContent* aContent,
+                                      WidgetQueryContentEvent* aEvent)
 {
   NS_PRECONDITION(aContent, "aContent must not be null");
 
   nsIFrame* frame = aContent->GetPrimaryFrame();
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
 
   // get rect for first frame
   nsRect resultRect(nsPoint(0, 0), frame->GetRect().Size());
@@ -205,41 +210,44 @@ static void ConvertToNativeNewlines(nsAF
 #endif
 }
 
 static void AppendString(nsAString& aString, nsIContent* aContent)
 {
   NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
                "aContent is not a text node!");
   const nsTextFragment* text = aContent->GetText();
-  if (!text)
+  if (!text) {
     return;
+  }
   text->AppendTo(aString);
 }
 
 static void AppendSubString(nsAString& aString, nsIContent* aContent,
                             uint32_t aXPOffset, uint32_t aXPLength)
 {
   NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
                "aContent is not a text node!");
   const nsTextFragment* text = aContent->GetText();
-  if (!text)
+  if (!text) {
     return;
+  }
   text->AppendTo(aString, int32_t(aXPOffset), int32_t(aXPLength));
 }
 
 #if defined(XP_WIN)
 static uint32_t CountNewlinesInXPLength(nsIContent* aContent,
                                         uint32_t aXPLength)
 {
   NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
                "aContent is not a text node!");
   const nsTextFragment* text = aContent->GetText();
-  if (!text)
+  if (!text) {
     return 0;
+  }
   // For automated tests, we should abort on debug build.
   NS_ABORT_IF_FALSE(
     (aXPLength == UINT32_MAX || aXPLength <= text->GetLength()),
     "aXPLength is out-of-bounds");
   const uint32_t length = std::min(aXPLength, text->GetLength());
   uint32_t newlines = 0;
   for (uint32_t i = 0; i < length; ++i) {
     if (text->CharAt(i) == '\n') {
@@ -274,37 +282,40 @@ static uint32_t CountNewlinesInNativeLen
       ++nativeOffset;
     }
   }
   return newlines;
 }
 #endif
 
 /* static */ uint32_t
-nsContentEventHandler::GetNativeTextLength(nsIContent* aContent, uint32_t aMaxLength)
+ContentEventHandler::GetNativeTextLength(nsIContent* aContent,
+                                         uint32_t aMaxLength)
 {
   if (aContent->IsNodeOfType(nsINode::eTEXT)) {
     uint32_t textLengthDifference =
 #if defined(XP_MACOSX)
       // On Mac, the length of a native newline ("\r") is equal to the length of
-      // the XP newline ("\n"), so the native length is the same as the XP length.
+      // the XP newline ("\n"), so the native length is the same as the XP
+      // length.
       0;
 #elif defined(XP_WIN)
-      // On Windows, the length of a native newline ("\r\n") is twice the length of
-      // the XP newline ("\n"), so XP length is equal to the length of the native
-      // offset plus the number of newlines encountered in the string.
+      // On Windows, the length of a native newline ("\r\n") is twice the length
+      // of the XP newline ("\n"), so XP length is equal to the length of the
+      // native offset plus the number of newlines encountered in the string.
       CountNewlinesInXPLength(aContent, aMaxLength);
 #else
       // On other platforms, the native and XP newlines are the same.
       0;
 #endif
 
     const nsTextFragment* text = aContent->GetText();
-    if (!text)
+    if (!text) {
       return 0;
+    }
     uint32_t length = std::min(text->GetLength(), aMaxLength);
     return length + textLengthDifference;
   } else if (IsContentBR(aContent)) {
 #if defined(XP_WIN)
     // Length of \r\n
     return 2;
 #else
     return 1;
@@ -349,112 +360,123 @@ static nsresult GenerateFlatTextContent(
                     aRange->EndOffset() - aRange->StartOffset());
     ConvertToNativeNewlines(aString);
     return NS_OK;
   }
 
   nsAutoString tmpStr;
   for (; !iter->IsDone(); iter->Next()) {
     nsINode* node = iter->GetCurrentNode();
-    if (!node)
+    if (!node) {
       break;
-    if (!node->IsNodeOfType(nsINode::eCONTENT))
+    }
+    if (!node->IsNodeOfType(nsINode::eCONTENT)) {
       continue;
+    }
     nsIContent* content = static_cast<nsIContent*>(node);
 
     if (content->IsNodeOfType(nsINode::eTEXT)) {
-      if (content == startNode)
+      if (content == startNode) {
         AppendSubString(aString, content, aRange->StartOffset(),
                         content->TextLength() - aRange->StartOffset());
-      else if (content == endNode)
+      } else if (content == endNode) {
         AppendSubString(aString, content, 0, aRange->EndOffset());
-      else
+      } else {
         AppendString(aString, content);
-    } else if (IsContentBR(content))
-        aString.Append(char16_t('\n'));
+      }
+    } else if (IsContentBR(content)) {
+      aString.Append(char16_t('\n'));
+    }
   }
   ConvertToNativeNewlines(aString);
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
-                                               bool aForward,
-                                               uint32_t* aXPOffset)
+ContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent,
+                                             bool aForward,
+                                             uint32_t* aXPOffset)
 {
   // XXX This method assumes that the frame boundaries must be cluster
   // boundaries. It's false, but no problem now, maybe.
   if (!aContent->IsNodeOfType(nsINode::eTEXT) ||
-      *aXPOffset == 0 || *aXPOffset == aContent->TextLength())
+      *aXPOffset == 0 || *aXPOffset == aContent->TextLength()) {
     return NS_OK;
+  }
 
   NS_ASSERTION(*aXPOffset <= aContent->TextLength(),
                "offset is out of range.");
 
   nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
   int32_t offsetInFrame;
   nsFrameSelection::HINT hint =
     aForward ? nsFrameSelection::HINTLEFT : nsFrameSelection::HINTRIGHT;
   nsIFrame* frame = fs->GetFrameForNodeOffset(aContent, int32_t(*aXPOffset),
                                               hint, &offsetInFrame);
   if (!frame) {
     // This content doesn't have any frames, we only can check surrogate pair...
     const nsTextFragment* text = aContent->GetText();
     NS_ENSURE_TRUE(text, NS_ERROR_FAILURE);
     if (NS_IS_LOW_SURROGATE(text->CharAt(*aXPOffset)) &&
-        NS_IS_HIGH_SURROGATE(text->CharAt(*aXPOffset - 1)))
+        NS_IS_HIGH_SURROGATE(text->CharAt(*aXPOffset - 1))) {
       *aXPOffset += aForward ? 1 : -1;
+    }
     return NS_OK;
   }
   int32_t startOffset, endOffset;
   nsresult rv = frame->GetOffsets(startOffset, endOffset);
   NS_ENSURE_SUCCESS(rv, rv);
-  if (*aXPOffset == uint32_t(startOffset) || *aXPOffset == uint32_t(endOffset))
+  if (*aXPOffset == static_cast<uint32_t>(startOffset) ||
+      *aXPOffset == static_cast<uint32_t>(endOffset)) {
     return NS_OK;
-  if (frame->GetType() != nsGkAtoms::textFrame)
+  }
+  if (frame->GetType() != nsGkAtoms::textFrame) {
     return NS_ERROR_FAILURE;
+  }
   nsTextFrame* textFrame = static_cast<nsTextFrame*>(frame);
   int32_t newOffsetInFrame = *aXPOffset - startOffset;
   newOffsetInFrame += aForward ? -1 : 1;
   textFrame->PeekOffsetCharacter(aForward, &newOffsetInFrame);
   *aXPOffset = startOffset + newOffsetInFrame;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::SetRangeFromFlatTextOffset(
-                              nsRange* aRange,
-                              uint32_t aNativeOffset,
-                              uint32_t aNativeLength,
-                              bool aExpandToClusterBoundaries,
-                              uint32_t* aNewNativeOffset)
+ContentEventHandler::SetRangeFromFlatTextOffset(nsRange* aRange,
+                                                uint32_t aNativeOffset,
+                                                uint32_t aNativeLength,
+                                                bool aExpandToClusterBoundaries,
+                                                uint32_t* aNewNativeOffset)
 {
   if (aNewNativeOffset) {
     *aNewNativeOffset = aNativeOffset;
   }
 
   nsCOMPtr<nsIContentIterator> iter = NS_NewPreContentIterator();
   nsresult rv = iter->Init(mRootContent);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t nativeOffset = 0;
   uint32_t nativeEndOffset = aNativeOffset + aNativeLength;
   bool startSet = false;
   for (; !iter->IsDone(); iter->Next()) {
     nsINode* node = iter->GetCurrentNode();
-    if (!node)
+    if (!node) {
       break;
-    if (!node->IsNodeOfType(nsINode::eCONTENT))
+    }
+    if (!node->IsNodeOfType(nsINode::eCONTENT)) {
       continue;
+    }
     nsIContent* content = static_cast<nsIContent*>(node);
 
     uint32_t nativeTextLength;
     nativeTextLength = GetNativeTextLength(content);
-    if (nativeTextLength == 0)
+    if (nativeTextLength == 0) {
       continue;
+    }
 
     if (nativeOffset <= aNativeOffset &&
         aNativeOffset < nativeOffset + nativeTextLength) {
       nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(content));
       NS_ASSERTION(domNode, "aContent doesn't have nsIDOMNode!");
 
       uint32_t xpOffset =
         content->IsNodeOfType(nsINode::eTEXT) ?
@@ -490,31 +512,33 @@ nsContentEventHandler::SetRangeFromFlatT
           rv = ExpandToClusterBoundary(content, true, &xpOffset);
           NS_ENSURE_SUCCESS(rv, rv);
         }
       } else {
         // Use first position of next node, because the end node is ignored
         // by ContentIterator when the offset is zero.
         xpOffset = 0;
         iter->Next();
-        if (iter->IsDone())
+        if (iter->IsDone()) {
           break;
+        }
         domNode = do_QueryInterface(iter->GetCurrentNode());
       }
 
       rv = aRange->SetEnd(domNode, int32_t(xpOffset));
       NS_ENSURE_SUCCESS(rv, rv);
       return NS_OK;
     }
 
     nativeOffset += nativeTextLength;
   }
 
-  if (nativeOffset < aNativeOffset)
+  if (nativeOffset < aNativeOffset) {
     return NS_ERROR_FAILURE;
+  }
 
   nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(mRootContent));
   NS_ASSERTION(domNode, "lastContent doesn't have nsIDOMNode!");
   if (!startSet) {
     MOZ_ASSERT(!mRootContent->IsNodeOfType(nsINode::eTEXT));
     rv = aRange->SetStart(domNode, int32_t(mRootContent->GetChildCount()));
     NS_ENSURE_SUCCESS(rv, rv);
     if (aNewNativeOffset) {
@@ -522,21 +546,22 @@ nsContentEventHandler::SetRangeFromFlatT
     }
   }
   rv = aRange->SetEnd(domNode, int32_t(mRootContent->GetChildCount()));
   NS_ASSERTION(NS_SUCCEEDED(rv), "nsIDOMRange::SetEnd failed");
   return rv;
 }
 
 nsresult
-nsContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQuerySelectedText(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
                "The reply string must be empty");
 
   rv = GetFlatTextOffsetOfRange(mRootContent,
                                 mFirstSelectedRange, &aEvent->mReply.mOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -565,21 +590,22 @@ nsContentEventHandler::OnQuerySelectedTe
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryTextContent(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryTextContent(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   NS_ASSERTION(aEvent->mReply.mString.IsEmpty(),
                "The reply string must be empty");
 
   nsRefPtr<nsRange> range = new nsRange(mRootContent);
   rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
                                   aEvent->mInput.mLength, false,
                                   &aEvent->mReply.mOffset);
@@ -626,21 +652,22 @@ static nsresult GetFrameForTextRect(nsIN
   nsIFrame* frame = content->GetPrimaryFrame();
   NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
   int32_t childOffset = 0;
   return frame->GetChildFrameContainingOffset(aOffset, aHint, &childOffset,
                                               aReturnFrame);
 }
 
 nsresult
-nsContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryTextRect(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   nsRefPtr<nsRange> range = new nsRange(mRootContent);
   rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset,
                                   aEvent->mInput.mLength, true,
                                   &aEvent->mReply.mOffset);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = GenerateFlatTextContent(range, aEvent->mReply.mString);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -679,20 +706,22 @@ nsContentEventHandler::OnQueryTextRect(W
 
   // iterate over all covered frames
   for (nsIFrame* frame = firstFrame; frame != lastFrame;) {
     frame = frame->GetNextContinuation();
     if (!frame) {
       do {
         iter->Next();
         node = iter->GetCurrentNode();
-        if (!node)
+        if (!node) {
           break;
-        if (!node->IsNodeOfType(nsINode::eCONTENT))
+        }
+        if (!node->IsNodeOfType(nsINode::eCONTENT)) {
           continue;
+        }
         frame = static_cast<nsIContent*>(node)->GetPrimaryFrame();
       } while (!frame && !iter->IsDone());
       if (!frame) {
         // this can happen when the end offset of the range is 0.
         frame = lastFrame;
       }
     }
     frameRect.SetRect(nsPoint(0, 0), frame->GetRect().Size());
@@ -716,35 +745,37 @@ nsContentEventHandler::OnQueryTextRect(W
   }
   aEvent->mReply.mRect =
       rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel());
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryEditorRect(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryEditorRect(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   nsIContent* focusedContent = GetFocusedContent();
   rv = QueryContentRect(IsPlugin(focusedContent) ?
                           focusedContent : mRootContent.get(), aEvent);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryCaretRect(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryCaretRect(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   nsRefPtr<nsCaret> caret = mPresShell->GetCaret();
   NS_ASSERTION(caret, "GetCaret returned null");
 
   // When the selection is collapsed and the queried offset is current caret
   // position, we should return the "real" caret rect.
   bool selectionIsCollapsed;
   rv = mSelection->GetIsCollapsed(&selectionIsCollapsed);
@@ -759,18 +790,19 @@ nsContentEventHandler::OnQueryCaretRect(
     // element offset properties. We need to match those or things break. 
     nsINode* startNode = mFirstSelectedRange->GetStartParent();
     if (startNode && startNode->IsNodeOfType(nsINode::eTEXT)) {
       offset = ConvertToXPOffset(static_cast<nsIContent*>(startNode), offset);
     }
     if (offset == aEvent->mInput.mOffset) {
       nsRect rect;
       nsIFrame* caretFrame = caret->GetGeometry(mSelection, &rect);
-      if (!caretFrame)
+      if (!caretFrame) {
         return NS_ERROR_FAILURE;
+      }
       rv = ConvertToRootViewRelativeOffset(caretFrame, rect);
       NS_ENSURE_SUCCESS(rv, rv);
       aEvent->mReply.mRect =
         rect.ToOutsidePixels(caretFrame->PresContext()->AppUnitsPerDevPixel());
       aEvent->mReply.mOffset = aEvent->mInput.mOffset;
       aEvent->mSucceeded = true;
       return NS_OK;
     }
@@ -802,57 +834,59 @@ nsContentEventHandler::OnQueryCaretRect(
 
   aEvent->mReply.mRect =
       rect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel());
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryContentState(WidgetQueryContentEvent * aEvent)
+ContentEventHandler::OnQueryContentState(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
-  
+  }
   aEvent->mSucceeded = true;
-
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQuerySelectionAsTransferable(
-                         WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQuerySelectionAsTransferable(
+                       WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   if (!aEvent->mReply.mHasSelection) {
     aEvent->mSucceeded = true;
     aEvent->mReply.mTransferable = nullptr;
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = mPresShell->GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
-  rv = nsCopySupport::GetTransferableForSelection(mSelection, doc, getter_AddRefs(aEvent->mReply.mTransferable));
+  rv = nsCopySupport::GetTransferableForSelection(
+         mSelection, doc, getter_AddRefs(aEvent->mReply.mTransferable));
   NS_ENSURE_SUCCESS(rv, rv);
 
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   nsIFrame* rootFrame = mPresShell->GetRootFrame();
   NS_ENSURE_TRUE(rootFrame, NS_ERROR_FAILURE);
   nsIWidget* rootWidget = rootFrame->GetNearestWidget();
   NS_ENSURE_TRUE(rootWidget, NS_ERROR_FAILURE);
 
   // The root frame's widget might be different, e.g., the event was fired on
   // a popup but the rootFrame is the document root.
@@ -866,17 +900,18 @@ nsContentEventHandler::OnQueryCharacterA
     NS_ENSURE_TRUE(rootWidget, NS_ERROR_FAILURE);
   }
 
   WidgetQueryContentEvent eventOnRoot(true, NS_QUERY_CHARACTER_AT_POINT,
                                       rootWidget);
   eventOnRoot.refPoint = aEvent->refPoint;
   if (rootWidget != aEvent->widget) {
     eventOnRoot.refPoint += LayoutDeviceIntPoint::FromUntyped(
-      aEvent->widget->WidgetToScreenOffset() - rootWidget->WidgetToScreenOffset());
+      aEvent->widget->WidgetToScreenOffset() -
+        rootWidget->WidgetToScreenOffset());
   }
   nsPoint ptInRoot =
     nsLayoutUtils::GetEventCoordinatesRelativeTo(&eventOnRoot, rootFrame);
 
   nsIFrame* targetFrame = nsLayoutUtils::GetFrameForPoint(rootFrame, ptInRoot);
   if (!targetFrame || targetFrame->GetType() != nsGkAtoms::textFrame ||
       !targetFrame->GetContent() ||
       !nsContentUtils::ContentIsDescendantOf(targetFrame->GetContent(),
@@ -909,21 +944,22 @@ nsContentEventHandler::OnQueryCharacterA
   // currently, we don't need to get the actual text.
   aEvent->mReply.mOffset = nativeOffset;
   aEvent->mReply.mRect = textRect.mReply.mRect;
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent)
+ContentEventHandler::OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
-  if (NS_FAILED(rv))
+  if (NS_FAILED(rv)) {
     return rv;
+  }
 
   aEvent->mReply.mWidgetIsHit = false;
 
   NS_ENSURE_TRUE(aEvent->widget, NS_ERROR_FAILURE);
 
   nsIDocument* doc = mPresShell->GetDocument();
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
   nsIFrame* docFrame = mPresShell->GetRootFrame();
@@ -942,29 +978,30 @@ nsContentEventHandler::OnQueryDOMWidgetH
     nsIWidget* targetWidget = nullptr;
     nsIFrame* targetFrame = contentUnderMouse->GetPrimaryFrame();
     nsIObjectFrame* pluginFrame = do_QueryFrame(targetFrame);
     if (pluginFrame) {
       targetWidget = pluginFrame->GetWidget();
     } else if (targetFrame) {
       targetWidget = targetFrame->GetNearestWidget();
     }
-    if (aEvent->widget == targetWidget)
+    if (aEvent->widget == targetWidget) {
       aEvent->mReply.mWidgetIsHit = true;
+    }
   }
 
   aEvent->mSucceeded = true;
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
-                                                nsINode* aNode,
-                                                int32_t aNodeOffset,
-                                                uint32_t* aNativeOffset)
+ContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
+                                              nsINode* aNode,
+                                              int32_t aNodeOffset,
+                                              uint32_t* aNativeOffset)
 {
   NS_ENSURE_STATE(aRootContent);
   NS_ASSERTION(aNativeOffset, "param is invalid");
 
   nsRefPtr<nsRange> prev = new nsRange(aRootContent);
   nsCOMPtr<nsIDOMNode> rootDOMNode(do_QueryInterface(aRootContent));
   prev->SetStart(rootDOMNode, 0);
 
@@ -976,86 +1013,91 @@ nsContentEventHandler::GetFlatTextOffset
   iter->Init(prev);
 
   nsCOMPtr<nsINode> startNode = do_QueryInterface(startDOMNode);
   nsINode* endNode = aNode;
 
   *aNativeOffset = 0;
   for (; !iter->IsDone(); iter->Next()) {
     nsINode* node = iter->GetCurrentNode();
-    if (!node)
+    if (!node) {
       break;
-    if (!node->IsNodeOfType(nsINode::eCONTENT))
+    }
+    if (!node->IsNodeOfType(nsINode::eCONTENT)) {
       continue;
+    }
     nsIContent* content = static_cast<nsIContent*>(node);
 
     if (node->IsNodeOfType(nsINode::eTEXT)) {
       // Note: our range always starts from offset 0
-      if (node == endNode)
+      if (node == endNode) {
         *aNativeOffset += GetNativeTextLength(content, aNodeOffset);
-      else
+      } else {
         *aNativeOffset += GetNativeTextLength(content);
+      }
     } else if (IsContentBR(content)) {
 #if defined(XP_WIN)
       // On Windows, the length of the newline is 2.
       *aNativeOffset += 2;
 #else
       // On other platforms, the length of the newline is 1.
       *aNativeOffset += 1;
 #endif
     }
   }
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
-                                                nsRange* aRange,
-                                                uint32_t* aNativeOffset)
+ContentEventHandler::GetFlatTextOffsetOfRange(nsIContent* aRootContent,
+                                              nsRange* aRange,
+                                              uint32_t* aNativeOffset)
 {
   nsINode* startNode = aRange->GetStartParent();
   NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);
   int32_t startOffset = aRange->StartOffset();
   return GetFlatTextOffsetOfRange(aRootContent, startNode, startOffset,
                                   aNativeOffset);
 }
 
 nsresult
-nsContentEventHandler::GetStartFrameAndOffset(nsRange* aRange,
-                                              nsIFrame** aFrame,
-                                              int32_t* aOffsetInFrame)
+ContentEventHandler::GetStartFrameAndOffset(nsRange* aRange,
+                                            nsIFrame** aFrame,
+                                            int32_t* aOffsetInFrame)
 {
   NS_ASSERTION(aRange && aFrame && aOffsetInFrame, "params are invalid");
 
   nsIContent* content = nullptr;
   nsINode* node = aRange->GetStartParent();
-  if (node && node->IsNodeOfType(nsINode::eCONTENT))
+  if (node && node->IsNodeOfType(nsINode::eCONTENT)) {
     content = static_cast<nsIContent*>(node);
+  }
   NS_ASSERTION(content, "the start node doesn't have nsIContent!");
 
   nsRefPtr<nsFrameSelection> fs = mPresShell->FrameSelection();
   *aFrame = fs->GetFrameForNodeOffset(content, aRange->StartOffset(),
                                       fs->GetHint(), aOffsetInFrame);
   NS_ENSURE_TRUE((*aFrame), NS_ERROR_FAILURE);
   NS_ASSERTION((*aFrame)->GetType() == nsGkAtoms::textFrame,
                "The frame is not textframe");
   return NS_OK;
 }
 
 nsresult
-nsContentEventHandler::ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
-                                                       nsRect& aRect)
+ContentEventHandler::ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
+                                                     nsRect& aRect)
 {
   NS_ASSERTION(aFrame, "aFrame must not be null");
 
   nsView* view = nullptr;
   nsPoint posInView;
   aFrame->GetOffsetFromView(posInView, &view);
-  if (!view)
+  if (!view) {
     return NS_ERROR_FAILURE;
+  }
   aRect += posInView + view->GetOffsetTo(nullptr);
   return NS_OK;
 }
 
 static void AdjustRangeForSelection(nsIContent* aRoot,
                                     nsINode** aNode,
                                     int32_t* aOffset)
 {
@@ -1075,26 +1117,27 @@ static void AdjustRangeForSelection(nsIC
     } else {
       node = node->GetParent();
       offset = node->IndexOf(*aNode) + (offset ? 1 : 0);
     }
   }
 
   nsIContent* brContent = node->GetChildAt(offset - 1);
   while (brContent && brContent->IsHTML()) {
-    if (brContent->Tag() != nsGkAtoms::br || IsContentBR(brContent))
+    if (brContent->Tag() != nsGkAtoms::br || IsContentBR(brContent)) {
       break;
+    }
     brContent = node->GetChildAt(--offset - 1);
   }
   *aNode = node;
   *aOffset = std::max(offset, 0);
 }
 
 nsresult
-nsContentEventHandler::OnSelectionEvent(WidgetSelectionEvent* aEvent)
+ContentEventHandler::OnSelectionEvent(WidgetSelectionEvent* aEvent)
 {
   aEvent->mSucceeded = false;
 
   // Get selection to manipulate
   // XXX why do we need to get them from ISM? This method should work fine
   //     without ISM.
   nsresult rv =
     IMEStateManager::GetFocusSelectionAndRoot(getter_AddRefs(mSelection),
@@ -1148,8 +1191,10 @@ nsContentEventHandler::OnSelectionEvent(
   NS_ENSURE_SUCCESS(rv, rv);
 
   selPrivate->ScrollIntoViewInternal(
     nsISelectionController::SELECTION_FOCUS_REGION,
     false, nsIPresShell::ScrollAxis(), nsIPresShell::ScrollAxis());
   aEvent->mSucceeded = true;
   return NS_OK;
 }
+
+} // namespace mozilla
rename from dom/events/nsContentEventHandler.h
rename to dom/events/ContentEventHandler.h
--- a/dom/events/nsContentEventHandler.h
+++ b/dom/events/ContentEventHandler.h
@@ -1,71 +1,71 @@
 /* -*- 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 nsContentEventHandler_h__
-#define nsContentEventHandler_h__
+#ifndef mozilla_ContentEventHandler_h_
+#define mozilla_ContentEventHandler_h_
 
+#include "mozilla/EventForwards.h"
 #include "nsCOMPtr.h"
-
 #include "nsISelection.h"
 #include "nsRange.h"
-#include "mozilla/EventForwards.h"
 
-class nsCaret;
 class nsPresContext;
 
 struct nsRect;
 
+namespace mozilla {
+
 /*
  * Query Content Event Handler
- *   nsContentEventHandler is a helper class for nsEventStateManager.
+ *   ContentEventHandler is a helper class for nsEventStateManager.
  *   The platforms request some content informations, e.g., the selected text,
  *   the offset of the selected text and the text for specified range.
  *   This class answers to NS_QUERY_* events from actual contents.
  */
 
-class MOZ_STACK_CLASS nsContentEventHandler {
+class MOZ_STACK_CLASS ContentEventHandler
+{
 public:
-  nsContentEventHandler(nsPresContext *aPresContext);
+  ContentEventHandler(nsPresContext* aPresContext);
 
   // NS_QUERY_SELECTED_TEXT event handler
-  nsresult OnQuerySelectedText(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQuerySelectedText(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_TEXT_CONTENT event handler
-  nsresult OnQueryTextContent(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryTextContent(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_CARET_RECT event handler
-  nsresult OnQueryCaretRect(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryCaretRect(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_TEXT_RECT event handler
-  nsresult OnQueryTextRect(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryTextRect(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_EDITOR_RECT event handler
-  nsresult OnQueryEditorRect(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryEditorRect(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_CONTENT_STATE event handler
-  nsresult OnQueryContentState(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryContentState(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
-  nsresult OnQuerySelectionAsTransferable(
-             mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQuerySelectionAsTransferable(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_CHARACTER_AT_POINT event handler
-  nsresult OnQueryCharacterAtPoint(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent);
   // NS_QUERY_DOM_WIDGET_HITTEST event handler
-  nsresult OnQueryDOMWidgetHittest(mozilla::WidgetQueryContentEvent* aEvent);
+  nsresult OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent);
 
   // NS_SELECTION_* event
-  nsresult OnSelectionEvent(mozilla::WidgetSelectionEvent* aEvent);
+  nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
 
 protected:
   nsPresContext* mPresContext;
   nsCOMPtr<nsIPresShell> mPresShell;
   nsCOMPtr<nsISelection> mSelection;
   nsRefPtr<nsRange> mFirstSelectedRange;
   nsCOMPtr<nsIContent> mRootContent;
 
-  nsresult Init(mozilla::WidgetQueryContentEvent* aEvent);
-  nsresult Init(mozilla::WidgetSelectionEvent* aEvent);
+  nsresult Init(WidgetQueryContentEvent* aEvent);
+  nsresult Init(WidgetSelectionEvent* aEvent);
 
   // InitCommon() is called from each Init().
   nsresult InitCommon();
 
 public:
   // FlatText means the text that is generated from DOM tree. The BR elements
   // are replaced to native linefeeds. Other elements are ignored.
 
@@ -82,17 +82,17 @@ public:
                                       uint32_t aMaxLength = UINT32_MAX);
 protected:
   // Returns focused content (including its descendant documents).
   nsIContent* GetFocusedContent();
   // Returns true if the content is a plugin host.
   bool IsPlugin(nsIContent* aContent);
   // QueryContentRect() sets the rect of aContent's frame(s) to aEvent.
   nsresult QueryContentRect(nsIContent* aContent,
-                            mozilla::WidgetQueryContentEvent* aEvent);
+                            WidgetQueryContentEvent* aEvent);
   // Make the DOM range from the offset of FlatText and the text length.
   // If aExpandToClusterBoundaries is true, the start offset and the end one are
   // expanded to nearest cluster boundaries.
   nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
                                       uint32_t aNativeOffset,
                                       uint32_t aNativeLength,
                                       bool aExpandToClusterBoundaries,
                                       uint32_t* aNewNativeOffset = nullptr);
@@ -105,9 +105,11 @@ protected:
   nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
                                            nsRect& aRect);
   // Expand aXPOffset to the nearest offset in cluster boundary. aForward is
   // true, it is expanded to forward.
   nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
                                    uint32_t* aXPOffset);
 };
 
-#endif // nsContentEventHandler_h__
+} // namespace mozilla
+
+#endif // mozilla_ContentEventHandler_h_
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "ContentEventHandler.h"
 #include "IMEContentObserver.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/dom/Element.h"
 #include "nsAutoPtr.h"
 #include "nsAsyncDOMEvent.h"
-#include "nsContentEventHandler.h"
 #include "nsContentUtils.h"
 #include "nsGkAtoms.h"
 #include "nsIAtom.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMRange.h"
 #include "nsIFrame.h"
@@ -365,19 +365,19 @@ IMEContentObserver::CharacterDataChanged
   if (causedByComposition &&
       !mUpdatePreference.WantChangesCausedByComposition()) {
     return;
   }
 
   uint32_t offset = 0;
   // get offsets of change and fire notification
   nsresult rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContent,
-                                                    aInfo->mChangeStart,
-                                                    &offset);
+    ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContent,
+                                                  aInfo->mChangeStart,
+                                                  &offset);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   uint32_t oldEnd = offset + aInfo->mChangeEnd - aInfo->mChangeStart;
   uint32_t newEnd = offset + aInfo->mReplaceLength;
 
   nsContentUtils::AddScriptRunner(
     new TextChangeEvent(this, offset, oldEnd, newEnd, causedByComposition));
 }
@@ -390,26 +390,25 @@ IMEContentObserver::NotifyContentAdded(n
   bool causedByComposition = IsEditorHandlingEventForComposition();
   if (causedByComposition &&
       !mUpdatePreference.WantChangesCausedByComposition()) {
     return;
   }
 
   uint32_t offset = 0;
   nsresult rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContainer,
-                                                    aStartIndex, &offset);
+    ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContainer,
+                                                  aStartIndex, &offset);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   // get offset at the end of the last added node
   nsIContent* childAtStart = aContainer->GetChildAt(aStartIndex);
   uint32_t addingLength = 0;
-  rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(childAtStart, aContainer,
-                                                    aEndIndex, &addingLength);
+  rv = ContentEventHandler::GetFlatTextOffsetOfRange(childAtStart, aContainer,
+                                                     aEndIndex, &addingLength);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   if (!addingLength) {
     return;
   }
 
   nsContentUtils::AddScriptRunner(
     new TextChangeEvent(this, offset, offset, offset + addingLength,
@@ -446,32 +445,31 @@ IMEContentObserver::ContentRemoved(nsIDo
   bool causedByComposition = IsEditorHandlingEventForComposition();
   if (causedByComposition &&
       !mUpdatePreference.WantChangesCausedByComposition()) {
     return;
   }
 
   uint32_t offset = 0;
   nsresult rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(mRootContent,
-                                                    NODE_FROM(aContainer,
-                                                              aDocument),
-                                                    aIndexInContainer, &offset);
+    ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent,
+                                                  NODE_FROM(aContainer,
+                                                            aDocument),
+                                                  aIndexInContainer, &offset);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   // get offset at the end of the deleted node
   int32_t nodeLength =
     aChild->IsNodeOfType(nsINode::eTEXT) ?
       static_cast<int32_t>(aChild->TextLength()) :
       std::max(static_cast<int32_t>(aChild->GetChildCount()), 1);
   MOZ_ASSERT(nodeLength >= 0, "The node length is out of range");
   uint32_t textLength = 0;
-  rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(aChild, aChild,
-                                                    nodeLength, &textLength);
+  rv = ContentEventHandler::GetFlatTextOffsetOfRange(aChild, aChild,
+                                                     nodeLength, &textLength);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   if (!textLength) {
     return;
   }
 
   nsContentUtils::AddScriptRunner(
     new TextChangeEvent(this, offset, offset + textLength, offset,
@@ -492,17 +490,17 @@ void
 IMEContentObserver::AttributeWillChange(nsIDocument* aDocument,
                                         dom::Element* aElement,
                                         int32_t aNameSpaceID,
                                         nsIAtom* aAttribute,
                                         int32_t aModType)
 {
   nsIContent *content = GetContentBR(aElement);
   mPreAttrChangeLength = content ?
-    nsContentEventHandler::GetNativeTextLength(content) : 0;
+    ContentEventHandler::GetNativeTextLength(content) : 0;
 }
 
 void
 IMEContentObserver::AttributeChanged(nsIDocument* aDocument,
                                      dom::Element* aElement,
                                      int32_t aNameSpaceID,
                                      nsIAtom* aAttribute,
                                      int32_t aModType)
@@ -514,24 +512,24 @@ IMEContentObserver::AttributeChanged(nsI
   }
 
   nsIContent *content = GetContentBR(aElement);
   if (!content) {
     return;
   }
 
   uint32_t postAttrChangeLength =
-    nsContentEventHandler::GetNativeTextLength(content);
+    ContentEventHandler::GetNativeTextLength(content);
   if (postAttrChangeLength == mPreAttrChangeLength) {
     return;
   }
   uint32_t start;
   nsresult rv =
-    nsContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, content,
-                                                    0, &start);
+    ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, content,
+                                                  0, &start);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   nsContentUtils::AddScriptRunner(
     new TextChangeEvent(this, start, start + mPreAttrChangeLength,
                         start + postAttrChangeLength, causedByComposition));
 }
 
 } // namespace mozilla
--- a/dom/events/TextComposition.cpp
+++ b/dom/events/TextComposition.cpp
@@ -1,16 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 et tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "ContentEventHandler.h"
 #include "TextComposition.h"
-#include "nsContentEventHandler.h"
 #include "nsContentUtils.h"
 #include "nsEventDispatcher.h"
 #include "nsIContent.h"
 #include "nsIEditor.h"
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "mozilla/IMEStateManager.h"
 #include "mozilla/MiscEvents.h"
@@ -222,17 +222,17 @@ TextComposition::CompositionEventDispatc
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
   switch (mEventMessage) {
     case NS_COMPOSITION_START: {
       WidgetCompositionEvent compStart(true, NS_COMPOSITION_START, mWidget);
       WidgetQueryContentEvent selectedText(true, NS_QUERY_SELECTED_TEXT,
                                            mWidget);
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQuerySelectedText(&selectedText);
       NS_ASSERTION(selectedText.mSucceeded, "Failed to get selected text");
       compStart.data = selectedText.mReply.mString;
       IMEStateManager::DispatchCompositionEvent(mEventTarget, mPresContext,
                                                 &compStart, &status, nullptr);
       break;
     }
     case NS_COMPOSITION_UPDATE:
--- a/dom/events/moz.build
+++ b/dom/events/moz.build
@@ -66,16 +66,17 @@ if CONFIG['MOZ_WEBSPEECH']:
     EXPORTS.mozilla.dom += ['SpeechRecognitionError.h']
 
 UNIFIED_SOURCES += [
     'AnimationEvent.cpp',
     'BeforeUnloadEvent.cpp',
     'ClipboardEvent.cpp',
     'CommandEvent.cpp',
     'CompositionEvent.cpp',
+    'ContentEventHandler.cpp',
     'DataContainerEvent.cpp',
     'DataTransfer.cpp',
     'DeviceMotionEvent.cpp',
     'DragEvent.cpp',
     'Event.cpp',
     'EventTarget.cpp',
     'FocusEvent.cpp',
     'IMEContentObserver.cpp',
@@ -83,17 +84,16 @@ UNIFIED_SOURCES += [
     'KeyboardEvent.cpp',
     'MessageEvent.cpp',
     'MouseEvent.cpp',
     'MouseScrollEvent.cpp',
     'MutationEvent.cpp',
     'NotifyAudioAvailableEvent.cpp',
     'NotifyPaintEvent.cpp',
     'nsAsyncDOMEvent.cpp',
-    'nsContentEventHandler.cpp',
     'nsDOMEventTargetHelper.cpp',
     'nsEventDispatcher.cpp',
     'nsEventListenerManager.cpp',
     'nsEventListenerService.cpp',
     'nsJSEventListener.cpp',
     'nsPaintRequest.cpp',
     'PointerEvent.cpp',
     'ScrollAreaEvent.cpp',
--- a/dom/events/nsEventStateManager.cpp
+++ b/dom/events/nsEventStateManager.cpp
@@ -10,20 +10,21 @@
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/UIEvent.h"
 
+#include "ContentEventHandler.h"
+
 #include "nsCOMPtr.h"
 #include "nsEventStateManager.h"
 #include "nsFocusManager.h"
-#include "nsContentEventHandler.h"
 #include "nsIContent.h"
 #include "nsINodeInfo.h"
 #include "nsIDocument.h"
 #include "nsIFrame.h"
 #include "nsIWidget.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsGkAtoms.h"
@@ -1211,85 +1212,87 @@ nsEventStateManager::PreHandleEvent(nsPr
         InitLineOrPageDelta(aTargetFrame, this, wheelEvent);
     }
     break;
   case NS_QUERY_SELECTED_TEXT:
     DoQuerySelectedText(aEvent->AsQueryContentEvent());
     break;
   case NS_QUERY_TEXT_CONTENT:
     {
-      if (RemoteQueryContentEvent(aEvent))
+      if (RemoteQueryContentEvent(aEvent)) {
         break;
-      nsContentEventHandler handler(mPresContext);
+      }
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryTextContent(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_CARET_RECT:
     {
       if (RemoteQueryContentEvent(aEvent)) {
         break;
       }
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryCaretRect(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_TEXT_RECT:
     {
       if (RemoteQueryContentEvent(aEvent)) {
         break;
       }
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryTextRect(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_EDITOR_RECT:
     {
       // XXX remote event
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryEditorRect(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_CONTENT_STATE:
     {
       // XXX remote event
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryContentState(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_SELECTION_AS_TRANSFERABLE:
     {
       // XXX remote event
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQuerySelectionAsTransferable(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_CHARACTER_AT_POINT:
     {
       // XXX remote event
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryCharacterAtPoint(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_QUERY_DOM_WIDGET_HITTEST:
     {
       // XXX remote event
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnQueryDOMWidgetHittest(aEvent->AsQueryContentEvent());
     }
     break;
   case NS_SELECTION_SET:
     {
       WidgetSelectionEvent* selectionEvent = aEvent->AsSelectionEvent();
       if (IsTargetCrossProcess(selectionEvent)) {
         // Will not be handled locally, remote the event
-        if (GetCrossProcessTarget()->SendSelectionEvent(*selectionEvent))
+        if (GetCrossProcessTarget()->SendSelectionEvent(*selectionEvent)) {
           selectionEvent->mSucceeded = true;
+        }
         break;
       }
-      nsContentEventHandler handler(mPresContext);
+      ContentEventHandler handler(mPresContext);
       handler.OnSelectionEvent(selectionEvent);
     }
     break;
   case NS_CONTENT_COMMAND_CUT:
   case NS_CONTENT_COMMAND_COPY:
   case NS_CONTENT_COMMAND_PASTE:
   case NS_CONTENT_COMMAND_DELETE:
   case NS_CONTENT_COMMAND_UNDO:
@@ -5422,17 +5425,17 @@ nsEventStateManager::DoContentCommandScr
 }
 
 void
 nsEventStateManager::DoQuerySelectedText(WidgetQueryContentEvent* aEvent)
 {
   if (RemoteQueryContentEvent(aEvent)) {
     return;
   }
-  nsContentEventHandler handler(mPresContext);
+  ContentEventHandler handler(mPresContext);
   handler.OnQuerySelectedText(aEvent);
 }
 
 void
 nsEventStateManager::SetActiveManager(nsEventStateManager* aNewESM,
                                       nsIContent* aContent)
 {
   if (sActiveESM && aNewESM != sActiveESM) {
--- a/widget/tests/TestWinTSF.cpp
+++ b/widget/tests/TestWinTSF.cpp
@@ -1880,20 +1880,20 @@ TestApp::TestSelectionInternal(char* aTe
 
 bool
 TestApp::TestSelection(void)
 {
   bool succeeded = true;
 
   /* If these fail the cause is probably one or more of:
    * nsTextStore::GetSelection not sending NS_QUERY_SELECTED_TEXT
-   * NS_QUERY_SELECTED_TEXT not handled by nsContentEventHandler
+   * NS_QUERY_SELECTED_TEXT not handled by ContentEventHandler
    * Bug in NS_QUERY_SELECTED_TEXT handler
    * nsTextStore::SetSelection not sending NS_SELECTION_SET
-   * NS_SELECTION_SET not handled by nsContentEventHandler
+   * NS_SELECTION_SET not handled by ContentEventHandler
    * Bug in NS_SELECTION_SET handler
    */
 
   TS_SELECTION_ACP testSel;
   ULONG selFetched;
 
   if (!mMgr->GetFocusedStore()) {
     fail("TestSelection: GetFocusedStore returns null");
@@ -1954,17 +1954,17 @@ TestApp::TestText(void)
   TS_RUNINFO runInfo[RUNINFO_SIZE];
   ULONG bufferRet, runInfoRet;
   LONG acpRet, acpCurrent;
   TS_TEXTCHANGE textChange;
   HRESULT hr;
 
   /* If these fail the cause is probably one or more of:
    * nsTextStore::GetText not sending NS_QUERY_TEXT_CONTENT
-   * NS_QUERY_TEXT_CONTENT not handled by nsContentEventHandler
+   * NS_QUERY_TEXT_CONTENT not handled by ContentEventHandler
    * Bug in NS_QUERY_TEXT_CONTENT handler
    * nsTextStore::SetText not calling SetSelection or InsertTextAtSelection
    * Bug in SetSelection or InsertTextAtSelection
    *  NS_SELECTION_SET bug or NS_COMPOSITION_* / NS_TEXT_TEXT bug
    */
 
   if (!mMgr->GetFocusedStore()) {
     fail("TestText: GetFocusedStore returns null #1");