|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* rendering object for CSS display:inline objects */ |
|
7 |
|
8 #ifndef nsInlineFrame_h___ |
|
9 #define nsInlineFrame_h___ |
|
10 |
|
11 #include "mozilla/Attributes.h" |
|
12 #include "nsContainerFrame.h" |
|
13 |
|
14 class nsLineLayout; |
|
15 |
|
16 typedef nsContainerFrame nsInlineFrameBase; |
|
17 |
|
18 /** |
|
19 * Inline frame class. |
|
20 * |
|
21 * This class manages a list of child frames that are inline frames. Working with |
|
22 * nsLineLayout, the class will reflow and place inline frames on a line. |
|
23 */ |
|
24 class nsInlineFrame : public nsInlineFrameBase |
|
25 { |
|
26 public: |
|
27 NS_DECL_QUERYFRAME_TARGET(nsInlineFrame) |
|
28 NS_DECL_QUERYFRAME |
|
29 NS_DECL_FRAMEARENA_HELPERS |
|
30 |
|
31 friend nsIFrame* NS_NewInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
32 |
|
33 // nsIFrame overrides |
|
34 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
35 const nsRect& aDirtyRect, |
|
36 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
37 |
|
38 #ifdef ACCESSIBILITY |
|
39 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
|
40 #endif |
|
41 |
|
42 #ifdef DEBUG_FRAME_DUMP |
|
43 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
44 #endif |
|
45 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
46 |
|
47 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
48 { |
|
49 if (aFlags & eSupportsCSSTransforms) { |
|
50 return false; |
|
51 } |
|
52 return nsContainerFrame::IsFrameOfType(aFlags & |
|
53 ~(nsIFrame::eBidiInlineContainer | nsIFrame::eLineParticipant)); |
|
54 } |
|
55 |
|
56 virtual void InvalidateFrame(uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; |
|
57 virtual void InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey = 0) MOZ_OVERRIDE; |
|
58 |
|
59 virtual bool IsEmpty() MOZ_OVERRIDE; |
|
60 virtual bool IsSelfEmpty() MOZ_OVERRIDE; |
|
61 |
|
62 virtual FrameSearchResult PeekOffsetCharacter(bool aForward, int32_t* aOffset, |
|
63 bool aRespectClusters = true) MOZ_OVERRIDE; |
|
64 |
|
65 // nsIHTMLReflow overrides |
|
66 virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext, |
|
67 InlineMinWidthData *aData) MOZ_OVERRIDE; |
|
68 virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext, |
|
69 InlinePrefWidthData *aData) MOZ_OVERRIDE; |
|
70 virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext, |
|
71 nsSize aCBSize, nscoord aAvailableWidth, |
|
72 nsSize aMargin, nsSize aBorder, nsSize aPadding, |
|
73 uint32_t aFlags) MOZ_OVERRIDE; |
|
74 virtual nsRect ComputeTightBounds(gfxContext* aContext) const MOZ_OVERRIDE; |
|
75 virtual nsresult Reflow(nsPresContext* aPresContext, |
|
76 nsHTMLReflowMetrics& aDesiredSize, |
|
77 const nsHTMLReflowState& aReflowState, |
|
78 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
79 |
|
80 virtual bool CanContinueTextRun() const MOZ_OVERRIDE; |
|
81 |
|
82 virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; |
|
83 virtual nscoord GetBaseline() const MOZ_OVERRIDE; |
|
84 virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; |
|
85 |
|
86 /** |
|
87 * Return true if the frame is first visual frame or first continuation |
|
88 */ |
|
89 bool IsFirst() const { |
|
90 // If the frame's bidi visual state is set, return is-first state |
|
91 // else return true if it's the first continuation. |
|
92 return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) |
|
93 ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_FIRST) |
|
94 : (!GetPrevInFlow()); |
|
95 } |
|
96 |
|
97 /** |
|
98 * Return true if the frame is last visual frame or last continuation. |
|
99 */ |
|
100 bool IsLast() const { |
|
101 // If the frame's bidi visual state is set, return is-last state |
|
102 // else return true if it's the last continuation. |
|
103 return (GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET) |
|
104 ? !!(GetStateBits() & NS_INLINE_FRAME_BIDI_VISUAL_IS_LAST) |
|
105 : (!GetNextInFlow()); |
|
106 } |
|
107 |
|
108 protected: |
|
109 // Additional reflow state used during our reflow methods |
|
110 struct InlineReflowState { |
|
111 nsIFrame* mPrevFrame; |
|
112 nsInlineFrame* mNextInFlow; |
|
113 nsIFrame* mLineContainer; |
|
114 nsLineLayout* mLineLayout; |
|
115 bool mSetParentPointer; // when reflowing child frame first set its |
|
116 // parent frame pointer |
|
117 |
|
118 InlineReflowState() { |
|
119 mPrevFrame = nullptr; |
|
120 mNextInFlow = nullptr; |
|
121 mLineContainer = nullptr; |
|
122 mLineLayout = nullptr; |
|
123 mSetParentPointer = false; |
|
124 } |
|
125 }; |
|
126 |
|
127 nsInlineFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {} |
|
128 |
|
129 virtual int GetLogicalSkipSides(const nsHTMLReflowState* aReflowState = nullptr) const MOZ_OVERRIDE; |
|
130 |
|
131 nsresult ReflowFrames(nsPresContext* aPresContext, |
|
132 const nsHTMLReflowState& aReflowState, |
|
133 InlineReflowState& rs, |
|
134 nsHTMLReflowMetrics& aMetrics, |
|
135 nsReflowStatus& aStatus); |
|
136 |
|
137 nsresult ReflowInlineFrame(nsPresContext* aPresContext, |
|
138 const nsHTMLReflowState& aReflowState, |
|
139 InlineReflowState& rs, |
|
140 nsIFrame* aFrame, |
|
141 nsReflowStatus& aStatus); |
|
142 |
|
143 /** |
|
144 * Reparent floats whose placeholders are inline descendants of aFrame from |
|
145 * whatever block they're currently parented by to aOurBlock. |
|
146 * @param aReparentSiblings if this is true, we follow aFrame's |
|
147 * GetNextSibling chain reparenting them all |
|
148 */ |
|
149 void ReparentFloatsForInlineChild(nsIFrame* aOurBlock, nsIFrame* aFrame, |
|
150 bool aReparentSiblings); |
|
151 |
|
152 virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, |
|
153 InlineReflowState& rs, |
|
154 bool* aIsComplete); |
|
155 |
|
156 virtual void PushFrames(nsPresContext* aPresContext, |
|
157 nsIFrame* aFromChild, |
|
158 nsIFrame* aPrevSibling, |
|
159 InlineReflowState& aState); |
|
160 |
|
161 private: |
|
162 // Helper method for DrainSelfOverflowList() to deal with lazy parenting |
|
163 // (which we only do for nsInlineFrame, not nsFirstLineFrame). |
|
164 enum DrainFlags { |
|
165 eDontReparentFrames = 1, // skip reparenting the overflow list frames |
|
166 eInFirstLine = 2, // the request is for an inline descendant of a nsFirstLineFrame |
|
167 }; |
|
168 /** |
|
169 * Move any frames on our overflow list to the end of our principal list. |
|
170 * @param aFlags one or more of the above DrainFlags |
|
171 * @param aLineContainer the nearest line container ancestor |
|
172 * @return true if there were any overflow frames |
|
173 */ |
|
174 bool DrainSelfOverflowListInternal(DrainFlags aFlags, |
|
175 nsIFrame* aLineContainer); |
|
176 protected: |
|
177 nscoord mBaseline; |
|
178 }; |
|
179 |
|
180 //---------------------------------------------------------------------- |
|
181 |
|
182 /** |
|
183 * Variation on inline-frame used to manage lines for line layout in |
|
184 * special situations (:first-line style in particular). |
|
185 */ |
|
186 class nsFirstLineFrame MOZ_FINAL : public nsInlineFrame { |
|
187 public: |
|
188 NS_DECL_FRAMEARENA_HELPERS |
|
189 |
|
190 friend nsIFrame* NS_NewFirstLineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
191 |
|
192 #ifdef DEBUG_FRAME_DUMP |
|
193 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
194 #endif |
|
195 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
196 virtual nsresult Reflow(nsPresContext* aPresContext, |
|
197 nsHTMLReflowMetrics& aDesiredSize, |
|
198 const nsHTMLReflowState& aReflowState, |
|
199 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
200 |
|
201 virtual void Init(nsIContent* aContent, nsIFrame* aParent, |
|
202 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
203 virtual void PullOverflowsFromPrevInFlow() MOZ_OVERRIDE; |
|
204 virtual bool DrainSelfOverflowList() MOZ_OVERRIDE; |
|
205 |
|
206 protected: |
|
207 nsFirstLineFrame(nsStyleContext* aContext) : nsInlineFrame(aContext) {} |
|
208 |
|
209 virtual nsIFrame* PullOneFrame(nsPresContext* aPresContext, |
|
210 InlineReflowState& rs, |
|
211 bool* aIsComplete) MOZ_OVERRIDE; |
|
212 }; |
|
213 |
|
214 #endif /* nsInlineFrame_h___ */ |