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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutTableSection.cpp

Issue 2884763003: Combine and simplify LayoutTableSection::DirtiedRows() and DirtiedEffectiveColumns() (Closed)
Patch Set: Rebase on origin/master Created 3 years, 7 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. 7 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 9 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
10 * 10 *
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 const Vector<int>& column_pos = Table()->EffectiveColumnPositions(); 1515 const Vector<int>& column_pos = Table()->EffectiveColumnPositions();
1516 // FIXME: The table's direction should determine our row's direction, not the 1516 // FIXME: The table's direction should determine our row's direction, not the
1517 // section's (see bug 96691). 1517 // section's (see bug 96691).
1518 if (!Style()->IsLeftToRightDirection()) 1518 if (!Style()->IsLeftToRightDirection())
1519 table_aligned_rect.SetX(column_pos[column_pos.size() - 1] - 1519 table_aligned_rect.SetX(column_pos[column_pos.size() - 1] -
1520 table_aligned_rect.MaxX()); 1520 table_aligned_rect.MaxX());
1521 1521
1522 return table_aligned_rect; 1522 return table_aligned_rect;
1523 } 1523 }
1524 1524
1525 CellSpan LayoutTableSection::DirtiedRows(const LayoutRect& damage_rect) const { 1525 void LayoutTableSection::DirtiedRowsAndEffectiveColumns(
1526 if (force_full_paint_) 1526 const LayoutRect& damage_rect,
1527 return FullSectionRowSpan(); 1527 CellSpan& rows,
1528 CellSpan& columns) const {
1529 if (!grid_.size()) {
1530 rows = CellSpan();
1531 columns = CellSpan();
dgrogan 2017/08/10 02:30:02 wkorman, could you take another look at this? Seem
1532 }
1528 1533
1529 if (!grid_.size()) 1534 if (force_full_paint_) {
1530 return CellSpan(0, 0); 1535 rows = FullSectionRowSpan();
1536 columns = FullTableEffectiveColumnSpan();
1537 return;
1538 }
1531 1539
1532 CellSpan covered_rows = SpannedRows(damage_rect); 1540 rows = SpannedRows(damage_rect);
1541 columns = SpannedEffectiveColumns(damage_rect);
1533 1542
1534 // To paint the border we might need to paint the first or last row even if 1543 // Expand by one cell in each direction to cover any collapsed borders.
1535 // they are not spanned themselves. 1544 if (Table()->ShouldCollapseBorders()) {
1536 CHECK_LT(covered_rows.Start(), row_pos_.size()); 1545 if (rows.Start() > 0)
1537 if (covered_rows.Start() == row_pos_.size() - 1 && 1546 rows.DecreaseStart();
1538 row_pos_[row_pos_.size() - 1] + Table()->OuterBorderAfter() >= 1547 if (rows.End() < grid_.size())
1539 damage_rect.Y()) 1548 rows.IncreaseEnd();
1540 covered_rows.DecreaseStart(); 1549 if (columns.Start() > 0)
1550 columns.DecreaseStart();
1551 if (columns.End() < Table()->NumEffectiveColumns())
1552 columns.IncreaseEnd();
1553 }
1541 1554
1542 if (!covered_rows.end() && 1555 rows.EnsureConsistency(grid_.size());
1543 row_pos_[0] - Table()->OuterBorderBefore() <= damage_rect.MaxY()) 1556 columns.EnsureConsistency(Table()->NumEffectiveColumns());
1544 covered_rows.IncreaseEnd();
1545 1557
1546 covered_rows.EnsureConsistency(grid_.size()); 1558 if (!has_spanning_cells_)
1547 if (!has_spanning_cells_ || !covered_rows.Start() || 1559 return;
1548 covered_rows.Start() >= grid_.size())
1549 return covered_rows;
1550 1560
1551 // If there are any cells spanning into the first row, expand covered_rows 1561 if (rows.Start() > 0 && rows.Start() < grid_.size()) {
1552 // to cover the primary cells. 1562 // If there are any cells spanning into the first row, expand |rows| to
1553 unsigned n_cols = NumCols(covered_rows.Start()); 1563 // cover the cells.
1554 unsigned smallest_row = covered_rows.Start(); 1564 unsigned n_cols = NumCols(rows.Start());
1555 CellSpan covered_columns = SpannedEffectiveColumns(damage_rect); 1565 unsigned smallest_row = rows.Start();
1556 for (unsigned c = covered_columns.Start(); 1566 for (unsigned c = columns.Start(); c < std::min(columns.End(), n_cols);
1557 c < std::min(covered_columns.end(), n_cols); ++c) { 1567 ++c) {
1558 if (const auto* cell = PrimaryCellAt(covered_rows.Start(), c)) { 1568 for (const auto* cell : GridCellAt(rows.Start(), c).Cells()) {
1559 smallest_row = std::min(smallest_row, cell->RowIndex()); 1569 smallest_row = std::min(smallest_row, cell->RowIndex());
1560 if (!smallest_row) 1570 if (!smallest_row)
1561 break; 1571 break;
1572 }
1562 } 1573 }
1574 rows = CellSpan(smallest_row, rows.End());
1563 } 1575 }
1564 return CellSpan(smallest_row, covered_rows.end());
1565 }
1566 1576
1567 CellSpan LayoutTableSection::DirtiedEffectiveColumns( 1577 if (columns.Start() > 0 && columns.Start() < Table()->NumEffectiveColumns()) {
1568 const LayoutRect& damage_rect) const { 1578 // If there are any cells spanning into the first column, expand |columns|
1569 if (force_full_paint_) 1579 // to cover the cells.
1570 return FullTableEffectiveColumnSpan(); 1580 unsigned smallest_column = columns.Start();
1571 1581 for (unsigned r = rows.Start(); r < rows.End(); ++r) {
1572 CHECK(Table()->NumEffectiveColumns()); 1582 const auto& grid_cells = grid_[r].grid_cells;
1573 CellSpan covered_columns = SpannedEffectiveColumns(damage_rect); 1583 if (columns.Start() < grid_cells.size()) {
1574 1584 unsigned c = columns.Start();
1575 const Vector<int>& column_pos = Table()->EffectiveColumnPositions(); 1585 while (c && grid_cells[c].InColSpan())
1576 // To paint the border we might need to paint the first or last column even if 1586 --c;
1577 // they are not spanned themselves. 1587 smallest_column = std::min(c, smallest_column);
1578 CHECK_LT(covered_columns.Start(), column_pos.size()); 1588 if (!smallest_column)
1579 if (covered_columns.Start() == column_pos.size() - 1 && 1589 break;
1580 column_pos[column_pos.size() - 1] + Table()->OuterBorderEnd() >= 1590 }
1581 damage_rect.X())
1582 covered_columns.DecreaseStart();
1583
1584 if (!covered_columns.end() &&
1585 column_pos[0] - Table()->OuterBorderStart() <= damage_rect.MaxX())
1586 covered_columns.IncreaseEnd();
1587
1588 covered_columns.EnsureConsistency(Table()->NumEffectiveColumns());
1589 if (!has_spanning_cells_ || !covered_columns.Start())
1590 return covered_columns;
1591
1592 // If there are any cells spanning into the first column, expand
1593 // covered_columns to cover the primary cells.
1594 unsigned smallest_column = covered_columns.Start();
1595 CellSpan covered_rows = SpannedRows(damage_rect);
1596 for (unsigned r = covered_rows.Start(); r < covered_rows.end(); ++r) {
1597 const auto& grid_cells = grid_[r].grid_cells;
1598 if (covered_columns.Start() < grid_cells.size()) {
1599 unsigned c = covered_columns.Start();
1600 while (c && grid_cells[c].InColSpan())
1601 --c;
1602 smallest_column = std::min(c, smallest_column);
1603 if (!smallest_column)
1604 break;
1605 } 1591 }
1592 columns = CellSpan(smallest_column, columns.End());
1606 } 1593 }
1607 return CellSpan(smallest_column, covered_columns.end());
1608 } 1594 }
1609 1595
1610 CellSpan LayoutTableSection::SpannedRows(const LayoutRect& flipped_rect) const { 1596 CellSpan LayoutTableSection::SpannedRows(const LayoutRect& flipped_rect) const {
1611 // Find the first row that starts after rect top. 1597 // Find the first row that starts after rect top.
1612 unsigned next_row = 1598 unsigned next_row =
1613 std::upper_bound(row_pos_.begin(), row_pos_.end(), flipped_rect.Y()) - 1599 std::upper_bound(row_pos_.begin(), row_pos_.end(), flipped_rect.Y()) -
1614 row_pos_.begin(); 1600 row_pos_.begin();
1615 1601
1616 // After all rows. 1602 // After all rows.
1617 if (next_row == row_pos_.size()) 1603 if (next_row == row_pos_.size())
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 1841
1856 LayoutRect hit_test_rect = LayoutRect(location_in_container.BoundingBox()); 1842 LayoutRect hit_test_rect = LayoutRect(location_in_container.BoundingBox());
1857 hit_test_rect.MoveBy(-adjusted_location); 1843 hit_test_rect.MoveBy(-adjusted_location);
1858 1844
1859 LayoutRect table_aligned_rect = 1845 LayoutRect table_aligned_rect =
1860 LogicalRectForWritingModeAndDirection(hit_test_rect); 1846 LogicalRectForWritingModeAndDirection(hit_test_rect);
1861 CellSpan row_span = SpannedRows(table_aligned_rect); 1847 CellSpan row_span = SpannedRows(table_aligned_rect);
1862 CellSpan column_span = SpannedEffectiveColumns(table_aligned_rect); 1848 CellSpan column_span = SpannedEffectiveColumns(table_aligned_rect);
1863 1849
1864 // Now iterate over the spanned rows and columns. 1850 // Now iterate over the spanned rows and columns.
1865 for (unsigned hit_row = row_span.Start(); hit_row < row_span.end(); 1851 for (unsigned hit_row = row_span.Start(); hit_row < row_span.End();
1866 ++hit_row) { 1852 ++hit_row) {
1867 unsigned n_cols = NumCols(hit_row); 1853 unsigned n_cols = NumCols(hit_row);
1868 for (unsigned hit_column = column_span.Start(); 1854 for (unsigned hit_column = column_span.Start();
1869 hit_column < n_cols && hit_column < column_span.end(); ++hit_column) { 1855 hit_column < n_cols && hit_column < column_span.End(); ++hit_column) {
1870 auto& grid_cell = GridCellAt(hit_row, hit_column); 1856 auto& grid_cell = GridCellAt(hit_row, hit_column);
1871 1857
1872 // If the cell is empty, there's nothing to do 1858 // If the cell is empty, there's nothing to do
1873 if (!grid_cell.HasCells()) 1859 if (!grid_cell.HasCells())
1874 continue; 1860 continue;
1875 1861
1876 for (unsigned i = grid_cell.Cells().size(); i;) { 1862 for (unsigned i = grid_cell.Cells().size(); i;) {
1877 --i; 1863 --i;
1878 LayoutTableCell* cell = grid_cell.Cells()[i]; 1864 LayoutTableCell* cell = grid_cell.Cells()[i];
1879 LayoutPoint cell_point = 1865 LayoutPoint cell_point =
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 bool LayoutTableSection::PaintedOutputOfObjectHasNoEffectRegardlessOfSize() 2125 bool LayoutTableSection::PaintedOutputOfObjectHasNoEffectRegardlessOfSize()
2140 const { 2126 const {
2141 // LayoutTableSection paints background from columns. 2127 // LayoutTableSection paints background from columns.
2142 if (Table()->HasColElements()) 2128 if (Table()->HasColElements())
2143 return false; 2129 return false;
2144 return LayoutTableBoxComponent:: 2130 return LayoutTableBoxComponent::
2145 PaintedOutputOfObjectHasNoEffectRegardlessOfSize(); 2131 PaintedOutputOfObjectHasNoEffectRegardlessOfSize();
2146 } 2132 }
2147 2133
2148 } // namespace blink 2134 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698