tor-browser

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

PaintRequest.h (2290B)


      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 #ifndef mozilla_dom_PaintRequest_h_
      8 #define mozilla_dom_PaintRequest_h_
      9 
     10 #include "mozilla/RefPtr.h"
     11 #include "mozilla/dom/Event.h"
     12 #include "nsPresContext.h"
     13 #include "nsWrapperCache.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class DOMRect;
     18 
     19 class PaintRequest final : public nsISupports, public nsWrapperCache {
     20 public:
     21  explicit PaintRequest(Event* aParent) : mParent(aParent) {}
     22 
     23  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     24  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PaintRequest)
     25 
     26  virtual JSObject* WrapObject(JSContext* aCx,
     27                               JS::Handle<JSObject*> aGivenProto) override;
     28 
     29  Event* GetParentObject() const { return mParent; }
     30 
     31  already_AddRefed<DOMRect> ClientRect();
     32  void GetReason(nsAString& aResult) const { aResult.AssignLiteral("repaint"); }
     33 
     34  void SetRequest(const nsRect& aRequest) { mRequest = aRequest; }
     35 
     36 private:
     37  ~PaintRequest() = default;
     38 
     39  RefPtr<Event> mParent;
     40  nsRect mRequest;
     41 };
     42 
     43 class PaintRequestList final : public nsISupports, public nsWrapperCache {
     44 public:
     45  explicit PaintRequestList(Event* aParent) : mParent(aParent) {}
     46 
     47  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     48  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PaintRequestList)
     49 
     50  virtual JSObject* WrapObject(JSContext* aCx,
     51                               JS::Handle<JSObject*> aGivenProto) override;
     52  nsISupports* GetParentObject() { return mParent; }
     53 
     54  void Append(RefPtr<PaintRequest>&& aElement) {
     55    mArray.AppendElement(std::move(aElement));
     56  }
     57 
     58  uint32_t Length() { return mArray.Length(); }
     59 
     60  PaintRequest* Item(uint32_t aIndex) { return mArray.SafeElementAt(aIndex); }
     61  PaintRequest* IndexedGetter(uint32_t aIndex, bool& aFound) {
     62    aFound = aIndex < mArray.Length();
     63    if (!aFound) {
     64      return nullptr;
     65    }
     66    return mArray.ElementAt(aIndex);
     67  }
     68 
     69 private:
     70  ~PaintRequestList() = default;
     71 
     72  nsTArray<RefPtr<PaintRequest> > mArray;
     73  RefPtr<Event> mParent;
     74 };
     75 
     76 }  // namespace mozilla::dom
     77 
     78 #endif  // mozilla_dom_PaintRequest_h_