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 "base/basictypes.h"
8 #include "ipc/IPCMessageUtils.h"
9 #include "mozilla/dom/DOMRect.h"
10 #include "mozilla/dom/ScrollAreaEvent.h"
11 #include "mozilla/ContentEvents.h"
12 
13 namespace mozilla {
14 namespace dom {
15 
ScrollAreaEvent(EventTarget * aOwner,nsPresContext * aPresContext,InternalScrollAreaEvent * aEvent)16 ScrollAreaEvent::ScrollAreaEvent(EventTarget* aOwner,
17                                  nsPresContext* aPresContext,
18                                  InternalScrollAreaEvent* aEvent)
19     : UIEvent(aOwner, aPresContext, aEvent), mClientArea(new DOMRect(nullptr)) {
20   mClientArea->SetLayoutRect(aEvent ? aEvent->mArea : nsRect());
21 }
22 
NS_IMPL_CYCLE_COLLECTION_INHERITED(ScrollAreaEvent,UIEvent,mClientArea)23 NS_IMPL_CYCLE_COLLECTION_INHERITED(ScrollAreaEvent, UIEvent, mClientArea)
24 
25 NS_IMPL_ADDREF_INHERITED(ScrollAreaEvent, UIEvent)
26 NS_IMPL_RELEASE_INHERITED(ScrollAreaEvent, UIEvent)
27 
28 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScrollAreaEvent)
29 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
30 
31 void ScrollAreaEvent::InitScrollAreaEvent(const nsAString& aEventType,
32                                           bool aCanBubble, bool aCancelable,
33                                           nsGlobalWindowInner* aView,
34                                           int32_t aDetail, float aX, float aY,
35                                           float aWidth, float aHeight) {
36   NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
37 
38   UIEvent::InitUIEvent(aEventType, aCanBubble, aCancelable, aView, aDetail);
39   mClientArea->SetRect(aX, aY, aWidth, aHeight);
40 }
41 
Serialize(IPC::Message * aMsg,bool aSerializeInterfaceType)42 void ScrollAreaEvent::Serialize(IPC::Message* aMsg,
43                                 bool aSerializeInterfaceType) {
44   if (aSerializeInterfaceType) {
45     IPC::WriteParam(aMsg, NS_LITERAL_STRING("scrollareaevent"));
46   }
47 
48   Event::Serialize(aMsg, false);
49 
50   IPC::WriteParam(aMsg, X());
51   IPC::WriteParam(aMsg, Y());
52   IPC::WriteParam(aMsg, Width());
53   IPC::WriteParam(aMsg, Height());
54 }
55 
Deserialize(const IPC::Message * aMsg,PickleIterator * aIter)56 bool ScrollAreaEvent::Deserialize(const IPC::Message* aMsg,
57                                   PickleIterator* aIter) {
58   NS_ENSURE_TRUE(Event::Deserialize(aMsg, aIter), false);
59 
60   float x, y, width, height;
61   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &x), false);
62   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &y), false);
63   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &width), false);
64   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &height), false);
65   mClientArea->SetRect(x, y, width, height);
66 
67   return true;
68 }
69 
70 }  // namespace dom
71 }  // namespace mozilla
72 
73 using namespace mozilla;
74 using namespace mozilla::dom;
75 
NS_NewDOMScrollAreaEvent(EventTarget * aOwner,nsPresContext * aPresContext,InternalScrollAreaEvent * aEvent)76 already_AddRefed<ScrollAreaEvent> NS_NewDOMScrollAreaEvent(
77     EventTarget* aOwner, nsPresContext* aPresContext,
78     InternalScrollAreaEvent* aEvent) {
79   RefPtr<ScrollAreaEvent> ev =
80       new ScrollAreaEvent(aOwner, aPresContext, aEvent);
81   return ev.forget();
82 }
83