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
);
36 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
37 const nsDisplayListSet
& aLists
) override
;
40 virtual mozilla::a11y::AccType
AccessibleType() override
;
43 #ifdef DEBUG_FRAME_DUMP
44 virtual nsresult
GetFrameName(nsAString
& aResult
) const override
;
47 virtual void InvalidateFrame(uint32_t aDisplayItemKey
= 0,
48 bool aRebuildDisplayItems
= true) override
;
49 virtual void InvalidateFrameWithRect(
50 const nsRect
& aRect
, uint32_t aDisplayItemKey
= 0,
51 bool aRebuildDisplayItems
= true) override
;
53 virtual bool IsEmpty() override
;
54 virtual bool IsSelfEmpty() override
;
56 virtual FrameSearchResult
PeekOffsetCharacter(
57 bool aForward
, int32_t* aOffset
,
58 PeekOffsetCharacterOptions aOptions
=
59 PeekOffsetCharacterOptions()) override
;
61 void Destroy(DestroyContext
&) override
;
63 void StealFrame(nsIFrame
* aChild
) override
;
65 // nsIHTMLReflow overrides
66 virtual void AddInlineMinISize(gfxContext
* aRenderingContext
,
67 InlineMinISizeData
* aData
) override
;
68 virtual void AddInlinePrefISize(gfxContext
* aRenderingContext
,
69 InlinePrefISizeData
* aData
) override
;
70 SizeComputationResult
ComputeSize(
71 gfxContext
* aRenderingContext
, mozilla::WritingMode aWM
,
72 const mozilla::LogicalSize
& aCBSize
, nscoord aAvailableISize
,
73 const mozilla::LogicalSize
& aMargin
,
74 const mozilla::LogicalSize
& aBorderPadding
,
75 const mozilla::StyleSizeOverrides
& aSizeOverrides
,
76 mozilla::ComputeSizeFlags aFlags
) override
;
77 virtual nsRect
ComputeTightBounds(DrawTarget
* aDrawTarget
) const override
;
78 virtual void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
79 const ReflowInput
& aReflowInput
,
80 nsReflowStatus
& aStatus
) override
;
82 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
83 int32_t aModType
) override
;
85 virtual bool CanContinueTextRun() const override
;
87 virtual void PullOverflowsFromPrevInFlow() override
;
89 Maybe
<nscoord
> GetNaturalBaselineBOffset(
90 mozilla::WritingMode aWM
, BaselineSharingGroup aBaselineGroup
,
91 BaselineExportContext
) const override
;
92 virtual bool DrainSelfOverflowList() override
;
95 * Return true if the frame is first visual frame or first continuation
97 bool IsFirst() const {
98 // If the frame's bidi visual state is set, return is-first state
99 // else return true if it's the first continuation.
100 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
101 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST
)
106 * Return true if the frame is last visual frame or last continuation.
108 bool IsLast() const {
109 // If the frame's bidi visual state is set, return is-last state
110 // else return true if it's the last continuation.
111 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
112 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST
)
116 // Restyles the block wrappers around our non-inline-outside kids.
117 // This will only be called when such wrappers in fact exist.
118 void UpdateStyleOfOwnedAnonBoxesForIBSplit(
119 mozilla::ServoRestyleState
& aRestyleState
);
122 // Additional reflow input used during our reflow methods
123 struct InlineReflowInput
{
124 nsIFrame
* mPrevFrame
;
125 nsInlineFrame
* mNextInFlow
;
126 nsIFrame
* mLineContainer
;
127 nsLineLayout
* mLineLayout
;
128 bool mSetParentPointer
; // when reflowing child frame first set its
129 // parent frame pointer
131 InlineReflowInput() {
132 mPrevFrame
= nullptr;
133 mNextInFlow
= nullptr;
134 mLineContainer
= nullptr;
135 mLineLayout
= nullptr;
136 mSetParentPointer
= false;
140 nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
, ClassID aID
)
141 : nsContainerFrame(aStyle
, aPresContext
, aID
),
142 mBaseline(NS_INTRINSIC_ISIZE_UNKNOWN
) {}
144 LogicalSides
GetLogicalSkipSides() const override
;
146 void ReflowFrames(nsPresContext
* aPresContext
,
147 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
148 ReflowOutput
& aMetrics
, nsReflowStatus
& aStatus
);
150 void ReflowInlineFrame(nsPresContext
* aPresContext
,
151 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
152 nsIFrame
* aFrame
, nsReflowStatus
& aStatus
);
154 // Returns whether there's any frame that PullOneFrame would pull from
155 // aNextInFlow or any of aNextInFlow's next-in-flows.
156 static bool HasFramesToPull(nsInlineFrame
* aNextInFlow
);
158 virtual nsIFrame
* PullOneFrame(nsPresContext
*, InlineReflowInput
&);
160 virtual void PushFrames(nsPresContext
* aPresContext
, nsIFrame
* aFromChild
,
161 nsIFrame
* aPrevSibling
, InlineReflowInput
& aState
);
164 explicit nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
165 : nsInlineFrame(aStyle
, aPresContext
, kClassID
) {}
168 * Move any frames on our overflow list to the end of our principal list.
169 * @param aInFirstLine whether we're in a first-line frame.
170 * @return true if there were any overflow frames
172 bool DrainSelfOverflowListInternal(bool aInFirstLine
);
178 //----------------------------------------------------------------------
181 * Variation on inline-frame used to manage lines for line layout in
182 * special situations (:first-line style in particular).
184 class nsFirstLineFrame final
: public nsInlineFrame
{
186 NS_DECL_FRAMEARENA_HELPERS(nsFirstLineFrame
)
188 friend nsFirstLineFrame
* NS_NewFirstLineFrame(mozilla::PresShell
* aPresShell
,
189 ComputedStyle
* aStyle
);
191 #ifdef DEBUG_FRAME_DUMP
192 virtual nsresult
GetFrameName(nsAString
& aResult
) const override
;
194 virtual void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
195 const ReflowInput
& aReflowInput
,
196 nsReflowStatus
& aStatus
) override
;
198 virtual void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
199 nsIFrame
* aPrevInFlow
) override
;
200 virtual void PullOverflowsFromPrevInFlow() override
;
201 virtual 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___ */