ScrollAreaEvent.cpp 2.9 KB

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