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 /* rendering object for CSS display:inline objects */
9 #ifndef nsInlineFrame_h___
10 #define nsInlineFrame_h___
12 #include "mozilla/Attributes.h"
13 #include "nsContainerFrame.h"
19 } // namespace mozilla
24 * This class manages a list of child frames that are inline frames. Working
25 * with nsLineLayout, the class will reflow and place inline frames on a line.
27 class nsInlineFrame
: public nsContainerFrame
{
30 NS_DECL_FRAMEARENA_HELPERS(nsInlineFrame
)
32 friend nsInlineFrame
* NS_NewInlineFrame(mozilla::PresShell
* aPresShell
,
33 ComputedStyle
* aStyle
);
35 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
36 const nsDisplayListSet
& aLists
) override
;
39 mozilla::a11y::AccType
AccessibleType() override
;
42 #ifdef DEBUG_FRAME_DUMP
43 nsresult
GetFrameName(nsAString
& aResult
) const override
;
46 void InvalidateFrame(uint32_t aDisplayItemKey
= 0,
47 bool aRebuildDisplayItems
= true) override
;
48 void InvalidateFrameWithRect(const nsRect
& aRect
,
49 uint32_t aDisplayItemKey
= 0,
50 bool aRebuildDisplayItems
= true) override
;
52 bool IsEmpty() override
;
53 bool IsSelfEmpty() override
;
55 FrameSearchResult
PeekOffsetCharacter(
56 bool aForward
, int32_t* aOffset
,
57 PeekOffsetCharacterOptions aOptions
=
58 PeekOffsetCharacterOptions()) override
;
60 void Destroy(DestroyContext
&) override
;
62 void StealFrame(nsIFrame
* aChild
) override
;
64 void AddInlineMinISize(gfxContext
* aRenderingContext
,
65 InlineMinISizeData
* aData
) override
;
66 void AddInlinePrefISize(gfxContext
* aRenderingContext
,
67 InlinePrefISizeData
* aData
) override
;
68 SizeComputationResult
ComputeSize(
69 gfxContext
* aRenderingContext
, mozilla::WritingMode aWM
,
70 const mozilla::LogicalSize
& aCBSize
, nscoord aAvailableISize
,
71 const mozilla::LogicalSize
& aMargin
,
72 const mozilla::LogicalSize
& aBorderPadding
,
73 const mozilla::StyleSizeOverrides
& aSizeOverrides
,
74 mozilla::ComputeSizeFlags aFlags
) override
;
75 nsRect
ComputeTightBounds(DrawTarget
* aDrawTarget
) const override
;
77 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aReflowOutput
,
78 const ReflowInput
& aReflowInput
,
79 nsReflowStatus
& aStatus
) override
;
81 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
82 int32_t aModType
) override
;
84 bool CanContinueTextRun() const override
;
86 void PullOverflowsFromPrevInFlow() override
;
88 Maybe
<nscoord
> GetNaturalBaselineBOffset(
89 mozilla::WritingMode aWM
, BaselineSharingGroup aBaselineGroup
,
90 BaselineExportContext
) const override
;
91 bool DrainSelfOverflowList() override
;
94 * Return true if the frame is first visual frame or first continuation
96 bool IsFirst() const {
97 // If the frame's bidi visual state is set, return is-first state
98 // else return true if it's the first continuation.
99 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
100 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST
)
105 * Return true if the frame is last visual frame or last continuation.
107 bool IsLast() const {
108 // If the frame's bidi visual state is set, return is-last state
109 // else return true if it's the last continuation.
110 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
111 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST
)
115 // Restyles the block wrappers around our non-inline-outside kids.
116 // This will only be called when such wrappers in fact exist.
117 void UpdateStyleOfOwnedAnonBoxesForIBSplit(
118 mozilla::ServoRestyleState
& aRestyleState
);
121 // Additional reflow input used during our reflow methods
122 struct InlineReflowInput
{
123 nsIFrame
* mPrevFrame
;
124 nsInlineFrame
* mNextInFlow
;
125 nsIFrame
* mLineContainer
;
126 nsLineLayout
* mLineLayout
;
127 bool mSetParentPointer
; // when reflowing child frame first set its
128 // parent frame pointer
130 InlineReflowInput() {
131 mPrevFrame
= nullptr;
132 mNextInFlow
= nullptr;
133 mLineContainer
= nullptr;
134 mLineLayout
= nullptr;
135 mSetParentPointer
= false;
139 nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
, ClassID aID
)
140 : nsContainerFrame(aStyle
, aPresContext
, aID
),
141 mBaseline(NS_INTRINSIC_ISIZE_UNKNOWN
) {}
143 LogicalSides
GetLogicalSkipSides() const override
;
145 void ReflowFrames(nsPresContext
* aPresContext
,
146 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
147 ReflowOutput
& aMetrics
, nsReflowStatus
& aStatus
);
149 void ReflowInlineFrame(nsPresContext
* aPresContext
,
150 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
151 nsIFrame
* aFrame
, nsReflowStatus
& aStatus
);
153 // Returns whether there's any frame that PullOneFrame would pull from
154 // aNextInFlow or any of aNextInFlow's next-in-flows.
155 static bool HasFramesToPull(nsInlineFrame
* aNextInFlow
);
157 virtual nsIFrame
* PullOneFrame(nsPresContext
*, InlineReflowInput
&);
159 virtual void PushFrames(nsPresContext
* aPresContext
, nsIFrame
* aFromChild
,
160 nsIFrame
* aPrevSibling
, InlineReflowInput
& aState
);
163 explicit nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
164 : nsInlineFrame(aStyle
, aPresContext
, kClassID
) {}
167 * Move any frames on our overflow list to the end of our principal list.
168 * @param aInFirstLine whether we're in a first-line frame.
169 * @return true if there were any overflow frames
171 bool DrainSelfOverflowListInternal(bool aInFirstLine
);
177 //----------------------------------------------------------------------
180 * Variation on inline-frame used to manage lines for line layout in
181 * special situations (:first-line style in particular).
183 class nsFirstLineFrame final
: public nsInlineFrame
{
185 NS_DECL_FRAMEARENA_HELPERS(nsFirstLineFrame
)
187 friend nsFirstLineFrame
* NS_NewFirstLineFrame(mozilla::PresShell
* aPresShell
,
188 ComputedStyle
* aStyle
);
190 #ifdef DEBUG_FRAME_DUMP
191 nsresult
GetFrameName(nsAString
& aResult
) const override
;
194 void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aReflowOutput
,
195 const ReflowInput
& aReflowInput
,
196 nsReflowStatus
& aStatus
) override
;
198 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
199 nsIFrame
* aPrevInFlow
) override
;
200 void PullOverflowsFromPrevInFlow() override
;
201 bool DrainSelfOverflowList() override
;
204 explicit nsFirstLineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
205 : nsInlineFrame(aStyle
, aPresContext
, kClassID
) {}
207 nsIFrame
* PullOneFrame(nsPresContext
*, InlineReflowInput
&) override
;
210 #endif /* nsInlineFrame_h___ */