Bug 856962: Move Touch to its own file r=Ms2ger
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 05 Apr 2013 04:49:00 -0400
changeset 134543 f134e2c4bb2a3c6fe5343869978e1e98f89551fd
parent 134542 acd478e0bd550b69bf952f28f614363916e5a3ac
child 134544 3552a2a5faf702beac010e6e69547d4fb05f9ffb
push idunknown
push userunknown
push dateunknown
reviewersMs2ger
bugs856962
milestone23.0a1
Bug 856962: Move Touch to its own file r=Ms2ger
content/base/src/nsDocument.cpp
content/events/src/Makefile.in
content/events/src/Touch.cpp
content/events/src/Touch.h
content/events/src/nsDOMTouchEvent.cpp
content/events/src/nsDOMTouchEvent.h
dom/base/nsDOMWindowUtils.cpp
dom/ipc/TabChild.cpp
layout/base/nsPresShell.cpp
layout/xul/base/src/nsBoxFrame.cpp
layout/xul/base/src/nsSliderFrame.cpp
widget/InputData.h
widget/android/nsWindow.cpp
widget/gonk/nsAppShell.cpp
widget/nsGUIEventIPC.h
widget/windows/nsWindow.cpp
widget/windows/winrt/MetroInput.cpp
widget/xpwidgets/InputData.cpp
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -175,16 +175,17 @@
 #include "nsHTMLCSSStyleSheet.h"
 #include "mozilla/dom/DOMImplementation.h"
 #include "mozilla/dom/Comment.h"
 #include "nsTextNode.h"
 #include "mozilla/dom/Link.h"
 #include "mozilla/dom/HTMLElementBinding.h"
 #include "nsXULAppAPI.h"
 #include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "DictionaryHelpers.h"
 #include "GeneratedEvents.h"
 
 #include "mozilla/Preferences.h"
 
 #include "imgILoader.h"
 #include "imgRequestProxy.h"
 #include "nsWrapperCacheInlines.h"
