MouseScrollEvent.cpp (2520B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "MouseScrollEvent.h" 8 9 #include "mozilla/MouseEvents.h" 10 #include "mozilla/dom/MouseEventBinding.h" 11 12 namespace mozilla::dom { 13 14 MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner, 15 nsPresContext* aPresContext, 16 WidgetMouseScrollEvent* aEvent) 17 : MouseEvent(aOwner, aPresContext, 18 aEvent 19 ? aEvent 20 : new WidgetMouseScrollEvent(false, eVoidEvent, nullptr)) { 21 if (aEvent) { 22 mEventIsInternal = false; 23 } else { 24 mEventIsInternal = true; 25 mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0); 26 static_cast<WidgetMouseEventBase*>(mEvent)->mInputSource = 27 MouseEvent_Binding::MOZ_SOURCE_UNKNOWN; 28 } 29 30 mDetail = mEvent->AsMouseScrollEvent()->mDelta; 31 } 32 33 void MouseScrollEvent::InitMouseScrollEventInternal( 34 const nsAString& aType, bool aCanBubble, bool aCancelable, 35 nsGlobalWindowInner* aView, int32_t aDetail, double aScreenX, 36 double aScreenY, double aClientX, double aClientY, bool aCtrlKey, 37 bool aAltKey, bool aShiftKey, bool aMetaKey, uint16_t aButton, 38 EventTarget* aRelatedTarget, int32_t aAxis) { 39 NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched); 40 41 MouseEvent::InitMouseEventInternal(aType, aCanBubble, aCancelable, aView, 42 aDetail, aScreenX, aScreenY, aClientX, 43 aClientY, aCtrlKey, aAltKey, aShiftKey, 44 aMetaKey, aButton, aRelatedTarget); 45 mEvent->AsMouseScrollEvent()->mIsHorizontal = 46 (aAxis == MouseScrollEvent_Binding::HORIZONTAL_AXIS); 47 } 48 49 int32_t MouseScrollEvent::Axis() { 50 return mEvent->AsMouseScrollEvent()->mIsHorizontal 51 ? MouseScrollEvent_Binding::HORIZONTAL_AXIS 52 : MouseScrollEvent_Binding::VERTICAL_AXIS; 53 } 54 55 } // namespace mozilla::dom 56 57 using namespace mozilla; 58 using namespace dom; 59 60 already_AddRefed<MouseScrollEvent> NS_NewDOMMouseScrollEvent( 61 EventTarget* aOwner, nsPresContext* aPresContext, 62 WidgetMouseScrollEvent* aEvent) { 63 RefPtr<MouseScrollEvent> it = 64 new MouseScrollEvent(aOwner, aPresContext, aEvent); 65 return it.forget(); 66 }