| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "core/layout/MultiColumnFragmentainerGroup.h" | 7 #include "core/layout/MultiColumnFragmentainerGroup.h" |
| 8 | 8 |
| 9 #include "core/layout/ColumnBalancer.h" | 9 #include "core/layout/ColumnBalancer.h" |
| 10 #include "core/layout/LayoutMultiColumnSet.h" | 10 #include "core/layout/LayoutMultiColumnSet.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 bool MultiColumnFragmentainerGroup::recalculateColumnHeight(BalancedColumnHeight
Calculation calculationMode) | 61 bool MultiColumnFragmentainerGroup::recalculateColumnHeight(BalancedColumnHeight
Calculation calculationMode) |
| 62 { | 62 { |
| 63 LayoutUnit oldColumnHeight = m_columnHeight; | 63 LayoutUnit oldColumnHeight = m_columnHeight; |
| 64 | 64 |
| 65 m_maxColumnHeight = calculateMaxColumnHeight(); | 65 m_maxColumnHeight = calculateMaxColumnHeight(); |
| 66 | 66 |
| 67 // Only the last row may have auto height, and thus be balanced. There are n
o good reasons to | 67 // Only the last row may have auto height, and thus be balanced. There are n
o good reasons to |
| 68 // balance the preceding rows, and that could potentially lead to an insane
number of layout | 68 // balance the preceding rows, and that could potentially lead to an insane
number of layout |
| 69 // passes as well. | 69 // passes as well. |
| 70 if (isLastGroup() && m_columnSet.heightIsAuto()) { | 70 if (isLastGroup() && m_columnSet.heightIsAuto()) { |
| 71 LayoutUnit newColumnHeight = calculateColumnHeight(calculationMode); | 71 LayoutUnit newColumnHeight; |
| 72 if (calculationMode == GuessFromFlowThreadPortion) { |
| 73 // Initial balancing: Start with the lowest imaginable column height
. Also calculate the |
| 74 // height of the tallest piece of unbreakable content. Columns shoul
d never get any |
| 75 // shorter than that (unless constrained by max-height). Propagate t
his to our |
| 76 // containing column set, in case there is an outer multicol contain
er that also needs |
| 77 // to balance. After having calculated the initial column height, th
e multicol container |
| 78 // needs another layout pass with the column height that we just cal
culated. |
| 79 InitialColumnHeightFinder initialHeightFinder(*this); |
| 80 LayoutUnit tallestUnbreakableLogicalHeight = initialHeightFinder.tal
lestUnbreakableLogicalHeight(); |
| 81 m_columnSet.propagateTallestUnbreakableLogicalHeight(tallestUnbreaka
bleLogicalHeight); |
| 82 newColumnHeight = std::max(initialHeightFinder.initialMinimalBalance
dHeight(), tallestUnbreakableLogicalHeight); |
| 83 } else { |
| 84 // Rebalancing: After having laid out again, we'll need to rebalance
if the height |
| 85 // wasn't enough and we're allowed to stretch it, and then re-lay ou
t. There are further |
| 86 // details on the column balancing machinery in ColumnBalancer and i
ts derivates. |
| 87 newColumnHeight = rebalanceColumnHeightIfNeeded(); |
| 88 } |
| 72 setAndConstrainColumnHeight(newColumnHeight); | 89 setAndConstrainColumnHeight(newColumnHeight); |
| 73 // After having calculated an initial column height, the multicol contai
ner typically needs at | |
| 74 // least one more layout pass with a new column height, but if a height
was specified, we only | |
| 75 // need to do this if we think that we need less space than specified. C
onversely, if we | |
| 76 // determined that the columns need to be as tall as the specified heigh
t of the container, we | |
| 77 // have already laid it out correctly, and there's no need for another p
ass. | |
| 78 } else { | 90 } else { |
| 79 // The position of the column set may have changed, in which case height
available for | 91 // The position of the column set may have changed, in which case height
available for |
| 80 // columns may have changed as well. | 92 // columns may have changed as well. |
| 81 setAndConstrainColumnHeight(m_columnHeight); | 93 setAndConstrainColumnHeight(m_columnHeight); |
| 82 } | 94 } |
| 83 | 95 |
| 84 if (m_columnHeight == oldColumnHeight) | 96 if (m_columnHeight == oldColumnHeight) |
| 85 return false; // No change. We're done. | 97 return false; // No change. We're done. |
| 86 | 98 |
| 87 return true; // Need another pass. | 99 return true; // Need another pass. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return maxHeight; | 336 return maxHeight; |
| 325 } | 337 } |
| 326 | 338 |
| 327 void MultiColumnFragmentainerGroup::setAndConstrainColumnHeight(LayoutUnit newHe
ight) | 339 void MultiColumnFragmentainerGroup::setAndConstrainColumnHeight(LayoutUnit newHe
ight) |
| 328 { | 340 { |
| 329 m_columnHeight = newHeight; | 341 m_columnHeight = newHeight; |
| 330 if (m_columnHeight > m_maxColumnHeight) | 342 if (m_columnHeight > m_maxColumnHeight) |
| 331 m_columnHeight = m_maxColumnHeight; | 343 m_columnHeight = m_maxColumnHeight; |
| 332 } | 344 } |
| 333 | 345 |
| 334 LayoutUnit MultiColumnFragmentainerGroup::calculateColumnHeight(BalancedColumnHe
ightCalculation calculationMode) const | 346 LayoutUnit MultiColumnFragmentainerGroup::rebalanceColumnHeightIfNeeded() const |
| 335 { | 347 { |
| 336 if (calculationMode == GuessFromFlowThreadPortion) { | |
| 337 // Initial balancing. Start with the lowest imaginable column height. We
use the tallest | |
| 338 // content run (after having "inserted" implicit breaks), and find its s
tart offset (by | |
| 339 // looking at the previous run's end offset, or, if there's no previous
run, the set's start | |
| 340 // offset in the flow thread). | |
| 341 return InitialColumnHeightFinder::initialMinimalBalancedHeight(*this); | |
| 342 } | |
| 343 | |
| 344 if (actualColumnCount() <= m_columnSet.usedColumnCount()) { | 348 if (actualColumnCount() <= m_columnSet.usedColumnCount()) { |
| 345 // With the current column height, the content fits without creating ove
rflowing columns. We're done. | 349 // With the current column height, the content fits without creating ove
rflowing columns. We're done. |
| 346 return m_columnHeight; | 350 return m_columnHeight; |
| 347 } | 351 } |
| 348 | 352 |
| 349 if (m_columnHeight >= m_maxColumnHeight) { | 353 if (m_columnHeight >= m_maxColumnHeight) { |
| 350 // We cannot stretch any further. We'll just have to live with the overf
lowing columns. This | 354 // We cannot stretch any further. We'll just have to live with the overf
lowing columns. This |
| 351 // typically happens if the max column height is less than the height of
the tallest piece | 355 // typically happens if the max column height is less than the height of
the tallest piece |
| 352 // of unbreakable content (e.g. lines). | 356 // of unbreakable content (e.g. lines). |
| 353 return m_columnHeight; | 357 return m_columnHeight; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 append(MultiColumnFragmentainerGroup(m_columnSet)); | 553 append(MultiColumnFragmentainerGroup(m_columnSet)); |
| 550 return last(); | 554 return last(); |
| 551 } | 555 } |
| 552 | 556 |
| 553 void MultiColumnFragmentainerGroupList::deleteExtraGroups() | 557 void MultiColumnFragmentainerGroupList::deleteExtraGroups() |
| 554 { | 558 { |
| 555 shrink(1); | 559 shrink(1); |
| 556 } | 560 } |
| 557 | 561 |
| 558 } // namespace blink | 562 } // namespace blink |
| OLD | NEW |