@@ -9267,24 +9268,24 @@ nsIDocument::CreateTouch(nsIDOMWindow* a
                          int32_t aPageX, int32_t aPageY,
                          int32_t aScreenX, int32_t aScreenY,
                          int32_t aClientX, int32_t aClientY,
                          int32_t aRadiusX, int32_t aRadiusY,
                          float aRotationAngle,
                          float aForce)
 {
   nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(aTarget);
-  nsCOMPtr<nsIDOMTouch> touch = new nsDOMTouch(target,
-                                               aIdentifier,
-                                               aPageX, aPageY,
-                                               aScreenX, aScreenY,
-                                               aClientX, aClientY,
-                                               aRadiusX, aRadiusY,
-                                               aRotationAngle,
-                                               aForce);
+  nsCOMPtr<nsIDOMTouch> touch = new Touch(target,
+                                          aIdentifier,
+                                          aPageX, aPageY,
+                                          aScreenX, aScreenY,
+                                          aClientX, aClientY,
+                                          aRadiusX, aRadiusY,
+                                          aRotationAngle,
+                                          aForce);
   return touch.forget();
 }
 
 NS_IMETHODIMP
 nsDocument::CreateTouchList(nsIVariant* aPoints,
                             nsIDOMTouchList** aRetVal)
 {
   nsRefPtr<nsDOMTouchList> retval = new nsDOMTouchList();
--- a/content/events/src/Makefile.in
+++ b/content/events/src/Makefile.in
@@ -11,16 +11,22 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 LIBRARY_NAME	= gkconevents_s
 LIBXUL_LIBRARY  = 1
 ifndef _MSC_VER
 FAIL_ON_WARNINGS = 1
 endif # !_MSC_VER
 
+EXPORTS_NAMESPACES = mozilla/dom
+
+EXPORTS_mozilla/dom = \
+		Touch.h \
+		$(NULL)
+
 EXPORTS		= \
 		nsEventStateManager.h \
 		nsEventListenerManager.h \
 		nsDOMEventTargetHelper.h \
 		nsDOMEvent.h \
 		nsDOMGamepad.h \
 		nsDOMTouchEvent.h \
 		nsDOMUIEvent.h \
@@ -58,16 +64,17 @@ CPPSRCS		= \
 		nsDOMScrollAreaEvent.cpp \
 		nsDOMTransitionEvent.cpp \
 		nsDOMAnimationEvent.cpp \
 		nsDOMTouchEvent.cpp \
 		nsDOMCompositionEvent.cpp \
 		nsDOMClipboardEvent.cpp \
 		DOMWheelEvent.cpp \
 		TextComposition.cpp \
+		Touch.cpp \
 		$(NULL)
 
 ifdef MOZ_GAMEPAD
 CPPSRCS += \
   nsDOMGamepad.cpp \
   $(NULL)
 endif
 
copy from content/events/src/nsDOMTouchEvent.cpp
copy to content/events/src/Touch.cpp
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/Touch.cpp
@@ -1,420 +1,139 @@
 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
 /* 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 "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsGUIEvent.h"
 #include "nsDOMClassInfoID.h"
 #include "nsIClassInfo.h"
 #include "nsIXPCScriptable.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsPresContext.h"
 
-using namespace mozilla;
-
-DOMCI_DATA(Touch, nsDOMTouch)
+DOMCI_DATA(Touch, mozilla::dom::Touch)
 
-NS_IMPL_CYCLE_COLLECTION_1(nsDOMTouch, mTarget)
+namespace mozilla {
+namespace dom {
 
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouch)
+NS_IMPL_CYCLE_COLLECTION_1(Touch, mTarget)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Touch)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMTouch)
   NS_INTERFACE_MAP_ENTRY(nsIDOMTouch)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Touch)
 NS_INTERFACE_MAP_END
 
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouch)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouch)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(Touch)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(Touch)
 
 NS_IMETHODIMP
-nsDOMTouch::GetIdentifier(int32_t* aIdentifier)
+Touch::GetIdentifier(int32_t* aIdentifier)
 {
   *aIdentifier = mIdentifier;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetTarget(nsIDOMEventTarget** aTarget)
+Touch::GetTarget(nsIDOMEventTarget** aTarget)
 {
   nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
   if (content && content->ChromeOnlyAccess() &&
       !nsContentUtils::CanAccessNativeAnon()) {
     content = content->FindFirstNonChromeOnlyAccessContent();
     *aTarget = content.forget().get();
     return NS_OK;
   }
   NS_IF_ADDREF(*aTarget = mTarget);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetScreenX(int32_t* aScreenX)
+Touch::GetScreenX(int32_t* aScreenX)
 {
   *aScreenX = mScreenPoint.x;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetScreenY(int32_t* aScreenY)
+Touch::GetScreenY(int32_t* aScreenY)
 {
   *aScreenY = mScreenPoint.y;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetClientX(int32_t* aClientX)
+Touch::GetClientX(int32_t* aClientX)
 {
   *aClientX = mClientPoint.x;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetClientY(int32_t* aClientY)
+Touch::GetClientY(int32_t* aClientY)
 {
   *aClientY = mClientPoint.y;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetPageX(int32_t* aPageX)
+Touch::GetPageX(int32_t* aPageX)
 {
   *aPageX = mPagePoint.x;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetPageY(int32_t* aPageY)
+Touch::GetPageY(int32_t* aPageY)
 {
   *aPageY = mPagePoint.y;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetRadiusX(int32_t* aRadiusX)
+Touch::GetRadiusX(int32_t* aRadiusX)
 {
   *aRadiusX = mRadius.x;
   return NS_OK;
 }
                                              
 NS_IMETHODIMP
-nsDOMTouch::GetRadiusY(int32_t* aRadiusY)
+Touch::GetRadiusY(int32_t* aRadiusY)
 {
   *aRadiusY = mRadius.y;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetRotationAngle(float* aRotationAngle)
+Touch::GetRotationAngle(float* aRotationAngle)
 {
   *aRotationAngle = mRotationAngle;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMTouch::GetForce(float* aForce)
+Touch::GetForce(float* aForce)
 {
   *aForce = mForce;
   return NS_OK;
 }
 
 bool
-nsDOMTouch::Equals(nsIDOMTouch* aTouch)
+Touch::Equals(nsIDOMTouch* aTouch)
 {
   float force;
   float orientation;
   int32_t radiusX, radiusY;
   aTouch->GetForce(&force);
   aTouch->GetRotationAngle(&orientation);
   aTouch->GetRadiusX(&radiusX);
   aTouch->GetRadiusY(&radiusY);
   return mRefPoint != aTouch->mRefPoint ||
          (mForce != force) ||
          (mRotationAngle != orientation) ||
          (mRadius.x != radiusX) || (mRadius.y != radiusY);
 }
 
-// TouchList
-nsDOMTouchList::nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
-{
-  mPoints.AppendElements(aTouches);
-  nsJSContext::LikelyShortLivingObjectCreated();
-}
-
-DOMCI_DATA(TouchList, nsDOMTouchList)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouchList)
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMTouchList)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TouchList)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTION_1(nsDOMTouchList, mPoints)
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouchList)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouchList)
-
-NS_IMETHODIMP
-nsDOMTouchList::GetLength(uint32_t* aLength)
-{
-  *aLength = mPoints.Length();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchList::Item(uint32_t aIndex, nsIDOMTouch** aRetVal)
-{
-  NS_IF_ADDREF(*aRetVal = mPoints.SafeElementAt(aIndex, nullptr));
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchList::IdentifiedTouch(int32_t aIdentifier, nsIDOMTouch** aRetVal)
-{
-  *aRetVal = nullptr;
-  for (uint32_t i = 0; i < mPoints.Length(); ++i) {
-    nsCOMPtr<nsIDOMTouch> point = mPoints[i];
-    int32_t identifier;
-    if (point && NS_SUCCEEDED(point->GetIdentifier(&identifier)) &&
-        aIdentifier == identifier) {
-      point.swap(*aRetVal);
-      break;
-    }
-  }
-  return NS_OK;
-}
-
-// TouchEvent
-
-nsDOMTouchEvent::nsDOMTouchEvent(mozilla::dom::EventTarget* aOwner,
-                                 nsPresContext* aPresContext,
-                                 nsTouchEvent* aEvent)
-  : nsDOMUIEvent(aOwner, aPresContext,
-                 aEvent ? aEvent : new nsTouchEvent(false, 0, nullptr))
-{
-  if (aEvent) {
-    mEventIsInternal = false;
-
-    for (uint32_t i = 0; i < aEvent->touches.Length(); ++i) {
-      nsIDOMTouch *touch = aEvent->touches[i];
-      nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
-      domtouch->InitializePoints(mPresContext, aEvent);
-    }
-  } else {
-    mEventIsInternal = true;
-    mEvent->time = PR_Now();
-  }
-}
-
-nsDOMTouchEvent::~nsDOMTouchEvent()
-{
-  if (mEventIsInternal && mEvent) {
-    delete static_cast<nsTouchEvent*>(mEvent);
-    mEvent = nullptr;
-  }
-}
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mTouches)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mTargetTouches)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mChangedTouches)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTouches)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTargetTouches)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChangedTouches)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-DOMCI_DATA(TouchEvent, nsDOMTouchEvent)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMTouchEvent)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMTouchEvent)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TouchEvent)
-NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
-
-NS_IMPL_ADDREF_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
-NS_IMPL_RELEASE_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
-
-
-NS_IMETHODIMP
-nsDOMTouchEvent::InitTouchEvent(const nsAString& aType,
-                                bool aCanBubble,
-                                bool aCancelable,
-                                nsIDOMWindow* aView,
-                                int32_t aDetail,
-                                bool aCtrlKey,
-                                bool aAltKey,
-                                bool aShiftKey,
-                                bool aMetaKey,
-                                nsIDOMTouchList* aTouches,
-                                nsIDOMTouchList* aTargetTouches,
-                                nsIDOMTouchList* aChangedTouches)
-{
-  nsresult rv = nsDOMUIEvent::InitUIEvent(aType,
-                                          aCanBubble,
-                                          aCancelable,
-                                          aView,
-                                          aDetail);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  static_cast<nsInputEvent*>(mEvent)->InitBasicModifiers(aCtrlKey, aAltKey,
-                                                         aShiftKey, aMetaKey);
-  mTouches = aTouches;
-  mTargetTouches = aTargetTouches;
-  mChangedTouches = aChangedTouches;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetTouches(nsIDOMTouchList** aTouches)
-{
-  NS_ENSURE_ARG_POINTER(aTouches);
-  NS_ENSURE_STATE(mEvent);
-  nsRefPtr<nsDOMTouchList> t;
-
-  if (mTouches) {
-    return CallQueryInterface(mTouches, aTouches);
-  }
-
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
-    // for touchend events, remove any changed touches from the touches array
-    nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
-    const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-    for (uint32_t i = 0; i < touches.Length(); ++i) {
-      if (!touches[i]->mChanged) {
-        unchangedTouches.AppendElement(touches[i]);
-      }
-    }
-    t = new nsDOMTouchList(unchangedTouches);
-  } else {
-    t = new nsDOMTouchList(touchEvent->touches);
-  }
-  mTouches = t;
-  return CallQueryInterface(mTouches, aTouches);
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetTargetTouches(nsIDOMTouchList** aTargetTouches)
-{
-  NS_ENSURE_ARG_POINTER(aTargetTouches);
-  NS_ENSURE_STATE(mEvent);
-
-  if (mTargetTouches) {
-    return CallQueryInterface(mTargetTouches, aTargetTouches);
-  }
-
-  nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-  for (uint32_t i = 0; i < touches.Length(); ++i) {
-    // for touchend/cancel events, don't append to the target list if this is a
-    // touch that is ending
-    if ((mEvent->message != NS_TOUCH_END &&
-         mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
-      nsIDOMEventTarget* targetPtr = touches[i]->GetTarget();
-      if (targetPtr == mEvent->originalTarget) {
-        targetTouches.AppendElement(touches[i]);
-      }
-    }
-  }
-  mTargetTouches = new nsDOMTouchList(targetTouches);
-  return CallQueryInterface(mTargetTouches, aTargetTouches);
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetChangedTouches(nsIDOMTouchList** aChangedTouches)
-{
-  NS_ENSURE_ARG_POINTER(aChangedTouches);
-  NS_ENSURE_STATE(mEvent);
-
-  if (mChangedTouches) {
-    return CallQueryInterface(mChangedTouches, aChangedTouches);
-  }
-
-  nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
-  nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
-  const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
-  for (uint32_t i = 0; i < touches.Length(); ++i) {
-    if (touches[i]->mChanged) {
-      changedTouches.AppendElement(touches[i]);
-    }
-  }
-  mChangedTouches = new nsDOMTouchList(changedTouches);
-  return CallQueryInterface(mChangedTouches, aChangedTouches);
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetAltKey(bool* aAltKey)
-{
-  *aAltKey = static_cast<nsInputEvent*>(mEvent)->IsAlt();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetMetaKey(bool* aMetaKey)
-{
-  *aMetaKey = static_cast<nsInputEvent*>(mEvent)->IsMeta();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetCtrlKey(bool* aCtrlKey)
-{
-  *aCtrlKey = static_cast<nsInputEvent*>(mEvent)->IsControl();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouchEvent::GetShiftKey(bool* aShiftKey)
-{
-  *aShiftKey = static_cast<nsInputEvent*>(mEvent)->IsShift();
-  return NS_OK;
-}
-
-#ifdef XP_WIN
-namespace mozilla {
-namespace widget {
-extern int32_t IsTouchDeviceSupportPresent();
-} }
-#endif
-
-bool
-nsDOMTouchEvent::PrefEnabled()
-{
-  static bool sDidCheckPref = false;
-  static bool sPrefValue = false;
-  if (!sDidCheckPref) {
-    sDidCheckPref = true;
-    int32_t flag = 0;
-    if (NS_SUCCEEDED(Preferences::GetInt("dom.w3c_touch_events.enabled",
-                                         &flag))) {
-      if (flag == 2) {
-#ifdef XP_WIN
-        // On Windows we auto-detect based on device support.
-        sPrefValue = mozilla::widget::IsTouchDeviceSupportPresent();
-#else
-        NS_WARNING("dom.w3c_touch_events.enabled=2 not implemented!");
-        sPrefValue = false;
-#endif
-      } else {
-        sPrefValue = !!flag;
-      }
-    }
-    if (sPrefValue) {
-      nsContentUtils::InitializeTouchEventTable();
-    }
-  }
-  return sPrefValue;
-}
-
-nsresult
-NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
-                    mozilla::dom::EventTarget* aOwner,
-                    nsPresContext* aPresContext,
-                    nsTouchEvent *aEvent)
-{
-  nsDOMTouchEvent* it = new nsDOMTouchEvent(aOwner, aPresContext, aEvent);
-  return CallQueryInterface(it, aInstancePtrResult);
-}
+} // namespace dom
+} // namespace mozilla
copy from content/events/src/nsDOMTouchEvent.h
copy to content/events/src/Touch.h
--- a/content/events/src/nsDOMTouchEvent.h
+++ b/content/events/src/Touch.h
@@ -1,37 +1,41 @@
 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
 /* 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 nsDOMTouchEvent_h_
-#define nsDOMTouchEvent_h_
+
+#ifndef mozilla_dom_Touch_h
+#define mozilla_dom_Touch_h
 
 #include "nsDOMUIEvent.h"
 #include "nsIDOMTouchEvent.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
 #include "nsJSEnvironment.h"
 
-class nsDOMTouch MOZ_FINAL : public nsIDOMTouch
+namespace mozilla {
+namespace dom {
+
+class Touch MOZ_FINAL : public nsIDOMTouch
 {
 public:
-  nsDOMTouch(nsIDOMEventTarget* aTarget,
-             int32_t aIdentifier,
-             int32_t aPageX,
-             int32_t aPageY,
-             int32_t aScreenX,
-             int32_t aScreenY,
-             int32_t aClientX,
-             int32_t aClientY,
-             int32_t aRadiusX,
-             int32_t aRadiusY,
-             float aRotationAngle,
-             float aForce)
+  Touch(nsIDOMEventTarget* aTarget,
+        int32_t aIdentifier,
+        int32_t aPageX,
+        int32_t aPageY,
+        int32_t aScreenX,
+        int32_t aScreenY,
+        int32_t aClientX,
+        int32_t aClientY,
+        int32_t aRadiusX,
+        int32_t aRadiusY,
+        float aRotationAngle,
+        float aForce)
     {
       mTarget = aTarget;
       mIdentifier = aIdentifier;
       mPagePoint = nsIntPoint(aPageX, aPageY);
       mScreenPoint = nsIntPoint(aScreenX, aScreenY);
       mClientPoint = nsIntPoint(aClientX, aClientY);
       mRefPoint = nsIntPoint(0, 0);
       mPointsInitialized = true;
@@ -39,38 +43,38 @@ public:
       mRadius.y = aRadiusY;
       mRotationAngle = aRotationAngle;
       mForce = aForce;
 
       mChanged = false;
       mMessage = 0;
       nsJSContext::LikelyShortLivingObjectCreated();
     }
-  nsDOMTouch(int32_t aIdentifier,
-             nsIntPoint aPoint,
-             nsIntPoint aRadius,
-             float aRotationAngle,
-             float aForce)
+  Touch(int32_t aIdentifier,
+        nsIntPoint aPoint,
+        nsIntPoint aRadius,
+        float aRotationAngle,
+        float aForce)
     {
       mIdentifier = aIdentifier;
       mPagePoint = nsIntPoint(0, 0);
       mScreenPoint = nsIntPoint(0, 0);
       mClientPoint = nsIntPoint(0, 0);
       mRefPoint = aPoint;
       mPointsInitialized = false;
       mRadius = aRadius;
       mRotationAngle = aRotationAngle;
       mForce = aForce;
 
       mChanged = false;
       mMessage = 0;
       nsJSContext::LikelyShortLivingObjectCreated();
     }
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouch)
+  NS_DECL_CYCLE_COLLECTION_CLASS(Touch)
   NS_DECL_NSIDOMTOUCH
   void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent)
   {
     if (mPointsInitialized) {
       return;
     }
     mClientPoint = nsDOMEvent::GetClientCoords(aPresContext,
                                                aEvent,
@@ -95,57 +99,12 @@ public:
   nsIntPoint mScreenPoint;
   nsIntPoint mRadius;
   float mRotationAngle;
   float mForce;
 protected:
   bool mPointsInitialized;
 };
 
-class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList
-{
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList)
-  NS_DECL_NSIDOMTOUCHLIST
-
-  nsDOMTouchList()
-  {
-    nsJSContext::LikelyShortLivingObjectCreated();
-  }
-  nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches);
-
-  void Append(nsIDOMTouch* aPoint)
-  {
-    mPoints.AppendElement(aPoint);
-  }
-
-  nsIDOMTouch* GetItemAt(uint32_t aIndex)
-  {
-    return mPoints.SafeElementAt(aIndex, nullptr);
-  }
+} // namespace dom
+} // namespace mozilla
 
-protected:
-  nsTArray<nsCOMPtr<nsIDOMTouch> > mPoints;
-};
-
-class nsDOMTouchEvent : public nsDOMUIEvent,
-                        public nsIDOMTouchEvent
-{
-public:
-  nsDOMTouchEvent(mozilla::dom::EventTarget* aOwner,
-                  nsPresContext* aPresContext, nsTouchEvent* aEvent);
-  virtual ~nsDOMTouchEvent();
-
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
-  NS_DECL_NSIDOMTOUCHEVENT
-
-  NS_FORWARD_TO_NSDOMUIEVENT
-
-  static bool PrefEnabled();
-protected:
-  nsCOMPtr<nsIDOMTouchList> mTouches;
-  nsCOMPtr<nsIDOMTouchList> mTargetTouches;
-  nsCOMPtr<nsIDOMTouchList> mChangedTouches;
-};
-
-#endif /* !defined(nsDOMTouchEvent_h_) */
+#endif // mozilla_dom_Touch_h
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/nsDOMTouchEvent.cpp
@@ -6,139 +6,20 @@
 #include "nsDOMTouchEvent.h"
 #include "nsGUIEvent.h"
 #include "nsDOMClassInfoID.h"
 #include "nsIClassInfo.h"
 #include "nsIXPCScriptable.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsPresContext.h"
+#include "mozilla/dom/Touch.h"
 
 using namespace mozilla;
 
-DOMCI_DATA(Touch, nsDOMTouch)
-
-NS_IMPL_CYCLE_COLLECTION_1(nsDOMTouch, mTarget)
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouch)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMTouch)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMTouch)
-  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Touch)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouch)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouch)
-
-NS_IMETHODIMP
-nsDOMTouch::GetIdentifier(int32_t* aIdentifier)
-{
-  *aIdentifier = mIdentifier;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetTarget(nsIDOMEventTarget** aTarget)
-{
-  nsCOMPtr<nsIContent> content = do_QueryInterface(mTarget);
-  if (content && content->ChromeOnlyAccess() &&
-      !nsContentUtils::CanAccessNativeAnon()) {
-    content = content->FindFirstNonChromeOnlyAccessContent();
-    *aTarget = content.forget().get();
-    return NS_OK;
-  }
-  NS_IF_ADDREF(*aTarget = mTarget);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetScreenX(int32_t* aScreenX)
-{
-  *aScreenX = mScreenPoint.x;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetScreenY(int32_t* aScreenY)
-{
-  *aScreenY = mScreenPoint.y;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetClientX(int32_t* aClientX)
-{
-  *aClientX = mClientPoint.x;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetClientY(int32_t* aClientY)
-{
-  *aClientY = mClientPoint.y;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetPageX(int32_t* aPageX)
-{
-  *aPageX = mPagePoint.x;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetPageY(int32_t* aPageY)
-{
-  *aPageY = mPagePoint.y;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetRadiusX(int32_t* aRadiusX)
-{
-  *aRadiusX = mRadius.x;
-  return NS_OK;
-}
-                                             
-NS_IMETHODIMP
-nsDOMTouch::GetRadiusY(int32_t* aRadiusY)
-{
-  *aRadiusY = mRadius.y;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetRotationAngle(float* aRotationAngle)
-{
-  *aRotationAngle = mRotationAngle;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsDOMTouch::GetForce(float* aForce)
-{
-  *aForce = mForce;
-  return NS_OK;
-}
-
-bool
-nsDOMTouch::Equals(nsIDOMTouch* aTouch)
-{
-  float force;
-  float orientation;
-  int32_t radiusX, radiusY;
-  aTouch->GetForce(&force);
-  aTouch->GetRotationAngle(&orientation);
-  aTouch->GetRadiusX(&radiusX);
-  aTouch->GetRadiusY(&radiusY);
-  return mRefPoint != aTouch->mRefPoint ||
-         (mForce != force) ||
-         (mRotationAngle != orientation) ||
-         (mRadius.x != radiusX) || (mRadius.y != radiusY);
-}
-
 // TouchList
 nsDOMTouchList::nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
 {
   mPoints.AppendElements(aTouches);
   nsJSContext::LikelyShortLivingObjectCreated();
 }
 
 DOMCI_DATA(TouchList, nsDOMTouchList)
@@ -192,17 +73,17 @@ nsDOMTouchEvent::nsDOMTouchEvent(mozilla
   : nsDOMUIEvent(aOwner, aPresContext,
                  aEvent ? aEvent : new nsTouchEvent(false, 0, nullptr))
 {
   if (aEvent) {
     mEventIsInternal = false;
 
     for (uint32_t i = 0; i < aEvent->touches.Length(); ++i) {
       nsIDOMTouch *touch = aEvent->touches[i];
-      nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
+      dom::Touch *domtouch = static_cast<dom::Touch*>(touch);
       domtouch->InitializePoints(mPresContext, aEvent);
     }
   } else {
     mEventIsInternal = true;
     mEvent->time = PR_Now();
   }
 }
 
--- a/content/events/src/nsDOMTouchEvent.h
+++ b/content/events/src/nsDOMTouchEvent.h
@@ -7,104 +7,16 @@
 
 #include "nsDOMUIEvent.h"
 #include "nsIDOMTouchEvent.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "mozilla/Attributes.h"
 #include "nsJSEnvironment.h"
 
-class nsDOMTouch MOZ_FINAL : public nsIDOMTouch
-{
-public:
-  nsDOMTouch(nsIDOMEventTarget* aTarget,
-             int32_t aIdentifier,
-             int32_t aPageX,
-             int32_t aPageY,
-             int32_t aScreenX,
-             int32_t aScreenY,
-             int32_t aClientX,
-             int32_t aClientY,
-             int32_t aRadiusX,
-             int32_t aRadiusY,
-             float aRotationAngle,
-             float aForce)
-    {
-      mTarget = aTarget;
-      mIdentifier = aIdentifier;
-      mPagePoint = nsIntPoint(aPageX, aPageY);
-      mScreenPoint = nsIntPoint(aScreenX, aScreenY);
-      mClientPoint = nsIntPoint(aClientX, aClientY);
-      mRefPoint = nsIntPoint(0, 0);
-      mPointsInitialized = true;
-      mRadius.x = aRadiusX;
-      mRadius.y = aRadiusY;
-      mRotationAngle = aRotationAngle;
-      mForce = aForce;
-
-      mChanged = false;
-      mMessage = 0;
-      nsJSContext::LikelyShortLivingObjectCreated();
-    }
-  nsDOMTouch(int32_t aIdentifier,
-             nsIntPoint aPoint,
-             nsIntPoint aRadius,
-             float aRotationAngle,
-             float aForce)
-    {
-      mIdentifier = aIdentifier;
-      mPagePoint = nsIntPoint(0, 0);
-      mScreenPoint = nsIntPoint(0, 0);
-      mClientPoint = nsIntPoint(0, 0);
-      mRefPoint = aPoint;
-      mPointsInitialized = false;
-      mRadius = aRadius;
-      mRotationAngle = aRotationAngle;
-      mForce = aForce;
-
-      mChanged = false;
-      mMessage = 0;
-      nsJSContext::LikelyShortLivingObjectCreated();
-    }
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouch)
-  NS_DECL_NSIDOMTOUCH
-  void InitializePoints(nsPresContext* aPresContext, nsEvent* aEvent)
-  {
-    if (mPointsInitialized) {
-      return;
-    }
-    mClientPoint = nsDOMEvent::GetClientCoords(aPresContext,
-                                               aEvent,
-                                               mRefPoint,
-                                               mClientPoint);
-    mPagePoint = nsDOMEvent::GetPageCoords(aPresContext,
-                                           aEvent,
-                                           mRefPoint,
-                                           mClientPoint);
-    mScreenPoint = nsDOMEvent::GetScreenCoords(aPresContext, aEvent, mRefPoint);
-    mPointsInitialized = true;
-  }
-  void SetTarget(nsIDOMEventTarget *aTarget)
-  {
-    mTarget = aTarget;
-  }
-  bool Equals(nsIDOMTouch* aTouch);
-
-  int32_t mIdentifier;
-  nsIntPoint mPagePoint;
-  nsIntPoint mClientPoint;
-  nsIntPoint mScreenPoint;
-  nsIntPoint mRadius;
-  float mRotationAngle;
-  float mForce;
-protected:
-  bool mPointsInitialized;
-};
-
 class nsDOMTouchList MOZ_FINAL : public nsIDOMTouchList
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMTouchList)
   NS_DECL_NSIDOMTOUCHLIST
 
   nsDOMTouchList()
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -12,16 +12,17 @@
 #include "nsQueryContentEventResult.h"
 #include "nsGlobalWindow.h"
 #include "nsIDocument.h"
 #include "nsFocusManager.h"
 #include "nsEventStateManager.h"
 #include "nsFrameManager.h"
 #include "nsRefreshDriver.h"
 #include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsIDOMTouchEvent.h"
 #include "nsObjectLoadingContent.h"
 #include "nsFrame.h"
 
 #include "nsIScrollableFrame.h"
 
 #include "nsContentUtils.h"
 #include "nsLayoutUtils.h"
@@ -844,21 +845,21 @@ nsDOMWindowUtils::SendTouchEvent(const n
 
   nsPresContext* presContext = GetPresContext();
   if (!presContext) {
     return NS_ERROR_FAILURE;
   }
   event.touches.SetCapacity(aCount);
   for (uint32_t i = 0; i < aCount; ++i) {
     nsIntPoint pt = ToWidgetPoint(aXs[i], aYs[i], offset, presContext);
-    nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(aIdentifiers[i],
-                                           pt,
-                                           nsIntPoint(aRxs[i], aRys[i]),
-                                           aRotationAngles[i],
-                                           aForces[i]));
+    nsCOMPtr<nsIDOMTouch> t(new Touch(aIdentifiers[i],
+                                      pt,
+                                      nsIntPoint(aRxs[i], aRys[i]),
+                                      aRotationAngles[i],
+                                      aForces[i]));
     event.touches.AppendElement(t);
   }
 
   nsEventStatus status;
   nsresult rv = widget->DispatchEvent(&event, status);
   *aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
   return rv;
 }
@@ -1603,17 +1604,17 @@ nsDOMWindowUtils::FindElementWithViewId(
 
   if (aID == FrameMetrics::ROOT_SCROLL_ID) {
     nsPresContext* presContext = GetPresContext();
     if (!presContext) {
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     nsIDocument* document = presContext->Document();
-    mozilla::dom::Element* rootElement = document->GetRootElement();
+    Element* rootElement = document->GetRootElement();
     if (!rootElement) {
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     CallQueryInterface(rootElement, aResult);
     return NS_OK;
   }
 
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -1615,21 +1615,21 @@ TabChild::DispatchSynthesizedMouseEvent(
   event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
   if (aMsg != NS_MOUSE_MOVE) {
     event.clickCount = 1;
   }
 
   DispatchWidgetEvent(event);
 }
 
-static nsDOMTouch*
+static Touch*
 GetTouchForIdentifier(const nsTouchEvent& aEvent, int32_t aId)
 {
   for (uint32_t i = 0; i < aEvent.touches.Length(); ++i) {
-    nsDOMTouch* touch = static_cast<nsDOMTouch*>(aEvent.touches[i].get());
+    Touch* touch = static_cast<Touch*>(aEvent.touches[i].get());
     if (touch->mIdentifier == aId) {
       return touch;
     }
   }
   return nullptr;
 }
 
 void
@@ -1659,17 +1659,17 @@ TabChild::UpdateTapState(const nsTouchEv
       // the first point.  Ignore this one.
       return;
     }
     if (aStatus == nsEventStatus_eConsumeNoDefault ||
         nsIPresShell::gPreventMouseEvents) {
       return;
     }
 
-    nsDOMTouch* touch = static_cast<nsDOMTouch*>(aEvent.touches[0].get());
+    Touch* touch = static_cast<Touch*>(aEvent.touches[0].get());
     mGestureDownPoint = touch->mRefPoint;
     mActivePointerId = touch->mIdentifier;
     if (sClickHoldContextMenusEnabled) {
       MOZ_ASSERT(!mTapHoldTimer);
       mTapHoldTimer = NewRunnableMethod(this,
                                         &TabChild::FireContextMenuEvent);
       MessageLoop::current()->PostDelayedTask(FROM_HERE, mTapHoldTimer,
                                               sContextMenuDelayMs);
@@ -1677,17 +1677,17 @@ TabChild::UpdateTapState(const nsTouchEv
     return;
   }
 
   // If we're not tracking a touch or this event doesn't include the
   // one we care about, bail.
   if (!currentlyTrackingTouch) {
     return;
   }
-  nsDOMTouch* trackedTouch = GetTouchForIdentifier(aEvent, mActivePointerId);
+  Touch* trackedTouch = GetTouchForIdentifier(aEvent, mActivePointerId);
   if (!trackedTouch) {
     return;
   }
 
   nsIntPoint currentPoint = trackedTouch->mRefPoint;
   int64_t time = aEvent.time;
   switch (aEvent.message) {
   case NS_TOUCH_MOVE:
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -76,17 +76,17 @@
 #include "nsEventStateManager.h"
 #include "nsIMEStateManager.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsILayoutHistoryState.h"
 #include "nsILineIterator.h" // for ScrollContentIntoView
 #include "nsWeakPtr.h"
 #include "pldhash.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsIObserverService.h"
 #include "nsIDocShell.h"        // for reflow observation
 #include "nsIBaseWindow.h"
 #include "nsError.h"
 #include "nsLayoutUtils.h"
 #include "nsCSSRendering.h"
   // for |#ifdef DEBUG| code
 #include "prenv.h"
@@ -6171,17 +6171,17 @@ PresShell::HandleEvent(nsIFrame        *
         } else {
           gPreventMouseEvents = false;
         }
 
         // Add any new touches to the queue
         for (int32_t i = touchEvent->touches.Length(); i; ) {
           --i;
           nsIDOMTouch *touch = touchEvent->touches[i];
-          nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
+          Touch *domtouch = static_cast<Touch*>(touch);
           touch->mMessage = aEvent->message;
 
           int32_t id = 0;
           touch->GetIdentifier(&id);
           if (!gCaptureTouchList.Get(id, nullptr)) {
             // This event is a new touch. Mark it as a changedTouch and
             // add it to the queue.
             touch->mChanged = true;
@@ -6703,17 +6703,17 @@ PresShell::HandleEventInternal(nsEvent* 
       case NS_TOUCH_CANCEL:
       case NS_TOUCH_END: {
         // Remove the changed touches
         // need to make sure we only remove touches that are ending here
         nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
         nsTArray<nsCOMPtr<nsIDOMTouch> >  &touches = touchEvent->touches;
         for (uint32_t i = 0; i < touches.Length(); ++i) {
           nsIDOMTouch *touch = touches[i];
-          nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
+          Touch *domtouch = static_cast<Touch*>(touch);
           if (!touch) {
             continue;
           }
           touch->mMessage = aEvent->message;
           touch->mChanged = true;
           nsCOMPtr<nsIDOMTouch> oldTouch;
 
           int32_t id;
@@ -6737,17 +6737,17 @@ PresShell::HandleEventInternal(nsEvent* 
       case NS_TOUCH_MOVE: {
         // Check for touches that changed. Mark them add to queue
         nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
         nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
         bool haveChanged = false;
         for (int32_t i = touches.Length(); i; ) {
           --i;
           nsIDOMTouch *touch = touches[i];
-          nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
+          Touch *domtouch = static_cast<Touch*>(touch);
           if (!touch) {
             continue;
           }
           int32_t id;
           touch->GetIdentifier(&id);
           touch->mMessage = aEvent->message;
 
           nsCOMPtr<nsIDOMTouch> oldTouch;
--- a/layout/xul/base/src/nsBoxFrame.cpp
+++ b/layout/xul/base/src/nsBoxFrame.cpp
@@ -28,17 +28,17 @@
 // ----------------------------
 // Boxes layout out top down by adding up their children's min, max, and preferred sizes. Only problem is if a incremental
 // reflow occurs. The preferred size of a child deep in the hierarchy could change. And this could change
 // any number of syblings around the box. Basically any children in the reflow chain must have their caches cleared
 // so when asked for there current size they can relayout themselves. 
 
 #include "nsBoxLayoutState.h"
 #include "nsBoxFrame.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsStyleContext.h"
 #include "nsPresContext.h"
 #include "nsCOMPtr.h"
 #include "nsINameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsIContent.h"
 #include "nsHTMLParts.h"
 #include "nsViewManager.h"
@@ -61,16 +61,17 @@
 #include "nsDisplayList.h"
 #include "mozilla/Preferences.h"
 #include <algorithm>
 
 // Needed for Print Preview
 #include "nsIURI.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
 
 //define DEBUG_REDRAW
 
 #define DEBUG_SPRING_SIZE 8
 #define DEBUG_BORDER_SIZE 2
 #define COIL_SIZE 8
 
 //#define TEST_SANITY
@@ -2066,20 +2067,20 @@ nsBoxFrame::GetEventPoint(nsGUIEvent* aE
 
   if (aEvent->eventStructType == NS_TOUCH_EVENT) {
     nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
     // return false if there is more than one touch on the page, or if
     // we can't find a touch point
     if (touchEvent->touches.Length() != 1) {
       return false;
     }
-  
+
     nsIDOMTouch *touch = touchEvent->touches.SafeElementAt(0);
     if (!touch) {
       return false;
     }
-    nsDOMTouch* domtouch = static_cast<nsDOMTouch*>(touch);
+    Touch* domtouch = static_cast<Touch*>(touch);
     aPoint = domtouch->mRefPoint;
   } else {
     aPoint = aEvent->refPoint;
   }
   return true;
 }
--- a/layout/xul/base/src/nsSliderFrame.cpp
+++ b/layout/xul/base/src/nsSliderFrame.cpp
@@ -15,17 +15,16 @@
 #include "nsPresContext.h"
 #include "nsIContent.h"
 #include "nsCOMPtr.h"
 #include "nsINameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsHTMLParts.h"
 #include "nsIPresShell.h"
 #include "nsCSSRendering.h"
-#include "nsDOMTouchEvent.h"
 #include "nsEventListenerManager.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMMouseEvent.h"
 #include "nsScrollbarButtonFrame.h"
 #include "nsISliderListener.h"
 #include "nsIScrollbarMediator.h"
 #include "nsScrollbarFrame.h"
 #include "nsRepeatService.h"
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -62,29 +62,29 @@ protected:
       mTime(aTime)
   {
 
 
   }
 };
 
 /**
- * Data container for a single touch input. Similar to nsDOMTouch, but used in
+ * Data container for a single touch input. Similar to dom::Touch, but used in
  * off-main-thread situations. This is more for just storing touch data, whereas
- * nsDOMTouch derives from nsIDOMTouch so it is more useful for dispatching
- * through the DOM (which can only happen on the main thread). nsDOMTouch also
+ * dom::Touch derives from nsIDOMTouch so it is more useful for dispatching
+ * through the DOM (which can only happen on the main thread). dom::Touch also
  * bears the problem of storing pointers to nsIWidget instances which can only
- * be used on the main thread, so if instead we used nsDOMTouch and ever set
+ * be used on the main thread, so if instead we used dom::Touch and ever set
  * these pointers off-main-thread, Bad Things Can Happen(tm).
  *
  * Note that this doesn't inherit from InputData because this itself is not an
  * event. It is only a container/struct that should have any number of instances
  * within a MultiTouchInput.
  *
- * fixme/bug 775746: Make nsDOMTouch inherit from this class.
+ * fixme/bug 775746: Make dom::Touch inherit from this class.
  */
 class SingleTouchData
 {
 public:
   SingleTouchData(int32_t aIdentifier,
                   nsIntPoint aScreenPoint,
                   nsIntPoint aRadius,
                   float aRotationAngle,
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -23,17 +23,17 @@ using mozilla::unused;
 #include "nsWindow.h"
 #include "nsIObserverService.h"
 #include "nsFocusManager.h"
 #include "nsIWidgetListener.h"
 #include "nsViewManager.h"
 
 #include "nsRenderingContext.h"
 #include "nsIDOMSimpleGestureEvent.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 
 #include "nsGkAtoms.h"
 #include "nsWidgetsCID.h"
 #include "nsGfxCIID.h"
 
 #include "gfxImageSurface.h"
 #include "gfxContext.h"
 
@@ -48,16 +48,17 @@ using mozilla::unused;
 #include "AndroidBridge.h"
 #include "android_npapi.h"
 
 #include "imgIEncoder.h"
 
 #include "nsStringGlue.h"
 
 using namespace mozilla;
+using namespace mozilla::dom;
 using namespace mozilla::widget;
 
 NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsBaseWidget)
 
 // The dimensions of the current android view
 static gfxIntSize gAndroidBounds = gfxIntSize(0, 0);
 static gfxIntSize gAndroidScreenBounds;
 
@@ -1266,31 +1267,31 @@ nsWindow::DispatchMultitouchEvent(nsTouc
                              ae->IsShiftPressed(),
                              ae->IsMetaPressed());
 
     int action = ae->Action() & AndroidMotionEvent::ACTION_MASK;
     if (action == AndroidMotionEvent::ACTION_UP ||
         action == AndroidMotionEvent::ACTION_POINTER_UP) {
         event.touches.SetCapacity(1);
         int pointerIndex = ae->PointerIndex();
-        nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(ae->PointIndicies()[pointerIndex],
-                                               ae->Points()[pointerIndex] - offset,
-                                               ae->PointRadii()[pointerIndex],
-                                               ae->Orientations()[pointerIndex],
-                                               ae->Pressures()[pointerIndex]));
+        nsCOMPtr<nsIDOMTouch> t(new Touch(ae->PointIndicies()[pointerIndex],
+                                          ae->Points()[pointerIndex] - offset,
+                                          ae->PointRadii()[pointerIndex],
+                                          ae->Orientations()[pointerIndex],
+                                          ae->Pressures()[pointerIndex]));
         event.touches.AppendElement(t);
     } else {
         int count = ae->Count();
         event.touches.SetCapacity(count);
         for (int i = 0; i < count; i++) {
-            nsCOMPtr<nsIDOMTouch> t(new nsDOMTouch(ae->PointIndicies()[i],
-                                                   ae->Points()[i] - offset,
-                                                   ae->PointRadii()[i],
-                                                   ae->Orientations()[i],
-                                                   ae->Pressures()[i]));
+            nsCOMPtr<nsIDOMTouch> t(new Touch(ae->PointIndicies()[i],
+                                              ae->Points()[i] - offset,
+                                              ae->PointRadii()[i],
+                                              ae->Orientations()[i],
+                                              ae->Pressures()[i]));
             event.touches.AppendElement(t);
         }
     }
 
     nsEventStatus status;
     DispatchEvent(&event, status);
     // We check mMultipleActionsPrevented because that's what <input type=range>
     // sets when someone starts dragging the thumb. It doesn't set the status
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -30,17 +30,17 @@
 
 #include "base/basictypes.h"
 #include "nscore.h"
 #include "mozilla/FileUtils.h"
 #include "mozilla/Hal.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Services.h"
 #include "nsAppShell.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsGkAtoms.h"
 #include "nsGUIEvent.h"
 #include "nsIObserverService.h"
 #include "nsIScreen.h"
 #include "nsScreenManagerGonk.h"
 #include "nsWindow.h"
 #include "OrientationObserver.h"
 #include "GonkMemoryPressureMonitoring.h"
@@ -82,17 +82,17 @@ bool ProcessNextEvent()
     return gAppShell->ProcessNextNativeEvent(true);
 }
 
 void NotifyEvent()
 {
     gAppShell->NotifyNativeEvent();
 }
 
-}
+} // namespace mozilla
 
 static void
 pipeHandler(int fd, FdHandler *data)
 {
     ssize_t len;
     do {
         char tmp[32];
         len = read(fd, tmp, sizeof(tmp));
@@ -115,17 +115,17 @@ struct UserInputData {
     int32_t metaState;
     union {
         struct {
             int32_t keyCode;
             int32_t scanCode;
         } key;
         struct {
             int32_t touchCount;
-            Touch touches[MAX_POINTERS];
+            ::Touch touches[MAX_POINTERS];
         } motion;
     };
 };
 
 static void
 sendMouseEvent(uint32_t msg, uint64_t timeMs, int x, int y, bool forwardToChildren)
 {
     nsMouseEvent event(true, msg, NULL,
@@ -142,19 +142,19 @@ sendMouseEvent(uint32_t msg, uint64_t ti
     event.mFlags.mNoCrossProcessBoundaryForwarding = !forwardToChildren;
 
     nsWindow::DispatchInputEvent(event);
 }
 
 static void
 addDOMTouch(UserInputData& data, nsTouchEvent& event, int i)
 {
-    const Touch& touch = data.motion.touches[i];
+    const ::Touch& touch = data.motion.touches[i];
     event.touches.AppendElement(
-        new nsDOMTouch(touch.id,
+        new dom::Touch(touch.id,
                        nsIntPoint(touch.coords.getX(), touch.coords.getY()),
                        nsIntPoint(touch.coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE),
                                   touch.coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE)),
                        0,
                        touch.coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE))
     );
 }
 
@@ -519,17 +519,17 @@ GeckoInputDispatcher::notifyMotion(const
     data.timeMs = nanosecsToMillisecs(args->eventTime);
     data.type = UserInputData::MOTION_DATA;
     data.action = args->action;
     data.flags = args->flags;
     data.metaState = args->metaState;
     MOZ_ASSERT(args->pointerCount <= MAX_POINTERS);
     data.motion.touchCount = args->pointerCount;
     for (uint32_t i = 0; i < args->pointerCount; ++i) {
-        Touch& touch = data.motion.touches[i];
+        ::Touch& touch = data.motion.touches[i];
         touch.id = args->pointerProperties[i].id;
         memcpy(&touch.coords, &args->pointerCoords[i], sizeof(*args->pointerCoords));
     }
     {
         MutexAutoLock lock(mQueueLock);
         if (!mEventQueue.empty() &&
              mEventQueue.back().type == UserInputData::MOTION_DATA &&
            ((mEventQueue.back().action & AMOTION_EVENT_ACTION_MASK) ==
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -2,17 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsGUIEventIPC_h__
 #define nsGUIEventIPC_h__
 
 #include "ipc/IPCMessageUtils.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsGUIEvent.h"
 
 namespace IPC
 {
 
 template<>
 struct ParamTraits<mozilla::widget::BaseEventFlags>
 {
@@ -199,22 +199,22 @@ struct ParamTraits<nsMouseEvent>
 template<>
 struct ParamTraits<nsTouchEvent>
 {
   typedef nsTouchEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, static_cast<const nsInputEvent&>(aParam));
-    // Sigh, nsDOMTouch bites us again!  We want to be able to do
+    // Sigh, Touch bites us again!  We want to be able to do
     //   WriteParam(aMsg, aParam.touches);
     const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = aParam.touches;
     WriteParam(aMsg, touches.Length());
     for (uint32_t i = 0; i < touches.Length(); ++i) {
-      nsDOMTouch* touch = static_cast<nsDOMTouch*>(touches[i].get());
+      mozilla::dom::Touch* touch = static_cast<mozilla::dom::Touch*>(touches[i].get());
       WriteParam(aMsg, touch->mIdentifier);
       WriteParam(aMsg, touch->mRefPoint);
       WriteParam(aMsg, touch->mRadius);
       WriteParam(aMsg, touch->mRotationAngle);
       WriteParam(aMsg, touch->mForce);
     }
   }
 
@@ -234,17 +234,17 @@ struct ParamTraits<nsTouchEvent>
         if (!ReadParam(aMsg, aIter, &identifier) ||
             !ReadParam(aMsg, aIter, &refPoint) ||
             !ReadParam(aMsg, aIter, &radius) ||
             !ReadParam(aMsg, aIter, &rotationAngle) ||
             !ReadParam(aMsg, aIter, &force)) {
           return false;
         }
         aResult->touches.AppendElement(
-          new nsDOMTouch(identifier, refPoint, radius, rotationAngle, force));
+          new mozilla::dom::Touch(identifier, refPoint, radius, rotationAngle, force));
     }
     return true;
   }
 };
 
 template<>
 struct ParamTraits<nsKeyEvent>
 {
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -113,17 +113,17 @@
 #include "Layers.h"
 #include "nsPrintfCString.h"
 #include "mozilla/Preferences.h"
 #include "nsISound.h"
 #include "WinTaskbar.h"
 #include "WinUtils.h"
 #include "WidgetUtils.h"
 #include "nsIWidgetListener.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 
 #ifdef MOZ_ENABLE_D3D9_LAYER
 #include "LayerManagerD3D9.h"
 #endif
 
 #ifdef MOZ_ENABLE_D3D10_LAYER
 #include "LayerManagerD3D10.h"
 #endif
@@ -159,19 +159,20 @@
 #include "nsCrashOnException.h"
 #include "nsIXULRuntime.h"
 
 #include "nsIContent.h"
 
 #include "mozilla/HangMonitor.h"
 #include "WinIMEHandler.h"
 
-using namespace mozilla::widget;
+using namespace mozilla;
+using namespace mozilla::dom;
 using namespace mozilla::layers;
-using namespace mozilla;
+using namespace mozilla::widget;
 
 /**************************************************************
  **************************************************************
  **
  ** BLOCK: Variables
  **
  ** nsWindow Class static initializations and global variables. 
  **
@@ -6327,26 +6328,26 @@ bool nsWindow::OnTouch(WPARAM wParam, LP
       }
 
       // Setup the touch point we'll append to the touch event array
       nsPointWin touchPoint;
       touchPoint.x = TOUCH_COORD_TO_PIXEL(pInputs[i].x);
       touchPoint.y = TOUCH_COORD_TO_PIXEL(pInputs[i].y);
       touchPoint.ScreenToClient(mWnd);
       nsCOMPtr<nsIDOMTouch> touch =
-        new nsDOMTouch(pInputs[i].dwID,
-                       touchPoint,
-                       /* radius, if known */
-                       pInputs[i].dwFlags & TOUCHINPUTMASKF_CONTACTAREA ?
-                         nsIntPoint(
-                           TOUCH_COORD_TO_PIXEL(pInputs[i].cxContact) / 2,
-                           TOUCH_COORD_TO_PIXEL(pInputs[i].cyContact) / 2) :
-                         nsIntPoint(1,1),
-                       /* rotation angle and force */
-                       0.0f, 0.0f);
+        new Touch(pInputs[i].dwID,
+                  touchPoint,
+                  /* radius, if known */
+                  pInputs[i].dwFlags & TOUCHINPUTMASKF_CONTACTAREA ?
+                    nsIntPoint(
+                      TOUCH_COORD_TO_PIXEL(pInputs[i].cxContact) / 2,
+                      TOUCH_COORD_TO_PIXEL(pInputs[i].cyContact) / 2) :
+                    nsIntPoint(1,1),
+                  /* rotation angle and force */
+                  0.0f, 0.0f);
 
       // Append to the appropriate event
       if (msg == NS_TOUCH_START || msg == NS_TOUCH_MOVE) {
         touchEventToSend->touches.AppendElement(touch);
       } else {
         touchEndEventToSend->touches.AppendElement(touch);
       }
     }
--- a/widget/windows/winrt/MetroInput.cpp
+++ b/widget/windows/winrt/MetroInput.cpp
@@ -4,30 +4,31 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MetroInput.h"
 
 // Moz headers (alphabetical)
 #include "MetroUtils.h" // Logging, POINT_CEIL_*, ActivateGenericInstance, etc
 #include "MetroWidget.h" // MetroInput::mWidget
 #include "npapi.h" // NPEvent
-#include "nsDOMTouchEvent.h"  // nsDOMTouch
+#include "mozilla/dom/Touch.h"  // Touch
 #include "nsTArray.h" // Touch lists
 #include "nsIDOMSimpleGestureEvent.h" // Constants for gesture events
 
 // System headers (alphabetical)
 #include <windows.ui.core.h> // ABI::Window::UI::Core namespace
 #include <windows.ui.input.h> // ABI::Window::UI::Input namespace
 
 //#define DEBUG_INPUT
 
 // Using declarations
 using namespace ABI::Windows; // UI, System, Foundation namespaces
 using namespace Microsoft; // WRL namespace (ComPtr, possibly others)
 using namespace mozilla::widget::winrt;
+using namespace mozilla::dom;
 
 // File-scoped statics (unnamed namespace)
 namespace {
   // XXX: Set these min values appropriately
   const double SWIPE_MIN_DISTANCE = 5.0;
   const double SWIPE_MIN_VELOCITY = 5.0;
 
   const double WHEEL_DELTA_DOUBLE = static_cast<double>(WHEEL_DELTA);
@@ -41,27 +42,27 @@ namespace {
   typedef Foundation::__FITypedEventHandler_2_Windows__CUI__CInput__CGestureRecognizer_Windows__CUI__CInput__CManipulationStartedEventArgs_t ManipulationStartedEventHandler;
   typedef Foundation::__FITypedEventHandler_2_Windows__CUI__CInput__CGestureRecognizer_Windows__CUI__CInput__CManipulationUpdatedEventArgs_t ManipulationUpdatedEventHandler;
   typedef Foundation::__FITypedEventHandler_2_Windows__CUI__CInput__CGestureRecognizer_Windows__CUI__CInput__CManipulationCompletedEventArgs_t ManipulationCompletedEventHandler;
 
   // Other convenience typedefs
   typedef ABI::Windows::UI::Core::ICoreAcceleratorKeys ICoreAcceleratorKeys;
 
   /**
-   * Creates and returns a new {@link nsDOMTouch} from the given
+   * Creates and returns a new {@link Touch} from the given
    * ABI::Windows::UI::Input::IPointerPoint.  Note that the caller is
-   * responsible for freeing the memory for the nsDOMTouch returned from
+   * responsible for freeing the memory for the Touch returned from
    * this function.
    *
    * @param aPoint the ABI::Windows::UI::Input::IPointerPoint containing the
-   *               metadata from which to create our new {@link nsDOMTouch}
-   * @return a new {@link nsDOMTouch} representing the touch point. The caller
+   *               metadata from which to create our new {@link Touch}
+   * @return a new {@link Touch} representing the touch point. The caller
    *         is responsible for freeing the memory for this touch point.
    */
-  nsDOMTouch*
+  Touch*
   CreateDOMTouch(UI::Input::IPointerPoint* aPoint) {
     WRL::ComPtr<UI::Input::IPointerPointProperties> props;
     Foundation::Point position;
     uint32_t pointerId;
     Foundation::Rect contactRect;
     float pressure;
 
     aPoint->get_Properties(props.GetAddressOf());
@@ -69,38 +70,38 @@ namespace {
     aPoint->get_PointerId(&pointerId);
     props->get_ContactRect(&contactRect);
     props->get_Pressure(&pressure);
 
     nsIntPoint touchPoint = MetroUtils::LogToPhys(position);
     nsIntPoint touchRadius;
     touchRadius.x = MetroUtils::LogToPhys(contactRect.Width) / 2;
     touchRadius.y = MetroUtils::LogToPhys(contactRect.Height) / 2;
-    return new nsDOMTouch(pointerId,
-                          touchPoint,
-                          // Rotation radius and angle.
-                          // W3C touch events v1 do not use these.
-                          // The draft for W3C touch events v2 explains that
-                          // radius and angle should describe the ellipse that
-                          // most closely circumscribes the touching area.  Since
-                          // Windows gives us a bounding rectangle rather than an
-                          // ellipse, we provide the ellipse that is most closely
-                          // circumscribed by the bounding rectangle that Windows
-                          // gave us.
-                          touchRadius,
-                          0.0f,
-                          // Pressure
-                          // W3C touch events v1 do not use this.
-                          // The current draft for W3C touch events v2 says that
-                          // this should be a value between 0.0 and 1.0, which is
-                          // consistent with what Windows provides us here.
-                          // XXX: Windows defaults to 0.5, but the current W3C
-                          // draft says that the value should be 0.0 if no value
-                          // known.
-                          pressure);
+    return new Touch(pointerId,
+                     touchPoint,
+                     // Rotation radius and angle.
+                     // W3C touch events v1 do not use these.
+                     // The draft for W3C touch events v2 explains that
+                     // radius and angle should describe the ellipse that
+                     // most closely circumscribes the touching area.  Since
+                     // Windows gives us a bounding rectangle rather than an
+                     // ellipse, we provide the ellipse that is most closely
+                     // circumscribed by the bounding rectangle that Windows
+                     // gave us.
+                     touchRadius,
+                     0.0f,
+                     // Pressure
+                     // W3C touch events v1 do not use this.
+                     // The current draft for W3C touch events v2 says that
+                     // this should be a value between 0.0 and 1.0, which is
+                     // consistent with what Windows provides us here.
+                     // XXX: Windows defaults to 0.5, but the current W3C
+                     // draft says that the value should be 0.0 if no value
+                     // known.
+                     pressure);
   }
 
   bool
   IsControlCharacter(uint32_t aCharCode) {
     return (0x1F >= aCharCode
          || (0x7F <= aCharCode && 0x9F >= aCharCode));
   }
 
--- a/widget/xpwidgets/InputData.cpp
+++ b/widget/xpwidgets/InputData.cpp
@@ -1,21 +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 "InputData.h"
 
 #include "nsGUIEvent.h"
-#include "nsDOMTouchEvent.h"
+#include "mozilla/dom/Touch.h"
 #include "nsDebug.h"
 
 namespace mozilla {
 
+using namespace dom;
+
 MultiTouchInput::MultiTouchInput(const nsTouchEvent& aTouchEvent)
   : InputData(MULTITOUCH_INPUT, aTouchEvent.time)
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(),
                     "Can only copy from nsTouchEvent on main thread");
 
   switch (aTouchEvent.message) {
     case NS_TOUCH_START:
@@ -37,17 +39,17 @@ MultiTouchInput::MultiTouchInput(const n
       mType = MULTITOUCH_CANCEL;
       break;
     default:
       NS_WARNING("Did not assign a type to a MultiTouchInput");
       break;
   }
 
   for (size_t i = 0; i < aTouchEvent.touches.Length(); i++) {
-    nsDOMTouch* domTouch = (nsDOMTouch*)(aTouchEvent.touches[i].get());
+    Touch* domTouch = static_cast<Touch*>(aTouchEvent.touches[i].get());
 
     // Extract data from weird interfaces.
     int32_t identifier, radiusX, radiusY;
     float rotationAngle, force;
     domTouch->GetIdentifier(&identifier);
     domTouch->GetRadiusX(&radiusX);
     domTouch->GetRadiusY(&radiusY);
     domTouch->GetRotationAngle(&rotationAngle);