Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / base / DepthOrderedFrameList.h
bloba12a5c9c86bd8b35bf2d5703b1d82ae3dc960814
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/. */
7 #ifndef mozilla_DepthOrderedFrameList_h
8 #define mozilla_DepthOrderedFrameList_h
10 #include "mozilla/ReverseIterator.h"
11 #include "nsTArray.h"
13 class nsIFrame;
15 namespace mozilla {
17 class DepthOrderedFrameList {
18 public:
19 // Add a dirty root.
20 void Add(nsIFrame* aFrame);
21 // Remove this frame if present.
22 void Remove(nsIFrame* aFrame);
23 // Remove and return one of the shallowest dirty roots from the list.
24 // (If two roots are at the same depth, order is indeterminate.)
25 nsIFrame* PopShallowestRoot();
26 // Remove all dirty roots.
27 void Clear() { mList.Clear(); }
28 // Is this frame one of the elements in the list?
29 bool Contains(nsIFrame* aFrame) const { return mList.Contains(aFrame); }
30 // Are there no elements?
31 bool IsEmpty() const { return mList.IsEmpty(); }
33 // Is the given frame an ancestor of any dirty root?
34 bool FrameIsAncestorOfAnyElement(nsIFrame* aFrame) const;
36 auto IterFromShallowest() const { return Reversed(mList); }
38 private:
39 struct FrameAndDepth {
40 nsIFrame* mFrame;
41 const uint32_t mDepth;
43 // Easy conversion to nsIFrame*, as it's the most likely need.
44 operator nsIFrame*() const { return mFrame; }
46 // Used to sort by reverse depths, i.e., deeper < shallower.
47 class CompareByReverseDepth {
48 public:
49 bool Equals(const FrameAndDepth& aA, const FrameAndDepth& aB) const {
50 return aA.mDepth == aB.mDepth;
52 bool LessThan(const FrameAndDepth& aA, const FrameAndDepth& aB) const {
53 // Reverse depth! So '>' instead of '<'.
54 return aA.mDepth > aB.mDepth;
58 // List of all known dirty roots, sorted by decreasing depths.
59 nsTArray<FrameAndDepth> mList;
62 } // namespace mozilla
64 #endif