|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "mozilla/dom/MouseScrollEvent.h" |
|
7 #include "mozilla/MouseEvents.h" |
|
8 #include "prtime.h" |
|
9 |
|
10 namespace mozilla { |
|
11 namespace dom { |
|
12 |
|
13 MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner, |
|
14 nsPresContext* aPresContext, |
|
15 WidgetMouseScrollEvent* aEvent) |
|
16 : MouseEvent(aOwner, aPresContext, |
|
17 aEvent ? aEvent : new WidgetMouseScrollEvent(false, 0, nullptr)) |
|
18 { |
|
19 if (aEvent) { |
|
20 mEventIsInternal = false; |
|
21 } else { |
|
22 mEventIsInternal = true; |
|
23 mEvent->time = PR_Now(); |
|
24 mEvent->refPoint.x = mEvent->refPoint.y = 0; |
|
25 static_cast<WidgetMouseEventBase*>(mEvent)->inputSource = |
|
26 nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; |
|
27 } |
|
28 |
|
29 mDetail = mEvent->AsMouseScrollEvent()->delta; |
|
30 } |
|
31 |
|
32 NS_IMPL_ADDREF_INHERITED(MouseScrollEvent, MouseEvent) |
|
33 NS_IMPL_RELEASE_INHERITED(MouseScrollEvent, MouseEvent) |
|
34 |
|
35 NS_INTERFACE_MAP_BEGIN(MouseScrollEvent) |
|
36 NS_INTERFACE_MAP_ENTRY(nsIDOMMouseScrollEvent) |
|
37 NS_INTERFACE_MAP_END_INHERITING(MouseEvent) |
|
38 |
|
39 NS_IMETHODIMP |
|
40 MouseScrollEvent::InitMouseScrollEvent(const nsAString& aType, |
|
41 bool aCanBubble, |
|
42 bool aCancelable, |
|
43 nsIDOMWindow* aView, |
|
44 int32_t aDetail, |
|
45 int32_t aScreenX, |
|
46 int32_t aScreenY, |
|
47 int32_t aClientX, |
|
48 int32_t aClientY, |
|
49 bool aCtrlKey, |
|
50 bool aAltKey, |
|
51 bool aShiftKey, |
|
52 bool aMetaKey, |
|
53 uint16_t aButton, |
|
54 nsIDOMEventTarget* aRelatedTarget, |
|
55 int32_t aAxis) |
|
56 { |
|
57 nsresult rv = |
|
58 MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail, |
|
59 aScreenX, aScreenY, aClientX, aClientY, |
|
60 aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton, |
|
61 aRelatedTarget); |
|
62 NS_ENSURE_SUCCESS(rv, rv); |
|
63 mEvent->AsMouseScrollEvent()->isHorizontal = (aAxis == HORIZONTAL_AXIS); |
|
64 return NS_OK; |
|
65 } |
|
66 |
|
67 |
|
68 NS_IMETHODIMP |
|
69 MouseScrollEvent::GetAxis(int32_t* aResult) |
|
70 { |
|
71 NS_ENSURE_ARG_POINTER(aResult); |
|
72 *aResult = Axis(); |
|
73 return NS_OK; |
|
74 } |
|
75 |
|
76 int32_t |
|
77 MouseScrollEvent::Axis() |
|
78 { |
|
79 return mEvent->AsMouseScrollEvent()->isHorizontal ? |
|
80 static_cast<int32_t>(HORIZONTAL_AXIS) : |
|
81 static_cast<int32_t>(VERTICAL_AXIS); |
|
82 } |
|
83 |
|
84 } // namespace dom |
|
85 } // namespace mozilla |
|
86 |
|
87 using namespace mozilla; |
|
88 using namespace dom; |
|
89 |
|
90 nsresult |
|
91 NS_NewDOMMouseScrollEvent(nsIDOMEvent** aInstancePtrResult, |
|
92 EventTarget* aOwner, |
|
93 nsPresContext* aPresContext, |
|
94 WidgetMouseScrollEvent* aEvent) |
|
95 { |
|
96 MouseScrollEvent* it = new MouseScrollEvent(aOwner, aPresContext, aEvent); |
|
97 NS_ADDREF(it); |
|
98 *aInstancePtrResult = static_cast<Event*>(it); |
|
99 return NS_OK; |
|
100 } |