Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / base / nsFrameTraversal.h
blob2226e603453ff6a0c8325668ba3bd4d74a83343d
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 NSFRAMETRAVERSAL_H
8 #define NSFRAMETRAVERSAL_H
10 #include <cstdint>
11 #include "mozilla/Attributes.h"
13 class nsIFrame;
14 class nsPresContext;
16 class MOZ_STACK_CLASS nsFrameIterator final {
17 public:
18 void First();
19 void Next();
20 nsIFrame* CurrentItem();
21 bool IsDone();
23 void Last();
24 void Prev();
26 inline nsIFrame* Traverse(bool aForward) {
27 if (aForward) {
28 Next();
29 } else {
30 Prev();
32 return CurrentItem();
35 enum class Type : uint8_t {
36 // only leaf nodes
37 Leaf,
38 // "open tag" order
39 PreOrder,
40 // "close tag" order
41 PostOrder,
43 nsFrameIterator(nsPresContext* aPresContext, nsIFrame* aStart, Type aType,
44 bool aVisual, bool aLockInScrollView, bool aFollowOOFs,
45 bool aSkipPopupChecks, nsIFrame* aLimiter = nullptr);
46 ~nsFrameIterator() = default;
48 protected:
49 void SetCurrent(nsIFrame* aFrame) { mCurrent = aFrame; }
50 nsIFrame* GetCurrent() { return mCurrent; }
51 nsIFrame* GetStart() { return mStart; }
52 nsIFrame* GetLast() { return mLast; }
53 void SetLast(nsIFrame* aFrame) { mLast = aFrame; }
54 int8_t GetOffEdge() { return mOffEdge; }
55 void SetOffEdge(int8_t aOffEdge) { mOffEdge = aOffEdge; }
58 Our own versions of the standard frame tree navigation
59 methods, which, if the iterator is following out-of-flows,
60 apply the following rules for placeholder frames:
62 - If a frame HAS a placeholder frame, getting its parent
63 gets the placeholder's parent.
65 - If a frame's first child or next/prev sibling IS a
66 placeholder frame, then we instead return the real frame.
68 - If a frame HAS a placeholder frame, getting its next/prev
69 sibling gets the placeholder frame's next/prev sibling.
71 These are all applied recursively to support multiple levels of
72 placeholders.
75 nsIFrame* GetParentFrame(nsIFrame* aFrame);
76 // like GetParentFrame but returns null once a popup frame is reached
77 nsIFrame* GetParentFrameNotPopup(nsIFrame* aFrame);
79 nsIFrame* GetFirstChild(nsIFrame* aFrame);
80 nsIFrame* GetLastChild(nsIFrame* aFrame);
82 nsIFrame* GetNextSibling(nsIFrame* aFrame);
83 nsIFrame* GetPrevSibling(nsIFrame* aFrame);
86 These methods are overridden by the bidi visual iterator to have the
87 semantics of "get first child in visual order", "get last child in visual
88 order", "get next sibling in visual order" and "get previous sibling in
89 visual order".
92 nsIFrame* GetFirstChildInner(nsIFrame* aFrame);
93 nsIFrame* GetLastChildInner(nsIFrame* aFrame);
95 nsIFrame* GetNextSiblingInner(nsIFrame* aFrame);
96 nsIFrame* GetPrevSiblingInner(nsIFrame* aFrame);
98 /**
99 * Return the placeholder frame for aFrame if it has one, otherwise return
100 * aFrame itself.
102 nsIFrame* GetPlaceholderFrame(nsIFrame* aFrame);
103 bool IsPopupFrame(nsIFrame* aFrame);
105 bool IsInvokerOpenPopoverFrame(nsIFrame* aFrame);
107 nsPresContext* const mPresContext;
108 const bool mLockScroll;
109 const bool mFollowOOFs;
110 const bool mSkipPopupChecks;
111 const bool mVisual;
112 const Type mType;
114 private:
115 nsIFrame* const mStart;
116 nsIFrame* mCurrent;
117 nsIFrame* mLast; // the last one that was in current;
118 nsIFrame* mLimiter;
119 int8_t mOffEdge; // 0= no -1 to far prev, 1 to far next;
122 #endif // NSFRAMETRAVERSAL_H