Bug 912956 part.6 Create mozilla/TouchEvents.h r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 24 Sep 2013 19:04:15 +0900
changeset 163199 93a96f509d9a1a3cada77f275c6e317e903813cc
parent 163198 354ac52e532516e169ff2769bedcf6e57cfcbcc5
child 163200 e4e2588531d623d5ae73018293e5a65295f0cc37
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs912956
milestone27.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 912956 part.6 Create mozilla/TouchEvents.h r=roc
widget/BasicEvents.h
widget/EventForwards.h
widget/TouchEvents.h
widget/moz.build
widget/nsGUIEvent.h
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -37,20 +37,20 @@ enum nsEventStructType
   NS_SELECTION_EVENT,                // WidgetSelectionEvent
 
   // MouseEvents.h
   NS_MOUSE_EVENT,                    // WidgetMouseEvent
   NS_DRAG_EVENT,                     // WidgetDragEvent
   NS_MOUSE_SCROLL_EVENT,             // WidgetMouseScrollEvent
   NS_WHEEL_EVENT,                    // WidgetWheelEvent
 
-  // Touchpad related events
-  NS_GESTURENOTIFY_EVENT,            // nsGestureNotifyEvent
-  NS_SIMPLE_GESTURE_EVENT,           // nsSimpleGestureEvent
-  NS_TOUCH_EVENT,                    // nsTouchEvent
+  // TouchEvents.h
+  NS_GESTURENOTIFY_EVENT,            // WidgetGestureNotifyEvent
+  NS_SIMPLE_GESTURE_EVENT,           // WidgetSimpleGestureEvent
+  NS_TOUCH_EVENT,                    // WidgetTouchEvent
 
   // Scroll related events
   NS_SCROLLPORT_EVENT,               // nsScrollPortEvent
   NS_SCROLLAREA_EVENT,               // nsScrollAreaEvent
 
   // DOM events
   NS_SCRIPT_ERROR_EVENT,             // nsScriptErrorEvent
   NS_MUTATION_EVENT,                 // nsMutationEvent
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -72,22 +72,22 @@ class WidgetQueryContentEvent;
 class WidgetSelectionEvent;
 
 // MouseEvents.h
 class WidgetMouseEventBase;
 class WidgetMouseEvent;
 class WidgetDragEvent;
 class WidgetMouseScrollEvent;
 class WidgetWheelEvent;
-} // namespace mozilla
 
 // TouchEvents.h
-class nsGestureNotifyEvent;
-class nsTouchEvent;
-class nsSimpleGestureEvent;
+class WidgetGestureNotifyEvent;
+class WidgetSimpleGestureEvent;
+class WidgetTouchEvent;
+} // namespace mozilla
 
 // ContentEvents.h
 class nsScriptErrorEvent;
 class nsScrollPortEvent;
 class nsScrollAreaEvent;
 class nsFormEvent;
 class nsClipboardEvent;
 class nsFocusEvent;
@@ -120,9 +120,13 @@ typedef mozilla::WidgetMouseEventBase   
 typedef mozilla::WidgetMouseEvent         nsMouseEvent;
 typedef mozilla::WidgetDragEvent          nsDragEvent;
 typedef mozilla::WidgetMouseScrollEvent   nsMouseScrollEvent;
 
 namespace mozilla {
 typedef WidgetWheelEvent                  WheelEvent;
 }
 
+typedef mozilla::WidgetGestureNotifyEvent nsGestureNotifyEvent;
+typedef mozilla::WidgetSimpleGestureEvent nsSimpleGestureEvent;
+typedef mozilla::WidgetTouchEvent         nsTouchEvent;
+
 #endif // mozilla_EventForwards_h__
