2011-04-24 06:54:25 +00:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2011-04-26 12:30:17 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsDOMTouchEvent.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Olli Pettay <Olli.Pettay@helsinki.fi> (Original Author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsDOMTouchEvent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsDOMClassInfoID.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIXPCScriptable.h"
|
|
|
|
#include "nsContentUtils.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-12-17 00:24:11 +00:00
|
|
|
#include "nsPresContext.h"
|
2011-05-25 06:31:59 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2011-04-27 11:58:25 +00:00
|
|
|
DOMCI_DATA(Touch, nsDOMTouch)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2011-04-27 11:58:25 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_1(nsDOMTouch, mTarget)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
2011-04-27 11:58:25 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouch)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMTouch)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMTouch)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Touch)
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-04-27 11:58:25 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouch)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouch)
|
2011-04-26 12:30:17 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetIdentifier(PRInt32* aIdentifier)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
*aIdentifier = mIdentifier;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetTarget(nsIDOMEventTarget** aTarget)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aTarget = mTarget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetScreenX(PRInt32* aScreenX)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aScreenX = mScreenPoint.x;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetScreenY(PRInt32* aScreenY)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aScreenY = mScreenPoint.y;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetClientX(PRInt32* aClientX)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aClientX = mClientPoint.x;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetClientY(PRInt32* aClientY)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aClientY = mClientPoint.y;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetPageX(PRInt32* aPageX)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aPageX = mPagePoint.x;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetPageY(PRInt32* aPageY)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aPageY = mPagePoint.y;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetRadiusX(PRInt32* aRadiusX)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aRadiusX = mRadius.x;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetRadiusY(PRInt32* aRadiusY)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aRadiusY = mRadius.y;
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetRotationAngle(float* aRotationAngle)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
*aRotationAngle = mRotationAngle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouch::GetForce(float* aForce)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
*aForce = mForce;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-17 00:24:11 +00:00
|
|
|
bool
|
|
|
|
nsDOMTouch::Equals(nsIDOMTouch* aTouch)
|
|
|
|
{
|
|
|
|
float force;
|
|
|
|
float orientation;
|
|
|
|
PRInt32 radiusX, radiusY;
|
|
|
|
aTouch->GetForce(&force);
|
|
|
|
aTouch->GetRotationAngle(&orientation);
|
|
|
|
aTouch->GetRadiusX(&radiusX);
|
|
|
|
aTouch->GetRadiusY(&radiusY);
|
|
|
|
return mRefPoint != aTouch->mRefPoint ||
|
|
|
|
(mForce != force) ||
|
|
|
|
(mRotationAngle != orientation) ||
|
|
|
|
(mRadius.x != radiusX) || (mRadius.y != radiusY);
|
|
|
|
}
|
|
|
|
|
2011-04-26 12:30:17 +00:00
|
|
|
// TouchList
|
2012-04-24 14:51:56 +00:00
|
|
|
nsDOMTouchList::nsDOMTouchList(nsTArray<nsCOMPtr<nsIDOMTouch> > &aTouches)
|
|
|
|
{
|
|
|
|
mPoints.AppendElements(aTouches);
|
|
|
|
}
|
2011-04-26 12:30:17 +00:00
|
|
|
|
|
|
|
DOMCI_DATA(TouchList, nsDOMTouchList)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMTouchList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMTouchList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMTouchList)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TouchList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMTouchList)
|
2011-12-17 00:24:11 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSTARRAY_OF_NSCOMPTR(mPoints)
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-04-24 14:51:56 +00:00
|
|
|
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMTouchList)
|
2011-12-17 00:24:11 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSTARRAY(mPoints)
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMTouchList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMTouchList)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMTouchList::GetLength(PRUint32* aLength)
|
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
*aLength = mPoints.Length();
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouchList::Item(PRUint32 aIndex, nsIDOMTouch** aRetVal)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2012-04-24 14:51:56 +00:00
|
|
|
NS_IF_ADDREF(*aRetVal = mPoints.SafeElementAt(aIndex, nsnull));
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-27 11:58:25 +00:00
|
|
|
nsDOMTouchList::IdentifiedTouch(PRInt32 aIdentifier, nsIDOMTouch** aRetVal)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2011-04-27 11:58:25 +00:00
|
|
|
*aRetVal = nsnull;
|
2011-12-17 00:24:11 +00:00
|
|
|
for (PRUint32 i = 0; i < mPoints.Length(); ++i) {
|
2011-04-27 11:58:25 +00:00
|
|
|
nsCOMPtr<nsIDOMTouch> point = mPoints[i];
|
2011-04-26 12:30:17 +00:00
|
|
|
PRInt32 identifier;
|
|
|
|
if (point && NS_SUCCEEDED(point->GetIdentifier(&identifier)) &&
|
|
|
|
aIdentifier == identifier) {
|
|
|
|
point.swap(*aRetVal);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TouchEvent
|
|
|
|
|
|
|
|
nsDOMTouchEvent::nsDOMTouchEvent(nsPresContext* aPresContext,
|
2011-12-17 00:24:11 +00:00
|
|
|
nsTouchEvent* aEvent)
|
2011-04-26 12:30:17 +00:00
|
|
|
: nsDOMUIEvent(aPresContext, aEvent ? aEvent :
|
2011-12-17 00:24:11 +00:00
|
|
|
new nsTouchEvent(false, 0, nsnull))
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = false;
|
2011-12-17 00:24:11 +00:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aEvent->touches.Length(); ++i) {
|
|
|
|
nsIDOMTouch *touch = aEvent->touches[i];
|
|
|
|
nsDOMTouch *domtouch = static_cast<nsDOMTouch*>(touch);
|
|
|
|
domtouch->InitializePoints(mPresContext, aEvent);
|
|
|
|
}
|
2011-04-26 12:30:17 +00:00
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
mEventIsInternal = true;
|
2011-04-26 12:30:17 +00:00
|
|
|
mEvent->time = PR_Now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMTouchEvent::~nsDOMTouchEvent()
|
|
|
|
{
|
|
|
|
if (mEventIsInternal && mEvent) {
|
2011-12-17 00:24:11 +00:00
|
|
|
delete static_cast<nsTouchEvent*>(mEvent);
|
2011-04-26 12:30:17 +00:00
|
|
|
mEvent = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMTouchEvent)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTargetTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChangedTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTargetTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChangedTouches)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
DOMCI_DATA(TouchEvent, nsDOMTouchEvent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMTouchEvent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMTouchEvent)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TouchEvent)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMTouchEvent, nsDOMUIEvent)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMTouchEvent::InitTouchEvent(const nsAString& aType,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2011-04-24 06:54:25 +00:00
|
|
|
nsIDOMWindow* aView,
|
2011-04-26 12:30:17 +00:00
|
|
|
PRInt32 aDetail,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
2011-04-26 12:30:17 +00:00
|
|
|
nsIDOMTouchList* aTouches,
|
|
|
|
nsIDOMTouchList* aTargetTouches,
|
|
|
|
nsIDOMTouchList* aChangedTouches)
|
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
nsresult rv = nsDOMUIEvent::InitUIEvent(aType,
|
|
|
|
aCanBubble,
|
|
|
|
aCancelable,
|
|
|
|
aView,
|
|
|
|
aDetail);
|
2011-04-26 12:30:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-04-25 03:00:02 +00:00
|
|
|
static_cast<nsInputEvent*>(mEvent)->InitBasicModifiers(aCtrlKey, aAltKey,
|
|
|
|
aShiftKey, aMetaKey);
|
2011-04-26 12:30:17 +00:00
|
|
|
mTouches = aTouches;
|
|
|
|
mTargetTouches = aTargetTouches;
|
|
|
|
mChangedTouches = aChangedTouches;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMTouchEvent::GetTouches(nsIDOMTouchList** aTouches)
|
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aTouches);
|
|
|
|
NS_ENSURE_STATE(mEvent);
|
|
|
|
nsRefPtr<nsDOMTouchList> t;
|
|
|
|
|
|
|
|
if (mTouches) {
|
|
|
|
return CallQueryInterface(mTouches, aTouches);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
|
|
|
|
if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
|
|
|
|
// for touchend events, remove any changed touches from the touches array
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > unchangedTouches;
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > touches = touchEvent->touches;
|
|
|
|
for (PRUint32 i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (!touches[i]->mChanged) {
|
|
|
|
unchangedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 14:51:56 +00:00
|
|
|
t = new nsDOMTouchList(unchangedTouches);
|
2011-12-17 00:24:11 +00:00
|
|
|
} else {
|
2012-04-24 14:51:56 +00:00
|
|
|
t = new nsDOMTouchList(touchEvent->touches);
|
2011-12-17 00:24:11 +00:00
|
|
|
}
|
|
|
|
mTouches = t;
|
|
|
|
return CallQueryInterface(mTouches, aTouches);
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMTouchEvent::GetTargetTouches(nsIDOMTouchList** aTargetTouches)
|
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aTargetTouches);
|
|
|
|
NS_ENSURE_STATE(mEvent);
|
|
|
|
|
|
|
|
if (mTargetTouches) {
|
|
|
|
return CallQueryInterface(mTargetTouches, aTargetTouches);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > targetTouches;
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > touches = touchEvent->touches;
|
|
|
|
for (PRUint32 i = 0; i < touches.Length(); ++i) {
|
|
|
|
// for touchend/cancel events, don't append to the target list if this is a
|
|
|
|
// touch that is ending
|
|
|
|
if ((mEvent->message != NS_TOUCH_END &&
|
|
|
|
mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
|
|
|
|
nsIDOMEventTarget* targetPtr = touches[i]->GetTarget();
|
|
|
|
if (targetPtr == mEvent->target) {
|
|
|
|
targetTouches.AppendElement(touches[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 14:51:56 +00:00
|
|
|
mTargetTouches = new nsDOMTouchList(targetTouches);
|
2011-12-17 00:24:11 +00:00
|
|
|
return CallQueryInterface(mTargetTouches, aTargetTouches);
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMTouchEvent::GetChangedTouches(nsIDOMTouchList** aChangedTouches)
|
|
|
|
{
|
2011-12-17 00:24:11 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aChangedTouches);
|
|
|
|
NS_ENSURE_STATE(mEvent);
|
|
|
|
|
|
|
|
if (mChangedTouches) {
|
|
|
|
return CallQueryInterface(mChangedTouches, aChangedTouches);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > changedTouches;
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(mEvent);
|
|
|
|
nsTArray<nsCOMPtr<nsIDOMTouch> > touches = touchEvent->touches;
|
|
|
|
for (PRUint32 i = 0; i < touches.Length(); ++i) {
|
|
|
|
if (touches[i]->mChanged) {
|
|
|
|
changedTouches.AppendElement(touches[i]);
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 14:51:56 +00:00
|
|
|
mChangedTouches = new nsDOMTouchList(changedTouches);
|
2011-12-17 00:24:11 +00:00
|
|
|
return CallQueryInterface(mChangedTouches, aChangedTouches);
|
2011-04-26 12:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsDOMTouchEvent::GetAltKey(bool* aAltKey)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2012-04-25 03:00:02 +00:00
|
|
|
*aAltKey = static_cast<nsInputEvent*>(mEvent)->IsAlt();
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsDOMTouchEvent::GetMetaKey(bool* aMetaKey)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2012-04-25 03:00:02 +00:00
|
|
|
*aMetaKey = static_cast<nsInputEvent*>(mEvent)->IsMeta();
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsDOMTouchEvent::GetCtrlKey(bool* aCtrlKey)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2012-04-25 03:00:02 +00:00
|
|
|
*aCtrlKey = static_cast<nsInputEvent*>(mEvent)->IsControl();
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsDOMTouchEvent::GetShiftKey(bool* aShiftKey)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
2012-04-25 03:00:02 +00:00
|
|
|
*aShiftKey = static_cast<nsInputEvent*>(mEvent)->IsShift();
|
2011-04-26 12:30:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-04-26 12:30:17 +00:00
|
|
|
nsDOMTouchEvent::PrefEnabled()
|
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sDidCheckPref = false;
|
|
|
|
static bool sPrefValue = false;
|
2011-04-26 12:30:17 +00:00
|
|
|
if (!sDidCheckPref) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sDidCheckPref = true;
|
2011-09-29 06:19:26 +00:00
|
|
|
sPrefValue = Preferences::GetBool("dom.w3c_touch_events.enabled", false);
|
2011-04-26 12:30:17 +00:00
|
|
|
if (sPrefValue) {
|
|
|
|
nsContentUtils::InitializeTouchEventTable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sPrefValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
nsPresContext* aPresContext,
|
2011-12-17 00:24:11 +00:00
|
|
|
nsTouchEvent *aEvent)
|
2011-04-26 12:30:17 +00:00
|
|
|
{
|
|
|
|
nsDOMTouchEvent* it = new nsDOMTouchEvent(aPresContext, aEvent);
|
|
|
|
|
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
|
|
|
}
|