2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS IN..0TERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "core/rendering/RenderMultiColumnFlowThread.h"
29 #include "core/rendering/RenderMultiColumnBlock.h"
30 #include "core/rendering/RenderMultiColumnSet.h"
34 RenderMultiColumnFlowThread::RenderMultiColumnFlowThread()
36 setFlowThreadState(InsideInFlowThread);
39 RenderMultiColumnFlowThread::~RenderMultiColumnFlowThread()
43 RenderMultiColumnFlowThread* RenderMultiColumnFlowThread::createAnonymous(Document* document)
45 RenderMultiColumnFlowThread* renderer = new RenderMultiColumnFlowThread();
46 renderer->setDocumentForAnonymous(document);
50 const char* RenderMultiColumnFlowThread::renderName() const
52 return "RenderMultiColumnFlowThread";
55 void RenderMultiColumnFlowThread::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
57 // We simply remain at our intrinsic height.
58 computedValues.m_extent = logicalHeight;
59 computedValues.m_position = logicalTop;
62 LayoutUnit RenderMultiColumnFlowThread::initialLogicalWidth() const
64 RenderMultiColumnBlock* parentBlock = toRenderMultiColumnBlock(parent());
65 return parentBlock->columnWidth();
68 void RenderMultiColumnFlowThread::autoGenerateRegionsToBlockOffset(LayoutUnit /*offset*/)
70 // This function ensures we have the correct column set information at all times.
71 // For a simple multi-column layout in continuous media, only one column set child is required.
72 // Once a column is nested inside an enclosing pagination context, the number of column sets
73 // required becomes 2n-1, where n is the total number of nested pagination contexts. For example:
75 // Column layout with no enclosing pagination model = 2 * 1 - 1 = 1 column set.
76 // Columns inside pages = 2 * 2 - 1 = 3 column sets (bottom of first page, all the subsequent pages, then the last page).
77 // Columns inside columns inside pages = 2 * 3 - 1 = 5 column sets.
79 // In addition, column spans will force a column set to "split" into before/after sets around the spanning element.
81 // Finally, we will need to deal with columns inside regions. If regions have variable widths, then there will need
82 // to be unique column sets created inside any region whose width is different from its surrounding regions. This is
83 // actually pretty similar to the spanning case, in that we break up the column sets whenever the width varies.
85 // FIXME: For now just make one column set. This matches the old multi-column code.
86 // Right now our goal is just feature parity with the old multi-column code so that we can switch over to the
87 // new code as soon as possible.
88 RenderMultiColumnSet* firstSet = toRenderMultiColumnSet(firstRegion());
94 RenderMultiColumnBlock* parentBlock = toRenderMultiColumnBlock(parent());
95 firstSet = RenderMultiColumnSet::createAnonymous(this);
96 firstSet->setStyle(RenderStyle::createAnonymousStyleWithDisplay(parentBlock->style(), BLOCK));
97 parentBlock->RenderBlock::addChild(firstSet);
99 // Even though we aren't placed yet, we can go ahead and set up our size. At this point we're
100 // typically in the middle of laying out the thread, attempting to paginate, and we need to do
101 // some rudimentary "layout" of the set now, so that pagination will work.
102 firstSet->prepareForLayout();
107 void RenderMultiColumnFlowThread::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage)
109 if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset)))
110 multicolSet->recordSpaceShortage(spaceShortage);
113 void RenderMultiColumnFlowThread::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight)
115 if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset)))
116 multicolSet->updateMinimumColumnHeight(minHeight);
119 bool RenderMultiColumnFlowThread::addForcedRegionBreak(LayoutUnit offset, RenderObject* /*breakChild*/, bool /*isBefore*/, LayoutUnit* offsetBreakAdjustment)
121 if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset))) {
122 multicolSet->addForcedBreak(offset);
123 if (offsetBreakAdjustment)
124 *offsetBreakAdjustment = pageLogicalHeightForOffset(offset) ? pageRemainingLogicalHeightForOffset(offset, IncludePageBoundary) : LayoutUnit();