Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/core/rendering/RenderTableSection.cpp

Issue 596823002: Tables with specific merge cell configuration render with extra height to tr elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments addressed Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1997 Martin Jones (mjones@kde.org) 2 * Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 * (C) 1997 Torben Weis (weis@kde.org) 3 * (C) 1997 Torben Weis (weis@kde.org)
4 * (C) 1998 Waldo Bastian (bastian@kde.org) 4 * (C) 1998 Waldo Bastian (bastian@kde.org)
5 * (C) 1999 Lars Knoll (knoll@kde.org) 5 * (C) 1999 Lars Knoll (knoll@kde.org)
6 * (C) 1999 Antti Koivisto (koivisto@kde.org) 6 * (C) 1999 Antti Koivisto (koivisto@kde.org)
7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2013 Apple Inc. All r ights reserved. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2013 Apple Inc. All r ights reserved.
8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (cellIsFullyIncludedInOtherCell(cell1, cell2)) 478 if (cellIsFullyIncludedInOtherCell(cell1, cell2))
479 return true; 479 return true;
480 // Sorting lower row index first because first we need to apply the extra he ight of spanning cell which 480 // Sorting lower row index first because first we need to apply the extra he ight of spanning cell which
481 // comes first in the table so lower rows's position would increment in sequ ence. 481 // comes first in the table so lower rows's position would increment in sequ ence.
482 if (!cellIsFullyIncludedInOtherCell(cell2, cell1)) 482 if (!cellIsFullyIncludedInOtherCell(cell2, cell1))
483 return (cell1->rowIndex() < cell2->rowIndex()); 483 return (cell1->rowIndex() < cell2->rowIndex());
484 484
485 return false; 485 return false;
486 } 486 }
487 487
488 bool RenderTableSection::isHeightNeededForRowHavingOnlySpanningCells(unsigned ro w) 488 unsigned RenderTableSection::calcRowHeightHavingOnlySpanningCells(unsigned row, int& accumulatedPositionIncrease, unsigned effectedRowByExtraHeight, unsigned& e xtraHeightToPropagate, Vector<int>& rowsCountWithOnlySpanningCells)
dsinclair 2014/10/15 21:37:41 s/rowsCountWithOnlySpanningCells/rowCountWithOnlyS
dsinclair 2014/10/15 21:37:42 How does accumulatedPositionIncrease relate to ext
dsinclair 2014/10/15 21:37:42 What does effectedRowByExtraHeight mean? Does it m
suchit.agrawal 2014/10/25 04:28:59 There is no relation between these 2. extraHeight
dsinclair 2014/11/05 17:03:20 So, if I'm understanding correctly, accumulatedPos
a.suchit 2014/12/03 13:09:13 right.
489 {
490 unsigned totalCols = m_grid[row].row.size();
491
492 if (!totalCols)
493 return false;
494
495 for (unsigned col = 0; col < totalCols; col++) {
496 const CellStruct& rowSpanCell = cellAt(row, col);
497
498 if (rowSpanCell.cells.size()) {
499 RenderTableCell* cell = rowSpanCell.cells[0];
500 const unsigned rowIndex = cell->rowIndex();
501 const unsigned rowSpan = cell->rowSpan();
502 int totalRowSpanCellHeight = 0;
503
504 for (unsigned row = 0; row < rowSpan; row++) {
505 unsigned actualRow = row + rowIndex;
506 totalRowSpanCellHeight += m_rowPos[actualRow + 1] - m_rowPos[act ualRow];
507 }
508 totalRowSpanCellHeight -= borderSpacingForRow(rowIndex + rowSpan - 1 );
509
510 if (totalRowSpanCellHeight < cell->logicalHeightForRowSizing())
511 return true;
512 }
513 }
514
515 return false;
516 }
517
518 unsigned RenderTableSection::calcRowHeightHavingOnlySpanningCells(unsigned row)
519 { 489 {
520 ASSERT(rowHasOnlySpanningCells(row)); 490 ASSERT(rowHasOnlySpanningCells(row));
521 491
522 unsigned totalCols = m_grid[row].row.size(); 492 unsigned totalCols = m_grid[row].row.size();
523 493
524 if (!totalCols) 494 if (!totalCols)
525 return 0; 495 return 0;
526 496
527 unsigned rowHeight = 0; 497 unsigned rowHeight = 0;
528 498
529 for (unsigned col = 0; col < totalCols; col++) { 499 for (unsigned col = 0; col < totalCols; col++) {
530 const CellStruct& rowSpanCell = cellAt(row, col); 500 const CellStruct& rowSpanCell = cellAt(row, col);
531 if (rowSpanCell.cells.size() && rowSpanCell.cells[0]->rowSpan() > 1) 501
532 rowHeight = std::max(rowHeight, rowSpanCell.cells[0]->logicalHeightF orRowSizing() / rowSpanCell.cells[0]->rowSpan()); 502 if (rowSpanCell.cells.size()) {
dsinclair 2014/10/15 21:37:41 if (!rowSpanCell.cells.size()) continue;
a.suchit 2014/12/03 13:09:13 Done.
503 RenderTableCell* cell = rowSpanCell.cells[0];
504
505 if (cell->rowSpan() > 1) {
dsinclair 2014/10/15 21:37:42 if (cell.rowSpan() <= 1) continue;
a.suchit 2014/12/03 13:09:13 Done.
506 const unsigned rowIndex = cell->rowIndex();
507 const unsigned rowSpan = cell->rowSpan();
dsinclair 2014/10/15 21:37:42 Can we rename these to cellRowIndex and cellRowSpa
a.suchit 2014/12/03 13:09:13 Done.
508
509 // As we are moving from top to bottom for calculating rows heig ht of row with only spanning cells
510 // and all previous rows are already processed so we need to fin d the number of rows with only
dsinclair 2014/10/15 21:37:41 This comment is difficult to process, does the bel
a.suchit 2014/12/03 13:09:13 Done.
511 // spanning cells presents from current row to end of the spanni ng cell.
512 unsigned startRow = max(rowIndex, row);
513 unsigned endRow = rowIndex + rowSpan;
dsinclair 2014/10/15 21:37:42 Does this mean the endRow of our current cell, or
suchit.agrawal 2014/10/25 04:28:59 we can see it in 2 ways, 1. It is the row that com
514 unsigned spanningCellsRowsCountHavingZeroHeight = 0;
515
516 if (startRow) {
517 spanningCellsRowsCountHavingZeroHeight = rowsCountWithOnlySp anningCells[endRow - 1] - rowsCountWithOnlySpanningCells[startRow - 1];
dsinclair 2014/10/15 21:37:42 Why is this startRow - 1 and not startRow?
suchit.agrawal 2014/10/25 04:28:59 000112223334 ^ ^ 4-3=1. Means 1 row with
518 } else {
519 spanningCellsRowsCountHavingZeroHeight = (rowsCountWithOnlyS panningCells[endRow - 1] - rowsCountWithOnlySpanningCells[startRow]) + rowsCount WithOnlySpanningCells[0];
dsinclair 2014/10/15 21:37:41 If I'm reading this correctly we're doing: spanni
suchit.agrawal 2014/10/25 04:28:59 yes, we can remove subtraction and addition.
a.suchit 2014/12/03 13:09:13 Done.
520 }
521
522 int totalRowspanCellHeight = m_rowPos[endRow] - m_rowPos[rowInde x];
dsinclair 2014/10/15 21:37:41 It's very confusing that we jump back and forth be
suchit.agrawal 2014/10/25 04:28:59 I will change |startRow| to |startRowforSpanningCe
a.suchit 2014/12/03 13:09:13 Done.
523
524 totalRowspanCellHeight -= borderSpacingForRow(endRow - 1);
525
526 totalRowspanCellHeight += accumulatedPositionIncrease;
527 if (effectedRowByExtraHeight >= rowIndex && effectedRowByExtraHe ight < endRow)
528 totalRowspanCellHeight += extraHeightToPropagate;
529
530 if (totalRowspanCellHeight < cell->logicalHeightForRowSizing()) {
531 unsigned extraHeightRequired = rowSpanCell.cells[0]->logical HeightForRowSizing() - totalRowspanCellHeight;
532 int remainder = extraHeightRequired % spanningCellsRowsCount HavingZeroHeight;
533
534 if (remainder)
535 extraHeightRequired += spanningCellsRowsCountHavingZeroH eight - remainder;
536
537 rowHeight = std::max(rowHeight, extraHeightRequired / spanni ngCellsRowsCountHavingZeroHeight);
dsinclair 2014/10/15 21:37:41 Wont' this fail to set rowHeight in the case where
dsinclair 2014/10/15 21:37:41 Can we ever have a case where spanningCellsRowsCou
suchit.agrawal 2014/10/25 04:28:59 rowHeight would be less than logicalHeightForRowSi
suchit.agrawal 2014/10/25 04:28:59 spanningCellsRowsCountHavingZeroHeight would not b
538 }
539 }
540 }
533 } 541 }
534 542
535 return rowHeight; 543 return rowHeight;
536 } 544 }
537 545
538 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight) 546 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight, unsigned& extraHeightToPr opagate, Vector<int>& rowsCountWithOnlySpanningCells)
539 { 547 {
540 ASSERT(spanningRowsHeight.rowHeight.size()); 548 ASSERT(spanningRowsHeight.rowHeight.size());
541 549
542 int accumulatedPositionIncrease = 0; 550 int accumulatedPositionIncrease = 0;
543 const unsigned rowSpan = cell->rowSpan(); 551 const unsigned rowSpan = cell->rowSpan();
544 const unsigned rowIndex = cell->rowIndex(); 552 const unsigned rowIndex = cell->rowIndex();
545 553
546 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); 554 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size());
547 555
548 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { 556 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) {
549 unsigned actualRow = row + rowIndex; 557 unsigned actualRow = row + rowIndex;
550 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row) && isHeightNeededForRowHavingOnlySpanningCells(actualRow)) { 558 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row)) {
551 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow); 559 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow, accumulatedPositionIncrease, rowIndex + rowSpan, extraHeightToPr opagate, rowsCountWithOnlySpanningCells);
dsinclair 2014/10/15 21:37:41 We set effectedRowByExtraHeight to rowIndex + rowS
suchit.agrawal 2014/10/25 04:28:59 In calcRowHeightHavingOnlySpanningCells(), We may
552 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; 560 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row];
553 } 561 }
554 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; 562 m_rowPos[actualRow + 1] += accumulatedPositionIncrease;
555 } 563 }
556 564
557 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; 565 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease;
558 } 566 }
559 567
560 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if 568 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if
561 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll 569 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll
562 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) 570 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells)
563 { 571 {
564 ASSERT(rowSpanCells.size()); 572 ASSERT(rowSpanCells.size());
565 573
566 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce nding order 574 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce nding order
567 // Arrange row spanning cell in the order in which we need to process first. 575 // Arrange row spanning cell in the order in which we need to process first.
568 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder); 576 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder);
569 577
570 unsigned extraHeightToPropagate = 0; 578 unsigned extraHeightToPropagate = 0;
571 unsigned lastRowIndex = 0; 579 unsigned lastRowIndex = 0;
572 unsigned lastRowSpan = 0; 580 unsigned lastRowSpan = 0;
573 581
582 Vector<int> rowsCountWithOnlySpanningCells;
583
584 // At this stage, Height of the rows are zero for the one containing only sp anning cells.
dsinclair 2014/10/15 21:37:42 This comment doesn't make sense to me, can you re-
suchit.agrawal 2014/10/25 04:28:59 We are collecting the information of the rows with
585 int count = 0;
586 for (unsigned row = 0; row < m_grid.size(); row++) {
587 if (rowHasOnlySpanningCells(row))
588 count++;
589 rowsCountWithOnlySpanningCells.append(count);
dsinclair 2014/10/15 21:37:41 I'm not sure I understand what this is storing. We
suchit.agrawal 2014/10/25 04:28:59 yes, we are doing same here.
590 }
591
574 for (unsigned i = 0; i < rowSpanCells.size(); i++) { 592 for (unsigned i = 0; i < rowSpanCells.size(); i++) {
575 RenderTableCell* cell = rowSpanCells[i]; 593 RenderTableCell* cell = rowSpanCells[i];
576 594
577 unsigned rowIndex = cell->rowIndex(); 595 unsigned rowIndex = cell->rowIndex();
578 596
579 unsigned rowSpan = cell->rowSpan(); 597 unsigned rowSpan = cell->rowSpan();
580 598
581 unsigned spanningCellEndIndex = rowIndex + rowSpan; 599 unsigned spanningCellEndIndex = rowIndex + rowSpan;
582 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; 600 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan;
583 601
(...skipping 17 matching lines...) Expand all
601 619
602 lastRowIndex = rowIndex; 620 lastRowIndex = rowIndex;
603 lastRowSpan = rowSpan; 621 lastRowSpan = rowSpan;
604 622
605 struct SpanningRowsHeight spanningRowsHeight; 623 struct SpanningRowsHeight spanningRowsHeight;
606 624
607 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); 625 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight);
608 626
609 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell. 627 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell.
610 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) 628 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells)
611 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight); 629 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight, ex traHeightToPropagate, rowsCountWithOnlySpanningCells);
612 630
613 // This code handle row(s) that have rowspanning cell(s) and at least on e empty cell. 631 // This code handle row(s) that have rowspanning cell(s) and at least on e empty cell.
614 // Such rows are not handled below and end up having a height of 0. That would mean 632 // Such rows are not handled below and end up having a height of 0. That would mean
615 // content overlapping if one of their cells has any content. To avoid t he problem, we 633 // content overlapping if one of their cells has any content. To avoid t he problem, we
616 // add all the remaining spanning cells' height to the last spanned row. 634 // add all the remaining spanning cells' height to the last spanned row.
617 // This means that we could grow a row past its 'height' or break percen tage spreading 635 // This means that we could grow a row past its 'height' or break percen tage spreading
618 // however this is better than overlapping content. 636 // however this is better than overlapping content.
619 // FIXME: Is there a better algorithm? 637 // FIXME: Is there a better algorithm?
620 if (!spanningRowsHeight.totalRowsHeight) { 638 if (!spanningRowsHeight.totalRowsHeight) {
621 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) 639 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing)
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691). 1628 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691).
1611 if (!style()->isLeftToRightDirection()) 1629 if (!style()->isLeftToRightDirection())
1612 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); 1630 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing);
1613 else 1631 else
1614 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); 1632 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing);
1615 1633
1616 cell->setLogicalLocation(cellLocation); 1634 cell->setLogicalLocation(cellLocation);
1617 } 1635 }
1618 1636
1619 } // namespace blink 1637 } // namespace blink
OLDNEW
« Source/core/rendering/RenderTableSection.h ('K') | « Source/core/rendering/RenderTableSection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698