| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 56             toLayoutTableCol(child)->clearPreferredLogicalWidthsDirtyBits(); | 56             toLayoutTableCol(child)->clearPreferredLogicalWidthsDirtyBits(); | 
| 57         } else if (child->isTableSection()) { | 57         } else if (child->isTableSection()) { | 
| 58             LayoutTableSection* section = toLayoutTableSection(child); | 58             LayoutTableSection* section = toLayoutTableSection(child); | 
| 59             unsigned numRows = section->numRows(); | 59             unsigned numRows = section->numRows(); | 
| 60             for (unsigned i = 0; i < numRows; i++) { | 60             for (unsigned i = 0; i < numRows; i++) { | 
| 61                 LayoutTableSection::CellStruct current = section->cellAt(i, effC
     ol); | 61                 LayoutTableSection::CellStruct current = section->cellAt(i, effC
     ol); | 
| 62                 LayoutTableCell* cell = current.primaryCell(); | 62                 LayoutTableCell* cell = current.primaryCell(); | 
| 63 | 63 | 
| 64                 if (current.inColSpan || !cell) | 64                 if (current.inColSpan || !cell) | 
| 65                     continue; | 65                     continue; | 
|  | 66                 columnLayout.columnHasNoCells = false; | 
| 66 | 67 | 
| 67                 bool cellHasContent = cell->children()->firstChild() || cell->st
     yle()->hasBorder() || cell->style()->hasPadding() || cell->style()->hasBackgroun
     d(); | 68                 if (cell->maxPreferredLogicalWidth()) | 
| 68                 if (cellHasContent) |  | 
| 69                     columnLayout.emptyCellsOnly = false; | 69                     columnLayout.emptyCellsOnly = false; | 
| 70 | 70 | 
| 71                 // A cell originates in this column. Ensure we have |  | 
| 72                 // a min/max width of at least 1px for this column now. |  | 
| 73                 columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLog
     icalWidth, cellHasContent ? 1 : 0); |  | 
| 74                 columnLayout.maxLogicalWidth = std::max<int>(columnLayout.maxLog
     icalWidth, 1); |  | 
| 75 |  | 
| 76                 if (cell->colSpan() == 1) { | 71                 if (cell->colSpan() == 1) { | 
| 77                     columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer
     redLogicalWidth(), columnLayout.minLogicalWidth); | 72                     columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer
     redLogicalWidth(), columnLayout.minLogicalWidth); | 
| 78                     if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic
     alWidth) { | 73                     if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic
     alWidth) { | 
| 79                         columnLayout.maxLogicalWidth = cell->maxPreferredLogical
     Width(); | 74                         columnLayout.maxLogicalWidth = cell->maxPreferredLogical
     Width(); | 
| 80                         maxContributor = cell; | 75                         maxContributor = cell; | 
| 81                     } | 76                     } | 
| 82 | 77 | 
| 83                     // All browsers implement a size limit on the cell's max wid
     th. | 78                     // All browsers implement a size limit on the cell's max wid
     th. | 
| 84                     // Our limit is based on KHTML's representation that used 16
      bits widths. | 79                     // Our limit is based on KHTML's representation that used 16
      bits widths. | 
| 85                     // FIXME: Other browsers have a lower limit for the cell's m
     ax width. | 80                     // FIXME: Other browsers have a lower limit for the cell's m
     ax width. | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 113                     case Percent: | 108                     case Percent: | 
| 114                         m_hasPercent = true; | 109                         m_hasPercent = true; | 
| 115                         // TODO(alancutter): Make this work correctly for calc l
     engths. | 110                         // TODO(alancutter): Make this work correctly for calc l
     engths. | 
| 116                         if (cellLogicalWidth.isPositive() && (!columnLayout.logi
     calWidth.hasPercent() || cellLogicalWidth.value() > columnLayout.logicalWidth.va
     lue())) | 111                         if (cellLogicalWidth.isPositive() && (!columnLayout.logi
     calWidth.hasPercent() || cellLogicalWidth.value() > columnLayout.logicalWidth.va
     lue())) | 
