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/. */
|
|
|
|
|
2018-03-20 07:16:06 +03:00
|
|
|
#include "mozilla/dom/MouseEventBinding.h"
|
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.
|
2018-06-26 00:20:54 +03:00
|
|
|
if (aWheelEvent->mDeltaMode == WheelEvent_Binding::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);
|
2019-04-21 21:19:43 +03:00
|
|
|
mEvent->AsWheelEvent()->mInputSource =
|
2018-06-26 00:20:54 +03:00
|
|
|
MouseEvent_Binding::MOZ_SOURCE_UNKNOWN;
|
2012-08-12 05:42:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
void WheelEvent::InitWheelEvent(
|
|
|
|
const nsAString& aType, bool aCanBubble, bool aCancelable,
|
2017-11-07 01:52:14 +03:00
|
|
|
nsGlobalWindowInner* aView, int32_t aDetail, int32_t aScreenX,
|
2014-02-26 09:23:55 +04:00
|
|
|
int32_t aScreenY, int32_t aClientX, int32_t aClientY, uint16_t aButton,
|
|
|
|
EventTarget* aRelatedTarget, const nsAString& aModifiersList,
|
|
|
|
double aDeltaX, double aDeltaY, double aDeltaZ, uint32_t aDeltaMode) {
|
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
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
double WheelEvent::DeltaX() {
|
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 * mAppUnitsPerDevPixel /
|
2018-08-11 07:46:23 +03:00
|
|
|
AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
double WheelEvent::DeltaY() {
|
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 * mAppUnitsPerDevPixel /
|
2018-08-11 07:46:23 +03:00
|
|
|
AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
2014-02-26 09:23:55 +04:00
|
|
|
double WheelEvent::DeltaZ() {
|
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 * mAppUnitsPerDevPixel /
|
2018-08-11 07:46:23 +03:00
|
|
|
AppUnitsPerCSSPixel();
|
2013-10-22 12:55:21 +04:00
|
|
|
}
|
|
|
|
|
2016-03-31 12:35:24 +03:00
|
|
|
uint32_t WheelEvent::DeltaMode() { 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,
|
2019-09-11 17:35:28 +03:00
|
|
|
const WheelEventInit& aParam) {
|
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) {
|
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
|
|
|
}
|