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

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

Issue 712553003: [New Multicolumn] Actual support for layout of column-span:all. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review. Camelize. Created 6 years 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
OLDNEW
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 14 matching lines...) Expand all
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/rendering/RenderMultiColumnFlowThread.h" 27 #include "core/rendering/RenderMultiColumnFlowThread.h"
28 28
29 #include "core/rendering/RenderMultiColumnSet.h" 29 #include "core/rendering/RenderMultiColumnSet.h"
30 #include "core/rendering/RenderMultiColumnSpannerSet.h" 30 #include "core/rendering/RenderMultiColumnSpannerSet.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 RenderMultiColumnFlowThread::RenderMultiColumnFlowThread() 34 RenderMultiColumnFlowThread::RenderMultiColumnFlowThread()
35 : m_columnCount(1) 35 : m_lastSetWorkedOn(0)
36 , m_columnCount(1)
36 , m_columnHeightAvailable(0) 37 , m_columnHeightAvailable(0)
37 , m_inBalancingPass(false) 38 , m_inBalancingPass(false)
38 , m_needsColumnHeightsRecalculation(false) 39 , m_needsColumnHeightsRecalculation(false)
39 , m_progressionIsInline(true) 40 , m_progressionIsInline(true)
41 , m_isBeingEvacuated(false)
40 { 42 {
41 setFlowThreadState(InsideInFlowThread); 43 setFlowThreadState(InsideInFlowThread);
42 } 44 }
43 45
44 RenderMultiColumnFlowThread::~RenderMultiColumnFlowThread() 46 RenderMultiColumnFlowThread::~RenderMultiColumnFlowThread()
45 { 47 {
46 } 48 }
47 49
48 RenderMultiColumnFlowThread* RenderMultiColumnFlowThread::createAnonymous(Docume nt& document, RenderStyle* parentStyle) 50 RenderMultiColumnFlowThread* RenderMultiColumnFlowThread::createAnonymous(Docume nt& document, RenderStyle* parentStyle)
49 { 51 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ASSERT(!nextSibling()); 97 ASSERT(!nextSibling());
96 // Reparent children preceding the flow thread into the flow thread. It's mu lticol content 98 // Reparent children preceding the flow thread into the flow thread. It's mu lticol content
97 // now. At this point there's obviously nothing after the flow thread, but r enderers (column 99 // now. At this point there's obviously nothing after the flow thread, but r enderers (column
98 // sets and spanners) will be inserted there as we insert elements into the flow thread. 100 // sets and spanners) will be inserted there as we insert elements into the flow thread.
99 multicolContainer->moveChildrenTo(this, multicolContainer->firstChild(), thi s, true); 101 multicolContainer->moveChildrenTo(this, multicolContainer->firstChild(), thi s, true);
100 } 102 }
101 103
102 void RenderMultiColumnFlowThread::evacuateAndDestroy() 104 void RenderMultiColumnFlowThread::evacuateAndDestroy()
103 { 105 {
104 RenderBlockFlow* multicolContainer = multiColumnBlockFlow(); 106 RenderBlockFlow* multicolContainer = multiColumnBlockFlow();
107 m_isBeingEvacuated = true;
105 108
106 // Remove all sets. 109 // Remove all sets.
107 while (RenderMultiColumnSet* columnSet = firstMultiColumnSet()) 110 while (RenderMultiColumnSet* columnSet = firstMultiColumnSet())
108 columnSet->destroy(); 111 columnSet->destroy();
109 112
110 ASSERT(!previousSibling()); 113 ASSERT(!previousSibling());
111 ASSERT(!nextSibling()); 114 ASSERT(!nextSibling());
112 115
113 // Finally we can promote all flow thread's children. Before we move them to the flow thread's 116 // Finally we can promote all flow thread's children. Before we move them to the flow thread's
114 // container, we need to unregister the flow thread, so that they aren't jus t re-added again to 117 // container, we need to unregister the flow thread, so that they aren't jus t re-added again to
(...skipping 24 matching lines...) Expand all
139 } 142 }
140 143
141 bool RenderMultiColumnFlowThread::needsNewWidth() const 144 bool RenderMultiColumnFlowThread::needsNewWidth() const
142 { 145 {
143 LayoutUnit newWidth; 146 LayoutUnit newWidth;
144 unsigned dummyColumnCount; // We only care if used column-width changes. 147 unsigned dummyColumnCount; // We only care if used column-width changes.
145 calculateColumnCountAndWidth(newWidth, dummyColumnCount); 148 calculateColumnCountAndWidth(newWidth, dummyColumnCount);
146 return newWidth != logicalWidth(); 149 return newWidth != logicalWidth();
147 } 150 }
148 151
152 RenderMultiColumnSet* RenderMultiColumnFlowThread::columnSetAtBlockOffset(Layout Unit offset) const
153 {
154 if (m_lastSetWorkedOn) {
155 // Layout in progress. We are calculating the set heights as we speak, s o the column set range
156 // information is not up-to-date.
157 return m_lastSetWorkedOn;
158 }
159
160 ASSERT(!m_regionsInvalidated);
161 if (offset <= 0)
162 return m_multiColumnSetList.isEmpty() ? 0 : m_multiColumnSetList.first() ;
163
164 MultiColumnSetSearchAdapter adapter(offset);
165 m_multiColumnSetIntervalTree.allOverlapsWithAdapter<MultiColumnSetSearchAdap ter>(adapter);
166
167 // If no set was found, the offset is in the flow thread overflow.
168 if (!adapter.result() && !m_multiColumnSetList.isEmpty())
169 return m_multiColumnSetList.last();
170 return adapter.result();
171 }
172
149 void RenderMultiColumnFlowThread::layoutColumns(bool relayoutChildren, SubtreeLa youtScope& layoutScope) 173 void RenderMultiColumnFlowThread::layoutColumns(bool relayoutChildren, SubtreeLa youtScope& layoutScope)
150 { 174 {
151 if (relayoutChildren) 175 if (relayoutChildren)
152 layoutScope.setChildNeedsLayout(this); 176 layoutScope.setChildNeedsLayout(this);
153 177
178 m_needsColumnHeightsRecalculation = false;
154 if (!needsLayout()) { 179 if (!needsLayout()) {
155 // Just before the multicol container (our parent RenderBlockFlow) finis hes laying out, it 180 // Just before the multicol container (our parent RenderBlockFlow) finis hes laying out, it
156 // will call recalculateColumnHeights() on us unconditionally, but we on ly want that method 181 // will call recalculateColumnHeights() on us unconditionally, but we on ly want that method
157 // to do any work if we actually laid out the flow thread. Otherwise, th e balancing 182 // to do any work if we actually laid out the flow thread. Otherwise, th e balancing
158 // machinery would kick in needlessly, and trigger additional layout pas ses. Furthermore, we 183 // machinery would kick in needlessly, and trigger additional layout pas ses. Furthermore, we
159 // actually depend on a proper flowthread layout pass in order to do bal ancing, since it's 184 // actually depend on a proper flowthread layout pass in order to do bal ancing, since it's
160 // flowthread layout that sets up content runs. 185 // flowthread layout that sets up content runs.
161 m_needsColumnHeightsRecalculation = false;
162 return; 186 return;
163 } 187 }
164 188
165 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet()) { 189 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet()) {
166 if (!m_inBalancingPass) { 190 if (!m_inBalancingPass) {
167 // This is the initial layout pass. We need to reset the column heig ht, because contents 191 // This is the initial layout pass. We need to reset the column heig ht, because contents
168 // typically have changed. 192 // typically have changed.
169 columnSet->resetColumnHeight(); 193 columnSet->resetColumnHeight();
170 } 194 }
195 if (!m_needsColumnHeightsRecalculation)
196 m_needsColumnHeightsRecalculation = columnSet->isRenderMultiColumnSp annerSet() || columnSet->heightIsAuto();
171 } 197 }
172 198
173 invalidateRegions(); 199 invalidateRegions();
174 m_needsColumnHeightsRecalculation = heightIsAuto();
175 layout(); 200 layout();
176 } 201 }
177 202
178 bool RenderMultiColumnFlowThread::recalculateColumnHeights() 203 bool RenderMultiColumnFlowThread::recalculateColumnHeights()
179 { 204 {
180 // All column sets that needed layout have now been laid out, so we can fina lly validate them. 205 // All column sets that needed layout have now been laid out, so we can fina lly validate them.
181 validateRegions(); 206 validateRegions();
182 207
183 if (!m_needsColumnHeightsRecalculation) 208 if (!m_needsColumnHeightsRecalculation)
184 return false; 209 return false;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 m_spannerMap.clear(); 334 m_spannerMap.clear();
310 // Detach all column sets from the flow thread. Cannot destroy them at this point, since they 335 // Detach all column sets from the flow thread. Cannot destroy them at this point, since they
311 // are siblings of this object, and there may be pointers to this object's s ibling somewhere 336 // are siblings of this object, and there may be pointers to this object's s ibling somewhere
312 // further up on the call stack. 337 // further up on the call stack.
313 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet()) 338 for (RenderMultiColumnSet* columnSet = firstMultiColumnSet(); columnSet; col umnSet = columnSet->nextSiblingMultiColumnSet())
314 columnSet->detachRegion(); 339 columnSet->detachRegion();
315 multiColumnBlockFlow()->resetMultiColumnFlowThread(); 340 multiColumnBlockFlow()->resetMultiColumnFlowThread();
316 RenderFlowThread::willBeRemovedFromTree(); 341 RenderFlowThread::willBeRemovedFromTree();
317 } 342 }
318 343
344 bool RenderMultiColumnFlowThread::isColumnSpanner(const RenderObject* descendant ) const
345 {
346 ASSERT(descendant->isDescendantOf(this));
347 return m_spannerMap.get(descendant);
348 }
349
350 bool RenderMultiColumnFlowThread::isInsideColumnSpanner(const RenderObject* desc endant) const
351 {
352 ASSERT(descendant->isDescendantOf(this));
353 return containingColumnSpannerSet(descendant);
354 }
355
356 LayoutUnit RenderMultiColumnFlowThread::enterColumnSpannerBeforeLayout(RenderBox * renderer, LayoutUnit logicalTop, SubtreeLayoutScope& layoutScope)
357 {
358 ASSERT(isColumnSpanner(renderer));
359 RenderMultiColumnSpannerSet* spannerSet = m_spannerMap.get(renderer);
360
361 // FIXME: it's really only necessary to mark the spanner set for layout when the height of
362 // |renderer| changes.
363 spannerSet->setChildNeedsLayout(MarkOnlyThis, &layoutScope);
364
365 RenderMultiColumnSet* previousSet = spannerSet->previousSiblingMultiColumnSe t();
366 if (!previousSet) {
367 // The first set is entered at the beginning of flow thread layout. If t he first set happens
368 // to be a spanner, we have nothing more to do here.
369 return LayoutUnit();
370 }
371
372 LayoutUnit logicalTopInFlowThread = renderer->parentBlock()->offsetFromLogic alTopOfFirstPage() + logicalTop;
373 LayoutUnit adjustment;
374 if (!previousSet->isRenderMultiColumnSpannerSet() && previousSet->pageLogica lHeight()) {
375 // Pad flow thread offset to a column boundary, so that any content that 's supposed to come
376 // after the spanner (or the spanner itself) doesn't bleed into the colu mn preceding the
377 // spanner.
378 LayoutUnit columnLogicalTopInFlowThread = previousSet->pageLogicalTopFor Offset(logicalTopInFlowThread);
379 if (columnLogicalTopInFlowThread != logicalTopInFlowThread) {
380 adjustment = columnLogicalTopInFlowThread + previousSet->pageLogical Height() - logicalTopInFlowThread;
381 logicalTopInFlowThread += adjustment;
382 }
383 }
384
385 if (!previousSet->isRenderMultiColumnSpannerSet())
386 previousSet->endFlow(logicalTopInFlowThread);
387 spannerSet->beginFlow(logicalTopInFlowThread);
388
389 m_lastSetWorkedOn = spannerSet;
390 return adjustment;
391 }
392
393 void RenderMultiColumnFlowThread::exitColumnSpannerAfterLayout(RenderBox* render er, LayoutUnit logicalBottom)
394 {
395 ASSERT(m_lastSetWorkedOn == m_spannerMap.get(renderer));
396
397 LayoutUnit logicalBottomInFlowThread = renderer->parentBlock()->offsetFromLo gicalTopOfFirstPage() + logicalBottom;
398 m_lastSetWorkedOn->endFlow(logicalBottomInFlowThread);
399 if (RenderMultiColumnSet* nextSet = m_lastSetWorkedOn->nextSiblingMultiColum nSet()) {
400 m_lastSetWorkedOn = nextSet;
401 if (!m_lastSetWorkedOn->isRenderMultiColumnSpannerSet())
402 m_lastSetWorkedOn->beginFlow(logicalBottomInFlowThread);
403 }
404 }
405
319 void RenderMultiColumnFlowThread::flowThreadDescendantWasInserted(RenderObject* descendant) 406 void RenderMultiColumnFlowThread::flowThreadDescendantWasInserted(RenderObject* descendant)
320 { 407 {
408 ASSERT(!m_isBeingEvacuated);
321 // Go through the subtree that was just inserted and create column sets (nee ded by regular 409 // Go through the subtree that was just inserted and create column sets (nee ded by regular
322 // column content) and spanner sets (one needed by each spanner). 410 // column content) and spanner sets (one needed by each spanner).
323 for (RenderObject* renderer = descendant; renderer; renderer = renderer->nex tInPreOrder(descendant)) { 411 for (RenderObject* renderer = descendant; renderer; renderer = renderer->nex tInPreOrder(descendant)) {
324 if (containingColumnSpannerSet(renderer)) 412 if (containingColumnSpannerSet(renderer))
325 continue; // Inside a column spanner set. Nothing to do, then. 413 continue; // Inside a column spanner set. Nothing to do, then.
326 if (descendantIsValidColumnSpanner(renderer)) { 414 if (descendantIsValidColumnSpanner(renderer)) {
327 // This renderer is a spanner, so it needs to establish a spanner se t. 415 // This renderer is a spanner, so it needs to establish a spanner se t.
328 createAndInsertSpannerSet(toRenderBox(renderer)); 416 createAndInsertSpannerSet(toRenderBox(renderer));
329 continue; 417 continue;
330 } 418 }
331 // This renderer is regular column content (i.e. not a spanner). Create a set if necessary. 419 // This renderer is regular column content (i.e. not a spanner). Create a set if necessary.
332 RenderMultiColumnSet* lastSet = lastMultiColumnSet(); 420 RenderMultiColumnSet* lastSet = lastMultiColumnSet();
333 if (!lastSet || lastSet->isRenderMultiColumnSpannerSet()) 421 if (!lastSet || lastSet->isRenderMultiColumnSpannerSet())
334 createAndInsertMultiColumnSet(); 422 createAndInsertMultiColumnSet();
335 } 423 }
336 } 424 }
337 425
426 void RenderMultiColumnFlowThread::flowThreadDescendantWillBeRemoved(RenderObject * descendant)
427 {
428 if (m_isBeingEvacuated)
429 return;
430 RenderObject* next;
431 // Remove spanner sets that are no longer needed, and merge column sets arou nd them.
432 for (RenderObject* renderer = descendant; renderer; renderer = next) {
433 RenderMultiColumnSpannerSet* spanner = m_spannerMap.get(renderer);
434 if (!spanner) {
435 next = renderer->nextInPreOrder(descendant);
436 continue;
437 }
438 next = renderer->nextInPreOrderAfterChildren(descendant); // It's a span ner. Its children are of no interest to us.
439 if (RenderMultiColumnSet* nextSet = spanner->nextSiblingMultiColumnSet() ) {
440 RenderMultiColumnSet* previousSet = spanner->previousSiblingMultiCol umnSet();
441 if (nextSet && !nextSet->isRenderMultiColumnSpannerSet()
442 && previousSet && !previousSet->isRenderMultiColumnSpannerSet()) {
443 // Need to merge two column sets.
444 nextSet->destroy();
445 previousSet->setNeedsLayout();
446 invalidateRegions();
447 }
448 }
449 m_spannerMap.remove(renderer);
450 spanner->destroy();
451 }
452 }
453
338 void RenderMultiColumnFlowThread::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const 454 void RenderMultiColumnFlowThread::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
339 { 455 {
340 // We simply remain at our intrinsic height. 456 // We simply remain at our intrinsic height.
341 computedValues.m_extent = logicalHeight; 457 computedValues.m_extent = logicalHeight;
342 computedValues.m_position = logicalTop; 458 computedValues.m_position = logicalTop;
343 } 459 }
344 460
345 void RenderMultiColumnFlowThread::updateLogicalWidth() 461 void RenderMultiColumnFlowThread::updateLogicalWidth()
346 { 462 {
347 LayoutUnit columnWidth; 463 LayoutUnit columnWidth;
348 calculateColumnCountAndWidth(columnWidth, m_columnCount); 464 calculateColumnCountAndWidth(columnWidth, m_columnCount);
349 setLogicalWidth(columnWidth); 465 setLogicalWidth(columnWidth);
350 } 466 }
351 467
352 void RenderMultiColumnFlowThread::layout() 468 void RenderMultiColumnFlowThread::layout()
353 { 469 {
470 ASSERT(!m_lastSetWorkedOn);
471 m_lastSetWorkedOn = firstMultiColumnSet();
472 if (m_lastSetWorkedOn)
473 m_lastSetWorkedOn->beginFlow(LayoutUnit());
354 RenderFlowThread::layout(); 474 RenderFlowThread::layout();
355 if (RenderMultiColumnSet* lastSet = lastMultiColumnSet()) 475 if (RenderMultiColumnSet* lastSet = lastMultiColumnSet()) {
476 ASSERT(lastSet == m_lastSetWorkedOn);
477 lastSet->endFlow(logicalHeight());
356 lastSet->expandToEncompassFlowThreadContentsIfNeeded(); 478 lastSet->expandToEncompassFlowThreadContentsIfNeeded();
479 }
480 m_lastSetWorkedOn = 0;
357 } 481 }
358 482
359 void RenderMultiColumnFlowThread::setPageBreak(LayoutUnit offset, LayoutUnit spa ceShortage) 483 void RenderMultiColumnFlowThread::setPageBreak(LayoutUnit offset, LayoutUnit spa ceShortage)
360 { 484 {
361 // Only positive values are interesting (and allowed) here. Zero space short age may be reported 485 // Only positive values are interesting (and allowed) here. Zero space short age may be reported
362 // when we're at the top of a column and the element has zero height. Ignore this, and also 486 // when we're at the top of a column and the element has zero height. Ignore this, and also
363 // ignore any negative values, which may occur when we set an early break in order to honor 487 // ignore any negative values, which may occur when we set an early break in order to honor
364 // widows in the next column. 488 // widows in the next column.
365 if (spaceShortage <= 0) 489 if (spaceShortage <= 0)
366 return; 490 return;
367 491
368 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset)) 492 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset))
369 multicolSet->recordSpaceShortage(spaceShortage); 493 multicolSet->recordSpaceShortage(spaceShortage);
370 } 494 }
371 495
372 void RenderMultiColumnFlowThread::updateMinimumPageHeight(LayoutUnit offset, Lay outUnit minHeight) 496 void RenderMultiColumnFlowThread::updateMinimumPageHeight(LayoutUnit offset, Lay outUnit minHeight)
373 { 497 {
374 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset)) 498 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset))
375 multicolSet->updateMinimumColumnHeight(minHeight); 499 multicolSet->updateMinimumColumnHeight(minHeight);
376 } 500 }
377 501
378 RenderMultiColumnSet* RenderMultiColumnFlowThread::columnSetAtBlockOffset(Layout Unit /*offset*/) const
379 {
380 // For now there's only one column set, so this is easy:
381 return firstMultiColumnSet();
382 }
383
384 bool RenderMultiColumnFlowThread::addForcedRegionBreak(LayoutUnit offset, Render Object* /*breakChild*/, bool /*isBefore*/, LayoutUnit* offsetBreakAdjustment) 502 bool RenderMultiColumnFlowThread::addForcedRegionBreak(LayoutUnit offset, Render Object* /*breakChild*/, bool /*isBefore*/, LayoutUnit* offsetBreakAdjustment)
385 { 503 {
386 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset)) { 504 if (RenderMultiColumnSet* multicolSet = columnSetAtBlockOffset(offset)) {
387 multicolSet->addContentRun(offset); 505 multicolSet->addContentRun(offset);
388 if (offsetBreakAdjustment) 506 if (offsetBreakAdjustment)
389 *offsetBreakAdjustment = pageLogicalHeightForOffset(offset) ? pageRe mainingLogicalHeightForOffset(offset, IncludePageBoundary) : LayoutUnit(); 507 *offsetBreakAdjustment = pageLogicalHeightForOffset(offset) ? pageRe mainingLogicalHeightForOffset(offset, IncludePageBoundary) : LayoutUnit();
390 return true; 508 return true;
391 } 509 }
392 return false; 510 return false;
393 } 511 }
394 512
395 bool RenderMultiColumnFlowThread::isPageLogicalHeightKnown() const 513 bool RenderMultiColumnFlowThread::isPageLogicalHeightKnown() const
396 { 514 {
397 if (RenderMultiColumnSet* columnSet = lastMultiColumnSet()) 515 for (RenderMultiColumnSet* columnSet = lastMultiColumnSet(); columnSet; colu mnSet = columnSet->previousSiblingMultiColumnSet()) {
398 return columnSet->pageLogicalHeight(); 516 if (!columnSet->isRenderMultiColumnSpannerSet())
517 return columnSet->pageLogicalHeight();
518 }
399 return false; 519 return false;
400 } 520 }
401 521
402 } 522 }
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderMultiColumnFlowThread.h ('k') | Source/core/rendering/RenderMultiColumnFlowThreadTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698