1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/SimpleGestureEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,161 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/SimpleGestureEvent.h" 1.10 +#include "mozilla/TouchEvents.h" 1.11 +#include "prtime.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +SimpleGestureEvent::SimpleGestureEvent(EventTarget* aOwner, 1.17 + nsPresContext* aPresContext, 1.18 + WidgetSimpleGestureEvent* aEvent) 1.19 + : MouseEvent(aOwner, aPresContext, 1.20 + aEvent ? aEvent : 1.21 + new WidgetSimpleGestureEvent(false, 0, nullptr)) 1.22 +{ 1.23 + NS_ASSERTION(mEvent->eventStructType == NS_SIMPLE_GESTURE_EVENT, "event type mismatch"); 1.24 + 1.25 + if (aEvent) { 1.26 + mEventIsInternal = false; 1.27 + } else { 1.28 + mEventIsInternal = true; 1.29 + mEvent->time = PR_Now(); 1.30 + mEvent->refPoint.x = mEvent->refPoint.y = 0; 1.31 + static_cast<WidgetMouseEventBase*>(mEvent)->inputSource = 1.32 + nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; 1.33 + } 1.34 +} 1.35 + 1.36 +NS_IMPL_ADDREF_INHERITED(SimpleGestureEvent, MouseEvent) 1.37 +NS_IMPL_RELEASE_INHERITED(SimpleGestureEvent, MouseEvent) 1.38 + 1.39 +NS_INTERFACE_MAP_BEGIN(SimpleGestureEvent) 1.40 + NS_INTERFACE_MAP_ENTRY(nsIDOMSimpleGestureEvent) 1.41 +NS_INTERFACE_MAP_END_INHERITING(MouseEvent) 1.42 + 1.43 +/* attribute unsigned long allowedDirections; */ 1.44 +uint32_t 1.45 +SimpleGestureEvent::AllowedDirections() 1.46 +{ 1.47 + return mEvent->AsSimpleGestureEvent()->allowedDirections; 1.48 +} 1.49 + 1.50 +NS_IMETHODIMP 1.51 +SimpleGestureEvent::GetAllowedDirections(uint32_t* aAllowedDirections) 1.52 +{ 1.53 + NS_ENSURE_ARG_POINTER(aAllowedDirections); 1.54 + *aAllowedDirections = AllowedDirections(); 1.55 + return NS_OK; 1.56 +} 1.57 + 1.58 +NS_IMETHODIMP 1.59 +SimpleGestureEvent::SetAllowedDirections(uint32_t aAllowedDirections) 1.60 +{ 1.61 + mEvent->AsSimpleGestureEvent()->allowedDirections = aAllowedDirections; 1.62 + return NS_OK; 1.63 +} 1.64 + 1.65 +/* readonly attribute unsigned long direction; */ 1.66 +uint32_t 1.67 +SimpleGestureEvent::Direction() 1.68 +{ 1.69 + return mEvent->AsSimpleGestureEvent()->direction; 1.70 +} 1.71 + 1.72 +NS_IMETHODIMP 1.73 +SimpleGestureEvent::GetDirection(uint32_t* aDirection) 1.74 +{ 1.75 + NS_ENSURE_ARG_POINTER(aDirection); 1.76 + *aDirection = Direction(); 1.77 + return NS_OK; 1.78 +} 1.79 + 1.80 +/* readonly attribute float delta; */ 1.81 +double 1.82 +SimpleGestureEvent::Delta() 1.83 +{ 1.84 + return mEvent->AsSimpleGestureEvent()->delta; 1.85 +} 1.86 + 1.87 +NS_IMETHODIMP 1.88 +SimpleGestureEvent::GetDelta(double* aDelta) 1.89 +{ 1.90 + NS_ENSURE_ARG_POINTER(aDelta); 1.91 + *aDelta = Delta(); 1.92 + return NS_OK; 1.93 +} 1.94 + 1.95 +/* readonly attribute unsigned long clickCount; */ 1.96 +uint32_t 1.97 +SimpleGestureEvent::ClickCount() 1.98 +{ 1.99 + return mEvent->AsSimpleGestureEvent()->clickCount; 1.100 +} 1.101 + 1.102 +NS_IMETHODIMP 1.103 +SimpleGestureEvent::GetClickCount(uint32_t* aClickCount) 1.104 +{ 1.105 + NS_ENSURE_ARG_POINTER(aClickCount); 1.106 + *aClickCount = ClickCount(); 1.107 + return NS_OK; 1.108 +} 1.109 + 1.110 +NS_IMETHODIMP 1.111 +SimpleGestureEvent::InitSimpleGestureEvent(const nsAString& aTypeArg, 1.112 + bool aCanBubbleArg, 1.113 + bool aCancelableArg, 1.114 + nsIDOMWindow* aViewArg, 1.115 + int32_t aDetailArg, 1.116 + int32_t aScreenX, 1.117 + int32_t aScreenY, 1.118 + int32_t aClientX, 1.119 + int32_t aClientY, 1.120 + bool aCtrlKeyArg, 1.121 + bool aAltKeyArg, 1.122 + bool aShiftKeyArg, 1.123 + bool aMetaKeyArg, 1.124 + uint16_t aButton, 1.125 + nsIDOMEventTarget* aRelatedTarget, 1.126 + uint32_t aAllowedDirectionsArg, 1.127 + uint32_t aDirectionArg, 1.128 + double aDeltaArg, 1.129 + uint32_t aClickCountArg) 1.130 +{ 1.131 + nsresult rv = 1.132 + MouseEvent::InitMouseEvent(aTypeArg, aCanBubbleArg, aCancelableArg, 1.133 + aViewArg, aDetailArg, 1.134 + aScreenX, aScreenY, aClientX, aClientY, 1.135 + aCtrlKeyArg, aAltKeyArg, aShiftKeyArg, 1.136 + aMetaKeyArg, aButton, aRelatedTarget); 1.137 + NS_ENSURE_SUCCESS(rv, rv); 1.138 + 1.139 + WidgetSimpleGestureEvent* simpleGestureEvent = mEvent->AsSimpleGestureEvent(); 1.140 + simpleGestureEvent->allowedDirections = aAllowedDirectionsArg; 1.141 + simpleGestureEvent->direction = aDirectionArg; 1.142 + simpleGestureEvent->delta = aDeltaArg; 1.143 + simpleGestureEvent->clickCount = aClickCountArg; 1.144 + 1.145 + return NS_OK; 1.146 +} 1.147 + 1.148 +} // namespace dom 1.149 +} // namespace mozilla 1.150 + 1.151 +using namespace mozilla; 1.152 +using namespace mozilla::dom; 1.153 + 1.154 +nsresult 1.155 +NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult, 1.156 + EventTarget* aOwner, 1.157 + nsPresContext* aPresContext, 1.158 + WidgetSimpleGestureEvent* aEvent) 1.159 +{ 1.160 + SimpleGestureEvent* it = new SimpleGestureEvent(aOwner, aPresContext, aEvent); 1.161 + NS_ADDREF(it); 1.162 + *aInstancePtrResult = static_cast<Event*>(it); 1.163 + return NS_OK; 1.164 +}