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