| 117                             columnLayout.logicalWidth = cellLogicalWidth; | 112                             columnLayout.logicalWidth = cellLogicalWidth; | 
| 118                         break; | 113                         break; | 
| 119                     default: | 114                     default: | 
| 120                         break; | 115                         break; | 
| 121                     } | 116                     } | 
| 122                 } else if (!effCol || section->primaryCellAt(i, effCol - 1) != c
     ell) { | 117                 } else if (!effCol || section->primaryCellAt(i, effCol - 1) != c
     ell) { | 
|  | 118                     // If a cell originates in this spanning column ensure we ha
     ve a min/max width of at least 1px for it. | 
|  | 119                     columnLayout.minLogicalWidth = std::max<int>(columnLayout.mi
     nLogicalWidth, cell->maxPreferredLogicalWidth() ? 1 : 0); | 
|  | 120 | 
| 123                     // This spanning cell originates in this column. Insert the 
     cell into spanning cells list. | 121                     // This spanning cell originates in this column. Insert the 
     cell into spanning cells list. | 
| 124                     insertSpanCell(cell); | 122                     insertSpanCell(cell); | 
| 125                 } | 123                 } | 
| 126             } | 124             } | 
| 127         } | 125         } | 
| 128     } | 126     } | 
| 129 | 127 | 
| 130     // Nav/IE weirdness | 128     // Nav/IE weirdness | 
| 131     if (columnLayout.logicalWidth.isFixed()) { | 129     if (columnLayout.logicalWidth.isFixed()) { | 
| 132         if (m_table->document().inQuirksMode() && columnLayout.maxLogicalWidth >
      columnLayout.logicalWidth.value() && fixedContributor != maxContributor) { | 130         if (m_table->document().inQuirksMode() && columnLayout.maxLogicalWidth >
      columnLayout.logicalWidth.value() && fixedContributor != maxContributor) { | 
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 366                 // can't satify this condition, treat as variable | 364                 // can't satify this condition, treat as variable | 
| 367                 cellLogicalWidth = Length(); | 365                 cellLogicalWidth = Length(); | 
| 368             } else { | 366             } else { | 
| 369                 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std
     ::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100  / cellLogicalWidth.percen
     t())); | 367                 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std
     ::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100  / cellLogicalWidth.percen
     t())); | 
| 370 | 368 | 
| 371                 // all non percent columns in the span get percent values to sum
      up correctly. | 369                 // all non percent columns in the span get percent values to sum
      up correctly. | 
| 372                 float percentMissing = cellLogicalWidth.percent() - totalPercent
     ; | 370                 float percentMissing = cellLogicalWidth.percent() - totalPercent
     ; | 
| 373                 int totalWidth = 0; | 371                 int totalWidth = 0; | 
| 374                 for (unsigned pos = effCol; pos < lastCol; ++pos) { | 372                 for (unsigned pos = effCol; pos < lastCol; ++pos) { | 
| 375                     if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) | 373                     if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) | 
| 376                         totalWidth += m_layoutStruct[pos].effectiveMaxLogicalWid
     th; | 374                         totalWidth += m_layoutStruct[pos].clampedEffectiveMaxLog
     icalWidth(); | 
