/src/mozilla-central/layout/tables/nsTableRowFrame.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 "mozilla/Maybe.h" |
7 | | |
8 | | #include "nsTableRowFrame.h" |
9 | | #include "nsTableRowGroupFrame.h" |
10 | | #include "nsIPresShell.h" |
11 | | #include "nsPresContext.h" |
12 | | #include "mozilla/ComputedStyle.h" |
13 | | #include "nsStyleConsts.h" |
14 | | #include "nsGkAtoms.h" |
15 | | #include "nsIContent.h" |
16 | | #include "nsTableFrame.h" |
17 | | #include "nsTableCellFrame.h" |
18 | | #include "nsCSSRendering.h" |
19 | | #include "nsHTMLParts.h" |
20 | | #include "nsTableColGroupFrame.h" |
21 | | #include "nsTableColFrame.h" |
22 | | #include "nsCOMPtr.h" |
23 | | #include "nsDisplayList.h" |
24 | | #include "nsIFrameInlines.h" |
25 | | #include <algorithm> |
26 | | |
27 | | using namespace mozilla; |
28 | | |
29 | | namespace mozilla { |
30 | | |
31 | | struct TableCellReflowInput : public ReflowInput |
32 | | { |
33 | | TableCellReflowInput(nsPresContext* aPresContext, |
34 | | const ReflowInput& aParentReflowInput, |
35 | | nsIFrame* aFrame, |
36 | | const LogicalSize& aAvailableSpace, |
37 | | uint32_t aFlags = 0) |
38 | | : ReflowInput(aPresContext, aParentReflowInput, aFrame, |
39 | | aAvailableSpace, nullptr, aFlags) |
40 | 0 | { |
41 | 0 | } |
42 | | |
43 | | void FixUp(const LogicalSize& aAvailSpace); |
44 | | }; |
45 | | |
46 | | } // namespace mozilla |
47 | | |
48 | | void TableCellReflowInput::FixUp(const LogicalSize& aAvailSpace) |
49 | 0 | { |
50 | 0 | // fix the mComputed values during a pass 2 reflow since the cell can be a percentage base |
51 | 0 | NS_WARNING_ASSERTION( |
52 | 0 | NS_UNCONSTRAINEDSIZE != aAvailSpace.ISize(mWritingMode), |
53 | 0 | "have unconstrained inline-size; this should only result from very large " |
54 | 0 | "sizes, not attempts at intrinsic inline size calculation"); |
55 | 0 | if (NS_UNCONSTRAINEDSIZE != ComputedISize()) { |
56 | 0 | nscoord computedISize = aAvailSpace.ISize(mWritingMode) - |
57 | 0 | ComputedLogicalBorderPadding().IStartEnd(mWritingMode); |
58 | 0 | computedISize = std::max(0, computedISize); |
59 | 0 | SetComputedISize(computedISize); |
60 | 0 | } |
61 | 0 | if (NS_UNCONSTRAINEDSIZE != ComputedBSize() && |
62 | 0 | NS_UNCONSTRAINEDSIZE != aAvailSpace.BSize(mWritingMode)) { |
63 | 0 | nscoord computedBSize = aAvailSpace.BSize(mWritingMode) - |
64 | 0 | ComputedLogicalBorderPadding().BStartEnd(mWritingMode); |
65 | 0 | computedBSize = std::max(0, computedBSize); |
66 | 0 | SetComputedBSize(computedBSize); |
67 | 0 | } |
68 | 0 | } |
69 | | |
70 | | void |
71 | | nsTableRowFrame::InitChildReflowInput(nsPresContext& aPresContext, |
72 | | const LogicalSize& aAvailSize, |
73 | | bool aBorderCollapse, |
74 | | TableCellReflowInput& aReflowInput) |
75 | 0 | { |
76 | 0 | nsMargin collapseBorder; |
77 | 0 | nsMargin* pCollapseBorder = nullptr; |
78 | 0 | if (aBorderCollapse) { |
79 | 0 | // we only reflow cells, so don't need to check frame type |
80 | 0 | nsBCTableCellFrame* bcCellFrame = (nsBCTableCellFrame*)aReflowInput.mFrame; |
81 | 0 | if (bcCellFrame) { |
82 | 0 | WritingMode wm = GetWritingMode(); |
83 | 0 | collapseBorder = bcCellFrame->GetBorderWidth(wm).GetPhysicalMargin(wm); |
84 | 0 | pCollapseBorder = &collapseBorder; |
85 | 0 | } |
86 | 0 | } |
87 | 0 | aReflowInput.Init(&aPresContext, nullptr, pCollapseBorder); |
88 | 0 | aReflowInput.FixUp(aAvailSize); |
89 | 0 | } |
90 | | |
91 | | void |
92 | | nsTableRowFrame::SetFixedBSize(nscoord aValue) |
93 | 0 | { |
94 | 0 | nscoord bsize = std::max(0, aValue); |
95 | 0 | if (HasFixedBSize()) { |
96 | 0 | if (bsize > mStyleFixedBSize) { |
97 | 0 | mStyleFixedBSize = bsize; |
98 | 0 | } |
99 | 0 | } |
100 | 0 | else { |
101 | 0 | mStyleFixedBSize = bsize; |
102 | 0 | if (bsize > 0) { |
103 | 0 | SetHasFixedBSize(true); |
104 | 0 | } |
105 | 0 | } |
106 | 0 | } |
107 | | |
108 | | void |
109 | | nsTableRowFrame::SetPctBSize(float aPctValue, |
110 | | bool aForce) |
111 | 0 | { |
112 | 0 | nscoord bsize = std::max(0, NSToCoordRound(aPctValue * 100.0f)); |
113 | 0 | if (HasPctBSize()) { |
114 | 0 | if ((bsize > mStylePctBSize) || aForce) { |
115 | 0 | mStylePctBSize = bsize; |
116 | 0 | } |
117 | 0 | } |
118 | 0 | else { |
119 | 0 | mStylePctBSize = bsize; |
120 | 0 | if (bsize > 0) { |
121 | 0 | SetHasPctBSize(true); |
122 | 0 | } |
123 | 0 | } |
124 | 0 | } |
125 | | |
126 | | /* ----------- nsTableRowFrame ---------- */ |
127 | | |
128 | 0 | NS_QUERYFRAME_HEAD(nsTableRowFrame) |
129 | 0 | NS_QUERYFRAME_ENTRY(nsTableRowFrame) |
130 | 0 | NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame) |
131 | | |
132 | | nsTableRowFrame::nsTableRowFrame(ComputedStyle* aStyle, ClassID aID) |
133 | | : nsContainerFrame(aStyle, aID) |
134 | | , mContentBSize(0) |
135 | | , mStylePctBSize(0) |
136 | | , mStyleFixedBSize(0) |
137 | | , mMaxCellAscent(0) |
138 | | , mMaxCellDescent(0) |
139 | | , mBStartBorderWidth(0) |
140 | | , mBEndBorderWidth(0) |
141 | | , mIEndContBorderWidth(0) |
142 | | , mBStartContBorderWidth(0) |
143 | | , mIStartContBorderWidth(0) |
144 | 0 | { |
145 | 0 | mBits.mRowIndex = 0; |
146 | 0 | mBits.mHasFixedBSize = 0; |
147 | 0 | mBits.mHasPctBSize = 0; |
148 | 0 | mBits.mFirstInserted = 0; |
149 | 0 | ResetBSize(0); |
150 | 0 | } |
151 | | |
152 | | nsTableRowFrame::~nsTableRowFrame() |
153 | 0 | { |
154 | 0 | } |
155 | | |
156 | | void |
157 | | nsTableRowFrame::Init(nsIContent* aContent, |
158 | | nsContainerFrame* aParent, |
159 | | nsIFrame* aPrevInFlow) |
160 | 0 | { |
161 | 0 | // Let the base class do its initialization |
162 | 0 | nsContainerFrame::Init(aContent, aParent, aPrevInFlow); |
163 | 0 |
|
164 | 0 | NS_ASSERTION(mozilla::StyleDisplay::TableRow == StyleDisplay()->mDisplay, |
165 | 0 | "wrong display on table row frame"); |
166 | 0 |
|
167 | 0 | if (aPrevInFlow) { |
168 | 0 | // Set the row index |
169 | 0 | nsTableRowFrame* rowFrame = (nsTableRowFrame*)aPrevInFlow; |
170 | 0 |
|
171 | 0 | SetRowIndex(rowFrame->GetRowIndex()); |
172 | 0 | } else { |
173 | 0 | mWritingMode = GetTableFrame()->GetWritingMode(); |
174 | 0 | } |
175 | 0 | } |
176 | | |
177 | | void |
178 | | nsTableRowFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) |
179 | 0 | { |
180 | 0 | if (HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN)) { |
181 | 0 | nsTableFrame::UnregisterPositionedTablePart(this, aDestructRoot); |
182 | 0 | } |
183 | 0 |
|
184 | 0 | nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData); |
185 | 0 | } |
186 | | |
187 | | /* virtual */ void |
188 | | nsTableRowFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle) |
189 | 0 | { |
190 | 0 | nsContainerFrame::DidSetComputedStyle(aOldComputedStyle); |
191 | 0 |
|
192 | 0 | if (!aOldComputedStyle) //avoid this on init |
193 | 0 | return; |
194 | 0 | |
195 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
196 | 0 | if (tableFrame->IsBorderCollapse() && |
197 | 0 | tableFrame->BCRecalcNeeded(aOldComputedStyle, Style())) { |
198 | 0 | TableArea damageArea(0, GetRowIndex(), tableFrame->GetColCount(), 1); |
199 | 0 | tableFrame->AddBCDamageArea(damageArea); |
200 | 0 | } |
201 | 0 | } |
202 | | |
203 | | void |
204 | | nsTableRowFrame::AppendFrames(ChildListID aListID, |
205 | | nsFrameList& aFrameList) |
206 | 0 | { |
207 | 0 | NS_ASSERTION(aListID == kPrincipalList, "unexpected child list"); |
208 | 0 |
|
209 | 0 | DrainSelfOverflowList(); // ensure the last frame is in mFrames |
210 | 0 | const nsFrameList::Slice& newCells = mFrames.AppendFrames(nullptr, aFrameList); |
211 | 0 |
|
212 | 0 | // Add the new cell frames to the table |
213 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
214 | 0 | for (nsFrameList::Enumerator e(newCells) ; !e.AtEnd(); e.Next()) { |
215 | 0 | nsIFrame *childFrame = e.get(); |
216 | 0 | NS_ASSERTION(IsTableCell(childFrame->Type()), |
217 | 0 | "Not a table cell frame/pseudo frame construction failure"); |
218 | 0 | tableFrame->AppendCell(static_cast<nsTableCellFrame&>(*childFrame), GetRowIndex()); |
219 | 0 | } |
220 | 0 |
|
221 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
222 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
223 | 0 | tableFrame->SetGeometryDirty(); |
224 | 0 | } |
225 | | |
226 | | |
227 | | void |
228 | | nsTableRowFrame::InsertFrames(ChildListID aListID, |
229 | | nsIFrame* aPrevFrame, |
230 | | nsFrameList& aFrameList) |
231 | 0 | { |
232 | 0 | NS_ASSERTION(aListID == kPrincipalList, "unexpected child list"); |
233 | 0 | NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this, |
234 | 0 | "inserting after sibling frame with different parent"); |
235 | 0 | if (mFrames.IsEmpty() || |
236 | 0 | (aPrevFrame && !aPrevFrame->GetNextSibling())) { |
237 | 0 | // This is actually an append (though our caller didn't figure that out), |
238 | 0 | // and our append codepath is both simpler/faster _and_ less buggy. |
239 | 0 | // https://bugzilla.mozilla.org/show_bug.cgi?id=1388898 tracks the bugginess |
240 | 0 | AppendFrames(aListID, aFrameList); |
241 | 0 | return; |
242 | 0 | } |
243 | 0 | |
244 | 0 | DrainSelfOverflowList(); // ensure aPrevFrame is in mFrames |
245 | 0 | //Insert Frames in the frame list |
246 | 0 | const nsFrameList::Slice& newCells = mFrames.InsertFrames(nullptr, aPrevFrame, aFrameList); |
247 | 0 |
|
248 | 0 | // Get the table frame |
249 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
250 | 0 | LayoutFrameType cellFrameType = tableFrame->IsBorderCollapse() |
251 | 0 | ? LayoutFrameType::BCTableCell : LayoutFrameType::TableCell; |
252 | 0 | nsTableCellFrame* prevCellFrame = (nsTableCellFrame *)nsTableFrame::GetFrameAtOrBefore(this, aPrevFrame, cellFrameType); |
253 | 0 | nsTArray<nsTableCellFrame*> cellChildren; |
254 | 0 | for (nsFrameList::Enumerator e(newCells); !e.AtEnd(); e.Next()) { |
255 | 0 | nsIFrame *childFrame = e.get(); |
256 | 0 | NS_ASSERTION(IsTableCell(childFrame->Type()), |
257 | 0 | "Not a table cell frame/pseudo frame construction failure"); |
258 | 0 | cellChildren.AppendElement(static_cast<nsTableCellFrame*>(childFrame)); |
259 | 0 | } |
260 | 0 | // insert the cells into the cell map |
261 | 0 | int32_t colIndex = -1; |
262 | 0 | if (prevCellFrame) { |
263 | 0 | colIndex = prevCellFrame->ColIndex(); |
264 | 0 | } |
265 | 0 | tableFrame->InsertCells(cellChildren, GetRowIndex(), colIndex); |
266 | 0 |
|
267 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
268 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
269 | 0 | tableFrame->SetGeometryDirty(); |
270 | 0 | } |
271 | | |
272 | | void |
273 | | nsTableRowFrame::RemoveFrame(ChildListID aListID, |
274 | | nsIFrame* aOldFrame) |
275 | 0 | { |
276 | 0 | NS_ASSERTION(aListID == kPrincipalList, "unexpected child list"); |
277 | 0 |
|
278 | 0 | MOZ_ASSERT((nsTableCellFrame*)do_QueryFrame(aOldFrame)); |
279 | 0 | nsTableCellFrame* cellFrame = static_cast<nsTableCellFrame*>(aOldFrame); |
280 | 0 | // remove the cell from the cell map |
281 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
282 | 0 | tableFrame->RemoveCell(cellFrame, GetRowIndex()); |
283 | 0 |
|
284 | 0 | // Remove the frame and destroy it |
285 | 0 | mFrames.DestroyFrame(aOldFrame); |
286 | 0 |
|
287 | 0 | PresShell()->FrameNeedsReflow(this, nsIPresShell::eTreeChange, |
288 | 0 | NS_FRAME_HAS_DIRTY_CHILDREN); |
289 | 0 |
|
290 | 0 | tableFrame->SetGeometryDirty(); |
291 | 0 | } |
292 | | |
293 | | /* virtual */ nsMargin |
294 | | nsTableRowFrame::GetUsedMargin() const |
295 | 0 | { |
296 | 0 | return nsMargin(0,0,0,0); |
297 | 0 | } |
298 | | |
299 | | /* virtual */ nsMargin |
300 | | nsTableRowFrame::GetUsedBorder() const |
301 | 0 | { |
302 | 0 | return nsMargin(0,0,0,0); |
303 | 0 | } |
304 | | |
305 | | /* virtual */ nsMargin |
306 | | nsTableRowFrame::GetUsedPadding() const |
307 | 0 | { |
308 | 0 | return nsMargin(0,0,0,0); |
309 | 0 | } |
310 | | |
311 | | static nscoord |
312 | | GetBSizeOfRowsSpannedBelowFirst(nsTableCellFrame& aTableCellFrame, |
313 | | nsTableFrame& aTableFrame, |
314 | | const WritingMode aWM) |
315 | 0 | { |
316 | 0 | nscoord bsize = 0; |
317 | 0 | int32_t rowSpan = aTableFrame.GetEffectiveRowSpan(aTableCellFrame); |
318 | 0 | // add in bsize of rows spanned beyond the 1st one |
319 | 0 | nsIFrame* nextRow = aTableCellFrame.GetParent()->GetNextSibling(); |
320 | 0 | for (int32_t rowX = 1; ((rowX < rowSpan) && nextRow);) { |
321 | 0 | if (nextRow->IsTableRowFrame()) { |
322 | 0 | bsize += nextRow->BSize(aWM); |
323 | 0 | rowX++; |
324 | 0 | } |
325 | 0 | bsize += aTableFrame.GetRowSpacing(rowX); |
326 | 0 | nextRow = nextRow->GetNextSibling(); |
327 | 0 | } |
328 | 0 | return bsize; |
329 | 0 | } |
330 | | |
331 | | /** |
332 | | * Post-reflow hook. This is where the table row does its post-processing |
333 | | */ |
334 | | void |
335 | | nsTableRowFrame::DidResize() |
336 | 0 | { |
337 | 0 | // Resize and re-align the cell frames based on our row bsize |
338 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
339 | 0 |
|
340 | 0 | WritingMode wm = GetWritingMode(); |
341 | 0 | ReflowOutput desiredSize(wm); |
342 | 0 | desiredSize.SetSize(wm, GetLogicalSize(wm)); |
343 | 0 | desiredSize.SetOverflowAreasToDesiredBounds(); |
344 | 0 |
|
345 | 0 | nsSize containerSize = mRect.Size(); |
346 | 0 |
|
347 | 0 | for (nsIFrame* childFrame : mFrames) { |
348 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(childFrame); |
349 | 0 | if (cellFrame) { |
350 | 0 | nscoord cellBSize = BSize(wm) + |
351 | 0 | GetBSizeOfRowsSpannedBelowFirst(*cellFrame, *tableFrame, wm); |
352 | 0 |
|
353 | 0 | // If the bsize for the cell has changed, we need to reset it; |
354 | 0 | // and in vertical-rl mode, we need to update the cell's block position |
355 | 0 | // to account for the containerSize, which may not have been known |
356 | 0 | // earlier, so we always apply it here. |
357 | 0 | LogicalSize cellSize = cellFrame->GetLogicalSize(wm); |
358 | 0 | if (cellSize.BSize(wm) != cellBSize || wm.IsVerticalRL()) { |
359 | 0 | nsRect cellOldRect = cellFrame->GetRect(); |
360 | 0 | nsRect cellVisualOverflow = cellFrame->GetVisualOverflowRect(); |
361 | 0 |
|
362 | 0 | if (wm.IsVerticalRL()) { |
363 | 0 | // Get the old position of the cell, as we want to preserve its |
364 | 0 | // inline coordinate. |
365 | 0 | LogicalPoint oldPos = |
366 | 0 | cellFrame->GetLogicalPosition(wm, containerSize); |
367 | 0 |
|
368 | 0 | // The cell should normally be aligned with the row's block-start, |
369 | 0 | // so set the B component of the position to zero: |
370 | 0 | LogicalPoint newPos(wm, oldPos.I(wm), 0); |
371 | 0 |
|
372 | 0 | // ...unless relative positioning is in effect, in which case the |
373 | 0 | // cell may have been moved away from the row's block-start |
374 | 0 | if (cellFrame->IsRelativelyPositioned()) { |
375 | 0 | // Find out where the cell would have been without relative |
376 | 0 | // positioning. |
377 | 0 | LogicalPoint oldNormalPos = |
378 | 0 | cellFrame->GetLogicalNormalPosition(wm, containerSize); |
379 | 0 | // The difference (if any) between oldPos and oldNormalPos reflects |
380 | 0 | // relative positioning that was applied to the cell, and which we |
381 | 0 | // need to incorporate when resetting the position. |
382 | 0 | newPos.B(wm) = oldPos.B(wm) - oldNormalPos.B(wm); |
383 | 0 | } |
384 | 0 |
|
385 | 0 | if (oldPos != newPos) { |
386 | 0 | cellFrame->SetPosition(wm, newPos, containerSize); |
387 | 0 | nsTableFrame::RePositionViews(cellFrame); |
388 | 0 | } |
389 | 0 | } |
390 | 0 |
|
391 | 0 | cellSize.BSize(wm) = cellBSize; |
392 | 0 | cellFrame->SetSize(wm, cellSize); |
393 | 0 |
|
394 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
395 | 0 | if (tableFrame->IsBorderCollapse()) { |
396 | 0 | nsTableFrame::InvalidateTableFrame(cellFrame, cellOldRect, |
397 | 0 | cellVisualOverflow, |
398 | 0 | false); |
399 | 0 | } |
400 | 0 | } |
401 | 0 |
|
402 | 0 | // realign cell content based on the new bsize. We might be able to |
403 | 0 | // skip this if the bsize didn't change... maybe. Hard to tell. |
404 | 0 | cellFrame->BlockDirAlignChild(wm, mMaxCellAscent); |
405 | 0 |
|
406 | 0 | // Always store the overflow, even if the height didn't change, since |
407 | 0 | // we'll lose part of our overflow area otherwise. |
408 | 0 | ConsiderChildOverflow(desiredSize.mOverflowAreas, cellFrame); |
409 | 0 |
|
410 | 0 | // Note that if the cell's *content* needs to change in response |
411 | 0 | // to this height, it will get a special bsize reflow. |
412 | 0 | } |
413 | 0 | } |
414 | 0 | FinishAndStoreOverflow(&desiredSize); |
415 | 0 | if (HasView()) { |
416 | 0 | nsContainerFrame::SyncFrameViewAfterReflow(PresContext(), this, GetView(), |
417 | 0 | desiredSize.VisualOverflow(), 0); |
418 | 0 | } |
419 | 0 | // Let our base class do the usual work |
420 | 0 | } |
421 | | |
422 | | // returns max-ascent amongst all cells that have 'vertical-align: baseline' |
423 | | // *including* cells with rowspans |
424 | | nscoord nsTableRowFrame::GetMaxCellAscent() const |
425 | 0 | { |
426 | 0 | return mMaxCellAscent; |
427 | 0 | } |
428 | | |
429 | | nscoord nsTableRowFrame::GetRowBaseline(WritingMode aWM) |
430 | 0 | { |
431 | 0 | if (mMaxCellAscent) { |
432 | 0 | return mMaxCellAscent; |
433 | 0 | } |
434 | 0 | |
435 | 0 | // If we don't have a baseline on any of the cells we go for the lowest |
436 | 0 | // content edge of the inner block frames. |
437 | 0 | // Every table cell has a cell frame with its border and padding. Inside |
438 | 0 | // the cell is a block frame. The cell is as high as the tallest cell in |
439 | 0 | // the parent row. As a consequence the block frame might not touch both |
440 | 0 | // the top and the bottom padding of it parent cell frame at the same time. |
441 | 0 | // |
442 | 0 | // bbbbbbbbbbbbbbbbbb cell border: b |
443 | 0 | // bppppppppppppppppb cell padding: p |
444 | 0 | // bpxxxxxxxxxxxxxxpb inner block: x |
445 | 0 | // bpx xpb |
446 | 0 | // bpx xpb |
447 | 0 | // bpx xpb |
448 | 0 | // bpxxxxxxxxxxxxxxpb base line |
449 | 0 | // bp pb |
450 | 0 | // bp pb |
451 | 0 | // bppppppppppppppppb |
452 | 0 | // bbbbbbbbbbbbbbbbbb |
453 | 0 | |
454 | 0 | nscoord ascent = 0; |
455 | 0 | nsSize containerSize = GetSize(); |
456 | 0 | for (nsIFrame* childFrame : mFrames) { |
457 | 0 | if (IsTableCell(childFrame->Type())) { |
458 | 0 | nsIFrame* firstKid = childFrame->PrincipalChildList().FirstChild(); |
459 | 0 | ascent = std::max(ascent, |
460 | 0 | LogicalRect(aWM, firstKid->GetNormalRect(), |
461 | 0 | containerSize).BEnd(aWM)); |
462 | 0 | } |
463 | 0 | } |
464 | 0 | return ascent; |
465 | 0 | } |
466 | | |
467 | | nscoord |
468 | | nsTableRowFrame::GetInitialBSize(nscoord aPctBasis) const |
469 | 0 | { |
470 | 0 | nscoord bsize = 0; |
471 | 0 | if ((aPctBasis > 0) && HasPctBSize()) { |
472 | 0 | bsize = NSToCoordRound(GetPctBSize() * (float)aPctBasis); |
473 | 0 | } |
474 | 0 | if (HasFixedBSize()) { |
475 | 0 | bsize = std::max(bsize, GetFixedBSize()); |
476 | 0 | } |
477 | 0 | return std::max(bsize, GetContentBSize()); |
478 | 0 | } |
479 | | |
480 | | void |
481 | | nsTableRowFrame::ResetBSize(nscoord aFixedBSize) |
482 | 0 | { |
483 | 0 | SetHasFixedBSize(false); |
484 | 0 | SetHasPctBSize(false); |
485 | 0 | SetFixedBSize(0); |
486 | 0 | SetPctBSize(0); |
487 | 0 | SetContentBSize(0); |
488 | 0 |
|
489 | 0 | if (aFixedBSize > 0) { |
490 | 0 | SetFixedBSize(aFixedBSize); |
491 | 0 | } |
492 | 0 |
|
493 | 0 | mMaxCellAscent = 0; |
494 | 0 | mMaxCellDescent = 0; |
495 | 0 | } |
496 | | |
497 | | void |
498 | | nsTableRowFrame::UpdateBSize(nscoord aBSize, |
499 | | nscoord aAscent, |
500 | | nscoord aDescent, |
501 | | nsTableFrame* aTableFrame, |
502 | | nsTableCellFrame* aCellFrame) |
503 | 0 | { |
504 | 0 | if (!aTableFrame || !aCellFrame) { |
505 | 0 | NS_ASSERTION(false , "invalid call"); |
506 | 0 | return; |
507 | 0 | } |
508 | 0 |
|
509 | 0 | if (aBSize != NS_UNCONSTRAINEDSIZE) { |
510 | 0 | if (!(aCellFrame->HasVerticalAlignBaseline())) { // only the cell's height matters |
511 | 0 | if (GetInitialBSize() < aBSize) { |
512 | 0 | int32_t rowSpan = aTableFrame->GetEffectiveRowSpan(*aCellFrame); |
513 | 0 | if (rowSpan == 1) { |
514 | 0 | SetContentBSize(aBSize); |
515 | 0 | } |
516 | 0 | } |
517 | 0 | } |
518 | 0 | else { // the alignment on the baseline can change the bsize |
519 | 0 | NS_ASSERTION((aAscent != NS_UNCONSTRAINEDSIZE) && |
520 | 0 | (aDescent != NS_UNCONSTRAINEDSIZE), "invalid call"); |
521 | 0 | // see if this is a long ascender |
522 | 0 | if (mMaxCellAscent < aAscent) { |
523 | 0 | mMaxCellAscent = aAscent; |
524 | 0 | } |
525 | 0 | // see if this is a long descender and without rowspan |
526 | 0 | if (mMaxCellDescent < aDescent) { |
527 | 0 | int32_t rowSpan = aTableFrame->GetEffectiveRowSpan(*aCellFrame); |
528 | 0 | if (rowSpan == 1) { |
529 | 0 | mMaxCellDescent = aDescent; |
530 | 0 | } |
531 | 0 | } |
532 | 0 | // keep the tallest bsize in sync |
533 | 0 | if (GetInitialBSize() < mMaxCellAscent + mMaxCellDescent) { |
534 | 0 | SetContentBSize(mMaxCellAscent + mMaxCellDescent); |
535 | 0 | } |
536 | 0 | } |
537 | 0 | } |
538 | 0 | } |
539 | | |
540 | | nscoord |
541 | | nsTableRowFrame::CalcBSize(const ReflowInput& aReflowInput) |
542 | 0 | { |
543 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
544 | 0 | nscoord computedBSize = (NS_UNCONSTRAINEDSIZE == aReflowInput.ComputedBSize()) |
545 | 0 | ? 0 : aReflowInput.ComputedBSize(); |
546 | 0 | ResetBSize(computedBSize); |
547 | 0 |
|
548 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
549 | 0 | const nsStylePosition* position = StylePosition(); |
550 | 0 | const nsStyleCoord& bsizeStyleCoord = position->BSize(wm); |
551 | 0 | if (bsizeStyleCoord.ConvertsToLength()) { |
552 | 0 | SetFixedBSize(bsizeStyleCoord.ComputeCoordPercentCalc(0)); |
553 | 0 | } |
554 | 0 | else if (eStyleUnit_Percent == bsizeStyleCoord.GetUnit()) { |
555 | 0 | SetPctBSize(bsizeStyleCoord.GetPercentValue()); |
556 | 0 | } |
557 | 0 | // calc() with percentages is treated like 'auto' on table rows. |
558 | 0 |
|
559 | 0 | for (nsIFrame* kidFrame : mFrames) { |
560 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); |
561 | 0 | if (cellFrame) { |
562 | 0 | MOZ_ASSERT(cellFrame->GetWritingMode() == wm); |
563 | 0 | LogicalSize desSize = cellFrame->GetDesiredSize(); |
564 | 0 | if ((NS_UNCONSTRAINEDSIZE == aReflowInput.AvailableBSize()) && !GetPrevInFlow()) { |
565 | 0 | CalculateCellActualBSize(cellFrame, desSize.BSize(wm), wm); |
566 | 0 | } |
567 | 0 | // bsize may have changed, adjust descent to absorb any excess difference |
568 | 0 | nscoord ascent; |
569 | 0 | if (!kidFrame->PrincipalChildList().FirstChild()->PrincipalChildList().FirstChild()) |
570 | 0 | ascent = desSize.BSize(wm); |
571 | 0 | else |
572 | 0 | ascent = cellFrame->GetCellBaseline(); |
573 | 0 | nscoord descent = desSize.BSize(wm) - ascent; |
574 | 0 | UpdateBSize(desSize.BSize(wm), ascent, descent, tableFrame, cellFrame); |
575 | 0 | } |
576 | 0 | } |
577 | 0 | return GetInitialBSize(); |
578 | 0 | } |
579 | | |
580 | | void |
581 | | nsTableRowFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
582 | | const nsDisplayListSet& aLists) |
583 | 0 | { |
584 | 0 | nsTableFrame::DisplayGenericTablePart(aBuilder, this, aLists); |
585 | 0 | } |
586 | | |
587 | | nsIFrame::LogicalSides |
588 | | nsTableRowFrame::GetLogicalSkipSides(const ReflowInput* aReflowInput) const |
589 | 0 | { |
590 | 0 | if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak == |
591 | 0 | StyleBoxDecorationBreak::Clone)) { |
592 | 0 | return LogicalSides(); |
593 | 0 | } |
594 | 0 | |
595 | 0 | LogicalSides skip; |
596 | 0 | if (nullptr != GetPrevInFlow()) { |
597 | 0 | skip |= eLogicalSideBitsBStart; |
598 | 0 | } |
599 | 0 | if (nullptr != GetNextInFlow()) { |
600 | 0 | skip |= eLogicalSideBitsBEnd; |
601 | 0 | } |
602 | 0 | return skip; |
603 | 0 | } |
604 | | |
605 | | // Calculate the cell's actual bsize given its pass2 bsize. |
606 | | // Takes into account the specified bsize (in the style). |
607 | | // Modifies the desired bsize that is passed in. |
608 | | nsresult |
609 | | nsTableRowFrame::CalculateCellActualBSize(nsTableCellFrame* aCellFrame, |
610 | | nscoord& aDesiredBSize, |
611 | | WritingMode aWM) |
612 | 0 | { |
613 | 0 | nscoord specifiedBSize = 0; |
614 | 0 |
|
615 | 0 | // Get the bsize specified in the style information |
616 | 0 | const nsStylePosition* position = aCellFrame->StylePosition(); |
617 | 0 |
|
618 | 0 | int32_t rowSpan = GetTableFrame()->GetEffectiveRowSpan(*aCellFrame); |
619 | 0 |
|
620 | 0 | const nsStyleCoord& bsizeStyleCoord = position->BSize(aWM); |
621 | 0 | switch (bsizeStyleCoord.GetUnit()) { |
622 | 0 | case eStyleUnit_Calc: { |
623 | 0 | if (bsizeStyleCoord.CalcHasPercent()) { |
624 | 0 | // Treat this like "auto" |
625 | 0 | break; |
626 | 0 | } |
627 | 0 | // Fall through to the coord case |
628 | 0 | MOZ_FALLTHROUGH; |
629 | 0 | } |
630 | 0 | case eStyleUnit_Coord: { |
631 | 0 | // In quirks mode, table cell isize should be content-box, but bsize |
632 | 0 | // should be border-box. |
633 | 0 | // Because of this historic anomaly, we do not use quirk.css |
634 | 0 | // (since we can't specify one value of box-sizing for isize and another |
635 | 0 | // for bsize) |
636 | 0 | specifiedBSize = bsizeStyleCoord.ComputeCoordPercentCalc(0); |
637 | 0 | if (PresContext()->CompatibilityMode() != eCompatibility_NavQuirks && |
638 | 0 | position->mBoxSizing == StyleBoxSizing::Content) { |
639 | 0 | specifiedBSize += |
640 | 0 | aCellFrame->GetLogicalUsedBorderAndPadding(aWM).BStartEnd(aWM); |
641 | 0 | } |
642 | 0 |
|
643 | 0 | if (1 == rowSpan) { |
644 | 0 | SetFixedBSize(specifiedBSize); |
645 | 0 | } |
646 | 0 | break; |
647 | 0 | } |
648 | 0 | case eStyleUnit_Percent: { |
649 | 0 | if (1 == rowSpan) { |
650 | 0 | SetPctBSize(bsizeStyleCoord.GetPercentValue()); |
651 | 0 | } |
652 | 0 | // pct bsizes are handled when all of the cells are finished, |
653 | 0 | // so don't set specifiedBSize |
654 | 0 | break; |
655 | 0 | } |
656 | 0 | case eStyleUnit_Auto: |
657 | 0 | default: |
658 | 0 | break; |
659 | 0 | } |
660 | 0 | |
661 | 0 | // If the specified bsize is greater than the desired bsize, |
662 | 0 | // then use the specified bsize |
663 | 0 | if (specifiedBSize > aDesiredBSize) { |
664 | 0 | aDesiredBSize = specifiedBSize; |
665 | 0 | } |
666 | 0 |
|
667 | 0 | return NS_OK; |
668 | 0 | } |
669 | | |
670 | | // Calculates the available isize for the table cell based on the known |
671 | | // column isizes taking into account column spans and column spacing |
672 | | static nscoord |
673 | | CalcAvailISize(nsTableFrame& aTableFrame, |
674 | | nsTableCellFrame& aCellFrame) |
675 | 0 | { |
676 | 0 | nscoord cellAvailISize = 0; |
677 | 0 | uint32_t colIndex = aCellFrame.ColIndex(); |
678 | 0 | int32_t colspan = aTableFrame.GetEffectiveColSpan(aCellFrame); |
679 | 0 | NS_ASSERTION(colspan > 0, "effective colspan should be positive"); |
680 | 0 | nsTableFrame* fifTable = |
681 | 0 | static_cast<nsTableFrame*>(aTableFrame.FirstInFlow()); |
682 | 0 |
|
683 | 0 | for (int32_t spanX = 0; spanX < colspan; spanX++) { |
684 | 0 | cellAvailISize += |
685 | 0 | fifTable->GetColumnISizeFromFirstInFlow(colIndex + spanX); |
686 | 0 | if (spanX > 0 && |
687 | 0 | aTableFrame.ColumnHasCellSpacingBefore(colIndex + spanX)) { |
688 | 0 | cellAvailISize += aTableFrame.GetColSpacing(colIndex + spanX - 1); |
689 | 0 | } |
690 | 0 | } |
691 | 0 | return cellAvailISize; |
692 | 0 | } |
693 | | |
694 | | static nscoord |
695 | | GetSpaceBetween(int32_t aPrevColIndex, |
696 | | int32_t aColIndex, |
697 | | int32_t aColSpan, |
698 | | nsTableFrame& aTableFrame, |
699 | | bool aCheckVisibility) |
700 | 0 | { |
701 | 0 | nscoord space = 0; |
702 | 0 | int32_t colIdx; |
703 | 0 | nsTableFrame* fifTable = |
704 | 0 | static_cast<nsTableFrame*>(aTableFrame.FirstInFlow()); |
705 | 0 | for (colIdx = aPrevColIndex + 1; aColIndex > colIdx; colIdx++) { |
706 | 0 | bool isCollapsed = false; |
707 | 0 | if (!aCheckVisibility) { |
708 | 0 | space += fifTable->GetColumnISizeFromFirstInFlow(colIdx); |
709 | 0 | } |
710 | 0 | else { |
711 | 0 | nsTableColFrame* colFrame = aTableFrame.GetColFrame(colIdx); |
712 | 0 | const nsStyleVisibility* colVis = colFrame->StyleVisibility(); |
713 | 0 | bool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == colVis->mVisible); |
714 | 0 | nsIFrame* cgFrame = colFrame->GetParent(); |
715 | 0 | const nsStyleVisibility* groupVis = cgFrame->StyleVisibility(); |
716 | 0 | bool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE == |
717 | 0 | groupVis->mVisible); |
718 | 0 | isCollapsed = collapseCol || collapseGroup; |
719 | 0 | if (!isCollapsed) |
720 | 0 | space += fifTable->GetColumnISizeFromFirstInFlow(colIdx); |
721 | 0 | } |
722 | 0 | if (!isCollapsed && aTableFrame.ColumnHasCellSpacingBefore(colIdx)) { |
723 | 0 | space += aTableFrame.GetColSpacing(colIdx - 1); |
724 | 0 | } |
725 | 0 | } |
726 | 0 | return space; |
727 | 0 | } |
728 | | |
729 | | // subtract the bsizes of aRow's prev in flows from the unpaginated bsize |
730 | | static |
731 | | nscoord CalcBSizeFromUnpaginatedBSize(nsTableRowFrame& aRow, |
732 | | WritingMode aWM) |
733 | 0 | { |
734 | 0 | nscoord bsize = 0; |
735 | 0 | nsTableRowFrame* firstInFlow = |
736 | 0 | static_cast<nsTableRowFrame*>(aRow.FirstInFlow()); |
737 | 0 | if (firstInFlow->HasUnpaginatedBSize()) { |
738 | 0 | bsize = firstInFlow->GetUnpaginatedBSize(); |
739 | 0 | for (nsIFrame* prevInFlow = aRow.GetPrevInFlow(); prevInFlow; |
740 | 0 | prevInFlow = prevInFlow->GetPrevInFlow()) { |
741 | 0 | bsize -= prevInFlow->BSize(aWM); |
742 | 0 | } |
743 | 0 | } |
744 | 0 | return std::max(bsize, 0); |
745 | 0 | } |
746 | | |
747 | | void |
748 | | nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, |
749 | | ReflowOutput& aDesiredSize, |
750 | | const ReflowInput& aReflowInput, |
751 | | nsTableFrame& aTableFrame, |
752 | | nsReflowStatus& aStatus) |
753 | 0 | { |
754 | 0 | aStatus.Reset(); |
755 | 0 |
|
756 | 0 | // XXXldb Should we be checking constrained bsize instead? |
757 | 0 | const bool isPaginated = aPresContext->IsPaginated(); |
758 | 0 | const bool borderCollapse = aTableFrame.IsBorderCollapse(); |
759 | 0 |
|
760 | 0 | int32_t cellColSpan = 1; // must be defined here so it's set properly for non-cell kids |
761 | 0 |
|
762 | 0 | // remember the col index of the previous cell to handle rowspans into this row |
763 | 0 | int32_t prevColIndex = -1; |
764 | 0 | nscoord iCoord = 0; // running total of children inline-coord offset |
765 | 0 |
|
766 | 0 | // This computes the max of all cell bsizes |
767 | 0 | nscoord cellMaxBSize = 0; |
768 | 0 |
|
769 | 0 | // Reflow each of our existing cell frames |
770 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
771 | 0 | nsSize containerSize = |
772 | 0 | aReflowInput.ComputedSizeAsContainerIfConstrained(); |
773 | 0 |
|
774 | 0 | for (nsIFrame* kidFrame : mFrames) { |
775 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); |
776 | 0 | if (!cellFrame) { |
777 | 0 | // XXXldb nsCSSFrameConstructor needs to enforce this! |
778 | 0 | MOZ_ASSERT_UNREACHABLE("yikes, a non-row child"); |
779 | 0 |
|
780 | 0 | // it's an unknown frame type, give it a generic reflow and ignore the results |
781 | 0 | TableCellReflowInput |
782 | 0 | kidReflowInput(aPresContext, aReflowInput, kidFrame, |
783 | 0 | LogicalSize(kidFrame->GetWritingMode(), 0, 0), |
784 | 0 | ReflowInput::CALLER_WILL_INIT); |
785 | 0 | InitChildReflowInput(*aPresContext, LogicalSize(wm), false, kidReflowInput); |
786 | 0 | ReflowOutput desiredSize(aReflowInput); |
787 | 0 | nsReflowStatus status; |
788 | 0 | ReflowChild(kidFrame, aPresContext, desiredSize, kidReflowInput, 0, 0, 0, status); |
789 | 0 | kidFrame->DidReflow(aPresContext, nullptr); |
790 | 0 |
|
791 | 0 | continue; |
792 | 0 | } |
793 | 0 |
|
794 | 0 | // See if we should only reflow the dirty child frames |
795 | 0 | bool doReflowChild = true; |
796 | 0 | if (!aReflowInput.ShouldReflowAllKids() && |
797 | 0 | !aTableFrame.IsGeometryDirty() && |
798 | 0 | !NS_SUBTREE_DIRTY(kidFrame)) { |
799 | 0 | if (!aReflowInput.mFlags.mSpecialBSizeReflow) |
800 | 0 | doReflowChild = false; |
801 | 0 | } |
802 | 0 | else if ((NS_UNCONSTRAINEDSIZE != aReflowInput.AvailableBSize())) { |
803 | 0 | // We don't reflow a rowspan >1 cell here with a constrained bsize. |
804 | 0 | // That happens in nsTableRowGroupFrame::SplitSpanningCells. |
805 | 0 | if (aTableFrame.GetEffectiveRowSpan(*cellFrame) > 1) { |
806 | 0 | doReflowChild = false; |
807 | 0 | } |
808 | 0 | } |
809 | 0 | if (aReflowInput.mFlags.mSpecialBSizeReflow) { |
810 | 0 | if (!isPaginated && |
811 | 0 | !cellFrame->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE)) { |
812 | 0 | continue; |
813 | 0 | } |
814 | 0 | } |
815 | 0 | |
816 | 0 | uint32_t cellColIndex = cellFrame->ColIndex(); |
817 | 0 | cellColSpan = aTableFrame.GetEffectiveColSpan(*cellFrame); |
818 | 0 |
|
819 | 0 | // If the adjacent cell is in a prior row (because of a rowspan) add in the space |
820 | 0 | // NOTE: prevColIndex can be -1 here. |
821 | 0 | if (prevColIndex != (static_cast<int32_t>(cellColIndex) - 1)) { |
822 | 0 | iCoord += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, aTableFrame, |
823 | 0 | false); |
824 | 0 | } |
825 | 0 |
|
826 | 0 | // remember the rightmost (ltr) or leftmost (rtl) column this cell spans into |
827 | 0 | prevColIndex = cellColIndex + (cellColSpan - 1); |
828 | 0 |
|
829 | 0 | // Reflow the child frame |
830 | 0 | nsRect kidRect = kidFrame->GetRect(); |
831 | 0 | LogicalPoint origKidNormalPosition = |
832 | 0 | kidFrame->GetLogicalNormalPosition(wm, containerSize); |
833 | 0 | // All cells' no-relative-positioning position should be snapped to the |
834 | 0 | // row's bstart edge. |
835 | 0 | // This doesn't hold in vertical-rl mode, where we don't yet know the |
836 | 0 | // correct containerSize for the row frame. In that case, we'll have to |
837 | 0 | // fix up child positions later, after determining our desiredSize. |
838 | 0 | NS_ASSERTION(origKidNormalPosition.B(wm) == 0 || wm.IsVerticalRL(), |
839 | 0 | "unexpected kid position"); |
840 | 0 |
|
841 | 0 | nsRect kidVisualOverflow = kidFrame->GetVisualOverflowRect(); |
842 | 0 | LogicalPoint kidPosition(wm, iCoord, 0); |
843 | 0 | bool firstReflow = kidFrame->HasAnyStateBits(NS_FRAME_FIRST_REFLOW); |
844 | 0 |
|
845 | 0 | if (doReflowChild) { |
846 | 0 | // Calculate the available isize for the table cell using the known |
847 | 0 | // column isizes |
848 | 0 | nscoord availCellISize = CalcAvailISize(aTableFrame, *cellFrame); |
849 | 0 |
|
850 | 0 | Maybe<TableCellReflowInput> kidReflowInput; |
851 | 0 | ReflowOutput desiredSize(aReflowInput); |
852 | 0 |
|
853 | 0 | // If the avail isize is not the same as last time we reflowed the cell or |
854 | 0 | // the cell wants to be bigger than what was available last time or |
855 | 0 | // it is a style change reflow or we are printing, then we must reflow the |
856 | 0 | // cell. Otherwise we can skip the reflow. |
857 | 0 | // XXXldb Why is this condition distinct from doReflowChild above? |
858 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
859 | 0 | NS_ASSERTION(cellFrame->GetWritingMode() == wm, |
860 | 0 | "expected consistent writing-mode within table"); |
861 | 0 | LogicalSize cellDesiredSize = cellFrame->GetDesiredSize(); |
862 | 0 | if ((availCellISize != cellFrame->GetPriorAvailISize()) || |
863 | 0 | (cellDesiredSize.ISize(wm) > cellFrame->GetPriorAvailISize()) || |
864 | 0 | HasAnyStateBits(NS_FRAME_IS_DIRTY) || |
865 | 0 | isPaginated || |
866 | 0 | NS_SUBTREE_DIRTY(cellFrame) || |
867 | 0 | // See if it needs a special reflow, or if it had one that we need to undo. |
868 | 0 | cellFrame->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE) || |
869 | 0 | HasPctBSize()) { |
870 | 0 | // Reflow the cell to fit the available isize, bsize |
871 | 0 | // XXX The old IR_ChildIsDirty code used availCellISize here. |
872 | 0 | LogicalSize kidAvailSize(wm, availCellISize, aReflowInput.AvailableBSize()); |
873 | 0 |
|
874 | 0 | // Reflow the child |
875 | 0 | kidReflowInput.emplace(aPresContext, aReflowInput, kidFrame, |
876 | 0 | kidAvailSize, |
877 | 0 | ReflowInput::CALLER_WILL_INIT); |
878 | 0 | InitChildReflowInput(*aPresContext, kidAvailSize, borderCollapse, |
879 | 0 | *kidReflowInput); |
880 | 0 |
|
881 | 0 | nsReflowStatus status; |
882 | 0 | ReflowChild(kidFrame, aPresContext, desiredSize, *kidReflowInput, |
883 | 0 | wm, kidPosition, containerSize, 0, status); |
884 | 0 |
|
885 | 0 | // allow the table to determine if/how the table needs to be rebalanced |
886 | 0 | // If any of the cells are not complete, then we're not complete |
887 | 0 | if (status.IsIncomplete()) { |
888 | 0 | aStatus.Reset(); |
889 | 0 | aStatus.SetIncomplete(); |
890 | 0 | } |
891 | 0 | } else { |
892 | 0 | if (iCoord != origKidNormalPosition.I(wm)) { |
893 | 0 | kidFrame->InvalidateFrameSubtree(); |
894 | 0 | } |
895 | 0 |
|
896 | 0 | desiredSize.SetSize(wm, cellDesiredSize); |
897 | 0 | desiredSize.mOverflowAreas = cellFrame->GetOverflowAreas(); |
898 | 0 |
|
899 | 0 | // if we are in a floated table, our position is not yet established, so we cannot reposition our views |
900 | 0 | // the containing block will do this for us after positioning the table |
901 | 0 | if (!aTableFrame.IsFloating()) { |
902 | 0 | // Because we may have moved the frame we need to make sure any views are |
903 | 0 | // positioned properly. We have to do this, because any one of our parent |
904 | 0 | // frames could have moved and we have no way of knowing... |
905 | 0 | nsTableFrame::RePositionViews(kidFrame); |
906 | 0 | } |
907 | 0 | } |
908 | 0 |
|
909 | 0 | if (NS_UNCONSTRAINEDSIZE == aReflowInput.AvailableBSize()) { |
910 | 0 | if (!GetPrevInFlow()) { |
911 | 0 | // Calculate the cell's actual bsize given its pass2 bsize. This |
912 | 0 | // function takes into account the specified bsize (in the style) |
913 | 0 | CalculateCellActualBSize(cellFrame, desiredSize.BSize(wm), wm); |
914 | 0 | } |
915 | 0 | // bsize may have changed, adjust descent to absorb any excess difference |
916 | 0 | nscoord ascent; |
917 | 0 | if (!kidFrame->PrincipalChildList().FirstChild()->PrincipalChildList().FirstChild()) { |
918 | 0 | ascent = desiredSize.BSize(wm); |
919 | 0 | } else { |
920 | 0 | ascent = ((nsTableCellFrame *)kidFrame)->GetCellBaseline(); |
921 | 0 | } |
922 | 0 | nscoord descent = desiredSize.BSize(wm) - ascent; |
923 | 0 | UpdateBSize(desiredSize.BSize(wm), ascent, descent, &aTableFrame, cellFrame); |
924 | 0 | } else { |
925 | 0 | cellMaxBSize = std::max(cellMaxBSize, desiredSize.BSize(wm)); |
926 | 0 | int32_t rowSpan = aTableFrame.GetEffectiveRowSpan((nsTableCellFrame&)*kidFrame); |
927 | 0 | if (1 == rowSpan) { |
928 | 0 | SetContentBSize(cellMaxBSize); |
929 | 0 | } |
930 | 0 | } |
931 | 0 |
|
932 | 0 | // Place the child |
933 | 0 | desiredSize.ISize(wm) = availCellISize; |
934 | 0 |
|
935 | 0 | if (kidReflowInput) { |
936 | 0 | // We reflowed. Apply relative positioning in the normal way. |
937 | 0 | kidReflowInput->ApplyRelativePositioning(&kidPosition, containerSize); |
938 | 0 | } else if (kidFrame->IsRelativelyPositioned()) { |
939 | 0 | // We didn't reflow. Do the positioning part of what |
940 | 0 | // MovePositionBy does internally. (This codepath should really |
941 | 0 | // be merged into the else below if we can.) |
942 | 0 | nsMargin* computedOffsetProp = |
943 | 0 | kidFrame->GetProperty(nsIFrame::ComputedOffsetProperty()); |
944 | 0 |
|
945 | 0 | // On our fist reflow sticky children may not have the property yet (we |
946 | 0 | // need to reflow the children first to size the scroll frame). |
947 | 0 | LogicalMargin computedOffsets( |
948 | 0 | wm, computedOffsetProp ? *computedOffsetProp : nsMargin()); |
949 | 0 | ReflowInput::ApplyRelativePositioning( |
950 | 0 | kidFrame, wm, computedOffsets, &kidPosition, containerSize); |
951 | 0 | } |
952 | 0 |
|
953 | 0 | // In vertical-rl mode, we are likely to have containerSize.width = 0 |
954 | 0 | // because ComputedWidth() was NS_UNCONSTRAINEDSIZE. |
955 | 0 | // For cases where that's wrong, we will fix up the position later. |
956 | 0 | FinishReflowChild(kidFrame, aPresContext, desiredSize, nullptr, |
957 | 0 | wm, kidPosition, containerSize, 0); |
958 | 0 |
|
959 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
960 | 0 | if (tableFrame->IsBorderCollapse()) { |
961 | 0 | nsTableFrame::InvalidateTableFrame(kidFrame, kidRect, kidVisualOverflow, |
962 | 0 | firstReflow); |
963 | 0 | } |
964 | 0 |
|
965 | 0 | iCoord += desiredSize.ISize(wm); |
966 | 0 | } else { |
967 | 0 | if (iCoord != origKidNormalPosition.I(wm)) { |
968 | 0 | // Invalidate the old position |
969 | 0 | kidFrame->InvalidateFrameSubtree(); |
970 | 0 | // Move to the new position. As above, we need to account for relative |
971 | 0 | // positioning. |
972 | 0 | kidFrame->MovePositionBy(wm, |
973 | 0 | LogicalPoint(wm, iCoord - origKidNormalPosition.I(wm), 0)); |
974 | 0 | nsTableFrame::RePositionViews(kidFrame); |
975 | 0 | // invalidate the new position |
976 | 0 | kidFrame->InvalidateFrameSubtree(); |
977 | 0 | } |
978 | 0 | // we need to account for the cell's isize even if it isn't reflowed |
979 | 0 | iCoord += kidFrame->ISize(wm); |
980 | 0 |
|
981 | 0 | if (kidFrame->GetNextInFlow()) { |
982 | 0 | aStatus.Reset(); |
983 | 0 | aStatus.SetIncomplete(); |
984 | 0 | } |
985 | 0 | } |
986 | 0 | ConsiderChildOverflow(aDesiredSize.mOverflowAreas, kidFrame); |
987 | 0 | iCoord += aTableFrame.GetColSpacing(cellColIndex); |
988 | 0 | } |
989 | 0 |
|
990 | 0 | // Just set our isize to what was available. |
991 | 0 | // The table will calculate the isize and not use our value. |
992 | 0 | aDesiredSize.ISize(wm) = aReflowInput.AvailableISize(); |
993 | 0 |
|
994 | 0 | if (aReflowInput.mFlags.mSpecialBSizeReflow) { |
995 | 0 | aDesiredSize.BSize(wm) = BSize(wm); |
996 | 0 | } else if (NS_UNCONSTRAINEDSIZE == aReflowInput.AvailableBSize()) { |
997 | 0 | aDesiredSize.BSize(wm) = CalcBSize(aReflowInput); |
998 | 0 | if (GetPrevInFlow()) { |
999 | 0 | nscoord bsize = CalcBSizeFromUnpaginatedBSize(*this, wm); |
1000 | 0 | aDesiredSize.BSize(wm) = std::max(aDesiredSize.BSize(wm), bsize); |
1001 | 0 | } else { |
1002 | 0 | if (isPaginated && HasStyleBSize()) { |
1003 | 0 | // set the unpaginated bsize so next in flows can try to honor it |
1004 | 0 | SetHasUnpaginatedBSize(true); |
1005 | 0 | SetUnpaginatedBSize(aPresContext, aDesiredSize.BSize(wm)); |
1006 | 0 | } |
1007 | 0 | if (isPaginated && HasUnpaginatedBSize()) { |
1008 | 0 | aDesiredSize.BSize(wm) = std::max(aDesiredSize.BSize(wm), |
1009 | 0 | GetUnpaginatedBSize()); |
1010 | 0 | } |
1011 | 0 | } |
1012 | 0 | } else { // constrained bsize, paginated |
1013 | 0 | // Compute the bsize we should have from style (subtracting the |
1014 | 0 | // bsize from our prev-in-flows from the style bsize) |
1015 | 0 | nscoord styleBSize = CalcBSizeFromUnpaginatedBSize(*this, wm); |
1016 | 0 | if (styleBSize > aReflowInput.AvailableBSize()) { |
1017 | 0 | styleBSize = aReflowInput.AvailableBSize(); |
1018 | 0 | aStatus.SetIncomplete(); |
1019 | 0 | } |
1020 | 0 | aDesiredSize.BSize(wm) = std::max(cellMaxBSize, styleBSize); |
1021 | 0 | } |
1022 | 0 |
|
1023 | 0 | if (wm.IsVerticalRL()) { |
1024 | 0 | // Any children whose width was not the same as our final |
1025 | 0 | // aDesiredSize.BSize will have been misplaced earlier at the |
1026 | 0 | // FinishReflowChild stage. So fix them up now. |
1027 | 0 | for (nsIFrame* kidFrame : mFrames) { |
1028 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); |
1029 | 0 | if (!cellFrame) { |
1030 | 0 | continue; |
1031 | 0 | } |
1032 | 0 | if (kidFrame->BSize(wm) != aDesiredSize.BSize(wm)) { |
1033 | 0 | kidFrame->MovePositionBy(wm, |
1034 | 0 | LogicalPoint(wm, 0, kidFrame->BSize(wm) - aDesiredSize.BSize(wm))); |
1035 | 0 | nsTableFrame::RePositionViews(kidFrame); |
1036 | 0 | // Do we need to InvalidateFrameSubtree() here? |
1037 | 0 | } |
1038 | 0 | } |
1039 | 0 | } |
1040 | 0 |
|
1041 | 0 | aDesiredSize.UnionOverflowAreasWithDesiredBounds(); |
1042 | 0 | FinishAndStoreOverflow(&aDesiredSize); |
1043 | 0 | } |
1044 | | |
1045 | | /** Layout the entire row. |
1046 | | * This method stacks cells in the inline dir according to HTML 4.0 rules. |
1047 | | */ |
1048 | | void |
1049 | | nsTableRowFrame::Reflow(nsPresContext* aPresContext, |
1050 | | ReflowOutput& aDesiredSize, |
1051 | | const ReflowInput& aReflowInput, |
1052 | | nsReflowStatus& aStatus) |
1053 | 0 | { |
1054 | 0 | MarkInReflow(); |
1055 | 0 | DO_GLOBAL_REFLOW_COUNT("nsTableRowFrame"); |
1056 | 0 | DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus); |
1057 | 0 | MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!"); |
1058 | 0 |
|
1059 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
1060 | 0 |
|
1061 | 0 | nsTableFrame* tableFrame = GetTableFrame(); |
1062 | 0 | const nsStyleVisibility* rowVis = StyleVisibility(); |
1063 | 0 | bool collapseRow = (NS_STYLE_VISIBILITY_COLLAPSE == rowVis->mVisible); |
1064 | 0 | if (collapseRow) { |
1065 | 0 | tableFrame->SetNeedToCollapse(true); |
1066 | 0 | } |
1067 | 0 |
|
1068 | 0 | // see if a special bsize reflow needs to occur due to having a pct bsize |
1069 | 0 | nsTableFrame::CheckRequestSpecialBSizeReflow(aReflowInput); |
1070 | 0 |
|
1071 | 0 | // See if we have a cell with specified/pct bsize |
1072 | 0 | InitHasCellWithStyleBSize(tableFrame); |
1073 | 0 |
|
1074 | 0 | ReflowChildren(aPresContext, aDesiredSize, aReflowInput, *tableFrame, aStatus); |
1075 | 0 |
|
1076 | 0 | if (aPresContext->IsPaginated() && !aStatus.IsFullyComplete() && |
1077 | 0 | ShouldAvoidBreakInside(aReflowInput)) { |
1078 | 0 | aStatus.SetInlineLineBreakBeforeAndReset(); |
1079 | 0 | } |
1080 | 0 |
|
1081 | 0 | // Just set our isize to what was available. |
1082 | 0 | // The table will calculate the isize and not use our value. |
1083 | 0 | aDesiredSize.ISize(wm) = aReflowInput.AvailableISize(); |
1084 | 0 |
|
1085 | 0 | // If our parent is in initial reflow, it'll handle invalidating our |
1086 | 0 | // entire overflow rect. |
1087 | 0 | if (!GetParent()->HasAnyStateBits(NS_FRAME_FIRST_REFLOW) && |
1088 | 0 | nsSize(aDesiredSize.Width(), aDesiredSize.Height()) != mRect.Size()) { |
1089 | 0 | InvalidateFrame(); |
1090 | 0 | } |
1091 | 0 |
|
1092 | 0 | // Any absolutely-positioned children will get reflowed in |
1093 | 0 | // nsFrame::FixupPositionedTableParts in another pass, so propagate our |
1094 | 0 | // dirtiness to them before our parent clears our dirty bits. |
1095 | 0 | PushDirtyBitToAbsoluteFrames(); |
1096 | 0 |
|
1097 | 0 | NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize); |
1098 | 0 | } |
1099 | | |
1100 | | /** |
1101 | | * This function is called by the row group frame's SplitRowGroup() code when |
1102 | | * pushing a row frame that has cell frames that span into it. The cell frame |
1103 | | * should be reflowed with the specified height |
1104 | | */ |
1105 | | nscoord |
1106 | | nsTableRowFrame::ReflowCellFrame(nsPresContext* aPresContext, |
1107 | | const ReflowInput& aReflowInput, |
1108 | | bool aIsTopOfPage, |
1109 | | nsTableCellFrame* aCellFrame, |
1110 | | nscoord aAvailableBSize, |
1111 | | nsReflowStatus& aStatus) |
1112 | 0 | { |
1113 | 0 | WritingMode wm = aReflowInput.GetWritingMode(); |
1114 | 0 |
|
1115 | 0 | // Reflow the cell frame with the specified height. Use the existing width |
1116 | 0 | nsSize containerSize = aCellFrame->GetSize(); |
1117 | 0 | LogicalRect cellRect = aCellFrame->GetLogicalRect(wm, containerSize); |
1118 | 0 | nsRect cellVisualOverflow = aCellFrame->GetVisualOverflowRect(); |
1119 | 0 |
|
1120 | 0 | LogicalSize cellSize = cellRect.Size(wm); |
1121 | 0 | LogicalSize availSize(wm, cellRect.ISize(wm), aAvailableBSize); |
1122 | 0 | bool borderCollapse = GetTableFrame()->IsBorderCollapse(); |
1123 | 0 | NS_ASSERTION(aCellFrame->GetWritingMode() == wm, |
1124 | 0 | "expected consistent writing-mode within table"); |
1125 | 0 | TableCellReflowInput |
1126 | 0 | cellReflowInput(aPresContext, aReflowInput, aCellFrame, availSize, |
1127 | 0 | ReflowInput::CALLER_WILL_INIT); |
1128 | 0 | InitChildReflowInput(*aPresContext, availSize, borderCollapse, cellReflowInput); |
1129 | 0 | cellReflowInput.mFlags.mIsTopOfPage = aIsTopOfPage; |
1130 | 0 |
|
1131 | 0 | ReflowOutput desiredSize(aReflowInput); |
1132 | 0 |
|
1133 | 0 | ReflowChild(aCellFrame, aPresContext, desiredSize, cellReflowInput, |
1134 | 0 | 0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus); |
1135 | 0 | bool fullyComplete = aStatus.IsComplete() && !aStatus.IsTruncated(); |
1136 | 0 | if (fullyComplete) { |
1137 | 0 | desiredSize.BSize(wm) = aAvailableBSize; |
1138 | 0 | } |
1139 | 0 | aCellFrame->SetSize(wm, LogicalSize(wm, cellSize.ISize(wm), |
1140 | 0 | desiredSize.BSize(wm))); |
1141 | 0 |
|
1142 | 0 | // Note: BlockDirAlignChild can affect the overflow rect. |
1143 | 0 | // XXX What happens if this cell has 'vertical-align: baseline' ? |
1144 | 0 | // XXX Why is it assumed that the cell's ascent hasn't changed ? |
1145 | 0 | if (fullyComplete) { |
1146 | 0 | aCellFrame->BlockDirAlignChild(wm, mMaxCellAscent); |
1147 | 0 | } |
1148 | 0 |
|
1149 | 0 | nsTableFrame::InvalidateTableFrame(aCellFrame, |
1150 | 0 | cellRect.GetPhysicalRect(wm, containerSize), |
1151 | 0 | cellVisualOverflow, |
1152 | 0 | aCellFrame-> |
1153 | 0 | HasAnyStateBits(NS_FRAME_FIRST_REFLOW)); |
1154 | 0 |
|
1155 | 0 | aCellFrame->DidReflow(aPresContext, nullptr); |
1156 | 0 |
|
1157 | 0 | return desiredSize.BSize(wm); |
1158 | 0 | } |
1159 | | |
1160 | | nscoord |
1161 | | nsTableRowFrame::CollapseRowIfNecessary(nscoord aRowOffset, |
1162 | | nscoord aISize, |
1163 | | bool aCollapseGroup, |
1164 | | bool& aDidCollapse) |
1165 | 0 | { |
1166 | 0 | const nsStyleVisibility* rowVis = StyleVisibility(); |
1167 | 0 | bool collapseRow = (NS_STYLE_VISIBILITY_COLLAPSE == rowVis->mVisible); |
1168 | 0 | nsTableFrame* tableFrame = |
1169 | 0 | static_cast<nsTableFrame*>(GetTableFrame()->FirstInFlow()); |
1170 | 0 | if (collapseRow) { |
1171 | 0 | tableFrame->SetNeedToCollapse(true); |
1172 | 0 | } |
1173 | 0 |
|
1174 | 0 | if (aRowOffset != 0) { |
1175 | 0 | // We're moving, so invalidate our old position |
1176 | 0 | InvalidateFrameSubtree(); |
1177 | 0 | } |
1178 | 0 |
|
1179 | 0 | WritingMode wm = GetWritingMode(); |
1180 | 0 |
|
1181 | 0 | nsSize parentSize = GetParent()->GetSize(); |
1182 | 0 | LogicalRect rowRect = GetLogicalRect(wm, parentSize); |
1183 | 0 | nsRect oldRect = mRect; |
1184 | 0 | nsRect oldVisualOverflow = GetVisualOverflowRect(); |
1185 | 0 |
|
1186 | 0 | rowRect.BStart(wm) -= aRowOffset; |
1187 | 0 | rowRect.ISize(wm) = aISize; |
1188 | 0 | nsOverflowAreas overflow; |
1189 | 0 | nscoord shift = 0; |
1190 | 0 | nsSize containerSize = mRect.Size(); |
1191 | 0 |
|
1192 | 0 | if (aCollapseGroup || collapseRow) { |
1193 | 0 | aDidCollapse = true; |
1194 | 0 | shift = rowRect.BSize(wm); |
1195 | 0 | nsTableCellFrame* cellFrame = GetFirstCell(); |
1196 | 0 | if (cellFrame) { |
1197 | 0 | uint32_t rowIndex = cellFrame->RowIndex(); |
1198 | 0 | shift += tableFrame->GetRowSpacing(rowIndex); |
1199 | 0 | while (cellFrame) { |
1200 | 0 | LogicalRect cRect = cellFrame->GetLogicalRect(wm, containerSize); |
1201 | 0 | // If aRowOffset != 0, there's no point in invalidating the cells, since |
1202 | 0 | // we've already invalidated our overflow area. Note that we _do_ still |
1203 | 0 | // need to invalidate if our row is not moving, because the cell might |
1204 | 0 | // span out of this row, so invalidating our row rect won't do enough. |
1205 | 0 | if (aRowOffset == 0) { |
1206 | 0 | InvalidateFrame(); |
1207 | 0 | } |
1208 | 0 | cRect.BSize(wm) = 0; |
1209 | 0 | cellFrame->SetRect(wm, cRect, containerSize); |
1210 | 0 | cellFrame = cellFrame->GetNextCell(); |
1211 | 0 | } |
1212 | 0 | } else { |
1213 | 0 | shift += tableFrame->GetRowSpacing(GetRowIndex()); |
1214 | 0 | } |
1215 | 0 | rowRect.BSize(wm) = 0; |
1216 | 0 | } |
1217 | 0 | else { // row is not collapsed |
1218 | 0 | // remember the col index of the previous cell to handle rowspans into this |
1219 | 0 | // row |
1220 | 0 | int32_t prevColIndex = -1; |
1221 | 0 | nscoord iPos = 0; // running total of children inline-axis offset |
1222 | 0 | nsTableFrame* fifTable = |
1223 | 0 | static_cast<nsTableFrame*>(tableFrame->FirstInFlow()); |
1224 | 0 |
|
1225 | 0 | for (nsIFrame* kidFrame : mFrames) { |
1226 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); |
1227 | 0 | if (cellFrame) { |
1228 | 0 | uint32_t cellColIndex = cellFrame->ColIndex(); |
1229 | 0 | int32_t cellColSpan = tableFrame->GetEffectiveColSpan(*cellFrame); |
1230 | 0 |
|
1231 | 0 | // If the adjacent cell is in a prior row (because of a rowspan) add in |
1232 | 0 | // the space |
1233 | 0 | // NOTE: prevColIndex can be -1 here. |
1234 | 0 | if (prevColIndex != (static_cast<int32_t>(cellColIndex) - 1)) { |
1235 | 0 | iPos += GetSpaceBetween(prevColIndex, cellColIndex, cellColSpan, |
1236 | 0 | *tableFrame, true); |
1237 | 0 | } |
1238 | 0 | LogicalRect cRect(wm, iPos, 0, 0, rowRect.BSize(wm)); |
1239 | 0 |
|
1240 | 0 | // remember the last (iend-wards-most) column this cell spans into |
1241 | 0 | prevColIndex = cellColIndex + cellColSpan - 1; |
1242 | 0 | int32_t actualColSpan = cellColSpan; |
1243 | 0 | bool isVisible = false; |
1244 | 0 | for (int32_t colIdx = cellColIndex; actualColSpan > 0; |
1245 | 0 | colIdx++, actualColSpan--) { |
1246 | 0 |
|
1247 | 0 | nsTableColFrame* colFrame = tableFrame->GetColFrame(colIdx); |
1248 | 0 | const nsStyleVisibility* colVis = colFrame->StyleVisibility(); |
1249 | 0 | bool collapseCol = (NS_STYLE_VISIBILITY_COLLAPSE == |
1250 | 0 | colVis->mVisible); |
1251 | 0 | nsIFrame* cgFrame = colFrame->GetParent(); |
1252 | 0 | const nsStyleVisibility* groupVis = cgFrame->StyleVisibility(); |
1253 | 0 | bool collapseGroup = (NS_STYLE_VISIBILITY_COLLAPSE == |
1254 | 0 | groupVis->mVisible); |
1255 | 0 | bool isCollapsed = collapseCol || collapseGroup; |
1256 | 0 | if (!isCollapsed) { |
1257 | 0 | cRect.ISize(wm) += fifTable->GetColumnISizeFromFirstInFlow(colIdx); |
1258 | 0 | isVisible = true; |
1259 | 0 | if ((actualColSpan > 1)) { |
1260 | 0 | nsTableColFrame* nextColFrame = |
1261 | 0 | tableFrame->GetColFrame(colIdx + 1); |
1262 | 0 | const nsStyleVisibility* nextColVis = |
1263 | 0 | nextColFrame->StyleVisibility(); |
1264 | 0 | if ( (NS_STYLE_VISIBILITY_COLLAPSE != nextColVis->mVisible) && |
1265 | 0 | tableFrame->ColumnHasCellSpacingBefore(colIdx + 1)) { |
1266 | 0 | cRect.ISize(wm) += tableFrame->GetColSpacing(cellColIndex); |
1267 | 0 | } |
1268 | 0 | } |
1269 | 0 | } |
1270 | 0 | } |
1271 | 0 | iPos += cRect.ISize(wm); |
1272 | 0 | if (isVisible) { |
1273 | 0 | iPos += tableFrame->GetColSpacing(cellColIndex); |
1274 | 0 | } |
1275 | 0 | int32_t actualRowSpan = tableFrame->GetEffectiveRowSpan(*cellFrame); |
1276 | 0 | nsTableRowFrame* rowFrame = GetNextRow(); |
1277 | 0 | for (actualRowSpan--; actualRowSpan > 0 && rowFrame; actualRowSpan--) { |
1278 | 0 | const nsStyleVisibility* nextRowVis = rowFrame->StyleVisibility(); |
1279 | 0 | bool collapseNextRow = (NS_STYLE_VISIBILITY_COLLAPSE == |
1280 | 0 | nextRowVis->mVisible); |
1281 | 0 | if (!collapseNextRow) { |
1282 | 0 | LogicalRect nextRect = rowFrame->GetLogicalRect(wm, |
1283 | 0 | containerSize); |
1284 | 0 | cRect.BSize(wm) += |
1285 | 0 | nextRect.BSize(wm) + |
1286 | 0 | tableFrame->GetRowSpacing(rowFrame->GetRowIndex()); |
1287 | 0 | } |
1288 | 0 | rowFrame = rowFrame->GetNextRow(); |
1289 | 0 | } |
1290 | 0 |
|
1291 | 0 | nsRect oldCellRect = cellFrame->GetRect(); |
1292 | 0 | LogicalPoint oldCellNormalPos = |
1293 | 0 | cellFrame->GetLogicalNormalPosition(wm, containerSize); |
1294 | 0 |
|
1295 | 0 | nsRect oldCellVisualOverflow = cellFrame->GetVisualOverflowRect(); |
1296 | 0 |
|
1297 | 0 | if (aRowOffset == 0 && cRect.Origin(wm) != oldCellNormalPos) { |
1298 | 0 | // We're moving the cell. Invalidate the old overflow area |
1299 | 0 | cellFrame->InvalidateFrameSubtree(); |
1300 | 0 | } |
1301 | 0 |
|
1302 | 0 | cellFrame->MovePositionBy(wm, cRect.Origin(wm) - oldCellNormalPos); |
1303 | 0 | cellFrame->SetSize(wm, cRect.Size(wm)); |
1304 | 0 |
|
1305 | 0 | // XXXbz This looks completely bogus in the cases when we didn't |
1306 | 0 | // collapse the cell! |
1307 | 0 | LogicalRect cellBounds(wm, 0, 0, cRect.ISize(wm), cRect.BSize(wm)); |
1308 | 0 | nsRect cellPhysicalBounds = |
1309 | 0 | cellBounds.GetPhysicalRect(wm, containerSize); |
1310 | 0 | nsOverflowAreas cellOverflow(cellPhysicalBounds, cellPhysicalBounds); |
1311 | 0 | cellFrame->FinishAndStoreOverflow(cellOverflow, |
1312 | 0 | cRect.Size(wm).GetPhysicalSize(wm)); |
1313 | 0 | nsTableFrame::RePositionViews(cellFrame); |
1314 | 0 | ConsiderChildOverflow(overflow, cellFrame); |
1315 | 0 |
|
1316 | 0 | if (aRowOffset == 0) { |
1317 | 0 | nsTableFrame::InvalidateTableFrame(cellFrame, oldCellRect, |
1318 | 0 | oldCellVisualOverflow, false); |
1319 | 0 | } |
1320 | 0 | } |
1321 | 0 | } |
1322 | 0 | } |
1323 | 0 |
|
1324 | 0 | SetRect(wm, rowRect, containerSize); |
1325 | 0 | overflow.UnionAllWith(nsRect(0, 0, rowRect.Width(wm), rowRect.Height(wm))); |
1326 | 0 | FinishAndStoreOverflow(overflow, rowRect.Size(wm).GetPhysicalSize(wm)); |
1327 | 0 |
|
1328 | 0 | nsTableFrame::RePositionViews(this); |
1329 | 0 | nsTableFrame::InvalidateTableFrame(this, oldRect, oldVisualOverflow, false); |
1330 | 0 | return shift; |
1331 | 0 | } |
1332 | | |
1333 | | /* |
1334 | | * The following method is called by the row group frame's SplitRowGroup() |
1335 | | * when it creates a continuing cell frame and wants to insert it into the |
1336 | | * row's child list. |
1337 | | */ |
1338 | | void |
1339 | | nsTableRowFrame::InsertCellFrame(nsTableCellFrame* aFrame, |
1340 | | int32_t aColIndex) |
1341 | 0 | { |
1342 | 0 | // Find the cell frame where col index < aColIndex |
1343 | 0 | nsTableCellFrame* priorCell = nullptr; |
1344 | 0 | for (nsIFrame* child : mFrames) { |
1345 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(child); |
1346 | 0 | if (cellFrame) { |
1347 | 0 | uint32_t colIndex = cellFrame->ColIndex(); |
1348 | 0 | // Can aColIndex be -1 here? Let's assume it can for now. |
1349 | 0 | if (static_cast<int32_t>(colIndex) < aColIndex) { |
1350 | 0 | priorCell = cellFrame; |
1351 | 0 | } |
1352 | 0 | else break; |
1353 | 0 | } |
1354 | 0 | } |
1355 | 0 | mFrames.InsertFrame(this, priorCell, aFrame); |
1356 | 0 | } |
1357 | | |
1358 | | nsTableRowFrame* |
1359 | | nsTableRowFrame::GetNextRow() const |
1360 | 0 | { |
1361 | 0 | nsIFrame* childFrame = GetNextSibling(); |
1362 | 0 | while (childFrame) { |
1363 | 0 | nsTableRowFrame *rowFrame = do_QueryFrame(childFrame); |
1364 | 0 | if (rowFrame) { |
1365 | 0 | NS_ASSERTION(mozilla::StyleDisplay::TableRow == childFrame->StyleDisplay()->mDisplay, |
1366 | 0 | "wrong display type on rowframe"); |
1367 | 0 | return rowFrame; |
1368 | 0 | } |
1369 | 0 | childFrame = childFrame->GetNextSibling(); |
1370 | 0 | } |
1371 | 0 | return nullptr; |
1372 | 0 | } |
1373 | | |
1374 | | NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(RowUnpaginatedHeightProperty, nscoord) |
1375 | | |
1376 | | void |
1377 | | nsTableRowFrame::SetUnpaginatedBSize(nsPresContext* aPresContext, |
1378 | | nscoord aValue) |
1379 | 0 | { |
1380 | 0 | NS_ASSERTION(!GetPrevInFlow(), "program error"); |
1381 | 0 | // Set the property |
1382 | 0 | SetProperty(RowUnpaginatedHeightProperty(), aValue); |
1383 | 0 | } |
1384 | | |
1385 | | nscoord |
1386 | | nsTableRowFrame::GetUnpaginatedBSize() |
1387 | 0 | { |
1388 | 0 | return GetProperty(RowUnpaginatedHeightProperty()); |
1389 | 0 | } |
1390 | | |
1391 | | void nsTableRowFrame::SetContinuousBCBorderWidth(LogicalSide aForSide, |
1392 | | BCPixelSize aPixelValue) |
1393 | 0 | { |
1394 | 0 | switch (aForSide) { |
1395 | 0 | case eLogicalSideIEnd: |
1396 | 0 | mIEndContBorderWidth = aPixelValue; |
1397 | 0 | return; |
1398 | 0 | case eLogicalSideBStart: |
1399 | 0 | mBStartContBorderWidth = aPixelValue; |
1400 | 0 | return; |
1401 | 0 | case eLogicalSideIStart: |
1402 | 0 | mIStartContBorderWidth = aPixelValue; |
1403 | 0 | return; |
1404 | 0 | default: |
1405 | 0 | NS_ERROR("invalid LogicalSide arg"); |
1406 | 0 | } |
1407 | 0 | } |
1408 | | #ifdef ACCESSIBILITY |
1409 | | a11y::AccType |
1410 | | nsTableRowFrame::AccessibleType() |
1411 | 0 | { |
1412 | 0 | return a11y::eHTMLTableRowType; |
1413 | 0 | } |
1414 | | #endif |
1415 | | /** |
1416 | | * Sets the NS_ROW_HAS_CELL_WITH_STYLE_BSIZE bit to indicate whether |
1417 | | * this row has any cells that have non-auto-bsize. (Row-spanning |
1418 | | * cells are ignored.) |
1419 | | */ |
1420 | | void nsTableRowFrame::InitHasCellWithStyleBSize(nsTableFrame* aTableFrame) |
1421 | 0 | { |
1422 | 0 | WritingMode wm = GetWritingMode(); |
1423 | 0 |
|
1424 | 0 | for (nsIFrame* kidFrame : mFrames) { |
1425 | 0 | nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame); |
1426 | 0 | if (!cellFrame) { |
1427 | 0 | MOZ_ASSERT_UNREACHABLE("Table row has a non-cell child."); |
1428 | 0 | continue; |
1429 | 0 | } |
1430 | 0 | // Ignore row-spanning cells |
1431 | 0 | const nsStyleCoord &cellBSize = cellFrame->StylePosition()->BSize(wm); |
1432 | 0 | if (aTableFrame->GetEffectiveRowSpan(*cellFrame) == 1 && |
1433 | 0 | cellBSize.GetUnit() != eStyleUnit_Auto && |
1434 | 0 | /* calc() with percentages treated like 'auto' */ |
1435 | 0 | (!cellBSize.IsCalcUnit() || !cellBSize.HasPercent())) { |
1436 | 0 | AddStateBits(NS_ROW_HAS_CELL_WITH_STYLE_BSIZE); |
1437 | 0 | return; |
1438 | 0 | } |
1439 | 0 | } |
1440 | 0 | RemoveStateBits(NS_ROW_HAS_CELL_WITH_STYLE_BSIZE); |
1441 | 0 | } |
1442 | | |
1443 | | void |
1444 | | nsTableRowFrame::InvalidateFrame(uint32_t aDisplayItemKey, bool aRebuildDisplayItems) |
1445 | 0 | { |
1446 | 0 | nsIFrame::InvalidateFrame(aDisplayItemKey, aRebuildDisplayItems); |
1447 | 0 | if (GetTableFrame()->IsBorderCollapse()) { |
1448 | 0 | GetParent()->InvalidateFrameWithRect(GetVisualOverflowRect() + GetPosition(), aDisplayItemKey, false); |
1449 | 0 | } |
1450 | 0 | } |
1451 | | |
1452 | | void |
1453 | | nsTableRowFrame::InvalidateFrameWithRect(const nsRect& aRect, uint32_t aDisplayItemKey, bool aRebuildDisplayItems) |
1454 | 0 | { |
1455 | 0 | nsIFrame::InvalidateFrameWithRect(aRect, aDisplayItemKey, aRebuildDisplayItems); |
1456 | 0 | // If we have filters applied that would affects our bounds, then |
1457 | 0 | // we get an inactive layer created and this is computed |
1458 | 0 | // within FrameLayerBuilder |
1459 | 0 | GetParent()->InvalidateFrameWithRect(aRect + GetPosition(), aDisplayItemKey, false); |
1460 | 0 | } |
1461 | | |
1462 | | /* ----- global methods ----- */ |
1463 | | |
1464 | | nsTableRowFrame* |
1465 | | NS_NewTableRowFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
1466 | 0 | { |
1467 | 0 | return new (aPresShell) nsTableRowFrame(aStyle); |
1468 | 0 | } |
1469 | | |
1470 | | NS_IMPL_FRAMEARENA_HELPERS(nsTableRowFrame) |
1471 | | |
1472 | | #ifdef DEBUG_FRAME_DUMP |
1473 | | nsresult |
1474 | | nsTableRowFrame::GetFrameName(nsAString& aResult) const |
1475 | | { |
1476 | | return MakeFrameName(NS_LITERAL_STRING("TableRow"), aResult); |
1477 | | } |
1478 | | #endif |