Chromium Code Reviews| 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 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, unsigned& extraHeightToPropagate, unsigned r1, int& accumulatedPositionIncrease, unsigned r2, Vector<int>& rowsCountWithOnlySpanningCells) |
|
Julien - ping for review
2014/10/08 00:16:08
r1 and r2 are not good variable names :(
Also thi
a.suchit
2014/10/08 11:30:08
changed and name of r1 variable
I did not observe
| |
| 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()) { |
| 503 RenderTableCell* cell = rowSpanCell.cells[0]; | |
| 504 | |
| 505 if (cell->rowSpan() > 1) { | |
| 506 const unsigned rowIndex = cell->rowIndex(); | |
| 507 const unsigned rowSpan = cell->rowSpan(); | |
| 508 | |
| 509 unsigned endRow = rowIndex + rowSpan; | |
| 510 unsigned spanningCellsRowsCountHavingZeroHeight = rowsCountWithO nlySpanningCells[endRow -1] - rowsCountWithOnlySpanningCells[max(rowIndex, row)] ; | |
|
Julien - ping for review
2014/10/08 00:16:08
max(rowIndex, row) is repeated 4 times, it seems l
a.suchit
2014/10/08 11:30:08
Done.
| |
| 511 | |
| 512 if (max(rowIndex, row)) { | |
| 513 spanningCellsRowsCountHavingZeroHeight += rowsCountWithOnlyS panningCells[max(rowIndex, row)] - rowsCountWithOnlySpanningCells[max(rowIndex, row) - 1]; | |
|
Julien - ping for review
2014/10/08 00:16:08
I am probably confused by this line but it seems d
a.suchit
2014/10/08 11:30:08
Acknowledged.
| |
| 514 } else { | |
| 515 spanningCellsRowsCountHavingZeroHeight += rowsCountWithOnlyS panningCells[0]; | |
|
Julien - ping for review
2014/10/08 00:16:08
This else is suspicious, I don't see why some cell
a.suchit
2014/10/08 11:30:08
Acknowledged.
| |
| 516 } | |
| 517 | |
| 518 int totalRowspanCellHeight = m_rowPos[rowIndex + rowSpan] - m_ro wPos[rowIndex]; | |
| 519 | |
| 520 totalRowspanCellHeight -= borderSpacingForRow(rowIndex + rowSpan - 1); | |
| 521 if (r1 > rowIndex && r1 < endRow) | |
| 522 totalRowspanCellHeight += extraHeightToPropagate; | |
| 523 if (r2 > rowIndex && r2 < endRow) | |
| 524 totalRowspanCellHeight += accumulatedPositionIncrease; | |
| 525 | |
| 526 if (totalRowspanCellHeight < cell->logicalHeightForRowSizing()) { | |
| 527 unsigned extraHeightRequired = rowSpanCell.cells[0]->logical HeightForRowSizing() - totalRowspanCellHeight; | |
| 528 int remainder = extraHeightRequired % spanningCellsRowsCount HavingZeroHeight; | |
| 529 | |
| 530 if (remainder) | |
| 531 extraHeightRequired += spanningCellsRowsCountHavingZeroH eight - remainder; | |
| 532 | |
| 533 rowHeight = std::max(rowHeight, extraHeightRequired / spanni ngCellsRowsCountHavingZeroHeight); | |
| 534 } | |
| 535 } | |
| 536 } | |
| 533 } | 537 } |
| 534 | 538 |
| 535 return rowHeight; | 539 return rowHeight; |
| 536 } | 540 } |
| 537 | 541 |
| 538 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight) | 542 void RenderTableSection::updateRowsHeightHavingOnlySpanningCells(RenderTableCell * cell, struct SpanningRowsHeight& spanningRowsHeight, unsigned& extraHeightToPr opagate, Vector<int>& rowsCountWithOnlySpanningCells) |
| 539 { | 543 { |
| 540 ASSERT(spanningRowsHeight.rowHeight.size()); | 544 ASSERT(spanningRowsHeight.rowHeight.size()); |
| 541 | 545 |
| 542 int accumulatedPositionIncrease = 0; | 546 int accumulatedPositionIncrease = 0; |
| 543 const unsigned rowSpan = cell->rowSpan(); | 547 const unsigned rowSpan = cell->rowSpan(); |
| 544 const unsigned rowIndex = cell->rowIndex(); | 548 const unsigned rowIndex = cell->rowIndex(); |
| 545 | 549 |
| 546 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); | 550 ASSERT_UNUSED(rowSpan, rowSpan == spanningRowsHeight.rowHeight.size()); |
| 547 | 551 |
| 548 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { | 552 for (unsigned row = 0; row < spanningRowsHeight.rowHeight.size(); row++) { |
| 549 unsigned actualRow = row + rowIndex; | 553 unsigned actualRow = row + rowIndex; |
| 550 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row) && isHeightNeededForRowHavingOnlySpanningCells(actualRow)) { | 554 if (!spanningRowsHeight.rowHeight[row] && rowHasOnlySpanningCells(actual Row)) { |
| 551 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow); | 555 spanningRowsHeight.rowHeight[row] = calcRowHeightHavingOnlySpanningC ells(actualRow, extraHeightToPropagate, rowIndex + rowSpan, accumulatedPositionI ncrease, actualRow, rowsCountWithOnlySpanningCells); |
| 552 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; | 556 accumulatedPositionIncrease += spanningRowsHeight.rowHeight[row]; |
| 553 } | 557 } |
| 554 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; | 558 m_rowPos[actualRow + 1] += accumulatedPositionIncrease; |
| 555 } | 559 } |
| 556 | 560 |
| 557 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; | 561 spanningRowsHeight.totalRowsHeight += accumulatedPositionIncrease; |
| 558 } | 562 } |
| 559 | 563 |
| 560 // Distribute rowSpan cell height in rows those comes in rowSpan cell based on t he ratio of row's height if | 564 // 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 | 565 // 1. RowSpan cell height is greater then the total height of rows in rowSpan ce ll |
| 562 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) | 566 void RenderTableSection::distributeRowSpanHeightToRows(SpanningRenderTableCells& rowSpanCells) |
| 563 { | 567 { |
| 564 ASSERT(rowSpanCells.size()); | 568 ASSERT(rowSpanCells.size()); |
| 565 | 569 |
| 566 // 'rowSpanCells' list is already sorted based on the cells rowIndex in asce nding order | 570 // '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. | 571 // Arrange row spanning cell in the order in which we need to process first. |
| 568 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder); | 572 std::sort(rowSpanCells.begin(), rowSpanCells.end(), compareRowSpanCellsInHei ghtDistributionOrder); |
| 569 | 573 |
| 570 unsigned extraHeightToPropagate = 0; | 574 unsigned extraHeightToPropagate = 0; |
| 571 unsigned lastRowIndex = 0; | 575 unsigned lastRowIndex = 0; |
| 572 unsigned lastRowSpan = 0; | 576 unsigned lastRowSpan = 0; |
| 573 | 577 |
| 578 Vector<int> rowsCountWithOnlySpanningCells; | |
| 579 | |
| 580 // At this stage, Height of the rows are zero those contains only spanning c ells. | |
|
Julien - ping for review
2014/10/08 00:16:08
Let's do correct English sentence:
// At this sta
a.suchit
2014/10/08 11:30:08
Done.
| |
| 581 int count = 0; | |
| 582 for (unsigned row = 0; row < m_grid.size(); row++) { | |
| 583 if (rowHasOnlySpanningCells(row)) | |
| 584 count++; | |
| 585 rowsCountWithOnlySpanningCells.append(count); | |
| 586 } | |
|
Julien - ping for review
2014/10/08 00:16:08
You've added an unrelated O(N) loop here inside a
a.suchit
2014/10/08 11:30:08
If it is not done here then repeatedly, need to ch
| |
| 587 | |
| 574 for (unsigned i = 0; i < rowSpanCells.size(); i++) { | 588 for (unsigned i = 0; i < rowSpanCells.size(); i++) { |
| 575 RenderTableCell* cell = rowSpanCells[i]; | 589 RenderTableCell* cell = rowSpanCells[i]; |
| 576 | 590 |
| 577 unsigned rowIndex = cell->rowIndex(); | 591 unsigned rowIndex = cell->rowIndex(); |
| 578 | 592 |
| 579 unsigned rowSpan = cell->rowSpan(); | 593 unsigned rowSpan = cell->rowSpan(); |
| 580 | 594 |
| 581 unsigned spanningCellEndIndex = rowIndex + rowSpan; | 595 unsigned spanningCellEndIndex = rowIndex + rowSpan; |
| 582 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; | 596 unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan; |
| 583 | 597 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 601 | 615 |
| 602 lastRowIndex = rowIndex; | 616 lastRowIndex = rowIndex; |
| 603 lastRowSpan = rowSpan; | 617 lastRowSpan = rowSpan; |
| 604 | 618 |
| 605 struct SpanningRowsHeight spanningRowsHeight; | 619 struct SpanningRowsHeight spanningRowsHeight; |
| 606 | 620 |
| 607 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); | 621 populateSpanningRowsHeightFromCell(cell, spanningRowsHeight); |
| 608 | 622 |
| 609 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell. | 623 // Here we are handling only row(s) who have only rowspanning cells and do not have any empty cell. |
| 610 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) | 624 if (spanningRowsHeight.isAnyRowWithOnlySpanningCells) |
| 611 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight); | 625 updateRowsHeightHavingOnlySpanningCells(cell, spanningRowsHeight, ex traHeightToPropagate, rowsCountWithOnlySpanningCells); |
| 612 | 626 |
| 613 // This code handle row(s) that have rowspanning cell(s) and at least on e empty cell. | 627 // 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 | 628 // 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 | 629 // 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. | 630 // 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 | 631 // This means that we could grow a row past its 'height' or break percen tage spreading |
| 618 // however this is better than overlapping content. | 632 // however this is better than overlapping content. |
| 619 // FIXME: Is there a better algorithm? | 633 // FIXME: Is there a better algorithm? |
| 620 if (!spanningRowsHeight.totalRowsHeight) { | 634 if (!spanningRowsHeight.totalRowsHeight) { |
| 621 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) | 635 if (spanningRowsHeight.spanningCellHeightIgnoringBorderSpacing) |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1610 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691). | 1624 // FIXME: The table's direction should determine our row's direction, not th e section's (see bug 96691). |
| 1611 if (!style()->isLeftToRightDirection()) | 1625 if (!style()->isLeftToRightDirection()) |
| 1612 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); | 1626 cellLocation.setX(table()->columnPositions()[table()->numEffCols()] - ta ble()->columnPositions()[table()->colToEffCol(cell->col() + cell->colSpan())] + horizontalBorderSpacing); |
| 1613 else | 1627 else |
| 1614 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); | 1628 cellLocation.setX(table()->columnPositions()[effectiveColumn] + horizont alBorderSpacing); |
| 1615 | 1629 |
| 1616 cell->setLogicalLocation(cellLocation); | 1630 cell->setLogicalLocation(cellLocation); |
| 1617 } | 1631 } |
| 1618 | 1632 |
| 1619 } // namespace blink | 1633 } // namespace blink |
| OLD | NEW |