OLD | NEW |
---|---|
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 if (cellIsFullyIncludedInOtherCell(cell1, cell2)) | 477 if (cellIsFullyIncludedInOtherCell(cell1, cell2)) |
478 return true; | 478 return true; |
479 // Sorting lower row index first because first we need to apply the extra he ight of spanning cell which | 479 // Sorting lower row index first because first we need to apply the extra he ight of spanning cell which |
480 // comes first in the table so lower rows's position would increment in sequ ence. | 480 // comes first in the table so lower rows's position would increment in sequ ence. |
481 if (!cellIsFullyIncludedInOtherCell(cell2, cell1)) | 481 if (!cellIsFullyIncludedInOtherCell(cell2, cell1)) |
482 return (cell1->rowIndex() < cell2->rowIndex()); | 482 return (cell1->rowIndex() < cell2->rowIndex()); |
483 | 483 |
484 return false; | 484 return false; |
485 } | 485 } |
486 | 486 |
487 bool RenderTableSection::isHeightNeededForRowHavingOnlySpanningCells(unsigned ro w) | 487 unsigned RenderTableSection::calcRowHeightHavingOnlySpanningCells(unsigned row, int& accumulatedPositionIncrease, unsigned effectedRowByExtraHeight, unsigned& e xtraHeightToPropagate, Vector<int>& rowsCountWithOnlySpanningCells) |
dsinclair
2014/12/03 19:25:23
If I'm reading this correctly effectedRowByExtraHe
dsinclair
2014/12/03 19:25:23
To clarify this, can we rename extraHeightToPropga
a.suchit
2014/12/10 04:27:42
Done.
a.suchit
2014/12/10 04:27:42
Done.
| |
488 { | |
489 unsigned totalCols = m_grid[row].row.size(); | |
490 | |
491 if (!totalCols) | |
492 return false; | |
493 | |
494 for (unsigned col = 0; col < totalCols; col++) { | |
495 const CellStruct& rowSpanCell = cellAt(row, col); | |
496 | |
497 if (rowSpanCell.cells.size()) { | |
498 RenderTableCell* cell = rowSpanCell.cells[0]; | |
499 const unsigned rowIndex = cell->rowIndex(); | |
500 const unsigned rowSpan = cell->rowSpan(); | |
501 int totalRowSpanCellHeight = 0; | |
502 | |
503 for (unsigned row = 0; row < rowSpan; row++) { | |
504 unsigned actualRow = row + rowIndex; | |
505 totalRowSpanCellHeight += m_rowPos[actualRow + 1] - m_rowPos[act ualRow]; | |
506 } | |
507 totalRowSpanCellHeight -= borderSpacingForRow(rowIndex + rowSpan - 1 ); | |
508 | |
509 if (totalRowSpanCellHeight < cell->logicalHeightForRowSizing()) | |
510 return true; | |
511 } | |
512 } | |
513 | |
514 return false; | |
515 } | |
516 | |
517 unsigned RenderTableSection::calcRowHeightHavingOnlySpanningCells(unsigned row) | |
518 { | 488 { |
519 ASSERT(rowHasOnlySpanningCells(row)); | 489 ASSERT(rowHasOnlySpanningCells(row)); |
520 | 490 |
521 unsigned totalCols = m_grid[row].row.size(); | 491 unsigned totalCols = m_grid[row].row.size(); |
522 | 492 |
523 if (!totalCols) | 493 if (!totalCols) |
524 return 0; | 494 return 0; |
525 | 495 |
526 unsigned rowHeight = 0; | 496 unsigned rowHeight = 0; |
527 | 497 |
528 for (unsigned col = 0; col < totalCols; col++) { | 498 for (unsigned col = 0; col < totalCols; col++) { |
529 const CellStruct& rowSpanCell = cellAt(row, col); | 499 const CellStruct& rowSpanCell = cellAt(row, col); |
530 if (rowSpanCell.cells.size() && rowSpanCell.cells[0]->rowSpan() > 1) | 500 |
531 rowHeight = std::max(rowHeight, rowSpanCell.cells[0]->logicalHeightF orRowSizing() / rowSpanCell.cells[0]->rowSpan()); | 501 if (!rowSpanCell.cells.size()) |
502 continue; | |
503 | |
504 RenderTableCell* cell = rowSpanCell.cells[0]; | |
505 | |
506 if (cell->rowSpan() <= 1) | |
507 continue; | |
508 | |
509 const unsigned cellRowIndex = cell->rowIndex(); | |
510 const unsigned cellRowSpan = cell->rowSpan(); | |
511 | |
512 // As we are going from the top of the table to the bottom to calculate the row | |
513 // heights for rows that only contain spanning cells and all previous ro ws are | |
514 // processed we only need to find the number of rows with spanning cells from the | |
515 // current cell to the end of the current cells spanning height. | |
516 unsigned startRowForSpanningCellCount = max(cellRowIndex, row); | |
517 unsigned endRow = cellRowIndex + cellRowSpan; | |
518 unsigned spanningCellsRowsCountHavingZeroHeight = 0; | |
519 | |
520 if (startRowForSpanningCellCount) { | |
521 spanningCellsRowsCountHavingZeroHeight = rowsCountWithOnlySpanningCe lls[endRow - 1] - rowsCountWithOnlySpanningCells[startRowForSpanningCellCount - 1]; | |
522 } else { | |
523 spanningCellsRowsCountHavingZeroHeight = rowsCountWithOnlySpanningCe lls[endRow - 1]; | |
524 } | |
dsinclair
2014/12/03 19:25:22
I think this can be simplified too:
unsigned span
a.suchit
2014/12/10 04:27:42
Done.
| |
525 | |
526 int totalRowspanCellHeight = m_rowPos[endRow] - m_rowPos[cellRowIndex]; | |
dsinclair
2014/12/03 19:25:23
Is totalRowspanCellHeight the total height that is
a.suchit
2014/12/10 04:27:42
This is current rowspan cells height.
| |
527 | |
528 totalRowspanCellHeight -= borderSpacingForRow(endRow - 1); | |
529 | |
530 totalRowspanCellHeight += accumulatedPositionIncrease; | |
dsinclair
2014/12/03 19:25:23
Why not do these three calculations at the same ti
a.suchit
2014/12/10 04:27:42
Done.
a.suchit
2014/12/10 04:27:42
Readability and clarification.
| |
531 if (effectedRowByExtraHeight >= cellRowIndex && effectedRowByExtraHeight < endRow) | |
532 totalRowspanCellHeight += extraHeightToPropagate; | |
533 | |
534 if (totalRowspanCellHeight < cell->logicalHeightForRowSizing()) { | |
535 unsigned extraHeightRequired = rowSpanCell.cells[0]->logicalHeightFo rRowSizing() - totalRowspanCellHeight; | |
dsinclair
2014/12/03 19:25:23
We use cell above and rowSpanCell.cells[0] here, c
a.suchit
2014/12/10 04:27:42
Done.
| |
536 int remainder = extraHeightRequired % spanningCellsRowsCountHavingZe roHeight; | |
537 | |
538 if (remainder) | |
539 extraHeightRequired += spanningCellsRowsCountHavingZeroHeight - remainder; | |
dsinclair
2014/12/03 19:25:22
Why do rows having zero height effect the height r
a.suchit
2014/12/10 04:27:42
Just assume a example here :
spanning cell have 7
| |
540 | |
541 rowHeight = std::max(rowHeight, extraHeightRequired / spanningCellsR owsCountHavingZeroHeight); | |
542 } | |
532 } | 543 } |
533 | 544 |
534 return rowHeight; | 545 return rowHeight; |
535 } | 546 } |
536 | 547 |
537 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight) | 548 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight, unsigned& extraHeightToPr opagate, Vector<int>& rowsCountWithOnlySpanningCells) |
538 { | 549 { |
539 ASSERT(spanningRowsHeight.rowHeight.size()); | 550 ASSERT(spanningRowsHeight.rowHeight.size()); |
540 | 551 |
541 int accumulatedPositionIncrease = 0; | 552 int accumulatedPositionIncrease = 0; |
542 const unsigned rowSpan = cell->rowSpan(); | 553 const unsigned rowSpan = cell->rowSpan(); |
543 const unsigned rowIndex = cell->rowIndex(); | 554 const unsigned rowIndex = cell->rowIndex(); |
544 | 555 |
545 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); | 556 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); |
546 | 557 |
547 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { | 558 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { |
548 unsigned actualRow = row + rowIndex; | 559 unsigned actualRow = row + rowIndex; |
549 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row) && isHeightNeededForRowHavingOnlySpanningCells(actualRow)) { | 560 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row)) { |
550 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow); | 561 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow, accumulatedPositionIncrease, rowIndex + rowSpan, extraHeightToPr opagate, rowsCountWithOnlySpanningCells); |
551 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; | 562 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; |
552 } | 563 } |
553 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; | 564 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; |
554 } | 565 } |
555 | 566 |
556 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; | 567 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; |
557 } | 568 } |
558 | 569 |
559 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if | 570 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if |
560 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll | 571 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll |
561 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) | 572 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) |
562 { | 573 { |
563 ASSERT(rowSpanCells.size()); | 574 ASSERT(rowSpanCells.size()); |
564 | 575 |
565 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce nding order | 576 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce nding order |
566 // Arrange row spanning cell in the order in which we need to process first. | 577 // Arrange row spanning cell in the order in which we need to process first. |
567 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder); | 578 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder); |
568 | 579 |
569 unsigned extraHeightToPropagate = 0; | 580 unsigned extraHeightToPropagate = 0; |
570 unsigned lastRowIndex = 0; | 581 unsigned lastRowIndex = 0; |
571 unsigned lastRowSpan = 0; | 582 unsigned lastRowSpan = 0; |
572 | 583 |
584 Vector<int> rowsCountWithOnlySpanningCells; | |
585 | |
586 // At this stage, Height of the rows are zero for the one containing only sp anning cells. | |
587 int count = 0; | |
588 for (unsigned row = 0; row < m_grid.size(); row++) { | |
589 if (rowHasOnlySpanningCells(row)) | |
590 count++; | |
591 rowsCountWithOnlySpanningCells.append(count); | |
592 } | |
593 | |
573 for (unsigned i = 0; i < rowSpanCells.size(); i++) { | 594 for (unsigned i = 0; i < rowSpanCells.size(); i++) { |
574 RenderTableCell* cell = rowSpanCells[i]; | 595 RenderTableCell* cell = rowSpanCells[i]; |
575 | 596 |
576 unsigned rowIndex = cell->rowIndex(); | 597 unsigned rowIndex = cell->rowIndex(); |
577 | 598 |
578 unsigned rowSpan = cell->rowSpan(); | 599 unsigned rowSpan = cell->rowSpan(); |
579 | 600 |
580 unsigned spanningCellEndIndex = rowIndex + rowSpan; | 601 unsigned spanningCellEndIndex = rowIndex + rowSpan; |
581 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; | 602 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; |
582 | 603 |
(...skipping 17 matching lines...) Expand all Loading... | |
600 | 621 |
601 lastRowIndex = rowIndex; | 622 lastRowIndex = rowIndex; |
602 lastRowSpan = rowSpan; | 623 lastRowSpan = rowSpan; |
603 | 624 |
604 struct SpanningRowsHeight spanningRowsHeight; | 625 struct SpanningRowsHeight spanningRowsHeight; |
605 | 626 |
606 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); | 627 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); |
607 | 628 |
608 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell. | 629 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell. |
609 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) | 630 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) |
610 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight); | 631 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight, ex traHeightToPropagate, rowsCountWithOnlySpanningCells); |
611 | 632 |
612 // This code handle row(s) that have rowspanning cell(s) and at least on e empty cell. | 633 // This code handle row(s) that have rowspanning cell(s) and at least on e empty cell. |
613 // Such rows are not handled below and end up having a height of 0. That would mean | 634 // Such rows are not handled below and end up having a height of 0. That would mean |
614 // content overlapping if one of their cells has any content. To avoid t he problem, we | 635 // content overlapping if one of their cells has any content. To avoid t he problem, we |
615 // add all the remaining spanning cells' height to the last spanned row. | 636 // add all the remaining spanning cells' height to the last spanned row. |
616 // This means that we could grow a row past its 'height' or break percen tage spreading | 637 // This means that we could grow a row past its 'height' or break percen tage spreading |
617 // however this is better than overlapping content. | 638 // however this is better than overlapping content. |
618 // FIXME: Is there a better algorithm? | 639 // FIXME: Is there a better algorithm? |
619 if (!spanningRowsHeight.totalRowsHeight) { | 640 if (!spanningRowsHeight.totalRowsHeight) { |
620 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) | 641 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1613 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691). | 1634 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691). |
1614 if (!style()->isLeftToRightDirection()) | 1635 if (!style()->isLeftToRightDirection()) |
1615 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); | 1636 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); |
1616 else | 1637 else |
1617 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); | 1638 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); |
1618 | 1639 |
1619 cell->setLogicalLocation(cellLocation); | 1640 cell->setLogicalLocation(cellLocation); |
1620 } | 1641 } |
1621 | 1642 |
1622 } // namespace blink | 1643 } // namespace blink |
OLD | NEW |