FlexibleBoxAlgorithm.cpp [plain text]
#include "config.h"
#include "FlexibleBoxAlgorithm.h"
#include "RenderBox.h"
namespace WebCore {
FlexItem::FlexItem(RenderBox& box, LayoutUnit flexBaseContentSize, LayoutUnit hypotheticalMainContentSize, LayoutUnit mainAxisBorderAndPadding, LayoutUnit mainAxisMargin)
: box(box)
, flexBaseContentSize(flexBaseContentSize)
, hypotheticalMainContentSize(hypotheticalMainContentSize)
, mainAxisBorderAndPadding(mainAxisBorderAndPadding)
, mainAxisMargin(mainAxisMargin)
, frozen(false)
{
ASSERT(!box.isOutOfFlowPositioned());
}
FlexLayoutAlgorithm::FlexLayoutAlgorithm(const RenderStyle& style, LayoutUnit lineBreakLength, const Vector<FlexItem>& allItems)
: m_style(style)
, m_lineBreakLength(lineBreakLength)
, m_allItems(allItems)
{
}
bool FlexLayoutAlgorithm::computeNextFlexLine(size_t& nextIndex, Vector<FlexItem>& lineItems, LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalFlexShrink, double& totalWeightedFlexShrink, LayoutUnit& sumHypotheticalMainSize)
{
lineItems.clear();
sumFlexBaseSize = LayoutUnit();
totalFlexGrow = totalFlexShrink = totalWeightedFlexShrink = 0;
sumHypotheticalMainSize = LayoutUnit();
bool lineHasInFlowItem = false;
for (; nextIndex < m_allItems.size(); ++nextIndex) {
const auto& flexItem = m_allItems[nextIndex];
ASSERT(!flexItem.box.isOutOfFlowPositioned());
if (isMultiline() && sumHypotheticalMainSize + flexItem.hypotheticalMainAxisMarginBoxSize() > m_lineBreakLength && lineHasInFlowItem)
break;
lineItems.append(flexItem);
lineHasInFlowItem = true;
sumFlexBaseSize += flexItem.flexBaseMarginBoxSize();
totalFlexGrow += flexItem.box.style().flexGrow();
totalFlexShrink += flexItem.box.style().flexShrink();
totalWeightedFlexShrink += flexItem.box.style().flexShrink() * flexItem.flexBaseContentSize;
sumHypotheticalMainSize += flexItem.hypotheticalMainAxisMarginBoxSize();
}
ASSERT(lineItems.size() > 0 || nextIndex == m_allItems.size());
return lineItems.size() > 0;
}
}