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

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

Issue 2392353002: Move table cell height flexing into a separate method. (Closed)
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutTableSection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 CellStruct& cs = cellAt(r, c); 1126 CellStruct& cs = cellAt(r, c);
1127 LayoutTableCell* cell = cs.primaryCell(); 1127 LayoutTableCell* cell = cs.primaryCell();
1128 1128
1129 if (!cell || cs.inColSpan) 1129 if (!cell || cs.inColSpan)
1130 continue; 1130 continue;
1131 1131
1132 int rowIndex = cell->rowIndex(); 1132 int rowIndex = cell->rowIndex();
1133 int rHeight = 1133 int rHeight =
1134 m_rowPos[rowIndex + cell->rowSpan()] - m_rowPos[rowIndex] - vspacing; 1134 m_rowPos[rowIndex + cell->rowSpan()] - m_rowPos[rowIndex] - vspacing;
1135 1135
1136 // Force percent height children to lay themselves out again. 1136 relayoutCellIfFlexed(*cell, r, rHeight);
1137 // This will cause these children to grow to fill the cell.
1138 // FIXME: There is still more work to do here to fully match WinIE (should
1139 // it become necessary to do so). In quirks mode, WinIE behaves like we
1140 // do, but it will clip the cells that spill out of the table section. In
1141 // strict mode, Mozilla and WinIE both regrow the table to accommodate the
1142 // new height of the cell (thus letting the percentages cause growth one
1143 // time only). We may also not be handling row-spanning cells correctly.
1144 //
1145 // Note also the oddity where replaced elements always flex, and yet block s/tables do
1146 // not necessarily flex. WinIE is crazy and inconsistent, and we can't ho pe to
1147 // match the behavior perfectly, but we'll continue to refine it as we dis cover new
1148 // bugs. :)
1149 bool cellChildrenFlex = false;
1150 bool flexAllChildren = cell->style()->logicalHeight().isFixed() ||
1151 (!table()->style()->logicalHeight().isAuto() &&
1152 rHeight != cell->logicalHeight());
1153
1154 for (LayoutObject* child = cell->firstChild(); child;
1155 child = child->nextSibling()) {
1156 if (!child->isText() &&
1157 child->style()->logicalHeight().isPercentOrCalc() &&
1158 (flexAllChildren || shouldFlexCellChild(child)) &&
1159 (!child->isTable() || toLayoutTable(child)->hasSections())) {
1160 cellChildrenFlex = true;
1161 break;
1162 }
1163 }
1164
1165 if (!cellChildrenFlex) {
1166 if (TrackedLayoutBoxListHashSet* percentHeightDescendants =
1167 cell->percentHeightDescendants()) {
1168 for (auto* descendant : *percentHeightDescendants) {
1169 if (flexAllChildren || shouldFlexCellChild(descendant)) {
1170 cellChildrenFlex = true;
1171 break;
1172 }
1173 }
1174 }
1175 }
1176
1177 if (cellChildrenFlex) {
1178 // Alignment within a cell is based off the calculated
1179 // height, which becomes irrelevant once the cell has
1180 // been resized based off its percentage.
1181 cell->setOverrideLogicalContentHeightFromRowHeight(LayoutUnit(rHeight));
1182 cell->forceChildLayout();
1183
1184 // If the baseline moved, we may have to update the data for our row. Fi nd out the new baseline.
1185 if (cell->isBaselineAligned()) {
1186 int baseline = cell->cellBaselinePosition();
1187 if (baseline > cell->borderBefore() + cell->paddingBefore())
1188 m_grid[r].baseline = std::max(m_grid[r].baseline, baseline);
1189 }
1190 }
1191 1137
1192 SubtreeLayoutScope layouter(*cell); 1138 SubtreeLayoutScope layouter(*cell);
1193 cell->computeIntrinsicPadding(rHeight, layouter); 1139 cell->computeIntrinsicPadding(rHeight, layouter);
1194 1140
1195 LayoutRect oldCellRect = cell->frameRect(); 1141 LayoutRect oldCellRect = cell->frameRect();
1196 1142
1197 setLogicalPositionForCell(cell, c); 1143 setLogicalPositionForCell(cell, c);
1198 1144
1199 if (!cell->needsLayout()) 1145 if (!cell->needsLayout())
1200 markChildForPaginationRelayoutIfNeeded(*cell, layouter); 1146 markChildForPaginationRelayoutIfNeeded(*cell, layouter);
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 cell->absoluteColumnIndex() + cell->colSpan())] + 1839 cell->absoluteColumnIndex() + cell->colSpan())] +
1894 horizontalBorderSpacing)); 1840 horizontalBorderSpacing));
1895 else 1841 else
1896 cellLocation.setX( 1842 cellLocation.setX(
1897 LayoutUnit(table()->effectiveColumnPositions()[effectiveColumn] + 1843 LayoutUnit(table()->effectiveColumnPositions()[effectiveColumn] +
1898 horizontalBorderSpacing)); 1844 horizontalBorderSpacing));
1899 1845
1900 cell->setLogicalLocation(cellLocation); 1846 cell->setLogicalLocation(cellLocation);
1901 } 1847 }
1902 1848
1849 void LayoutTableSection::relayoutCellIfFlexed(LayoutTableCell& cell,
1850 int rowIndex,
1851 int rowHeight) {
1852 // Force percent height children to lay themselves out again.
1853 // This will cause these children to grow to fill the cell.
1854 // FIXME: There is still more work to do here to fully match WinIE (should
1855 // it become necessary to do so). In quirks mode, WinIE behaves like we
1856 // do, but it will clip the cells that spill out of the table section. In
1857 // strict mode, Mozilla and WinIE both regrow the table to accommodate the
1858 // new height of the cell (thus letting the percentages cause growth one
1859 // time only). We may also not be handling row-spanning cells correctly.
1860 //
1861 // Note also the oddity where replaced elements always flex, and yet
1862 // blocks/tables do not necessarily flex. WinIE is crazy and inconsistent,
1863 // and we can't hope to match the behavior perfectly, but we'll continue to
1864 // refine it as we discover new bugs. :)
1865 bool cellChildrenFlex = false;
1866 bool flexAllChildren = cell.style()->logicalHeight().isFixed() ||
1867 (!table()->style()->logicalHeight().isAuto() &&
1868 rowHeight != cell.logicalHeight());
1869
1870 for (LayoutObject* child = cell.firstChild(); child;
1871 child = child->nextSibling()) {
1872 if (!child->isText() && child->style()->logicalHeight().isPercentOrCalc() &&
1873 (flexAllChildren || shouldFlexCellChild(child)) &&
1874 (!child->isTable() || toLayoutTable(child)->hasSections())) {
1875 cellChildrenFlex = true;
1876 break;
1877 }
1878 }
1879
1880 if (!cellChildrenFlex) {
1881 if (TrackedLayoutBoxListHashSet* percentHeightDescendants =
1882 cell.percentHeightDescendants()) {
1883 for (auto* descendant : *percentHeightDescendants) {
1884 if (flexAllChildren || shouldFlexCellChild(descendant)) {
1885 cellChildrenFlex = true;
1886 break;
1887 }
1888 }
1889 }
1890 }
1891
1892 if (!cellChildrenFlex)
1893 return;
1894
1895 // Alignment within a cell is based off the calculated height, which becomes
1896 // irrelevant once the cell has been resized based off its percentage.
1897 cell.setOverrideLogicalContentHeightFromRowHeight(LayoutUnit(rowHeight));
1898 cell.forceChildLayout();
1899
1900 // If the baseline moved, we may have to update the data for our row. Find
1901 // out the new baseline.
1902 if (cell.isBaselineAligned()) {
1903 int baseline = cell.cellBaselinePosition();
1904 if (baseline > cell.borderBefore() + cell.paddingBefore())
1905 m_grid[rowIndex].baseline = std::max(m_grid[rowIndex].baseline, baseline);
1906 }
1907 }
1908
1903 bool LayoutTableSection::isRepeatingHeaderGroup() const { 1909 bool LayoutTableSection::isRepeatingHeaderGroup() const {
1904 if (getPaginationBreakability() == LayoutBox::AllowAnyBreaks) 1910 if (getPaginationBreakability() == LayoutBox::AllowAnyBreaks)
1905 return false; 1911 return false;
1906 // TODO(rhogan): Should we paint a header repeatedly if it's self-painting? 1912 // TODO(rhogan): Should we paint a header repeatedly if it's self-painting?
1907 if (hasSelfPaintingLayer()) 1913 if (hasSelfPaintingLayer())
1908 return false; 1914 return false;
1909 LayoutUnit pageHeight = table()->pageLogicalHeightForOffset(LayoutUnit()); 1915 LayoutUnit pageHeight = table()->pageLogicalHeightForOffset(LayoutUnit());
1910 if (!pageHeight) 1916 if (!pageHeight)
1911 return false; 1917 return false;
1912 1918
(...skipping 19 matching lines...) Expand all
1932 // Repeating table headers are painted once per fragmentation page/column. Thi s does not go through the regular fragmentation machinery, 1938 // Repeating table headers are painted once per fragmentation page/column. Thi s does not go through the regular fragmentation machinery,
1933 // so we need special code to expand the invalidation rect to contain all posi tions of the header in all columns. 1939 // so we need special code to expand the invalidation rect to contain all posi tions of the header in all columns.
1934 // Note that this is in flow thread coordinates, not visual coordinates. The e nclosing LayoutFlowThread will convert to visual coordinates. 1940 // Note that this is in flow thread coordinates, not visual coordinates. The e nclosing LayoutFlowThread will convert to visual coordinates.
1935 if (table()->header() == this && isRepeatingHeaderGroup()) 1941 if (table()->header() == this && isRepeatingHeaderGroup())
1936 rect.setHeight(table()->logicalHeight()); 1942 rect.setHeight(table()->logicalHeight());
1937 return LayoutTableBoxComponent::mapToVisualRectInAncestorSpace(ancestor, rect, 1943 return LayoutTableBoxComponent::mapToVisualRectInAncestorSpace(ancestor, rect,
1938 flags); 1944 flags);
1939 } 1945 }
1940 1946
1941 } // namespace blink 1947 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutTableSection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698