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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return scale; | 207 return scale; |
208 } | 208 } |
209 | 209 |
210 void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt
h, LayoutUnit& maxWidth) | 210 void TableLayoutAlgorithmAuto::computeIntrinsicLogicalWidths(LayoutUnit& minWidt
h, LayoutUnit& maxWidth) |
211 { | 211 { |
212 TextAutosizer::TableLayoutScope textAutosizerTableLayoutScope(m_table); | 212 TextAutosizer::TableLayoutScope textAutosizerTableLayoutScope(m_table); |
213 | 213 |
214 fullRecalc(); | 214 fullRecalc(); |
215 | 215 |
216 int spanMaxLogicalWidth = calcEffectiveLogicalWidth(); | 216 int spanMaxLogicalWidth = calcEffectiveLogicalWidth(); |
217 minWidth = 0; | 217 minWidth = LayoutUnit(); |
218 maxWidth = 0; | 218 maxWidth = LayoutUnit(); |
219 float maxPercent = 0; | 219 float maxPercent = 0; |
220 float maxNonPercent = 0; | 220 float maxNonPercent = 0; |
221 bool scaleColumns = shouldScaleColumns(m_table); | 221 bool scaleColumns = shouldScaleColumns(m_table); |
222 | 222 |
223 // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two
places below to avoid division by zero. | 223 // We substitute 0 percent by (epsilon / percentScaleFactor) percent in two
places below to avoid division by zero. |
224 // FIXME: Handle the 0% cases properly. | 224 // FIXME: Handle the 0% cases properly. |
225 const float epsilon = 1 / 128.0f; | 225 const float epsilon = 1 / 128.0f; |
226 | 226 |
227 float remainingPercent = 100; | 227 float remainingPercent = 100; |
228 for (size_t i = 0; i < m_layoutStruct.size(); ++i) { | 228 for (size_t i = 0; i < m_layoutStruct.size(); ++i) { |
229 minWidth += m_layoutStruct[i].effectiveMinLogicalWidth; | 229 minWidth += m_layoutStruct[i].effectiveMinLogicalWidth; |
230 maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth; | 230 maxWidth += m_layoutStruct[i].effectiveMaxLogicalWidth; |
231 if (scaleColumns) { | 231 if (scaleColumns) { |
232 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { | 232 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { |
233 float percent = std::min(static_cast<float>(m_layoutStruct[i].ef
fectiveLogicalWidth.percent()), remainingPercent); | 233 float percent = std::min(static_cast<float>(m_layoutStruct[i].ef
fectiveLogicalWidth.percent()), remainingPercent); |
234 float logicalWidth = static_cast<float>(m_layoutStruct[i].effect
iveMaxLogicalWidth) * 100 / std::max(percent, epsilon); | 234 float logicalWidth = static_cast<float>(m_layoutStruct[i].effect
iveMaxLogicalWidth) * 100 / std::max(percent, epsilon); |
235 maxPercent = std::max(logicalWidth, maxPercent); | 235 maxPercent = std::max(logicalWidth, maxPercent); |
236 remainingPercent -= percent; | 236 remainingPercent -= percent; |
237 } else { | 237 } else { |
238 maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth; | 238 maxNonPercent += m_layoutStruct[i].effectiveMaxLogicalWidth; |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 if (scaleColumns) { | 243 if (scaleColumns) { |
244 maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon
); | 244 maxNonPercent = maxNonPercent * 100 / std::max(remainingPercent, epsilon
); |
245 maxWidth = std::max<int>(maxWidth, static_cast<int>(std::min(maxNonPerce
nt, static_cast<float>(tableMaxWidth)))); | 245 maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxNonPercent, static_
cast<float>(tableMaxWidth)))).floor(); |
246 maxWidth = std::max<int>(maxWidth, static_cast<int>(std::min(maxPercent,
static_cast<float>(tableMaxWidth)))); | 246 maxWidth = std::max(maxWidth, LayoutUnit(std::min(maxPercent, static_cas
t<float>(tableMaxWidth)))).floor(); |
247 } | 247 } |
248 | 248 |
249 maxWidth = std::max<int>(maxWidth, spanMaxLogicalWidth); | 249 maxWidth = std::max(maxWidth.floor(), spanMaxLogicalWidth); |
250 } | 250 } |
251 | 251 |
252 void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minW
idth, LayoutUnit& maxWidth) const | 252 void TableLayoutAlgorithmAuto::applyPreferredLogicalWidthQuirks(LayoutUnit& minW
idth, LayoutUnit& maxWidth) const |
253 { | 253 { |
254 Length tableLogicalWidth = m_table->style()->logicalWidth(); | 254 Length tableLogicalWidth = m_table->style()->logicalWidth(); |
255 if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) { | 255 if (tableLogicalWidth.isFixed() && tableLogicalWidth.isPositive()) { |
256 // |minWidth| is the result of measuring the intrinsic content's size. K
eep it to | 256 // |minWidth| is the result of measuring the intrinsic content's size. K
eep it to |
257 // make sure we are *never* smaller than the actual content. | 257 // make sure we are *never* smaller than the actual content. |
258 LayoutUnit minContentWidth = minWidth; | 258 LayoutUnit minContentWidth = minWidth; |
259 // FIXME: This line looks REALLY suspicious as it could allow the minimu
m | 259 // FIXME: This line looks REALLY suspicious as it could allow the minimu
m |
260 // preferred logical width to be smaller than the table content. This ha
s | 260 // preferred logical width to be smaller than the table content. This ha
s |
261 // to be cross-checked against other browsers. | 261 // to be cross-checked against other browsers. |
262 minWidth = maxWidth = std::max<int>(minWidth, tableLogicalWidth.value())
; | 262 minWidth = maxWidth = std::max<int>(minWidth.floor(), tableLogicalWidth.
value()); |
263 | 263 |
264 const Length& styleMaxLogicalWidth = m_table->style()->logicalMaxWidth()
; | 264 const Length& styleMaxLogicalWidth = m_table->style()->logicalMaxWidth()
; |
265 if (styleMaxLogicalWidth.isFixed() && !styleMaxLogicalWidth.isNegative()
) { | 265 if (styleMaxLogicalWidth.isFixed() && !styleMaxLogicalWidth.isNegative()
) { |
266 minWidth = std::min<int>(minWidth, styleMaxLogicalWidth.value()); | 266 minWidth = std::min<int>(minWidth.floor(), styleMaxLogicalWidth.valu
e()); |
267 minWidth = std::max(minWidth, minContentWidth); | 267 minWidth = std::max(minWidth, minContentWidth); |
268 maxWidth = minWidth; | 268 maxWidth = minWidth; |
269 } | 269 } |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 /* | 273 /* |
274 This method takes care of colspans. | 274 This method takes care of colspans. |
275 effWidth is the same as width for cells without colspans. If we have colspans,
they get modified. | 275 effWidth is the same as width for cells without colspans. If we have colspans,
they get modified. |
276 */ | 276 */ |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 default: | 551 default: |
552 break; | 552 break; |
553 } | 553 } |
554 } | 554 } |
555 | 555 |
556 // allocate width to percent cols | 556 // allocate width to percent cols |
557 if (available > 0 && havePercent) { | 557 if (available > 0 && havePercent) { |
558 for (size_t i = 0; i < nEffCols; ++i) { | 558 for (size_t i = 0; i < nEffCols; ++i) { |
559 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; | 559 Length& logicalWidth = m_layoutStruct[i].effectiveLogicalWidth; |
560 if (logicalWidth.hasPercent()) { | 560 if (logicalWidth.hasPercent()) { |
561 int cellLogicalWidth = std::max<int>(m_layoutStruct[i].effective
MinLogicalWidth, minimumValueForLength(logicalWidth, tableLogicalWidth)); | 561 int cellLogicalWidth = std::max<int>(m_layoutStruct[i].effective
MinLogicalWidth, |
| 562 minimumValueForLength(logicalWidth, LayoutUnit(tableLogicalW
idth))); |
562 available += m_layoutStruct[i].computedLogicalWidth - cellLogica
lWidth; | 563 available += m_layoutStruct[i].computedLogicalWidth - cellLogica
lWidth; |
563 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; | 564 m_layoutStruct[i].computedLogicalWidth = cellLogicalWidth; |
564 } | 565 } |
565 } | 566 } |
566 if (totalPercent > 100) { | 567 if (totalPercent > 100) { |
567 // remove overallocated space from the last columns | 568 // remove overallocated space from the last columns |
568 int excess = tableLogicalWidth * (totalPercent - 100) / 100; | 569 int excess = tableLogicalWidth * (totalPercent - 100) / 100; |
569 for (unsigned i = nEffCols; i; ) { | 570 for (unsigned i = nEffCols; i; ) { |
570 --i; | 571 --i; |
571 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { | 572 if (m_layoutStruct[i].effectiveLogicalWidth.hasPercent()) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 int reduce = available * minMaxDiff / logicalWidthBeyondMin; | 692 int reduce = available * minMaxDiff / logicalWidthBeyondMin; |
692 m_layoutStruct[i].computedLogicalWidth += reduce; | 693 m_layoutStruct[i].computedLogicalWidth += reduce; |
693 available -= reduce; | 694 available -= reduce; |
694 logicalWidthBeyondMin -= minMaxDiff; | 695 logicalWidthBeyondMin -= minMaxDiff; |
695 if (available >= 0) | 696 if (available >= 0) |
696 break; | 697 break; |
697 } | 698 } |
698 } | 699 } |
699 } | 700 } |
700 } // namespace blink | 701 } // namespace blink |
OLD | NEW |