michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/SimpleGestureEvent.h" michael@0: #include "mozilla/TouchEvents.h" michael@0: #include "prtime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetSimpleGestureEvent* aEvent) michael@0: : MouseEvent(aOwner, aPresContext, michael@0: aEvent ? aEvent : michael@0: new WidgetSimpleGestureEvent(false, 0, nullptr)) michael@0: { michael@0: NS_ASSERTION(mEvent->eventStructType == NS_SIMPLE_GESTURE_EVENT, "event type mismatch"); michael@0: michael@0: if (aEvent) { michael@0: mEventIsInternal = false; michael@0: } else { michael@0: mEventIsInternal = true; michael@0: mEvent->time = PR_Now(); michael@0: mEvent->refPoint.x = mEvent->refPoint.y = 0; michael@0: static_cast(mEvent)->inputSource = michael@0: nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; michael@0: } michael@0: } michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent, MouseEvent) michael@0: NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent, MouseEvent) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(MouseEvent) michael@0: michael@0: /* attribute unsigned long allowedDirections; */ michael@0: uint32_t michael@0: SimpleGestureEvent::AllowedDirections() michael@0: { michael@0: return mEvent->AsSimpleGestureEvent()->allowedDirections; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aAllowedDirections); michael@0: *aAllowedDirections = AllowedDirections(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections) michael@0: { michael@0: mEvent->AsSimpleGestureEvent()->allowedDirections = aAllowedDirections; michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* readonly attribute unsigned long direction; */ michael@0: uint32_t michael@0: SimpleGestureEvent::Direction() michael@0: { michael@0: return mEvent->AsSimpleGestureEvent()->direction; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::GetDirection(uint32_t* aDirection) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aDirection); michael@0: *aDirection = Direction(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* readonly attribute float delta; */ michael@0: double michael@0: SimpleGestureEvent::Delta() michael@0: { michael@0: return mEvent->AsSimpleGestureEvent()->delta; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::GetDelta(double* aDelta) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aDelta); michael@0: *aDelta = Delta(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: /* readonly attribute unsigned long clickCount; */ michael@0: uint32_t michael@0: SimpleGestureEvent::ClickCount() michael@0: { michael@0: return mEvent->AsSimpleGestureEvent()->clickCount; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::GetClickCount(uint32_t* aClickCount) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aClickCount); michael@0: *aClickCount = ClickCount(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, michael@0: bool aCanBubbleArg, michael@0: bool aCancelableArg, michael@0: nsIDOMWindow* aViewArg, michael@0: int32_t aDetailArg, michael@0: int32_t aScreenX, michael@0: int32_t aScreenY, michael@0: int32_t aClientX, michael@0: int32_t aClientY, michael@0: bool aCtrlKeyArg, michael@0: bool aAltKeyArg, michael@0: bool aShiftKeyArg, michael@0: bool aMetaKeyArg, michael@0: uint16_t aButton, michael@0: nsIDOMEventTarget* aRelatedTarget, michael@0: uint32_t aAllowedDirectionsArg, michael@0: uint32_t aDirectionArg, michael@0: double aDeltaArg, michael@0: uint32_t aClickCountArg) michael@0: { michael@0: nsresult rv = michael@0: MouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg, michael@0: aViewArg, aDetailArg, michael@0: aScreenX, aScreenY, aClientX, aClientY, michael@0: aCtrlKeyArg, aAltKeyArg, aShiftKeyArg, michael@0: aMetaKeyArg, aButton, aRelatedTarget); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent(); michael@0: simpleGestureEvent->allowedDirections = aAllowedDirectionsArg; michael@0: simpleGestureEvent->direction = aDirectionArg; michael@0: simpleGestureEvent->delta = aDeltaArg; michael@0: simpleGestureEvent->clickCount = aClickCountArg; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetSimpleGestureEvent* aEvent) michael@0: { michael@0: SimpleGestureEvent* it = new SimpleGestureEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }