Chromium Code Reviews| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 | 208 |
| 209 void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt h, LayoutUnit& maxWidth) | 209 void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt h, LayoutUnit& maxWidth) |
| 210 { | 210 { |
| 211 TextAutosizer::TableLayoutScope textAutosizerTableLayoutScope(m_table); | 211 TextAutosizer::TableLayoutScope textAutosizerTableLayoutScope(m_table); |
| 212 | 212 |
| 213 fullRecalc(); | 213 fullRecalc(); |
| 214 | 214 |
| 215 int spanMaxLogicalWidth = calcEffectiveLogicalWidth(); | 215 int spanMaxLogicalWidth = calcEffectiveLogicalWidth(); |
| 216 minWidth = LayoutUnit(); | 216 minWidth = LayoutUnit(); |
| 217 maxWidth = LayoutUnit(); | 217 maxWidth = LayoutUnit(); |
| 218 | |
| 219 for (size_t i = 0; i < m_layoutStruct.size(); ++i) { | |
| 220 minWidth += m_layoutStruct[i].effectiveMinLogicalWidth; | |
| 221 maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth; | |
| 222 } | |
| 223 | |
| 224 maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth)); | |
| 225 } | |
| 226 | |
| 227 LayoutUnit TableLayoutAlgorithmAuto::scaledWidthFromPercentColumns() | |
| 228 { | |
| 229 // Normally, scale all columns to satisfy this from CSS2.2: | |
| 230 // "A percentage value for a column width is relative to the table width. | |
| 231 // If the table has 'width: auto', a percentage represents a constraint on t he column's width" | |
| 232 if (!shouldScaleColumns(m_table)) | |
| 233 return LayoutUnit(0); | |
| 234 | |
| 218 float maxPercent = 0; | 235 float maxPercent = 0; |
| 219 float maxNonPercent = 0; | 236 float maxNonPercent = 0; |
| 220 bool scaleColumns = shouldScaleColumns(m_table); | |
| 221 | 237 |
| 222 // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two places below to avoid division by zero. | 238 // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two places below to avoid division by zero. |
| 223 // FIXME: Handle the 0% cases properly. | 239 // FIXME: Handle the 0% cases properly. |
| 224 const float epsilon = 1 / 128.0f; | 240 const float epsilon = 1 / 128.0f; |
| 225 | 241 |
| 226 float remainingPercent = 100; | 242 float remainingPercent = 100; |
| 227 for (size_t i = 0; i < m_layoutStruct.size(); ++i) { | 243 for (size_t i = 0; i < m_layoutStruct.size(); ++i) { |
| 228 minWidth += m_layoutStruct[i].effectiveMinLogicalWidth; | 244 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { |
|
dgrogan
2016/04/27 03:14:05
Your excerpt was instrumental in my understanding
| |
| 229 maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth; | 245 float percent = std::min(static_cast<float>(m_layoutStruct[i].effect iveLogicalWidth.percent()), remainingPercent); |
| 230 if (scaleColumns) { | 246 float logicalWidth = static_cast<float>(m_layoutStruct[i].effectiveM axLogicalWidth) * 100 / std::max(percent, epsilon); |
| 231 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { | 247 maxPercent = std::max(logicalWidth, maxPercent); |
| 232 float percent = std::min(static_cast<float>(m_layoutStruct[i].ef fectiveLogicalWidth.percent()), remainingPercent); | 248 remainingPercent -= percent; |
| 233 float logicalWidth = static_cast<float>(m_layoutStruct[i].effect iveMaxLogicalWidth) * 100 / std::max(percent, epsilon); | 249 } else { |
| 234 maxPercent = std::max(logicalWidth, maxPercent); | 250 maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth; |
| 235 remainingPercent -= percent; | |
| 236 } else { | |
| 237 maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth; | |
| 238 } | |
| 239 } | 251 } |
| 240 } | 252 } |
| 241 | 253 |
| 242 if (scaleColumns) { | 254 maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon); |
| 243 maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon ); | 255 LayoutUnit maxWidth = LayoutUnit(std::min(maxNonPercent, static_cast<float>( tableMaxWidth))); |
| 244 maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxNonPercent, static_ cast<float>(tableMaxWidth)))); | 256 return std::max(maxWidth, LayoutUnit(std::min(maxPercent, static_cast<float> (tableMaxWidth)))); |
| 245 maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxPercent, static_cas t<float>(tableMaxWidth)))); | |
| 246 } | |
| 247 | |
| 248 maxWidth = LayoutUnit(std::max(maxWidth.floor(), spanMaxLogicalWidth)); | |
| 249 } | 257 } |
| 250 | 258 |
| 251 void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minW idth, LayoutUnit& maxWidth) const | 259 void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minW idth, LayoutUnit& maxWidth) const |
| 252 { | 260 { |
| 253 Length tableLogicalWidth = m_table->style()->logicalWidth(); | 261 Length tableLogicalWidth = m_table->style()->logicalWidth(); |
| 254 if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) { | 262 if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) { |
| 255 // |minWidth| is the result of measuring the intrinsic content's size. K eep it to | 263 // |minWidth| is the result of measuring the intrinsic content's size. K eep it to |
| 256 // make sure we are *never* smaller than the actual content. | 264 // make sure we are *never* smaller than the actual content. |
| 257 LayoutUnit minContentWidth = minWidth; | 265 LayoutUnit minContentWidth = minWidth; |
| 258 // FIXME: This line looks REALLY suspicious as it could allow the minimu m | 266 // FIXME: This line looks REALLY suspicious as it could allow the minimu m |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 702 int reduce = available * minMaxDiff / logicalWidthBeyondMin; |
| 695 m_layoutStruct[i].computedLogicalWidth += reduce; | 703 m_layoutStruct[i].computedLogicalWidth += reduce; |
| 696 available -= reduce; | 704 available -= reduce; |
| 697 logicalWidthBeyondMin -= minMaxDiff; | 705 logicalWidthBeyondMin -= minMaxDiff; |
| 698 if (available >= 0) | 706 if (available >= 0) |
| 699 break; | 707 break; |
| 700 } | 708 } |
| 701 } | 709 } |
| 702 } | 710 } |
| 703 } // namespace blink | 711 } // namespace blink |
| OLD | NEW |