widget/TouchEvents.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_TouchEvents_h__
     7 #define mozilla_TouchEvents_h__
     9 #include <stdint.h>
    11 #include "mozilla/dom/Touch.h"
    12 #include "mozilla/MouseEvents.h"
    13 #include "nsAutoPtr.h"
    14 #include "nsIDOMSimpleGestureEvent.h"
    15 #include "nsTArray.h"
    17 namespace mozilla {
    19 /******************************************************************************
    20  * mozilla::WidgetGestureNotifyEvent
    21  *
    22  * This event is the first event generated when the user touches
    23  * the screen with a finger, and it's meant to decide what kind
    24  * of action we'll use for that touch interaction.
    25  *
    26  * The event is dispatched to the layout and based on what is underneath
    27  * the initial contact point it's then decided if we should pan
    28  * (finger scrolling) or drag the target element.
    29  ******************************************************************************/
    31 class WidgetGestureNotifyEvent : public WidgetGUIEvent
    32 {
    33 public:
    34   virtual WidgetGestureNotifyEvent* AsGestureNotifyEvent() MOZ_OVERRIDE
    35   {
    36     return this;
    37   }
    39   WidgetGestureNotifyEvent(bool aIsTrusted, uint32_t aMessage,
    40                            nsIWidget *aWidget) :
    41     WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_GESTURENOTIFY_EVENT),
    42     panDirection(ePanNone), displayPanFeedback(false)
    43   {
    44   }
    46   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
    47   {
    48     // XXX Looks like this event is handled only in PostHandleEvent() of
    49     //     EventStateManager.  Therefore, it might be possible to handle this
    50     //     in PreHandleEvent() and not to dispatch as a DOM event into the DOM
    51     //     tree like ContentQueryEvent.  Then, this event doesn't need to
    52     //     support Duplicate().
    53     MOZ_ASSERT(eventStructType == NS_GESTURENOTIFY_EVENT,
    54                "Duplicate() must be overridden by sub class");
    55     // Not copying widget, it is a weak reference.
    56     WidgetGestureNotifyEvent* result =
    57       new WidgetGestureNotifyEvent(false, message, nullptr);
    58     result->AssignGestureNotifyEventData(*this, true);
    59     result->mFlags = mFlags;
    60     return result;
    61   }
    63   enum ePanDirection
    64   {
    65     ePanNone,
    66     ePanVertical,
    67     ePanHorizontal,
    68     ePanBoth
    69   };
    71   ePanDirection panDirection;
    72   bool displayPanFeedback;
    74   void AssignGestureNotifyEventData(const WidgetGestureNotifyEvent& aEvent,
    75                                     bool aCopyTargets)
    76   {
    77     AssignGUIEventData(aEvent, aCopyTargets);
    79     panDirection = aEvent.panDirection;
    80     displayPanFeedback = aEvent.displayPanFeedback;
    81   }
    82 };
    84 /******************************************************************************
    85  * mozilla::WidgetTouchEvent
    86  ******************************************************************************/
    88 class WidgetSimpleGestureEvent : public WidgetMouseEventBase
    89 {
    90 public:
    91   virtual WidgetSimpleGestureEvent* AsSimpleGestureEvent() MOZ_OVERRIDE
    92   {
    93     return this;
    94   }
    96   WidgetSimpleGestureEvent(bool aIsTrusted, uint32_t aMessage,
    97                            nsIWidget* aWidget)
    98     : WidgetMouseEventBase(aIsTrusted, aMessage, aWidget,
    99                            NS_SIMPLE_GESTURE_EVENT)
   100     , allowedDirections(0)
   101     , direction(0)
   102     , delta(0.0)
   103     , clickCount(0)
   104   {
   105   }
   107   WidgetSimpleGestureEvent(const WidgetSimpleGestureEvent& aOther)
   108     : WidgetMouseEventBase(aOther.mFlags.mIsTrusted, aOther.message,
   109                            aOther.widget, NS_SIMPLE_GESTURE_EVENT)
   110     , allowedDirections(aOther.allowedDirections)
   111     , direction(aOther.direction)
   112     , delta(aOther.delta)
   113     , clickCount(0)
   114   {
   115   }
   117   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   118   {
   119     MOZ_ASSERT(eventStructType == NS_SIMPLE_GESTURE_EVENT,
   120                "Duplicate() must be overridden by sub class");
   121     // Not copying widget, it is a weak reference.
   122     WidgetSimpleGestureEvent* result =
   123       new WidgetSimpleGestureEvent(false, message, nullptr);
   124     result->AssignSimpleGestureEventData(*this, true);
   125     result->mFlags = mFlags;
   126     return result;
   127   }
   129   // See nsIDOMSimpleGestureEvent for values
   130   uint32_t allowedDirections;
   131   // See nsIDOMSimpleGestureEvent for values
   132   uint32_t direction;
   133   // Delta for magnify and rotate events
   134   double delta;
   135   // The number of taps for tap events
   136   uint32_t clickCount;
   138   // XXX Not tested by test_assign_event_data.html
   139   void AssignSimpleGestureEventData(const WidgetSimpleGestureEvent& aEvent,
   140                                     bool aCopyTargets)
   141   {
   142     AssignMouseEventBaseData(aEvent, aCopyTargets);
   144     // allowedDirections isn't copied
   145     direction = aEvent.direction;
   146     delta = aEvent.delta;
   147     clickCount = aEvent.clickCount;
   148   }
   149 };
   151 /******************************************************************************
   152  * mozilla::WidgetTouchEvent
   153  ******************************************************************************/
   155 class WidgetTouchEvent : public WidgetInputEvent
   156 {
   157 public:
   158   virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; }
   160   WidgetTouchEvent()
   161   {
   162   }
   164   WidgetTouchEvent(const WidgetTouchEvent& aOther) :
   165     WidgetInputEvent(aOther.mFlags.mIsTrusted, aOther.message, aOther.widget,
   166                      NS_TOUCH_EVENT)
   167   {
   168     modifiers = aOther.modifiers;
   169     time = aOther.time;
   170     touches.AppendElements(aOther.touches);
   171     mFlags.mCancelable = message != NS_TOUCH_CANCEL;
   172     MOZ_COUNT_CTOR(WidgetTouchEvent);
   173   }
   175   WidgetTouchEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
   176     WidgetInputEvent(aIsTrusted, aMessage, aWidget, NS_TOUCH_EVENT)
   177   {
   178     MOZ_COUNT_CTOR(WidgetTouchEvent);
   179     mFlags.mCancelable = message != NS_TOUCH_CANCEL;
   180   }
   182   virtual ~WidgetTouchEvent()
   183   {
   184     MOZ_COUNT_DTOR(WidgetTouchEvent);
   185   }
   187   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   188   {
   189     MOZ_ASSERT(eventStructType == NS_TOUCH_EVENT,
   190                "Duplicate() must be overridden by sub class");
   191     // Not copying widget, it is a weak reference.
   192     WidgetTouchEvent* result = new WidgetTouchEvent(false, message, nullptr);
   193     result->AssignTouchEventData(*this, true);
   194     result->mFlags = mFlags;
   195     return result;
   196   }
   198   nsTArray<nsRefPtr<mozilla::dom::Touch>> touches;
   200   void AssignTouchEventData(const WidgetTouchEvent& aEvent, bool aCopyTargets)
   201   {
   202     AssignInputEventData(aEvent, aCopyTargets);
   204     // Assign*EventData() assume that they're called only new instance.
   205     MOZ_ASSERT(touches.IsEmpty());
   206     touches.AppendElements(aEvent.touches);
   207   }
   208 };
   210 } // namespace mozilla
   212 #endif // mozilla_TouchEvents_h__

mercurial