Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2002 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2002 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2002 Dirk Mueller (mueller@kde.org) | 3 * (C) 2002 Dirk Mueller (mueller@kde.org) |
| 4 * Copyright (C) 2003, 2006, 2008, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2003, 2006, 2008, 2010 Apple Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License. | 9 * version 2 of the License. |
| 10 * | 10 * |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 if (available > 0) { | 583 if (available > 0) { |
| 584 for (size_t i = 0; i < nEffCols; ++i) { | 584 for (size_t i = 0; i < nEffCols; ++i) { |
| 585 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 585 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
| 586 if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[ i].computedLogicalWidth) { | 586 if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[ i].computedLogicalWidth) { |
| 587 available += m_layoutStruct[i].computedLogicalWidth - logicalWid th.value(); | 587 available += m_layoutStruct[i].computedLogicalWidth - logicalWid th.value(); |
| 588 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); | 588 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 // now satisfy variable | |
| 594 if (available > 0 && numAuto) { | 593 if (available > 0 && numAuto) { |
| 595 available += allocAuto; // this gets redistributed | 594 available += allocAuto; |
| 596 for (size_t i = 0; i < nEffCols; ++i) { | 595 distributeWidthToColumns(Auto, available, totalAuto, NonEmptyCells, Init ialWidth); |
| 597 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | |
| 598 if (logicalWidth.isAuto() && totalAuto && !m_layoutStruct[i].emptyCe llsOnly) { | |
| 599 int cellLogicalWidth = std::max<int>(m_layoutStruct[i].computedL ogicalWidth, static_cast<int>(available * static_cast<float>(m_layoutStruct[i].e ffectiveMaxLogicalWidth) / totalAuto)); | |
| 600 available -= cellLogicalWidth; | |
| 601 totalAuto -= m_layoutStruct[i].effectiveMaxLogicalWidth; | |
| 602 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; | |
| 603 } | |
| 604 } | |
| 605 } | 596 } |
| 606 | 597 |
| 607 // spread over fixed columns | 598 if (available > 0 && numFixed) |
| 608 if (available > 0 && numFixed) { | 599 distributeWidthToColumns(Fixed, available, totalFixed); |
| 609 for (size_t i = 0; i < nEffCols; ++i) { | |
| 610 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | |
| 611 if (logicalWidth.isFixed()) { | |
| 612 int cellLogicalWidth = static_cast<int>(available * static_cast< float>(m_layoutStruct[i].effectiveMaxLogicalWidth) / totalFixed); | |
| 613 available -= cellLogicalWidth; | |
| 614 totalFixed -= m_layoutStruct[i].effectiveMaxLogicalWidth; | |
| 615 m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth; | |
| 616 } | |
| 617 } | |
| 618 } | |
| 619 | 600 |
| 620 // spread over percent colums | 601 if (available > 0 && m_hasPercent && totalPercent < 100) |
| 621 if (available > 0 && m_hasPercent && totalPercent < 100) { | 602 distributeWidthToColumns(Percent, available, totalPercent); |
| 622 for (size_t i = 0; i < nEffCols; ++i) { | |
| 623 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | |
| 624 if (logicalWidth.isPercent()) { | |
| 625 int cellLogicalWidth = available * logicalWidth.percent() / tota lPercent; | |
| 626 available -= cellLogicalWidth; | |
| 627 totalPercent -= logicalWidth.percent(); | |
| 628 m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth; | |
| 629 if (!available || !totalPercent) | |
| 630 break; | |
| 631 } | |
| 632 } | |
| 633 } | |
| 634 | 603 |
| 635 // spread over the rest | |
| 636 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { | 604 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { |
| 637 unsigned total = nEffCols - numAutoEmptyCellsOnly; | 605 unsigned total = nEffCols - numAutoEmptyCellsOnly; |
| 638 // still have some width to spread | 606 distributeWidthToColumns(Auto, available, total, NonEmptyCells, LeftOver Width, EndToStart); |
| 639 for (unsigned i = nEffCols; i; ) { | |
| 640 --i; | |
| 641 // variable columns with empty cells only don't get any width | |
| 642 if (m_layoutStruct[i].effectiveLogicalWidth.isAuto() && m_layoutStru ct[i].emptyCellsOnly) | |
| 643 continue; | |
| 644 int cellLogicalWidth = available / total; | |
| 645 available -= cellLogicalWidth; | |
| 646 total--; | |
| 647 m_layoutStruct[i].computedLogicalWidth += cellLogicalWidth; | |
| 648 } | |
| 649 } | 607 } |
|
rhogan
2015/04/28 13:44:08
This End to Start order for this left over width i
mstensho (USE GERRIT)
2015/04/28 21:53:12
OK. Worth a comment?
mstensho (USE GERRIT)
2015/05/04 20:42:47
Acknowledged.
| |
| 650 | 608 |
| 651 // If we have overallocated, reduce every cell according to the difference b etween desired width and minwidth | 609 // If we have overallocated, reduce every cell according to the difference b etween desired width and minwidth |
| 652 // this seems to produce to the pixel exact results with IE. Wonder is some of this also holds for width distributing. | 610 // this seems to produce to the pixel exact results with IE. Wonder is some of this also holds for width distributing. |
| 653 // Need to reduce cells with the following prioritization: | |
| 654 // This is basically the reverse of how we grew the cells. | 611 // This is basically the reverse of how we grew the cells. |
| 655 if (available < 0) | 612 if (available < 0) |
| 656 shrinkCellWidth(Auto, available); | 613 shrinkColumnWidth(Auto, available); |
| 657 if (available < 0) | 614 if (available < 0) |
| 658 shrinkCellWidth(Fixed, available); | 615 shrinkColumnWidth(Fixed, available); |
| 659 if (available < 0) | 616 if (available < 0) |
| 660 shrinkCellWidth(Percent, available); | 617 shrinkColumnWidth(Percent, available); |
| 661 | 618 |
| 662 int pos = 0; | 619 int pos = 0; |
| 663 for (size_t i = 0; i < nEffCols; ++i) { | 620 for (size_t i = 0; i < nEffCols; ++i) { |
| 664 m_table->setColumnPosition(i, pos); | 621 m_table->setColumnPosition(i, pos); |
| 665 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing( ); | 622 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing( ); |
| 666 } | 623 } |
| 667 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos); | 624 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos); |
| 668 } | 625 } |
| 669 | 626 |
| 670 void TableLayoutAlgorithmAuto::shrinkCellWidth(const LengthType& lengthType, int & available) | 627 |
| 628 void TableLayoutAlgorithmAuto::distributeWidthToColumns(const LengthType& length Type, int& available, int total, LimitToCells limitToCells, DistributionMode dis tributionMode, DistributionDirection distributionDirection) | |
| 629 { | |
| 630 int nEffCols = static_cast<int>(m_table->numEffCols()); | |
| 631 bool startToEnd = distributionDirection == StartToEnd; | |
| 632 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) { | |
| 633 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | |
| 634 if (limitToCells == NonEmptyCells && logicalWidth.isAuto() && m_layoutSt ruct[i].emptyCellsOnly) | |
| 635 continue; | |
| 636 if (distributionMode != LeftOverWidth && logicalWidth.type() != lengthTy pe) | |
| 637 continue; | |
| 638 | |
| 639 int factor = 1; | |
| 640 if (distributionMode == LeftOverWidth) | |
| 641 factor = 1; | |
| 642 else if (lengthType == Percent) | |
| 643 factor = logicalWidth.percent(); | |
| 644 else if (lengthType == Auto || lengthType == Fixed) | |
| 645 factor = m_layoutStruct[i].effectiveMaxLogicalWidth; | |
| 646 | |
| 647 int newWidth = available * factor / total; | |
| 648 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; | |
| 649 available -= cellLogicalWidth; | |
| 650 total -= factor; | |
| 651 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid th; | |
| 652 | |
| 653 if (!available || !total) | |
| 654 return; | |
|
rhogan
2015/04/28 13:44:08
This is a change. We only bail early for auto and
mstensho (USE GERRIT)
2015/04/28 21:53:12
But is it safe to change the bailing policy at all
mstensho (USE GERRIT)
2015/05/04 20:42:47
OK, you added a comment, so I'll just trust you. :
| |
| 655 } | |
| 656 } | |
| 657 | |
| 658 void TableLayoutAlgorithmAuto::shrinkColumnWidth(const LengthType& lengthType, i nt& available) | |
| 671 { | 659 { |
| 672 size_t nEffCols = m_table->numEffCols(); | 660 size_t nEffCols = m_table->numEffCols(); |
| 673 int logicalWidthBeyondMin = 0; | 661 int logicalWidthBeyondMin = 0; |
| 674 for (unsigned i = nEffCols; i; ) { | 662 for (unsigned i = nEffCols; i; ) { |
| 675 --i; | 663 --i; |
| 676 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 664 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
| 677 if (logicalWidth.type() == lengthType) | 665 if (logicalWidth.type() == lengthType) |
| 678 logicalWidthBeyondMin += m_layoutStruct[i].computedLogicalWidth - m_ layoutStruct[i].effectiveMinLogicalWidth; | 666 logicalWidthBeyondMin += m_layoutStruct[i].computedLogicalWidth - m_ layoutStruct[i].effectiveMinLogicalWidth; |
| 679 } | 667 } |
| 680 | 668 |
| 681 for (unsigned i = nEffCols; i && logicalWidthBeyondMin > 0; ) { | 669 for (unsigned i = nEffCols; i && logicalWidthBeyondMin > 0; ) { |
| 682 --i; | 670 --i; |
| 683 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 671 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
| 684 if (logicalWidth.type() == lengthType) { | 672 if (logicalWidth.type() == lengthType) { |
| 685 int minMaxDiff = m_layoutStruct[i].computedLogicalWidth - m_layoutSt ruct[i].effectiveMinLogicalWidth; | 673 int minMaxDiff = m_layoutStruct[i].computedLogicalWidth - m_layoutSt ruct[i].effectiveMinLogicalWidth; |
| 686 int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 674 int reduce = available * minMaxDiff / logicalWidthBeyondMin; |
| 687 m_layoutStruct[i].computedLogicalWidth += reduce; | 675 m_layoutStruct[i].computedLogicalWidth += reduce; |
| 688 available -= reduce; | 676 available -= reduce; |
| 689 logicalWidthBeyondMin -= minMaxDiff; | 677 logicalWidthBeyondMin -= minMaxDiff; |
| 690 if (available >= 0) | 678 if (available >= 0) |
| 691 break; | 679 break; |
| 692 } | 680 } |
| 693 } | 681 } |
| 694 } | 682 } |
| 695 } | 683 } |
| OLD | NEW |