| 377                 } | 375                 } | 
| 378 | 376 | 
| 379                 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p
     os) { | 377                 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p
     os) { | 
| 380                     if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
      { | 378                     if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
      { | 
| 381                         float percent = percentMissing * static_cast<float>(m_la
     youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth; | 379                         float percent = percentMissing * static_cast<float>(m_la
     youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth; | 
| 382                         totalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWid
     th; | 380                         totalWidth -= m_layoutStruct[pos].clampedEffectiveMaxLog
     icalWidth(); | 
| 383                         percentMissing -= percent; | 381                         percentMissing -= percent; | 
| 384                         if (percent > 0) | 382                         if (percent > 0) | 
| 385                             m_layoutStruct[pos].effectiveLogicalWidth.setValue(P
     ercent, percent); | 383                             m_layoutStruct[pos].effectiveLogicalWidth.setValue(P
     ercent, percent); | 
| 386                         else | 384                         else | 
| 387                             m_layoutStruct[pos].effectiveLogicalWidth = Length()
     ; | 385                             m_layoutStruct[pos].effectiveLogicalWidth = Length()
     ; | 
| 388                     } | 386                     } | 
| 389                 } | 387                 } | 
| 390             } | 388             } | 
| 391         } | 389         } | 
| 392 | 390 | 
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 531         m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; | 529         m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; | 
| 532         available -= cellLogicalWidth; | 530         available -= cellLogicalWidth; | 
| 533         Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 531         Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 
| 534         switch (logicalWidth.type()) { | 532         switch (logicalWidth.type()) { | 
| 535         case Percent: | 533         case Percent: | 
| 536             havePercent = true; | 534             havePercent = true; | 
| 537             totalPercent += logicalWidth.percent(); | 535             totalPercent += logicalWidth.percent(); | 
| 538             break; | 536             break; | 
| 539         case Fixed: | 537         case Fixed: | 
| 540             numFixed++; | 538             numFixed++; | 
| 541             totalFixed += m_layoutStruct[i].effectiveMaxLogicalWidth; | 539             totalFixed += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); | 
| 542             // fall through | 540             // fall through | 
| 543             break; | 541             break; | 
| 544         case Auto: | 542         case Auto: | 
| 545             if (m_layoutStruct[i].emptyCellsOnly) { | 543             if (m_layoutStruct[i].emptyCellsOnly) { | 
| 546                 numAutoEmptyCellsOnly++; | 544                 numAutoEmptyCellsOnly++; | 
| 547             } else { | 545             } else { | 
| 548                 numAuto++; | 546                 numAuto++; | 
| 549                 totalAuto += m_layoutStruct[i].effectiveMaxLogicalWidth; | 547                 totalAuto += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth()
     ; | 
| 550                 allocAuto += cellLogicalWidth; | 548                 allocAuto += cellLogicalWidth; | 
| 551             } | 549             } | 
| 552             break; | 550             break; | 
| 553         default: | 551         default: | 
| 554             break; | 552             break; | 
| 555         } | 553         } | 
| 556     } | 554     } | 
| 557 | 555 | 
| 558     // allocate width to percent cols | 556     // allocate width to percent cols | 
| 559     if (available > 0 && havePercent) { | 557     if (available > 0 && havePercent) { | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 587     if (available > 0) { | 585     if (available > 0) { | 
| 588         for (size_t i = 0; i < nEffCols; ++i) { | 586         for (size_t i = 0; i < nEffCols; ++i) { | 
| 589             Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 587             Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 
| 590             if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[
     i].computedLogicalWidth) { | 588             if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[
     i].computedLogicalWidth) { | 
| 591                 available += m_layoutStruct[i].computedLogicalWidth - logicalWid
     th.value(); | 589                 available += m_layoutStruct[i].computedLogicalWidth - logicalWid
     th.value(); | 
| 592                 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); | 590                 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); | 
| 593             } | 591             } | 
| 594         } | 592         } | 
| 595     } | 593     } | 
| 596 | 594 | 
| 597     // Give each auto width column its share of the available width. | 595     // Give each auto width column its share of the available width, non-empty c
     olumns then empty columns. | 
| 598     if (available > 0 && numAuto) { | 596     if (available > 0 && numAuto) { | 
| 599         available += allocAuto; | 597         available += allocAuto; | 
| 600         distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start
     ToEnd>(available, totalAuto); | 598         distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start
     ToEnd>(available, totalAuto); | 
| 601     } | 599     } | 
|  | 600     if (available > 0 && numAutoEmptyCellsOnly) { | 
|  | 601         unsigned total = numAutoEmptyCellsOnly; | 
|  | 602         distributeWidthToColumns<unsigned, Auto, EmptyCells, InitialWidth, Start
     ToEnd>(available, total); | 
|  | 603     } | 
| 602 | 604 | 
| 603     // Any remaining available width expands fixed width, percent width and non-
     empty auto width columns, in that order. | 605     // Any remaining available width expands fixed width, percent width, and non
     -empty auto width columns, in that order. | 
| 604     if (available > 0 && numFixed) | 606     if (available > 0 && numFixed) | 
| 605         distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd>
     (available, totalFixed); | 607         distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd>
     (available, totalFixed); | 
| 606 | 608 | 
| 607     if (available > 0 && m_hasPercent && totalPercent < 100) | 609     if (available > 0 && m_hasPercent && totalPercent < 100) | 
| 608         distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn
     d>(available, totalPercent); | 610         distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn
     d>(available, totalPercent); | 
