void RenderMultiColumnFlowThread::autoGenerateRegionsToBlockOffset(LayoutUnit offset) { // This function ensures we have the correct column set information at all times. // For a simple multi-column layout in continuous media, only one column set child is required. // Once a column is nested inside an enclosing pagination context, the number of column sets // required becomes 2n-1, where n is the total number of nested pagination contexts. For example: // // Column layout with no enclosing pagination model = 2 * 1 - 1 = 1 column set. // Columns inside pages = 2 * 2 - 1 = 3 column sets (bottom of first page, all the subsequent pages, then the last page). // Columns inside columns inside pages = 2 * 3 - 1 = 5 column sets. // // In addition, column spans will force a column set to "split" into before/after sets around the spanning element. // // Finally, we will need to deal with columns inside regions. If regions have variable widths, then there will need // to be unique column sets created inside any region whose width is different from its surrounding regions. This is // actually pretty similar to the spanning case, in that we break up the column sets whenever the width varies. // // FIXME: Parent fragmentation contexts might require us to insert additional column sets here, // but we don't worry about it for now. This matches the old multi-column code. Right now our // goal is just feature parity with the old multi-column code so that we can switch over to the // new code as soon as possible. The one column set that we need has already been made during // render tree creation, so there's nothing to do here, for the time being. (void)offset; // hide warning ASSERT(toRenderMultiColumnSet(regionAtBlockOffset(0, offset, true, DisallowRegionAutoGeneration))); }
LayoutUnit RenderFlowThread::pageLogicalHeightForOffset(LayoutUnit offset) const { RenderRegion* region = regionAtBlockOffset(offset); if (!region) return 0; return region->pageLogicalHeight(); }
void RenderFlowThread::computeOverflowStateForRegions(LayoutUnit oldClientAfterEdge) { LayoutUnit height = oldClientAfterEdge; LayoutUnit offsetBreakAdjustment = 0; // Simulate a region break at height. If it points inside an auto logical height region, // then it may determine the region override logical content height. addForcedRegionBreak(height, this, false, &offsetBreakAdjustment); // During the normal layout phase of the flow thread all the auto-height regions have the overrideLogicalContentHeight set to max height. // We need to clear the overrideLogicalContentHeight for all the regions that didn't receive any content, starting with firstEmptyRegion. RenderRegion* firstEmptyRegion = 0; if (view()->normalLayoutPhase()) firstEmptyRegion = regionAtBlockOffset(height + offsetBreakAdjustment); // FIXME: the visual overflow of middle region (if it is the last one to contain any content in a render flow thread) // might not be taken into account because the render flow thread height is greater that that regions height + its visual overflow // because of how computeLogicalHeight is implemented for RenderFlowThread (as a sum of all regions height). // This means that the middle region will be marked as fit (even if it has visual overflow flowing into the next region) if (hasRenderOverflow() && ( (isHorizontalWritingMode() && visualOverflowRect().maxY() > clientBoxRect().maxY()) || (!isHorizontalWritingMode() && visualOverflowRect().maxX() > clientBoxRect().maxX()))) height = isHorizontalWritingMode() ? visualOverflowRect().maxY() : visualOverflowRect().maxX(); bool inEmptyRegionsSection = false; RenderRegion* lastReg = lastRegion(); for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) { RenderRegion* region = *iter; LayoutUnit flowMin = height - (isHorizontalWritingMode() ? region->flowThreadPortionRect().y() : region->flowThreadPortionRect().x()); LayoutUnit flowMax = height - (isHorizontalWritingMode() ? region->flowThreadPortionRect().maxY() : region->flowThreadPortionRect().maxX()); RenderRegion::RegionState previousState = region->regionState(); RenderRegion::RegionState state = RenderRegion::RegionFit; if (flowMin <= 0) state = RenderRegion::RegionEmpty; if (flowMax > 0 && region == lastReg) state = RenderRegion::RegionOverset; region->setRegionState(state); // determine whether the NamedFlow object should dispatch a regionLayoutUpdate event // FIXME: currently it cannot determine whether a region whose regionOverset state remained either "fit" or "overset" has actually // changed, so it just assumes that the NamedFlow should dispatch the event if (previousState != state || state == RenderRegion::RegionFit || state == RenderRegion::RegionOverset) setDispatchRegionLayoutUpdateEvent(true); if (region == firstEmptyRegion) inEmptyRegionsSection = true; // Clear the overrideLogicalContentHeight value for autoheight regions that didn't receive any content. if (inEmptyRegionsSection && region->hasAutoLogicalHeight()) region->clearOverrideLogicalContentHeight(); } // With the regions overflow state computed we can also set the overset flag for the named flow. // If there are no valid regions in the chain, overset is true. m_overset = lastReg ? lastReg->regionState() == RenderRegion::RegionOverset : true; }
bool RenderMultiColumnFlowThread::addForcedRegionBreak(const RenderBlock* block, LayoutUnit offset, RenderBox* /*breakChild*/, bool /*isBefore*/, LayoutUnit* offsetBreakAdjustment) { if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(block, offset))) { multicolSet->addForcedBreak(offset); if (offsetBreakAdjustment) *offsetBreakAdjustment = pageLogicalHeightForOffset(offset) ? pageRemainingLogicalHeightForOffset(offset, IncludePageBoundary) : LayoutUnit::fromPixel(0); return true; } return false; }
void RenderFlowThread::setRegionRangeForBox(const RenderBox* box, LayoutUnit offsetFromLogicalTopOfFirstPage) { if (!hasRegions()) return; // FIXME: Not right for differing writing-modes. 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)); clearRenderObjectCustomStyle(box); return; } // If nothing changed, just bail. RenderRegionRange& range = it->value; if (range.startRegion() == startRegion && range.endRegion() == endRegion) return; // Delete any info that we find before our new startRegion and after our new endRegion. for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) { RenderRegion* region = *iter; if (region == startRegion) { iter = m_regionList.find(endRegion); continue; } region->removeRenderBoxRegionInfo(box); if (region == range.endRegion()) break; } clearRenderObjectCustomStyle(box, range.startRegion(), range.endRegion(), startRegion, endRegion); range.setRange(startRegion, endRegion); }
LayoutUnit RenderFlowThread::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const { 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) { // If IncludePageBoundary is set, the line exactly on the top edge of a // region will act as being part of the previous region. remainingHeight = intMod(remainingHeight, pageLogicalHeight); } return remainingHeight; }
RenderRegion* RenderFlowThread::mapFromFlowToRegion(TransformState& transformState) const { if (!hasValidRegionInfo()) return 0; LayoutRect boxRect = transformState.mappedQuad().enclosingBoundingBox(); flipForWritingMode(boxRect); // FIXME: We need to refactor RenderObject::absoluteQuads to be able to split the quads across regions, // for now we just take the center of the mapped enclosing box and map it to a region. // Note: Using the center in order to avoid rounding errors. LayoutPoint center = boxRect.center(); RenderRegion* renderRegion = regionAtBlockOffset(isHorizontalWritingMode() ? center.y() : center.x(), true); if (!renderRegion) return 0; LayoutRect flippedRegionRect(renderRegion->flowThreadPortionRect()); flipForWritingMode(flippedRegionRect); transformState.move(renderRegion->contentBoxRect().location() - flippedRegionRect.location()); return renderRegion; }
// Even if we require the break to occur at offsetBreakInFlowThread, because regions may have min/max-height values, // it is possible that the break will occur at a different offset than the original one required. // offsetBreakAdjustment measures the different between the requested break offset and the current break offset. bool RenderFlowThread::addForcedRegionBreak(LayoutUnit offsetBreakInFlowThread, RenderObject* breakChild, bool isBefore, LayoutUnit* offsetBreakAdjustment) { // We take breaks into account for height computation for auto logical height regions // only in the layout phase in which we lay out the flows threads unconstrained // and we use the content breaks to determine the overrideContentLogicalHeight for // auto logical height regions. if (view()->constrainedFlowThreadsLayoutPhase()) return false; // Breaks can come before or after some objects. We need to track these objects, so that if we get // multiple breaks for the same object (for example because of multiple layouts on the same object), // we need to invalidate every other region after the old one and start computing from fresh. RenderObjectToRegionMap& mapToUse = isBefore ? m_breakBeforeToRegionMap : m_breakAfterToRegionMap; RenderObjectToRegionMap::iterator iter = mapToUse.find(breakChild); if (iter != mapToUse.end()) { RenderRegionList::iterator regionIter = m_regionList.find(iter->value); ASSERT(regionIter != m_regionList.end()); ASSERT((*regionIter)->hasAutoLogicalHeight()); initializeRegionsOverrideLogicalContentHeight(*regionIter); // We need to update the regions flow thread portion rect because we are going to process // a break on these regions. updateRegionsFlowThreadPortionRect(); } // Simulate a region break at offsetBreakInFlowThread. If it points inside an auto logical height region, // then it determines the region override logical content height. RenderRegion* region = regionAtBlockOffset(offsetBreakInFlowThread); if (!region) return false; bool overrideLogicalContentHeightComputed = false; LayoutUnit currentRegionOffsetInFlowThread = isHorizontalWritingMode() ? region->flowThreadPortionRect().y() : region->flowThreadPortionRect().x(); LayoutUnit offsetBreakInCurrentRegion = offsetBreakInFlowThread - currentRegionOffsetInFlowThread; if (region->hasAutoLogicalHeight()) { // A forced break can appear only in an auto-height region that didn't have a forced break before. // This ASSERT is a good-enough heuristic to verify the above condition. ASSERT(region->maxPageLogicalHeight() == region->overrideLogicalContentHeight()); mapToUse.set(breakChild, region); overrideLogicalContentHeightComputed = true; // Compute the region height pretending that the offsetBreakInCurrentRegion is the logicalHeight for the auto-height region. LayoutUnit regionOverrideLogicalContentHeight = region->computeReplacedLogicalHeightRespectingMinMaxHeight(offsetBreakInCurrentRegion); // The new height of this region needs to be smaller than the initial value, the max height. A forced break is the only way to change the initial // height of an auto-height region besides content ending. ASSERT(regionOverrideLogicalContentHeight <= region->maxPageLogicalHeight()); region->setOverrideLogicalContentHeight(regionOverrideLogicalContentHeight); currentRegionOffsetInFlowThread += regionOverrideLogicalContentHeight; } else currentRegionOffsetInFlowThread += isHorizontalWritingMode() ? region->flowThreadPortionRect().height() : region->flowThreadPortionRect().width(); // If the break was found inside an auto-height region its size changed so we need to recompute the flow thread portion rectangles. if (overrideLogicalContentHeightComputed) updateRegionsFlowThreadPortionRect(); if (offsetBreakAdjustment) *offsetBreakAdjustment = max<LayoutUnit>(0, currentRegionOffsetInFlowThread - offsetBreakInFlowThread); return overrideLogicalContentHeightComputed; }
LayoutUnit RenderFlowThread::pageLogicalWidthForOffset(LayoutUnit offset) const { RenderRegion* region = regionAtBlockOffset(offset, true); return region ? region->pageLogicalWidth() : contentLogicalWidth(); }
LayoutUnit RenderFlowThread::pageLogicalTopForOffset(LayoutUnit offset) const { RenderRegion* region = regionAtBlockOffset(offset); return region ? region->pageLogicalTopForOffset(offset) : LayoutUnit(); }
LayoutUnit RenderFlowThread::pageLogicalHeightForOffset(LayoutUnit offset) const { RenderRegion* region = regionAtBlockOffset(offset); return region ? region->pageLogicalHeight() : ZERO_LAYOUT_UNIT; }
void RenderMultiColumnFlowThread::updateMinimumPageHeight(const RenderBlock* block, LayoutUnit offset, LayoutUnit minHeight) { if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(block, offset))) multicolSet->updateMinimumColumnHeight(minHeight); }
void RenderMultiColumnFlowThread::setPageBreak(const RenderBlock* block, LayoutUnit offset, LayoutUnit spaceShortage) { if (RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(regionAtBlockOffset(block, offset))) multicolSet->recordSpaceShortage(spaceShortage); }