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

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

Issue 2286543002: Add Length::isPercent and use it in tables. (Closed)
Patch Set: and code changes Created 4 years, 3 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. 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (cell->rowSpan() != 1) 57 if (cell->rowSpan() != 1)
58 return; 58 return;
59 59
60 Length logicalHeight = cell->style()->logicalHeight(); 60 Length logicalHeight = cell->style()->logicalHeight();
61 if (logicalHeight.isPositive()) { 61 if (logicalHeight.isPositive()) {
62 Length cRowLogicalHeight = row.logicalHeight; 62 Length cRowLogicalHeight = row.logicalHeight;
63 switch (logicalHeight.type()) { 63 switch (logicalHeight.type()) {
64 case Percent: 64 case Percent:
65 // TODO(alancutter): Make this work correctly for calc lengths. 65 // TODO(alancutter): Make this work correctly for calc lengths.
66 if (!(cRowLogicalHeight.hasPercent()) 66 if (!(cRowLogicalHeight.hasPercent())
67 || (cRowLogicalHeight.hasPercent() && cRowLogicalHeight.percent( ) < logicalHeight.percent())) 67 || (cRowLogicalHeight.isPercent() && cRowLogicalHeight.percent() < logicalHeight.percent()))
68 row.logicalHeight = logicalHeight; 68 row.logicalHeight = logicalHeight;
69 break; 69 break;
70 case Fixed: 70 case Fixed:
71 if (cRowLogicalHeight.type() < Percent 71 if (cRowLogicalHeight.type() < Percent
72 || (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < l ogicalHeight.value())) 72 || (cRowLogicalHeight.isFixed() && cRowLogicalHeight.value() < l ogicalHeight.value()))
73 row.logicalHeight = logicalHeight; 73 row.logicalHeight = logicalHeight;
74 break; 74 break;
75 default: 75 default:
76 break; 76 break;
77 } 77 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const unsigned rowIndex = cell->rowIndex(); 359 const unsigned rowIndex = cell->rowIndex();
360 float percent = std::min(totalPercent, 100.0f); 360 float percent = std::min(totalPercent, 100.0f);
361 const int tableHeight = m_rowPos[m_grid.size()] + extraRowSpanningHeight; 361 const int tableHeight = m_rowPos[m_grid.size()] + extraRowSpanningHeight;
362 362
363 // Our algorithm matches Firefox. Extra spanning height would be distributed Only in first percent height rows 363 // Our algorithm matches Firefox. Extra spanning height would be distributed Only in first percent height rows
364 // those total percent is 100. Other percent rows would be uneffected even e xtra spanning height is remain. 364 // those total percent is 100. Other percent rows would be uneffected even e xtra spanning height is remain.
365 int accumulatedPositionIncrease = 0; 365 int accumulatedPositionIncrease = 0;
366 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { 366 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
367 if (percent > 0 && extraRowSpanningHeight > 0) { 367 if (percent > 0 && extraRowSpanningHeight > 0) {
368 // TODO(alancutter): Make this work correctly for calc lengths. 368 // TODO(alancutter): Make this work correctly for calc lengths.
369 if (m_grid[row].logicalHeight.hasPercent()) { 369 if (m_grid[row].logicalHeight.isPercent()) {
370 int toAdd = (tableHeight * std::min(m_grid[row].logicalHeight.pe rcent(), percent) / 100) - rowsHeight[row - rowIndex]; 370 int toAdd = (tableHeight * std::min(m_grid[row].logicalHeight.pe rcent(), percent) / 100) - rowsHeight[row - rowIndex];
371 371
372 toAdd = std::max(std::min(toAdd, extraRowSpanningHeight), 0); 372 toAdd = std::max(std::min(toAdd, extraRowSpanningHeight), 0);
373 accumulatedPositionIncrease += toAdd; 373 accumulatedPositionIncrease += toAdd;
374 extraRowSpanningHeight -= toAdd; 374 extraRowSpanningHeight -= toAdd;
375 percent -= m_grid[row].logicalHeight.percent(); 375 percent -= m_grid[row].logicalHeight.percent();
376 } 376 }
377 } 377 }
378 m_rowPos[row + 1] += accumulatedPositionIncrease; 378 m_rowPos[row + 1] += accumulatedPositionIncrease;
379 } 379 }
(...skipping 22 matching lines...) Expand all
402 if (!extraRowSpanningHeight || !totalPercent) 402 if (!extraRowSpanningHeight || !totalPercent)
403 return; 403 return;
404 404
405 const unsigned rowSpan = cell->rowSpan(); 405 const unsigned rowSpan = cell->rowSpan();
406 const unsigned rowIndex = cell->rowIndex(); 406 const unsigned rowIndex = cell->rowIndex();
407 double remainder = 0; 407 double remainder = 0;
408 408
409 int accumulatedPositionIncrease = 0; 409 int accumulatedPositionIncrease = 0;
410 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) { 410 for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
411 // TODO(alancutter): Make this work correctly for calc lengths. 411 // TODO(alancutter): Make this work correctly for calc lengths.
412 if (m_grid[row].logicalHeight.hasPercent()) { 412 if (m_grid[row].logicalHeight.isPercent()) {
413 updatePositionIncreasedWithRowHeight(extraRowSpanningHeight, m_grid[ row].logicalHeight.percent(), totalPercent, accumulatedPositionIncrease, remaind er); 413 updatePositionIncreasedWithRowHeight(extraRowSpanningHeight, m_grid[ row].logicalHeight.percent(), totalPercent, accumulatedPositionIncrease, remaind er);
414 } 414 }
415 m_rowPos[row + 1] += accumulatedPositionIncrease; 415 m_rowPos[row + 1] += accumulatedPositionIncrease;
416 } 416 }
417 417
418 DCHECK(!round(remainder)) << "remainder was " << remainder; 418 DCHECK(!round(remainder)) << "remainder was " << remainder;
419 419
420 extraRowSpanningHeight -= accumulatedPositionIncrease; 420 extraRowSpanningHeight -= accumulatedPositionIncrease;
421 } 421 }
422 422
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 float totalPercent = 0; 654 float totalPercent = 0;
655 int totalAutoRowsHeight = 0; 655 int totalAutoRowsHeight = 0;
656 int totalRemainingRowsHeight = spanningRowsHeight.totalRowsHeight; 656 int totalRemainingRowsHeight = spanningRowsHeight.totalRowsHeight;
657 657
658 // FIXME: Inner spanning cell height should not change if it have fixed height when it's parent spanning cell 658 // FIXME: Inner spanning cell height should not change if it have fixed height when it's parent spanning cell
659 // is distributing it's extra height in rows. 659 // is distributing it's extra height in rows.
660 660
661 // Calculate total percentage, total auto rows height and total rows hei ght except percent rows. 661 // Calculate total percentage, total auto rows height and total rows hei ght except percent rows.
662 for (unsigned row = rowIndex; row < spanningCellEndIndex; row++) { 662 for (unsigned row = rowIndex; row < spanningCellEndIndex; row++) {
663 // TODO(alancutter): Make this work correctly for calc lengths. 663 // TODO(alancutter): Make this work correctly for calc lengths.
664 if (m_grid[row].logicalHeight.hasPercent()) { 664 if (m_grid[row].logicalHeight.isPercent()) {
665 totalPercent += m_grid[row].logicalHeight.percent(); 665 totalPercent += m_grid[row].logicalHeight.percent();
666 totalRemainingRowsHeight -= spanningRowsHeight.rowHeight[row - r owIndex]; 666 totalRemainingRowsHeight -= spanningRowsHeight.rowHeight[row - r owIndex];
667 } else if (m_grid[row].logicalHeight.isAuto()) { 667 } else if (m_grid[row].logicalHeight.isAuto()) {
668 totalAutoRowsHeight += spanningRowsHeight.rowHeight[row - rowInd ex]; 668 totalAutoRowsHeight += spanningRowsHeight.rowHeight[row - rowInd ex];
669 } 669 }
670 } 670 }
671 671
672 int extraRowSpanningHeight = spanningRowsHeight.spanningCellHeightIgnori ngBorderSpacing - spanningRowsHeight.totalRowsHeight; 672 int extraRowSpanningHeight = spanningRowsHeight.spanningCellHeightIgnori ngBorderSpacing - spanningRowsHeight.totalRowsHeight;
673 673
674 if (totalPercent < 100 && !totalAutoRowsHeight && !totalRemainingRowsHei ght) { 674 if (totalPercent < 100 && !totalAutoRowsHeight && !totalRemainingRowsHei ght) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 if (!totalPercent) 862 if (!totalPercent)
863 return; 863 return;
864 864
865 unsigned totalRows = m_grid.size(); 865 unsigned totalRows = m_grid.size();
866 int totalHeight = m_rowPos[totalRows] + extraLogicalHeight; 866 int totalHeight = m_rowPos[totalRows] + extraLogicalHeight;
867 int totalLogicalHeightAdded = 0; 867 int totalLogicalHeightAdded = 0;
868 totalPercent = std::min(totalPercent, 100); 868 totalPercent = std::min(totalPercent, 100);
869 int rowHeight = m_rowPos[1] - m_rowPos[0]; 869 int rowHeight = m_rowPos[1] - m_rowPos[0];
870 for (unsigned r = 0; r < totalRows; ++r) { 870 for (unsigned r = 0; r < totalRows; ++r) {
871 // TODO(alancutter): Make this work correctly for calc lengths. 871 // TODO(alancutter): Make this work correctly for calc lengths.
872 if (totalPercent > 0 && m_grid[r].logicalHeight.hasPercent()) { 872 if (totalPercent > 0 && m_grid[r].logicalHeight.isPercent()) {
873 int toAdd = std::min<int>(extraLogicalHeight, (totalHeight * m_grid[ r].logicalHeight.percent() / 100) - rowHeight); 873 int toAdd = std::min<int>(extraLogicalHeight, (totalHeight * m_grid[ r].logicalHeight.percent() / 100) - rowHeight);
874 // If toAdd is negative, then we don't want to shrink the row (this bug 874 // If toAdd is negative, then we don't want to shrink the row (this bug
875 // affected Outlook Web Access). 875 // affected Outlook Web Access).
876 toAdd = std::max(0, toAdd); 876 toAdd = std::max(0, toAdd);
877 totalLogicalHeightAdded += toAdd; 877 totalLogicalHeightAdded += toAdd;
878 extraLogicalHeight -= toAdd; 878 extraLogicalHeight -= toAdd;
879 totalPercent -= m_grid[r].logicalHeight.percent(); 879 totalPercent -= m_grid[r].logicalHeight.percent();
880 } 880 }
881 ASSERT(totalRows >= 1); 881 ASSERT(totalRows >= 1);
882 if (r < totalRows - 1) 882 if (r < totalRows - 1)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 return extraLogicalHeight; 934 return extraLogicalHeight;
935 935
936 if (!m_rowPos[totalRows] && nextSibling()) 936 if (!m_rowPos[totalRows] && nextSibling())
937 return extraLogicalHeight; 937 return extraLogicalHeight;
938 938
939 unsigned autoRowsCount = 0; 939 unsigned autoRowsCount = 0;
940 int totalPercent = 0; 940 int totalPercent = 0;
941 for (unsigned r = 0; r < totalRows; r++) { 941 for (unsigned r = 0; r < totalRows; r++) {
942 if (m_grid[r].logicalHeight.isAuto()) 942 if (m_grid[r].logicalHeight.isAuto())
943 ++autoRowsCount; 943 ++autoRowsCount;
944 else if (m_grid[r].logicalHeight.hasPercent()) 944 else if (m_grid[r].logicalHeight.isPercent())
dgrogan 2016/08/26 00:27:18 This is the only change tested by the layout test.
945 totalPercent += m_grid[r].logicalHeight.percent(); 945 totalPercent += m_grid[r].logicalHeight.percent();
946 } 946 }
947 947
948 int remainingExtraLogicalHeight = extraLogicalHeight; 948 int remainingExtraLogicalHeight = extraLogicalHeight;
949 distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, total Percent); 949 distributeExtraLogicalHeightToPercentRows(remainingExtraLogicalHeight, total Percent);
950 distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRows Count); 950 distributeExtraLogicalHeightToAutoRows(remainingExtraLogicalHeight, autoRows Count);
951 distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight); 951 distributeRemainingExtraLogicalHeight(remainingExtraLogicalHeight);
952 return extraLogicalHeight - remainingExtraLogicalHeight; 952 return extraLogicalHeight - remainingExtraLogicalHeight;
953 } 953 }
954 954
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 // Repeating table headers are painted once per fragmentation page/column. T his does not go through the regular fragmentation machinery, 1746 // Repeating table headers are painted once per fragmentation page/column. T his does not go through the regular fragmentation machinery,
1747 // so we need special code to expand the invalidation rect to contain all po sitions of the header in all columns. 1747 // so we need special code to expand the invalidation rect to contain all po sitions of the header in all columns.
1748 // Note that this is in flow thread coordinates, not visual coordinates. The enclosing LayoutFlowThread will convert to visual coordinates. 1748 // Note that this is in flow thread coordinates, not visual coordinates. The enclosing LayoutFlowThread will convert to visual coordinates.
1749 if (table()->header() == this && hasRepeatingHeaderGroup()) 1749 if (table()->header() == this && hasRepeatingHeaderGroup())
1750 rect.setHeight(table()->logicalHeight()); 1750 rect.setHeight(table()->logicalHeight());
1751 return LayoutTableBoxComponent::mapToVisualRectInAncestorSpace(ancestor, rec t, flags); 1751 return LayoutTableBoxComponent::mapToVisualRectInAncestorSpace(ancestor, rec t, flags);
1752 } 1752 }
1753 1753
1754 1754
1755 } // namespace blink 1755 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698