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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 flipForWritingMode(flowThreadPoint); | 132 flipForWritingMode(flowThreadPoint); |
133 LayoutUnit blockOffset = isHorizontalWritingMode() ? flowThreadPoint.y() : f lowThreadPoint.x(); | 133 LayoutUnit blockOffset = isHorizontalWritingMode() ? flowThreadPoint.y() : f lowThreadPoint.x(); |
134 RenderRegion* renderRegion = regionAtBlockOffset(blockOffset); | 134 RenderRegion* renderRegion = regionAtBlockOffset(blockOffset); |
135 if (!renderRegion) | 135 if (!renderRegion) |
136 return LayoutSize(0, 0); | 136 return LayoutSize(0, 0); |
137 return toRenderMultiColumnSet(renderRegion)->flowThreadTranslationAtOffset(b lockOffset); | 137 return toRenderMultiColumnSet(renderRegion)->flowThreadTranslationAtOffset(b lockOffset); |
138 } | 138 } |
139 | 139 |
140 void RenderMultiColumnFlowThread::layoutColumns(bool relayoutChildren, SubtreeLa youtScope& layoutScope) | 140 void RenderMultiColumnFlowThread::layoutColumns(bool relayoutChildren, SubtreeLa youtScope& layoutScope) |
141 { | 141 { |
142 // Update the dimensions of our regions before we lay out the flow thread. | |
143 // FIXME: Eventually this is going to get way more complicated, and we will be destroying regions | |
144 // instead of trying to keep them around. | |
145 bool shouldInvalidateRegions = false; | |
146 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet()) { | |
147 if (relayoutChildren || columnSet->needsLayout()) { | |
148 if (!m_inBalancingPass) | |
149 columnSet->prepareForLayout(); | |
150 shouldInvalidateRegions = true; | |
151 } | |
152 } | |
153 | |
154 if (shouldInvalidateRegions) | |
155 invalidateRegions(); | |
156 | |
157 if (relayoutChildren) | 142 if (relayoutChildren) |
158 layoutScope.setChildNeedsLayout(this); | 143 layoutScope.setChildNeedsLayout(this); |
159 | 144 |
160 if (requiresBalancing()) { | 145 if (!needsLayout()) { |
161 // At the end of multicol layout, relayoutForPagination() is called unco nditionally, but if | 146 // At the end of multicol container (our parent RenderBlockFlow) layout, it will call |
162 // no children are to be laid out (e.g. fixed width with layout already being up-to-date), | 147 // recalculateColumnHeights() on us unconditionally, but if we won't lay out (e.g. because |
163 // we want to prevent it from doing any work, so that the column balanci ng machinery doesn't | 148 // we have fixed width with layout already being up-to-date), we want to prevent |
164 // kick in and trigger additional unnecessary layout passes. Actually, i t's not just a good | 149 // recalculateColumnHeights() from doing any work, so that the column ba lancing machinery |
165 // idea in general to not waste time on balancing content that hasn't be en re-laid out; we | 150 // doesn't kick in and trigger additional unnecessary layout passes. Act ually, it's not just |
166 // are actually required to guarantee this. The calculation of implicit breaks needs to be | 151 // a good idea in general to not waste time on balancing content that ha sn't been re-laid |
167 // preceded by a proper layout pass, since it's layout that sets up cont ent runs, and the | 152 // out; we are actually required to guarantee this. The calculation of i mplicit breaks needs |
168 // runs get deleted right after every pass. | 153 // to be preceded by a proper layout pass, since it's layout that sets u p content runs, and |
169 m_needsColumnHeightsRecalculation = shouldInvalidateRegions || needsLayo ut(); | 154 // the runs get deleted right after every pass. |
155 m_needsColumnHeightsRecalculation = false; | |
156 return; | |
170 } | 157 } |
171 | 158 |
172 layoutIfNeeded(); | 159 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet()) |
160 columnSet->prepareForLayout(!m_inBalancingPass); | |
Julien - ping for review
2014/05/20 17:03:04
We should rename this function to something better
mstensho (USE GERRIT)
2014/05/21 09:02:33
This function prepares a column set for flow threa
mstensho (USE GERRIT)
2014/05/22 15:07:18
Done.
Ended up with resetColumnHeight(), which is
| |
161 | |
162 invalidateRegions(); | |
163 m_needsColumnHeightsRecalculation = requiresBalancing(); | |
164 layout(); | |
173 } | 165 } |
174 | 166 |
175 bool RenderMultiColumnFlowThread::computeColumnCountAndWidth() | 167 bool RenderMultiColumnFlowThread::computeColumnCountAndWidth() |
176 { | 168 { |
177 RenderBlock* columnBlock = multiColumnBlockFlow(); | 169 RenderBlock* columnBlock = multiColumnBlockFlow(); |
178 LayoutUnit oldColumnWidth = m_columnWidth; | 170 LayoutUnit oldColumnWidth = m_columnWidth; |
179 | 171 |
180 // Calculate our column width and column count. | 172 // Calculate our column width and column count. |
181 m_columnCount = 1; | 173 m_columnCount = 1; |
182 m_columnWidth = columnBlock->contentLogicalWidth(); | 174 m_columnWidth = columnBlock->contentLogicalWidth(); |
(...skipping 15 matching lines...) Expand all Loading... | |
198 } else { | 190 } else { |
199 m_columnCount = std::max<LayoutUnit>(std::min<LayoutUnit>(colCount, (ava ilWidth + colGap) / (colWidth + colGap)), 1); | 191 m_columnCount = std::max<LayoutUnit>(std::min<LayoutUnit>(colCount, (ava ilWidth + colGap) / (colWidth + colGap)), 1); |
200 m_columnWidth = ((availWidth + colGap) / m_columnCount) - colGap; | 192 m_columnWidth = ((availWidth + colGap) / m_columnCount) - colGap; |
201 } | 193 } |
202 | 194 |
203 return m_columnWidth != oldColumnWidth; | 195 return m_columnWidth != oldColumnWidth; |
204 } | 196 } |
205 | 197 |
206 bool RenderMultiColumnFlowThread::recalculateColumnHeights() | 198 bool RenderMultiColumnFlowThread::recalculateColumnHeights() |
207 { | 199 { |
200 // All column sets that needed layout have now been laid out, so we can fina lly validate them. | |
201 validateRegions(); | |
202 | |
208 if (!m_needsColumnHeightsRecalculation) | 203 if (!m_needsColumnHeightsRecalculation) |
209 return false; | 204 return false; |
210 | 205 |
211 // Column heights may change here because of balancing. We may have to do mu ltiple layout | 206 // Column heights may change here because of balancing. We may have to do mu ltiple layout |
212 // passes, depending on how the contents is fitted to the changed column hei ghts. In most | 207 // passes, depending on how the contents is fitted to the changed column hei ghts. In most |
213 // cases, laying out again twice or even just once will suffice. Sometimes w e need more | 208 // cases, laying out again twice or even just once will suffice. Sometimes w e need more |
214 // passes than that, though, but the number of retries should not exceed the number of | 209 // passes than that, though, but the number of retries should not exceed the number of |
215 // columns, unless we have a bug. | 210 // columns, unless we have a bug. |
216 bool needsRelayout = false; | 211 bool needsRelayout = false; |
217 for (RenderMultiColumnSet* multicolSet = firstMultiColumnSet(); multicolSet; multicolSet = multicolSet->nextSiblingMultiColumnSet()) { | 212 for (RenderMultiColumnSet* multicolSet = firstMultiColumnSet(); multicolSet; multicolSet = multicolSet->nextSiblingMultiColumnSet()) { |
218 if (multicolSet->recalculateColumnHeight(!m_inBalancingPass)) { | 213 if (multicolSet->recalculateColumnHeight(!m_inBalancingPass)) |
214 needsRelayout = true; | |
215 if (needsRelayout) { | |
216 // Once a column set gets a new column height, that column set and a ll successive column | |
217 // sets need to be laid out over again, since their logical top will be affected by | |
218 // this, and therefore their column heights may change as well, at l east if the multicol | |
219 // height is constrained. | |
219 multicolSet->setChildNeedsLayout(MarkOnlyThis); | 220 multicolSet->setChildNeedsLayout(MarkOnlyThis); |
220 needsRelayout = true; | |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 if (needsRelayout) | 224 if (needsRelayout) |
225 setChildNeedsLayout(MarkOnlyThis); | 225 setChildNeedsLayout(MarkOnlyThis); |
226 | 226 |
227 m_inBalancingPass = needsRelayout; | 227 m_inBalancingPass = needsRelayout; |
228 return needsRelayout; | 228 return needsRelayout; |
229 } | 229 } |
230 | 230 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 313 } |
314 | 314 |
315 bool RenderMultiColumnFlowThread::isPageLogicalHeightKnown() const | 315 bool RenderMultiColumnFlowThread::isPageLogicalHeightKnown() const |
316 { | 316 { |
317 if (RenderMultiColumnSet* columnSet = lastMultiColumnSet()) | 317 if (RenderMultiColumnSet* columnSet = lastMultiColumnSet()) |
318 return columnSet->computedColumnHeight(); | 318 return columnSet->computedColumnHeight(); |
319 return false; | 319 return false; |
320 } | 320 } |
321 | 321 |
322 } | 322 } |
OLD | NEW |