This source file includes following definitions.
- m_needsRebalancing
- createAnonymous
- layoutColumns
- computeColumnCountAndWidth
- recalculateColumnHeights
- renderName
- computeLogicalHeight
- initialLogicalWidth
- autoGenerateRegionsToBlockOffset
- setPageBreak
- updateMinimumPageHeight
- addForcedRegionBreak
- isPageLogicalHeightKnown
#include "config.h"
#include "core/rendering/RenderMultiColumnFlowThread.h"
#include "core/rendering/RenderMultiColumnSet.h"
namespace WebCore {
RenderMultiColumnFlowThread::RenderMultiColumnFlowThread()
: m_columnCount(1)
, m_columnWidth(0)
, m_columnHeightAvailable(0)
, m_inBalancingPass(false)
, m_needsRebalancing(false)
{
setFlowThreadState(InsideInFlowThread);
}
RenderMultiColumnFlowThread::~RenderMultiColumnFlowThread()
{
}
RenderMultiColumnFlowThread* RenderMultiColumnFlowThread::createAnonymous(Document& document, RenderStyle* parentStyle)
{
RenderMultiColumnFlowThread* renderer = new RenderMultiColumnFlowThread();
renderer->setDocumentForAnonymous(&document);
renderer->setStyle(RenderStyle::createAnonymousStyleWithDisplay(parentStyle, BLOCK));
return renderer;
}
void RenderMultiColumnFlowThread::layoutColumns(bool relayoutChildren, SubtreeLayoutScope& layoutScope)
{
RenderBlockFlow* container = multiColumnBlockFlow();
bool shouldInvalidateRegions = false;
for (RenderBox* childBox = container->firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
if (childBox == this)
continue;
if (relayoutChildren || childBox->needsLayout()) {
if (!m_inBalancingPass && childBox->isRenderMultiColumnSet())
toRenderMultiColumnSet(childBox)->prepareForLayout();
shouldInvalidateRegions = true;
}
}
if (shouldInvalidateRegions)
invalidateRegions();
if (relayoutChildren)
layoutScope.setChildNeedsLayout(this);
if (requiresBalancing()) {
m_needsRebalancing = shouldInvalidateRegions || needsLayout();
}
layoutIfNeeded();
}
bool RenderMultiColumnFlowThread::computeColumnCountAndWidth()
{
RenderBlock* columnBlock = multiColumnBlockFlow();
LayoutUnit oldColumnWidth = m_columnWidth;
m_columnCount = 1;
m_columnWidth = columnBlock->contentLogicalWidth();
const RenderStyle* columnStyle = columnBlock->style();
ASSERT(!columnStyle->hasAutoColumnCount() || !columnStyle->hasAutoColumnWidth());
LayoutUnit availWidth = m_columnWidth;
LayoutUnit colGap = columnBlock->columnGap();
LayoutUnit colWidth = max<LayoutUnit>(1, LayoutUnit(columnStyle->columnWidth()));
int colCount = max<int>(1, columnStyle->columnCount());
if (columnStyle->hasAutoColumnWidth() && !columnStyle->hasAutoColumnCount()) {
m_columnCount = colCount;
m_columnWidth = std::max<LayoutUnit>(0, (availWidth - ((m_columnCount - 1) * colGap)) / m_columnCount);
} else if (!columnStyle->hasAutoColumnWidth() && columnStyle->hasAutoColumnCount()) {
m_columnCount = std::max<LayoutUnit>(1, (availWidth + colGap) / (colWidth + colGap));
m_columnWidth = ((availWidth + colGap) / m_columnCount) - colGap;
} else {
m_columnCount = std::max<LayoutUnit>(std::min<LayoutUnit>(colCount, (availWidth + colGap) / (colWidth + colGap)), 1);
m_columnWidth = ((availWidth + colGap) / m_columnCount) - colGap;
}
return m_columnWidth != oldColumnWidth;
}
bool RenderMultiColumnFlowThread::recalculateColumnHeights()
{
if (!m_needsRebalancing)
return false;
bool needsRelayout = false;
for (RenderBox* childBox = multiColumnBlockFlow()->firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
if (childBox != this && childBox->isRenderMultiColumnSet()) {
RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(childBox);
if (multicolSet->recalculateBalancedHeight(!m_inBalancingPass)) {
multicolSet->setChildNeedsLayout(MarkOnlyThis);
needsRelayout = true;
}
}
}
if (needsRelayout)
setChildNeedsLayout(MarkOnlyThis);
m_inBalancingPass = needsRelayout;
return needsRelayout;
}
const char* RenderMultiColumnFlowThread::renderName() const
{
return "RenderMultiColumnFlowThread";
}
void RenderMultiColumnFlowThread::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
{
computedValues.m_extent = logicalHeight;
computedValues.m_position = logicalTop;
}
LayoutUnit RenderMultiColumnFlowThread::initialLogicalWidth() const
{
return columnWidth();
}
void RenderMultiColumnFlowThread::autoGenerateRegionsToBlockOffset(LayoutUnit )
{
RenderMultiColumnSet* firstSet = toRenderMultiColumnSet(firstRegion());
if (firstSet)
return;
invalidateRegions();
RenderBlockFlow* parentBlock = multiColumnBlockFlow();
firstSet = RenderMultiColumnSet::createAnonymous(this);
firstSet->setStyle(RenderStyle::createAnonymousStyleWithDisplay(parentBlock->style(), BLOCK));
parentBlock->RenderBlock::addChild(firstSet);
firstSet->prepareForLayout();
validateRegions();
}
void RenderMultiColumnFlowThread::setPageBreak(LayoutUnit offset, LayoutUnit spaceShortage)
{
if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset)))
multicolSet->recordSpaceShortage(spaceShortage);
}
void RenderMultiColumnFlowThread::updateMinimumPageHeight(LayoutUnit offset, LayoutUnit minHeight)
{
if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset)))
multicolSet->updateMinimumColumnHeight(minHeight);
}
bool RenderMultiColumnFlowThread::addForcedRegionBreak(LayoutUnit offset, RenderObject* , bool , LayoutUnit* offsetBreakAdjustment)
{
if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(offset))) {
multicolSet->addForcedBreak(offset);
if (offsetBreakAdjustment)
*offsetBreakAdjustment = pageLogicalHeightForOffset(offset) ? pageRemainingLogicalHeightForOffset(offset, IncludePageBoundary) : LayoutUnit();
return true;
}
return false;
}
bool RenderMultiColumnFlowThread::isPageLogicalHeightKnown() const
{
for (RenderBox* renderer = parentBox()->lastChildBox(); renderer; renderer = renderer->previousSiblingBox()) {
if (renderer->isRenderMultiColumnSet())
return toRenderMultiColumnSet(renderer)->computedColumnHeight();
}
return !requiresBalancing();
}
}