This source file includes following definitions.
- setAtBeforeSideOfBlock
- setAtAfterSideOfBlock
- clearMargin
- setHasMarginBeforeQuirk
- setHasMarginAfterQuirk
- setDeterminedMarginBeforeQuirk
- setPositiveMargin
- setNegativeMargin
- setPositiveMarginIfLarger
- setNegativeMarginIfLarger
- setMargin
- setCanCollapseMarginAfterWithChildren
- setCanCollapseMarginAfterWithLastChild
- setDiscardMargin
- atBeforeSideOfBlock
- canCollapseWithMarginBefore
- canCollapseWithMarginAfter
- canCollapseMarginBeforeWithChildren
- canCollapseMarginAfterWithChildren
- canCollapseMarginAfterWithLastChild
- quirkContainer
- determinedMarginBeforeQuirk
- hasMarginBeforeQuirk
- hasMarginAfterQuirk
- positiveMargin
- negativeMargin
- discardMargin
- margin
- inNormalFlow
- createAnonymous
- createAnonymousBlockFlow
- layoutSpecialExcludedChild
- updateLogicalWidthAndColumnWidth
- checkForPaginationLogicalHeightChange
- shouldRelayoutForPagination
- setColumnCountAndHeight
- isSelfCollapsingBlock
- layoutBlock
- layoutBlockFlow
- determineLogicalLeftPositionForChild
- setLogicalLeftForChild
- setLogicalTopForChild
- layoutBlockChild
- adjustBlockChildForPagination
- rebuildFloatsFromIntruding
- layoutBlockChildren
- m_discardMargin
- marginValuesForChild
- collapseMargins
- adjustPositionedBlock
- computeStartPositionDeltaForChildAvoidingFloats
- clearFloatsIfNeeded
- setCollapsedBottomMargin
- marginBeforeEstimateForChild
- estimateLogicalTopPosition
- marginOffsetForSelfCollapsingBlock
- adjustFloatingBlock
- handleAfterSideOfBlock
- setMustDiscardMarginBefore
- setMustDiscardMarginAfter
- mustDiscardMarginBefore
- mustDiscardMarginAfter
- mustDiscardMarginBeforeForChild
- mustDiscardMarginAfterForChild
- setMaxMarginBeforeValues
- setMaxMarginAfterValues
- mustSeparateMarginBeforeForChild
- mustSeparateMarginAfterForChild
- applyBeforeBreak
- applyAfterBreak
- addOverflowFromFloats
- computeOverflow
- createAndAppendRootInlineBox
- deleteLineBoxTree
- markAllDescendantsWithFloatsForLayout
- markSiblingsWithFloatsForLayout
- getClearDelta
- createFloatingObjects
- styleWillChange
- styleDidChange
- updateStaticInlinePositionForChild
- setStaticInlinePositionForChild
- addChild
- moveAllChildrenIncludingFloatsTo
- repaintOverhangingFloats
- repaintOverflow
- paintFloats
- clipOutFloatingObjects
- clearFloats
- containsFloat
- removeFloatingObjects
- flipFloatForWritingModeForChild
- logicalLeftOffsetForPositioningFloat
- logicalRightOffsetForPositioningFloat
- adjustLogicalLeftOffsetForLine
- adjustLogicalRightOffsetForLine
- computeLogicalLocationForFloat
- insertFloatingObject
- removeFloatingObject
- removeFloatingObjectsBelow
- positionNewFloats
- hasOverhangingFloat
- addIntrudingFloats
- addOverhangingFloats
- lowestFloatLogicalBottom
- nextFloatLogicalBottomBelow
- hitTestFloats
- adjustForBorderFit
- logicalLeftFloatOffsetForLine
- logicalRightFloatOffsetForLine
- inlineSelectionGaps
- logicalLeftSelectionOffset
- logicalRightSelectionOffset
- constructTextRunInternal
- constructTextRunInternal
- constructTextRun
- constructTextRun
- constructTextRun
- constructTextRun
- constructTextRun
- constructTextRun
- constructTextRun
- createRootInlineBox
- createMultiColumnFlowThreadIfNeeded
- ensureRareData
#include "config.h"
#include "core/rendering/RenderBlockFlow.h"
#include "core/accessibility/AXObjectCache.h"
#include "core/frame/FrameView.h"
#include "core/rendering/FastTextAutosizer.h"
#include "core/rendering/HitTestLocation.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/LayoutRepainter.h"
#include "core/rendering/RenderFlowThread.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderMultiColumnFlowThread.h"
#include "core/rendering/RenderText.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/line/LineWidth.h"
#include "core/rendering/svg/SVGTextRunRenderingContext.h"
#include "platform/text/BidiTextRun.h"
using namespace std;
namespace WebCore {
bool RenderBlockFlow::s_canPropagateFloatIntoSibling = false;
struct SameSizeAsMarginInfo {
uint16_t bitfields;
LayoutUnit margins[2];
};
COMPILE_ASSERT(sizeof(RenderBlockFlow::MarginValues) == sizeof(LayoutUnit[4]), MarginValues_should_stay_small);
class MarginInfo {
bool m_canCollapseWithChildren : 1;
bool m_canCollapseMarginBeforeWithChildren : 1;
bool m_canCollapseMarginAfterWithChildren : 1;
bool m_canCollapseMarginAfterWithLastChild: 1;
bool m_quirkContainer : 1;
bool m_atBeforeSideOfBlock : 1;
bool m_atAfterSideOfBlock : 1;
bool m_hasMarginBeforeQuirk : 1;
bool m_hasMarginAfterQuirk : 1;
bool m_determinedMarginBeforeQuirk : 1;
bool m_discardMargin : 1;
LayoutUnit m_positiveMargin;
LayoutUnit m_negativeMargin;
public:
MarginInfo(RenderBlockFlow*, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding);
void setAtBeforeSideOfBlock(bool b) { m_atBeforeSideOfBlock = b; }
void setAtAfterSideOfBlock(bool b) { m_atAfterSideOfBlock = b; }
void clearMargin()
{
m_positiveMargin = 0;
m_negativeMargin = 0;
}
void setHasMarginBeforeQuirk(bool b) { m_hasMarginBeforeQuirk = b; }
void setHasMarginAfterQuirk(bool b) { m_hasMarginAfterQuirk = b; }
void setDeterminedMarginBeforeQuirk(bool b) { m_determinedMarginBeforeQuirk = b; }
void setPositiveMargin(LayoutUnit p) { ASSERT(!m_discardMargin); m_positiveMargin = p; }
void setNegativeMargin(LayoutUnit n) { ASSERT(!m_discardMargin); m_negativeMargin = n; }
void setPositiveMarginIfLarger(LayoutUnit p)
{
ASSERT(!m_discardMargin);
if (p > m_positiveMargin)
m_positiveMargin = p;
}
void setNegativeMarginIfLarger(LayoutUnit n)
{
ASSERT(!m_discardMargin);
if (n > m_negativeMargin)
m_negativeMargin = n;
}
void setMargin(LayoutUnit p, LayoutUnit n) { ASSERT(!m_discardMargin); m_positiveMargin = p; m_negativeMargin = n; }
void setCanCollapseMarginAfterWithChildren(bool collapse) { m_canCollapseMarginAfterWithChildren = collapse; }
void setCanCollapseMarginAfterWithLastChild(bool collapse) { m_canCollapseMarginAfterWithLastChild = collapse; }
void setDiscardMargin(bool value) { m_discardMargin = value; }
bool atBeforeSideOfBlock() const { return m_atBeforeSideOfBlock; }
bool canCollapseWithMarginBefore() const { return m_atBeforeSideOfBlock && m_canCollapseMarginBeforeWithChildren; }
bool canCollapseWithMarginAfter() const { return m_atAfterSideOfBlock && m_canCollapseMarginAfterWithChildren; }
bool canCollapseMarginBeforeWithChildren() const { return m_canCollapseMarginBeforeWithChildren; }
bool canCollapseMarginAfterWithChildren() const { return m_canCollapseMarginAfterWithChildren; }
bool canCollapseMarginAfterWithLastChild() const { return m_canCollapseMarginAfterWithLastChild; }
bool quirkContainer() const { return m_quirkContainer; }
bool determinedMarginBeforeQuirk() const { return m_determinedMarginBeforeQuirk; }
bool hasMarginBeforeQuirk() const { return m_hasMarginBeforeQuirk; }
bool hasMarginAfterQuirk() const { return m_hasMarginAfterQuirk; }
LayoutUnit positiveMargin() const { return m_positiveMargin; }
LayoutUnit negativeMargin() const { return m_negativeMargin; }
bool discardMargin() const { return m_discardMargin; }
LayoutUnit margin() const { return m_positiveMargin - m_negativeMargin; }
};
static bool inNormalFlow(RenderBox* child)
{
RenderBlock* curr = child->containingBlock();
RenderView* renderView = child->view();
while (curr && curr != renderView) {
if (curr->hasColumns() || curr->isRenderFlowThread())
return true;
if (curr->isFloatingOrOutOfFlowPositioned())
return false;
curr = curr->containingBlock();
}
return true;
}
RenderBlockFlow::RenderBlockFlow(ContainerNode* node)
: RenderBlock(node)
{
COMPILE_ASSERT(sizeof(MarginInfo) == sizeof(SameSizeAsMarginInfo), MarginInfo_should_stay_small);
}
RenderBlockFlow::~RenderBlockFlow()
{
}
RenderBlockFlow* RenderBlockFlow::createAnonymous(Document* document)
{
RenderBlockFlow* renderer = new RenderBlockFlow(0);
renderer->setDocumentForAnonymous(document);
return renderer;
}
RenderBlockFlow* RenderBlockFlow::createAnonymousBlockFlow() const
{
return toRenderBlockFlow(createAnonymousWithParentRendererAndDisplay(this, BLOCK));
}
RenderObject* RenderBlockFlow::layoutSpecialExcludedChild(bool relayoutChildren, SubtreeLayoutScope& layoutScope)
{
RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread();
if (!flowThread)
return 0;
setLogicalTopForChild(flowThread, borderBefore() + paddingBefore());
flowThread->layoutColumns(relayoutChildren, layoutScope);
determineLogicalLeftPositionForChild(flowThread);
return flowThread;
}
bool RenderBlockFlow::updateLogicalWidthAndColumnWidth()
{
bool relayoutChildren = RenderBlock::updateLogicalWidthAndColumnWidth();
if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) {
if (flowThread->computeColumnCountAndWidth())
return true;
}
return relayoutChildren;
}
void RenderBlockFlow::checkForPaginationLogicalHeightChange(LayoutUnit& pageLogicalHeight, bool& pageLogicalHeightChanged, bool& hasSpecifiedPageLogicalHeight)
{
if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) {
updateLogicalHeight();
flowThread->setColumnHeightAvailable(std::max<LayoutUnit>(contentLogicalHeight(), 0));
setLogicalHeight(0);
} else if (hasColumns()) {
ColumnInfo* colInfo = columnInfo();
if (!pageLogicalHeight) {
LayoutUnit oldLogicalHeight = logicalHeight();
setLogicalHeight(0);
updateLogicalHeight();
LayoutUnit columnHeight = contentLogicalHeight();
if (columnHeight > 0) {
pageLogicalHeight = columnHeight;
hasSpecifiedPageLogicalHeight = true;
}
setLogicalHeight(oldLogicalHeight);
}
if (colInfo->columnHeight() != pageLogicalHeight && everHadLayout()) {
colInfo->setColumnHeight(pageLogicalHeight);
pageLogicalHeightChanged = true;
}
if (!hasSpecifiedPageLogicalHeight && !pageLogicalHeight)
colInfo->clearForcedBreaks();
} else if (isRenderFlowThread()) {
RenderFlowThread* flowThread = toRenderFlowThread(this);
pageLogicalHeight = flowThread->isPageLogicalHeightKnown() ? LayoutUnit(1) : LayoutUnit(0);
pageLogicalHeightChanged = flowThread->pageLogicalSizeChanged();
}
}
bool RenderBlockFlow::shouldRelayoutForPagination(LayoutUnit& pageLogicalHeight, LayoutUnit layoutOverflowLogicalBottom) const
{
ColumnInfo* colInfo = columnInfo();
LayoutUnit columnHeight = pageLogicalHeight;
const int minColumnCount = colInfo->forcedBreaks() + 1;
const int desiredColumnCount = colInfo->desiredColumnCount();
if (minColumnCount >= desiredColumnCount) {
if (!pageLogicalHeight) {
LayoutUnit distanceBetweenBreaks = max<LayoutUnit>(colInfo->maximumDistanceBetweenForcedBreaks(),
view()->layoutState()->pageLogicalOffset(*this, borderBefore() + paddingBefore() + layoutOverflowLogicalBottom) - colInfo->forcedBreakOffset());
columnHeight = max(colInfo->minimumColumnHeight(), distanceBetweenBreaks);
}
} else if (layoutOverflowLogicalBottom > boundedMultiply(pageLogicalHeight, desiredColumnCount)) {
columnHeight = max<LayoutUnit>(colInfo->minimumColumnHeight(), ceilf(layoutOverflowLogicalBottom.toFloat() / desiredColumnCount));
}
if (columnHeight && columnHeight != pageLogicalHeight) {
pageLogicalHeight = columnHeight;
return true;
}
return false;
}
void RenderBlockFlow::setColumnCountAndHeight(unsigned count, LayoutUnit pageLogicalHeight)
{
ColumnInfo* colInfo = columnInfo();
if (pageLogicalHeight)
colInfo->setColumnCountAndHeight(count, pageLogicalHeight);
if (columnCount(colInfo)) {
setLogicalHeight(borderBefore() + paddingBefore() + colInfo->columnHeight() + borderAfter() + paddingAfter() + scrollbarLogicalHeight());
m_overflow.clear();
}
}
bool RenderBlockFlow::isSelfCollapsingBlock() const
{
m_hasOnlySelfCollapsingChildren = RenderBlock::isSelfCollapsingBlock();
return m_hasOnlySelfCollapsingChildren;
}
void RenderBlockFlow::layoutBlock(bool relayoutChildren)
{
ASSERT(needsLayout());
ASSERT(isInlineBlockOrInlineTable() || !isInline());
m_hasOnlySelfCollapsingChildren = false;
if (!relayoutChildren && simplifiedLayout())
return;
SubtreeLayoutScope layoutScope(this);
bool done = false;
LayoutUnit pageLogicalHeight = 0;
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
while (!done)
done = layoutBlockFlow(relayoutChildren, pageLogicalHeight, layoutScope);
fitBorderToLinesIfNeeded();
RenderView* renderView = view();
if (renderView->layoutState()->pageLogicalHeight())
setPageLogicalOffset(renderView->layoutState()->pageLogicalOffset(*this, logicalTop()));
updateLayerTransform();
updateScrollInfoAfterLayout();
bool didFullRepaint = repainter.repaintAfterLayout();
if (!didFullRepaint && m_repaintLogicalTop != m_repaintLogicalBottom && (style()->visibility() == VISIBLE || enclosingLayer()->hasVisibleContent())) {
if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
setShouldRepaintOverflow(true);
else
repaintOverflow();
}
clearNeedsLayout();
}
inline bool RenderBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit &pageLogicalHeight, SubtreeLayoutScope& layoutScope)
{
LayoutUnit oldLeft = logicalLeft();
if (updateLogicalWidthAndColumnWidth())
relayoutChildren = true;
rebuildFloatsFromIntruding();
bool pageLogicalHeightChanged = false;
bool hasSpecifiedPageLogicalHeight = false;
checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightChanged, hasSpecifiedPageLogicalHeight);
LayoutStateMaintainer statePusher(*this, locationOffset(), pageLogicalHeight, pageLogicalHeightChanged, columnInfo());
if (!isTableCell()) {
initMaxMarginValues();
setHasMarginBeforeQuirk(style()->hasMarginBeforeQuirk());
setHasMarginAfterQuirk(style()->hasMarginAfterQuirk());
setPaginationStrut(0);
}
LayoutUnit beforeEdge = borderBefore() + paddingBefore();
LayoutUnit afterEdge = borderAfter() + paddingAfter() + scrollbarLogicalHeight();
LayoutUnit previousHeight = logicalHeight();
setLogicalHeight(beforeEdge);
m_repaintLogicalTop = 0;
m_repaintLogicalBottom = 0;
LayoutUnit maxFloatLogicalBottom = 0;
if (!firstChild() && !isAnonymousBlock())
setChildrenInline(true);
FastTextAutosizer::LayoutScope fastTextAutosizerLayoutScope(this);
if (childrenInline())
layoutInlineChildren(relayoutChildren, m_repaintLogicalTop, m_repaintLogicalBottom, afterEdge);
else
layoutBlockChildren(relayoutChildren, maxFloatLogicalBottom, layoutScope, beforeEdge, afterEdge);
if (lowestFloatLogicalBottom() > (logicalHeight() - afterEdge) && createsBlockFormattingContext())
setLogicalHeight(lowestFloatLogicalBottom() + afterEdge);
if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread()) {
if (flowThread->recalculateColumnHeights()) {
setChildNeedsLayout(MarkOnlyThis);
return false;
}
} else if (hasColumns()) {
OwnPtr<RenderOverflow> savedOverflow = m_overflow.release();
if (childrenInline())
addOverflowFromInlineChildren();
else
addOverflowFromBlockChildren();
LayoutUnit layoutOverflowLogicalBottom = (isHorizontalWritingMode() ? layoutOverflowRect().maxY() : layoutOverflowRect().maxX()) - borderBefore() - paddingBefore();
m_overflow = savedOverflow.release();
if (!hasSpecifiedPageLogicalHeight && shouldRelayoutForPagination(pageLogicalHeight, layoutOverflowLogicalBottom)) {
setEverHadLayout(true);
return false;
}
setColumnCountAndHeight(ceilf(layoutOverflowLogicalBottom.toFloat() / pageLogicalHeight.toFloat()), pageLogicalHeight.toFloat());
}
if (shouldBreakAtLineToAvoidWidow()) {
setEverHadLayout(true);
return false;
}
LayoutUnit oldHeight = logicalHeight();
LayoutUnit oldClientAfterEdge = clientLogicalBottom();
if (isRenderFlowThread())
toRenderFlowThread(this)->applyBreakAfterContent(oldClientAfterEdge);
updateLogicalHeight();
LayoutUnit newHeight = logicalHeight();
if (oldHeight != newHeight) {
if (oldHeight > newHeight && maxFloatLogicalBottom > newHeight && !childrenInline()) {
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if (child->isRenderBlockFlow() && !child->isFloatingOrOutOfFlowPositioned()) {
RenderBlockFlow* block = toRenderBlockFlow(child);
if (block->lowestFloatLogicalBottom() + block->logicalTop() > newHeight)
addOverhangingFloats(block, false);
}
}
}
}
bool heightChanged = (previousHeight != newHeight);
if (heightChanged)
relayoutChildren = true;
layoutPositionedObjects(relayoutChildren || isRoot(), oldLeft != logicalLeft() ? ForcedLayoutAfterContainingBlockMoved : DefaultLayout);
computeRegionRangeForBlock(flowThreadContainingBlock());
computeOverflow(oldClientAfterEdge);
return true;
}
void RenderBlockFlow::determineLogicalLeftPositionForChild(RenderBox* child, ApplyLayoutDeltaMode applyDelta)
{
LayoutUnit startPosition = borderStart() + paddingStart();
if (style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
startPosition -= verticalScrollbarWidth();
LayoutUnit totalAvailableLogicalWidth = borderAndPaddingLogicalWidth() + availableLogicalWidth();
LayoutUnit childMarginStart = marginStartForChild(child);
LayoutUnit newPosition = startPosition + childMarginStart;
if (child->avoidsFloats() && containsFloats() && !flowThreadContainingBlock())
newPosition += computeStartPositionDeltaForChildAvoidingFloats(child, marginStartForChild(child));
setLogicalLeftForChild(child, style()->isLeftToRightDirection() ? newPosition : totalAvailableLogicalWidth - newPosition - logicalWidthForChild(child), applyDelta);
}
void RenderBlockFlow::setLogicalLeftForChild(RenderBox* child, LayoutUnit logicalLeft, ApplyLayoutDeltaMode applyDelta)
{
if (isHorizontalWritingMode()) {
if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
view()->addLayoutDelta(LayoutSize(child->x() - logicalLeft, 0));
child->setX(logicalLeft);
} else {
if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
view()->addLayoutDelta(LayoutSize(0, child->y() - logicalLeft));
child->setY(logicalLeft);
}
}
void RenderBlockFlow::setLogicalTopForChild(RenderBox* child, LayoutUnit logicalTop, ApplyLayoutDeltaMode applyDelta)
{
if (isHorizontalWritingMode()) {
if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
view()->addLayoutDelta(LayoutSize(0, child->y() - logicalTop));
child->setY(logicalTop);
} else {
if (applyDelta == ApplyLayoutDelta && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
view()->addLayoutDelta(LayoutSize(child->x() - logicalTop, 0));
child->setX(logicalTop);
}
}
void RenderBlockFlow::layoutBlockChild(RenderBox* child, MarginInfo& marginInfo, LayoutUnit& previousFloatLogicalBottom, LayoutUnit& maxFloatLogicalBottom)
{
LayoutUnit oldPosMarginBefore = maxPositiveMarginBefore();
LayoutUnit oldNegMarginBefore = maxNegativeMarginBefore();
child->computeAndSetBlockDirectionMargins(this);
LayoutUnit estimateWithoutPagination;
LayoutUnit logicalTopEstimate = estimateLogicalTopPosition(child, marginInfo, estimateWithoutPagination);
LayoutRect oldRect = child->frameRect();
LayoutUnit oldLogicalTop = logicalTopForChild(child);
#if !ASSERT_DISABLED
LayoutSize oldLayoutDelta = RuntimeEnabledFeatures::repaintAfterLayoutEnabled() ? LayoutSize() : view()->layoutDelta();
#endif
setLogicalTopForChild(child, logicalTopEstimate, ApplyLayoutDelta);
RenderBlock* childRenderBlock = child->isRenderBlock() ? toRenderBlock(child) : 0;
RenderBlockFlow* childRenderBlockFlow = (childRenderBlock && child->isRenderBlockFlow()) ? toRenderBlockFlow(child) : 0;
bool markDescendantsWithFloats = false;
if (logicalTopEstimate != oldLogicalTop && !child->avoidsFloats() && childRenderBlock && childRenderBlock->containsFloats()) {
markDescendantsWithFloats = true;
} else if (UNLIKELY(logicalTopEstimate.mightBeSaturated())) {
markDescendantsWithFloats = true;
} else if (!child->avoidsFloats() || child->shrinkToAvoidFloats()) {
LayoutUnit fb = max(previousFloatLogicalBottom, lowestFloatLogicalBottom());
if (fb > logicalTopEstimate)
markDescendantsWithFloats = true;
}
if (childRenderBlockFlow) {
if (markDescendantsWithFloats)
childRenderBlockFlow->markAllDescendantsWithFloatsForLayout();
if (!child->isWritingModeRoot())
previousFloatLogicalBottom = max(previousFloatLogicalBottom, oldLogicalTop + childRenderBlockFlow->lowestFloatLogicalBottom());
}
SubtreeLayoutScope layoutScope(child);
if (!child->needsLayout())
child->markForPaginationRelayoutIfNeeded(layoutScope);
bool childHadLayout = child->everHadLayout();
bool childNeededLayout = child->needsLayout();
if (childNeededLayout)
child->layout();
bool atBeforeSideOfBlock = marginInfo.atBeforeSideOfBlock();
bool childIsSelfCollapsing = child->isSelfCollapsingBlock();
LayoutUnit logicalTopBeforeClear = collapseMargins(child, marginInfo, childIsSelfCollapsing);
LayoutUnit logicalTopAfterClear = clearFloatsIfNeeded(child, marginInfo, oldPosMarginBefore, oldNegMarginBefore, logicalTopBeforeClear, childIsSelfCollapsing);
bool paginated = view()->layoutState()->isPaginated();
if (paginated) {
logicalTopAfterClear = adjustBlockChildForPagination(logicalTopAfterClear, estimateWithoutPagination, child,
atBeforeSideOfBlock && logicalTopBeforeClear == logicalTopAfterClear);
}
setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta);
if (logicalTopAfterClear != logicalTopEstimate || child->needsLayout() || (paginated && childRenderBlock && childRenderBlock->shouldBreakAtLineToAvoidWidow())) {
SubtreeLayoutScope layoutScope(child);
if (child->shrinkToAvoidFloats()) {
layoutScope.setChildNeedsLayout(child);
}
if (childRenderBlock) {
if (!child->avoidsFloats() && childRenderBlock->containsFloats())
childRenderBlockFlow->markAllDescendantsWithFloatsForLayout();
if (!child->needsLayout())
child->markForPaginationRelayoutIfNeeded(layoutScope);
}
child->layoutIfNeeded();
}
if (!marginInfo.canCollapseMarginAfterWithLastChild() && !childIsSelfCollapsing)
marginInfo.setCanCollapseMarginAfterWithLastChild(true);
if (marginInfo.atBeforeSideOfBlock() && !childIsSelfCollapsing)
marginInfo.setAtBeforeSideOfBlock(false);
determineLogicalLeftPositionForChild(child, ApplyLayoutDelta);
LayoutSize childOffset = child->location() - oldRect.location();
setLogicalHeight(logicalHeight() + logicalHeightForChild(child));
if (mustSeparateMarginAfterForChild(child)) {
setLogicalHeight(logicalHeight() + marginAfterForChild(child));
marginInfo.clearMargin();
}
if (childRenderBlockFlow && childRenderBlockFlow->containsFloats())
maxFloatLogicalBottom = max(maxFloatLogicalBottom, addOverhangingFloats(childRenderBlockFlow, !childNeededLayout));
if (childOffset.width() || childOffset.height()) {
if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
view()->addLayoutDelta(childOffset);
if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled() && childHadLayout && !selfNeedsLayout())
child->repaintOverhangingFloats(true);
else if (childHadLayout && !selfNeedsLayout() && child->checkForRepaintDuringLayout())
child->repaintDuringLayoutIfMoved(oldRect);
}
if (!childHadLayout && child->checkForRepaint()) {
if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
child->repaint();
child->repaintOverhangingFloats(true);
}
if (paginated) {
LayoutUnit newHeight = applyAfterBreak(child, logicalHeight(), marginInfo);
if (newHeight != height())
setLogicalHeight(newHeight);
}
if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) {
ASSERT(view()->layoutDeltaMatches(oldLayoutDelta));
}
}
LayoutUnit RenderBlockFlow::adjustBlockChildForPagination(LayoutUnit logicalTopAfterClear, LayoutUnit estimateWithoutPagination, RenderBox* child, bool atBeforeSideOfBlock)
{
RenderBlock* childRenderBlock = child->isRenderBlock() ? toRenderBlock(child) : 0;
if (estimateWithoutPagination != logicalTopAfterClear) {
setLogicalHeight(logicalTopAfterClear);
setLogicalTopForChild(child, logicalTopAfterClear, ApplyLayoutDelta);
if (child->shrinkToAvoidFloats()) {
child->setChildNeedsLayout(MarkOnlyThis);
}
SubtreeLayoutScope layoutScope(child);
if (childRenderBlock) {
if (!child->avoidsFloats() && childRenderBlock->containsFloats())
toRenderBlockFlow(childRenderBlock)->markAllDescendantsWithFloatsForLayout();
if (!child->needsLayout())
child->markForPaginationRelayoutIfNeeded(layoutScope);
}
child->layoutIfNeeded();
}
LayoutUnit oldTop = logicalTopAfterClear;
LayoutUnit result = applyBeforeBreak(child, logicalTopAfterClear);
if (pageLogicalHeightForOffset(result)) {
LayoutUnit remainingLogicalHeight = pageRemainingLogicalHeightForOffset(result, ExcludePageBoundary);
LayoutUnit spaceShortage = child->logicalHeight() - remainingLogicalHeight;
if (spaceShortage > 0) {
setPageBreak(result, spaceShortage);
}
}
LayoutUnit logicalTopBeforeUnsplittableAdjustment = result;
LayoutUnit logicalTopAfterUnsplittableAdjustment = adjustForUnsplittableChild(child, result);
LayoutUnit paginationStrut = 0;
LayoutUnit unsplittableAdjustmentDelta = logicalTopAfterUnsplittableAdjustment - logicalTopBeforeUnsplittableAdjustment;
if (unsplittableAdjustmentDelta)
paginationStrut = unsplittableAdjustmentDelta;
else if (childRenderBlock && childRenderBlock->paginationStrut())
paginationStrut = childRenderBlock->paginationStrut();
if (paginationStrut) {
if (atBeforeSideOfBlock && oldTop == result && !isOutOfFlowPositioned() && !isTableCell()) {
setPaginationStrut(result + paginationStrut);
if (childRenderBlock)
childRenderBlock->setPaginationStrut(0);
} else {
result += paginationStrut;
}
}
setLogicalHeight(logicalHeight() + (result - oldTop));
return result;
}
void RenderBlockFlow::rebuildFloatsFromIntruding()
{
if (m_floatingObjects)
m_floatingObjects->setHorizontalWritingMode(isHorizontalWritingMode());
HashSet<RenderBox*> oldIntrudingFloatSet;
if (!childrenInline() && m_floatingObjects) {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (!floatingObject->isDescendant())
oldIntrudingFloatSet.add(floatingObject->renderer());
}
}
if (avoidsFloats() || isRoot() || isRenderView() || isFloatingOrOutOfFlowPositioned() || isTableCell()) {
if (m_floatingObjects) {
m_floatingObjects->clear();
}
if (!oldIntrudingFloatSet.isEmpty())
markAllDescendantsWithFloatsForLayout();
return;
}
RendererToFloatInfoMap floatMap;
if (m_floatingObjects) {
if (childrenInline())
m_floatingObjects->moveAllToFloatInfoMap(floatMap);
else
m_floatingObjects->clear();
}
if (!parent() || !parent()->isRenderBlockFlow())
return;
RenderBlockFlow* parentBlockFlow = toRenderBlockFlow(parent());
bool parentHasFloats = false;
RenderObject* prev = previousSibling();
while (prev && (prev->isFloatingOrOutOfFlowPositioned() || !prev->isBox() || !prev->isRenderBlock() || toRenderBlock(prev)->avoidsFloats())) {
if (prev->isFloating())
parentHasFloats = true;
prev = prev->previousSibling();
}
LayoutUnit logicalTopOffset = logicalTop();
if (parentHasFloats || (prev && toRenderBlockFlow(prev)->isSelfCollapsingBlock() && parentBlockFlow->lowestFloatLogicalBottom() > logicalTopOffset))
addIntrudingFloats(parentBlockFlow, parentBlockFlow->logicalLeftOffsetForContent(), logicalTopOffset);
LayoutUnit logicalLeftOffset = 0;
if (prev) {
logicalTopOffset -= toRenderBox(prev)->logicalTop();
} else {
prev = parentBlockFlow;
logicalLeftOffset += parentBlockFlow->logicalLeftOffsetForContent();
}
RenderBlockFlow* blockFlow = toRenderBlockFlow(prev);
if (blockFlow->m_floatingObjects && blockFlow->lowestFloatLogicalBottom() > logicalTopOffset)
addIntrudingFloats(blockFlow, logicalLeftOffset, logicalTopOffset);
if (childrenInline()) {
LayoutUnit changeLogicalTop = LayoutUnit::max();
LayoutUnit changeLogicalBottom = LayoutUnit::min();
if (m_floatingObjects) {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
FloatingObject* oldFloatingObject = floatMap.get(floatingObject->renderer());
LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject);
if (oldFloatingObject) {
LayoutUnit oldLogicalBottom = logicalBottomForFloat(oldFloatingObject);
if (logicalWidthForFloat(floatingObject) != logicalWidthForFloat(oldFloatingObject) || logicalLeftForFloat(floatingObject) != logicalLeftForFloat(oldFloatingObject)) {
changeLogicalTop = 0;
changeLogicalBottom = max(changeLogicalBottom, max(logicalBottom, oldLogicalBottom));
} else {
if (logicalBottom != oldLogicalBottom) {
changeLogicalTop = min(changeLogicalTop, min(logicalBottom, oldLogicalBottom));
changeLogicalBottom = max(changeLogicalBottom, max(logicalBottom, oldLogicalBottom));
}
LayoutUnit logicalTop = logicalTopForFloat(floatingObject);
LayoutUnit oldLogicalTop = logicalTopForFloat(oldFloatingObject);
if (logicalTop != oldLogicalTop) {
changeLogicalTop = min(changeLogicalTop, min(logicalTop, oldLogicalTop));
changeLogicalBottom = max(changeLogicalBottom, max(logicalTop, oldLogicalTop));
}
}
floatMap.remove(floatingObject->renderer());
if (oldFloatingObject->originatingLine() && !selfNeedsLayout()) {
ASSERT(oldFloatingObject->originatingLine()->renderer() == this);
oldFloatingObject->originatingLine()->markDirty();
}
delete oldFloatingObject;
} else {
changeLogicalTop = 0;
changeLogicalBottom = max(changeLogicalBottom, logicalBottom);
}
}
}
RendererToFloatInfoMap::iterator end = floatMap.end();
for (RendererToFloatInfoMap::iterator it = floatMap.begin(); it != end; ++it) {
FloatingObject* floatingObject = (*it).value;
if (!floatingObject->isDescendant()) {
changeLogicalTop = 0;
changeLogicalBottom = max(changeLogicalBottom, logicalBottomForFloat(floatingObject));
}
}
deleteAllValues(floatMap);
markLinesDirtyInBlockRange(changeLogicalTop, changeLogicalBottom);
} else if (!oldIntrudingFloatSet.isEmpty()) {
if (m_floatingObjects->set().size() < oldIntrudingFloatSet.size()) {
markAllDescendantsWithFloatsForLayout();
} else {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end && !oldIntrudingFloatSet.isEmpty(); ++it)
oldIntrudingFloatSet.remove((*it)->renderer());
if (!oldIntrudingFloatSet.isEmpty())
markAllDescendantsWithFloatsForLayout();
}
}
}
void RenderBlockFlow::layoutBlockChildren(bool relayoutChildren, LayoutUnit& maxFloatLogicalBottom, SubtreeLayoutScope& layoutScope, LayoutUnit beforeEdge, LayoutUnit afterEdge)
{
dirtyForLayoutFromPercentageHeightDescendants(layoutScope);
MarginInfo marginInfo(this, beforeEdge, afterEdge);
RenderObject* childToExclude = layoutSpecialExcludedChild(relayoutChildren, layoutScope);
LayoutUnit previousFloatLogicalBottom = 0;
maxFloatLogicalBottom = 0;
RenderBox* next = firstChildBox();
RenderBox* lastNormalFlowChild = 0;
while (next) {
RenderBox* child = next;
next = child->nextSiblingBox();
LayoutRectRecorder recorder(*child);
if (childToExclude == child)
continue;
updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child);
if (child->isOutOfFlowPositioned()) {
child->containingBlock()->insertPositionedObject(child);
adjustPositionedBlock(child, marginInfo);
continue;
}
if (child->isFloating()) {
insertFloatingObject(child);
adjustFloatingBlock(marginInfo);
continue;
}
layoutBlockChild(child, marginInfo, previousFloatLogicalBottom, maxFloatLogicalBottom);
lastNormalFlowChild = child;
}
handleAfterSideOfBlock(lastNormalFlowChild, beforeEdge, afterEdge, marginInfo);
}
MarginInfo::MarginInfo(RenderBlockFlow* blockFlow, LayoutUnit beforeBorderPadding, LayoutUnit afterBorderPadding)
: m_canCollapseMarginAfterWithLastChild(true)
, m_atBeforeSideOfBlock(true)
, m_atAfterSideOfBlock(false)
, m_hasMarginBeforeQuirk(false)
, m_hasMarginAfterQuirk(false)
, m_determinedMarginBeforeQuirk(false)
, m_discardMargin(false)
{
RenderStyle* blockStyle = blockFlow->style();
ASSERT(blockFlow->isRenderView() || blockFlow->parent());
m_canCollapseWithChildren = !blockFlow->createsBlockFormattingContext() && !blockFlow->isRenderFlowThread() && !blockFlow->isRenderView();
m_canCollapseMarginBeforeWithChildren = m_canCollapseWithChildren && !beforeBorderPadding && blockStyle->marginBeforeCollapse() != MSEPARATE;
m_canCollapseMarginAfterWithChildren = m_canCollapseWithChildren && !afterBorderPadding
&& (blockStyle->logicalHeight().isAuto() && !blockStyle->logicalHeight().value()) && blockStyle->marginAfterCollapse() != MSEPARATE;
m_quirkContainer = blockFlow->isTableCell() || blockFlow->isBody();
m_discardMargin = m_canCollapseMarginBeforeWithChildren && blockFlow->mustDiscardMarginBefore();
m_positiveMargin = (m_canCollapseMarginBeforeWithChildren && !blockFlow->mustDiscardMarginBefore()) ? blockFlow->maxPositiveMarginBefore() : LayoutUnit();
m_negativeMargin = (m_canCollapseMarginBeforeWithChildren && !blockFlow->mustDiscardMarginBefore()) ? blockFlow->maxNegativeMarginBefore() : LayoutUnit();
}
RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox* child) const
{
LayoutUnit childBeforePositive = 0;
LayoutUnit childBeforeNegative = 0;
LayoutUnit childAfterPositive = 0;
LayoutUnit childAfterNegative = 0;
LayoutUnit beforeMargin = 0;
LayoutUnit afterMargin = 0;
RenderBlockFlow* childRenderBlockFlow = child->isRenderBlockFlow() ? toRenderBlockFlow(child) : 0;
if (!child->isWritingModeRoot()) {
if (childRenderBlockFlow) {
childBeforePositive = childRenderBlockFlow->maxPositiveMarginBefore();
childBeforeNegative = childRenderBlockFlow->maxNegativeMarginBefore();
childAfterPositive = childRenderBlockFlow->maxPositiveMarginAfter();
childAfterNegative = childRenderBlockFlow->maxNegativeMarginAfter();
} else {
beforeMargin = child->marginBefore();
afterMargin = child->marginAfter();
}
} else if (child->isHorizontalWritingMode() == isHorizontalWritingMode()) {
if (childRenderBlockFlow) {
childBeforePositive = childRenderBlockFlow->maxPositiveMarginAfter();
childBeforeNegative = childRenderBlockFlow->maxNegativeMarginAfter();
childAfterPositive = childRenderBlockFlow->maxPositiveMarginBefore();
childAfterNegative = childRenderBlockFlow->maxNegativeMarginBefore();
} else {
beforeMargin = child->marginAfter();
afterMargin = child->marginBefore();
}
} else {
beforeMargin = marginBeforeForChild(child);
afterMargin = marginAfterForChild(child);
}
if (beforeMargin) {
if (beforeMargin > 0)
childBeforePositive = beforeMargin;
else
childBeforeNegative = -beforeMargin;
}
if (afterMargin) {
if (afterMargin > 0)
childAfterPositive = afterMargin;
else
childAfterNegative = -afterMargin;
}
return RenderBlockFlow::MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative);
}
LayoutUnit RenderBlockFlow::collapseMargins(RenderBox* child, MarginInfo& marginInfo, bool childIsSelfCollapsing)
{
bool childDiscardMarginBefore = mustDiscardMarginBeforeForChild(child);
bool childDiscardMarginAfter = mustDiscardMarginAfterForChild(child);
childDiscardMarginBefore = childDiscardMarginBefore || (childDiscardMarginAfter && childIsSelfCollapsing);
const RenderBlockFlow::MarginValues childMargins = marginValuesForChild(child);
LayoutUnit posTop = childMargins.positiveMarginBefore();
LayoutUnit negTop = childMargins.negativeMarginBefore();
if (childIsSelfCollapsing) {
posTop = max(posTop, childMargins.positiveMarginAfter());
negTop = max(negTop, childMargins.negativeMarginAfter());
}
bool topQuirk = hasMarginBeforeQuirk(child);
if (marginInfo.canCollapseWithMarginBefore()) {
if (!childDiscardMarginBefore && !marginInfo.discardMargin()) {
if (!document().inQuirksMode() || !marginInfo.quirkContainer() || !topQuirk)
setMaxMarginBeforeValues(max(posTop, maxPositiveMarginBefore()), max(negTop, maxNegativeMarginBefore()));
if (!marginInfo.determinedMarginBeforeQuirk() && !topQuirk && (posTop - negTop)) {
setHasMarginBeforeQuirk(false);
marginInfo.setDeterminedMarginBeforeQuirk(true);
}
if (!marginInfo.determinedMarginBeforeQuirk() && topQuirk && !marginBefore()) {
setHasMarginBeforeQuirk(true);
}
} else {
setMustDiscardMarginBefore();
}
}
if (childDiscardMarginBefore) {
marginInfo.setDiscardMargin(true);
marginInfo.clearMargin();
}
if (marginInfo.quirkContainer() && marginInfo.atBeforeSideOfBlock() && (posTop - negTop))
marginInfo.setHasMarginBeforeQuirk(topQuirk);
LayoutUnit beforeCollapseLogicalTop = logicalHeight();
LayoutUnit logicalTop = beforeCollapseLogicalTop;
LayoutUnit clearanceForSelfCollapsingBlock;
RenderObject* prev = child->previousSibling();
RenderBlockFlow* previousBlockFlow = prev && prev->isRenderBlockFlow() && !prev->isFloatingOrOutOfFlowPositioned() ? toRenderBlockFlow(prev) : 0;
if (!marginInfo.canCollapseWithMarginBefore() && previousBlockFlow && previousBlockFlow->isSelfCollapsingBlock()) {
clearanceForSelfCollapsingBlock = previousBlockFlow->marginOffsetForSelfCollapsingBlock();
setLogicalHeight(logicalHeight() - clearanceForSelfCollapsingBlock);
}
if (childIsSelfCollapsing) {
if (!childDiscardMarginBefore && !marginInfo.discardMargin()) {
LayoutUnit collapsedBeforePos = max(marginInfo.positiveMargin(), childMargins.positiveMarginBefore());
LayoutUnit collapsedBeforeNeg = max(marginInfo.negativeMargin(), childMargins.negativeMarginBefore());
marginInfo.setMargin(collapsedBeforePos, collapsedBeforeNeg);
marginInfo.setPositiveMarginIfLarger(childMargins.positiveMarginAfter());
marginInfo.setNegativeMarginIfLarger(childMargins.negativeMarginAfter());
if (!marginInfo.canCollapseWithMarginBefore()) {
logicalTop = logicalHeight() + collapsedBeforePos - collapsedBeforeNeg;
}
}
} else {
if (mustSeparateMarginBeforeForChild(child)) {
ASSERT(!marginInfo.discardMargin() || (marginInfo.discardMargin() && !marginInfo.margin()));
LayoutUnit separateMargin = !marginInfo.canCollapseWithMarginBefore() ? marginInfo.margin() : LayoutUnit(0);
setLogicalHeight(logicalHeight() + separateMargin + marginBeforeForChild(child));
logicalTop = logicalHeight();
} else if (!marginInfo.discardMargin() && (!marginInfo.atBeforeSideOfBlock()
|| (!marginInfo.canCollapseMarginBeforeWithChildren()
&& (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginBeforeQuirk())))) {
setLogicalHeight(logicalHeight() + max(marginInfo.positiveMargin(), posTop) - max(marginInfo.negativeMargin(), negTop));
logicalTop = logicalHeight();
}
marginInfo.setDiscardMargin(childDiscardMarginAfter);
if (!marginInfo.discardMargin()) {
marginInfo.setPositiveMargin(childMargins.positiveMarginAfter());
marginInfo.setNegativeMargin(childMargins.negativeMarginAfter());
} else {
marginInfo.clearMargin();
}
if (marginInfo.margin())
marginInfo.setHasMarginAfterQuirk(hasMarginAfterQuirk(child));
}
LayoutState* layoutState = view()->layoutState();
if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTop > beforeCollapseLogicalTop) {
LayoutUnit oldLogicalTop = logicalTop;
logicalTop = min(logicalTop, nextPageLogicalTop(beforeCollapseLogicalTop));
setLogicalHeight(logicalHeight() + (logicalTop - oldLogicalTop));
}
if (previousBlockFlow) {
LayoutUnit oldLogicalHeight = logicalHeight();
setLogicalHeight(logicalTop);
if (previousBlockFlow->containsFloats() && !previousBlockFlow->avoidsFloats() && (previousBlockFlow->logicalTop() + previousBlockFlow->lowestFloatLogicalBottom()) > logicalTop)
addOverhangingFloats(previousBlockFlow, false);
setLogicalHeight(oldLogicalHeight);
bool logicalTopIntrudesIntoFloat = clearanceForSelfCollapsingBlock > 0 && logicalTop < beforeCollapseLogicalTop;
if (logicalTopIntrudesIntoFloat && containsFloats() && !child->avoidsFloats() && lowestFloatLogicalBottom() > logicalTop)
child->setNeedsLayout();
}
return logicalTop;
}
void RenderBlockFlow::adjustPositionedBlock(RenderBox* child, const MarginInfo& marginInfo)
{
bool isHorizontal = isHorizontalWritingMode();
bool hasStaticBlockPosition = child->style()->hasStaticBlockPosition(isHorizontal);
LayoutUnit logicalTop = logicalHeight();
updateStaticInlinePositionForChild(child, logicalTop);
if (!marginInfo.canCollapseWithMarginBefore()) {
LayoutUnit collapsedBeforePos = marginInfo.positiveMargin();
LayoutUnit collapsedBeforeNeg = marginInfo.negativeMargin();
logicalTop += collapsedBeforePos - collapsedBeforeNeg;
}
RenderLayer* childLayer = child->layer();
if (childLayer->staticBlockPosition() != logicalTop) {
childLayer->setStaticBlockPosition(logicalTop);
if (hasStaticBlockPosition)
child->setChildNeedsLayout(MarkOnlyThis);
}
}
LayoutUnit RenderBlockFlow::computeStartPositionDeltaForChildAvoidingFloats(const RenderBox* child, LayoutUnit childMarginStart)
{
LayoutUnit startPosition = startOffsetForContent();
LayoutUnit oldPosition = startPosition + childMarginStart;
LayoutUnit newPosition = oldPosition;
LayoutUnit blockOffset = logicalTopForChild(child);
LayoutUnit startOff = startOffsetForLine(blockOffset, false, logicalHeightForChild(child));
if (style()->textAlign() != WEBKIT_CENTER && !child->style()->marginStartUsing(style()).isAuto()) {
if (childMarginStart < 0)
startOff += childMarginStart;
newPosition = max(newPosition, startOff);
} else if (startOff != startPosition) {
newPosition = startOff + childMarginStart;
}
return newPosition - oldPosition;
}
LayoutUnit RenderBlockFlow::clearFloatsIfNeeded(RenderBox* child, MarginInfo& marginInfo, LayoutUnit oldTopPosMargin, LayoutUnit oldTopNegMargin, LayoutUnit yPos, bool childIsSelfCollapsing)
{
LayoutUnit heightIncrease = getClearDelta(child, yPos);
if (!heightIncrease)
return yPos;
if (childIsSelfCollapsing) {
bool childDiscardMargin = mustDiscardMarginBeforeForChild(child) || mustDiscardMarginAfterForChild(child);
RenderBlockFlow::MarginValues childMargins = marginValuesForChild(child);
if (!childDiscardMargin) {
marginInfo.setPositiveMargin(max(childMargins.positiveMarginBefore(), childMargins.positiveMarginAfter()));
marginInfo.setNegativeMargin(max(childMargins.negativeMarginBefore(), childMargins.negativeMarginAfter()));
} else {
marginInfo.clearMargin();
}
marginInfo.setDiscardMargin(childDiscardMargin);
marginInfo.setCanCollapseMarginAfterWithLastChild(false);
setLogicalHeight(child->logicalTop() + childMargins.negativeMarginBefore());
} else {
setLogicalHeight(logicalHeight() + heightIncrease);
}
if (marginInfo.canCollapseWithMarginBefore()) {
setMaxMarginBeforeValues(oldTopPosMargin, oldTopNegMargin);
marginInfo.setAtBeforeSideOfBlock(false);
setMustDiscardMarginBefore(style()->marginBeforeCollapse() == MDISCARD);
}
return yPos + heightIncrease;
}
void RenderBlockFlow::setCollapsedBottomMargin(const MarginInfo& marginInfo)
{
if (marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()) {
if (marginInfo.discardMargin()) {
setMustDiscardMarginAfter();
return;
}
setMaxMarginAfterValues(max(maxPositiveMarginAfter(), marginInfo.positiveMargin()), max(maxNegativeMarginAfter(), marginInfo.negativeMargin()));
if (!marginInfo.hasMarginAfterQuirk())
setHasMarginAfterQuirk(false);
if (marginInfo.hasMarginAfterQuirk() && !marginAfter()) {
setHasMarginAfterQuirk(true);
}
}
}
void RenderBlockFlow::marginBeforeEstimateForChild(RenderBox* child, LayoutUnit& positiveMarginBefore, LayoutUnit& negativeMarginBefore, bool& discardMarginBefore) const
{
if ((document().inQuirksMode() && hasMarginBeforeQuirk(child) && (isTableCell() || isBody())) || child->style()->marginBeforeCollapse() == MSEPARATE)
return;
if (child->style()->marginBeforeCollapse() == MDISCARD) {
positiveMarginBefore = 0;
negativeMarginBefore = 0;
discardMarginBefore = true;
return;
}
LayoutUnit beforeChildMargin = marginBeforeForChild(child);
positiveMarginBefore = max(positiveMarginBefore, beforeChildMargin);
negativeMarginBefore = max(negativeMarginBefore, -beforeChildMargin);
if (!child->isRenderBlockFlow())
return;
RenderBlockFlow* childBlockFlow = toRenderBlockFlow(child);
if (childBlockFlow->childrenInline() || childBlockFlow->isWritingModeRoot())
return;
MarginInfo childMarginInfo(childBlockFlow, childBlockFlow->borderBefore() + childBlockFlow->paddingBefore(), childBlockFlow->borderAfter() + childBlockFlow->paddingAfter());
if (!childMarginInfo.canCollapseMarginBeforeWithChildren())
return;
RenderBox* grandchildBox = childBlockFlow->firstChildBox();
for ( ; grandchildBox; grandchildBox = grandchildBox->nextSiblingBox()) {
if (!grandchildBox->isFloatingOrOutOfFlowPositioned())
break;
}
if (!grandchildBox || grandchildBox->style()->clear() != CNONE)
return;
if (grandchildBox->needsLayout()) {
grandchildBox->computeAndSetBlockDirectionMargins(this);
if (grandchildBox->isRenderBlock()) {
RenderBlock* grandchildBlock = toRenderBlock(grandchildBox);
grandchildBlock->setHasMarginBeforeQuirk(grandchildBox->style()->hasMarginBeforeQuirk());
grandchildBlock->setHasMarginAfterQuirk(grandchildBox->style()->hasMarginAfterQuirk());
}
}
childBlockFlow->marginBeforeEstimateForChild(grandchildBox, positiveMarginBefore, negativeMarginBefore, discardMarginBefore);
}
LayoutUnit RenderBlockFlow::estimateLogicalTopPosition(RenderBox* child, const MarginInfo& marginInfo, LayoutUnit& estimateWithoutPagination)
{
LayoutUnit logicalTopEstimate = logicalHeight();
if (!marginInfo.canCollapseWithMarginBefore()) {
LayoutUnit positiveMarginBefore = 0;
LayoutUnit negativeMarginBefore = 0;
bool discardMarginBefore = false;
if (child->selfNeedsLayout()) {
marginBeforeEstimateForChild(child, positiveMarginBefore, negativeMarginBefore, discardMarginBefore);
} else {
RenderBlockFlow::MarginValues marginValues = marginValuesForChild(child);
positiveMarginBefore = max(positiveMarginBefore, marginValues.positiveMarginBefore());
negativeMarginBefore = max(negativeMarginBefore, marginValues.negativeMarginBefore());
discardMarginBefore = mustDiscardMarginBeforeForChild(child);
}
if (!discardMarginBefore)
logicalTopEstimate += max(marginInfo.positiveMargin(), positiveMarginBefore) - max(marginInfo.negativeMargin(), negativeMarginBefore);
}
LayoutState* layoutState = view()->layoutState();
if (layoutState->isPaginated() && layoutState->pageLogicalHeight() && logicalTopEstimate > logicalHeight())
logicalTopEstimate = min(logicalTopEstimate, nextPageLogicalTop(logicalHeight()));
logicalTopEstimate += getClearDelta(child, logicalTopEstimate);
estimateWithoutPagination = logicalTopEstimate;
if (layoutState->isPaginated()) {
logicalTopEstimate = applyBeforeBreak(child, logicalTopEstimate);
logicalTopEstimate = adjustForUnsplittableChild(child, logicalTopEstimate);
if (!child->selfNeedsLayout() && child->isRenderBlock())
logicalTopEstimate += toRenderBlock(child)->paginationStrut();
}
return logicalTopEstimate;
}
LayoutUnit RenderBlockFlow::marginOffsetForSelfCollapsingBlock()
{
ASSERT(isSelfCollapsingBlock());
RenderBlockFlow* parentBlock = toRenderBlockFlow(parent());
if (parentBlock && style()->clear() && parentBlock->getClearDelta(this, logicalHeight()))
return marginValuesForChild(this).positiveMarginBefore();
return LayoutUnit();
}
void RenderBlockFlow::adjustFloatingBlock(const MarginInfo& marginInfo)
{
LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin();
setLogicalHeight(logicalHeight() + marginOffset);
positionNewFloats();
setLogicalHeight(logicalHeight() - marginOffset);
}
void RenderBlockFlow::handleAfterSideOfBlock(RenderBox* lastChild, LayoutUnit beforeSide, LayoutUnit afterSide, MarginInfo& marginInfo)
{
marginInfo.setAtAfterSideOfBlock(true);
if (lastChild && lastChild->isRenderBlockFlow() && lastChild->isSelfCollapsingBlock())
setLogicalHeight(logicalHeight() - toRenderBlockFlow(lastChild)->marginOffsetForSelfCollapsingBlock());
if (marginInfo.canCollapseMarginAfterWithChildren() && !marginInfo.canCollapseMarginAfterWithLastChild())
marginInfo.setCanCollapseMarginAfterWithChildren(false);
if (!marginInfo.discardMargin() && (!marginInfo.canCollapseWithMarginAfter() && !marginInfo.canCollapseWithMarginBefore()
&& (!document().inQuirksMode() || !marginInfo.quirkContainer() || !marginInfo.hasMarginAfterQuirk())))
setLogicalHeight(logicalHeight() + marginInfo.margin());
setLogicalHeight(logicalHeight() + afterSide);
setLogicalHeight(max(logicalHeight(), beforeSide + afterSide));
setCollapsedBottomMargin(marginInfo);
}
void RenderBlockFlow::setMustDiscardMarginBefore(bool value)
{
if (style()->marginBeforeCollapse() == MDISCARD) {
ASSERT(value);
return;
}
if (!m_rareData && !value)
return;
if (!m_rareData)
m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
m_rareData->m_discardMarginBefore = value;
}
void RenderBlockFlow::setMustDiscardMarginAfter(bool value)
{
if (style()->marginAfterCollapse() == MDISCARD) {
ASSERT(value);
return;
}
if (!m_rareData && !value)
return;
if (!m_rareData)
m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
m_rareData->m_discardMarginAfter = value;
}
bool RenderBlockFlow::mustDiscardMarginBefore() const
{
return style()->marginBeforeCollapse() == MDISCARD || (m_rareData && m_rareData->m_discardMarginBefore);
}
bool RenderBlockFlow::mustDiscardMarginAfter() const
{
return style()->marginAfterCollapse() == MDISCARD || (m_rareData && m_rareData->m_discardMarginAfter);
}
bool RenderBlockFlow::mustDiscardMarginBeforeForChild(const RenderBox* child) const
{
ASSERT(!child->selfNeedsLayout());
if (!child->isWritingModeRoot())
return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginBefore() : (child->style()->marginBeforeCollapse() == MDISCARD);
if (child->isHorizontalWritingMode() == isHorizontalWritingMode())
return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginAfter() : (child->style()->marginAfterCollapse() == MDISCARD);
return false;
}
bool RenderBlockFlow::mustDiscardMarginAfterForChild(const RenderBox* child) const
{
ASSERT(!child->selfNeedsLayout());
if (!child->isWritingModeRoot())
return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginAfter() : (child->style()->marginAfterCollapse() == MDISCARD);
if (child->isHorizontalWritingMode() == isHorizontalWritingMode())
return child->isRenderBlockFlow() ? toRenderBlockFlow(child)->mustDiscardMarginBefore() : (child->style()->marginBeforeCollapse() == MDISCARD);
return false;
}
void RenderBlockFlow::setMaxMarginBeforeValues(LayoutUnit pos, LayoutUnit neg)
{
if (!m_rareData) {
if (pos == RenderBlockFlowRareData::positiveMarginBeforeDefault(this) && neg == RenderBlockFlowRareData::negativeMarginBeforeDefault(this))
return;
m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
}
m_rareData->m_margins.setPositiveMarginBefore(pos);
m_rareData->m_margins.setNegativeMarginBefore(neg);
}
void RenderBlockFlow::setMaxMarginAfterValues(LayoutUnit pos, LayoutUnit neg)
{
if (!m_rareData) {
if (pos == RenderBlockFlowRareData::positiveMarginAfterDefault(this) && neg == RenderBlockFlowRareData::negativeMarginAfterDefault(this))
return;
m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
}
m_rareData->m_margins.setPositiveMarginAfter(pos);
m_rareData->m_margins.setNegativeMarginAfter(neg);
}
bool RenderBlockFlow::mustSeparateMarginBeforeForChild(const RenderBox* child) const
{
ASSERT(!child->selfNeedsLayout());
const RenderStyle* childStyle = child->style();
if (!child->isWritingModeRoot())
return childStyle->marginBeforeCollapse() == MSEPARATE;
if (child->isHorizontalWritingMode() == isHorizontalWritingMode())
return childStyle->marginAfterCollapse() == MSEPARATE;
return false;
}
bool RenderBlockFlow::mustSeparateMarginAfterForChild(const RenderBox* child) const
{
ASSERT(!child->selfNeedsLayout());
const RenderStyle* childStyle = child->style();
if (!child->isWritingModeRoot())
return childStyle->marginAfterCollapse() == MSEPARATE;
if (child->isHorizontalWritingMode() == isHorizontalWritingMode())
return childStyle->marginBeforeCollapse() == MSEPARATE;
return false;
}
LayoutUnit RenderBlockFlow::applyBeforeBreak(RenderBox* child, LayoutUnit logicalOffset)
{
RenderFlowThread* flowThread = flowThreadContainingBlock();
bool isInsideMulticolFlowThread = flowThread;
bool checkColumnBreaks = isInsideMulticolFlowThread || view()->layoutState()->isPaginatingColumns();
bool checkPageBreaks = !checkColumnBreaks && view()->layoutState()->pageLogicalHeight();
bool checkBeforeAlways = (checkColumnBreaks && child->style()->columnBreakBefore() == PBALWAYS)
|| (checkPageBreaks && child->style()->pageBreakBefore() == PBALWAYS);
if (checkBeforeAlways && inNormalFlow(child)) {
if (checkColumnBreaks) {
if (isInsideMulticolFlowThread) {
LayoutUnit offsetBreakAdjustment = 0;
if (flowThread->addForcedRegionBreak(offsetFromLogicalTopOfFirstPage() + logicalOffset, child, true, &offsetBreakAdjustment))
return logicalOffset + offsetBreakAdjustment;
} else {
view()->layoutState()->addForcedColumnBreak(*child, logicalOffset);
}
}
return nextPageLogicalTop(logicalOffset, IncludePageBoundary);
}
return logicalOffset;
}
LayoutUnit RenderBlockFlow::applyAfterBreak(RenderBox* child, LayoutUnit logicalOffset, MarginInfo& marginInfo)
{
RenderFlowThread* flowThread = flowThreadContainingBlock();
bool isInsideMulticolFlowThread = flowThread;
bool checkColumnBreaks = isInsideMulticolFlowThread || view()->layoutState()->isPaginatingColumns();
bool checkPageBreaks = !checkColumnBreaks && view()->layoutState()->pageLogicalHeight();
bool checkAfterAlways = (checkColumnBreaks && child->style()->columnBreakAfter() == PBALWAYS)
|| (checkPageBreaks && child->style()->pageBreakAfter() == PBALWAYS);
if (checkAfterAlways && inNormalFlow(child)) {
LayoutUnit marginOffset = marginInfo.canCollapseWithMarginBefore() ? LayoutUnit() : marginInfo.margin();
marginInfo.clearMargin();
if (checkColumnBreaks) {
if (isInsideMulticolFlowThread) {
LayoutUnit offsetBreakAdjustment = 0;
if (flowThread->addForcedRegionBreak(offsetFromLogicalTopOfFirstPage() + logicalOffset + marginOffset, child, false, &offsetBreakAdjustment))
return logicalOffset + marginOffset + offsetBreakAdjustment;
} else {
view()->layoutState()->addForcedColumnBreak(*child, logicalOffset);
}
}
return nextPageLogicalTop(logicalOffset, IncludePageBoundary);
}
return logicalOffset;
}
void RenderBlockFlow::addOverflowFromFloats()
{
if (!m_floatingObjects)
return;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (floatingObject->isDescendant())
addOverflowFromChild(floatingObject->renderer(), IntSize(xPositionForFloatIncludingMargin(floatingObject), yPositionForFloatIncludingMargin(floatingObject)));
}
}
void RenderBlockFlow::computeOverflow(LayoutUnit oldClientAfterEdge, bool recomputeFloats)
{
RenderBlock::computeOverflow(oldClientAfterEdge, recomputeFloats);
if (!hasColumns() && (recomputeFloats || createsBlockFormattingContext() || hasSelfPaintingLayer()))
addOverflowFromFloats();
}
RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
{
RootInlineBox* rootBox = createRootInlineBox();
m_lineBoxes.appendLineBox(rootBox);
if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && m_lineBoxes.firstLineBox() == rootBox) {
if (AXObjectCache* cache = document().existingAXObjectCache())
cache->recomputeIsIgnored(this);
}
return rootBox;
}
void RenderBlockFlow::deleteLineBoxTree()
{
if (containsFloats())
m_floatingObjects->clearLineBoxTreePointers();
RenderBlock::deleteLineBoxTree();
}
void RenderBlockFlow::markAllDescendantsWithFloatsForLayout(RenderBox* floatToRemove, bool inLayout)
{
if (!everHadLayout() && !containsFloats())
return;
MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain;
setChildNeedsLayout(markParents);
if (floatToRemove)
removeFloatingObject(floatToRemove);
if (!childrenInline()) {
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
if ((!floatToRemove && child->isFloatingOrOutOfFlowPositioned()) || !child->isRenderBlock())
continue;
if (!child->isRenderBlockFlow()) {
RenderBlock* childBlock = toRenderBlock(child);
if (childBlock->shrinkToAvoidFloats() && childBlock->everHadLayout())
childBlock->setChildNeedsLayout(markParents);
continue;
}
RenderBlockFlow* childBlockFlow = toRenderBlockFlow(child);
if ((floatToRemove ? childBlockFlow->containsFloat(floatToRemove) : childBlockFlow->containsFloats()) || childBlockFlow->shrinkToAvoidFloats())
childBlockFlow->markAllDescendantsWithFloatsForLayout(floatToRemove, inLayout);
}
}
}
void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove)
{
if (!m_floatingObjects)
return;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) {
if (!next->isRenderBlockFlow() || next->isFloatingOrOutOfFlowPositioned() || toRenderBlock(next)->avoidsFloats())
continue;
RenderBlockFlow* nextBlock = toRenderBlockFlow(next);
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
RenderBox* floatingBox = (*it)->renderer();
if (floatToRemove && floatingBox != floatToRemove)
continue;
if (nextBlock->containsFloat(floatingBox))
nextBlock->markAllDescendantsWithFloatsForLayout(floatingBox);
}
}
}
LayoutUnit RenderBlockFlow::getClearDelta(RenderBox* child, LayoutUnit logicalTop)
{
if (!containsFloats())
return 0;
bool clearSet = child->style()->clear() != CNONE;
LayoutUnit logicalBottom = 0;
switch (child->style()->clear()) {
case CNONE:
break;
case CLEFT:
logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatLeft);
break;
case CRIGHT:
logicalBottom = lowestFloatLogicalBottom(FloatingObject::FloatRight);
break;
case CBOTH:
logicalBottom = lowestFloatLogicalBottom();
break;
}
LayoutUnit result = clearSet ? max<LayoutUnit>(0, logicalBottom - logicalTop) : LayoutUnit();
if (!result && child->avoidsFloats()) {
LayoutUnit newLogicalTop = logicalTop;
while (true) {
LayoutUnit availableLogicalWidthAtNewLogicalTopOffset = availableLogicalWidthForLine(newLogicalTop, false, logicalHeightForChild(child));
if (availableLogicalWidthAtNewLogicalTopOffset == availableLogicalWidthForContent())
return newLogicalTop - logicalTop;
LayoutRect borderBox = child->borderBoxRect();
LayoutUnit childLogicalWidthAtOldLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height();
LayoutUnit childOldLogicalWidth = child->logicalWidth();
LayoutUnit childOldMarginLeft = child->marginLeft();
LayoutUnit childOldMarginRight = child->marginRight();
LayoutUnit childOldLogicalTop = child->logicalTop();
child->setLogicalTop(newLogicalTop);
child->updateLogicalWidth();
borderBox = child->borderBoxRect();
LayoutUnit childLogicalWidthAtNewLogicalTopOffset = isHorizontalWritingMode() ? borderBox.width() : borderBox.height();
child->setLogicalTop(childOldLogicalTop);
child->setLogicalWidth(childOldLogicalWidth);
child->setMarginLeft(childOldMarginLeft);
child->setMarginRight(childOldMarginRight);
if (childLogicalWidthAtNewLogicalTopOffset <= availableLogicalWidthAtNewLogicalTopOffset) {
if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset)
child->setChildNeedsLayout(MarkOnlyThis);
return newLogicalTop - logicalTop;
}
newLogicalTop = nextFloatLogicalBottomBelow(newLogicalTop);
ASSERT(newLogicalTop >= logicalTop);
if (newLogicalTop < logicalTop)
break;
}
ASSERT_NOT_REACHED();
}
return result;
}
void RenderBlockFlow::createFloatingObjects()
{
m_floatingObjects = adoptPtr(new FloatingObjects(this, isHorizontalWritingMode()));
}
void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
{
RenderStyle* oldStyle = style();
s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned() && !avoidsFloats() : false;
if (oldStyle && parent() && diff == StyleDifferenceLayout && oldStyle->position() != newStyle.position()
&& containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlowPosition())
markAllDescendantsWithFloatsForLayout();
RenderBlock::styleWillChange(diff, newStyle);
}
void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBlock::styleDidChange(diff, oldStyle);
bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !avoidsFloats();
if (diff == StyleDifferenceLayout && s_canPropagateFloatIntoSibling && !canPropagateFloatIntoSibling && hasOverhangingFloats()) {
RenderBlockFlow* parentBlockFlow = this;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (RenderObject* curr = parent(); curr && !curr->isRenderView(); curr = curr->parent()) {
if (curr->isRenderBlockFlow()) {
RenderBlockFlow* currBlock = toRenderBlockFlow(curr);
if (currBlock->hasOverhangingFloats()) {
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
RenderBox* renderer = (*it)->renderer();
if (currBlock->hasOverhangingFloat(renderer)) {
parentBlockFlow = currBlock;
break;
}
}
}
}
}
parentBlockFlow->markAllDescendantsWithFloatsForLayout();
parentBlockFlow->markSiblingsWithFloatsForLayout();
}
createMultiColumnFlowThreadIfNeeded();
}
void RenderBlockFlow::updateStaticInlinePositionForChild(RenderBox* child, LayoutUnit logicalTop)
{
if (child->style()->isOriginalDisplayInlineType())
setStaticInlinePositionForChild(child, logicalTop, startAlignedOffsetForLine(logicalTop, false));
else
setStaticInlinePositionForChild(child, logicalTop, startOffsetForContent());
}
void RenderBlockFlow::setStaticInlinePositionForChild(RenderBox* child, LayoutUnit blockOffset, LayoutUnit inlinePosition)
{
child->layer()->setStaticInlinePosition(inlinePosition);
}
void RenderBlockFlow::addChild(RenderObject* newChild, RenderObject* beforeChild)
{
if (RenderMultiColumnFlowThread* flowThread = multiColumnFlowThread())
return flowThread->addChild(newChild, beforeChild);
RenderBlock::addChild(newChild, beforeChild);
}
void RenderBlockFlow::moveAllChildrenIncludingFloatsTo(RenderBlock* toBlock, bool fullRemoveInsert)
{
RenderBlockFlow* toBlockFlow = toRenderBlockFlow(toBlock);
moveAllChildrenTo(toBlockFlow, fullRemoveInsert);
if (m_floatingObjects) {
if (!toBlockFlow->m_floatingObjects)
toBlockFlow->createFloatingObjects();
const FloatingObjectSet& fromFloatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = fromFloatingObjectSet.end();
for (FloatingObjectSetIterator it = fromFloatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (toBlockFlow->containsFloat(floatingObject->renderer()))
continue;
toBlockFlow->m_floatingObjects->add(floatingObject->unsafeClone());
}
}
}
void RenderBlockFlow::repaintOverhangingFloats(bool paintAllDescendants)
{
if (!hasOverhangingFloats())
return;
LayoutStateDisabler layoutStateDisabler(*this);
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (logicalBottomForFloat(floatingObject) > logicalHeight()
&& !floatingObject->renderer()->hasSelfPaintingLayer()
&& (floatingObject->shouldPaint() || (paintAllDescendants && floatingObject->renderer()->isDescendantOf(this)))) {
RenderBox* floatingRenderer = floatingObject->renderer();
LayoutRectRecorder recorder(*floatingRenderer);
if (RuntimeEnabledFeatures::repaintAfterLayoutEnabled())
floatingRenderer->setShouldDoFullRepaintAfterLayout(true);
else
floatingRenderer->repaint();
floatingRenderer->repaintOverhangingFloats(false);
}
}
}
void RenderBlockFlow::repaintOverflow()
{
LayoutUnit repaintLogicalLeft = logicalLeftVisualOverflow();
LayoutUnit repaintLogicalRight = logicalRightVisualOverflow();
if (hasOverflowClip()) {
repaintLogicalLeft = min(repaintLogicalLeft, logicalLeftLayoutOverflow());
repaintLogicalRight = max(repaintLogicalRight, logicalRightLayoutOverflow());
}
LayoutRect repaintRect;
if (isHorizontalWritingMode())
repaintRect = LayoutRect(repaintLogicalLeft, m_repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft, m_repaintLogicalBottom - m_repaintLogicalTop);
else
repaintRect = LayoutRect(m_repaintLogicalTop, repaintLogicalLeft, m_repaintLogicalBottom - m_repaintLogicalTop, repaintLogicalRight - repaintLogicalLeft);
adjustRectForColumns(repaintRect);
if (hasOverflowClip()) {
repaintRect.move(-scrolledContentOffset());
repaintRect.intersect(LayoutRect(LayoutPoint(), size()));
}
if (!repaintRect.isEmpty()) {
DisableCompositingQueryAsserts disabler;
repaintRectangle(repaintRect);
if (hasReflection())
repaintRectangle(reflectedRect(repaintRect));
}
m_repaintLogicalTop = 0;
m_repaintLogicalBottom = 0;
}
void RenderBlockFlow::paintFloats(PaintInfo& paintInfo, const LayoutPoint& paintOffset, bool preservePhase)
{
if (!m_floatingObjects)
return;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer()) {
PaintInfo currentPaintInfo(paintInfo);
currentPaintInfo.phase = preservePhase ? paintInfo.phase : PaintPhaseBlockBackground;
LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, LayoutPoint(paintOffset.x() + xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x(), paintOffset.y() + yPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->y()));
floatingObject->renderer()->paint(currentPaintInfo, childPoint);
if (!preservePhase) {
currentPaintInfo.phase = PaintPhaseChildBlockBackgrounds;
floatingObject->renderer()->paint(currentPaintInfo, childPoint);
currentPaintInfo.phase = PaintPhaseFloat;
floatingObject->renderer()->paint(currentPaintInfo, childPoint);
currentPaintInfo.phase = PaintPhaseForeground;
floatingObject->renderer()->paint(currentPaintInfo, childPoint);
currentPaintInfo.phase = PaintPhaseOutline;
floatingObject->renderer()->paint(currentPaintInfo, childPoint);
}
}
}
}
void RenderBlockFlow::clipOutFloatingObjects(RenderBlock* rootBlock, const PaintInfo* paintInfo, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock)
{
if (m_floatingObjects) {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
LayoutRect floatBox(offsetFromRootBlock.width() + xPositionForFloatIncludingMargin(floatingObject),
offsetFromRootBlock.height() + yPositionForFloatIncludingMargin(floatingObject),
floatingObject->renderer()->width(), floatingObject->renderer()->height());
rootBlock->flipForWritingMode(floatBox);
floatBox.move(rootBlockPhysicalPosition.x(), rootBlockPhysicalPosition.y());
paintInfo->context->clipOut(pixelSnappedIntRect(floatBox));
}
}
}
void RenderBlockFlow::clearFloats(EClear clear)
{
positionNewFloats();
LayoutUnit newY = 0;
switch (clear) {
case CLEFT:
newY = lowestFloatLogicalBottom(FloatingObject::FloatLeft);
break;
case CRIGHT:
newY = lowestFloatLogicalBottom(FloatingObject::FloatRight);
break;
case CBOTH:
newY = lowestFloatLogicalBottom();
default:
break;
}
if (height() < newY)
setLogicalHeight(newY);
}
bool RenderBlockFlow::containsFloat(RenderBox* renderer) const
{
return m_floatingObjects && m_floatingObjects->set().contains<FloatingObjectHashTranslator>(renderer);
}
void RenderBlockFlow::removeFloatingObjects()
{
if (!m_floatingObjects)
return;
markSiblingsWithFloatsForLayout();
m_floatingObjects->clear();
}
LayoutPoint RenderBlockFlow::flipFloatForWritingModeForChild(const FloatingObject* child, const LayoutPoint& point) const
{
if (!style()->isFlippedBlocksWritingMode())
return point;
if (isHorizontalWritingMode())
return LayoutPoint(point.x(), point.y() + height() - child->renderer()->height() - 2 * yPositionForFloatIncludingMargin(child));
return LayoutPoint(point.x() + width() - child->renderer()->width() - 2 * xPositionForFloatIncludingMargin(child), point.y());
}
LayoutUnit RenderBlockFlow::logicalLeftOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const
{
LayoutUnit offset = fixedOffset;
if (m_floatingObjects && m_floatingObjects->hasLeftObjects())
offset = m_floatingObjects->logicalLeftOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining);
return adjustLogicalLeftOffsetForLine(offset, applyTextIndent);
}
LayoutUnit RenderBlockFlow::logicalRightOffsetForPositioningFloat(LayoutUnit logicalTop, LayoutUnit fixedOffset, bool applyTextIndent, LayoutUnit* heightRemaining) const
{
LayoutUnit offset = fixedOffset;
if (m_floatingObjects && m_floatingObjects->hasRightObjects())
offset = m_floatingObjects->logicalRightOffsetForPositioningFloat(fixedOffset, logicalTop, heightRemaining);
return adjustLogicalRightOffsetForLine(offset, applyTextIndent);
}
LayoutUnit RenderBlockFlow::adjustLogicalLeftOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const
{
LayoutUnit left = offsetFromFloats;
if (applyTextIndent && style()->isLeftToRightDirection())
left += textIndentOffset();
return left;
}
LayoutUnit RenderBlockFlow::adjustLogicalRightOffsetForLine(LayoutUnit offsetFromFloats, bool applyTextIndent) const
{
LayoutUnit right = offsetFromFloats;
if (applyTextIndent && !style()->isLeftToRightDirection())
right -= textIndentOffset();
return right;
}
LayoutPoint RenderBlockFlow::computeLogicalLocationForFloat(const FloatingObject* floatingObject, LayoutUnit logicalTopOffset) const
{
RenderBox* childBox = floatingObject->renderer();
LayoutUnit logicalLeftOffset = logicalLeftOffsetForContent();
LayoutUnit logicalRightOffset;
logicalRightOffset = logicalRightOffsetForContent();
LayoutUnit floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset);
LayoutUnit floatLogicalLeft;
bool insideFlowThread = flowThreadContainingBlock();
if (childBox->style()->floating() == LeftFloat) {
LayoutUnit heightRemainingLeft = 1;
LayoutUnit heightRemainingRight = 1;
floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft);
while (logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight) - floatLogicalLeft < floatLogicalWidth) {
logicalTopOffset += min(heightRemainingLeft, heightRemainingRight);
floatLogicalLeft = logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft);
if (insideFlowThread) {
logicalRightOffset = logicalRightOffsetForContent();
logicalLeftOffset = logicalLeftOffsetForContent();
floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset);
}
}
floatLogicalLeft = max(logicalLeftOffset - borderAndPaddingLogicalLeft(), floatLogicalLeft);
} else {
LayoutUnit heightRemainingLeft = 1;
LayoutUnit heightRemainingRight = 1;
floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight);
while (floatLogicalLeft - logicalLeftOffsetForPositioningFloat(logicalTopOffset, logicalLeftOffset, false, &heightRemainingLeft) < floatLogicalWidth) {
logicalTopOffset += min(heightRemainingLeft, heightRemainingRight);
floatLogicalLeft = logicalRightOffsetForPositioningFloat(logicalTopOffset, logicalRightOffset, false, &heightRemainingRight);
if (insideFlowThread) {
logicalRightOffset = logicalRightOffsetForContent();
logicalLeftOffset = logicalLeftOffsetForContent();
floatLogicalWidth = min(logicalWidthForFloat(floatingObject), logicalRightOffset - logicalLeftOffset);
}
}
floatLogicalLeft -= logicalWidthForFloat(floatingObject);
}
return LayoutPoint(floatLogicalLeft, logicalTopOffset);
}
FloatingObject* RenderBlockFlow::insertFloatingObject(RenderBox* floatBox)
{
ASSERT(floatBox->isFloating());
if (!m_floatingObjects) {
createFloatingObjects();
} else {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox);
if (it != floatingObjectSet.end())
return *it;
}
OwnPtr<FloatingObject> newObj = FloatingObject::create(floatBox);
bool isChildRenderBlock = floatBox->isRenderBlock();
if (isChildRenderBlock && !floatBox->needsLayout() && view()->layoutState()->pageLogicalHeightChanged())
floatBox->setChildNeedsLayout(MarkOnlyThis);
bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view()->layoutState()->needsBlockDirectionLocationSetBeforeLayout();
if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) {
floatBox->layoutIfNeeded();
} else {
floatBox->updateLogicalWidth();
floatBox->computeAndSetBlockDirectionMargins(this);
}
setLogicalWidthForFloat(newObj.get(), logicalWidthForChild(floatBox) + marginStartForChild(floatBox) + marginEndForChild(floatBox));
return m_floatingObjects->add(newObj.release());
}
void RenderBlockFlow::removeFloatingObject(RenderBox* floatBox)
{
if (m_floatingObjects) {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(floatBox);
if (it != floatingObjectSet.end()) {
FloatingObject* floatingObject = *it;
if (childrenInline()) {
LayoutUnit logicalTop = logicalTopForFloat(floatingObject);
LayoutUnit logicalBottom = logicalBottomForFloat(floatingObject);
if (logicalBottom < 0 || logicalBottom < logicalTop || logicalTop == LayoutUnit::max()) {
logicalBottom = LayoutUnit::max();
} else {
logicalBottom = max(logicalBottom, logicalTop + 1);
}
if (floatingObject->originatingLine()) {
if (!selfNeedsLayout()) {
ASSERT(floatingObject->originatingLine()->renderer() == this);
floatingObject->originatingLine()->markDirty();
}
#if !ASSERT_DISABLED
floatingObject->setOriginatingLine(0);
#endif
}
markLinesDirtyInBlockRange(0, logicalBottom);
}
m_floatingObjects->remove(floatingObject);
}
}
}
void RenderBlockFlow::removeFloatingObjectsBelow(FloatingObject* lastFloat, int logicalOffset)
{
if (!containsFloats())
return;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObject* curr = floatingObjectSet.last();
while (curr != lastFloat && (!curr->isPlaced() || logicalTopForFloat(curr) >= logicalOffset)) {
m_floatingObjects->remove(curr);
if (floatingObjectSet.isEmpty())
break;
curr = floatingObjectSet.last();
}
}
bool RenderBlockFlow::positionNewFloats()
{
if (!m_floatingObjects)
return false;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
if (floatingObjectSet.isEmpty())
return false;
if (floatingObjectSet.last()->isPlaced())
return false;
FloatingObjectSetIterator it = floatingObjectSet.end();
--it;
FloatingObjectSetIterator begin = floatingObjectSet.begin();
FloatingObject* lastPlacedFloatingObject = 0;
while (it != begin) {
--it;
if ((*it)->isPlaced()) {
lastPlacedFloatingObject = *it;
++it;
break;
}
}
LayoutUnit logicalTop = logicalHeight();
if (lastPlacedFloatingObject)
logicalTop = max(logicalTopForFloat(lastPlacedFloatingObject), logicalTop);
FloatingObjectSetIterator end = floatingObjectSet.end();
for (; it != end; ++it) {
FloatingObject* floatingObject = *it;
if (floatingObject->renderer()->containingBlock() != this)
continue;
RenderBox* childBox = floatingObject->renderer();
LayoutRectRecorder childBoxRecorder(*childBox);
LayoutUnit childLogicalLeftMargin = style()->isLeftToRightDirection() ? marginStartForChild(childBox) : marginEndForChild(childBox);
LayoutRect oldRect = childBox->frameRect();
if (childBox->style()->clear() & CLEFT)
logicalTop = max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), logicalTop);
if (childBox->style()->clear() & CRIGHT)
logicalTop = max(lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop);
LayoutPoint floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, logicalTop);
setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x());
setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin);
setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox));
SubtreeLayoutScope layoutScope(childBox);
LayoutState* layoutState = view()->layoutState();
bool isPaginated = layoutState->isPaginated();
if (isPaginated && !childBox->needsLayout())
childBox->markForPaginationRelayoutIfNeeded(layoutScope);
childBox->layoutIfNeeded();
if (isPaginated) {
LayoutUnit newLogicalTop = adjustForUnsplittableChild(childBox, floatLogicalLocation.y(), true);
RenderBlock* childBlock = childBox->isRenderBlock() ? toRenderBlock(childBox) : 0;
if (childBlock && childBlock->paginationStrut()) {
newLogicalTop += childBlock->paginationStrut();
childBlock->setPaginationStrut(0);
}
if (newLogicalTop != floatLogicalLocation.y()) {
floatingObject->setPaginationStrut(newLogicalTop - floatLogicalLocation.y());
floatLogicalLocation = computeLogicalLocationForFloat(floatingObject, newLogicalTop);
setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x());
setLogicalLeftForChild(childBox, floatLogicalLocation.x() + childLogicalLeftMargin);
setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox));
if (childBlock)
childBlock->setChildNeedsLayout(MarkOnlyThis);
childBox->layoutIfNeeded();
}
}
setLogicalTopForFloat(floatingObject, floatLogicalLocation.y());
setLogicalHeightForFloat(floatingObject, logicalHeightForChild(childBox) + marginBeforeForChild(childBox) + marginAfterForChild(childBox));
m_floatingObjects->addPlacedObject(floatingObject);
if (ShapeOutsideInfo* shapeOutside = childBox->shapeOutsideInfo())
shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(childBox));
if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()
&& childBox->checkForRepaintDuringLayout())
childBox->repaintDuringLayoutIfMoved(oldRect);
}
return true;
}
bool RenderBlockFlow::hasOverhangingFloat(RenderBox* renderer)
{
if (!m_floatingObjects || hasColumns() || !parent())
return false;
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator it = floatingObjectSet.find<FloatingObjectHashTranslator>(renderer);
if (it == floatingObjectSet.end())
return false;
return logicalBottomForFloat(*it) > logicalHeight();
}
void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset)
{
ASSERT(!avoidsFloats());
if (!prev->m_floatingObjects)
return;
logicalLeftOffset += marginLogicalLeft();
const FloatingObjectSet& prevSet = prev->m_floatingObjects->set();
FloatingObjectSetIterator prevEnd = prevSet.end();
for (FloatingObjectSetIterator prevIt = prevSet.begin(); prevIt != prevEnd; ++prevIt) {
FloatingObject* floatingObject = *prevIt;
if (logicalBottomForFloat(floatingObject) > logicalTopOffset) {
if (!m_floatingObjects || !m_floatingObjects->set().contains(floatingObject)) {
if (!m_floatingObjects)
createFloatingObjects();
LayoutSize offset = isHorizontalWritingMode()
? LayoutSize(logicalLeftOffset - (prev != parent() ? prev->marginLeft() : LayoutUnit()), logicalTopOffset)
: LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != parent() ? prev->marginTop() : LayoutUnit()));
m_floatingObjects->add(floatingObject->copyToNewContainer(offset));
}
}
}
}
LayoutUnit RenderBlockFlow::addOverhangingFloats(RenderBlockFlow* child, bool makeChildPaintOtherFloats)
{
if (child->hasOverflowClip() || !child->containsFloats() || child->isRoot() || child->hasColumns() || child->isWritingModeRoot())
return 0;
LayoutUnit childLogicalTop = child->logicalTop();
LayoutUnit childLogicalLeft = child->logicalLeft();
LayoutUnit lowestFloatLogicalBottom = 0;
FloatingObjectSetIterator childEnd = child->m_floatingObjects->set().end();
for (FloatingObjectSetIterator childIt = child->m_floatingObjects->set().begin(); childIt != childEnd; ++childIt) {
FloatingObject* floatingObject = *childIt;
LayoutUnit logicalBottomForFloat = min(this->logicalBottomForFloat(floatingObject), LayoutUnit::max() - childLogicalTop);
LayoutUnit logicalBottom = childLogicalTop + logicalBottomForFloat;
lowestFloatLogicalBottom = max(lowestFloatLogicalBottom, logicalBottom);
if (logicalBottom > logicalHeight()) {
if (!containsFloat(floatingObject->renderer())) {
LayoutSize offset = isHorizontalWritingMode() ? LayoutSize(-childLogicalLeft, -childLogicalTop) : LayoutSize(-childLogicalTop, -childLogicalLeft);
bool shouldPaint = false;
if (floatingObject->renderer()->enclosingFloatPaintingLayer() == enclosingFloatPaintingLayer()) {
floatingObject->setShouldPaint(false);
shouldPaint = true;
}
if (!m_floatingObjects)
createFloatingObjects();
m_floatingObjects->add(floatingObject->copyToNewContainer(offset, shouldPaint, true));
}
} else {
if (makeChildPaintOtherFloats && !floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer()
&& floatingObject->renderer()->isDescendantOf(child) && floatingObject->renderer()->enclosingFloatPaintingLayer() == child->enclosingFloatPaintingLayer()) {
floatingObject->setShouldPaint(true);
}
if (floatingObject->isDescendant())
child->addOverflowFromChild(floatingObject->renderer(), LayoutSize(xPositionForFloatIncludingMargin(floatingObject), yPositionForFloatIncludingMargin(floatingObject)));
}
}
return lowestFloatLogicalBottom;
}
LayoutUnit RenderBlockFlow::lowestFloatLogicalBottom(FloatingObject::Type floatType) const
{
if (!m_floatingObjects)
return 0;
return m_floatingObjects->lowestFloatLogicalBottom(floatType);
}
LayoutUnit RenderBlockFlow::nextFloatLogicalBottomBelow(LayoutUnit logicalHeight, ShapeOutsideFloatOffsetMode offsetMode) const
{
if (!m_floatingObjects)
return logicalHeight;
LayoutUnit logicalBottom = LayoutUnit::max();
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
LayoutUnit floatLogicalBottom = logicalBottomForFloat(floatingObject);
ShapeOutsideInfo* shapeOutside = floatingObject->renderer()->shapeOutsideInfo();
if (shapeOutside && (offsetMode == ShapeOutsideFloatShapeOffset)) {
LayoutUnit shapeLogicalBottom = logicalTopForFloat(floatingObject) + marginBeforeForChild(floatingObject->renderer()) + shapeOutside->shapeLogicalBottom();
if (shapeLogicalBottom < floatLogicalBottom)
floatLogicalBottom = shapeLogicalBottom;
}
if (floatLogicalBottom > logicalHeight)
logicalBottom = min(floatLogicalBottom, logicalBottom);
}
return logicalBottom == LayoutUnit::max() ? LayoutUnit() : logicalBottom;
}
bool RenderBlockFlow::hitTestFloats(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset)
{
if (!m_floatingObjects)
return false;
LayoutPoint adjustedLocation = accumulatedOffset;
if (isRenderView()) {
adjustedLocation += toLayoutSize(toRenderView(this)->frameView()->scrollPosition());
}
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator begin = floatingObjectSet.begin();
for (FloatingObjectSetIterator it = floatingObjectSet.end(); it != begin;) {
--it;
FloatingObject* floatingObject = *it;
if (floatingObject->shouldPaint() && !floatingObject->renderer()->hasSelfPaintingLayer()) {
LayoutUnit xOffset = xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x();
LayoutUnit yOffset = yPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->y();
LayoutPoint childPoint = flipFloatForWritingModeForChild(floatingObject, adjustedLocation + LayoutSize(xOffset, yOffset));
if (floatingObject->renderer()->hitTest(request, result, locationInContainer, childPoint)) {
updateHitTestResult(result, locationInContainer.point() - toLayoutSize(childPoint));
return true;
}
}
}
return false;
}
void RenderBlockFlow::adjustForBorderFit(LayoutUnit x, LayoutUnit& left, LayoutUnit& right) const
{
RenderBlock::adjustForBorderFit(x, left, right);
if (m_floatingObjects && style()->visibility() == VISIBLE) {
const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
FloatingObjectSetIterator end = floatingObjectSet.end();
for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end; ++it) {
FloatingObject* floatingObject = *it;
if (floatingObject->shouldPaint()) {
LayoutUnit floatLeft = xPositionForFloatIncludingMargin(floatingObject) - floatingObject->renderer()->x();
LayoutUnit floatRight = floatLeft + floatingObject->renderer()->width();
left = min(left, floatLeft);
right = max(right, floatRight);
}
}
}
}
LayoutUnit RenderBlockFlow::logicalLeftFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const
{
if (m_floatingObjects && m_floatingObjects->hasLeftObjects())
return m_floatingObjects->logicalLeftOffset(fixedOffset, logicalTop, logicalHeight);
return fixedOffset;
}
LayoutUnit RenderBlockFlow::logicalRightFloatOffsetForLine(LayoutUnit logicalTop, LayoutUnit fixedOffset, LayoutUnit logicalHeight) const
{
if (m_floatingObjects && m_floatingObjects->hasRightObjects())
return m_floatingObjects->logicalRightOffset(fixedOffset, logicalTop, logicalHeight);
return fixedOffset;
}
GapRects RenderBlockFlow::inlineSelectionGaps(RenderBlock* rootBlock, const LayoutPoint& rootBlockPhysicalPosition, const LayoutSize& offsetFromRootBlock,
LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const PaintInfo* paintInfo)
{
GapRects result;
bool containsStart = selectionState() == SelectionStart || selectionState() == SelectionBoth;
if (!firstLineBox()) {
if (containsStart) {
lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + logicalHeight();
lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, logicalHeight());
lastLogicalRight = logicalRightSelectionOffset(rootBlock, logicalHeight());
}
return result;
}
RootInlineBox* lastSelectedLine = 0;
RootInlineBox* curr;
for (curr = firstRootBox(); curr && !curr->hasSelectedChildren(); curr = curr->nextRootBox()) { }
for (; curr && curr->hasSelectedChildren(); curr = curr->nextRootBox()) {
LayoutUnit selTop = curr->selectionTopAdjustedForPrecedingBlock();
LayoutUnit selHeight = curr->selectionHeightAdjustedForPrecedingBlock();
if (!containsStart && !lastSelectedLine && selectionState() != SelectionStart && selectionState() != SelectionBoth) {
result.uniteCenter(blockSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, lastLogicalTop,
lastLogicalLeft, lastLogicalRight, selTop, paintInfo));
}
LayoutRect logicalRect(curr->logicalLeft(), selTop, curr->logicalWidth(), selTop + selHeight);
logicalRect.move(isHorizontalWritingMode() ? offsetFromRootBlock : offsetFromRootBlock.transposedSize());
LayoutRect physicalRect = rootBlock->logicalRectToPhysicalRect(rootBlockPhysicalPosition, logicalRect);
if (!paintInfo || (isHorizontalWritingMode() && physicalRect.y() < paintInfo->rect.maxY() && physicalRect.maxY() > paintInfo->rect.y())
|| (!isHorizontalWritingMode() && physicalRect.x() < paintInfo->rect.maxX() && physicalRect.maxX() > paintInfo->rect.x()))
result.unite(curr->lineSelectionGap(rootBlock, rootBlockPhysicalPosition, offsetFromRootBlock, selTop, selHeight, paintInfo));
lastSelectedLine = curr;
}
if (containsStart && !lastSelectedLine) {
lastSelectedLine = lastRootBox();
}
if (lastSelectedLine && selectionState() != SelectionEnd && selectionState() != SelectionBoth) {
lastLogicalTop = rootBlock->blockDirectionOffset(offsetFromRootBlock) + lastSelectedLine->selectionBottom();
lastLogicalLeft = logicalLeftSelectionOffset(rootBlock, lastSelectedLine->selectionBottom());
lastLogicalRight = logicalRightSelectionOffset(rootBlock, lastSelectedLine->selectionBottom());
}
return result;
}
LayoutUnit RenderBlockFlow::logicalLeftSelectionOffset(RenderBlock* rootBlock, LayoutUnit position)
{
LayoutUnit logicalLeft = logicalLeftOffsetForLine(position, false);
if (logicalLeft == logicalLeftOffsetForContent())
return RenderBlock::logicalLeftSelectionOffset(rootBlock, position);
RenderBlock* cb = this;
while (cb != rootBlock) {
logicalLeft += cb->logicalLeft();
cb = cb->containingBlock();
}
return logicalLeft;
}
LayoutUnit RenderBlockFlow::logicalRightSelectionOffset(RenderBlock* rootBlock, LayoutUnit position)
{
LayoutUnit logicalRight = logicalRightOffsetForLine(position, false);
if (logicalRight == logicalRightOffsetForContent())
return RenderBlock::logicalRightSelectionOffset(rootBlock, position);
RenderBlock* cb = this;
while (cb != rootBlock) {
logicalRight += cb->logicalLeft();
cb = cb->containingBlock();
}
return logicalRight;
}
template <typename CharacterType>
static inline TextRun constructTextRunInternal(RenderObject* context, const Font& font, const CharacterType* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion)
{
ASSERT(style);
TextDirection textDirection = direction;
bool directionalOverride = style->rtlOrdering() == VisualOrder;
TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
if (textRunNeedsRenderingContext(font))
run.setRenderingContext(SVGTextRunRenderingContext::create(context));
return run;
}
template <typename CharacterType>
static inline TextRun constructTextRunInternal(RenderObject* context, const Font& font, const CharacterType* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
{
ASSERT(style);
TextDirection textDirection = direction;
bool directionalOverride = style->rtlOrdering() == VisualOrder;
if (flags != DefaultTextRunFlags) {
if (flags & RespectDirection)
textDirection = style->direction();
if (flags & RespectDirectionOverride)
directionalOverride |= isOverride(style->unicodeBidi());
}
TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
if (textRunNeedsRenderingContext(font))
run.setRenderingContext(SVGTextRunRenderingContext::create(context));
return run;
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const LChar* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion)
{
return constructTextRunInternal(context, font, characters, length, style, direction, expansion);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const UChar* characters, int length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion)
{
return constructTextRunInternal(context, font, characters, length, style, direction, expansion);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion)
{
if (text->is8Bit())
return constructTextRunInternal(context, font, text->characters8(), text->textLength(), style, direction, expansion);
return constructTextRunInternal(context, font, text->characters16(), text->textLength(), style, direction, expansion);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, unsigned offset, unsigned length, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion)
{
ASSERT(offset + length <= text->textLength());
if (text->is8Bit())
return constructTextRunInternal(context, font, text->characters8() + offset, length, style, direction, expansion);
return constructTextRunInternal(context, font, text->characters16() + offset, length, style, direction, expansion);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const String& string, RenderStyle* style, TextDirection direction, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
{
unsigned length = string.length();
if (!length)
return constructTextRunInternal(context, font, static_cast<const LChar*>(0), length, style, direction, expansion, flags);
if (string.is8Bit())
return constructTextRunInternal(context, font, string.characters8(), length, style, direction, expansion, flags);
return constructTextRunInternal(context, font, string.characters16(), length, style, direction, expansion, flags);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const String& string, RenderStyle* style, TextRun::ExpansionBehavior expansion, TextRunFlags flags)
{
bool hasStrongDirectionality;
return constructTextRun(context, font, string, style,
determineDirectionality(string, hasStrongDirectionality),
expansion, flags);
}
TextRun RenderBlockFlow::constructTextRun(RenderObject* context, const Font& font, const RenderText* text, unsigned offset, unsigned length, RenderStyle* style, TextRun::ExpansionBehavior expansion)
{
ASSERT(offset + length <= text->textLength());
TextRun run = text->is8Bit()
? constructTextRunInternal(context, font, text->characters8() + offset, length, style, LTR, expansion)
: constructTextRunInternal(context, font, text->characters16() + offset, length, style, LTR, expansion);
bool hasStrongDirectionality;
run.setDirection(directionForRun(run, hasStrongDirectionality));
return run;
}
RootInlineBox* RenderBlockFlow::createRootInlineBox()
{
return new RootInlineBox(*this);
}
void RenderBlockFlow::createMultiColumnFlowThreadIfNeeded()
{
if ((style()->hasAutoColumnCount() && style()->hasAutoColumnWidth()) || !document().regionBasedColumnsEnabled())
return;
if (multiColumnFlowThread())
return;
setChildrenInline(false);
RenderMultiColumnFlowThread* flowThread = RenderMultiColumnFlowThread::createAnonymous(document(), style());
RenderBlock::addChild(flowThread);
RenderBlockFlowRareData& rareData = ensureRareData();
ASSERT(!rareData.m_multiColumnFlowThread);
rareData.m_multiColumnFlowThread = flowThread;
}
RenderBlockFlow::RenderBlockFlowRareData& RenderBlockFlow::ensureRareData()
{
if (m_rareData)
return *m_rareData;
m_rareData = adoptPtr(new RenderBlockFlowRareData(this));
return *m_rareData;
}
}