dom/events/SimpleGestureEvent.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 #include "mozilla/dom/SimpleGestureEvent.h"
     7 #include "mozilla/TouchEvents.h"
     8 #include "prtime.h"
    10 namespace mozilla {
    11 namespace dom {
    13 SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner,
    14                                        nsPresContext* aPresContext,
    15                                        WidgetSimpleGestureEvent* aEvent)
    16   : MouseEvent(aOwner, aPresContext,
    17                aEvent ? aEvent :
    18                         new WidgetSimpleGestureEvent(false, 0, nullptr))
    19 {
    20   NS_ASSERTION(mEvent->eventStructType == NS_SIMPLE_GESTURE_EVENT, "event type mismatch");
    22   if (aEvent) {
    23     mEventIsInternal = false;
    24   } else {
    25     mEventIsInternal = true;
    26     mEvent->time = PR_Now();
    27     mEvent->refPoint.x = mEvent->refPoint.y = 0;
    28     static_cast<WidgetMouseEventBase*>(mEvent)->inputSource =
    29       nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
    30   }
    31 }
    33 NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent, MouseEvent)
    34 NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent, MouseEvent)
    36 NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent)
    37   NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent)
    38 NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
    40 /* attribute unsigned long allowedDirections; */
    41 uint32_t
    42 SimpleGestureEvent::AllowedDirections()
    43 {
    44   return mEvent->AsSimpleGestureEvent()->allowedDirections;
    45 }
    47 NS_IMETHODIMP
    48 SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections)
    49 {
    50   NS_ENSURE_ARG_POINTER(aAllowedDirections);
    51   *aAllowedDirections = AllowedDirections();
    52   return NS_OK;
    53 }
    55 NS_IMETHODIMP
    56 SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections)
    57 {
    58   mEvent->AsSimpleGestureEvent()->allowedDirections = aAllowedDirections;
    59   return NS_OK;
    60 }
    62 /* readonly attribute unsigned long direction; */
    63 uint32_t
    64 SimpleGestureEvent::Direction()
    65 {
    66   return mEvent->AsSimpleGestureEvent()->direction;
    67 }
    69 NS_IMETHODIMP
    70 SimpleGestureEvent::GetDirection(uint32_t* aDirection)
    71 {
    72   NS_ENSURE_ARG_POINTER(aDirection);
    73   *aDirection = Direction();
    74   return NS_OK;
    75 }
    77 /* readonly attribute float delta; */
    78 double
    79 SimpleGestureEvent::Delta()
    80 {
    81   return mEvent->AsSimpleGestureEvent()->delta;
    82 }
    84 NS_IMETHODIMP
    85 SimpleGestureEvent::GetDelta(double* aDelta)
    86 {
    87   NS_ENSURE_ARG_POINTER(aDelta);
    88   *aDelta = Delta();
    89   return NS_OK;
    90 }
    92 /* readonly attribute unsigned long clickCount; */
    93 uint32_t
    94 SimpleGestureEvent::ClickCount()
    95 {
    96   return mEvent->AsSimpleGestureEvent()->clickCount;
    97 }
    99 NS_IMETHODIMP
   100 SimpleGestureEvent::GetClickCount(uint32_t* aClickCount)
   101 {
   102   NS_ENSURE_ARG_POINTER(aClickCount);
   103   *aClickCount = ClickCount();
   104   return NS_OK;
   105 }
   107 NS_IMETHODIMP
   108 SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg,
   109                                            bool aCanBubbleArg,
   110                                            bool aCancelableArg,
   111                                            nsIDOMWindow* aViewArg,
   112                                            int32_t aDetailArg,
   113                                            int32_t aScreenX, 
   114                                            int32_t aScreenY,
   115                                            int32_t aClientX,
   116                                            int32_t aClientY,
   117                                            bool aCtrlKeyArg,
   118                                            bool aAltKeyArg,
   119                                            bool aShiftKeyArg,
   120                                            bool aMetaKeyArg,
   121                                            uint16_t aButton,
   122                                            nsIDOMEventTarget* aRelatedTarget,
   123                                            uint32_t aAllowedDirectionsArg,
   124                                            uint32_t aDirectionArg,
   125                                            double aDeltaArg,
   126                                            uint32_t aClickCountArg)
   127 {
   128   nsresult rv =
   129     MouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg,
   130                                aViewArg, aDetailArg,
   131                                aScreenX, aScreenY, aClientX, aClientY,
   132                                aCtrlKeyArg, aAltKeyArg, aShiftKeyArg,
   133                                aMetaKeyArg, aButton, aRelatedTarget);
   134   NS_ENSURE_SUCCESS(rv, rv);
   136   WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent();
   137   simpleGestureEvent->allowedDirections = aAllowedDirectionsArg;
   138   simpleGestureEvent->direction = aDirectionArg;
   139   simpleGestureEvent->delta = aDeltaArg;
   140   simpleGestureEvent->clickCount = aClickCountArg;
   142   return NS_OK;
   143 }
   145 } // namespace dom
   146 } // namespace mozilla
   148 using namespace mozilla;
   149 using namespace mozilla::dom;
   151 nsresult
   152 NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult,
   153                             EventTarget* aOwner,
   154                             nsPresContext* aPresContext,
   155                             WidgetSimpleGestureEvent* aEvent)
   156 {
   157   SimpleGestureEvent* it = new SimpleGestureEvent(aOwner, aPresContext, aEvent);
   158   NS_ADDREF(it);
   159   *aInstancePtrResult = static_cast<Event*>(it);
   160   return NS_OK;
   161 }

mercurial