Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / generic / nsAbsoluteContainingBlock.h
blobfffed04dcaca94d1f510425f4044b16ddab4e8a1
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 /*
8 * code for managing absolutely positioned children of a rendering
9 * object that is a containing block for them
12 #ifndef nsAbsoluteContainingBlock_h___
13 #define nsAbsoluteContainingBlock_h___
15 #include "nsFrameList.h"
16 #include "nsIFrame.h"
17 #include "mozilla/TypedEnumBits.h"
19 class nsContainerFrame;
20 class nsPresContext;
22 /**
23 * This class contains the logic for being an absolute containing block. This
24 * class is used within viewport frames (for frames representing content with
25 * fixed position) and blocks (for frames representing absolutely positioned
26 * content), since each set of frames is absolutely positioned with respect to
27 * its parent.
29 * There is no principal child list, just a named child list which contains
30 * the absolutely positioned frames (FrameChildListID::Absolute or
31 * FrameChildListID::Fixed).
33 * All functions include as the first argument the frame that is delegating
34 * the request.
36 class nsAbsoluteContainingBlock {
37 using ReflowInput = mozilla::ReflowInput;
39 public:
40 explicit nsAbsoluteContainingBlock(mozilla::FrameChildListID aChildListID)
41 #ifdef DEBUG
42 : mChildListID(aChildListID)
43 #endif
45 MOZ_ASSERT(mChildListID == mozilla::FrameChildListID::Absolute ||
46 mChildListID == mozilla::FrameChildListID::Fixed,
47 "should either represent position:fixed or absolute content");
50 const nsFrameList& GetChildList() const { return mAbsoluteFrames; }
51 void AppendChildList(nsTArray<mozilla::FrameChildList>* aLists,
52 mozilla::FrameChildListID aListID) const {
53 NS_ASSERTION(aListID == mChildListID, "wrong list ID");
54 GetChildList().AppendIfNonempty(aLists, aListID);
57 void SetInitialChildList(nsIFrame* aDelegatingFrame,
58 mozilla::FrameChildListID aListID,
59 nsFrameList&& aChildList);
60 void AppendFrames(nsIFrame* aDelegatingFrame,
61 mozilla::FrameChildListID aListID,
62 nsFrameList&& aFrameList);
63 void InsertFrames(nsIFrame* aDelegatingFrame,
64 mozilla::FrameChildListID aListID, nsIFrame* aPrevFrame,
65 nsFrameList&& aFrameList);
66 void RemoveFrame(mozilla::FrameDestroyContext&, mozilla::FrameChildListID,
67 nsIFrame*);
69 enum class AbsPosReflowFlags {
70 ConstrainHeight = 0x1,
71 CBWidthChanged = 0x2,
72 CBHeightChanged = 0x4,
73 CBWidthAndHeightChanged = CBWidthChanged | CBHeightChanged,
74 IsGridContainerCB = 0x8,
77 /**
78 * Called by the delegating frame after it has done its reflow first. This
79 * function will reflow any absolutely positioned child frames that need to
80 * be reflowed, e.g., because the absolutely positioned child frame has
81 * 'auto' for an offset, or a percentage based width or height.
83 * @param aOverflowAreas, if non-null, is unioned with (in the local
84 * coordinate space) the overflow areas of the absolutely positioned
85 * children.
87 * @param aReflowStatus is assumed to be already-initialized, e.g. with the
88 * status of the delegating frame's main reflow. This function merges in the
89 * statuses of the absolutely positioned children's reflows.
91 * @param aFlags zero or more AbsPosReflowFlags
93 void Reflow(nsContainerFrame* aDelegatingFrame, nsPresContext* aPresContext,
94 const ReflowInput& aReflowInput, nsReflowStatus& aReflowStatus,
95 const nsRect& aContainingBlock, AbsPosReflowFlags aFlags,
96 mozilla::OverflowAreas* aOverflowAreas);
98 using DestroyContext = nsIFrame::DestroyContext;
99 void DestroyFrames(DestroyContext&);
101 bool HasAbsoluteFrames() const { return mAbsoluteFrames.NotEmpty(); }
104 * Mark our size-dependent absolute frames with NS_FRAME_HAS_DIRTY_CHILDREN
105 * so that we'll make sure to reflow them.
107 void MarkSizeDependentFramesDirty();
110 * Mark all our absolute frames with NS_FRAME_IS_DIRTY.
112 void MarkAllFramesDirty();
114 protected:
116 * Returns true if the position of aFrame depends on the position of
117 * its placeholder or if the position or size of aFrame depends on a
118 * containing block dimension that changed.
120 bool FrameDependsOnContainer(nsIFrame* aFrame, bool aCBWidthChanged,
121 bool aCBHeightChanged);
124 * After an abspos child's size is known, this method can be used to
125 * resolve size-dependent values in the ComputedLogicalOffsets on its
126 * reflow input. (This may involve resolving the inline dimension of
127 * aLogicalCBSize, too; hence, that variable is an in/outparam.)
129 * aKidSize, aMargin, aOffsets, and aLogicalCBSize are all expected to be
130 * represented in terms of the absolute containing block's writing-mode.
132 void ResolveSizeDependentOffsets(nsPresContext* aPresContext,
133 ReflowInput& aKidReflowInput,
134 const mozilla::LogicalSize& aKidSize,
135 const mozilla::LogicalMargin& aMargin,
136 mozilla::LogicalMargin* aOffsets,
137 mozilla::LogicalSize* aLogicalCBSize);
140 * For frames that have intrinsic block sizes, since we want to use the
141 * frame's actual instrinsic block-size, we don't compute margins in
142 * InitAbsoluteConstraints because the block-size isn't computed yet. This
143 * method computes the margins for them after layout.
144 * aMargin and aOffsets are both outparams (though we only touch aOffsets if
145 * the position is overconstrained)
147 void ResolveAutoMarginsAfterLayout(ReflowInput& aKidReflowInput,
148 const mozilla::LogicalSize* aLogicalCBSize,
149 const mozilla::LogicalSize& aKidSize,
150 mozilla::LogicalMargin& aMargin,
151 mozilla::LogicalMargin& aOffsets);
153 void ReflowAbsoluteFrame(nsIFrame* aDelegatingFrame,
154 nsPresContext* aPresContext,
155 const ReflowInput& aReflowInput,
156 const nsRect& aContainingBlockRect,
157 AbsPosReflowFlags aFlags, nsIFrame* aKidFrame,
158 nsReflowStatus& aStatus,
159 mozilla::OverflowAreas* aOverflowAreas);
162 * Mark our absolute frames dirty.
163 * @param aMarkAllDirty if true, all will be marked with NS_FRAME_IS_DIRTY.
164 * Otherwise, the size-dependant ones will be marked with
165 * NS_FRAME_HAS_DIRTY_CHILDREN.
167 void DoMarkFramesDirty(bool aMarkAllDirty);
169 protected:
170 nsFrameList mAbsoluteFrames; // additional named child list
172 #ifdef DEBUG
173 mozilla::FrameChildListID const
174 mChildListID; // FrameChildListID::Fixed or FrameChildListID::Absolute
175 #endif
178 namespace mozilla {
179 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(
180 nsAbsoluteContainingBlock::AbsPosReflowFlags)
182 #endif /* nsnsAbsoluteContainingBlock_h___ */