new file mode 100644
--- /dev/null
+++ b/widget/TouchEvents.h
@@ -0,0 +1,159 @@
+/* -*- 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 mozilla_TouchEvents_h__
+#define mozilla_TouchEvents_h__
+
+#include <stdint.h>
+
+#include "mozilla/dom/Touch.h"
+#include "mozilla/MouseEvents.h"
+#include "nsAutoPtr.h"
+#include "nsIDOMSimpleGestureEvent.h"
+#include "nsTArray.h"
+
+namespace mozilla {
+
+/******************************************************************************
+ * mozilla::WidgetGestureNotifyEvent
+ *
+ * This event is the first event generated when the user touches
+ * the screen with a finger, and it's meant to decide what kind
+ * of action we'll use for that touch interaction.
+ *
+ * The event is dispatched to the layout and based on what is underneath
+ * the initial contact point it's then decided if we should pan
+ * (finger scrolling) or drag the target element.
+ ******************************************************************************/
+
+class WidgetGestureNotifyEvent : public WidgetGUIEvent
+{
+public:
+  WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage,
+                           nsIWidget *aWidget) :
+    WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_GESTURENOTIFY_EVENT),
+    panDirection(ePanNone), displayPanFeedback(false)
+  {
+  }
+
+  enum ePanDirection
+  {
+    ePanNone,
+    ePanVertical,
+    ePanHorizontal,
+    ePanBoth
+  };
+
+  ePanDirection panDirection;
+  bool displayPanFeedback;
+
+  // XXX Not tested by test_assign_event_data.html
+  void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
+                                    bool aCopyTargets)
+  {
+    AssignGUIEventData(aEvent, aCopyTargets);
+
+    panDirection = aEvent.panDirection;
+    displayPanFeedback = aEvent.displayPanFeedback;
+  }
+};
+
+/******************************************************************************
+ * mozilla::WidgetTouchEvent
+ ******************************************************************************/
+
+class WidgetSimpleGestureEvent : public WidgetMouseEventBase
+{
+public:
+  WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage,
+                           nsIWidget* aWidget, uint32_t aDirection,
+                           double aDelta) :
+    WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
+                         NS_SIMPLE_GESTURE_EVENT),
+    allowedDirections(0), direction(aDirection), delta(aDelta), clickCount(0)
+  {
+  }
+
+  WidgetSimpleGestureEvent(const nsSimpleGestureEvent& aOther) :
+    WidgetMouseEventBase(aOther.mFlags.mIsTrusted,
+                         aOther.message, aOther.widget,
+                         NS_SIMPLE_GESTURE_EVENT),
+    allowedDirections(aOther.allowedDirections), direction(aOther.direction),
+    delta(aOther.delta), clickCount(0)
+  {
+  }
+
+  // See nsIDOMSimpleGestureEvent for values
+  uint32_t allowedDirections;
+  // See nsIDOMSimpleGestureEvent for values
+  uint32_t direction;
+  // Delta for magnify and rotate events
+  double delta;
+  // The number of taps for tap events
+  uint32_t clickCount;
+
+  // XXX Not tested by test_assign_event_data.html
+  void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent,
+                                    bool aCopyTargets)
+  {
+    AssignMouseEventBaseData(aEvent, aCopyTargets);
+
+    // allowedDirections isn't copied
+    direction = aEvent.direction;
+    delta = aEvent.delta;
+    clickCount = aEvent.clickCount;
+  }
+};
+
+/******************************************************************************
+ * mozilla::WidgetTouchEvent
+ ******************************************************************************/
+
+class WidgetTouchEvent : public WidgetInputEvent
+{
+public:
+  WidgetTouchEvent()
+  {
+  }
+
+  WidgetTouchEvent(bool aIsTrusted, WidgetTouchEvent* aEvent) :
+    WidgetInputEvent(aIsTrusted, aEvent->message, aEvent->widget,
+                     NS_TOUCH_EVENT)
+  {
+    modifiers = aEvent->modifiers;
+    time = aEvent->time;
+    touches.AppendElements(aEvent->touches);
+    MOZ_COUNT_CTOR(WidgetTouchEvent);
+  }
+
+  WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
+    WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_TOUCH_EVENT)
+  {
+    MOZ_COUNT_CTOR(WidgetTouchEvent);
+  }
+
+  ~WidgetTouchEvent()
+  {
+    MOZ_COUNT_DTOR(WidgetTouchEvent);
+  }
+
+  nsTArray<nsRefPtr<mozilla::dom::Touch>> touches;
+
+  void AssignTouchEventData(const nsTouchEvent& aEvent, bool aCopyTargets)
+  {
+    AssignInputEventData(aEvent, aCopyTargets);
+
+    // Currently, we don't need to copy touches.
+  }
+};
+
+} // namespace mozilla
+
+// TODO: Remove following typedefs
+typedef mozilla::WidgetGestureNotifyEvent nsGestureNotifyEvent;
+typedef mozilla::WidgetSimpleGestureEvent nsSimpleGestureEvent;
+typedef mozilla::WidgetTouchEvent         nsTouchEvent;
+
+#endif // mozilla_TouchEvents_h__
--- a/widget/moz.build
+++ b/widget/moz.build
@@ -111,16 +111,17 @@ EXPORTS += [
 ]
 
 EXPORTS.mozilla += [
     'BasicEvents.h',
     'EventForwards.h',
     'LookAndFeel.h',
     'MouseEvents.h',
     'TextEvents.h',
+    'TouchEvents.h',
     'WidgetUtils.h',
 ]
 
 if CONFIG['MOZ_INSTRUMENT_EVENT_LOOP']:
     EXPORTS.mozilla += [
         'WidgetTraceEvent.h',
     ]
 
