2012-08-12 05:42:34 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-08-12 05:42:34 +04:00
|
|
|
/* 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-26 09:23:55 +04:00
|
|
|
#include "mozilla/dom/WheelEvent.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-07-03 19:56:26 +04:00
|
|
|
#include "prtime.h"
|
2012-08-12 05:42:34 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::WheelEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetWheelEvent* aWheelEvent)
|
2014-02-27 14:51:15 +04:00
|
|
|
: MouseEvent(aOwner, aPresContext,
|
|
|
|
aWheelEvent ? aWheelEvent :
|
2015-08-29 02:58:26 +03:00
|
|
|
new WidgetWheelEvent(false, eVoidEvent, nullptr))
|
2014-03-11 09:14:07 +04:00
|
|
|
, mAppUnitsPerDevPixel(0)
|
2012-08-12 05:42:34 +04:00
|
|
|
{
|
|
|
|
if (aWheelEvent) {
|
|
|
|
mEventIsInternal = false;
|
2014-03-11 09:14:07 +04: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.
|
2016-03-31 12:35:24 +03:00
|
|
|
if (aWheelEvent->mDeltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL) {
|
2014-03-11 09:14:07 +04:00
|
|
|
mAppUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
2012-08-12 05:42:34 +04:00
|
|
|
} else {
|
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2016-04-18 17:09:02 +03:00
|
|
|
mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2013-10-22 12:55:21 +04:00
|
|
|
mEvent->AsWheelEvent()->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2012-08-12 05:42:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WheelEvent, MouseEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WheelEvent, MouseEvent)
|
2012-08-12 05:42:34 +04:00
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(WheelEvent)
|
2014-02-27 14:51:15 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
|
2012-08-12 05:42:34 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
void
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::InitWheelEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* aView,
|
2014-02-26 09:23:55 +04:00
|
|
|
int32_t aDetail,
|
|
|
|
int32_t aScreenX,
|
|
|
|
int32_t aScreenY,
|
|
|
|
int32_t aClientX,
|
|
|
|
int32_t aClientY,
|
|
|
|
uint16_t aButton,
|
2016-01-30 20:05:36 +03:00
|
|
|
EventTarget* aRelatedTarget,
|
2014-02-26 09:23:55 +04:00
|
|
|
const nsAString& aModifiersList,
|
|
|
|
double aDeltaX,
|
|
|
|
double aDeltaY,
|
|
|
|
double aDeltaZ,
|
|
|
|
uint32_t aDeltaMode)
|
2012-08-12 05:42:34 +04:00
|
|
|
{
|
2016-10-30 22:30:06 +03:00
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
|
|
|
|
aScreenX, aScreenY, aClientX, aClientY, aButton,
|
|
|
|
aRelatedTarget, aModifiersList);
|
2012-08-12 05:42:34 +04:00
|
|
|
|
2013-10-22 12:55:21 +04:00
|
|
|
WidgetWheelEvent* wheelEvent = mEvent->AsWheelEvent();
|
2016-03-31 12:55:59 +03:00
|
|
|
wheelEvent->mDeltaX = aDeltaX;
|
2016-03-31 12:09:47 +03:00
|
|
|
wheelEvent->mDeltaY = aDeltaY;
|
2016-03-31 12:18:34 +03:00
|
|
|
wheelEvent->mDeltaZ = aDeltaZ;
|
2016-03-31 12:35:24 +03:00
|
|
|
wheelEvent->mDeltaMode = aDeltaMode;
|
2012-08-12 05:42:34 +04:00
|
|
|
}
|
|
|
|
|
2013-10-22 12:55:21 +04:00
|
|
|
double
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::DeltaX()
|
2013-10-22 12:55:21 +04:00
|
|
|
{
|
2014-03-11 09:14:07 +04:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
2016-03-31 12:55:59 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaX;
|
2014-03-11 09:14:07 +04:00
|
|
|
}
|
2016-03-31 12:55:59 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaX *
|
2014-03-11 09:14:07 +04:00
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::DeltaY()
|
2013-10-22 12:55:21 +04:00
|
|
|
{
|
2014-03-11 09:14:07 +04:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
2016-03-31 12:09:47 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaY;
|
2014-03-11 09:14:07 +04:00
|
|
|
}
|
2016-03-31 12:09:47 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaY *
|
2014-03-11 09:14:07 +04:00
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::DeltaZ()
|
2013-10-22 12:55:21 +04:00
|
|
|
{
|
2014-03-11 09:14:07 +04:00
|
|
|
if (!mAppUnitsPerDevPixel) {
|
2016-03-31 12:18:34 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaZ;
|
2014-03-11 09:14:07 +04:00
|
|
|
}
|
2016-03-31 12:18:34 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaZ *
|
2014-03-11 09:14:07 +04:00
|
|
|
mAppUnitsPerDevPixel / nsPresContext::AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2014-02-26 09:23:55 +04:00
|
|
|
WheelEvent::DeltaMode()
|
2013-10-22 12:55:21 +04:00
|
|
|
{
|
2016-03-31 12:35:24 +03:00
|
|
|
return mEvent->AsWheelEvent()->mDeltaMode;
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
already_AddRefed<WheelEvent>
|
|
|
|
WheelEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const WheelEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
2013-03-28 18:57:33 +04:00
|
|
|
{
|
2013-08-23 09:17:08 +04:00
|
|
|
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WheelEvent> e = new WheelEvent(t, nullptr, nullptr);
|
2013-03-28 18:57:33 +04:00
|
|
|
bool trusted = e->Init(t);
|
2016-01-30 20:05:36 +03:00
|
|
|
e->InitWheelEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, aParam.mDetail,
|
|
|
|
aParam.mScreenX, aParam.mScreenY,
|
|
|
|
aParam.mClientX, aParam.mClientY,
|
|
|
|
aParam.mButton, aParam.mRelatedTarget,
|
|
|
|
EmptyString(), aParam.mDeltaX,
|
|
|
|
aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode);
|
2015-05-19 23:26:02 +03:00
|
|
|
e->InitializeExtraMouseEventDictionaryMembers(aParam);
|
2013-03-28 18:57:33 +04:00
|
|
|
e->SetTrusted(trusted);
|
2016-08-31 06:16:11 +03:00
|
|
|
e->SetComposed(aParam.mComposed);
|
2013-03-28 18:57:33 +04:00
|
|
|
return e.forget();
|
|
|
|
}
|
|
|
|
|
2012-08-12 05:42:34 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-02-26 09:23:55 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-08-12 05:42:34 +04:00
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<WheelEvent>
|
|
|
|
NS_NewDOMWheelEvent(EventTarget* aOwner,
|
2014-02-26 09:23:55 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetWheelEvent* aEvent)
|
2012-08-12 05:42:34 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WheelEvent> it = new WheelEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2012-08-12 05:42:34 +04:00
|
|
|
}
|