Line data Source code
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 "mozilla/dom/MouseScrollEvent.h"
8 : #include "mozilla/MouseEvents.h"
9 : #include "prtime.h"
10 : #include "nsIDOMMouseScrollEvent.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 0 : MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner,
16 : nsPresContext* aPresContext,
17 0 : WidgetMouseScrollEvent* aEvent)
18 : : MouseEvent(aOwner, aPresContext,
19 : aEvent ? aEvent :
20 0 : new WidgetMouseScrollEvent(false, eVoidEvent, nullptr))
21 : {
22 0 : if (aEvent) {
23 0 : mEventIsInternal = false;
24 : } else {
25 0 : mEventIsInternal = true;
26 0 : mEvent->mTime = PR_Now();
27 0 : mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
28 0 : static_cast<WidgetMouseEventBase*>(mEvent)->inputSource =
29 : nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
30 : }
31 :
32 0 : mDetail = mEvent->AsMouseScrollEvent()->mDelta;
33 0 : }
34 :
35 0 : NS_IMPL_ADDREF_INHERITED(MouseScrollEvent, MouseEvent)
36 0 : NS_IMPL_RELEASE_INHERITED(MouseScrollEvent, MouseEvent)
37 :
38 0 : NS_INTERFACE_MAP_BEGIN(MouseScrollEvent)
39 0 : NS_INTERFACE_MAP_END_INHERITING(MouseEvent)
40 :
41 : void
42 0 : MouseScrollEvent::InitMouseScrollEvent(const nsAString& aType,
43 : bool aCanBubble,
44 : bool aCancelable,
45 : nsGlobalWindow* aView,
46 : int32_t aDetail,
47 : int32_t aScreenX,
48 : int32_t aScreenY,
49 : int32_t aClientX,
50 : int32_t aClientY,
51 : bool aCtrlKey,
52 : bool aAltKey,
53 : bool aShiftKey,
54 : bool aMetaKey,
55 : uint16_t aButton,
56 : EventTarget* aRelatedTarget,
57 : int32_t aAxis)
58 : {
59 0 : NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
60 :
61 0 : MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail,
62 : aScreenX, aScreenY, aClientX, aClientY,
63 : aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton,
64 0 : aRelatedTarget);
65 0 : mEvent->AsMouseScrollEvent()->mIsHorizontal =
66 0 : (aAxis == nsIDOMMouseScrollEvent::HORIZONTAL_AXIS);
67 : }
68 :
69 : int32_t
70 0 : MouseScrollEvent::Axis()
71 : {
72 0 : return mEvent->AsMouseScrollEvent()->mIsHorizontal ?
73 : static_cast<int32_t>(nsIDOMMouseScrollEvent::HORIZONTAL_AXIS) :
74 0 : static_cast<int32_t>(nsIDOMMouseScrollEvent::VERTICAL_AXIS);
75 : }
76 :
77 : } // namespace dom
78 : } // namespace mozilla
79 :
80 : using namespace mozilla;
81 : using namespace dom;
82 :
83 : already_AddRefed<MouseScrollEvent>
84 0 : NS_NewDOMMouseScrollEvent(EventTarget* aOwner,
85 : nsPresContext* aPresContext,
86 : WidgetMouseScrollEvent* aEvent)
87 : {
88 : RefPtr<MouseScrollEvent> it =
89 0 : new MouseScrollEvent(aOwner, aPresContext, aEvent);
90 0 : return it.forget();
91 : }
|