This source file includes following definitions.
- m_pageLogicalSizeChanged
- createFlowThreadStyle
- addRegionToThread
- removeRegionFromThread
- invalidateRegions
- m_renderFlowThread
- validateRegions
- layout
- updateLogicalWidth
- computeLogicalHeight
- computeRegionClippingRect
- nodeAtPoint
- shouldRepaint
- repaintRectangleInRegions
- regionAtBlockOffset
- regionFromAbsolutePointAndBox
- adjustedPositionRelativeToOffsetParent
- pageLogicalTopForOffset
- pageLogicalWidthForOffset
- pageLogicalHeightForOffset
- pageRemainingLogicalHeightForOffset
- mapFromFlowToRegion
- firstRegion
- lastRegion
- setRegionRangeForBox
- getRegionRangeForBox
- applyBreakAfterContent
- regionInRange
- updateRegionsFlowThreadPortionRect
- collectLayerFragments
- fragmentsBoundingBox
- cachedOffsetFromLogicalTopOfFirstRegion
- setOffsetFromLogicalTopOfFirstRegion
- clearOffsetFromLogicalTopOfFirstRegion
- currentStatePusherRenderBox
- pushFlowThreadLayoutState
- popFlowThreadLayoutState
- offsetFromLogicalTopOfFirstRegion
- collectIfNeeded
- mapLocalToContainer
- m_previousRenderFlowThread
#include "config.h"
#include "core/rendering/RenderFlowThread.h"
#include "core/dom/Node.h"
#include "core/rendering/FlowThreadController.h"
#include "core/rendering/HitTestRequest.h"
#include "core/rendering/HitTestResult.h"
#include "core/rendering/LayoutRectRecorder.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderInline.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderRegion.h"
#include "core/rendering/RenderView.h"
#include "platform/PODIntervalTree.h"
#include "platform/geometry/TransformState.h"
namespace WebCore {
RenderFlowThread::RenderFlowThread()
: RenderBlockFlow(0)
, m_previousRegionCount(0)
, m_regionsInvalidated(false)
, m_regionsHaveUniformLogicalHeight(true)
, m_pageLogicalSizeChanged(false)
{
setFlowThreadState(InsideOutOfFlowThread);
}
PassRefPtr<RenderStyle> RenderFlowThread::createFlowThreadStyle(RenderStyle* parentStyle)
{
RefPtr<RenderStyle> newStyle(RenderStyle::create());
newStyle->inheritFrom(parentStyle);
newStyle->setDisplay(BLOCK);
newStyle->setPosition(AbsolutePosition);
newStyle->setZIndex(0);
newStyle->setLeft(Length(0, Fixed));
newStyle->setTop(Length(0, Fixed));
newStyle->setWidth(Length(100, Percent));
newStyle->setHeight(Length(100, Percent));
newStyle->font().update(nullptr);
return newStyle.release();
}
void RenderFlowThread::addRegionToThread(RenderRegion* renderRegion)
{
ASSERT(renderRegion);
m_regionList.add(renderRegion);
renderRegion->setIsValid(true);
}
void RenderFlowThread::removeRegionFromThread(RenderRegion* renderRegion)
{
ASSERT(renderRegion);
m_regionList.remove(renderRegion);
}
void RenderFlowThread::invalidateRegions()
{
if (m_regionsInvalidated) {
ASSERT(selfNeedsLayout());
return;
}
m_regionRangeMap.clear();
setNeedsLayout();
m_regionsInvalidated = true;
}
class CurrentRenderFlowThreadDisabler {
WTF_MAKE_NONCOPYABLE(CurrentRenderFlowThreadDisabler);
public:
CurrentRenderFlowThreadDisabler(RenderView* view)
: m_view(view)
, m_renderFlowThread(0)
{
m_renderFlowThread = m_view->flowThreadController()->currentRenderFlowThread();
if (m_renderFlowThread)
view->flowThreadController()->setCurrentRenderFlowThread(0);
}
~CurrentRenderFlowThreadDisabler()
{
if (m_renderFlowThread)
m_view->flowThreadController()->setCurrentRenderFlowThread(m_renderFlowThread);
}
private:
RenderView* m_view;
RenderFlowThread* m_renderFlowThread;
};
void RenderFlowThread::validateRegions()
{
if (m_regionsInvalidated) {
m_regionsInvalidated = false;
m_regionsHaveUniformLogicalHeight = true;
if (hasRegions()) {
LayoutUnit previousRegionLogicalHeight = 0;
bool firstRegionVisited = false;
for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
LayoutUnit regionLogicalHeight = region->pageLogicalHeight();
if (!firstRegionVisited) {
firstRegionVisited = true;
} else {
if (m_regionsHaveUniformLogicalHeight && previousRegionLogicalHeight != regionLogicalHeight)
m_regionsHaveUniformLogicalHeight = false;
}
previousRegionLogicalHeight = regionLogicalHeight;
}
}
}
updateLogicalWidth();
updateRegionsFlowThreadPortionRect();
}
void RenderFlowThread::layout()
{
LayoutRectRecorder recorder(*this);
m_pageLogicalSizeChanged = m_regionsInvalidated && everHadLayout();
validateRegions();
CurrentRenderFlowThreadMaintainer currentFlowThreadSetter(this);
RenderBlockFlow::layout();
m_pageLogicalSizeChanged = false;
if (lastRegion())
lastRegion()->expandToEncompassFlowThreadContentsIfNeeded();
}
void RenderFlowThread::updateLogicalWidth()
{
setLogicalWidth(initialLogicalWidth());
}
void RenderFlowThread::computeLogicalHeight(LayoutUnit, LayoutUnit logicalTop, LogicalExtentComputedValues& computedValues) const
{
computedValues.m_position = logicalTop;
computedValues.m_extent = 0;
for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
computedValues.m_extent += region->logicalHeightOfAllFlowThreadContent();
}
}
LayoutRect RenderFlowThread::computeRegionClippingRect(const LayoutPoint& offset, const LayoutRect& flowThreadPortionRect, const LayoutRect& flowThreadPortionOverflowRect) const
{
LayoutRect regionClippingRect(offset + (flowThreadPortionOverflowRect.location() - flowThreadPortionRect.location()), flowThreadPortionOverflowRect.size());
if (style()->isFlippedBlocksWritingMode())
regionClippingRect.move(flowThreadPortionRect.size() - flowThreadPortionOverflowRect.size());
return regionClippingRect;
}
bool RenderFlowThread::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
{
if (hitTestAction == HitTestBlockBackground)
return false;
return RenderBlockFlow::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction);
}
bool RenderFlowThread::shouldRepaint(const LayoutRect& r) const
{
if (view()->document().printing() || r.isEmpty())
return false;
return true;
}
void RenderFlowThread::repaintRectangleInRegions(const LayoutRect& repaintRect) const
{
if (!shouldRepaint(repaintRect) || !hasValidRegionInfo())
return;
LayoutStateDisabler layoutStateDisabler(*this);
CurrentRenderFlowThreadDisabler disabler(view());
for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
region->repaintFlowThreadContent(repaintRect);
}
}
RenderRegion* RenderFlowThread::regionAtBlockOffset(LayoutUnit offset, bool extendLastRegion, RegionAutoGenerationPolicy autoGenerationPolicy)
{
ASSERT(!m_regionsInvalidated);
if (autoGenerationPolicy == AllowRegionAutoGeneration)
autoGenerateRegionsToBlockOffset(offset);
if (offset <= 0)
return m_regionList.isEmpty() ? 0 : m_regionList.first();
RegionSearchAdapter adapter(offset);
m_regionIntervalTree.allOverlapsWithAdapter<RegionSearchAdapter>(adapter);
if (!adapter.result() && !m_regionList.isEmpty())
return m_regionList.last();
return adapter.result();
}
RenderRegion* RenderFlowThread::regionFromAbsolutePointAndBox(IntPoint absolutePoint, const RenderBox* flowedBox)
{
if (!flowedBox)
return 0;
RenderRegion* startRegion = 0;
RenderRegion* endRegion = 0;
getRegionRangeForBox(flowedBox, startRegion, endRegion);
if (!startRegion)
return 0;
for (RenderRegionList::iterator iter = m_regionList.find(startRegion); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
IntRect regionAbsoluteRect(roundedIntPoint(region->localToAbsolute()), roundedIntSize(region->frameRect().size()));
if (regionAbsoluteRect.contains(absolutePoint))
return region;
if (region == endRegion)
break;
}
return 0;
}
LayoutPoint RenderFlowThread::adjustedPositionRelativeToOffsetParent(const RenderBoxModelObject& boxModelObject, const LayoutPoint& startPoint)
{
LayoutPoint referencePoint = startPoint;
RenderRegion* startRegion = regionAtBlockOffset(referencePoint.y());
if (startRegion) {
RenderObject* currObject = startRegion;
RenderObject* currOffsetParentRenderer;
Element* currOffsetParentElement;
while ((currOffsetParentElement = currObject->offsetParent()) && (currOffsetParentRenderer = currOffsetParentElement->renderer())) {
if (currObject->isBoxModelObject())
referencePoint.move(toRenderBoxModelObject(currObject)->offsetLeft(), toRenderBoxModelObject(currObject)->offsetTop());
if (currOffsetParentRenderer->isBox() && !currOffsetParentRenderer->isBody())
referencePoint.move(toRenderBox(currOffsetParentRenderer)->borderLeft(), toRenderBox(currOffsetParentRenderer)->borderTop());
currObject = currOffsetParentRenderer;
}
bool wasComputedRelativeToOtherRegion = false;
const RenderBlock* objContainingBlock = boxModelObject.containingBlock();
while (objContainingBlock) {
RenderRegion* parentStartRegion = 0;
RenderRegion* parentEndRegion = 0;
getRegionRangeForBox(objContainingBlock, parentStartRegion, parentEndRegion);
if (parentStartRegion && parentStartRegion != startRegion) {
wasComputedRelativeToOtherRegion = true;
break;
}
objContainingBlock = objContainingBlock->containingBlock();
}
if (wasComputedRelativeToOtherRegion) {
LayoutUnit top = 0;
if (boxModelObject.isRenderBlock()) {
top = toRenderBlock(&boxModelObject)->offsetFromLogicalTopOfFirstPage();
} else {
if (boxModelObject.containingBlock())
top = boxModelObject.containingBlock()->offsetFromLogicalTopOfFirstPage();
if (boxModelObject.isBox())
top += toRenderBox(&boxModelObject)->topLeftLocation().y();
else if (boxModelObject.isRenderInline())
top -= toRenderInline(&boxModelObject)->borderTop();
}
LayoutUnit regionLogicalTop = startRegion->pageLogicalTopForOffset(top);
LayoutUnit topRelativeToRegion = top - regionLogicalTop;
referencePoint.setY(startRegion->offsetTop() + topRelativeToRegion);
if (boxModelObject.isRelPositioned())
referencePoint.move(0, boxModelObject.relativePositionOffset().height());
else if (boxModelObject.isStickyPositioned())
referencePoint.move(0, boxModelObject.stickyPositionOffset().height());
}
referencePoint.move(startRegion->borderLeft(), startRegion->borderTop());
}
return referencePoint;
}
LayoutUnit RenderFlowThread::pageLogicalTopForOffset(LayoutUnit offset)
{
RenderRegion* region = regionAtBlockOffset(offset);
return region ? region->pageLogicalTopForOffset(offset) : LayoutUnit();
}
LayoutUnit RenderFlowThread::pageLogicalWidthForOffset(LayoutUnit offset)
{
RenderRegion* region = regionAtBlockOffset(offset, true);
return region ? region->pageLogicalWidth() : contentLogicalWidth();
}
LayoutUnit RenderFlowThread::pageLogicalHeightForOffset(LayoutUnit offset)
{
RenderRegion* region = regionAtBlockOffset(offset);
if (!region)
return 0;
return region->pageLogicalHeight();
}
LayoutUnit RenderFlowThread::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule)
{
RenderRegion* region = regionAtBlockOffset(offset);
if (!region)
return 0;
LayoutUnit pageLogicalTop = region->pageLogicalTopForOffset(offset);
LayoutUnit pageLogicalHeight = region->pageLogicalHeight();
LayoutUnit pageLogicalBottom = pageLogicalTop + pageLogicalHeight;
LayoutUnit remainingHeight = pageLogicalBottom - offset;
if (pageBoundaryRule == IncludePageBoundary) {
remainingHeight = intMod(remainingHeight, pageLogicalHeight);
}
return remainingHeight;
}
RenderRegion* RenderFlowThread::mapFromFlowToRegion(TransformState& transformState) const
{
if (!hasValidRegionInfo())
return 0;
LayoutRect boxRect = transformState.mappedQuad().enclosingBoundingBox();
flipForWritingMode(boxRect);
LayoutPoint center = boxRect.center();
RenderRegion* renderRegion = const_cast<RenderFlowThread*>(this)->regionAtBlockOffset(isHorizontalWritingMode() ? center.y() : center.x(), true, DisallowRegionAutoGeneration);
if (!renderRegion)
return 0;
LayoutRect flippedRegionRect(renderRegion->flowThreadPortionRect());
flipForWritingMode(flippedRegionRect);
transformState.move(renderRegion->contentBoxRect().location() - flippedRegionRect.location());
return renderRegion;
}
RenderRegion* RenderFlowThread::firstRegion() const
{
if (!hasValidRegionInfo())
return 0;
return m_regionList.first();
}
RenderRegion* RenderFlowThread::lastRegion() const
{
if (!hasValidRegionInfo())
return 0;
return m_regionList.last();
}
void RenderFlowThread::setRegionRangeForBox(const RenderBox* box, LayoutUnit offsetFromLogicalTopOfFirstPage)
{
if (!hasRegions())
return;
RenderRegion* startRegion = regionAtBlockOffset(offsetFromLogicalTopOfFirstPage, true);
RenderRegion* endRegion = regionAtBlockOffset(offsetFromLogicalTopOfFirstPage + box->logicalHeight(), true);
RenderRegionRangeMap::iterator it = m_regionRangeMap.find(box);
if (it == m_regionRangeMap.end()) {
m_regionRangeMap.set(box, RenderRegionRange(startRegion, endRegion));
return;
}
RenderRegionRange& range = it->value;
if (range.startRegion() == startRegion && range.endRegion() == endRegion)
return;
range.setRange(startRegion, endRegion);
}
void RenderFlowThread::getRegionRangeForBox(const RenderBox* box, RenderRegion*& startRegion, RenderRegion*& endRegion) const
{
startRegion = 0;
endRegion = 0;
RenderRegionRangeMap::const_iterator it = m_regionRangeMap.find(box);
if (it == m_regionRangeMap.end())
return;
const RenderRegionRange& range = it->value;
startRegion = range.startRegion();
endRegion = range.endRegion();
ASSERT(m_regionList.contains(startRegion) && m_regionList.contains(endRegion));
}
void RenderFlowThread::applyBreakAfterContent(LayoutUnit clientHeight)
{
addForcedRegionBreak(clientHeight, this, false);
}
bool RenderFlowThread::regionInRange(const RenderRegion* targetRegion, const RenderRegion* startRegion, const RenderRegion* endRegion) const
{
ASSERT(targetRegion);
for (RenderRegionList::const_iterator it = m_regionList.find(const_cast<RenderRegion*>(startRegion)); it != m_regionList.end(); ++it) {
const RenderRegion* currRegion = *it;
if (targetRegion == currRegion)
return true;
if (currRegion == endRegion)
break;
}
return false;
}
void RenderFlowThread::updateRegionsFlowThreadPortionRect()
{
LayoutUnit logicalHeight = 0;
m_regionIntervalTree.clear();
m_regionIntervalTree.initIfNeeded();
for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
LayoutUnit regionLogicalWidth = region->pageLogicalWidth();
LayoutUnit regionLogicalHeight = std::min<LayoutUnit>(RenderFlowThread::maxLogicalHeight() - logicalHeight, region->logicalHeightOfAllFlowThreadContent());
LayoutRect regionRect(style()->direction() == LTR ? LayoutUnit() : logicalWidth() - regionLogicalWidth, logicalHeight, regionLogicalWidth, regionLogicalHeight);
region->setFlowThreadPortionRect(isHorizontalWritingMode() ? regionRect : regionRect.transposedRect());
m_regionIntervalTree.add(RegionIntervalTree::createInterval(logicalHeight, logicalHeight + regionLogicalHeight, region));
logicalHeight += regionLogicalHeight;
}
}
void RenderFlowThread::collectLayerFragments(LayerFragments& layerFragments, const LayoutRect& layerBoundingBox, const LayoutRect& dirtyRect)
{
ASSERT(!m_regionsInvalidated);
for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
region->collectLayerFragments(layerFragments, layerBoundingBox, dirtyRect);
}
}
LayoutRect RenderFlowThread::fragmentsBoundingBox(const LayoutRect& layerBoundingBox)
{
ASSERT(!m_regionsInvalidated);
LayoutRect result;
for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
RenderRegion* region = *iter;
LayerFragments fragments;
region->collectLayerFragments(fragments, layerBoundingBox, PaintInfo::infiniteRect());
for (size_t i = 0; i < fragments.size(); ++i) {
const LayerFragment& fragment = fragments.at(i);
LayoutRect fragmentRect(layerBoundingBox);
fragmentRect.intersect(fragment.paginationClip);
fragmentRect.moveBy(fragment.paginationOffset);
result.unite(fragmentRect);
}
}
return result;
}
bool RenderFlowThread::cachedOffsetFromLogicalTopOfFirstRegion(const RenderBox* box, LayoutUnit& result) const
{
RenderBoxToOffsetMap::const_iterator offsetIterator = m_boxesToOffsetMap.find(box);
if (offsetIterator == m_boxesToOffsetMap.end())
return false;
result = offsetIterator->value;
return true;
}
void RenderFlowThread::setOffsetFromLogicalTopOfFirstRegion(const RenderBox* box, LayoutUnit offset)
{
m_boxesToOffsetMap.set(box, offset);
}
void RenderFlowThread::clearOffsetFromLogicalTopOfFirstRegion(const RenderBox* box)
{
ASSERT(m_boxesToOffsetMap.contains(box));
m_boxesToOffsetMap.remove(box);
}
const RenderBox* RenderFlowThread::currentStatePusherRenderBox() const
{
const RenderObject* currentObject = m_statePusherObjectsStack.isEmpty() ? 0 : m_statePusherObjectsStack.last();
if (currentObject && currentObject->isBox())
return toRenderBox(currentObject);
return 0;
}
void RenderFlowThread::pushFlowThreadLayoutState(const RenderObject& object)
{
if (const RenderBox* currentBoxDescendant = currentStatePusherRenderBox()) {
LayoutState* layoutState = currentBoxDescendant->view()->layoutState();
if (layoutState && layoutState->isPaginated()) {
ASSERT(layoutState->renderer() == currentBoxDescendant);
LayoutSize offsetDelta = layoutState->layoutOffset() - layoutState->pageOffset();
setOffsetFromLogicalTopOfFirstRegion(currentBoxDescendant, currentBoxDescendant->isHorizontalWritingMode() ? offsetDelta.height() : offsetDelta.width());
}
}
m_statePusherObjectsStack.add(&object);
}
void RenderFlowThread::popFlowThreadLayoutState()
{
m_statePusherObjectsStack.removeLast();
if (const RenderBox* currentBoxDescendant = currentStatePusherRenderBox()) {
LayoutState* layoutState = currentBoxDescendant->view()->layoutState();
if (layoutState && layoutState->isPaginated())
clearOffsetFromLogicalTopOfFirstRegion(currentBoxDescendant);
}
}
LayoutUnit RenderFlowThread::offsetFromLogicalTopOfFirstRegion(const RenderBlock* currentBlock) const
{
LayoutUnit offset;
if (cachedOffsetFromLogicalTopOfFirstRegion(currentBlock, offset))
return offset;
const RenderBox* currentBoxDescendant = currentStatePusherRenderBox();
if (currentBlock == currentBoxDescendant) {
LayoutState* layoutState = view()->layoutState();
ASSERT(layoutState->renderer() == currentBlock);
ASSERT(layoutState && layoutState->isPaginated());
LayoutSize offsetDelta = layoutState->layoutOffset() - layoutState->pageOffset();
return currentBoxDescendant->isHorizontalWritingMode() ? offsetDelta.height() : offsetDelta.width();
}
LayoutRect blockRect(0, 0, currentBlock->width(), currentBlock->height());
while (currentBlock && !currentBlock->isRenderFlowThread()) {
RenderBlock* containerBlock = currentBlock->containingBlock();
ASSERT(containerBlock);
if (!containerBlock)
return 0;
LayoutPoint currentBlockLocation = currentBlock->location();
if (containerBlock->style()->writingMode() != currentBlock->style()->writingMode()) {
if (containerBlock->style()->isFlippedBlocksWritingMode()) {
if (containerBlock->isHorizontalWritingMode())
blockRect.setY(currentBlock->height() - blockRect.maxY());
else
blockRect.setX(currentBlock->width() - blockRect.maxX());
}
currentBlock->flipForWritingMode(blockRect);
}
blockRect.moveBy(currentBlockLocation);
currentBlock = containerBlock;
}
return currentBlock->isHorizontalWritingMode() ? blockRect.y() : blockRect.x();
}
void RenderFlowThread::RegionSearchAdapter::collectIfNeeded(const RegionInterval& interval)
{
if (m_result)
return;
if (interval.low() <= m_offset && interval.high() > m_offset)
m_result = interval.data();
}
void RenderFlowThread::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const
{
if (this == repaintContainer)
return;
if (RenderRegion* region = mapFromFlowToRegion(transformState)) {
static_cast<const RenderObject*>(region)->mapLocalToContainer(region->containerForRepaint(), transformState, mode, wasFixed);
}
}
CurrentRenderFlowThreadMaintainer::CurrentRenderFlowThreadMaintainer(RenderFlowThread* renderFlowThread)
: m_renderFlowThread(renderFlowThread)
, m_previousRenderFlowThread(0)
{
if (!m_renderFlowThread)
return;
RenderView* view = m_renderFlowThread->view();
m_previousRenderFlowThread = view->flowThreadController()->currentRenderFlowThread();
view->flowThreadController()->setCurrentRenderFlowThread(m_renderFlowThread);
}
CurrentRenderFlowThreadMaintainer::~CurrentRenderFlowThreadMaintainer()
{
if (!m_renderFlowThread)
return;
RenderView* view = m_renderFlowThread->view();
ASSERT(view->flowThreadController()->currentRenderFlowThread() == m_renderFlowThread);
view->flowThreadController()->setCurrentRenderFlowThread(m_previousRenderFlowThread);
}
}