--- a/widget/nsGUIEvent.h
+++ b/widget/nsGUIEvent.h
@@ -4,24 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsGUIEvent_h__
 #define nsGUIEvent_h__
 
 #include "mozilla/BasicEvents.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEvents.h"
+#include "mozilla/TouchEvents.h"
 
 #include "nsPoint.h"
 #include "nsRect.h"
 #include "nsIDOMDataTransfer.h"
 #include "nsWeakPtr.h"
 #include "nsITransferable.h"
-#include "nsAutoPtr.h"
-#include "mozilla/dom/Touch.h"
 
 class nsIContent;
 
 #define NS_EVENT_TYPE_NULL                   0
 #define NS_EVENT_TYPE_ALL                  1 // Not a real event type
 
 /**
  * Script error event
@@ -95,48 +94,16 @@ public:
                                  bool aCopyTargets)
   {
     AssignGUIEventData(aEvent, aCopyTargets);
 
     mArea = aEvent.mArea;
   }
 };
 
-/*
- * Gesture Notify Event:
- *
- * This event is the first event generated when the user touches
- * the screen with a finger, and it's meant to decide what kind
- * of action we'll use for that touch interaction.
- *
- * The event is dispatched to the layout and based on what is underneath
- * the initial contact point it's then decided if we should pan
- * (finger scrolling) or drag the target element.
- */
-class nsGestureNotifyEvent : public nsGUIEvent
-{
-public:
-  enum ePanDirection {
-    ePanNone,
-    ePanVertical,
-    ePanHorizontal,
-    ePanBoth
-  };
-  
-  ePanDirection panDirection;
-  bool          displayPanFeedback;
-  
-  nsGestureNotifyEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget *aWidget):
-    nsGUIEvent(aIsTrusted, aMsg, aWidget, NS_GESTURENOTIFY_EVENT),
-    panDirection(ePanNone),
-    displayPanFeedback(false)
-  {
-  }
-};
-
 class nsContentCommandEvent : public nsGUIEvent
 {
 public:
   nsContentCommandEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget *aWidget,
                         bool aOnlyEnabledCheck = false) :
     nsGUIEvent(aIsTrusted, aMsg, aWidget, NS_CONTENT_COMMAND_EVENT),
     mOnlyEnabledCheck(bool(aOnlyEnabledCheck)),
     mSucceeded(false), mIsEnabled(false)
