|
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 "base/basictypes.h" |
|
7 #include "ipc/IPCMessageUtils.h" |
|
8 #include "mozilla/dom/DOMRect.h" |
|
9 #include "mozilla/dom/ScrollAreaEvent.h" |
|
10 #include "mozilla/ContentEvents.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 ScrollAreaEvent::ScrollAreaEvent(EventTarget* aOwner, |
|
16 nsPresContext* aPresContext, |
|
17 InternalScrollAreaEvent* aEvent) |
|
18 : UIEvent(aOwner, aPresContext, aEvent) |
|
19 , mClientArea(nullptr) |
|
20 { |
|
21 mClientArea.SetLayoutRect(aEvent ? aEvent->mArea : nsRect()); |
|
22 } |
|
23 |
|
24 NS_IMPL_ADDREF_INHERITED(ScrollAreaEvent, UIEvent) |
|
25 NS_IMPL_RELEASE_INHERITED(ScrollAreaEvent, UIEvent) |
|
26 |
|
27 NS_INTERFACE_MAP_BEGIN(ScrollAreaEvent) |
|
28 NS_INTERFACE_MAP_ENTRY(nsIDOMScrollAreaEvent) |
|
29 NS_INTERFACE_MAP_END_INHERITING(UIEvent) |
|
30 |
|
31 |
|
32 #define FORWARD_GETTER(_name) \ |
|
33 NS_IMETHODIMP \ |
|
34 ScrollAreaEvent::Get ## _name(float* aResult) \ |
|
35 { \ |
|
36 *aResult = _name(); \ |
|
37 return NS_OK; \ |
|
38 } |
|
39 |
|
40 FORWARD_GETTER(X) |
|
41 FORWARD_GETTER(Y) |
|
42 FORWARD_GETTER(Width) |
|
43 FORWARD_GETTER(Height) |
|
44 |
|
45 NS_IMETHODIMP |
|
46 ScrollAreaEvent::InitScrollAreaEvent(const nsAString& aEventType, |
|
47 bool aCanBubble, |
|
48 bool aCancelable, |
|
49 nsIDOMWindow* aView, |
|
50 int32_t aDetail, |
|
51 float aX, |
|
52 float aY, |
|
53 float aWidth, |
|
54 float aHeight) |
|
55 { |
|
56 nsresult rv = |
|
57 UIEvent::InitUIEvent(aEventType, aCanBubble, aCancelable, aView, aDetail); |
|
58 NS_ENSURE_SUCCESS(rv, rv); |
|
59 |
|
60 mClientArea.SetRect(aX, aY, aWidth, aHeight); |
|
61 |
|
62 return NS_OK; |
|
63 } |
|
64 |
|
65 NS_IMETHODIMP_(void) |
|
66 ScrollAreaEvent::Serialize(IPC::Message* aMsg, |
|
67 bool aSerializeInterfaceType) |
|
68 { |
|
69 if (aSerializeInterfaceType) { |
|
70 IPC::WriteParam(aMsg, NS_LITERAL_STRING("scrollareaevent")); |
|
71 } |
|
72 |
|
73 Event::Serialize(aMsg, false); |
|
74 |
|
75 IPC::WriteParam(aMsg, X()); |
|
76 IPC::WriteParam(aMsg, Y()); |
|
77 IPC::WriteParam(aMsg, Width()); |
|
78 IPC::WriteParam(aMsg, Height()); |
|
79 } |
|
80 |
|
81 NS_IMETHODIMP_(bool) |
|
82 ScrollAreaEvent::Deserialize(const IPC::Message* aMsg, void** aIter) |
|
83 { |
|
84 NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false); |
|
85 |
|
86 float x, y, width, height; |
|
87 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &x), false); |
|
88 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &y), false); |
|
89 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &width), false); |
|
90 NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &height), false); |
|
91 mClientArea.SetRect(x, y, width, height); |
|
92 |
|
93 return true; |
|
94 } |
|
95 |
|
96 } // namespace dom |
|
97 } // namespace mozilla |
|
98 |
|
99 using namespace mozilla; |
|
100 using namespace mozilla::dom; |
|
101 |
|
102 nsresult |
|
103 NS_NewDOMScrollAreaEvent(nsIDOMEvent** aInstancePtrResult, |
|
104 EventTarget* aOwner, |
|
105 nsPresContext* aPresContext, |
|
106 InternalScrollAreaEvent* aEvent) |
|
107 { |
|
108 ScrollAreaEvent* ev = new ScrollAreaEvent(aOwner, aPresContext, aEvent); |
|
109 return CallQueryInterface(ev, aInstancePtrResult); |
|
110 } |