nsTableRowFrame.cpp 54 KB

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