Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: Source/core/rendering/RenderBlockFlow.cpp

Issue 147233002: Remove internal recursion for RenderBlockFlow and RenderMultiColumnBlock layout (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase to apply on latest trunk Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/rendering/RenderBlockFlow.h ('k') | Source/core/rendering/RenderMultiColumnBlock.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "core/rendering/RenderBlockFlow.h" 32 #include "core/rendering/RenderBlockFlow.h"
33 33
34 #include "core/accessibility/AXObjectCache.h" 34 #include "core/accessibility/AXObjectCache.h"
35 #include "core/frame/FrameView.h" 35 #include "core/frame/FrameView.h"
36 #include "core/rendering/FastTextAutosizer.h" 36 #include "core/rendering/FastTextAutosizer.h"
37 #include "core/rendering/HitTestLocation.h" 37 #include "core/rendering/HitTestLocation.h"
38 #include "core/rendering/LayoutRectRecorder.h" 38 #include "core/rendering/LayoutRectRecorder.h"
39 #include "core/rendering/LayoutRepainter.h" 39 #include "core/rendering/LayoutRepainter.h"
40 #include "core/rendering/RenderLayer.h" 40 #include "core/rendering/RenderLayer.h"
41 #include "core/rendering/RenderMultiColumnBlock.h"
41 #include "core/rendering/RenderNamedFlowFragment.h" 42 #include "core/rendering/RenderNamedFlowFragment.h"
42 #include "core/rendering/RenderNamedFlowThread.h" 43 #include "core/rendering/RenderNamedFlowThread.h"
43 #include "core/rendering/RenderText.h" 44 #include "core/rendering/RenderText.h"
44 #include "core/rendering/RenderView.h" 45 #include "core/rendering/RenderView.h"
45 #include "core/rendering/line/LineWidth.h" 46 #include "core/rendering/line/LineWidth.h"
46 #include "core/rendering/svg/SVGTextRunRenderingContext.h" 47 #include "core/rendering/svg/SVGTextRunRenderingContext.h"
47 #include "platform/text/BidiTextRun.h" 48 #include "platform/text/BidiTextRun.h"
48 49
49 using namespace std; 50 using namespace std;
50 51
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (!hasSpecifiedPageLogicalHeight && !pageLogicalHeight) 213 if (!hasSpecifiedPageLogicalHeight && !pageLogicalHeight)
213 colInfo->clearForcedBreaks(); 214 colInfo->clearForcedBreaks();
214 215
215 colInfo->setPaginationUnit(paginationUnit()); 216 colInfo->setPaginationUnit(paginationUnit());
216 } else if (isRenderFlowThread()) { 217 } else if (isRenderFlowThread()) {
217 pageLogicalHeight = 1; // This is just a hack to always make sure we hav e a page logical height. 218 pageLogicalHeight = 1; // This is just a hack to always make sure we hav e a page logical height.
218 pageLogicalHeightChanged = toRenderFlowThread(this)->pageLogicalSizeChan ged(); 219 pageLogicalHeightChanged = toRenderFlowThread(this)->pageLogicalSizeChan ged();
219 } 220 }
220 } 221 }
221 222
222 bool RenderBlockFlow::relayoutForPagination(bool hasSpecifiedPageLogicalHeight, LayoutUnit pageLogicalHeight, LayoutStateMaintainer& statePusher) 223 bool RenderBlockFlow::shouldRelayoutForPagination(LayoutUnit& pageLogicalHeight, LayoutUnit layoutOverflowLogicalBottom) const
223 { 224 {
224 if (!hasColumns())
225 return false;
226
227 OwnPtr<RenderOverflow> savedOverflow = m_overflow.release();
228 if (childrenInline())
229 addOverflowFromInlineChildren();
230 else
231 addOverflowFromBlockChildren();
232 LayoutUnit layoutOverflowLogicalBottom = (isHorizontalWritingMode() ? layout OverflowRect().maxY() : layoutOverflowRect().maxX()) - borderBefore() - paddingB efore();
233
234 // FIXME: We don't balance properly at all in the presence of forced page br eaks. We need to understand what 225 // FIXME: We don't balance properly at all in the presence of forced page br eaks. We need to understand what
235 // the distance between forced page breaks is so that we can avoid making th e minimum column height too tall. 226 // the distance between forced page breaks is so that we can avoid making th e minimum column height too tall.
236 ColumnInfo* colInfo = columnInfo(); 227 ColumnInfo* colInfo = columnInfo();
237 if (!hasSpecifiedPageLogicalHeight) { 228 LayoutUnit columnHeight = pageLogicalHeight;
238 LayoutUnit columnHeight = pageLogicalHeight; 229 const int minColumnCount = colInfo->forcedBreaks() + 1;
239 int minColumnCount = colInfo->forcedBreaks() + 1; 230 const int desiredColumnCount = colInfo->desiredColumnCount();
240 int desiredColumnCount = colInfo->desiredColumnCount(); 231 if (minColumnCount >= desiredColumnCount) {
241 if (minColumnCount >= desiredColumnCount) { 232 // The forced page breaks are in control of the balancing. Just set the column height to the
242 // The forced page breaks are in control of the balancing. Just set the column height to the 233 // maximum page break distance.
243 // maximum page break distance. 234 if (!pageLogicalHeight) {
244 if (!pageLogicalHeight) { 235 LayoutUnit distanceBetweenBreaks = max<LayoutUnit>(colInfo->maximumD istanceBetweenForcedBreaks(),
245 LayoutUnit distanceBetweenBreaks = max<LayoutUnit>(colInfo->maxi mumDistanceBetweenForcedBreaks(), 236 view()->layoutState()->pageLogicalOffset(this, borderBefore() + paddingBefore() + layoutOverflowLogicalBottom) - colInfo->forcedBreakOffset());
246 view()->layoutState()->pageLogicalOffset(this, borderBefore( ) + paddingBefore() + layoutOverflowLogicalBottom) - colInfo->forcedBreakOffset( )); 237 columnHeight = max(colInfo->minimumColumnHeight(), distanceBetweenBr eaks);
247 columnHeight = max(colInfo->minimumColumnHeight(), distanceBetwe enBreaks);
248 }
249 } else if (layoutOverflowLogicalBottom > boundedMultiply(pageLogicalHeig ht, desiredColumnCount)) {
250 // Now that we know the intrinsic height of the columns, we have to rebalance them.
251 columnHeight = max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf ((float)layoutOverflowLogicalBottom / desiredColumnCount));
252 } 238 }
253 239 } else if (layoutOverflowLogicalBottom > boundedMultiply(pageLogicalHeight, desiredColumnCount)) {
254 if (columnHeight && columnHeight != pageLogicalHeight) { 240 // Now that we know the intrinsic height of the columns, we have to reba lance them.
255 statePusher.pop(); 241 columnHeight = max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf((fl oat)layoutOverflowLogicalBottom / desiredColumnCount));
256 setEverHadLayout(true);
257 layoutBlockFlow(false, columnHeight);
258 return true;
259 }
260 } 242 }
261 243
262 if (pageLogicalHeight) 244 if (columnHeight && columnHeight != pageLogicalHeight) {
263 colInfo->setColumnCountAndHeight(ceilf((float)layoutOverflowLogicalBotto m / pageLogicalHeight), pageLogicalHeight); 245 pageLogicalHeight = columnHeight;
264 246 return true;
265 if (columnCount(colInfo)) {
266 setLogicalHeight(borderBefore() + paddingBefore() + colInfo->columnHeigh t() + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
267 m_overflow.clear();
268 } else {
269 m_overflow = savedOverflow.release();
270 } 247 }
271 248
272 return false; 249 return false;
273 } 250 }
274 251
252 void RenderBlockFlow::setColumnCountAndHeight(unsigned count, LayoutUnit pageLog icalHeight)
253 {
254 ColumnInfo* colInfo = columnInfo();
255 if (pageLogicalHeight)
256 colInfo->setColumnCountAndHeight(count, pageLogicalHeight);
257
258 if (columnCount(colInfo)) {
259 setLogicalHeight(borderBefore() + paddingBefore() + colInfo->columnHeigh t() + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
260 m_overflow.clear();
261 }
262 }
263
275 bool RenderBlockFlow::isSelfCollapsingBlock() const 264 bool RenderBlockFlow::isSelfCollapsingBlock() const
276 { 265 {
277 m_hasOnlySelfCollapsingChildren = RenderBlock::isSelfCollapsingBlock(); 266 m_hasOnlySelfCollapsingChildren = RenderBlock::isSelfCollapsingBlock();
278 return m_hasOnlySelfCollapsingChildren; 267 return m_hasOnlySelfCollapsingChildren;
279 } 268 }
280 269
281 void RenderBlockFlow::layoutBlock(bool relayoutChildren) 270 void RenderBlockFlow::layoutBlock(bool relayoutChildren)
282 { 271 {
283 layoutBlockFlow(relayoutChildren);
284 }
285
286 inline void RenderBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit p ageLogicalHeight)
287 {
288 ASSERT(needsLayout()); 272 ASSERT(needsLayout());
289 ASSERT(isInlineBlockOrInlineTable() || !isInline()); 273 ASSERT(isInlineBlockOrInlineTable() || !isInline());
290 274
291 // If we are self-collapsing with self-collapsing descendants this will get set to save us burrowing through our 275 // If we are self-collapsing with self-collapsing descendants this will get set to save us burrowing through our
292 // descendants every time in |isSelfCollapsingBlock|. We reset it here so th at |isSelfCollapsingBlock| attempts to burrow 276 // descendants every time in |isSelfCollapsingBlock|. We reset it here so th at |isSelfCollapsingBlock| attempts to burrow
293 // at least once and so that it always gives a reliable result reflecting th e latest layout. 277 // at least once and so that it always gives a reliable result reflecting th e latest layout.
294 m_hasOnlySelfCollapsingChildren = false; 278 m_hasOnlySelfCollapsingChildren = false;
295 279
296 if (!relayoutChildren && simplifiedLayout()) 280 if (!relayoutChildren && simplifiedLayout())
297 return; 281 return;
298 282
283 SubtreeLayoutScope layoutScope(this);
284
285 // Multiple passes might be required for column and pagination based layout
286 // In the case of the old column code the number of passes will only be two
287 // however, in the newer column code the number of passes could equal the
288 // number of columns.
289 bool done = false;
290 LayoutUnit pageLogicalHeight = 0;
291 while (!done)
292 done = layoutBlockFlow(relayoutChildren, pageLogicalHeight, layoutScope) ;
293 }
294
295 inline bool RenderBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit & pageLogicalHeight, SubtreeLayoutScope& layoutScope)
296 {
299 LayoutRepainter repainter(*this, checkForRepaintDuringLayout()); 297 LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
300 298
301 if (updateLogicalWidthAndColumnWidth()) 299 if (updateLogicalWidthAndColumnWidth())
302 relayoutChildren = true; 300 relayoutChildren = true;
303 301
304 rebuildFloatsFromIntruding(); 302 rebuildFloatsFromIntruding();
305 303
306 bool pageLogicalHeightChanged = false; 304 bool pageLogicalHeightChanged = false;
307 bool hasSpecifiedPageLogicalHeight = false; 305 bool hasSpecifiedPageLogicalHeight = false;
308 checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightCh anged, hasSpecifiedPageLogicalHeight); 306 checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightCh anged, hasSpecifiedPageLogicalHeight);
(...skipping 20 matching lines...) Expand all
329 // 327 //
330 // Start out by setting our margin values to our current margins. Table cell s have 328 // Start out by setting our margin values to our current margins. Table cell s have
331 // no margins, so we don't fill in the values for table cells. 329 // no margins, so we don't fill in the values for table cells.
332 if (!isTableCell()) { 330 if (!isTableCell()) {
333 initMaxMarginValues(); 331 initMaxMarginValues();
334 setHasMarginBeforeQuirk(style()->hasMarginBeforeQuirk()); 332 setHasMarginBeforeQuirk(style()->hasMarginBeforeQuirk());
335 setHasMarginAfterQuirk(style()->hasMarginAfterQuirk()); 333 setHasMarginAfterQuirk(style()->hasMarginAfterQuirk());
336 setPaginationStrut(0); 334 setPaginationStrut(0);
337 } 335 }
338 336
339 SubtreeLayoutScope layoutScope(this);
340
341 LayoutUnit beforeEdge = borderBefore() + paddingBefore(); 337 LayoutUnit beforeEdge = borderBefore() + paddingBefore();
342 LayoutUnit afterEdge = borderAfter() + paddingAfter() + scrollbarLogicalHeig ht(); 338 LayoutUnit afterEdge = borderAfter() + paddingAfter() + scrollbarLogicalHeig ht();
343 LayoutUnit previousHeight = logicalHeight(); 339 LayoutUnit previousHeight = logicalHeight();
344 setLogicalHeight(beforeEdge); 340 setLogicalHeight(beforeEdge);
345 341
346 m_repaintLogicalTop = 0; 342 m_repaintLogicalTop = 0;
347 m_repaintLogicalBottom = 0; 343 m_repaintLogicalBottom = 0;
348 LayoutUnit maxFloatLogicalBottom = 0; 344 LayoutUnit maxFloatLogicalBottom = 0;
349 if (!firstChild() && !isAnonymousBlock()) 345 if (!firstChild() && !isAnonymousBlock())
350 setChildrenInline(true); 346 setChildrenInline(true);
351 347
352 FastTextAutosizer* textAutosizer = document().fastTextAutosizer(); 348 FastTextAutosizer* textAutosizer = document().fastTextAutosizer();
353 if (textAutosizer) 349 if (textAutosizer)
354 textAutosizer->beginLayout(this); 350 textAutosizer->beginLayout(this);
355 351
356 if (childrenInline()) 352 if (childrenInline())
357 layoutInlineChildren(relayoutChildren, m_repaintLogicalTop, m_repaintLog icalBottom, afterEdge); 353 layoutInlineChildren(relayoutChildren, m_repaintLogicalTop, m_repaintLog icalBottom, afterEdge);
358 else 354 else
359 layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom, layoutScope , beforeEdge, afterEdge); 355 layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom, layoutScope , beforeEdge, afterEdge);
360 356
361 if (textAutosizer) 357 if (textAutosizer)
362 textAutosizer->endLayout(this); 358 textAutosizer->endLayout(this);
363 359
364 if (frameView()->partialLayout().isStopping()) { 360 if (frameView()->partialLayout().isStopping()) {
365 statePusher.pop(); 361 statePusher.pop();
366 return; 362 return true;
367 } 363 }
368 364
369 // Expand our intrinsic height to encompass floats. 365 // Expand our intrinsic height to encompass floats.
370 if (lowestFloatLogicalBottom() > (logicalHeight() - afterEdge) && createsBlo ckFormattingContext()) 366 if (lowestFloatLogicalBottom() > (logicalHeight() - afterEdge) && createsBlo ckFormattingContext())
371 setLogicalHeight(lowestFloatLogicalBottom() + afterEdge); 367 setLogicalHeight(lowestFloatLogicalBottom() + afterEdge);
372 368
373 if (relayoutForPagination(hasSpecifiedPageLogicalHeight, pageLogicalHeight, statePusher) || relayoutToAvoidWidows(statePusher)) { 369 if (isRenderMultiColumnBlock()) {
374 ASSERT(!shouldBreakAtLineToAvoidWidow()); 370 if (toRenderMultiColumnBlock(this)->shouldRelayoutMultiColumnBlock()) {
375 return; 371 setChildNeedsLayout(MarkOnlyThis);
372 statePusher.pop();
373 return false;
374 }
375 } else if (hasColumns()) {
376 OwnPtr<RenderOverflow> savedOverflow = m_overflow.release();
377 if (childrenInline())
378 addOverflowFromInlineChildren();
379 else
380 addOverflowFromBlockChildren();
381 LayoutUnit layoutOverflowLogicalBottom = (isHorizontalWritingMode() ? la youtOverflowRect().maxY() : layoutOverflowRect().maxX()) - borderBefore() - padd ingBefore();
382 m_overflow = savedOverflow.release();
383
384 if (!hasSpecifiedPageLogicalHeight && shouldRelayoutForPagination(pageLo gicalHeight, layoutOverflowLogicalBottom)) {
385 statePusher.pop();
386 setEverHadLayout(true);
387 return false;
388 }
389
390 setColumnCountAndHeight(ceilf((float)layoutOverflowLogicalBottom / pageL ogicalHeight), pageLogicalHeight);
391 }
392
393 if (shouldBreakAtLineToAvoidWidow()) {
394 statePusher.pop();
395 setEverHadLayout(true);
396 return false;
376 } 397 }
377 398
378 // Calculate our new height. 399 // Calculate our new height.
379 LayoutUnit oldHeight = logicalHeight(); 400 LayoutUnit oldHeight = logicalHeight();
380 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 401 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
381 402
382 // Before updating the final size of the flow thread make sure a forced brea k is applied after the content. 403 // Before updating the final size of the flow thread make sure a forced brea k is applied after the content.
383 // This ensures the size information is correctly computed for the last auto -height region receiving content. 404 // This ensures the size information is correctly computed for the last auto -height region receiving content.
384 if (isRenderFlowThread()) 405 if (isRenderFlowThread())
385 toRenderFlowThread(this)->applyBreakAfterContent(oldClientAfterEdge); 406 toRenderFlowThread(this)->applyBreakAfterContent(oldClientAfterEdge);
(...skipping 22 matching lines...) Expand all
408 updateRegionsAndShapesAfterChildLayout(flowThread, heightChanged); 429 updateRegionsAndShapesAfterChildLayout(flowThread, heightChanged);
409 430
410 // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway). 431 // Add overflow from children (unless we're multi-column, since in that case all our child overflow is clipped anyway).
411 computeOverflow(oldClientAfterEdge); 432 computeOverflow(oldClientAfterEdge);
412 433
413 statePusher.pop(); 434 statePusher.pop();
414 435
415 fitBorderToLinesIfNeeded(); 436 fitBorderToLinesIfNeeded();
416 437
417 if (frameView()->partialLayout().isStopping()) 438 if (frameView()->partialLayout().isStopping())
418 return; 439 return true;
419 440
420 if (renderView->layoutState()->m_pageLogicalHeight) 441 if (renderView->layoutState()->m_pageLogicalHeight)
421 setPageLogicalOffset(renderView->layoutState()->pageLogicalOffset(this, logicalTop())); 442 setPageLogicalOffset(renderView->layoutState()->pageLogicalOffset(this, logicalTop()));
422 443
423 updateLayerTransform(); 444 updateLayerTransform();
424 445
425 // Update our scroll information if we're overflow:auto/scroll/hidden now th at we know if 446 // Update our scroll information if we're overflow:auto/scroll/hidden now th at we know if
426 // we overflow or not. 447 // we overflow or not.
427 updateScrollInfoAfterLayout(); 448 updateScrollInfoAfterLayout();
428 449
429 // Repaint with our new bounds if they are different from our old bounds. 450 // Repaint with our new bounds if they are different from our old bounds.
430 bool didFullRepaint = repainter.repaintAfterLayout(); 451 bool didFullRepaint = repainter.repaintAfterLayout();
431 if (!didFullRepaint && m_repaintLogicalTop != m_repaintLogicalBottom && (sty le()->visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) { 452 if (!didFullRepaint && m_repaintLogicalTop != m_repaintLogicalBottom && (sty le()->visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) {
432 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) 453 if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
433 setShouldRepaintOverflowIfNeeded(true); 454 setShouldRepaintOverflowIfNeeded(true);
434 else 455 else
435 repaintOverflow(); 456 repaintOverflow();
436 } 457 }
437 458
438 clearNeedsLayout(); 459 clearNeedsLayout();
460 return true;
439 } 461 }
440 462
441 void RenderBlockFlow::layoutBlockChild(RenderBox* child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom) 463 void RenderBlockFlow::layoutBlockChild(RenderBox* child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom)
442 { 464 {
443 LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore(); 465 LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore();
444 LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore(); 466 LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore();
445 467
446 // The child is a normal flow object. Compute the margins we will use for co llapsing now. 468 // The child is a normal flow object. Compute the margins we will use for co llapsing now.
447 child->computeAndSetBlockDirectionMargins(this); 469 child->computeAndSetBlockDirectionMargins(this);
448 470
(...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after
2854 RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareData() 2876 RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareData()
2855 { 2877 {
2856 if (m_rareData) 2878 if (m_rareData)
2857 return *m_rareData; 2879 return *m_rareData;
2858 2880
2859 m_rareData = adoptPtr(new RenderBlockFlowRareData(this)); 2881 m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
2860 return *m_rareData; 2882 return *m_rareData;
2861 } 2883 }
2862 2884
2863 } // namespace WebCore 2885 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderBlockFlow.h ('k') | Source/core/rendering/RenderMultiColumnBlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698