tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SimpleGestureEvent.cpp (3201B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "SimpleGestureEvent.h"
      8 
      9 #include "mozilla/TouchEvents.h"
     10 #include "mozilla/dom/MouseEventBinding.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner,
     15                                       nsPresContext* aPresContext,
     16                                       WidgetSimpleGestureEvent* aEvent)
     17    : MouseEvent(
     18          aOwner, aPresContext,
     19          aEvent ? aEvent
     20                 : new WidgetSimpleGestureEvent(false, eVoidEvent, nullptr)) {
     21  NS_ASSERTION(mEvent->mClass == eSimpleGestureEventClass,
     22               "event type mismatch");
     23 
     24  if (aEvent) {
     25    mEventIsInternal = false;
     26  } else {
     27    mEventIsInternal = true;
     28    mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
     29    static_cast<WidgetMouseEventBase*>(mEvent)->mInputSource =
     30        MouseEvent_Binding::MOZ_SOURCE_UNKNOWN;
     31  }
     32 }
     33 
     34 uint32_t SimpleGestureEvent::AllowedDirections() const {
     35  return mEvent->AsSimpleGestureEvent()->mAllowedDirections;
     36 }
     37 
     38 void SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections) {
     39  mEvent->AsSimpleGestureEvent()->mAllowedDirections = aAllowedDirections;
     40 }
     41 
     42 uint32_t SimpleGestureEvent::Direction() const {
     43  return mEvent->AsSimpleGestureEvent()->mDirection;
     44 }
     45 
     46 double SimpleGestureEvent::Delta() const {
     47  return mEvent->AsSimpleGestureEvent()->mDelta;
     48 }
     49 
     50 uint32_t SimpleGestureEvent::ClickCount() const {
     51  return mEvent->AsSimpleGestureEvent()->mClickCount;
     52 }
     53 
     54 void SimpleGestureEvent::InitSimpleGestureEventInternal(
     55    const nsAString& aTypeArg, bool aCanBubbleArg, bool aCancelableArg,
     56    nsGlobalWindowInner* aViewArg, int32_t aDetailArg, double aScreenX,
     57    double aScreenY, double aClientX, double aClientY, bool aCtrlKeyArg,
     58    bool aAltKeyArg, bool aShiftKeyArg, bool aMetaKeyArg, uint16_t aButton,
     59    EventTarget* aRelatedTarget, uint32_t aAllowedDirectionsArg,
     60    uint32_t aDirectionArg, double aDeltaArg, uint32_t aClickCountArg) {
     61  NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
     62 
     63  MouseEvent::InitMouseEventInternal(
     64      aTypeArg, aCanBubbleArg, aCancelableArg, aViewArg, aDetailArg, aScreenX,
     65      aScreenY, aClientX, aClientY, aCtrlKeyArg, aAltKeyArg, aShiftKeyArg,
     66      aMetaKeyArg, aButton, aRelatedTarget);
     67 
     68  WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent();
     69  simpleGestureEvent->mAllowedDirections = aAllowedDirectionsArg;
     70  simpleGestureEvent->mDirection = aDirectionArg;
     71  simpleGestureEvent->mDelta = aDeltaArg;
     72  simpleGestureEvent->mClickCount = aClickCountArg;
     73 }
     74 
     75 }  // namespace mozilla::dom
     76 
     77 using namespace mozilla;
     78 using namespace mozilla::dom;
     79 
     80 already_AddRefed<SimpleGestureEvent> NS_NewDOMSimpleGestureEvent(
     81    EventTarget* aOwner, nsPresContext* aPresContext,
     82    WidgetSimpleGestureEvent* aEvent) {
     83  RefPtr<SimpleGestureEvent> it =
     84      new SimpleGestureEvent(aOwner, aPresContext, aEvent);
     85  return it.forget();
     86 }