| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 RenderMultiColumnSet* RenderMultiColumnSet::previousSiblingMultiColumnSet() cons
t | 63 RenderMultiColumnSet* RenderMultiColumnSet::previousSiblingMultiColumnSet() cons
t |
| 64 { | 64 { |
| 65 for (RenderObject* sibling = previousSibling(); sibling; sibling = sibling->
previousSibling()) { | 65 for (RenderObject* sibling = previousSibling(); sibling; sibling = sibling->
previousSibling()) { |
| 66 if (sibling->isRenderMultiColumnSet()) | 66 if (sibling->isRenderMultiColumnSet()) |
| 67 return toRenderMultiColumnSet(sibling); | 67 return toRenderMultiColumnSet(sibling); |
| 68 } | 68 } |
| 69 return 0; | 69 return 0; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void RenderMultiColumnSet::setLogicalTopInFlowThread(LayoutUnit logicalTop) |
| 73 { |
| 74 LayoutRect rect = flowThreadPortionRect(); |
| 75 if (isHorizontalWritingMode()) |
| 76 rect.setY(logicalTop); |
| 77 else |
| 78 rect.setX(logicalTop); |
| 79 setFlowThreadPortionRect(rect); |
| 80 } |
| 81 |
| 82 void RenderMultiColumnSet::setLogicalBottomInFlowThread(LayoutUnit logicalBottom
) |
| 83 { |
| 84 LayoutRect rect = flowThreadPortionRect(); |
| 85 if (isHorizontalWritingMode()) |
| 86 rect.shiftMaxYEdgeTo(logicalBottom); |
| 87 else |
| 88 rect.shiftMaxXEdgeTo(logicalBottom); |
| 89 setFlowThreadPortionRect(rect); |
| 90 } |
| 91 |
| 92 bool RenderMultiColumnSet::heightIsAuto() const |
| 93 { |
| 94 RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread(); |
| 95 if (!flowThread->isRenderPagedFlowThread()) { |
| 96 if (RenderMultiColumnSet* next = nextSiblingMultiColumnSet()) { |
| 97 if (next->isRenderMultiColumnSpannerSet()) { |
| 98 // If we're followed by a spanner, we need to balance. |
| 99 return true; |
| 100 } |
| 101 } |
| 102 if (multiColumnBlockFlow()->style()->columnFill() == ColumnFillBalance) |
| 103 return true; |
| 104 } |
| 105 return !flowThread->columnHeightAvailable(); |
| 106 } |
| 107 |
| 72 LayoutSize RenderMultiColumnSet::flowThreadTranslationAtOffset(LayoutUnit blockO
ffset) const | 108 LayoutSize RenderMultiColumnSet::flowThreadTranslationAtOffset(LayoutUnit blockO
ffset) const |
| 73 { | 109 { |
| 74 unsigned columnIndex = columnIndexAtOffset(blockOffset); | 110 unsigned columnIndex = columnIndexAtOffset(blockOffset); |
| 75 LayoutRect portionRect(flowThreadPortionRectAt(columnIndex)); | 111 LayoutRect portionRect(flowThreadPortionRectAt(columnIndex)); |
| 76 flipForWritingMode(portionRect); | 112 flipForWritingMode(portionRect); |
| 77 LayoutRect columnRect(columnRectAt(columnIndex)); | 113 LayoutRect columnRect(columnRectAt(columnIndex)); |
| 78 flipForWritingMode(columnRect); | 114 flipForWritingMode(columnRect); |
| 79 return contentBoxRect().location() + columnRect.location() - portionRect.loc
ation(); | 115 return contentBoxRect().location() + columnRect.location() - portionRect.loc
ation(); |
| 80 } | 116 } |
| 81 | 117 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 ASSERT(m_minSpaceShortage > 0); // We should never _shrink_ the height! | 221 ASSERT(m_minSpaceShortage > 0); // We should never _shrink_ the height! |
| 186 ASSERT(m_minSpaceShortage != RenderFlowThread::maxLogicalHeight()); // If th
is happens, we probably have a bug. | 222 ASSERT(m_minSpaceShortage != RenderFlowThread::maxLogicalHeight()); // If th
is happens, we probably have a bug. |
| 187 if (m_minSpaceShortage == RenderFlowThread::maxLogicalHeight()) | 223 if (m_minSpaceShortage == RenderFlowThread::maxLogicalHeight()) |
| 188 return m_columnHeight; // So bail out rather than looping infinitely. | 224 return m_columnHeight; // So bail out rather than looping infinitely. |
| 189 | 225 |
| 190 return m_columnHeight + m_minSpaceShortage; | 226 return m_columnHeight + m_minSpaceShortage; |
| 191 } | 227 } |
| 192 | 228 |
| 193 void RenderMultiColumnSet::addContentRun(LayoutUnit endOffsetFromFirstPage) | 229 void RenderMultiColumnSet::addContentRun(LayoutUnit endOffsetFromFirstPage) |
| 194 { | 230 { |
| 195 if (!multiColumnFlowThread()->heightIsAuto()) | 231 if (!requiresBalancing()) |
| 196 return; | 232 return; |
| 197 if (!m_contentRuns.isEmpty() && endOffsetFromFirstPage <= m_contentRuns.last
().breakOffset()) | 233 if (!m_contentRuns.isEmpty() && endOffsetFromFirstPage <= m_contentRuns.last
().breakOffset()) |
| 198 return; | 234 return; |
| 199 // Append another item as long as we haven't exceeded used column count. Wha
t ends up in the | 235 // Append another item as long as we haven't exceeded used column count. Wha
t ends up in the |
| 200 // overflow area shouldn't affect column balancing. | 236 // overflow area shouldn't affect column balancing. |
| 201 if (m_contentRuns.size() < usedColumnCount()) | 237 if (m_contentRuns.size() < usedColumnCount()) |
| 202 m_contentRuns.append(ContentRun(endOffsetFromFirstPage)); | 238 m_contentRuns.append(ContentRun(endOffsetFromFirstPage)); |
| 203 } | 239 } |
| 204 | 240 |
| 205 bool RenderMultiColumnSet::recalculateColumnHeight(BalancedHeightCalculation cal
culationMode) | 241 bool RenderMultiColumnSet::recalculateColumnHeight(BalancedHeightCalculation cal
culationMode) |
| 206 { | 242 { |
| 207 ASSERT(multiColumnFlowThread()->heightIsAuto()); | 243 LayoutUnit oldColumnHeight = m_columnHeight; |
| 208 | 244 |
| 209 LayoutUnit oldColumnHeight = m_columnHeight; | 245 m_maxColumnHeight = calculateMaxColumnHeight(); |
| 210 if (calculationMode == GuessFromFlowThreadPortion) { | 246 |
| 211 // Post-process the content runs and find out where the implicit breaks
will occur. | 247 if (heightIsAuto()) { |
| 212 distributeImplicitBreaks(); | 248 if (calculationMode == GuessFromFlowThreadPortion) { |
| 249 // Post-process the content runs and find out where the implicit bre
aks will occur. |
| 250 distributeImplicitBreaks(); |
| 251 } |
| 252 LayoutUnit newColumnHeight = calculateColumnHeight(calculationMode); |
| 253 setAndConstrainColumnHeight(newColumnHeight); |
| 254 // After having calculated an initial column height, the multicol contai
ner typically needs at |
| 255 // least one more layout pass with a new column height, but if a height
was specified, we only |
| 256 // need to do this if we think that we need less space than specified. C
onversely, if we |
| 257 // determined that the columns need to be as tall as the specified heigh
t of the container, we |
| 258 // have already laid it out correctly, and there's no need for another p
ass. |
| 259 } else { |
| 260 // The position of the column set may have changed, in which case height
available for |
| 261 // columns may have changed as well. |
| 262 setAndConstrainColumnHeight(m_columnHeight); |
| 213 } | 263 } |
| 214 LayoutUnit newColumnHeight = calculateColumnHeight(calculationMode); | |
| 215 setAndConstrainColumnHeight(newColumnHeight); | |
| 216 | |
| 217 // After having calculated an initial column height, the multicol container
typically needs at | |
| 218 // least one more layout pass with a new column height, but if a height was
specified, we only | |
| 219 // need to do this if we think that we need less space than specified. Conve
rsely, if we | |
| 220 // determined that the columns need to be as tall as the specified height of
the container, we | |
| 221 // have already laid it out correctly, and there's no need for another pass. | |
| 222 | 264 |
| 223 // We can get rid of the content runs now, if we haven't already done so. Th
ey are only needed | 265 // We can get rid of the content runs now, if we haven't already done so. Th
ey are only needed |
| 224 // to calculate the initial balanced column height. In fact, we have to get
rid of them before | 266 // to calculate the initial balanced column height. In fact, we have to get
rid of them before |
| 225 // the next layout pass, since each pass will rebuild this. | 267 // the next layout pass, since each pass will rebuild this. |
| 226 m_contentRuns.clear(); | 268 m_contentRuns.clear(); |
| 227 | 269 |
| 228 if (m_columnHeight == oldColumnHeight) | 270 if (m_columnHeight == oldColumnHeight) |
| 229 return false; // No change. We're done. | 271 return false; // No change. We're done. |
| 230 | 272 |
| 231 m_minSpaceShortage = RenderFlowThread::maxLogicalHeight(); | 273 m_minSpaceShortage = RenderFlowThread::maxLogicalHeight(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 246 | 288 |
| 247 void RenderMultiColumnSet::resetColumnHeight() | 289 void RenderMultiColumnSet::resetColumnHeight() |
| 248 { | 290 { |
| 249 // Nuke previously stored minimum column height. Contents may have changed f
or all we know. | 291 // Nuke previously stored minimum column height. Contents may have changed f
or all we know. |
| 250 m_minimumColumnHeight = 0; | 292 m_minimumColumnHeight = 0; |
| 251 | 293 |
| 252 m_maxColumnHeight = calculateMaxColumnHeight(); | 294 m_maxColumnHeight = calculateMaxColumnHeight(); |
| 253 | 295 |
| 254 LayoutUnit oldColumnHeight = pageLogicalHeight(); | 296 LayoutUnit oldColumnHeight = pageLogicalHeight(); |
| 255 | 297 |
| 256 if (multiColumnFlowThread()->heightIsAuto()) | 298 if (heightIsAuto()) |
| 257 m_columnHeight = 0; | 299 m_columnHeight = 0; |
| 258 else | 300 else |
| 259 setAndConstrainColumnHeight(heightAdjustedForSetOffset(multiColumnFlowTh
read()->columnHeightAvailable())); | 301 setAndConstrainColumnHeight(heightAdjustedForSetOffset(multiColumnFlowTh
read()->columnHeightAvailable())); |
| 260 | 302 |
| 261 if (pageLogicalHeight() != oldColumnHeight) | 303 if (pageLogicalHeight() != oldColumnHeight) |
| 262 setChildNeedsLayout(MarkOnlyThis); | 304 setChildNeedsLayout(MarkOnlyThis); |
| 263 | 305 |
| 264 // Content runs are only needed in the initial layout pass, in order to find
an initial column | 306 // Content runs are only needed in the initial layout pass, in order to find
an initial column |
| 265 // height, and should have been deleted afterwards. We're about to rebuild t
he content runs, so | 307 // height, and should have been deleted afterwards. We're about to rebuild t
he content runs, so |
| 266 // the list needs to be empty. | 308 // the list needs to be empty. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 727 |
| 686 void RenderMultiColumnSet::detachRegion() | 728 void RenderMultiColumnSet::detachRegion() |
| 687 { | 729 { |
| 688 if (m_flowThread) { | 730 if (m_flowThread) { |
| 689 m_flowThread->removeRegionFromThread(this); | 731 m_flowThread->removeRegionFromThread(this); |
| 690 m_flowThread = 0; | 732 m_flowThread = 0; |
| 691 } | 733 } |
| 692 } | 734 } |
| 693 | 735 |
| 694 } | 736 } |
| OLD | NEW |