2012-08-11 18:42:34 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-02-25 21:23:55 -08:00
|
|
|
#include "mozilla/dom/WheelEvent.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-07-03 08:56:26 -07:00
|
|
|
#include "prtime.h"
|
2012-08-11 18:42:34 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::WheelEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetWheelEvent* aWheelEvent)
|
2014-02-27 02:51:15 -08:00
|
|
|
: MouseEvent(aOwner, aPresContext,
|
|
|
|
aWheelEvent ? aWheelEvent :
|
|
|
|
new WidgetWheelEvent(false, 0, nullptr))
|
2014-03-10 22:14:07 -07:00
|
|
|
, mAppUnitsPerDevPixel(0)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
if (aWheelEvent) {
|
|
|
|
mEventIsInternal = false;
|
2014-03-10 22:14:07 -07:00
|
|
|
// If the delta mode is pixel, the WidgetWheelEvent's delta values are in
|
|
|
|
// device pixels. However, JS contents need the delta values in CSS pixels.
|
|
|
|
// We should store the value of mAppUnitsPerDevPixel here because
|
|
|
|
// it might be changed by changing zoom or something.
|
|
|
|
if (aWheelEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL) {
|
|
|
|
mAppUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
} else {
|
|
|
|
mEventIsInternal = true;
|
|
|
|
mEvent->time = PR_Now();
|
|
|
|
mEvent->refPoint.x = mEvent->refPoint.y = 0;
|
2013-10-22 01:55:21 -07:00
|
|
|
mEvent->AsWheelEvent()->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 02:51:15 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WheelEvent, MouseEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WheelEvent, MouseEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2014-02-25 21:23:55 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(WheelEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMWheelEvent)
|
2014-02-27 02:51:15 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::InitWheelEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
|
|
|
nsIDOMWindow* aView,
|
|
|
|
int32_t aDetail,
|
|
|
|
int32_t aScreenX,
|
|
|
|
int32_t aScreenY,
|
|
|
|
int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
uint16_t aButton,
|
|
|
|
nsIDOMEventTarget* aRelatedTarget,
|
|
|
|
const nsAString& aModifiersList,
|
|
|
|
double aDeltaX,
|
|
|
|
double aDeltaY,
|
|
|
|
double aDeltaZ,
|
|
|
|
uint32_t aDeltaMode)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
nsresult rv =
|
2014-02-27 02:51:15 -08:00
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
|
|
|
|
aScreenX, aScreenY, aClientX, aClientY, aButton,
|
|
|
|
aRelatedTarget, aModifiersList);
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2013-10-22 01:55:21 -07:00
|
|
|
WidgetWheelEvent* wheelEvent = mEvent->AsWheelEvent();
|
2012-08-11 18:42:34 -07:00
|
|
|
wheelEvent->deltaX = aDeltaX;
|
|
|
|
wheelEvent->deltaY = aDeltaY;
|
|
|
|
wheelEvent->deltaZ = aDeltaZ;
|
|
|
|
wheelEvent->deltaMode = aDeltaMode;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:21 -07:00
|
|
|
double
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::DeltaX()
|
2013-10-22 01:55:21 -07:00
|
|
|
{
|
2014-03-10 22:14:07 -07:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
|
|
|
return mEvent->AsWheelEvent()->deltaX;
|
|
|
|
}
|
|
|
|
return mEvent->AsWheelEvent()->deltaX *
|
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 01:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::GetDeltaX(double* aDeltaX)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDeltaX);
|
|
|
|
|
2013-03-28 07:57:33 -07:00
|
|
|
*aDeltaX = DeltaX();
|
2012-08-11 18:42:34 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:21 -07:00
|
|
|
double
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::DeltaY()
|
2013-10-22 01:55:21 -07:00
|
|
|
{
|
2014-03-10 22:14:07 -07:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
|
|
|
return mEvent->AsWheelEvent()->deltaY;
|
|
|
|
}
|
|
|
|
return mEvent->AsWheelEvent()->deltaY *
|
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 01:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::GetDeltaY(double* aDeltaY)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDeltaY);
|
|
|
|
|
2013-03-28 07:57:33 -07:00
|
|
|
*aDeltaY = DeltaY();
|
2012-08-11 18:42:34 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:21 -07:00
|
|
|
double
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::DeltaZ()
|
2013-10-22 01:55:21 -07:00
|
|
|
{
|
2014-03-10 22:14:07 -07:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
|
|
|
return mEvent->AsWheelEvent()->deltaZ;
|
|
|
|
}
|
|
|
|
return mEvent->AsWheelEvent()->deltaZ *
|
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 01:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::GetDeltaZ(double* aDeltaZ)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDeltaZ);
|
|
|
|
|
2013-03-28 07:57:33 -07:00
|
|
|
*aDeltaZ = DeltaZ();
|
2012-08-11 18:42:34 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-22 01:55:21 -07:00
|
|
|
uint32_t
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::DeltaMode()
|
2013-10-22 01:55:21 -07:00
|
|
|
{
|
|
|
|
return mEvent->AsWheelEvent()->deltaMode;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
NS_IMETHODIMP
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent::GetDeltaMode(uint32_t* aDeltaMode)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDeltaMode);
|
|
|
|
|
2013-03-28 07:57:33 -07:00
|
|
|
*aDeltaMode = DeltaMode();
|
2012-08-11 18:42:34 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-28 07:57:33 -07:00
|
|
|
static void
|
|
|
|
GetModifierList(bool aCtrl, bool aShift, bool aAlt, bool aMeta,
|
|
|
|
nsAString& aModifierList)
|
|
|
|
{
|
|
|
|
if (aCtrl) {
|
|
|
|
aModifierList.AppendLiteral(NS_DOM_KEYNAME_CONTROL);
|
|
|
|
}
|
|
|
|
if (aShift) {
|
|
|
|
if (!aModifierList.IsEmpty()) {
|
|
|
|
aModifierList.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
aModifierList.AppendLiteral(NS_DOM_KEYNAME_SHIFT);
|
|
|
|
}
|
|
|
|
if (aAlt) {
|
|
|
|
if (!aModifierList.IsEmpty()) {
|
|
|
|
aModifierList.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
aModifierList.AppendLiteral(NS_DOM_KEYNAME_ALT);
|
|
|
|
}
|
|
|
|
if (aMeta) {
|
|
|
|
if (!aModifierList.IsEmpty()) {
|
|
|
|
aModifierList.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
aModifierList.AppendLiteral(NS_DOM_KEYNAME_META);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:23:55 -08:00
|
|
|
already_AddRefed<WheelEvent>
|
|
|
|
WheelEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const WheelEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-03-28 07:57:33 -07:00
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2014-02-25 21:23:55 -08:00
|
|
|
nsRefPtr<WheelEvent> e = new WheelEvent(t, nullptr, nullptr);
|
2013-03-28 07:57:33 -07:00
|
|
|
bool trusted = e->Init(t);
|
|
|
|
nsAutoString modifierList;
|
|
|
|
GetModifierList(aParam.mCtrlKey, aParam.mShiftKey,
|
|
|
|
aParam.mAltKey, aParam.mMetaKey,
|
|
|
|
modifierList);
|
|
|
|
aRv = e->InitWheelEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, aParam.mDetail,
|
|
|
|
aParam.mScreenX, aParam.mScreenY,
|
|
|
|
aParam.mClientX, aParam.mClientY,
|
|
|
|
aParam.mButton, aParam.mRelatedTarget,
|
|
|
|
modifierList, aParam.mDeltaX,
|
|
|
|
aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode);
|
2013-10-22 01:55:21 -07:00
|
|
|
e->mEvent->AsWheelEvent()->buttons = aParam.mButtons;
|
2013-03-28 07:57:33 -07:00
|
|
|
e->SetTrusted(trusted);
|
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-25 21:23:55 -08:00
|
|
|
using namespace mozilla::dom;
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2014-02-25 21:23:55 -08:00
|
|
|
nsresult
|
|
|
|
NS_NewDOMWheelEvent(nsIDOMEvent** aInstancePtrResult,
|
|
|
|
EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
2014-02-25 21:23:55 -08:00
|
|
|
WheelEvent* it = new WheelEvent(aOwner, aPresContext, aEvent);
|
2014-03-17 13:00:11 -07:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = static_cast<Event*>(it);
|
|
|
|
return NS_OK;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|