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

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

Issue 2261663002: Disallow cast/implicit conversion from LayoutUnit to int/unsigned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: - Created 4 years, 3 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 columnLayout.columnHasNoCells = false;
67 67
68 if (cell->maxPreferredLogicalWidth()) 68 if (cell->maxPreferredLogicalWidth())
69 columnLayout.emptyCellsOnly = false; 69 columnLayout.emptyCellsOnly = false;
70 70
71 if (cell->colSpan() == 1) { 71 if (cell->colSpan() == 1) {
72 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer redLogicalWidth(), columnLayout.minLogicalWidth); 72 columnLayout.minLogicalWidth = std::max<int>(cell->minPrefer redLogicalWidth().toInt(), columnLayout.minLogicalWidth);
73 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic alWidth) { 73 if (cell->maxPreferredLogicalWidth() > columnLayout.maxLogic alWidth) {
74 columnLayout.maxLogicalWidth = cell->maxPreferredLogical Width(); 74 columnLayout.maxLogicalWidth = cell->maxPreferredLogical Width().toInt();
75 maxContributor = cell; 75 maxContributor = cell;
76 } 76 }
77 77
78 // 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.
79 // 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.
80 // 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.
81 const int cCellMaxWidth = 32760; 81 const int cCellMaxWidth = 32760;
82 Length cellLogicalWidth = cell->styleOrColLogicalWidth(); 82 Length cellLogicalWidth = cell->styleOrColLogicalWidth();
83 // FIXME: calc() on tables should be handled consistently wi th other lengths. See bug: https://crbug.com/382725 83 // FIXME: calc() on tables should be handled consistently wi th other lengths. See bug: https://crbug.com/382725
84 if (cellLogicalWidth.isCalculated()) 84 if (cellLogicalWidth.isCalculated())
85 cellLogicalWidth = Length(); // Make it Auto 85 cellLogicalWidth = Length(); // Make it Auto
86 if (cellLogicalWidth.value() > cCellMaxWidth) 86 if (cellLogicalWidth.value() > cCellMaxWidth)
87 cellLogicalWidth.setValue(cCellMaxWidth); 87 cellLogicalWidth.setValue(cCellMaxWidth);
88 if (cellLogicalWidth.isNegative()) 88 if (cellLogicalWidth.isNegative())
89 cellLogicalWidth.setValue(0); 89 cellLogicalWidth.setValue(0);
90 switch (cellLogicalWidth.type()) { 90 switch (cellLogicalWidth.type()) {
91 case Fixed: 91 case Fixed:
92 // ignore width=0 92 // ignore width=0
93 if (cellLogicalWidth.isPositive() && !columnLayout.logic alWidth.hasPercent()) { 93 if (cellLogicalWidth.isPositive() && !columnLayout.logic alWidth.hasPercent()) {
94 int logicalWidth = cell->adjustBorderBoxLogicalWidth ForBoxSizing(cellLogicalWidth.value()); 94 int logicalWidth = cell->adjustBorderBoxLogicalWidth ForBoxSizing(cellLogicalWidth.value()).toInt();
95 if (columnLayout.logicalWidth.isFixed()) { 95 if (columnLayout.logicalWidth.isFixed()) {
96 // Nav/IE weirdness 96 // Nav/IE weirdness
97 if ((logicalWidth > columnLayout.logicalWidth.va lue()) 97 if ((logicalWidth > columnLayout.logicalWidth.va lue())
98 || ((columnLayout.logicalWidth.value() == lo gicalWidth) && (maxContributor == cell))) { 98 || ((columnLayout.logicalWidth.value() == lo gicalWidth) && (maxContributor == cell))) {
99 columnLayout.logicalWidth.setValue(Fixed, lo gicalWidth); 99 columnLayout.logicalWidth.setValue(Fixed, lo gicalWidth);
100 fixedContributor = cell; 100 fixedContributor = cell;
101 } 101 }
102 } else { 102 } else {
103 columnLayout.logicalWidth.setValue(Fixed, logica lWidth); 103 columnLayout.logicalWidth.setValue(Fixed, logica lWidth);
104 fixedContributor = cell; 104 fixedContributor = cell;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 unsigned span = cell->colSpan(); 315 unsigned span = cell->colSpan();
316 316
317 Length cellLogicalWidth = cell->styleOrColLogicalWidth(); 317 Length cellLogicalWidth = cell->styleOrColLogicalWidth();
318 // FIXME: calc() on tables should be handled consistently with other len gths. See bug: https://crbug.com/382725 318 // FIXME: calc() on tables should be handled consistently with other len gths. See bug: https://crbug.com/382725
319 if (cellLogicalWidth.isZero() || cellLogicalWidth.isCalculated()) 319 if (cellLogicalWidth.isZero() || cellLogicalWidth.isCalculated())
320 cellLogicalWidth = Length(); // Make it Auto 320 cellLogicalWidth = Length(); // Make it Auto
321 321
322 unsigned effCol = m_table->absoluteColumnToEffectiveColumn(cell->absolut eColumnIndex()); 322 unsigned effCol = m_table->absoluteColumnToEffectiveColumn(cell->absolut eColumnIndex());
323 size_t lastCol = effCol; 323 size_t lastCol = effCol;
324 int cellMinLogicalWidth = cell->minPreferredLogicalWidth() + spacingInRo wDirection; 324 int cellMinLogicalWidth = (cell->minPreferredLogicalWidth() + spacingInR owDirection).toInt();
325 int cellMaxLogicalWidth = cell->maxPreferredLogicalWidth() + spacingInRo wDirection; 325 int cellMaxLogicalWidth = (cell->maxPreferredLogicalWidth() + spacingInR owDirection).toInt();
326 float totalPercent = 0; 326 float totalPercent = 0;
327 int spanMinLogicalWidth = 0; 327 int spanMinLogicalWidth = 0;
328 int spanMaxLogicalWidth = 0; 328 int spanMaxLogicalWidth = 0;
329 bool allColsArePercent = true; 329 bool allColsArePercent = true;
330 bool allColsAreFixed = true; 330 bool allColsAreFixed = true;
331 bool haveAuto = false; 331 bool haveAuto = false;
332 bool spanHasEmptyCellsOnly = true; 332 bool spanHasEmptyCellsOnly = true;
333 int fixedWidth = 0; 333 int fixedWidth = 0;
334 while (lastCol < nEffCols && span > 0) { 334 while (lastCol < nEffCols && span > 0) {
335 Layout& columnLayout = m_layoutStruct[lastCol]; 335 Layout& columnLayout = m_layoutStruct[lastCol];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 while (pos < m_spanCells.size() && m_spanCells[pos] && span > m_spanCells[po s]->colSpan()) 512 while (pos < m_spanCells.size() && m_spanCells[pos] && span > m_spanCells[po s]->colSpan())
513 pos++; 513 pos++;
514 memmove(m_spanCells.data()+pos+1, m_spanCells.data()+pos, (size-pos-1)*sizeo f(LayoutTableCell *)); 514 memmove(m_spanCells.data()+pos+1, m_spanCells.data()+pos, (size-pos-1)*sizeo f(LayoutTableCell *));
515 m_spanCells[pos] = cell; 515 m_spanCells[pos] = cell;
516 } 516 }
517 517
518 518
519 void TableLayoutAlgorithmAuto::layout() 519 void TableLayoutAlgorithmAuto::layout()
520 { 520 {
521 // table layout based on the values collected in the layout structure. 521 // table layout based on the values collected in the layout structure.
522 int tableLogicalWidth = m_table->logicalWidth() - m_table->bordersPaddingAnd SpacingInRowDirection(); 522 int tableLogicalWidth = (m_table->logicalWidth() - m_table->bordersPaddingAn dSpacingInRowDirection()).toInt();
523 int available = tableLogicalWidth; 523 int available = tableLogicalWidth;
524 size_t nEffCols = m_table->numEffectiveColumns(); 524 size_t nEffCols = m_table->numEffectiveColumns();
525 525
526 // FIXME: It is possible to be called without having properly updated our in ternal representation. 526 // FIXME: It is possible to be called without having properly updated our in ternal representation.
527 // This means that our preferred logical widths were not recomputed as expec ted. 527 // This means that our preferred logical widths were not recomputed as expec ted.
528 if (nEffCols != m_layoutStruct.size()) { 528 if (nEffCols != m_layoutStruct.size()) {
529 fullRecalc(); 529 fullRecalc();
530 // FIXME: Table layout shouldn't modify our table structure (but does du e to columns and column-groups). 530 // FIXME: Table layout shouldn't modify our table structure (but does du e to columns and column-groups).
531 nEffCols = m_table->numEffectiveColumns(); 531 nEffCols = m_table->numEffectiveColumns();
532 } 532 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 break; 573 break;
574 } 574 }
575 } 575 }
576 576
577 // allocate width to percent cols 577 // allocate width to percent cols
578 if (available > 0 && havePercent) { 578 if (available > 0 && havePercent) {
579 for (size_t i = 0; i < nEffCols; ++i) { 579 for (size_t i = 0; i < nEffCols; ++i) {
580 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; 580 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth;
581 if (logicalWidth.hasPercent()) { 581 if (logicalWidth.hasPercent()) {
582 int cellLogicalWidth = std::max<int>(m_layoutStruct[i].effective MinLogicalWidth, 582 int cellLogicalWidth = std::max<int>(m_layoutStruct[i].effective MinLogicalWidth,
583 minimumValueForLength(logicalWidth, LayoutUnit(tableLogicalW idth))); 583 minimumValueForLength(logicalWidth, LayoutUnit(tableLogicalW idth)).toInt());
584 available += m_layoutStruct[i].computedLogicalWidth - cellLogica lWidth; 584 available += m_layoutStruct[i].computedLogicalWidth - cellLogica lWidth;
585 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; 585 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth;
586 } 586 }
587 } 587 }
588 if (totalPercent > 100) { 588 if (totalPercent > 100) {
589 // remove overallocated space from the last columns 589 // remove overallocated space from the last columns
590 int excess = tableLogicalWidth * (totalPercent - 100) / 100; 590 int excess = tableLogicalWidth * (totalPercent - 100) / 100;
591 for (unsigned i = nEffCols; i; ) { 591 for (unsigned i = nEffCols; i; ) {
592 --i; 592 --i;
593 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { 593 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 int reduce = available * minMaxDiff / logicalWidthBeyondMin; 715 int reduce = available * minMaxDiff / logicalWidthBeyondMin;
716 m_layoutStruct[i].computedLogicalWidth += reduce; 716 m_layoutStruct[i].computedLogicalWidth += reduce;
717 available -= reduce; 717 available -= reduce;
718 logicalWidthBeyondMin -= minMaxDiff; 718 logicalWidthBeyondMin -= minMaxDiff;
719 if (available >= 0) 719 if (available >= 0)
720 break; 720 break;
721 } 721 }
722 } 722 }
723 } 723 }
724 } // namespace blink 724 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698