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

Side by Side Diff: third_party/WebKit/Source/core/layout/TableLayoutAlgorithmFixed.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, 4 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, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc.
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 // FIXME: calc() on tables should be handled consistently with other len gths. See bug: https://crbug.com/382725 142 // FIXME: calc() on tables should be handled consistently with other len gths. See bug: https://crbug.com/382725
143 if (logicalWidth.isCalculated()) 143 if (logicalWidth.isCalculated())
144 logicalWidth = Length(); // Make it Auto 144 logicalWidth = Length(); // Make it Auto
145 145
146 unsigned span = cell->colSpan(); 146 unsigned span = cell->colSpan();
147 int fixedBorderBoxLogicalWidth = 0; 147 int fixedBorderBoxLogicalWidth = 0;
148 // FIXME: Support other length types. If the width is non-auto, it shoul d probably just use 148 // FIXME: Support other length types. If the width is non-auto, it shoul d probably just use
149 // LayoutBox::computeLogicalWidthUsing to compute the width. 149 // LayoutBox::computeLogicalWidthUsing to compute the width.
150 if (logicalWidth.isFixed() && logicalWidth.isPositive()) { 150 if (logicalWidth.isFixed() && logicalWidth.isPositive()) {
151 fixedBorderBoxLogicalWidth = cell->adjustBorderBoxLogicalWidthForBox Sizing(logicalWidth.value()); 151 fixedBorderBoxLogicalWidth = cell->adjustBorderBoxLogicalWidthForBox Sizing(logicalWidth.value()).toInt();
152 logicalWidth.setValue(fixedBorderBoxLogicalWidth); 152 logicalWidth.setValue(fixedBorderBoxLogicalWidth);
153 } 153 }
154 154
155 unsigned usedSpan = 0; 155 unsigned usedSpan = 0;
156 while (usedSpan < span && currentColumn < nEffCols) { 156 while (usedSpan < span && currentColumn < nEffCols) {
157 float eSpan = m_table->spanOfEffectiveColumn(currentColumn); 157 float eSpan = m_table->spanOfEffectiveColumn(currentColumn);
158 // Only set if no col element has already set it. 158 // Only set if no col element has already set it.
159 if (m_width[currentColumn].isAuto() && logicalWidth.type() != Auto) { 159 if (m_width[currentColumn].isAuto() && logicalWidth.type() != Auto) {
160 m_width[currentColumn] = logicalWidth; 160 m_width[currentColumn] = logicalWidth;
161 m_width[currentColumn] *= eSpan / span; 161 m_width[currentColumn] *= eSpan / span;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 */ 198 */
199 // In this example, the two inner tables should be as large as the outer tab le. 199 // In this example, the two inner tables should be as large as the outer tab le.
200 // We can achieve this effect by making the maxwidth of fixed tables with pe rcentage 200 // We can achieve this effect by making the maxwidth of fixed tables with pe rcentage
201 // widths be infinite. 201 // widths be infinite.
202 if (m_table->style()->logicalWidth().hasPercent() && maxWidth < tableMaxWidt h) 202 if (m_table->style()->logicalWidth().hasPercent() && maxWidth < tableMaxWidt h)
203 maxWidth = LayoutUnit(tableMaxWidth); 203 maxWidth = LayoutUnit(tableMaxWidth);
204 } 204 }
205 205
206 void TableLayoutAlgorithmFixed::layout() 206 void TableLayoutAlgorithmFixed::layout()
207 { 207 {
208 int tableLogicalWidth = m_table->logicalWidth() - m_table->bordersPaddingAnd SpacingInRowDirection(); 208 int tableLogicalWidth = (m_table->logicalWidth() - m_table->bordersPaddingAn dSpacingInRowDirection()).toInt();
209 unsigned nEffCols = m_table->numEffectiveColumns(); 209 unsigned nEffCols = m_table->numEffectiveColumns();
210 210
211 // FIXME: It is possible to be called without having properly updated our in ternal representation. 211 // FIXME: It is possible to be called without having properly updated our in ternal representation.
212 // This means that our preferred logical widths were not recomputed as expec ted. 212 // This means that our preferred logical widths were not recomputed as expec ted.
213 if (nEffCols != m_width.size()) { 213 if (nEffCols != m_width.size()) {
214 calcWidthArray(); 214 calcWidthArray();
215 // FIXME: Table layout shouldn't modify our table structure (but does du e to columns and column-groups). 215 // FIXME: Table layout shouldn't modify our table structure (but does du e to columns and column-groups).
216 nEffCols = m_table->numEffectiveColumns(); 216 nEffCols = m_table->numEffectiveColumns();
217 } 217 }
218 218
219 Vector<int> calcWidth(nEffCols, 0); 219 Vector<int> calcWidth(nEffCols, 0);
220 220
221 unsigned numAuto = 0; 221 unsigned numAuto = 0;
222 unsigned autoSpan = 0; 222 unsigned autoSpan = 0;
223 int totalFixedWidth = 0; 223 int totalFixedWidth = 0;
224 int totalPercentWidth = 0; 224 int totalPercentWidth = 0;
225 float totalPercent = 0; 225 float totalPercent = 0;
226 226
227 // Compute requirements and try to satisfy fixed and percent widths. 227 // Compute requirements and try to satisfy fixed and percent widths.
228 // Percentages are of the table's width, so for example 228 // Percentages are of the table's width, so for example
229 // for a table width of 100px with columns (40px, 10%), the 10% compute 229 // for a table width of 100px with columns (40px, 10%), the 10% compute
230 // to 10px here, and will scale up to 20px in the final (80px, 20px). 230 // to 10px here, and will scale up to 20px in the final (80px, 20px).
231 for (unsigned i = 0; i < nEffCols; i++) { 231 for (unsigned i = 0; i < nEffCols; i++) {
232 if (m_width[i].isFixed()) { 232 if (m_width[i].isFixed()) {
233 calcWidth[i] = m_width[i].value(); 233 calcWidth[i] = m_width[i].value();
234 totalFixedWidth += calcWidth[i]; 234 totalFixedWidth += calcWidth[i];
235 } else if (m_width[i].hasPercent()) { 235 } else if (m_width[i].hasPercent()) {
236 // TODO(alancutter): Make this work correctly for calc lengths. 236 // TODO(alancutter): Make this work correctly for calc lengths.
237 calcWidth[i] = valueForLength(m_width[i], LayoutUnit(tableLogicalWid th)); 237 calcWidth[i] = valueForLength(m_width[i], LayoutUnit(tableLogicalWid th)).toInt();
238 totalPercentWidth += calcWidth[i]; 238 totalPercentWidth += calcWidth[i];
239 totalPercent += m_width[i].percent(); 239 totalPercent += m_width[i].percent();
240 } else if (m_width[i].isAuto()) { 240 } else if (m_width[i].isAuto()) {
241 numAuto++; 241 numAuto++;
242 autoSpan += m_table->spanOfEffectiveColumn(i); 242 autoSpan += m_table->spanOfEffectiveColumn(i);
243 } 243 }
244 } 244 }
245 245
246 int hspacing = m_table->hBorderSpacing(); 246 int hspacing = m_table->hBorderSpacing();
247 int totalWidth = totalFixedWidth + totalPercentWidth; 247 int totalWidth = totalFixedWidth + totalPercentWidth;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // When switching table layout algorithm, we need to dirty the preferred 324 // When switching table layout algorithm, we need to dirty the preferred
325 // logical widths as we cleared the bits without computing them. 325 // logical widths as we cleared the bits without computing them.
326 // (see calcWidthArray above.) This optimization is preferred to always 326 // (see calcWidthArray above.) This optimization is preferred to always
327 // computing the logical widths we never intended to use. 327 // computing the logical widths we never intended to use.
328 m_table->recalcSectionsIfNeeded(); 328 m_table->recalcSectionsIfNeeded();
329 for (LayoutTableSection* section = m_table->topNonEmptySection(); section; s ection = m_table->sectionBelow(section)) 329 for (LayoutTableSection* section = m_table->topNonEmptySection(); section; s ection = m_table->sectionBelow(section))
330 section->markAllCellsWidthsDirtyAndOrNeedsLayout(LayoutTableSection::Mar kDirtyOnly); 330 section->markAllCellsWidthsDirtyAndOrNeedsLayout(LayoutTableSection::Mar kDirtyOnly);
331 } 331 }
332 332
333 } // namespace blink 333 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698