@@ -166,53 +133,16 @@ public:
   } mScroll;
 
   bool mOnlyEnabledCheck;                          // [in]
 
   bool mSucceeded;                                 // [out]
   bool mIsEnabled;                                 // [out]
 };
 
-class nsTouchEvent : public nsInputEvent
-{
-public:
-  nsTouchEvent()
-  {
-  }
-  nsTouchEvent(bool isTrusted, nsTouchEvent *aEvent)
-    : nsInputEvent(isTrusted,
-                   aEvent->message,
-                   aEvent->widget,
-                   NS_TOUCH_EVENT)
-  {
-    modifiers = aEvent->modifiers;
-    time = aEvent->time;
-    touches.AppendElements(aEvent->touches);
-    MOZ_COUNT_CTOR(nsTouchEvent);
-  }
-  nsTouchEvent(bool isTrusted, uint32_t msg, nsIWidget* w)
-    : nsInputEvent(isTrusted, msg, w, NS_TOUCH_EVENT)
-  {
-    MOZ_COUNT_CTOR(nsTouchEvent);
-  }
-  ~nsTouchEvent()
-  {
-    MOZ_COUNT_DTOR(nsTouchEvent);
-  }
-
-  nsTArray< nsRefPtr<mozilla::dom::Touch> > touches;
-
-  void AssignTouchEventData(const nsTouchEvent& aEvent, bool aCopyTargets)
-  {
-    AssignInputEventData(aEvent, aCopyTargets);
-
-    // Currently, we don't need to copy touches.
-  }
-};
-
 /**
  * Form event
  * 
  * We hold the originating form control for form submit and reset events.
  * originator is a weak pointer (does not hold a strong reference).
  */
 
 class nsFormEvent : public nsEvent
@@ -306,55 +236,16 @@ public:
     AssignUIEventData(aEvent, aCopyTargets);
 
     relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
     fromRaise = aEvent.fromRaise;
     isRefocus = aEvent.isRefocus;
   }
 };
 
-/**
- * Simple gesture event
- */
-class nsSimpleGestureEvent : public nsMouseEvent_base
-{
-public:
-  nsSimpleGestureEvent(bool isTrusted, uint32_t msg, nsIWidget* w,
-                         uint32_t directionArg, double deltaArg)
-    : nsMouseEvent_base(isTrusted, msg, w, NS_SIMPLE_GESTURE_EVENT),
-      allowedDirections(0), direction(directionArg), delta(deltaArg),
-      clickCount(0)
-  {
-  }
-
-  nsSimpleGestureEvent(const nsSimpleGestureEvent& other)
-    : nsMouseEvent_base(other.mFlags.mIsTrusted,
-                        other.message, other.widget, NS_SIMPLE_GESTURE_EVENT),
-      allowedDirections(other.allowedDirections), direction(other.direction),
-      delta(other.delta), clickCount(0)
-  {
-  }
-  uint32_t allowedDirections; // See nsIDOMSimpleGestureEvent for values
-  uint32_t direction;         // See nsIDOMSimpleGestureEvent for values
-  double delta;               // Delta for magnify and rotate events
-  uint32_t clickCount;        // The number of taps for tap events
-
-  // XXX Not tested by test_assign_event_data.html
-  void AssignSimpleGestureEventData(const nsSimpleGestureEvent& aEvent,
-                                    bool aCopyTargets)
-  {
-    AssignMouseEventBaseData(aEvent, aCopyTargets);
-
-    // allowedDirections isn't copied
-    direction = aEvent.direction;
-    delta = aEvent.delta;
-    clickCount = aEvent.clickCount;
-  }
-};
-
 class nsTransitionEvent : public nsEvent
 {
 public:
   nsTransitionEvent(bool isTrusted, uint32_t msg,
                     const nsAString& propertyNameArg, float elapsedTimeArg,
                     const nsAString& pseudoElementArg)
     : nsEvent(isTrusted, msg, NS_TRANSITION_EVENT),
       propertyName(propertyNameArg), elapsedTime(elapsedTimeArg),