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

Side by Side Diff: Source/core/layout/TableLayoutAlgorithmAuto.cpp

Issue 1181643007: Fix regression in unwinding overallocation on auto cells (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/TableLayoutAlgorithmAuto.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) 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 609
610 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { 610 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) {
611 unsigned total = nEffCols - numAutoEmptyCellsOnly; 611 unsigned total = nEffCols - numAutoEmptyCellsOnly;
612 // Starting from the last cell is for compatibility with FF/IE - it isn' t specified anywhere. 612 // Starting from the last cell is for compatibility with FF/IE - it isn' t specified anywhere.
613 distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E ndToStart>(available, total); 613 distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E ndToStart>(available, total);
614 } 614 }
615 615
616 // If we have overallocated, reduce every cell according to the difference b etween desired width and minwidth 616 // If we have overallocated, reduce every cell according to the difference b etween desired width and minwidth
617 // this seems to produce to the pixel exact results with IE. Wonder is some of this also holds for width distributing. 617 // this seems to produce to the pixel exact results with IE. Wonder is some of this also holds for width distributing.
618 // This is basically the reverse of how we grew the cells. 618 // This is basically the reverse of how we grew the cells.
619 if (available < 0) 619 if (available < 0) {
620 shrinkColumnWidth(Auto, available); 620 int autoWidthAvailable = available - static_cast<int>(totalAuto);
621 shrinkColumnWidth(Auto, autoWidthAvailable);
622 }
621 if (available < 0) 623 if (available < 0)
622 shrinkColumnWidth(Fixed, available); 624 shrinkColumnWidth(Fixed, available);
623 if (available < 0) 625 if (available < 0)
624 shrinkColumnWidth(Percent, available); 626 shrinkColumnWidth(Percent, available);
625 627
626 int pos = 0; 628 int pos = 0;
627 for (size_t i = 0; i < nEffCols; ++i) { 629 for (size_t i = 0; i < nEffCols; ++i) {
628 m_table->setColumnPosition(i, pos); 630 m_table->setColumnPosition(i, pos);
629 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing( ); 631 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing( );
630 } 632 }
631 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos); 633 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos);
632 } 634 }
633 635
634 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D istributionMode distributionMode, DistributionDirection distributionDirection> 636 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D istributionMode distributionMode, DistributionDirection distributionDirection>
635 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total to tal) 637 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total& t otal)
636 { 638 {
637 // TODO(alancutter): Make this work correctly for calc lengths. 639 // TODO(alancutter): Make this work correctly for calc lengths.
638 int nEffCols = static_cast<int>(m_table->numEffCols()); 640 int nEffCols = static_cast<int>(m_table->numEffCols());
639 bool startToEnd = distributionDirection == StartToEnd; 641 bool startToEnd = distributionDirection == StartToEnd;
640 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) { 642 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) {
641 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; 643 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
642 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout Struct[i].emptyCellsOnly) 644 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout Struct[i].emptyCellsOnly)
643 continue; 645 continue;
644 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy pe) 646 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy pe)
645 continue; 647 continue;
646 648
647 float factor = 1; 649 float factor = 1;
648 if (distributionMode != LeftoverWidth) { 650 if (distributionMode != LeftoverWidth) {
649 if (lengthType == Percent) 651 if (lengthType == Percent)
650 factor = logicalWidth.percent(); 652 factor = logicalWidth.percent();
651 else if (lengthType == Auto || lengthType == Fixed) 653 else if (lengthType == Auto || lengthType == Fixed)
652 factor = m_layoutStruct[i].effectiveMaxLogicalWidth; 654 factor = m_layoutStruct[i].effectiveMaxLogicalWidth;
653 } 655 }
654 656
655 int newWidth = available * factor / total; 657 int newWidth = available * factor / total;
656 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; 658 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth;
657 available -= cellLogicalWidth; 659 available -= cellLogicalWidth;
658 total -= factor; 660 total -= factor;
659 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid th; 661 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid th;
660 662
661 // If we have run out of width to allocate we're done. 663 // If we have run out of width to allocate we're done.
662 // Also, any overallocation will be unwound later so no point in buildin g up cells to unwind, just bail now. 664 // TODO(rhogan): Extend this to Fixed as well.
663 if (available <= 0 || total <= 0) 665 if ((lengthType == Percent || lengthType == Auto) && (available <= 0 || total <= 0))
664 return; 666 return;
665 } 667 }
666 } 668 }
667 669
668 void TableLayoutAlgorithmAuto::shrinkColumnWidth(const LengthType& lengthType, i nt& available) 670 void TableLayoutAlgorithmAuto::shrinkColumnWidth(const LengthType& lengthType, i nt& available)
669 { 671 {
670 size_t nEffCols = m_table->numEffCols(); 672 size_t nEffCols = m_table->numEffCols();
671 int logicalWidthBeyondMin = 0; 673 int logicalWidthBeyondMin = 0;
672 for (unsigned i = nEffCols; i; ) { 674 for (unsigned i = nEffCols; i; ) {
673 --i; 675 --i;
(...skipping 10 matching lines...) Expand all
684 int reduce = available * minMaxDiff / logicalWidthBeyondMin; 686 int reduce = available * minMaxDiff / logicalWidthBeyondMin;
685 m_layoutStruct[i].computedLogicalWidth += reduce; 687 m_layoutStruct[i].computedLogicalWidth += reduce;
686 available -= reduce; 688 available -= reduce;
687 logicalWidthBeyondMin -= minMaxDiff; 689 logicalWidthBeyondMin -= minMaxDiff;
688 if (available >= 0) 690 if (available >= 0)
689 break; 691 break;
690 } 692 }
691 } 693 }
692 } 694 }
693 } 695 }
OLDNEW
« no previous file with comments | « Source/core/layout/TableLayoutAlgorithmAuto.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698