tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NotifyPaintEvent.cpp (4115B)


      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/NotifyPaintEvent.h"
      8 
      9 #include "base/basictypes.h"
     10 #include "ipc/IPCMessageUtils.h"
     11 #include "mozilla/GfxMessageUtils.h"
     12 #include "mozilla/dom/DOMRect.h"
     13 #include "mozilla/dom/PaintRequest.h"
     14 #include "nsContentUtils.h"
     15 
     16 namespace mozilla::dom {
     17 
     18 NotifyPaintEvent::NotifyPaintEvent(
     19    EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent,
     20    EventMessage aEventMessage, nsTArray<nsRect>* aInvalidateRequests,
     21    uint64_t aTransactionId, DOMHighResTimeStamp aTimeStamp)
     22    : Event(aOwner, aPresContext, aEvent) {
     23  if (mEvent) {
     24    mEvent->mMessage = aEventMessage;
     25  }
     26  if (aInvalidateRequests) {
     27    mInvalidateRequests.SwapElements(*aInvalidateRequests);
     28  }
     29 
     30  mTransactionId = aTransactionId;
     31  mTimeStamp = aTimeStamp;
     32 }
     33 
     34 nsRegion NotifyPaintEvent::GetRegion(SystemCallerGuarantee) {
     35  nsRegion r;
     36  for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
     37    r.Or(r, mInvalidateRequests[i]);
     38    r.SimplifyOutward(10);
     39  }
     40  return r;
     41 }
     42 
     43 already_AddRefed<DOMRect> NotifyPaintEvent::BoundingClientRect(
     44    SystemCallerGuarantee aGuarantee) {
     45  RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
     46 
     47  if (mPresContext) {
     48    rect->SetLayoutRect(GetRegion(aGuarantee).GetBounds());
     49  }
     50 
     51  return rect.forget();
     52 }
     53 
     54 already_AddRefed<DOMRectList> NotifyPaintEvent::ClientRects(
     55    SystemCallerGuarantee aGuarantee) {
     56  nsISupports* parent = ToSupports(this);
     57  RefPtr<DOMRectList> rectList = new DOMRectList(parent);
     58 
     59  nsRegion r = GetRegion(aGuarantee);
     60  for (auto iter = r.RectIter(); !iter.Done(); iter.Next()) {
     61    RefPtr<DOMRect> rect = new DOMRect(parent);
     62    rect->SetLayoutRect(iter.Get());
     63    rectList->Append(std::move(rect));
     64  }
     65 
     66  return rectList.forget();
     67 }
     68 
     69 already_AddRefed<PaintRequestList> NotifyPaintEvent::PaintRequests(
     70    SystemCallerGuarantee) {
     71  Event* parent = this;
     72  RefPtr<PaintRequestList> requests = new PaintRequestList(parent);
     73 
     74  for (uint32_t i = 0; i < mInvalidateRequests.Length(); ++i) {
     75    RefPtr<PaintRequest> r = new PaintRequest(parent);
     76    r->SetRequest(mInvalidateRequests[i]);
     77    requests->Append(std::move(r));
     78  }
     79 
     80  return requests.forget();
     81 }
     82 
     83 void NotifyPaintEvent::Serialize(IPC::MessageWriter* aWriter,
     84                                 bool aSerializeInterfaceType) {
     85  if (aSerializeInterfaceType) {
     86    IPC::WriteParam(aWriter, u"notifypaintevent"_ns);
     87  }
     88 
     89  Event::Serialize(aWriter, false);
     90 
     91  uint32_t length = mInvalidateRequests.Length();
     92  IPC::WriteParam(aWriter, length);
     93  for (uint32_t i = 0; i < length; ++i) {
     94    IPC::WriteParam(aWriter, mInvalidateRequests[i]);
     95  }
     96 }
     97 
     98 bool NotifyPaintEvent::Deserialize(IPC::MessageReader* aReader) {
     99  NS_ENSURE_TRUE(Event::Deserialize(aReader), false);
    100 
    101  uint32_t length = 0;
    102  NS_ENSURE_TRUE(IPC::ReadParam(aReader, &length), false);
    103  mInvalidateRequests.SetCapacity(length);
    104  for (uint32_t i = 0; i < length; ++i) {
    105    nsRect req;
    106    NS_ENSURE_TRUE(IPC::ReadParam(aReader, &req), false);
    107    mInvalidateRequests.AppendElement(req);
    108  }
    109 
    110  return true;
    111 }
    112 
    113 uint64_t NotifyPaintEvent::TransactionId(SystemCallerGuarantee) {
    114  return mTransactionId;
    115 }
    116 
    117 DOMHighResTimeStamp NotifyPaintEvent::PaintTimeStamp(SystemCallerGuarantee) {
    118  return mTimeStamp;
    119 }
    120 
    121 }  // namespace mozilla::dom
    122 
    123 using namespace mozilla;
    124 using namespace mozilla::dom;
    125 
    126 already_AddRefed<NotifyPaintEvent> NS_NewDOMNotifyPaintEvent(
    127    EventTarget* aOwner, nsPresContext* aPresContext, WidgetEvent* aEvent,
    128    EventMessage aEventMessage, nsTArray<nsRect>* aInvalidateRequests,
    129    uint64_t aTransactionId, DOMHighResTimeStamp aTimeStamp) {
    130  RefPtr<NotifyPaintEvent> it =
    131      new NotifyPaintEvent(aOwner, aPresContext, aEvent, aEventMessage,
    132                           aInvalidateRequests, aTransactionId, aTimeStamp);
    133  return it.forget();
    134 }