| 609 | 611 | 
| 610     if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { | 612     if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { | 
| 611         unsigned total = nEffCols - numAutoEmptyCellsOnly; | 613         unsigned total = nEffCols - numAutoEmptyCellsOnly; | 
| 612         // Starting from the last cell is for compatibility with FF/IE - it isn'
     t specified anywhere. | 614         // 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); | 615         distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E
     ndToStart>(available, total); | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 636 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D
     istributionMode distributionMode, DistributionDirection distributionDirection> | 638 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D
     istributionMode distributionMode, DistributionDirection distributionDirection> | 
| 637 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total& t
     otal) | 639 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total& t
     otal) | 
| 638 { | 640 { | 
| 639     // TODO(alancutter): Make this work correctly for calc lengths. | 641     // TODO(alancutter): Make this work correctly for calc lengths. | 
| 640     int nEffCols = static_cast<int>(m_table->numEffCols()); | 642     int nEffCols = static_cast<int>(m_table->numEffCols()); | 
| 641     bool startToEnd = distributionDirection == StartToEnd; | 643     bool startToEnd = distributionDirection == StartToEnd; | 
| 642     for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > 
     -1; startToEnd ? ++i : --i) { | 644     for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > 
     -1; startToEnd ? ++i : --i) { | 
| 643         const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 645         const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 
| 644         if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout
     Struct[i].emptyCellsOnly) | 646         if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout
     Struct[i].emptyCellsOnly) | 
| 645             continue; | 647             continue; | 
|  | 648         // When allocating width to columns with nothing but empty cells we avoi
     d | 
|  | 649         // columns that exist only to flesh out a colspan and have no actual cel
     ls. | 
|  | 650         if (cellsToProcess == EmptyCells && logicalWidth.isAuto() && (!m_layoutS
     truct[i].emptyCellsOnly || m_layoutStruct[i].columnHasNoCells)) | 
|  | 651             continue; | 
| 646         if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy
     pe) | 652         if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy
     pe) | 
| 647             continue; | 653             continue; | 
| 648 | 654 | 
| 649         float factor = 1; | 655         float factor = 1; | 
| 650         if (distributionMode != LeftoverWidth) { | 656         if (distributionMode != LeftoverWidth) { | 
| 651             if (lengthType == Percent) | 657             if (lengthType == Percent) | 
| 652                 factor = logicalWidth.percent(); | 658                 factor = logicalWidth.percent(); | 
| 653             else if (lengthType == Auto || lengthType == Fixed) | 659             else if (lengthType == Auto || lengthType == Fixed) | 
| 654                 factor = m_layoutStruct[i].effectiveMaxLogicalWidth; | 660                 factor = m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); | 
| 655         } | 661         } | 
| 656 | 662 | 
| 657         int newWidth = available * factor / total; | 663         int newWidth = available * factor / total; | 
| 658         int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l
     ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; | 664         int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l
     ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; | 
| 659         available -= cellLogicalWidth; | 665         available -= cellLogicalWidth; | 
| 660         total -= factor; | 666         total -= factor; | 
| 661         m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid
     th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid
     th; | 667         m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid
     th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid
     th; | 
| 662 | 668 | 
| 663         // If we have run out of width to allocate we're done. | 669         // If we have run out of width to allocate we're done. | 
| 664         // TODO(rhogan): Extend this to Fixed as well. | 670         // TODO(rhogan): Extend this to Fixed as well. | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 686             int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 692             int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 
| 687             m_layoutStruct[i].computedLogicalWidth += reduce; | 693             m_layoutStruct[i].computedLogicalWidth += reduce; | 
| 688             available -= reduce; | 694             available -= reduce; | 
| 689             logicalWidthBeyondMin -= minMaxDiff; | 695             logicalWidthBeyondMin -= minMaxDiff; | 
| 690             if (available >= 0) | 696             if (available >= 0) | 
| 691                 break; | 697                 break; | 
| 692         } | 698         } | 
| 693     } | 699     } | 
| 694 } | 700 } | 
| 695 } | 701 } | 
| OLD | NEW | 
|---|