Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / layout / generic / nsPlaceholderFrame.h
blob4cbb54259a075a8c62df1ae408a9e3c08887dd36
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 * rendering object for the point that anchors out-of-flow rendering
9 * objects such as floats and absolutely positioned elements
13 * Destruction of a placeholder and its out-of-flow must observe the
14 * following constraints:
16 * - The mapping from the out-of-flow to the placeholder must be
17 * removed from the frame manager before the placeholder is destroyed.
18 * - The mapping from the out-of-flow to the placeholder must be
19 * removed from the frame manager before the out-of-flow is destroyed.
20 * - The placeholder must be removed from the frame tree, or have the
21 * mapping from it to its out-of-flow cleared, before the out-of-flow
22 * is destroyed (so that the placeholder will not point to a destroyed
23 * frame while it's in the frame tree).
25 * Furthermore, some code assumes that placeholders point to something
26 * useful, so placeholders without an associated out-of-flow should not
27 * remain in the tree.
29 * The placeholder's Destroy() implementation handles the destruction of
30 * the placeholder and its out-of-flow. To avoid crashes, frame removal
31 * and destruction code that works with placeholders must not assume
32 * that the placeholder points to its out-of-flow.
35 #ifndef nsPlaceholderFrame_h___
36 #define nsPlaceholderFrame_h___
38 #include "mozilla/Attributes.h"
39 #include "nsIFrame.h"
40 #include "nsGkAtoms.h"
42 namespace mozilla {
43 class PresShell;
44 } // namespace mozilla
46 class nsPlaceholderFrame;
47 nsPlaceholderFrame* NS_NewPlaceholderFrame(mozilla::PresShell* aPresShell,
48 mozilla::ComputedStyle* aStyle,
49 nsFrameState aTypeBits);
51 #define PLACEHOLDER_TYPE_MASK \
52 (PLACEHOLDER_FOR_FLOAT | PLACEHOLDER_FOR_ABSPOS | PLACEHOLDER_FOR_FIXEDPOS | \
53 PLACEHOLDER_FOR_TOPLAYER)
55 /**
56 * Implementation of a frame that's used as a placeholder for a frame that
57 * has been moved out of the flow.
59 class nsPlaceholderFrame final : public nsIFrame {
60 public:
61 NS_DECL_FRAMEARENA_HELPERS(nsPlaceholderFrame)
62 #ifdef DEBUG
63 NS_DECL_QUERYFRAME
64 #endif
66 /**
67 * Create a new placeholder frame. aTypeBit must be one of the
68 * PLACEHOLDER_FOR_* constants above.
70 friend nsPlaceholderFrame* NS_NewPlaceholderFrame(
71 mozilla::PresShell* aPresShell, ComputedStyle* aStyle,
72 nsFrameState aTypeBits);
74 nsPlaceholderFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
75 nsFrameState aTypeBits)
76 : nsIFrame(aStyle, aPresContext, kClassID), mOutOfFlowFrame(nullptr) {
77 MOZ_ASSERT(
78 aTypeBits == PLACEHOLDER_FOR_FLOAT ||
79 aTypeBits == PLACEHOLDER_FOR_ABSPOS ||
80 aTypeBits == PLACEHOLDER_FOR_FIXEDPOS ||
81 aTypeBits == (PLACEHOLDER_FOR_TOPLAYER | PLACEHOLDER_FOR_ABSPOS) ||
82 aTypeBits == (PLACEHOLDER_FOR_TOPLAYER | PLACEHOLDER_FOR_FIXEDPOS),
83 "Unexpected type bit");
84 AddStateBits(aTypeBits);
87 // Get/Set the associated out of flow frame
88 nsIFrame* GetOutOfFlowFrame() const { return mOutOfFlowFrame; }
89 void SetOutOfFlowFrame(nsIFrame* aFrame) {
90 NS_ASSERTION(!aFrame || !aFrame->GetPrevContinuation(),
91 "OOF must be first continuation");
92 mOutOfFlowFrame = aFrame;
95 // nsIFrame overrides
96 void AddInlineMinISize(gfxContext* aRenderingContext,
97 InlineMinISizeData* aData) override;
98 void AddInlinePrefISize(gfxContext* aRenderingContext,
99 InlinePrefISizeData* aData) override;
101 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
102 const ReflowInput& aReflowInput,
103 nsReflowStatus& aStatus) override;
105 void Destroy(DestroyContext&) override;
107 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
108 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
109 const nsDisplayListSet& aLists) override;
110 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
112 #ifdef DEBUG_FRAME_DUMP
113 void List(FILE* out = stderr, const char* aPrefix = "",
114 ListFlags aFlags = ListFlags()) const override;
115 nsresult GetFrameName(nsAString& aResult) const override;
116 #endif // DEBUG
118 bool IsEmpty() override { return true; }
119 bool IsSelfEmpty() override { return true; }
121 bool CanContinueTextRun() const override;
123 void SetLineIsEmptySoFar(bool aValue) {
124 AddOrRemoveStateBits(PLACEHOLDER_LINE_IS_EMPTY_SO_FAR, aValue);
125 AddStateBits(PLACEHOLDER_HAVE_LINE_IS_EMPTY_SO_FAR);
127 bool GetLineIsEmptySoFar(bool* aResult) const {
128 bool haveValue = HasAnyStateBits(PLACEHOLDER_HAVE_LINE_IS_EMPTY_SO_FAR);
129 if (haveValue) {
130 *aResult = HasAnyStateBits(PLACEHOLDER_LINE_IS_EMPTY_SO_FAR);
132 return haveValue;
134 void ForgetLineIsEmptySoFar() {
135 RemoveStateBits(PLACEHOLDER_HAVE_LINE_IS_EMPTY_SO_FAR);
138 #ifdef ACCESSIBILITY
139 mozilla::a11y::AccType AccessibleType() override {
140 nsIFrame* realFrame = GetRealFrameForPlaceholder(this);
141 return realFrame ? realFrame->AccessibleType() : nsIFrame::AccessibleType();
143 #endif
145 ComputedStyle* GetParentComputedStyleForOutOfFlow(
146 nsIFrame** aProviderFrame) const;
148 // Like GetParentComputedStyleForOutOfFlow, but ignores display:contents bits.
149 ComputedStyle* GetLayoutParentStyleForOutOfFlow(
150 nsIFrame** aProviderFrame) const;
152 bool RenumberFrameAndDescendants(int32_t* aOrdinal, int32_t aDepth,
153 int32_t aIncrement,
154 bool aForCounting) override {
155 return mOutOfFlowFrame->RenumberFrameAndDescendants(
156 aOrdinal, aDepth, aIncrement, aForCounting);
160 * @return the out-of-flow for aFrame if aFrame is a placeholder; otherwise
161 * aFrame
163 static nsIFrame* GetRealFrameFor(nsIFrame* aFrame) {
164 MOZ_ASSERT(aFrame, "Must have a frame to work with");
165 if (aFrame->IsPlaceholderFrame()) {
166 return GetRealFrameForPlaceholder(aFrame);
168 return aFrame;
172 * @return the out-of-flow for aFrame, which is known to be a placeholder
174 static nsIFrame* GetRealFrameForPlaceholder(nsIFrame* aFrame) {
175 MOZ_ASSERT(aFrame->IsPlaceholderFrame(),
176 "Must have placeholder frame as input");
177 nsIFrame* outOfFlow =
178 static_cast<nsPlaceholderFrame*>(aFrame)->GetOutOfFlowFrame();
179 NS_ASSERTION(outOfFlow, "Null out-of-flow for placeholder?");
180 return outOfFlow;
183 protected:
184 nsIFrame* mOutOfFlowFrame;
187 #endif /* nsPlaceholderFrame_h___ */