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

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

Issue 1177653002: Revert "Don't add artifical 1 pixel width to empty tables" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
« 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
67 66
68 bool cellHasContent = cell->minPreferredLogicalWidth(); 67 bool cellHasContent = cell->children()->firstChild() || cell->st yle()->hasBorder() || cell->style()->hasPadding() || cell->style()->hasBackgroun d();
69 if (cellHasContent) 68 if (cellHasContent)
70 columnLayout.emptyCellsOnly = false; 69 columnLayout.emptyCellsOnly = false;
71 70
72 // A cell originates in this column. Ensure we have 71 // A cell originates in this column. Ensure we have
73 // a min/max width of at least 1px for this column now. 72 // a min/max width of at least 1px for this column now.
74 columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLog icalWidth, cellHasContent ? 1 : 0); 73 columnLayout.minLogicalWidth = std::max<int>(columnLayout.minLog icalWidth, cellHasContent ? 1 : 0);
74 columnLayout.maxLogicalWidth = std::max<int>(columnLayout.maxLog icalWidth, 1);
75 75
76 if (cell->colSpan() == 1) { 76 if (cell->colSpan() == 1) {
77 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer redLogicalWidth(), columnLayout.minLogicalWidth); 77 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer redLogicalWidth(), columnLayout.minLogicalWidth);
78 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic alWidth) { 78 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic alWidth) {
79 columnLayout.maxLogicalWidth = cell->maxPreferredLogical Width(); 79 columnLayout.maxLogicalWidth = cell->maxPreferredLogical Width();
80 maxContributor = cell; 80 maxContributor = cell;
81 } 81 }
82 82
83 // All browsers implement a size limit on the cell's max wid th. 83 // 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. 84 // 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
366 // can't satify this condition, treat as variable 366 // can't satify this condition, treat as variable
367 cellLogicalWidth = Length(); 367 cellLogicalWidth = Length();
368 } else { 368 } else {
369 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std ::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100 / cellLogicalWidth.percen t())); 369 maxLogicalWidth = std::max(maxLogicalWidth, static_cast<int>(std ::max(spanMaxLogicalWidth, cellMaxLogicalWidth) * 100 / cellLogicalWidth.percen t()));
370 370
371 // all non percent columns in the span get percent values to sum up correctly. 371 // all non percent columns in the span get percent values to sum up correctly.
372 float percentMissing = cellLogicalWidth.percent() - totalPercent ; 372 float percentMissing = cellLogicalWidth.percent() - totalPercent ;
373 int totalWidth = 0; 373 int totalWidth = 0;
374 for (unsigned pos = effCol; pos < lastCol; ++pos) { 374 for (unsigned pos = effCol; pos < lastCol; ++pos) {
375 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) 375 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent())
376 totalWidth += m_layoutStruct[pos].clampedEffectiveMaxLog icalWidth(); 376 totalWidth += m_layoutStruct[pos].effectiveMaxLogicalWid th;
377 } 377 }
378 378
379 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p os) { 379 for (unsigned pos = effCol; pos < lastCol && totalWidth > 0; ++p os) {
380 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) { 380 if (!m_layoutStruct[pos].effectiveLogicalWidth.hasPercent()) {
381 float percent = percentMissing * static_cast<float>(m_la youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth; 381 float percent = percentMissing * static_cast<float>(m_la youtStruct[pos].effectiveMaxLogicalWidth) / totalWidth;
382 totalWidth -= m_layoutStruct[pos].clampedEffectiveMaxLog icalWidth(); 382 totalWidth -= m_layoutStruct[pos].effectiveMaxLogicalWid th;
383 percentMissing -= percent; 383 percentMissing -= percent;
384 if (percent > 0) 384 if (percent > 0)
385 m_layoutStruct[pos].effectiveLogicalWidth.setValue(P ercent, percent); 385 m_layoutStruct[pos].effectiveLogicalWidth.setValue(P ercent, percent);
386 else 386 else
387 m_layoutStruct[pos].effectiveLogicalWidth = Length() ; 387 m_layoutStruct[pos].effectiveLogicalWidth = Length() ;
388 } 388 }
389 } 389 }
390 } 390 }
391 } 391 }
392 392
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; 531 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth;
532 available -= cellLogicalWidth; 532 available -= cellLogicalWidth;
533 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; 533 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
534 switch (logicalWidth.type()) { 534 switch (logicalWidth.type()) {
535 case Percent: 535 case Percent:
536 havePercent = true; 536 havePercent = true;
537 totalPercent += logicalWidth.percent(); 537 totalPercent += logicalWidth.percent();
538 break; 538 break;
539 case Fixed: 539 case Fixed:
540 numFixed++; 540 numFixed++;
541 totalFixed += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); 541 totalFixed += m_layoutStruct[i].effectiveMaxLogicalWidth;
542 // fall through 542 // fall through
543 break; 543 break;
544 case Auto: 544 case Auto:
545 if (m_layoutStruct[i].emptyCellsOnly) { 545 if (m_layoutStruct[i].emptyCellsOnly) {
546 numAutoEmptyCellsOnly++; 546 numAutoEmptyCellsOnly++;
547 } else { 547 } else {
548 numAuto++; 548 numAuto++;
549 totalAuto += m_layoutStruct[i].clampedEffectiveMaxLogicalWidth() ; 549 totalAuto += m_layoutStruct[i].effectiveMaxLogicalWidth;
550 allocAuto += cellLogicalWidth; 550 allocAuto += cellLogicalWidth;
551 } 551 }
552 break; 552 break;
553 default: 553 default:
554 break; 554 break;
555 } 555 }
556 } 556 }
557 557
558 // allocate width to percent cols 558 // allocate width to percent cols
559 if (available > 0 && havePercent) { 559 if (available > 0 && havePercent) {
(...skipping 27 matching lines...) Expand all
587 if (available > 0) { 587 if (available > 0) {
588 for (size_t i = 0; i < nEffCols; ++i) { 588 for (size_t i = 0; i < nEffCols; ++i) {
589 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; 589 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
590 if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[ i].computedLogicalWidth) { 590 if (logicalWidth.isFixed() && logicalWidth.value() > m_layoutStruct[ i].computedLogicalWidth) {
591 available += m_layoutStruct[i].computedLogicalWidth - logicalWid th.value(); 591 available += m_layoutStruct[i].computedLogicalWidth - logicalWid th.value();
592 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value(); 592 m_layoutStruct[i].computedLogicalWidth = logicalWidth.value();
593 } 593 }
594 } 594 }
595 } 595 }
596 596
597 // Give each auto width column its share of the available width, non-empty c olumns then empty columns. 597 // Give each auto width column its share of the available width.
598 if (available > 0 && numAuto) { 598 if (available > 0 && numAuto) {
599 available += allocAuto; 599 available += allocAuto;
600 distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start ToEnd>(available, totalAuto); 600 distributeWidthToColumns<float, Auto, NonEmptyCells, InitialWidth, Start ToEnd>(available, totalAuto);
601 } 601 }
602 if (available > 0 && numAutoEmptyCellsOnly) {
603 unsigned total = numAutoEmptyCellsOnly;
604 distributeWidthToColumns<float, Auto, EmptyCells, InitialWidth, StartToE nd>(available, total);
605 }
606 602
607 // Any remaining available width expands fixed width, percent width, and non -empty auto width columns, in that order. 603 // Any remaining available width expands fixed width, percent width and non- empty auto width columns, in that order.
608 if (available > 0 && numFixed) 604 if (available > 0 && numFixed)
609 distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd> (available, totalFixed); 605 distributeWidthToColumns<float, Fixed, AllCells, ExtraWidth, StartToEnd> (available, totalFixed);
610 606
611 if (available > 0 && m_hasPercent && totalPercent < 100) 607 if (available > 0 && m_hasPercent && totalPercent < 100)
612 distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn d>(available, totalPercent); 608 distributeWidthToColumns<float, Percent, AllCells, ExtraWidth, StartToEn d>(available, totalPercent);
613 609
614 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) { 610 if (available > 0 && nEffCols > numAutoEmptyCellsOnly) {
615 unsigned total = nEffCols - numAutoEmptyCellsOnly; 611 unsigned total = nEffCols - numAutoEmptyCellsOnly;
616 // 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.
617 distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E ndToStart>(available, total); 613 distributeWidthToColumns<unsigned, Auto, NonEmptyCells, LeftoverWidth, E ndToStart>(available, total);
(...skipping 20 matching lines...) Expand all
638 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D istributionMode distributionMode, DistributionDirection distributionDirection> 634 template<typename Total, LengthType lengthType, CellsToProcess cellsToProcess, D istributionMode distributionMode, DistributionDirection distributionDirection>
639 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total to tal) 635 void TableLayoutAlgorithmAuto::distributeWidthToColumns(int& available, Total to tal)
640 { 636 {
641 // TODO(alancutter): Make this work correctly for calc lengths. 637 // TODO(alancutter): Make this work correctly for calc lengths.
642 int nEffCols = static_cast<int>(m_table->numEffCols()); 638 int nEffCols = static_cast<int>(m_table->numEffCols());
643 bool startToEnd = distributionDirection == StartToEnd; 639 bool startToEnd = distributionDirection == StartToEnd;
644 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) { 640 for (int i = startToEnd ? 0 : nEffCols - 1; startToEnd ? i < nEffCols : i > -1; startToEnd ? ++i : --i) {
645 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; 641 const Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
646 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout Struct[i].emptyCellsOnly) 642 if (cellsToProcess == NonEmptyCells && logicalWidth.isAuto() && m_layout Struct[i].emptyCellsOnly)
647 continue; 643 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;
652 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy pe) 644 if (distributionMode != LeftoverWidth && logicalWidth.type() != lengthTy pe)
653 continue; 645 continue;
654 646
655 float factor = 1; 647 float factor = 1;
656 if (distributionMode != LeftoverWidth) { 648 if (distributionMode != LeftoverWidth) {
657 if (lengthType == Percent) 649 if (lengthType == Percent)
658 factor = logicalWidth.percent(); 650 factor = logicalWidth.percent();
659 else if (lengthType == Auto || lengthType == Fixed) 651 else if (lengthType == Auto || lengthType == Fixed)
660 factor = m_layoutStruct[i].clampedEffectiveMaxLogicalWidth(); 652 factor = m_layoutStruct[i].effectiveMaxLogicalWidth;
661 } 653 }
662 654
663 int newWidth = available * factor / total; 655 int newWidth = available * factor / total;
664 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth; 656 int cellLogicalWidth = (distributionMode == InitialWidth) ? max<int>(m_l ayoutStruct[i].computedLogicalWidth, newWidth) : newWidth;
665 available -= cellLogicalWidth; 657 available -= cellLogicalWidth;
666 total -= factor; 658 total -= factor;
667 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid th; 659 m_layoutStruct[i].computedLogicalWidth = (distributionMode == InitialWid th) ? cellLogicalWidth : m_layoutStruct[i].computedLogicalWidth + cellLogicalWid th;
668 660
669 // If we have run out of width to allocate we're done. 661 // If we have run out of width to allocate we're done.
670 // Also, any overallocation will be unwound later so no point in buildin g up cells to unwind, just bail now. 662 // 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
692 int reduce = available * minMaxDiff / logicalWidthBeyondMin; 684 int reduce = available * minMaxDiff / logicalWidthBeyondMin;
693 m_layoutStruct[i].computedLogicalWidth += reduce; 685 m_layoutStruct[i].computedLogicalWidth += reduce;
694 available -= reduce; 686 available -= reduce;
695 logicalWidthBeyondMin -= minMaxDiff; 687 logicalWidthBeyondMin -= minMaxDiff;
696 if (available >= 0) 688 if (available >= 0)
697 break; 689 break;
698 } 690 }
699 } 691 }
700 } 692 }
701 } 693 }
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