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& accumulatedCellPositionIncrease, unsigned rowToApplyExtraHeight, unsigned&
extraTableHeightToPropgate, Vector<int>& rowsCountWithOnlySpanningCells) |
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() < 2) |
| 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 = std::max(cellRowIndex, row); |
| 517 unsigned endRow = cellRowIndex + cellRowSpan; |
| 518 unsigned spanningCellsRowsCountHavingZeroHeight = rowsCountWithOnlySpann
ingCells[endRow - 1]; |
| 519 |
| 520 if (startRowForSpanningCellCount) |
| 521 spanningCellsRowsCountHavingZeroHeight -= rowsCountWithOnlySpanningC
ells[startRowForSpanningCellCount - 1]; |
| 522 |
| 523 int totalRowspanCellHeight = (m_rowPos[endRow] - m_rowPos[cellRowIndex])
- borderSpacingForRow(endRow - 1); |
| 524 |
| 525 totalRowspanCellHeight += accumulatedCellPositionIncrease; |
| 526 if (rowToApplyExtraHeight >= cellRowIndex && rowToApplyExtraHeight < end
Row) |
| 527 totalRowspanCellHeight += extraTableHeightToPropgate; |
| 528 |
| 529 if (totalRowspanCellHeight < cell->logicalHeightForRowSizing()) { |
| 530 unsigned extraHeightRequired = cell->logicalHeightForRowSizing() - t
otalRowspanCellHeight; |
| 531 |
| 532 rowHeight = std::max(rowHeight, extraHeightRequired / spanningCellsR
owsCountHavingZeroHeight); |
| 533 } |
532 } | 534 } |
533 | 535 |
534 return rowHeight; | 536 return rowHeight; |
535 } | 537 } |
536 | 538 |
537 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell
* cell, struct SpanningRowsHeight& spanningRowsHeight) | 539 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell
* cell, struct SpanningRowsHeight& spanningRowsHeight, unsigned& extraHeightToPr
opagate, Vector<int>& rowsCountWithOnlySpanningCells) |
538 { | 540 { |
539 ASSERT(spanningRowsHeight.rowHeight.size()); | 541 ASSERT(spanningRowsHeight.rowHeight.size()); |
540 | 542 |
541 int accumulatedPositionIncrease = 0; | 543 int accumulatedPositionIncrease = 0; |
542 const unsigned rowSpan = cell->rowSpan(); | 544 const unsigned rowSpan = cell->rowSpan(); |
543 const unsigned rowIndex = cell->rowIndex(); | 545 const unsigned rowIndex = cell->rowIndex(); |
544 | 546 |
545 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); | 547 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); |
546 | 548 |
547 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { | 549 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { |
548 unsigned actualRow = row + rowIndex; | 550 unsigned actualRow = row + rowIndex; |
549 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual
Row) && isHeightNeededForRowHavingOnlySpanningCells(actualRow)) { | 551 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual
Row)) { |
550 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC
ells(actualRow); | 552 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC
ells(actualRow, accumulatedPositionIncrease, rowIndex + rowSpan, extraHeightToPr
opagate, rowsCountWithOnlySpanningCells); |
551 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; | 553 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; |
552 } | 554 } |
553 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; | 555 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; |
554 } | 556 } |
555 | 557 |
556 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; | 558 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; |
557 } | 559 } |
558 | 560 |
559 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t
he ratio of row's height if | 561 // 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 | 562 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce
ll |
561 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells&
rowSpanCells) | 563 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells&
rowSpanCells) |
562 { | 564 { |
563 ASSERT(rowSpanCells.size()); | 565 ASSERT(rowSpanCells.size()); |
564 | 566 |
565 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce
nding order | 567 // '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. | 568 // Arrange row spanning cell in the order in which we need to process first. |
567 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei
ghtDistributionOrder); | 569 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei
ghtDistributionOrder); |
568 | 570 |
569 unsigned extraHeightToPropagate = 0; | 571 unsigned extraHeightToPropagate = 0; |
570 unsigned lastRowIndex = 0; | 572 unsigned lastRowIndex = 0; |
571 unsigned lastRowSpan = 0; | 573 unsigned lastRowSpan = 0; |
572 | 574 |
| 575 Vector<int> rowsCountWithOnlySpanningCells; |
| 576 |
| 577 // At this stage, Height of the rows are zero for the one containing only sp
anning cells. |
| 578 int count = 0; |
| 579 for (unsigned row = 0; row < m_grid.size(); row++) { |
| 580 if (rowHasOnlySpanningCells(row)) |
| 581 count++; |
| 582 rowsCountWithOnlySpanningCells.append(count); |
| 583 } |
| 584 |
573 for (unsigned i = 0; i < rowSpanCells.size(); i++) { | 585 for (unsigned i = 0; i < rowSpanCells.size(); i++) { |
574 RenderTableCell* cell = rowSpanCells[i]; | 586 RenderTableCell* cell = rowSpanCells[i]; |
575 | 587 |
576 unsigned rowIndex = cell->rowIndex(); | 588 unsigned rowIndex = cell->rowIndex(); |
577 | 589 |
578 unsigned rowSpan = cell->rowSpan(); | 590 unsigned rowSpan = cell->rowSpan(); |
579 | 591 |
580 unsigned spanningCellEndIndex = rowIndex + rowSpan; | 592 unsigned spanningCellEndIndex = rowIndex + rowSpan; |
581 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; | 593 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; |
582 | 594 |
(...skipping 17 matching lines...) Expand all Loading... |
600 | 612 |
601 lastRowIndex = rowIndex; | 613 lastRowIndex = rowIndex; |
602 lastRowSpan = rowSpan; | 614 lastRowSpan = rowSpan; |
603 | 615 |
604 struct SpanningRowsHeight spanningRowsHeight; | 616 struct SpanningRowsHeight spanningRowsHeight; |
605 | 617 |
606 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); | 618 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); |
607 | 619 |
608 // Here we are handling only row(s) who have only rowspanning cells and
do not have any empty cell. | 620 // Here we are handling only row(s) who have only rowspanning cells and
do not have any empty cell. |
609 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) | 621 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) |
610 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight); | 622 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight, ex
traHeightToPropagate, rowsCountWithOnlySpanningCells); |
611 | 623 |
612 // This code handle row(s) that have rowspanning cell(s) and at least on
e empty cell. | 624 // 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 | 625 // 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 | 626 // 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. | 627 // 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 | 628 // This means that we could grow a row past its 'height' or break percen
tage spreading |
617 // however this is better than overlapping content. | 629 // however this is better than overlapping content. |
618 // FIXME: Is there a better algorithm? | 630 // FIXME: Is there a better algorithm? |
619 if (!spanningRowsHeight.totalRowsHeight) { | 631 if (!spanningRowsHeight.totalRowsHeight) { |
620 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) | 632 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 // FIXME: The table's direction should determine our row's direction, not th
e section's (see bug 96691). | 1627 // FIXME: The table's direction should determine our row's direction, not th
e section's (see bug 96691). |
1616 if (!style()->isLeftToRightDirection()) | 1628 if (!style()->isLeftToRightDirection()) |
1617 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta
ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] +
horizontalBorderSpacing); | 1629 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta
ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] +
horizontalBorderSpacing); |
1618 else | 1630 else |
1619 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont
alBorderSpacing); | 1631 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont
alBorderSpacing); |
1620 | 1632 |
1621 cell->setLogicalLocation(cellLocation); | 1633 cell->setLogicalLocation(cellLocation); |
1622 } | 1634 } |
1623 | 1635 |
1624 } // namespace blink | 1636 } // namespace blink |
OLD | NEW |