/src/mozilla-central/layout/tables/nsTableWrapperFrame.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "nsTableWrapperFrame.h" |
7 | | |
8 | | #include "nsFrameManager.h" |
9 | | #include "nsTableFrame.h" |
10 | | #include "nsTableCellFrame.h" |
11 | | #include "mozilla/ComputedStyle.h" |
12 | | #include "nsStyleConsts.h" |
13 | | #include "nsPresContext.h" |
14 | | #include "nsCSSRendering.h" |
15 | | #include "nsIContent.h" |
16 | | #include "prinrval.h" |
17 | | #include "nsGkAtoms.h" |
18 | | #include "nsHTMLParts.h" |
19 | | #include "nsIPresShell.h" |
20 | | #include "nsIServiceManager.h" |
21 | | #include "nsDisplayList.h" |
22 | | #include "nsLayoutUtils.h" |
23 | | #include "nsIFrameInlines.h" |
24 | | #include <algorithm> |
25 | | |
26 | | using namespace mozilla; |
27 | | using namespace mozilla::layout; |
28 | | |
29 | 0 | #define NO_SIDE 100 |
30 | | |
31 | | /* virtual */ nscoord |
32 | | nsTableWrapperFrame::GetLogicalBaseline(WritingMode aWritingMode) const |
33 | 0 | { |
34 | 0 | nsIFrame* kid = mFrames.FirstChild(); |
35 | 0 | if (!kid) { |
36 | 0 | MOZ_ASSERT_UNREACHABLE("no inner table"); |
37 | 0 | return nsContainerFrame::GetLogicalBaseline(aWritingMode); |
38 | 0 | } |
39 | 0 |
|
40 | 0 | return kid->GetLogicalBaseline(aWritingMode) + |
41 | 0 | kid->BStart(aWritingMode, mRect.Size()); |
42 | 0 | } |
43 | | |
44 | | nsTableWrapperFrame::nsTableWrapperFrame(ComputedStyle* aStyle, ClassID aID) |
45 | | : nsContainerFrame(aStyle, aID) |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | nsTableWrapperFrame::~nsTableWrapperFrame() |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | 0 | NS_QUERYFRAME_HEAD(nsTableWrapperFrame) |
54 | 0 | NS_QUERYFRAME_ENTRY(nsTableWrapperFrame) |
55 | 0 | NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame) |
56 | | |
57 | | #ifdef ACCESSIBILITY |
58 | | a11y::AccType |
59 | | nsTableWrapperFrame::AccessibleType() |
60 | 0 | { |
61 | 0 | return a11y::eHTMLTableType; |
62 | 0 | } |
63 | | #endif |
64 | | |
65 | | void |
66 | | nsTableWrapperFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) |
67 | 0 | { |
68 | 0 | DestroyAbsoluteFrames(aDestructRoot, aPostDestroyData); |
69 | 0 | mCaptionFrames.DestroyFramesFrom(aDestructRoot, aPostDestroyData); |
70 | 0 | nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData); |
71 | 0 | } |
72 | | |
73 | | const nsFrameList& |
74 | | nsTableWrapperFrame::GetChildList(ChildListID aListID) const |
75 | 0 | { |
76 | 0 | if (aListID == kCaptionList) { |
77 | 0 | return mCaptionFrames; |
78 | 0 | } |
79 | 0 | |
80 | 0 | return nsContainerFrame::GetChildList(aListID); |
81 | 0 | } |
82 | | |
83 | | void |
84 | | nsTableWrapperFrame::GetChildLists(nsTArray<ChildList>* aLists) const |
85 | 0 | { |
86 | 0 | nsContainerFrame::GetChildLists(aLists); |
87 | 0 | mCaptionFrames.AppendIfNonempty(aLists, kCaptionList); |
88 | 0 | } |
89 | | |
90 | | void |
91 | | nsTableWrapperFrame::SetInitialChildList(ChildListID aListID, |
92 | | nsFrameList& aChildList) |
93 | 0 | { |
94 | 0 | if (kCaptionList == aListID) { |
95 | 0 | // the frame constructor already checked for table-caption display type |
96 | 0 | MOZ_ASSERT(mCaptionFrames.IsEmpty(), |
97 | 0 | "already have child frames in CaptionList"); |
98 | 0 | mCaptionFrames.SetFrames(aChildList); |
99 | 0 | } else { |
100 | 0 | MOZ_ASSERT(kPrincipalList != aListID || |
101 | 0 | (aChildList.FirstChild() && |
102 | 0 | aChildList.FirstChild() == aChildList.LastChild() && |
103 | 0 | aChildList.FirstChild()->IsTableFrame()), |
104 | 0 | "expected a single table frame in principal child list"); |
105 | 0 | nsContainerFrame::SetInitialChildList(aListID, aChildList); |
106 | 0 | } |
107 | 0 | } |
108 | | |
109 | | void |
110 | | nsTableWrapperFrame::AppendFrames(ChildListID aListID, |
111 | | nsFrameList& aFrameList) |
112 | 0 | { |
113 | 0 | // We only have two child frames: the inner table and a caption frame. |
114 | 0 | // The inner frame is provided when we're initialized, and it cannot change |
115 | 0 | MOZ_ASSERT(kCaptionList == aListID, "unexpected child list"); |
116 | 0 | MOZ_ASSERT(aFrameList.IsEmpty() || |
117 | 0 | aFrameList.FirstChild()->IsTableCaption(), |
118 | 0 | "appending non-caption frame to captionList"); |
119 | 0 | mCaptionFrames.AppendFrames(this, aFrameList); |
120 | 0 |
|
121 | 0 | // Reflow the new caption frame. It's already marked dirty, so |
122 | 0 | // just tell the pres shell. |
123 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
124 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
125 | 0 | // The presence of caption frames makes us sort our display |
126 | 0 | // list differently, so mark us as changed for the new |
127 | 0 | // ordering. |
128 | 0 | MarkNeedsDisplayItemRebuild(); |
129 | 0 | } |
130 | | |
131 | | void |
132 | | nsTableWrapperFrame::InsertFrames(ChildListID aListID, |
133 | | nsIFrame* aPrevFrame, |
134 | | nsFrameList& aFrameList) |
135 | 0 | { |
136 | 0 | MOZ_ASSERT(kCaptionList == aListID, "unexpected child list"); |
137 | 0 | MOZ_ASSERT(aFrameList.IsEmpty() || |
138 | 0 | aFrameList.FirstChild()->IsTableCaption(), |
139 | 0 | "inserting non-caption frame into captionList"); |
140 | 0 | MOZ_ASSERT(!aPrevFrame || aPrevFrame->GetParent() == this, |
141 | 0 | "inserting after sibling frame with different parent"); |
142 | 0 | mCaptionFrames.InsertFrames(nullptr, aPrevFrame, aFrameList); |
143 | 0 |
|
144 | 0 | // Reflow the new caption frame. It's already marked dirty, so |
145 | 0 | // just tell the pres shell. |
146 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
147 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
148 | 0 | MarkNeedsDisplayItemRebuild(); |
149 | 0 | } |
150 | | |
151 | | void |
152 | | nsTableWrapperFrame::RemoveFrame(ChildListID aListID, |
153 | | nsIFrame* aOldFrame) |
154 | 0 | { |
155 | 0 | // We only have two child frames: the inner table and one caption frame. |
156 | 0 | // The inner frame can't be removed so this should be the caption |
157 | 0 | MOZ_ASSERT(kCaptionList == aListID, "can't remove inner frame"); |
158 | 0 |
|
159 | 0 | if (HasSideCaption()) { |
160 | 0 | // The old caption isize had an effect on the inner table isize, so |
161 | 0 | // we're going to need to reflow it. Mark it dirty |
162 | 0 | InnerTableFrame()->AddStateBits(NS_FRAME_IS_DIRTY); |
163 | 0 | } |
164 | 0 |
|
165 | 0 | // Remove the frame and destroy it |
166 | 0 | mCaptionFrames.DestroyFrame(aOldFrame); |
167 | 0 |
|
168 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
169 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
170 | 0 | MarkNeedsDisplayItemRebuild(); |
171 | 0 | } |
172 | | |
173 | | void |
174 | | nsTableWrapperFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
175 | | const nsDisplayListSet& aLists) |
176 | 0 | { |
177 | 0 | // No border, background or outline are painted because they all belong |
178 | 0 | // to the inner table. |
179 | 0 |
|
180 | 0 | // If there's no caption, take a short cut to avoid having to create |
181 | 0 | // the special display list set and then sort it. |
182 | 0 | if (mCaptionFrames.IsEmpty()) { |
183 | 0 | BuildDisplayListForInnerTable(aBuilder, aLists); |
184 | 0 | return; |
185 | 0 | } |
186 | 0 | |
187 | 0 | nsDisplayListCollection set(aBuilder); |
188 | 0 | BuildDisplayListForInnerTable(aBuilder, set); |
189 | 0 |
|
190 | 0 | nsDisplayListSet captionSet(set, set.BlockBorderBackgrounds()); |
191 | 0 | BuildDisplayListForChild(aBuilder, mCaptionFrames.FirstChild(), captionSet); |
192 | 0 |
|
193 | 0 | // Now we have to sort everything by content order, since the caption |
194 | 0 | // may be somewhere inside the table. |
195 | 0 | // We don't sort BlockBorderBackgrounds and BorderBackgrounds because the |
196 | 0 | // display items in those lists should stay out of content order in order to |
197 | 0 | // follow the rules in https://www.w3.org/TR/CSS21/zindex.html#painting-order |
198 | 0 | // and paint the caption background after all of the rest. |
199 | 0 | set.Floats()->SortByContentOrder(GetContent()); |
200 | 0 | set.Content()->SortByContentOrder(GetContent()); |
201 | 0 | set.PositionedDescendants()->SortByContentOrder(GetContent()); |
202 | 0 | set.Outlines()->SortByContentOrder(GetContent()); |
203 | 0 | set.MoveTo(aLists); |
204 | 0 | } |
205 | | |
206 | | void |
207 | | nsTableWrapperFrame::BuildDisplayListForInnerTable(nsDisplayListBuilder* aBuilder, |
208 | | const nsDisplayListSet& aLists) |
209 | 0 | { |
210 | 0 | // Just paint the regular children, but the children's background is our |
211 | 0 | // true background (there should only be one, the real table) |
212 | 0 | nsIFrame* kid = mFrames.FirstChild(); |
213 | 0 | // The children should be in content order |
214 | 0 | while (kid) { |
215 | 0 | BuildDisplayListForChild(aBuilder, kid, aLists); |
216 | 0 | kid = kid->GetNextSibling(); |
217 | 0 | } |
218 | 0 | } |
219 | | |
220 | | ComputedStyle* |
221 | | nsTableWrapperFrame::GetParentComputedStyle(nsIFrame** aProviderFrame) const |
222 | 0 | { |
223 | 0 | // The table wrapper frame and the (inner) table frame split the style |
224 | 0 | // data by giving the table frame the ComputedStyle associated with |
225 | 0 | // the table content node and creating a ComputedStyle for the wrapper |
226 | 0 | // frame that is a *child* of the table frame's ComputedStyle, |
227 | 0 | // matching the ::-moz-table-wrapper pseudo-element. html.css has a |
228 | 0 | // rule that causes that pseudo-element (and thus the wrapper table) |
229 | 0 | // to inherit *some* style properties from the table frame. The |
230 | 0 | // children of the table inherit directly from the inner table, and |
231 | 0 | // the table wrapper's ComputedStyle is a leaf. |
232 | 0 |
|
233 | 0 | return (*aProviderFrame = InnerTableFrame())->Style(); |
234 | 0 | } |
235 | | |
236 | | // INCREMENTAL REFLOW HELPER FUNCTIONS |
237 | | |
238 | | void |
239 | | nsTableWrapperFrame::InitChildReflowInput(nsPresContext& aPresContext, |
240 | | const ReflowInput& aOuterRI, |
241 | | ReflowInput& aReflowInput) |
242 | 0 | { |
243 | 0 | nsMargin collapseBorder; |
244 | 0 | nsMargin collapsePadding(0,0,0,0); |
245 | 0 | nsMargin* pCollapseBorder = nullptr; |
246 | 0 | nsMargin* pCollapsePadding = nullptr; |
247 | 0 | Maybe<LogicalSize> cbSize; |
248 | 0 | if (aReflowInput.mFrame == InnerTableFrame()) { |
249 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
250 | 0 | if (InnerTableFrame()->IsBorderCollapse()) { |
251 | 0 | LogicalMargin border = InnerTableFrame()->GetIncludedOuterBCBorder(wm); |
252 | 0 | collapseBorder = border.GetPhysicalMargin(wm); |
253 | 0 | pCollapseBorder = &collapseBorder; |
254 | 0 | pCollapsePadding = &collapsePadding; |
255 | 0 | } |
256 | 0 | // Propagate our stored CB size if present, minus any margins. |
257 | 0 | if (!HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) { |
258 | 0 | LogicalSize* cb = GetProperty(GridItemCBSizeProperty()); |
259 | 0 | if (cb) { |
260 | 0 | cbSize.emplace(*cb); |
261 | 0 | *cbSize -= aReflowInput.ComputedLogicalMargin().Size(wm); |
262 | 0 | } |
263 | 0 | } |
264 | 0 | if (!cbSize) { |
265 | 0 | // For inner table frames, the containing block is the same as for |
266 | 0 | // the outer table frame. |
267 | 0 | cbSize.emplace(aOuterRI.mContainingBlockSize); |
268 | 0 | } |
269 | 0 | } |
270 | 0 | aReflowInput.Init(&aPresContext, cbSize.ptrOr(nullptr), pCollapseBorder, |
271 | 0 | pCollapsePadding); |
272 | 0 | } |
273 | | |
274 | | // get the margin and padding data. ReflowInput doesn't handle the |
275 | | // case of auto margins |
276 | | void |
277 | | nsTableWrapperFrame::GetChildMargin(nsPresContext* aPresContext, |
278 | | const ReflowInput& aOuterRI, |
279 | | nsIFrame* aChildFrame, |
280 | | nscoord aAvailISize, |
281 | | LogicalMargin& aMargin) |
282 | 0 | { |
283 | 0 | NS_ASSERTION(!aChildFrame->IsTableCaption(), |
284 | 0 | "didn't expect caption frame; writing-mode may be wrong!"); |
285 | 0 |
|
286 | 0 | // construct a reflow state to compute margin and padding. Auto margins |
287 | 0 | // will not be computed at this time. |
288 | 0 |
|
289 | 0 | // create and init the child reflow state |
290 | 0 | // XXX We really shouldn't construct a reflow state to do this. |
291 | 0 | WritingMode wm = aOuterRI.GetWritingMode(); |
292 | 0 | LogicalSize availSize(wm, aAvailISize, aOuterRI.AvailableSize(wm).BSize(wm)); |
293 | 0 | ReflowInput childRI(aPresContext, aOuterRI, aChildFrame, availSize, |
294 | 0 | nullptr, ReflowInput::CALLER_WILL_INIT); |
295 | 0 | InitChildReflowInput(*aPresContext, aOuterRI, childRI); |
296 | 0 |
|
297 | 0 | aMargin = childRI.ComputedLogicalMargin(); |
298 | 0 | } |
299 | | |
300 | | static nsSize |
301 | | GetContainingBlockSize(const ReflowInput& aOuterRI) |
302 | 0 | { |
303 | 0 | nsSize size(0,0); |
304 | 0 | const ReflowInput* containRS = aOuterRI.mCBReflowInput; |
305 | 0 |
|
306 | 0 | if (containRS) { |
307 | 0 | size.width = containRS->ComputedWidth(); |
308 | 0 | if (NS_UNCONSTRAINEDSIZE == size.width) { |
309 | 0 | size.width = 0; |
310 | 0 | } |
311 | 0 | size.height = containRS->ComputedHeight(); |
312 | 0 | if (NS_UNCONSTRAINEDSIZE == size.height) { |
313 | 0 | size.height = 0; |
314 | 0 | } |
315 | 0 | } |
316 | 0 | return size; |
317 | 0 | } |
318 | | |
319 | | /* virtual */ nscoord |
320 | | nsTableWrapperFrame::GetMinISize(gfxContext *aRenderingContext) |
321 | 0 | { |
322 | 0 | nscoord iSize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
323 | 0 | InnerTableFrame(), nsLayoutUtils::MIN_ISIZE); |
324 | 0 | DISPLAY_MIN_INLINE_SIZE(this, iSize); |
325 | 0 | if (mCaptionFrames.NotEmpty()) { |
326 | 0 | nscoord capISize = |
327 | 0 | nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
328 | 0 | mCaptionFrames.FirstChild(), |
329 | 0 | nsLayoutUtils::MIN_ISIZE); |
330 | 0 | if (HasSideCaption()) { |
331 | 0 | iSize += capISize; |
332 | 0 | } else { |
333 | 0 | if (capISize > iSize) { |
334 | 0 | iSize = capISize; |
335 | 0 | } |
336 | 0 | } |
337 | 0 | } |
338 | 0 | return iSize; |
339 | 0 | } |
340 | | |
341 | | /* virtual */ nscoord |
342 | | nsTableWrapperFrame::GetPrefISize(gfxContext *aRenderingContext) |
343 | 0 | { |
344 | 0 | nscoord maxISize; |
345 | 0 | DISPLAY_PREF_INLINE_SIZE(this, maxISize); |
346 | 0 |
|
347 | 0 | maxISize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
348 | 0 | InnerTableFrame(), nsLayoutUtils::PREF_ISIZE); |
349 | 0 | if (mCaptionFrames.NotEmpty()) { |
350 | 0 | uint8_t captionSide = GetCaptionSide(); |
351 | 0 | switch (captionSide) { |
352 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
353 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
354 | 0 | { |
355 | 0 | nscoord capMin = |
356 | 0 | nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
357 | 0 | mCaptionFrames.FirstChild(), |
358 | 0 | nsLayoutUtils::MIN_ISIZE); |
359 | 0 | maxISize += capMin; |
360 | 0 | } |
361 | 0 | break; |
362 | 0 | default: |
363 | 0 | { |
364 | 0 | nsLayoutUtils::IntrinsicISizeType iwt; |
365 | 0 | if (captionSide == NS_STYLE_CAPTION_SIDE_TOP || |
366 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) { |
367 | 0 | // Don't let the caption's pref isize expand the table's pref |
368 | 0 | // isize. |
369 | 0 | iwt = nsLayoutUtils::MIN_ISIZE; |
370 | 0 | } else { |
371 | 0 | NS_ASSERTION(captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE || |
372 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE, |
373 | 0 | "unexpected caption side"); |
374 | 0 | iwt = nsLayoutUtils::PREF_ISIZE; |
375 | 0 | } |
376 | 0 | nscoord capPref = |
377 | 0 | nsLayoutUtils::IntrinsicForContainer(aRenderingContext, |
378 | 0 | mCaptionFrames.FirstChild(), |
379 | 0 | iwt); |
380 | 0 | maxISize = std::max(maxISize, capPref); |
381 | 0 | } |
382 | 0 | break; |
383 | 0 | } |
384 | 0 | } |
385 | 0 | return maxISize; |
386 | 0 | } |
387 | | |
388 | | nscoord |
389 | | nsTableWrapperFrame::ChildShrinkWrapISize(gfxContext* aRenderingContext, |
390 | | nsIFrame* aChildFrame, |
391 | | WritingMode aWM, |
392 | | LogicalSize aCBSize, |
393 | | nscoord aAvailableISize, |
394 | | nscoord* aMarginResult) const |
395 | 0 | { |
396 | 0 | AutoMaybeDisableFontInflation an(aChildFrame); |
397 | 0 |
|
398 | 0 | // For the caption frame, child's WM may differ from the table's main WM. |
399 | 0 | WritingMode childWM = aChildFrame->GetWritingMode(); |
400 | 0 |
|
401 | 0 | SizeComputationInput offsets(aChildFrame, aRenderingContext, aWM, |
402 | 0 | aCBSize.ISize(aWM)); |
403 | 0 | LogicalSize marginSize = |
404 | 0 | offsets.ComputedLogicalMargin().Size(childWM).ConvertTo(aWM, childWM); |
405 | 0 | LogicalSize paddingSize = |
406 | 0 | offsets.ComputedLogicalPadding().Size(childWM).ConvertTo(aWM, childWM); |
407 | 0 | LogicalSize bpSize = |
408 | 0 | offsets.ComputedLogicalBorderPadding().Size(childWM).ConvertTo(aWM, childWM); |
409 | 0 |
|
410 | 0 | // Shrink-wrap aChildFrame by default, except if we're a stretched grid item. |
411 | 0 | auto flags = ComputeSizeFlags::eShrinkWrap; |
412 | 0 | auto parent = GetParent(); |
413 | 0 | bool isGridItem = parent && parent->IsGridContainerFrame() && |
414 | 0 | !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW); |
415 | 0 | if (MOZ_UNLIKELY(isGridItem) && |
416 | 0 | !StyleMargin()->HasInlineAxisAuto(aWM)) { |
417 | 0 | auto inlineAxisAlignment = aWM.IsOrthogonalTo(parent->GetWritingMode()) ? |
418 | 0 | StylePosition()->UsedAlignSelf(parent->Style()) : |
419 | 0 | StylePosition()->UsedJustifySelf(parent->Style()); |
420 | 0 | if (inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL || |
421 | 0 | inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH) { |
422 | 0 | flags = nsIFrame::ComputeSizeFlags::eDefault; |
423 | 0 | } |
424 | 0 | } |
425 | 0 |
|
426 | 0 | LogicalSize size = |
427 | 0 | aChildFrame->ComputeSize(aRenderingContext, aWM, aCBSize, aAvailableISize, |
428 | 0 | marginSize, bpSize - paddingSize, paddingSize, |
429 | 0 | flags); |
430 | 0 | if (aMarginResult) { |
431 | 0 | *aMarginResult = offsets.ComputedLogicalMargin().IStartEnd(aWM); |
432 | 0 | } |
433 | 0 | return size.ISize(aWM) + marginSize.ISize(aWM) + bpSize.ISize(aWM); |
434 | 0 | } |
435 | | |
436 | | /* virtual */ |
437 | | LogicalSize |
438 | | nsTableWrapperFrame::ComputeAutoSize(gfxContext* aRenderingContext, |
439 | | WritingMode aWM, |
440 | | const LogicalSize& aCBSize, |
441 | | nscoord aAvailableISize, |
442 | | const LogicalSize& aMargin, |
443 | | const LogicalSize& aBorder, |
444 | | const LogicalSize& aPadding, |
445 | | ComputeSizeFlags aFlags) |
446 | 0 | { |
447 | 0 | nscoord kidAvailableISize = aAvailableISize - aMargin.ISize(aWM); |
448 | 0 | NS_ASSERTION(aBorder.IsAllZero() && aPadding.IsAllZero(), |
449 | 0 | "Table wrapper frames cannot have borders or paddings"); |
450 | 0 |
|
451 | 0 | // When we're shrink-wrapping, our auto size needs to wrap around the |
452 | 0 | // actual size of the table, which (if it is specified as a percent) |
453 | 0 | // could be something that is not reflected in our GetMinISize and |
454 | 0 | // GetPrefISize. See bug 349457 for an example. |
455 | 0 |
|
456 | 0 | // Match the availableISize logic in Reflow. |
457 | 0 | uint8_t captionSide = GetCaptionSide(); |
458 | 0 | nscoord inlineSize; |
459 | 0 | if (captionSide == NO_SIDE) { |
460 | 0 | inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM, |
461 | 0 | aCBSize, kidAvailableISize); |
462 | 0 | } else if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT || |
463 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) { |
464 | 0 | nscoord capISize = ChildShrinkWrapISize(aRenderingContext, |
465 | 0 | mCaptionFrames.FirstChild(), aWM, |
466 | 0 | aCBSize, kidAvailableISize); |
467 | 0 | inlineSize = capISize + ChildShrinkWrapISize(aRenderingContext, |
468 | 0 | InnerTableFrame(), aWM, |
469 | 0 | aCBSize, |
470 | 0 | kidAvailableISize - capISize); |
471 | 0 | } else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP || |
472 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) { |
473 | 0 | nscoord margin; |
474 | 0 | inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM, |
475 | 0 | aCBSize, kidAvailableISize, &margin); |
476 | 0 | nscoord capISize = ChildShrinkWrapISize(aRenderingContext, |
477 | 0 | mCaptionFrames.FirstChild(), aWM, |
478 | 0 | aCBSize, inlineSize - margin); |
479 | 0 | if (capISize > inlineSize) { |
480 | 0 | inlineSize = capISize; |
481 | 0 | } |
482 | 0 | } else { |
483 | 0 | NS_ASSERTION(captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE || |
484 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE, |
485 | 0 | "unexpected caption-side"); |
486 | 0 | inlineSize = ChildShrinkWrapISize(aRenderingContext, InnerTableFrame(), aWM, |
487 | 0 | aCBSize, kidAvailableISize); |
488 | 0 | nscoord capISize = ChildShrinkWrapISize(aRenderingContext, |
489 | 0 | mCaptionFrames.FirstChild(), aWM, |
490 | 0 | aCBSize, kidAvailableISize); |
491 | 0 | if (capISize > inlineSize) { |
492 | 0 | inlineSize = capISize; |
493 | 0 | } |
494 | 0 | } |
495 | 0 |
|
496 | 0 | return LogicalSize(aWM, inlineSize, NS_UNCONSTRAINEDSIZE); |
497 | 0 | } |
498 | | |
499 | | uint8_t |
500 | | nsTableWrapperFrame::GetCaptionSide() |
501 | 0 | { |
502 | 0 | if (mCaptionFrames.NotEmpty()) { |
503 | 0 | return mCaptionFrames.FirstChild()->StyleTableBorder()->mCaptionSide; |
504 | 0 | } |
505 | 0 | else { |
506 | 0 | return NO_SIDE; // no caption |
507 | 0 | } |
508 | 0 | } |
509 | | |
510 | | uint8_t |
511 | | nsTableWrapperFrame::GetCaptionVerticalAlign() |
512 | 0 | { |
513 | 0 | const nsStyleCoord& va = |
514 | 0 | mCaptionFrames.FirstChild()->StyleDisplay()->mVerticalAlign; |
515 | 0 |
|
516 | 0 | return (va.GetUnit() == eStyleUnit_Enumerated) |
517 | 0 | ? va.GetIntValue() |
518 | 0 | : NS_STYLE_VERTICAL_ALIGN_TOP; |
519 | 0 | } |
520 | | |
521 | | void |
522 | | nsTableWrapperFrame::SetDesiredSize(uint8_t aCaptionSide, |
523 | | const LogicalSize& aInnerSize, |
524 | | const LogicalSize& aCaptionSize, |
525 | | const LogicalMargin& aInnerMargin, |
526 | | const LogicalMargin& aCaptionMargin, |
527 | | nscoord& aISize, |
528 | | nscoord& aBSize, |
529 | | WritingMode aWM) |
530 | 0 | { |
531 | 0 | aISize = aBSize = 0; |
532 | 0 |
|
533 | 0 | // compute the overall inline-size |
534 | 0 | switch (aCaptionSide) { |
535 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
536 | 0 | aISize = |
537 | 0 | std::max(aInnerMargin.LineLeft(aWM), |
538 | 0 | aCaptionMargin.IStartEnd(aWM) + aCaptionSize.ISize(aWM)) + |
539 | 0 | aInnerSize.ISize(aWM) + aInnerMargin.LineRight(aWM); |
540 | 0 | break; |
541 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
542 | 0 | aISize = |
543 | 0 | std::max(aInnerMargin.LineRight(aWM), |
544 | 0 | aCaptionMargin.IStartEnd(aWM) + aCaptionSize.ISize(aWM)) + |
545 | 0 | aInnerSize.ISize(aWM) + aInnerMargin.LineLeft(aWM); |
546 | 0 | break; |
547 | 0 | default: |
548 | 0 | aISize = |
549 | 0 | std::max(aInnerMargin.IStartEnd(aWM) + aInnerSize.ISize(aWM), |
550 | 0 | aCaptionMargin.IStartEnd(aWM) + aCaptionSize.ISize(aWM)); |
551 | 0 | break; |
552 | 0 | } |
553 | 0 | |
554 | 0 | // compute the overall block-size |
555 | 0 | switch (aCaptionSide) { |
556 | 0 | case NS_STYLE_CAPTION_SIDE_TOP: |
557 | 0 | case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: |
558 | 0 | aBSize = aInnerSize.BSize(aWM) + aInnerMargin.BEnd(aWM); |
559 | 0 | aBSize += |
560 | 0 | std::max(aInnerMargin.BStart(aWM), |
561 | 0 | aCaptionSize.BSize(aWM) + aCaptionMargin.BStartEnd(aWM)); |
562 | 0 | break; |
563 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM: |
564 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: |
565 | 0 | aBSize = aInnerSize.BSize(aWM) + aInnerMargin.BStart(aWM); |
566 | 0 | aBSize += |
567 | 0 | std::max(aInnerMargin.BEnd(aWM), |
568 | 0 | aCaptionSize.BSize(aWM) + aCaptionMargin.BStartEnd(aWM)); |
569 | 0 | break; |
570 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
571 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
572 | 0 | aBSize = aInnerMargin.BStart(aWM); |
573 | 0 | aBSize += |
574 | 0 | std::max(aInnerSize.BSize(aWM) + aInnerMargin.BEnd(aWM), |
575 | 0 | aCaptionSize.BSize(aWM) + aCaptionMargin.BEnd(aWM)); |
576 | 0 | break; |
577 | 0 | default: |
578 | 0 | NS_ASSERTION(aCaptionSide == NO_SIDE, "unexpected caption side"); |
579 | 0 | aBSize = aInnerSize.BSize(aWM) + aInnerMargin.BStartEnd(aWM); |
580 | 0 | break; |
581 | 0 | } |
582 | 0 |
|
583 | 0 | // negative sizes can upset overflow-area code |
584 | 0 | aISize = std::max(aISize, 0); |
585 | 0 | aBSize = std::max(aBSize, 0); |
586 | 0 | } |
587 | | |
588 | | nsresult |
589 | | nsTableWrapperFrame::GetCaptionOrigin(uint32_t aCaptionSide, |
590 | | const LogicalSize& aContainBlockSize, |
591 | | const LogicalSize& aInnerSize, |
592 | | const LogicalMargin& aInnerMargin, |
593 | | const LogicalSize& aCaptionSize, |
594 | | LogicalMargin& aCaptionMargin, |
595 | | LogicalPoint& aOrigin, |
596 | | WritingMode aWM) |
597 | 0 | { |
598 | 0 | aOrigin.I(aWM) = aOrigin.B(aWM) = 0; |
599 | 0 | if ((NS_UNCONSTRAINEDSIZE == aInnerSize.ISize(aWM)) || |
600 | 0 | (NS_UNCONSTRAINEDSIZE == aInnerSize.BSize(aWM)) || |
601 | 0 | (NS_UNCONSTRAINEDSIZE == aCaptionSize.ISize(aWM)) || |
602 | 0 | (NS_UNCONSTRAINEDSIZE == aCaptionSize.BSize(aWM))) { |
603 | 0 | return NS_OK; |
604 | 0 | } |
605 | 0 | if (mCaptionFrames.IsEmpty()) { |
606 | 0 | return NS_OK; |
607 | 0 | } |
608 | 0 | |
609 | 0 | NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.IStart(aWM) && |
610 | 0 | NS_AUTOMARGIN != aCaptionMargin.BStart(aWM) && |
611 | 0 | NS_AUTOMARGIN != aCaptionMargin.BEnd(aWM), |
612 | 0 | "The computed caption margin is auto?"); |
613 | 0 |
|
614 | 0 | // inline-dir computation |
615 | 0 | switch (aCaptionSide) { |
616 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM: |
617 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: |
618 | 0 | aOrigin.I(aWM) = aCaptionMargin.IStart(aWM); |
619 | 0 | if (aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) { |
620 | 0 | // We placed the caption using only the table's isize as available |
621 | 0 | // isize, and we should position it this way as well. |
622 | 0 | aOrigin.I(aWM) += aInnerMargin.IStart(aWM); |
623 | 0 | } |
624 | 0 | break; |
625 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
626 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
627 | 0 | aOrigin.I(aWM) = aCaptionMargin.IStart(aWM); |
628 | 0 | if (aWM.IsBidiLTR() == (aCaptionSide == NS_STYLE_CAPTION_SIDE_RIGHT)) { |
629 | 0 | aOrigin.I(aWM) += aInnerMargin.IStart(aWM) + aInnerSize.ISize(aWM); |
630 | 0 | } |
631 | 0 | break; |
632 | 0 | default: // block-start |
633 | 0 | NS_ASSERTION(aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP || |
634 | 0 | aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE, |
635 | 0 | "unexpected caption side"); |
636 | 0 | aOrigin.I(aWM) = aCaptionMargin.IStart(aWM); |
637 | 0 | if (aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP) { |
638 | 0 | // We placed the caption using only the table's isize as available |
639 | 0 | // isize, and we should position it this way as well. |
640 | 0 | aOrigin.I(aWM) += aInnerMargin.IStart(aWM); |
641 | 0 | } |
642 | 0 | break; |
643 | 0 | } |
644 | 0 | // block-dir computation |
645 | 0 | switch (aCaptionSide) { |
646 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
647 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
648 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM); |
649 | 0 | switch (GetCaptionVerticalAlign()) { |
650 | 0 | case NS_STYLE_VERTICAL_ALIGN_MIDDLE: |
651 | 0 | aOrigin.B(aWM) = std::max(0, aInnerMargin.BStart(aWM) + |
652 | 0 | ((aInnerSize.BSize(aWM) - |
653 | 0 | aCaptionSize.BSize(aWM)) / 2)); |
654 | 0 | break; |
655 | 0 | case NS_STYLE_VERTICAL_ALIGN_BOTTOM: |
656 | 0 | aOrigin.B(aWM) = std::max(0, aInnerMargin.BStart(aWM) + |
657 | 0 | aInnerSize.BSize(aWM) - |
658 | 0 | aCaptionSize.BSize(aWM)); |
659 | 0 | break; |
660 | 0 | default: |
661 | 0 | break; |
662 | 0 | } |
663 | 0 | break; |
664 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: |
665 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM: |
666 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM) + aInnerSize.BSize(aWM) + |
667 | 0 | aCaptionMargin.BStart(aWM); |
668 | 0 | break; |
669 | 0 | case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: |
670 | 0 | case NS_STYLE_CAPTION_SIDE_TOP: |
671 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM) + aCaptionMargin.BStart(aWM); |
672 | 0 | break; |
673 | 0 | default: |
674 | 0 | MOZ_ASSERT_UNREACHABLE("Unknown caption alignment type"); |
675 | 0 | break; |
676 | 0 | } |
677 | 0 | return NS_OK; |
678 | 0 | } |
679 | | |
680 | | nsresult |
681 | | nsTableWrapperFrame::GetInnerOrigin(uint32_t aCaptionSide, |
682 | | const LogicalSize& aContainBlockSize, |
683 | | const LogicalSize& aCaptionSize, |
684 | | const LogicalMargin& aCaptionMargin, |
685 | | const LogicalSize& aInnerSize, |
686 | | LogicalMargin& aInnerMargin, |
687 | | LogicalPoint& aOrigin, |
688 | | WritingMode aWM) |
689 | 0 | { |
690 | 0 | NS_ASSERTION(NS_AUTOMARGIN != aCaptionMargin.IStart(aWM) && |
691 | 0 | NS_AUTOMARGIN != aCaptionMargin.IEnd(aWM), |
692 | 0 | "The computed caption margin is auto?"); |
693 | 0 | NS_ASSERTION(NS_AUTOMARGIN != aInnerMargin.IStart(aWM) && |
694 | 0 | NS_AUTOMARGIN != aInnerMargin.IEnd(aWM) && |
695 | 0 | NS_AUTOMARGIN != aInnerMargin.BStart(aWM) && |
696 | 0 | NS_AUTOMARGIN != aInnerMargin.BEnd(aWM), |
697 | 0 | "The computed inner margin is auto?"); |
698 | 0 |
|
699 | 0 | aOrigin.I(aWM) = aOrigin.B(aWM) = 0; |
700 | 0 | if ((NS_UNCONSTRAINEDSIZE == aInnerSize.ISize(aWM)) || |
701 | 0 | (NS_UNCONSTRAINEDSIZE == aInnerSize.BSize(aWM)) || |
702 | 0 | (NS_UNCONSTRAINEDSIZE == aCaptionSize.ISize(aWM)) || |
703 | 0 | (NS_UNCONSTRAINEDSIZE == aCaptionSize.BSize(aWM))) { |
704 | 0 | return NS_OK; |
705 | 0 | } |
706 | 0 | |
707 | 0 | nscoord minCapISize = |
708 | 0 | aCaptionSize.ISize(aWM) + aCaptionMargin.IStartEnd(aWM); |
709 | 0 |
|
710 | 0 | // inline-dir computation |
711 | 0 | switch (aCaptionSide) { |
712 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
713 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
714 | 0 | if (aWM.IsBidiLTR() == (aCaptionSide == NS_STYLE_CAPTION_SIDE_LEFT)) { |
715 | 0 | if (aInnerMargin.IStart(aWM) < minCapISize) { |
716 | 0 | // shift the inner table to get some place for the caption |
717 | 0 | aInnerMargin.IEnd(aWM) += aInnerMargin.IStart(aWM) - minCapISize; |
718 | 0 | aInnerMargin.IEnd(aWM) = std::max(0, aInnerMargin.IEnd(aWM)); |
719 | 0 | aInnerMargin.IStart(aWM) = minCapISize; |
720 | 0 | } |
721 | 0 | } |
722 | 0 | aOrigin.I(aWM) = aInnerMargin.IStart(aWM); |
723 | 0 | break; |
724 | 0 | default: |
725 | 0 | NS_ASSERTION(aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP || |
726 | 0 | aCaptionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE || |
727 | 0 | aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM || |
728 | 0 | aCaptionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE || |
729 | 0 | aCaptionSide == NO_SIDE, |
730 | 0 | "unexpected caption side"); |
731 | 0 | aOrigin.I(aWM) = aInnerMargin.IStart(aWM); |
732 | 0 | break; |
733 | 0 | } |
734 | 0 |
|
735 | 0 | // block-dir computation |
736 | 0 | switch (aCaptionSide) { |
737 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM: |
738 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: |
739 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM); |
740 | 0 | break; |
741 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
742 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
743 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM); |
744 | 0 | switch (GetCaptionVerticalAlign()) { |
745 | 0 | case NS_STYLE_VERTICAL_ALIGN_MIDDLE: |
746 | 0 | aOrigin.B(aWM) = |
747 | 0 | std::max(aInnerMargin.BStart(aWM), |
748 | 0 | (aCaptionSize.BSize(aWM) - aInnerSize.BSize(aWM)) / 2); |
749 | 0 | break; |
750 | 0 | case NS_STYLE_VERTICAL_ALIGN_BOTTOM: |
751 | 0 | aOrigin.B(aWM) = |
752 | 0 | std::max(aInnerMargin.BStart(aWM), |
753 | 0 | aCaptionSize.BSize(aWM) - aInnerSize.BSize(aWM)); |
754 | 0 | break; |
755 | 0 | default: |
756 | 0 | break; |
757 | 0 | } |
758 | 0 | break; |
759 | 0 | case NO_SIDE: |
760 | 0 | case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: |
761 | 0 | case NS_STYLE_CAPTION_SIDE_TOP: |
762 | 0 | aOrigin.B(aWM) = aInnerMargin.BStart(aWM) + aCaptionSize.BSize(aWM) + |
763 | 0 | aCaptionMargin.BStartEnd(aWM); |
764 | 0 | break; |
765 | 0 | default: |
766 | 0 | MOZ_ASSERT_UNREACHABLE("Unknown caption alignment type"); |
767 | 0 | break; |
768 | 0 | } |
769 | 0 | return NS_OK; |
770 | 0 | } |
771 | | |
772 | | void |
773 | | nsTableWrapperFrame::OuterBeginReflowChild(nsPresContext* aPresContext, |
774 | | nsIFrame* aChildFrame, |
775 | | const ReflowInput& aOuterRI, |
776 | | Maybe<ReflowInput>& aChildRI, |
777 | | nscoord aAvailISize) |
778 | 0 | { |
779 | 0 | // work around pixel rounding errors, round down to ensure we don't exceed the avail height in |
780 | 0 | WritingMode wm = aChildFrame->GetWritingMode(); |
781 | 0 | LogicalSize outerSize = aOuterRI.AvailableSize(wm); |
782 | 0 | nscoord availBSize = outerSize.BSize(wm); |
783 | 0 | if (NS_UNCONSTRAINEDSIZE != availBSize) { |
784 | 0 | if (mCaptionFrames.FirstChild() == aChildFrame) { |
785 | 0 | availBSize = NS_UNCONSTRAINEDSIZE; |
786 | 0 | } else { |
787 | 0 | LogicalMargin margin(wm); |
788 | 0 | GetChildMargin(aPresContext, aOuterRI, aChildFrame, |
789 | 0 | outerSize.ISize(wm), margin); |
790 | 0 |
|
791 | 0 | NS_ASSERTION(NS_UNCONSTRAINEDSIZE != margin.BStart(wm), |
792 | 0 | "No unconstrainedsize arithmetic, please"); |
793 | 0 | availBSize -= margin.BStart(wm); |
794 | 0 |
|
795 | 0 | NS_ASSERTION(NS_UNCONSTRAINEDSIZE != margin.BEnd(wm), |
796 | 0 | "No unconstrainedsize arithmetic, please"); |
797 | 0 | availBSize -= margin.BEnd(wm); |
798 | 0 | } |
799 | 0 | } |
800 | 0 | LogicalSize availSize(wm, aAvailISize, availBSize); |
801 | 0 | // create and init the child reflow state, using passed-in Maybe<>, |
802 | 0 | // so that caller can use it after we return. |
803 | 0 | aChildRI.emplace(aPresContext, aOuterRI, aChildFrame, availSize, |
804 | 0 | nullptr, ReflowInput::CALLER_WILL_INIT); |
805 | 0 | InitChildReflowInput(*aPresContext, aOuterRI, *aChildRI); |
806 | 0 |
|
807 | 0 | // see if we need to reset top-of-page due to a caption |
808 | 0 | if (aChildRI->mFlags.mIsTopOfPage && |
809 | 0 | mCaptionFrames.FirstChild() == aChildFrame) { |
810 | 0 | uint8_t captionSide = GetCaptionSide(); |
811 | 0 | if (captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM || |
812 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE) { |
813 | 0 | aChildRI->mFlags.mIsTopOfPage = false; |
814 | 0 | } |
815 | 0 | } |
816 | 0 | } |
817 | | |
818 | | void |
819 | | nsTableWrapperFrame::OuterDoReflowChild(nsPresContext* aPresContext, |
820 | | nsIFrame* aChildFrame, |
821 | | const ReflowInput& aChildRI, |
822 | | ReflowOutput& aMetrics, |
823 | | nsReflowStatus& aStatus) |
824 | 0 | { |
825 | 0 | // Using zero as containerSize here because we want consistency between |
826 | 0 | // the GetLogicalPosition and ReflowChild calls, to avoid unnecessarily |
827 | 0 | // changing the frame's coordinates; but we don't yet know its final |
828 | 0 | // position anyway so the actual value is unimportant. |
829 | 0 | const nsSize zeroCSize; |
830 | 0 | WritingMode wm = aChildRI.GetWritingMode(); |
831 | 0 |
|
832 | 0 | // Use the current position as a best guess for placement. |
833 | 0 | LogicalPoint childPt = aChildFrame->GetLogicalPosition(wm, zeroCSize); |
834 | 0 | uint32_t flags = NS_FRAME_NO_MOVE_FRAME; |
835 | 0 |
|
836 | 0 | // We don't want to delete our next-in-flow's child if it's an inner table |
837 | 0 | // frame, because table wrapper frames always assume that their inner table |
838 | 0 | // frames don't go away. If a table wrapper frame is removed because it is |
839 | 0 | // a next-in-flow of an already complete table wrapper frame, then it will |
840 | 0 | // take care of removing it's inner table frame. |
841 | 0 | if (aChildFrame == InnerTableFrame()) { |
842 | 0 | flags |= NS_FRAME_NO_DELETE_NEXT_IN_FLOW_CHILD; |
843 | 0 | } |
844 | 0 |
|
845 | 0 | ReflowChild(aChildFrame, aPresContext, aMetrics, aChildRI, |
846 | 0 | wm, childPt, zeroCSize, flags, aStatus); |
847 | 0 | } |
848 | | |
849 | | void |
850 | | nsTableWrapperFrame::UpdateOverflowAreas(ReflowOutput& aMet) |
851 | 0 | { |
852 | 0 | aMet.SetOverflowAreasToDesiredBounds(); |
853 | 0 | ConsiderChildOverflow(aMet.mOverflowAreas, InnerTableFrame()); |
854 | 0 | if (mCaptionFrames.NotEmpty()) { |
855 | 0 | ConsiderChildOverflow(aMet.mOverflowAreas, mCaptionFrames.FirstChild()); |
856 | 0 | } |
857 | 0 | } |
858 | | |
859 | | void |
860 | | nsTableWrapperFrame::Reflow(nsPresContext* aPresContext, |
861 | | ReflowOutput& aDesiredSize, |
862 | | const ReflowInput& aOuterRI, |
863 | | nsReflowStatus& aStatus) |
864 | 0 | { |
865 | 0 | MarkInReflow(); |
866 | 0 | DO_GLOBAL_REFLOW_COUNT("nsTableWrapperFrame"); |
867 | 0 | DISPLAY_REFLOW(aPresContext, this, aOuterRI, aDesiredSize, aStatus); |
868 | 0 | MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!"); |
869 | 0 |
|
870 | 0 | // Initialize out parameters |
871 | 0 | aDesiredSize.ClearSize(); |
872 | 0 |
|
873 | 0 | if (!HasAnyStateBits(NS_FRAME_FIRST_REFLOW)) { |
874 | 0 | // Set up our kids. They're already present, on an overflow list, |
875 | 0 | // or there are none so we'll create them now |
876 | 0 | MoveOverflowToChildList(); |
877 | 0 | } |
878 | 0 |
|
879 | 0 | Maybe<ReflowInput> captionRI; |
880 | 0 | Maybe<ReflowInput> innerRI; |
881 | 0 |
|
882 | 0 | nsRect origCaptionRect; |
883 | 0 | nsRect origCaptionVisualOverflow; |
884 | 0 | bool captionFirstReflow = false; |
885 | 0 | if (mCaptionFrames.NotEmpty()) { |
886 | 0 | origCaptionRect = mCaptionFrames.FirstChild()->GetRect(); |
887 | 0 | origCaptionVisualOverflow = |
888 | 0 | mCaptionFrames.FirstChild()->GetVisualOverflowRect(); |
889 | 0 | captionFirstReflow = |
890 | 0 | mCaptionFrames.FirstChild()->HasAnyStateBits(NS_FRAME_FIRST_REFLOW); |
891 | 0 | } |
892 | 0 |
|
893 | 0 | // ComputeAutoSize has to match this logic. |
894 | 0 | WritingMode wm = aOuterRI.GetWritingMode(); |
895 | 0 | uint8_t captionSide = GetCaptionSide(); |
896 | 0 | WritingMode captionWM = wm; // will be changed below if necessary |
897 | 0 |
|
898 | 0 | if (captionSide == NO_SIDE) { |
899 | 0 | // We don't have a caption. |
900 | 0 | OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, |
901 | 0 | innerRI, aOuterRI.ComputedSize(wm).ISize(wm)); |
902 | 0 | } else if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT || |
903 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) { |
904 | 0 | // ComputeAutoSize takes care of making side captions small. Compute |
905 | 0 | // the caption's size first, and tell the table to fit in what's left. |
906 | 0 | OuterBeginReflowChild(aPresContext, mCaptionFrames.FirstChild(), aOuterRI, |
907 | 0 | captionRI, aOuterRI.ComputedSize(wm).ISize(wm)); |
908 | 0 | captionWM = captionRI->GetWritingMode(); |
909 | 0 | nscoord innerAvailISize = aOuterRI.ComputedSize(wm).ISize(wm) - |
910 | 0 | captionRI->ComputedSizeWithMarginBorderPadding(wm).ISize(wm); |
911 | 0 | OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, |
912 | 0 | innerRI, innerAvailISize); |
913 | 0 | } else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP || |
914 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) { |
915 | 0 | // Compute the table's size first, and then prevent the caption from |
916 | 0 | // being larger in the inline dir unless it has to be. |
917 | 0 | // |
918 | 0 | // Note that CSS 2.1 (but not 2.0) says: |
919 | 0 | // The width of the anonymous box is the border-edge width of the |
920 | 0 | // table box inside it |
921 | 0 | // We don't actually make our anonymous box that isize (if we did, |
922 | 0 | // it would break 'auto' margins), but this effectively does that. |
923 | 0 | OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, |
924 | 0 | innerRI, aOuterRI.ComputedSize(wm).ISize(wm)); |
925 | 0 | // It's good that CSS 2.1 says not to include margins, since we |
926 | 0 | // can't, since they already been converted so they exactly |
927 | 0 | // fill the available isize (ignoring the margin on one side if |
928 | 0 | // neither are auto). (We take advantage of that later when we call |
929 | 0 | // GetCaptionOrigin, though.) |
930 | 0 | nscoord innerBorderISize = |
931 | 0 | innerRI->ComputedSizeWithBorderPadding(wm).ISize(wm); |
932 | 0 | OuterBeginReflowChild(aPresContext, mCaptionFrames.FirstChild(), aOuterRI, |
933 | 0 | captionRI, innerBorderISize); |
934 | 0 | captionWM = captionRI->GetWritingMode(); |
935 | 0 | } else { |
936 | 0 | NS_ASSERTION(captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE || |
937 | 0 | captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE, |
938 | 0 | "unexpected caption-side"); |
939 | 0 | // Size the table and the caption independently. |
940 | 0 | captionWM = mCaptionFrames.FirstChild()->GetWritingMode(); |
941 | 0 | OuterBeginReflowChild(aPresContext, mCaptionFrames.FirstChild(), |
942 | 0 | aOuterRI, captionRI, |
943 | 0 | aOuterRI.ComputedSize(captionWM).ISize(captionWM)); |
944 | 0 | OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, |
945 | 0 | innerRI, aOuterRI.ComputedSize(wm).ISize(wm)); |
946 | 0 | } |
947 | 0 |
|
948 | 0 | // First reflow the caption. |
949 | 0 | Maybe<ReflowOutput> captionMet; |
950 | 0 | LogicalSize captionSize(wm); |
951 | 0 | LogicalMargin captionMargin(wm); |
952 | 0 | if (mCaptionFrames.NotEmpty()) { |
953 | 0 | captionMet.emplace(wm); |
954 | 0 | nsReflowStatus capStatus; // don't let the caption cause incomplete |
955 | 0 | OuterDoReflowChild(aPresContext, mCaptionFrames.FirstChild(), |
956 | 0 | *captionRI, *captionMet, capStatus); |
957 | 0 | captionSize.ISize(wm) = captionMet->ISize(wm); |
958 | 0 | captionSize.BSize(wm) = captionMet->BSize(wm); |
959 | 0 | captionMargin = |
960 | 0 | captionRI->ComputedLogicalMargin().ConvertTo(wm, captionWM); |
961 | 0 | // Now that we know the bsize of the caption, reduce the available bsize |
962 | 0 | // for the table frame if we are bsize constrained and the caption is above |
963 | 0 | // or below the inner table. Also reduce the CB size that we store for |
964 | 0 | // our children in case we're a grid item, by the same amount. |
965 | 0 | LogicalSize* cbSize = GetProperty(GridItemCBSizeProperty()); |
966 | 0 | if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize() || cbSize) { |
967 | 0 | nscoord captionBSize = 0; |
968 | 0 | nscoord captionISize = 0; |
969 | 0 | switch (captionSide) { |
970 | 0 | case NS_STYLE_CAPTION_SIDE_TOP: |
971 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM: |
972 | 0 | case NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE: |
973 | 0 | case NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE: |
974 | 0 | captionBSize = captionSize.BSize(wm) + captionMargin.BStartEnd(wm); |
975 | 0 | break; |
976 | 0 | case NS_STYLE_CAPTION_SIDE_LEFT: |
977 | 0 | case NS_STYLE_CAPTION_SIDE_RIGHT: |
978 | 0 | captionISize = captionSize.ISize(wm) + captionMargin.IStartEnd(wm); |
979 | 0 | break; |
980 | 0 | } |
981 | 0 | if (NS_UNCONSTRAINEDSIZE != aOuterRI.AvailableBSize()) { |
982 | 0 | innerRI->AvailableBSize() = |
983 | 0 | std::max(0, innerRI->AvailableBSize() - captionBSize); |
984 | 0 | } |
985 | 0 | if (cbSize) { |
986 | 0 | // Shrink the CB size by the size reserved for the caption. |
987 | 0 | LogicalSize oldCBSize = *cbSize; |
988 | 0 | cbSize->ISize(wm) = std::max(0, cbSize->ISize(wm) - captionISize); |
989 | 0 | cbSize->BSize(wm) = std::max(0, cbSize->BSize(wm) - captionBSize); |
990 | 0 | if (oldCBSize != *cbSize) { |
991 | 0 | // Reset the inner table's ReflowInput to stretch it to the new size. |
992 | 0 | innerRI.reset(); |
993 | 0 | OuterBeginReflowChild(aPresContext, InnerTableFrame(), aOuterRI, |
994 | 0 | innerRI, aOuterRI.ComputedSize(wm).ISize(wm)); |
995 | 0 | } |
996 | 0 | } |
997 | 0 | } |
998 | 0 | } |
999 | 0 |
|
1000 | 0 | // Then, now that we know how much to reduce the isize of the inner |
1001 | 0 | // table to account for side captions, reflow the inner table. |
1002 | 0 | ReflowOutput innerMet(innerRI->GetWritingMode()); |
1003 | 0 | OuterDoReflowChild(aPresContext, InnerTableFrame(), *innerRI, |
1004 | 0 | innerMet, aStatus); |
1005 | 0 | LogicalSize innerSize(wm, innerMet.ISize(wm), innerMet.BSize(wm)); |
1006 | 0 | LogicalMargin innerMargin = innerRI->ComputedLogicalMargin(); |
1007 | 0 |
|
1008 | 0 | LogicalSize containSize(wm, GetContainingBlockSize(aOuterRI)); |
1009 | 0 |
|
1010 | 0 | // Now that we've reflowed both we can place them. |
1011 | 0 | // XXXldb Most of the input variables here are now uninitialized! |
1012 | 0 |
|
1013 | 0 | // XXX Need to recompute inner table's auto margins for the case of side |
1014 | 0 | // captions. (Caption's are broken too, but that should be fixed earlier.) |
1015 | 0 |
|
1016 | 0 | // Compute the desiredSize so that we can use it as the containerSize |
1017 | 0 | // for the FinishReflowChild calls below. |
1018 | 0 | LogicalSize desiredSize(wm); |
1019 | 0 | SetDesiredSize(captionSide, innerSize, captionSize, |
1020 | 0 | innerMargin, captionMargin, |
1021 | 0 | desiredSize.ISize(wm), desiredSize.BSize(wm), wm); |
1022 | 0 | aDesiredSize.SetSize(wm, desiredSize); |
1023 | 0 | nsSize containerSize = aDesiredSize.PhysicalSize(); |
1024 | 0 | // XXX It's possible for this to be NS_UNCONSTRAINEDSIZE, which will result |
1025 | 0 | // in assertions from FinishReflowChild. |
1026 | 0 |
|
1027 | 0 | if (mCaptionFrames.NotEmpty()) { |
1028 | 0 | LogicalPoint captionOrigin(wm); |
1029 | 0 | GetCaptionOrigin(captionSide, containSize, innerSize, innerMargin, |
1030 | 0 | captionSize, captionMargin, captionOrigin, wm); |
1031 | 0 | FinishReflowChild(mCaptionFrames.FirstChild(), aPresContext, *captionMet, |
1032 | 0 | captionRI.ptr(), wm, captionOrigin, containerSize, 0); |
1033 | 0 | captionRI.reset(); |
1034 | 0 | } |
1035 | 0 | // XXX If the bsize is constrained then we need to check whether |
1036 | 0 | // everything still fits... |
1037 | 0 |
|
1038 | 0 | LogicalPoint innerOrigin(wm); |
1039 | 0 | GetInnerOrigin(captionSide, containSize, captionSize, captionMargin, |
1040 | 0 | innerSize, innerMargin, innerOrigin, wm); |
1041 | 0 | FinishReflowChild(InnerTableFrame(), aPresContext, innerMet, innerRI.ptr(), |
1042 | 0 | wm, innerOrigin, containerSize, 0); |
1043 | 0 | innerRI.reset(); |
1044 | 0 |
|
1045 | 0 | if (mCaptionFrames.NotEmpty()) { |
1046 | 0 | nsTableFrame::InvalidateTableFrame(mCaptionFrames.FirstChild(), |
1047 | 0 | origCaptionRect, |
1048 | 0 | origCaptionVisualOverflow, |
1049 | 0 | captionFirstReflow); |
1050 | 0 | } |
1051 | 0 |
|
1052 | 0 | UpdateOverflowAreas(aDesiredSize); |
1053 | 0 |
|
1054 | 0 | if (GetPrevInFlow()) { |
1055 | 0 | ReflowOverflowContainerChildren(aPresContext, aOuterRI, |
1056 | 0 | aDesiredSize.mOverflowAreas, 0, |
1057 | 0 | aStatus); |
1058 | 0 | } |
1059 | 0 |
|
1060 | 0 | FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aOuterRI, aStatus); |
1061 | 0 |
|
1062 | 0 | // Return our desired rect |
1063 | 0 |
|
1064 | 0 | NS_FRAME_SET_TRUNCATION(aStatus, aOuterRI, aDesiredSize); |
1065 | 0 | } |
1066 | | |
1067 | | /* ----- global methods ----- */ |
1068 | | |
1069 | | nsIContent* |
1070 | | nsTableWrapperFrame::GetCellAt(uint32_t aRowIdx, uint32_t aColIdx) const |
1071 | 0 | { |
1072 | 0 | nsTableCellMap* cellMap = InnerTableFrame()->GetCellMap(); |
1073 | 0 | if (!cellMap) { |
1074 | 0 | return nullptr; |
1075 | 0 | } |
1076 | 0 | |
1077 | 0 | nsTableCellFrame* cell = cellMap->GetCellInfoAt(aRowIdx, aColIdx); |
1078 | 0 | if (!cell) { |
1079 | 0 | return nullptr; |
1080 | 0 | } |
1081 | 0 | |
1082 | 0 | return cell->GetContent(); |
1083 | 0 | } |
1084 | | |
1085 | | |
1086 | | nsTableWrapperFrame* |
1087 | | NS_NewTableWrapperFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
1088 | 0 | { |
1089 | 0 | return new (aPresShell) nsTableWrapperFrame(aStyle); |
1090 | 0 | } |
1091 | | |
1092 | | NS_IMPL_FRAMEARENA_HELPERS(nsTableWrapperFrame) |
1093 | | |
1094 | | #ifdef DEBUG_FRAME_DUMP |
1095 | | nsresult |
1096 | | nsTableWrapperFrame::GetFrameName(nsAString& aResult) const |
1097 | | { |
1098 | | return MakeFrameName(NS_LITERAL_STRING("TableWrapper"), aResult); |
1099 | | } |
1100 | | #endif |
1101 | | |