| 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 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 #include "core/layout/TableLayoutAlgorithmAuto.h" | 23 #include "core/layout/TableLayoutAlgorithmAuto.h" |
| 24 | 24 |
| 25 #include "core/layout/LayoutTable.h" | 25 #include "core/layout/LayoutTable.h" |
| 26 #include "core/layout/LayoutTableCell.h" | 26 #include "core/layout/LayoutTableCell.h" |
| 27 #include "core/layout/LayoutTableCol.h" | 27 #include "core/layout/LayoutTableCol.h" |
| 28 #include "core/layout/LayoutTableSection.h" | 28 #include "core/layout/LayoutTableSection.h" |
| 29 #include "core/layout/LayoutText.h" |
| 29 #include "core/layout/TextAutosizer.h" | 30 #include "core/layout/TextAutosizer.h" |
| 30 | 31 |
| 31 namespace blink { | 32 namespace blink { |
| 32 | 33 |
| 33 TableLayoutAlgorithmAuto::TableLayoutAlgorithmAuto(LayoutTable* table) | 34 TableLayoutAlgorithmAuto::TableLayoutAlgorithmAuto(LayoutTable* table) |
| 34 : TableLayoutAlgorithm(table) | 35 : TableLayoutAlgorithm(table) |
| 35 , m_hasPercent(false) | 36 , m_hasPercent(false) |
| 36 , m_effectiveLogicalWidthDirty(true) | 37 , m_effectiveLogicalWidthDirty(true) |
| 37 { | 38 { |
| 38 } | 39 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 toLayoutTableCol(child)->clearPreferredLogicalWidthsDirtyBits(); | 57 toLayoutTableCol(child)->clearPreferredLogicalWidthsDirtyBits(); |
| 57 } else if (child->isTableSection()) { | 58 } else if (child->isTableSection()) { |
| 58 LayoutTableSection* section = toLayoutTableSection(child); | 59 LayoutTableSection* section = toLayoutTableSection(child); |
| 59 unsigned numRows = section->numRows(); | 60 unsigned numRows = section->numRows(); |
| 60 for (unsigned i = 0; i < numRows; i++) { | 61 for (unsigned i = 0; i < numRows; i++) { |
| 61 LayoutTableSection::CellStruct current = section->cellAt(i, effC
ol); | 62 LayoutTableSection::CellStruct current = section->cellAt(i, effC
ol); |
| 62 LayoutTableCell* cell = current.primaryCell(); | 63 LayoutTableCell* cell = current.primaryCell(); |
| 63 | 64 |
| 64 if (current.inColSpan || !cell) | 65 if (current.inColSpan || !cell) |
| 65 continue; | 66 continue; |
| 67 columnLayout.columnHasNoCells = false; |
| 66 | 68 |
| 67 bool cellHasContent = cell->children()->firstChild() || cell->st
yle()->hasBorder() || cell->style()->hasPadding() || cell->style()->hasBackgroun
d(); | 69 bool cellHasContent = cell->minPreferredLogicalWidth(); |
| 68 if (cellHasContent) | 70 if (cellHasContent) |
| 69 columnLayout.emptyCellsOnly = false; | 71 columnLayout.emptyCellsOnly = false; |
| 70 | 72 |
| 71 // A cell originates in this column. Ensure we have | 73 // A cell originates in this column. Ensure we have |
| 72 // a min/max width of at least 1px for this column now. | 74 // a min/max width of at least 1px for this column now. |
| 73 columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLog
icalWidth, cellHasContent ? 1 : 0); | 75 columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLog
icalWidth, cellHasContent ? 1 : 0); |
| 74 columnLayout.maxLogicalWidth = std::max<int>(columnLayout.maxLog
icalWidth, 1); | |
| 75 | 76 |
| 76 if (cell->colSpan() == 1) { | 77 if (cell->colSpan() == 1) { |
| 77 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer
redLogicalWidth(), columnLayout.minLogicalWidth); | 78 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer
redLogicalWidth(), columnLayout.minLogicalWidth); |
| 78 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic
alWidth) { | 79 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic
alWidth) { |
| 79 columnLayout.maxLogicalWidth = cell->maxPreferredLogical
Width(); | 80 columnLayout.maxLogicalWidth = cell->maxPreferredLogical
Width(); |
| 80 maxContributor = cell; | 81 maxContributor = cell; |
| 81 } | 82 } |
| 82 | 83 |
| 83 // All browsers implement a size limit on the cell's max wid
th. | 84 // 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. | 85 // Our limit is based on KHTML's representation that used 16
bits widths. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // can't satify this condition, treat as variable | 367 // can't satify this condition, treat as variable |
| 367 cellLogicalWidth = Length(); | 368 cellLogicalWidth = Length(); |
| 368 } else { | 369 } else { |
| 369 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std
::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100 / cellLogicalWidth.percen
t())); | 370 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std
::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100 / cellLogicalWidth.percen
t())); |
| 370 | 371 |
| 371 // all non percent columns in the span get percent values to sum
up correctly. | 372 // all non percent columns in the span get percent values to sum
up correctly. |
| 372 float percentMissing = cellLogicalWidth.percent() - totalPercent
; | 373 float percentMissing = cellLogicalWidth.percent() - totalPercent
; |
| 373 int totalWidth = 0; | 374 int totalWidth = 0; |
| 374 for (unsigned pos = effCol; pos < lastCol; ++pos) { | 375 for (unsigned pos = effCol; pos < lastCol; ++pos) { |
| 375 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) | 376 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) |
| 376 totalWidth += m_layoutStruct[pos].effectiveMaxLogicalWid
th; | 377 totalWidth += m_layoutStruct[pos].clampedEffectiveMaxLog
icalWidth(); |
| 377 } | 378 } |
| 378 | 379 |
| 379 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p
os) { | 380 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p
os) { |
| 380 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
{ | 381 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
{ |
| 381 float percent = percentMissing * static_cast<float>(m_la
youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth; | 382 float percent = percentMissing * static_cast<float>(m_la
youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth; |
| 382 totalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWid
th; | 383 totalWidth -= m_layoutStruct[pos].clampedEffectiveMaxLog
icalWidth(); |
| 383 percentMissing -= percent; | 384 percentMissing -= percent; |
| 384 if (percent > 0) | 385 if (percent > 0) |
| 385 m_layoutStruct[pos].effectiveLogicalWidth.setValue(P
ercent, percent); | 386 m_layoutStruct[pos].effectiveLogicalWidth.setValue(P
ercent, percent); |
| 386 else | 387 else |
| 387 m_layoutStruct[pos].effectiveLogicalWidth = Length()
; | 388 m_layoutStruct[pos].effectiveLogicalWidth = Length()
; |
| 388 } | 389 } |
| 389 } | 390 } |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 | 393 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; | 532 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; |
| 532 available -= cellLogicalWidth; | 533 available -= cellLogicalWidth; |
| 533 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 534 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
| 534 switch (logicalWidth.type()) { | 535 switch (logicalWidth.type()) { |
| 535 case Percent: | 536 case Percent: |
| 536 havePercent = true; | 537 havePercent = true; |
| 537 totalPercent += logicalWidth.percent(); | 538 totalPercent += logicalWidth.percent(); |
| 538 break; | 539 break; |
| 539 case Fixed: | 540 case Fixed: |
| 540 numFixed++; | 541 numFixed++; |
| 541 totalFixed += m_layoutStruct[i].effectiveMaxLogicalWidth; | 542 totalFixed += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); |
| 542 // fall through | 543 // fall through |
| 543 break; | 544 break; |
| 544 case Auto: | 545 case Auto: |
| 545 if (m_layoutStruct[i].emptyCellsOnly) { | 546 if (m_layoutStruct[i].emptyCellsOnly) { |
| 546 numAutoEmptyCellsOnly++; | 547 numAutoEmptyCellsOnly++; |
| 547 } else { | 548 } else { |
| 548 numAuto++; | 549 numAuto++; |
| 549 totalAuto += m_layoutStruct[i].effectiveMaxLogicalWidth; | 550 totalAuto += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth()
; |
| 550 allocAuto += cellLogicalWidth; | 551 allocAuto += cellLogicalWidth; |
| 551 } | 552 } |
| 552 break; | 553 break; |
| 553 default: | 554 default: |
| 554 break; | 555 break; |
| 555 } | 556 } |
| 556 } | 557 } |
| 557 | 558 |
| 558 // allocate width to percent cols | 559 // allocate width to percent cols |
| 559 if (available > 0 && havePercent) { | 560 if (available > 0 && havePercent) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); | 593 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); |
| 593 } | 594 } |
| 594 } | 595 } |
| 595 } | 596 } |
| 596 | 597 |
| 597 // Give each auto width column its share of the available width. | 598 // Give each auto width column its share of the available width. |
| 598 if (available > 0 && numAuto) { | 599 if (available > 0 && numAuto) { |
| 599 available += allocAuto; | 600 available += allocAuto; |
| 600 distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start
ToEnd>(available, totalAuto); | 601 distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start
ToEnd>(available, totalAuto); |
| 601 } | 602 } |
| 603 if (available > 0 && numAutoEmptyCellsOnly) { |
| 604 unsigned total = numAutoEmptyCellsOnly; |
| 605 distributeWidthToColumns<float, Auto, EmptyCells, InitialWidth, StartToE
nd>(available, total); |
| 606 } |
| 602 | 607 |
| 603 // Any remaining available width expands fixed width, percent width and non-
empty auto width columns, in that order. | 608 // Any remaining available width expands fixed width, percent width, non-emp
ty auto width columns and empty auto width columns, in that order. |
| 604 if (available > 0 && numFixed) | 609 if (available > 0 && numFixed) |
| 605 distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd>
(available, totalFixed); | 610 distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd>
(available, totalFixed); |
| 606 | 611 |
| 607 if (available > 0 && m_hasPercent && totalPercent < 100) | 612 if (available > 0 && m_hasPercent && totalPercent < 100) |
| 608 distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn
d>(available, totalPercent); | 613 distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn
d>(available, totalPercent); |
| 609 | 614 |
| 610 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { | 615 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { |
| 611 unsigned total = nEffCols - numAutoEmptyCellsOnly; | 616 unsigned total = nEffCols - numAutoEmptyCellsOnly; |
| 612 // Starting from the last cell is for compatibility with FF/IE - it isn'
t specified anywhere. | 617 // 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); | 618 distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E
ndToStart>(available, total); |
| 614 } | 619 } |
| 615 | 620 |
| 621 if (available > 0) { |
| 622 unsigned total = numAutoEmptyCellsOnly; |
| 623 distributeWidthToColumns<unsigned, Auto, EmptyCells, LeftoverWidth, EndT
oStart>(available, total); |
| 624 } |
| 625 |
| 616 // If we have overallocated, reduce every cell according to the difference b
etween desired width and minwidth | 626 // 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. | 627 // 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. | 628 // This is basically the reverse of how we grew the cells. |
| 619 if (available < 0) | 629 if (available < 0) |
| 620 shrinkColumnWidth(Auto, available); | 630 shrinkColumnWidth(Auto, available); |
| 621 if (available < 0) | 631 if (available < 0) |
| 622 shrinkColumnWidth(Fixed, available); | 632 shrinkColumnWidth(Fixed, available); |
| 623 if (available < 0) | 633 if (available < 0) |
| 624 shrinkColumnWidth(Percent, available); | 634 shrinkColumnWidth(Percent, available); |
| 625 | 635 |
| 626 int pos = 0; | 636 int pos = 0; |
| 627 for (size_t i = 0; i < nEffCols; ++i) { | 637 for (size_t i = 0; i < nEffCols; ++i) { |
| 628 m_table->setColumnPosition(i, pos); | 638 m_table->setColumnPosition(i, pos); |
| 629 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing(
); | 639 pos += m_layoutStruct[i].computedLogicalWidth + m_table->hBorderSpacing(
); |
| 630 } | 640 } |
| 631 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos); | 641 m_table->setColumnPosition(m_table->columnPositions().size() - 1, pos); |
| 632 } | 642 } |
| 633 | 643 |
| 634 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D
istributionMode distributionMode, DistributionDirection distributionDirection> | 644 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D
istributionMode distributionMode, DistributionDirection distributionDirection> |
| 635 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total to
tal) | 645 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total to
tal) |
| 636 { | 646 { |
| 637 // TODO(alancutter): Make this work correctly for calc lengths. | 647 // TODO(alancutter): Make this work correctly for calc lengths. |
| 638 int nEffCols = static_cast<int>(m_table->numEffCols()); | 648 int nEffCols = static_cast<int>(m_table->numEffCols()); |
| 639 bool startToEnd = distributionDirection == StartToEnd; | 649 bool startToEnd = distributionDirection == StartToEnd; |
| 640 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i >
-1; startToEnd ? ++i : --i) { | 650 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i >
-1; startToEnd ? ++i : --i) { |
| 641 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 651 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
| 642 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout
Struct[i].emptyCellsOnly) | 652 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout
Struct[i].emptyCellsOnly) |
| 643 continue; | 653 continue; |
| 654 // When allocating width to columns with nothing but empty cells we avoi
d columns that exist only to flesh out a colspan and have no actual cells. |
| 655 if (cellsToProcess == EmptyCells && logicalWidth.isAuto() && (!m_layoutS
truct[i].emptyCellsOnly || m_layoutStruct[i].columnHasNoCells)) |
| 656 continue; |
| 644 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy
pe) | 657 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy
pe) |
| 645 continue; | 658 continue; |
| 646 | 659 |
| 647 float factor = 1; | 660 float factor = 1; |
| 648 if (distributionMode != LeftoverWidth) { | 661 if (distributionMode != LeftoverWidth) { |
| 649 if (lengthType == Percent) | 662 if (lengthType == Percent) |
| 650 factor = logicalWidth.percent(); | 663 factor = logicalWidth.percent(); |
| 651 else if (lengthType == Auto || lengthType == Fixed) | 664 else if (lengthType == Auto || lengthType == Fixed) |
| 652 factor = m_layoutStruct[i].effectiveMaxLogicalWidth; | 665 factor = m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); |
| 653 } | 666 } |
| 654 | 667 |
| 655 int newWidth = available * factor / total; | 668 int newWidth = available * factor / total; |
| 656 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l
ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; | 669 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l
ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; |
| 657 available -= cellLogicalWidth; | 670 available -= cellLogicalWidth; |
| 658 total -= factor; | 671 total -= factor; |
| 659 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid
th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid
th; | 672 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid
th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid
th; |
| 660 | 673 |
| 661 // If we have run out of width to allocate we're done. | 674 // 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. | 675 // Also, any overallocation will be unwound later so no point in buildin
g up cells to unwind, just bail now. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 684 int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 697 int reduce = available * minMaxDiff / logicalWidthBeyondMin; |
| 685 m_layoutStruct[i].computedLogicalWidth += reduce; | 698 m_layoutStruct[i].computedLogicalWidth += reduce; |
| 686 available -= reduce; | 699 available -= reduce; |
| 687 logicalWidthBeyondMin -= minMaxDiff; | 700 logicalWidthBeyondMin -= minMaxDiff; |
| 688 if (available >= 0) | 701 if (available >= 0) |
| 689 break; | 702 break; |
| 690 } | 703 } |
| 691 } | 704 } |
| 692 } | 705 } |
| 693 } | 706 } |
| OLD | NEW |