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 bool IsFrameOfType(uint32_t aFlags
) const override
{
48 if (aFlags
& (eSupportsCSSTransforms
| eSupportsContainLayoutAndPaint
|
49 eSupportsAspectRatio
)) {
52 return nsContainerFrame::IsFrameOfType(
54 ~(nsIFrame::eBidiInlineContainer
| nsIFrame::eLineParticipant
));
57 virtual void InvalidateFrame(uint32_t aDisplayItemKey
= 0,
58 bool aRebuildDisplayItems
= true) override
;
59 virtual void InvalidateFrameWithRect(
60 const nsRect
& aRect
, uint32_t aDisplayItemKey
= 0,
61 bool aRebuildDisplayItems
= true) override
;
63 virtual bool IsEmpty() override
;
64 virtual bool IsSelfEmpty() override
;
66 virtual FrameSearchResult
PeekOffsetCharacter(
67 bool aForward
, int32_t* aOffset
,
68 PeekOffsetCharacterOptions aOptions
=
69 PeekOffsetCharacterOptions()) override
;
71 void Destroy(DestroyContext
&) override
;
73 void StealFrame(nsIFrame
* aChild
) override
;
75 // nsIHTMLReflow overrides
76 virtual void AddInlineMinISize(gfxContext
* aRenderingContext
,
77 InlineMinISizeData
* aData
) override
;
78 virtual void AddInlinePrefISize(gfxContext
* aRenderingContext
,
79 InlinePrefISizeData
* aData
) override
;
80 SizeComputationResult
ComputeSize(
81 gfxContext
* aRenderingContext
, mozilla::WritingMode aWM
,
82 const mozilla::LogicalSize
& aCBSize
, nscoord aAvailableISize
,
83 const mozilla::LogicalSize
& aMargin
,
84 const mozilla::LogicalSize
& aBorderPadding
,
85 const mozilla::StyleSizeOverrides
& aSizeOverrides
,
86 mozilla::ComputeSizeFlags aFlags
) override
;
87 virtual nsRect
ComputeTightBounds(DrawTarget
* aDrawTarget
) const override
;
88 virtual void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
89 const ReflowInput
& aReflowInput
,
90 nsReflowStatus
& aStatus
) override
;
92 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
93 int32_t aModType
) override
;
95 virtual bool CanContinueTextRun() const override
;
97 virtual void PullOverflowsFromPrevInFlow() override
;
99 Maybe
<nscoord
> GetNaturalBaselineBOffset(
100 mozilla::WritingMode aWM
, BaselineSharingGroup aBaselineGroup
,
101 BaselineExportContext
) const override
;
102 virtual bool DrainSelfOverflowList() override
;
105 * Return true if the frame is first visual frame or first continuation
107 bool IsFirst() const {
108 // If the frame's bidi visual state is set, return is-first state
109 // else return true if it's the first continuation.
110 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
111 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST
)
116 * Return true if the frame is last visual frame or last continuation.
118 bool IsLast() const {
119 // If the frame's bidi visual state is set, return is-last state
120 // else return true if it's the last continuation.
121 return HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET
)
122 ? HasAnyStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST
)
126 // Restyles the block wrappers around our non-inline-outside kids.
127 // This will only be called when such wrappers in fact exist.
128 void UpdateStyleOfOwnedAnonBoxesForIBSplit(
129 mozilla::ServoRestyleState
& aRestyleState
);
132 // Additional reflow input used during our reflow methods
133 struct InlineReflowInput
{
134 nsIFrame
* mPrevFrame
;
135 nsInlineFrame
* mNextInFlow
;
136 nsIFrame
* mLineContainer
;
137 nsLineLayout
* mLineLayout
;
138 bool mSetParentPointer
; // when reflowing child frame first set its
139 // parent frame pointer
141 InlineReflowInput() {
142 mPrevFrame
= nullptr;
143 mNextInFlow
= nullptr;
144 mLineContainer
= nullptr;
145 mLineLayout
= nullptr;
146 mSetParentPointer
= false;
150 nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
, ClassID aID
)
151 : nsContainerFrame(aStyle
, aPresContext
, aID
),
152 mBaseline(NS_INTRINSIC_ISIZE_UNKNOWN
) {}
154 LogicalSides
GetLogicalSkipSides() const override
;
156 void ReflowFrames(nsPresContext
* aPresContext
,
157 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
158 ReflowOutput
& aMetrics
, nsReflowStatus
& aStatus
);
160 void ReflowInlineFrame(nsPresContext
* aPresContext
,
161 const ReflowInput
& aReflowInput
, InlineReflowInput
& rs
,
162 nsIFrame
* aFrame
, nsReflowStatus
& aStatus
);
164 // Returns whether there's any frame that PullOneFrame would pull from
165 // aNextInFlow or any of aNextInFlow's next-in-flows.
166 static bool HasFramesToPull(nsInlineFrame
* aNextInFlow
);
168 virtual nsIFrame
* PullOneFrame(nsPresContext
*, InlineReflowInput
&);
170 virtual void PushFrames(nsPresContext
* aPresContext
, nsIFrame
* aFromChild
,
171 nsIFrame
* aPrevSibling
, InlineReflowInput
& aState
);
174 explicit nsInlineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
175 : nsInlineFrame(aStyle
, aPresContext
, kClassID
) {}
178 * Move any frames on our overflow list to the end of our principal list.
179 * @param aInFirstLine whether we're in a first-line frame.
180 * @return true if there were any overflow frames
182 bool DrainSelfOverflowListInternal(bool aInFirstLine
);
188 //----------------------------------------------------------------------
191 * Variation on inline-frame used to manage lines for line layout in
192 * special situations (:first-line style in particular).
194 class nsFirstLineFrame final
: public nsInlineFrame
{
196 NS_DECL_FRAMEARENA_HELPERS(nsFirstLineFrame
)
198 friend nsFirstLineFrame
* NS_NewFirstLineFrame(mozilla::PresShell
* aPresShell
,
199 ComputedStyle
* aStyle
);
201 #ifdef DEBUG_FRAME_DUMP
202 virtual nsresult
GetFrameName(nsAString
& aResult
) const override
;
204 virtual void Reflow(nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
205 const ReflowInput
& aReflowInput
,
206 nsReflowStatus
& aStatus
) override
;
208 virtual void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
209 nsIFrame
* aPrevInFlow
) override
;
210 virtual void PullOverflowsFromPrevInFlow() override
;
211 virtual bool DrainSelfOverflowList() override
;
214 explicit nsFirstLineFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
215 : nsInlineFrame(aStyle
, aPresContext
, kClassID
) {}
217 nsIFrame
* PullOneFrame(nsPresContext
*, InlineReflowInput
&) override
;
220 #endif /* nsInlineFrame_h___ */