2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include "RenderFlowThread.h"
34 #include "FlowThreadController.h"
35 #include "HitTestRequest.h"
36 #include "HitTestResult.h"
38 #include "PaintInfo.h"
39 #include "RenderBoxRegionInfo.h"
40 #include "RenderLayer.h"
41 #include "RenderRegion.h"
42 #include "RenderView.h"
43 #include "TransformState.h"
44 #include "WebKitNamedFlow.h"
48 RenderFlowThread::RenderFlowThread(Node* node)
50 , m_hasValidRegions(false)
51 , m_regionsInvalidated(false)
52 , m_regionsHaveUniformLogicalWidth(true)
53 , m_regionsHaveUniformLogicalHeight(true)
55 , m_hasRegionsWithStyling(false)
56 , m_dispatchRegionLayoutUpdateEvent(false)
57 , m_pageLogicalHeightChanged(false)
59 ASSERT(node->document()->cssRegionsEnabled());
60 setIsAnonymous(false);
61 setInRenderFlowThread();
64 PassRefPtr<RenderStyle> RenderFlowThread::createFlowThreadStyle(RenderStyle* parentStyle)
66 RefPtr<RenderStyle> newStyle(RenderStyle::create());
67 newStyle->inheritFrom(parentStyle);
68 newStyle->setDisplay(BLOCK);
69 newStyle->setPosition(AbsolutePosition);
70 newStyle->setZIndex(0);
71 newStyle->setLeft(Length(0, Fixed));
72 newStyle->setTop(Length(0, Fixed));
73 newStyle->setWidth(Length(100, Percent));
74 newStyle->setHeight(Length(100, Percent));
75 newStyle->font().update(0);
77 return newStyle.release();
80 void RenderFlowThread::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
82 RenderBlock::styleDidChange(diff, oldStyle);
84 if (oldStyle && oldStyle->writingMode() != style()->writingMode())
85 m_regionsInvalidated = true;
88 void RenderFlowThread::removeFlowChildInfo(RenderObject* child)
91 removeRenderBoxRegionInfo(toRenderBox(child));
92 clearRenderObjectCustomStyle(child);
95 void RenderFlowThread::addRegionToThread(RenderRegion* renderRegion)
98 m_regionList.add(renderRegion);
99 renderRegion->setIsValid(true);
101 checkRegionsWithStyling();
104 void RenderFlowThread::removeRegionFromThread(RenderRegion* renderRegion)
106 ASSERT(renderRegion);
107 m_regionRangeMap.clear();
108 m_regionList.remove(renderRegion);
110 checkRegionsWithStyling();
113 class CurrentRenderFlowThreadDisabler {
114 WTF_MAKE_NONCOPYABLE(CurrentRenderFlowThreadDisabler);
116 CurrentRenderFlowThreadDisabler(RenderView* view)
118 , m_renderFlowThread(0)
120 m_renderFlowThread = m_view->flowThreadController()->currentRenderFlowThread();
121 if (m_renderFlowThread)
122 view->flowThreadController()->setCurrentRenderFlowThread(0);
124 ~CurrentRenderFlowThreadDisabler()
126 if (m_renderFlowThread)
127 m_view->flowThreadController()->setCurrentRenderFlowThread(m_renderFlowThread);
131 RenderFlowThread* m_renderFlowThread;
134 void RenderFlowThread::layout()
136 m_pageLogicalHeightChanged = m_regionsInvalidated && everHadLayout();
137 if (m_regionsInvalidated) {
138 m_regionsInvalidated = false;
139 m_hasValidRegions = false;
140 m_regionsHaveUniformLogicalWidth = true;
141 m_regionsHaveUniformLogicalHeight = true;
142 m_regionRangeMap.clear();
143 LayoutUnit previousRegionLogicalWidth = 0;
144 LayoutUnit previousRegionLogicalHeight = 0;
146 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
147 RenderRegion* region = *iter;
148 if (!region->isValid())
150 ASSERT(!region->needsLayout());
152 region->deleteAllRenderBoxRegionInfo();
154 LayoutUnit regionLogicalWidth = region->pageLogicalWidth();
155 LayoutUnit regionLogicalHeight = region->pageLogicalHeight();
157 if (!m_hasValidRegions)
158 m_hasValidRegions = true;
160 if (m_regionsHaveUniformLogicalWidth && previousRegionLogicalWidth != regionLogicalWidth)
161 m_regionsHaveUniformLogicalWidth = false;
162 if (m_regionsHaveUniformLogicalHeight && previousRegionLogicalHeight != regionLogicalHeight)
163 m_regionsHaveUniformLogicalHeight = false;
166 previousRegionLogicalWidth = regionLogicalWidth;
169 updateLogicalWidth(); // Called to get the maximum logical width for the region.
171 LayoutUnit logicalHeight = 0;
172 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
173 RenderRegion* region = *iter;
174 if (!region->isValid())
177 LayoutUnit regionLogicalWidth = region->pageLogicalWidth();
178 LayoutUnit regionLogicalHeight = region->logicalHeightOfAllFlowThreadContent();
180 LayoutRect regionRect(style()->direction() == LTR ? ZERO_LAYOUT_UNIT : logicalWidth() - regionLogicalWidth, logicalHeight, regionLogicalWidth, regionLogicalHeight);
181 region->setFlowThreadPortionRect(isHorizontalWritingMode() ? regionRect : regionRect.transposedRect());
182 logicalHeight += regionLogicalHeight;
187 CurrentRenderFlowThreadMaintainer currentFlowThreadSetter(this);
188 RenderBlock::layout();
190 m_pageLogicalHeightChanged = false;
193 lastRegion()->expandToEncompassFlowThreadContentsIfNeeded();
195 if (shouldDispatchRegionLayoutUpdateEvent())
196 dispatchRegionLayoutUpdateEvent();
199 void RenderFlowThread::updateLogicalWidth()
201 LayoutUnit logicalWidth = 0;
202 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
203 RenderRegion* region = *iter;
204 if (!region->isValid())
206 ASSERT(!region->needsLayout());
207 logicalWidth = max(region->pageLogicalWidth(), logicalWidth);
209 setLogicalWidth(logicalWidth);
211 // If the regions have non-uniform logical widths, then insert inset information for the RenderFlowThread.
212 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
213 RenderRegion* region = *iter;
214 if (!region->isValid())
217 LayoutUnit regionLogicalWidth = region->pageLogicalWidth();
218 if (regionLogicalWidth != logicalWidth) {
219 LayoutUnit logicalLeft = style()->direction() == LTR ? ZERO_LAYOUT_UNIT : logicalWidth - regionLogicalWidth;
220 region->setRenderBoxRegionInfo(this, logicalLeft, regionLogicalWidth, false);
225 void RenderFlowThread::updateLogicalHeight()
227 LayoutUnit logicalHeight = 0;
229 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
230 RenderRegion* region = *iter;
231 if (!region->isValid())
233 ASSERT(!region->needsLayout());
234 logicalHeight += region->logicalHeightOfAllFlowThreadContent();
237 setLogicalHeight(logicalHeight);
240 void RenderFlowThread::paintFlowThreadPortionInRegion(PaintInfo& paintInfo, RenderRegion* region, LayoutRect flowThreadPortionRect, LayoutRect flowThreadPortionOverflowRect, const LayoutPoint& paintOffset) const
242 GraphicsContext* context = paintInfo.context;
246 // Adjust the clipping rect for the region.
247 // paintOffset contains the offset where the painting should occur
248 // adjusted with the region padding and border.
249 LayoutRect regionClippingRect(paintOffset + (flowThreadPortionOverflowRect.location() - flowThreadPortionRect.location()), flowThreadPortionOverflowRect.size());
251 PaintInfo info(paintInfo);
252 info.rect.intersect(pixelSnappedIntRect(regionClippingRect));
254 if (!info.rect.isEmpty()) {
257 context->clip(regionClippingRect);
259 // RenderFlowThread should start painting its content in a position that is offset
260 // from the region rect's current position. The amount of offset is equal to the location of
261 // the flow thread portion in the flow thread's local coordinates.
262 IntPoint renderFlowThreadOffset;
263 if (style()->isFlippedBlocksWritingMode()) {
264 LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect);
265 flipForWritingMode(flippedFlowThreadPortionRect);
266 renderFlowThreadOffset = roundedIntPoint(paintOffset - flippedFlowThreadPortionRect.location());
268 renderFlowThreadOffset = roundedIntPoint(paintOffset - flowThreadPortionRect.location());
270 context->translate(renderFlowThreadOffset.x(), renderFlowThreadOffset.y());
271 info.rect.moveBy(-renderFlowThreadOffset);
273 layer()->paint(context, info.rect, 0, 0, region, RenderLayer::PaintLayerTemporaryClipRects);
279 bool RenderFlowThread::hitTestFlowThreadPortionInRegion(RenderRegion* region, LayoutRect flowThreadPortionRect, LayoutRect flowThreadPortionOverflowRect, const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset) const
281 LayoutRect regionClippingRect(accumulatedOffset + (flowThreadPortionOverflowRect.location() - flowThreadPortionRect.location()), flowThreadPortionOverflowRect.size());
282 if (!regionClippingRect.contains(locationInContainer.point()))
285 LayoutSize renderFlowThreadOffset;
286 if (style()->isFlippedBlocksWritingMode()) {
287 LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect);
288 flipForWritingMode(flippedFlowThreadPortionRect);
289 renderFlowThreadOffset = accumulatedOffset - flippedFlowThreadPortionRect.location();
291 renderFlowThreadOffset = accumulatedOffset - flowThreadPortionRect.location();
293 // Always ignore clipping, since the RenderFlowThread has nothing to do with the bounds of the FrameView.
294 HitTestRequest newRequest(request.type() | HitTestRequest::IgnoreClipping);
296 // Make a new temporary HitTestLocation in the new region.
297 HitTestLocation newHitTestLocation(locationInContainer, -renderFlowThreadOffset, region);
299 bool isPointInsideFlowThread = layer()->hitTest(newRequest, newHitTestLocation, result);
301 // FIXME: Should we set result.m_localPoint back to the RenderRegion's coordinate space or leave it in the RenderFlowThread's coordinate
302 // space? Right now it's staying in the RenderFlowThread's coordinate space, which may end up being ok. We will know more when we get around to
303 // patching positionForPoint.
304 return isPointInsideFlowThread;
307 bool RenderFlowThread::shouldRepaint(const LayoutRect& r) const
309 if (view()->printing() || r.isEmpty())
315 void RenderFlowThread::repaintRectangleInRegions(const LayoutRect& repaintRect, bool immediate)
317 if (!shouldRepaint(repaintRect) || !hasValidRegionInfo())
320 LayoutStateDisabler layoutStateDisabler(view()); // We can't use layout state to repaint, since the regions are somewhere else.
322 // We can't use currentFlowThread as it is possible to have interleaved flow threads and the wrong one could be used.
323 // Let each region figure out the proper enclosing flow thread.
324 CurrentRenderFlowThreadDisabler disabler(view());
326 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
327 RenderRegion* region = *iter;
328 if (!region->isValid())
331 region->repaintFlowThreadContent(repaintRect, immediate);
335 RenderRegion* RenderFlowThread::regionAtBlockOffset(LayoutUnit offset, bool extendLastRegion) const
337 ASSERT(!m_regionsInvalidated);
339 // If no region matches the position and extendLastRegion is true, it will return
340 // the last valid region. It is similar to auto extending the size of the last region.
341 RenderRegion* lastValidRegion = 0;
343 // FIXME: The regions are always in order, optimize this search.
344 bool useHorizontalWritingMode = isHorizontalWritingMode();
345 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
346 RenderRegion* region = *iter;
347 if (!region->isValid())
353 LayoutRect regionRect = region->flowThreadPortionRect();
354 if ((useHorizontalWritingMode && offset < regionRect.maxY()) || (!useHorizontalWritingMode && offset < regionRect.maxX()))
357 if (extendLastRegion || region->isRenderRegionSet())
358 lastValidRegion = region;
361 return lastValidRegion;
364 LayoutUnit RenderFlowThread::pageLogicalTopForOffset(LayoutUnit offset) const
366 RenderRegion* region = regionAtBlockOffset(offset);
367 return region ? region->pageLogicalTopForOffset(offset) : ZERO_LAYOUT_UNIT;
370 LayoutUnit RenderFlowThread::pageLogicalWidthForOffset(LayoutUnit offset) const
372 RenderRegion* region = regionAtBlockOffset(offset, true);
373 return region ? region->pageLogicalWidth() : contentLogicalWidth();
376 LayoutUnit RenderFlowThread::pageLogicalHeightForOffset(LayoutUnit offset) const
378 RenderRegion* region = regionAtBlockOffset(offset);
379 return region ? region->pageLogicalHeight() : ZERO_LAYOUT_UNIT;
382 LayoutUnit RenderFlowThread::pageRemainingLogicalHeightForOffset(LayoutUnit offset, PageBoundaryRule pageBoundaryRule) const
384 RenderRegion* region = regionAtBlockOffset(offset);
386 return ZERO_LAYOUT_UNIT;
388 LayoutUnit pageLogicalTop = region->pageLogicalTopForOffset(offset);
389 LayoutUnit pageLogicalHeight = region->pageLogicalHeight();
390 LayoutUnit pageLogicalBottom = pageLogicalTop + pageLogicalHeight;
391 LayoutUnit remainingHeight = pageLogicalBottom - offset;
392 if (pageBoundaryRule == IncludePageBoundary) {
393 // If IncludePageBoundary is set, the line exactly on the top edge of a
394 // region will act as being part of the previous region.
395 remainingHeight = intMod(remainingHeight, pageLogicalHeight);
397 return remainingHeight;
400 RenderRegion* RenderFlowThread::mapFromFlowToRegion(TransformState& transformState) const
402 if (!hasValidRegionInfo())
405 LayoutRect boxRect = transformState.mappedQuad().enclosingBoundingBox();
406 flipForWritingMode(boxRect);
408 // FIXME: We need to refactor RenderObject::absoluteQuads to be able to split the quads across regions,
409 // for now we just take the center of the mapped enclosing box and map it to a region.
410 // Note: Using the center in order to avoid rounding errors.
412 LayoutPoint center = boxRect.center();
413 RenderRegion* renderRegion = regionAtBlockOffset(isHorizontalWritingMode() ? center.y() : center.x(), true);
417 LayoutRect flippedRegionRect(renderRegion->flowThreadPortionRect());
418 flipForWritingMode(flippedRegionRect);
420 transformState.move(renderRegion->contentBoxRect().location() - flippedRegionRect.location());
425 void RenderFlowThread::removeRenderBoxRegionInfo(RenderBox* box)
430 RenderRegion* startRegion;
431 RenderRegion* endRegion;
432 getRegionRangeForBox(box, startRegion, endRegion);
434 for (RenderRegionList::iterator iter = m_regionList.find(startRegion); iter != m_regionList.end(); ++iter) {
435 RenderRegion* region = *iter;
436 if (!region->isValid())
438 region->removeRenderBoxRegionInfo(box);
439 if (region == endRegion)
444 // We have to make sure we did not leave any RenderBoxRegionInfo attached.
445 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
446 RenderRegion* region = *iter;
447 if (!region->isValid())
449 ASSERT(!region->renderBoxRegionInfo(box));
453 m_regionRangeMap.remove(box);
456 bool RenderFlowThread::logicalWidthChangedInRegions(const RenderBlock* block, LayoutUnit offsetFromLogicalTopOfFirstPage)
458 if (!hasRegions() || block == this) // Not necessary, since if any region changes, we do a full pagination relayout anyway.
461 RenderRegion* startRegion;
462 RenderRegion* endRegion;
463 getRegionRangeForBox(block, startRegion, endRegion);
465 for (RenderRegionList::iterator iter = m_regionList.find(startRegion); iter != m_regionList.end(); ++iter) {
466 RenderRegion* region = *iter;
468 if (!region->isValid())
471 ASSERT(!region->needsLayout());
473 OwnPtr<RenderBoxRegionInfo> oldInfo = region->takeRenderBoxRegionInfo(block);
477 LayoutUnit oldLogicalWidth = oldInfo->logicalWidth();
478 RenderBoxRegionInfo* newInfo = block->renderBoxRegionInfo(region, offsetFromLogicalTopOfFirstPage);
479 if (!newInfo || newInfo->logicalWidth() != oldLogicalWidth)
482 if (region == endRegion)
489 LayoutUnit RenderFlowThread::contentLogicalWidthOfFirstRegion() const
491 if (!hasValidRegionInfo())
493 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
494 RenderRegion* region = *iter;
495 if (!region->isValid())
497 return isHorizontalWritingMode() ? region->contentWidth() : region->contentHeight();
499 ASSERT_NOT_REACHED();
503 LayoutUnit RenderFlowThread::contentLogicalHeightOfFirstRegion() const
505 if (!hasValidRegionInfo())
507 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
508 RenderRegion* region = *iter;
509 if (!region->isValid())
511 return isHorizontalWritingMode() ? region->contentHeight() : region->contentWidth();
513 ASSERT_NOT_REACHED();
517 LayoutUnit RenderFlowThread::contentLogicalLeftOfFirstRegion() const
519 if (!hasValidRegionInfo())
521 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
522 RenderRegion* region = *iter;
523 if (!region->isValid())
525 return isHorizontalWritingMode() ? region->flowThreadPortionRect().x() : region->flowThreadPortionRect().y();
527 ASSERT_NOT_REACHED();
531 RenderRegion* RenderFlowThread::firstRegion() const
533 if (!hasValidRegionInfo())
535 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
536 RenderRegion* region = *iter;
537 if (!region->isValid())
544 RenderRegion* RenderFlowThread::lastRegion() const
546 if (!hasValidRegionInfo())
548 for (RenderRegionList::const_reverse_iterator iter = m_regionList.rbegin(); iter != m_regionList.rend(); ++iter) {
549 RenderRegion* region = *iter;
550 if (!region->isValid())
557 void RenderFlowThread::clearRenderObjectCustomStyle(const RenderObject* object,
558 const RenderRegion* oldStartRegion, const RenderRegion* oldEndRegion,
559 const RenderRegion* newStartRegion, const RenderRegion* newEndRegion)
561 // Clear the styles for the object in the regions.
562 // The styles are not cleared for the regions that are contained in both ranges.
563 bool insideOldRegionRange = false;
564 bool insideNewRegionRange = false;
565 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
566 RenderRegion* region = *iter;
568 if (oldStartRegion == region)
569 insideOldRegionRange = true;
570 if (newStartRegion == region)
571 insideNewRegionRange = true;
573 if (!(insideOldRegionRange && insideNewRegionRange))
574 region->clearObjectStyleInRegion(object);
576 if (oldEndRegion == region)
577 insideOldRegionRange = false;
578 if (newEndRegion == region)
579 insideNewRegionRange = false;
583 void RenderFlowThread::setRegionRangeForBox(const RenderBox* box, LayoutUnit offsetFromLogicalTopOfFirstPage)
588 // FIXME: Not right for differing writing-modes.
589 RenderRegion* startRegion = regionAtBlockOffset(offsetFromLogicalTopOfFirstPage, true);
590 RenderRegion* endRegion = regionAtBlockOffset(offsetFromLogicalTopOfFirstPage + box->logicalHeight(), true);
591 RenderRegionRangeMap::iterator it = m_regionRangeMap.find(box);
592 if (it == m_regionRangeMap.end()) {
593 m_regionRangeMap.set(box, RenderRegionRange(startRegion, endRegion));
594 clearRenderObjectCustomStyle(box);
598 // If nothing changed, just bail.
599 RenderRegionRange& range = it->second;
600 if (range.startRegion() == startRegion && range.endRegion() == endRegion)
603 // Delete any info that we find before our new startRegion and after our new endRegion.
604 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
605 RenderRegion* region = *iter;
606 if (region == startRegion) {
607 iter = m_regionList.find(endRegion);
611 region->removeRenderBoxRegionInfo(box);
613 if (region == range.endRegion())
617 clearRenderObjectCustomStyle(box, range.startRegion(), range.endRegion(), startRegion, endRegion);
618 range.setRange(startRegion, endRegion);
621 void RenderFlowThread::getRegionRangeForBox(const RenderBox* box, RenderRegion*& startRegion, RenderRegion*& endRegion) const
625 RenderRegionRangeMap::const_iterator it = m_regionRangeMap.find(box);
626 if (it == m_regionRangeMap.end())
629 const RenderRegionRange& range = it->second;
630 startRegion = range.startRegion();
631 endRegion = range.endRegion();
632 ASSERT(m_regionList.contains(startRegion) && m_regionList.contains(endRegion));
635 void RenderFlowThread::computeOverflowStateForRegions(LayoutUnit oldClientAfterEdge)
637 LayoutUnit height = oldClientAfterEdge;
638 // FIXME: the visual overflow of middle region (if it is the last one to contain any content in a render flow thread)
639 // might not be taken into account because the render flow thread height is greater that that regions height + its visual overflow
640 // because of how computeLogicalHeight is implemented for RenderFlowThread (as a sum of all regions height).
641 // This means that the middle region will be marked as fit (even if it has visual overflow flowing into the next region)
642 if (hasRenderOverflow() && ( (isHorizontalWritingMode() && visualOverflowRect().maxY() > clientBoxRect().maxY())
643 || (!isHorizontalWritingMode() && visualOverflowRect().maxX() > clientBoxRect().maxX())))
644 height = isHorizontalWritingMode() ? visualOverflowRect().maxY() : visualOverflowRect().maxX();
646 RenderRegion* lastReg = lastRegion();
647 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
648 RenderRegion* region = *iter;
649 if (!region->isValid()) {
650 region->setRegionState(RenderRegion::RegionUndefined);
653 LayoutUnit flowMin = height - (isHorizontalWritingMode() ? region->flowThreadPortionRect().y() : region->flowThreadPortionRect().x());
654 LayoutUnit flowMax = height - (isHorizontalWritingMode() ? region->flowThreadPortionRect().maxY() : region->flowThreadPortionRect().maxX());
655 RenderRegion::RegionState previousState = region->regionState();
656 RenderRegion::RegionState state = RenderRegion::RegionFit;
658 state = RenderRegion::RegionEmpty;
659 if (flowMax > 0 && region == lastReg)
660 state = RenderRegion::RegionOverset;
661 region->setRegionState(state);
662 // determine whether the NamedFlow object should dispatch a regionLayoutUpdate event
663 // FIXME: currently it cannot determine whether a region whose regionOverset state remained either "fit" or "overset" has actually
664 // changed, so it just assumes that the NamedFlow should dispatch the event
665 if (previousState != state
666 || state == RenderRegion::RegionFit
667 || state == RenderRegion::RegionOverset)
668 setDispatchRegionLayoutUpdateEvent(true);
671 // With the regions overflow state computed we can also set the overset flag for the named flow.
672 // If there are no valid regions in the chain, overset is true.
673 m_overset = lastReg ? lastReg->regionState() == RenderRegion::RegionOverset : true;
676 bool RenderFlowThread::regionInRange(const RenderRegion* targetRegion, const RenderRegion* startRegion, const RenderRegion* endRegion) const
678 ASSERT(targetRegion);
680 for (RenderRegionList::const_iterator it = m_regionList.find(const_cast<RenderRegion*>(startRegion)); it != m_regionList.end(); ++it) {
681 const RenderRegion* currRegion = *it;
682 if (!currRegion->isValid())
684 if (targetRegion == currRegion)
686 if (currRegion == endRegion)
693 // Check if the content is flown into at least a region with region styling rules.
694 void RenderFlowThread::checkRegionsWithStyling()
696 bool hasRegionsWithStyling = false;
697 for (RenderRegionList::iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
698 RenderRegion* region = *iter;
699 if (!region->isValid())
701 if (region->hasCustomRegionStyle()) {
702 hasRegionsWithStyling = true;
706 m_hasRegionsWithStyling = hasRegionsWithStyling;
709 bool RenderFlowThread::objectInFlowRegion(const RenderObject* object, const RenderRegion* region) const
714 if (!object->inRenderFlowThread())
716 if (object->enclosingRenderFlowThread() != this)
718 if (!m_regionList.contains(const_cast<RenderRegion*>(region)))
721 RenderBox* enclosingBox = object->enclosingBox();
722 RenderRegion* enclosingBoxStartRegion = 0;
723 RenderRegion* enclosingBoxEndRegion = 0;
724 getRegionRangeForBox(enclosingBox, enclosingBoxStartRegion, enclosingBoxEndRegion);
725 if (!regionInRange(region, enclosingBoxStartRegion, enclosingBoxEndRegion))
731 LayoutRect objectABBRect = object->absoluteBoundingBoxRect(true);
732 if (!objectABBRect.width())
733 objectABBRect.setWidth(1);
734 if (!objectABBRect.height())
735 objectABBRect.setHeight(1);
736 if (objectABBRect.intersects(region->absoluteBoundingBoxRect(true)))
739 if (region == lastRegion()) {
740 // If the object does not intersect any of the enclosing box regions
741 // then the object is in last region.
742 for (RenderRegionList::const_iterator it = m_regionList.find(enclosingBoxStartRegion); it != m_regionList.end(); ++it) {
743 const RenderRegion* currRegion = *it;
744 if (!region->isValid())
746 if (currRegion == region)
748 if (objectABBRect.intersects(currRegion->absoluteBoundingBoxRect(true)))
758 unsigned RenderFlowThread::autoLogicalHeightRegionsCount() const
760 unsigned autoLogicalHeightRegions = 0;
761 for (RenderRegionList::const_iterator iter = m_regionList.begin(); iter != m_regionList.end(); ++iter) {
762 const RenderRegion* region = *iter;
763 if (!region->isValid()) {
764 ASSERT(!region->hasAutoLogicalHeight());
768 if (region->hasAutoLogicalHeight())
769 autoLogicalHeightRegions++;
772 return autoLogicalHeightRegions;
776 CurrentRenderFlowThreadMaintainer::CurrentRenderFlowThreadMaintainer(RenderFlowThread* renderFlowThread)
777 : m_renderFlowThread(renderFlowThread)
779 if (!m_renderFlowThread)
781 RenderView* view = m_renderFlowThread->view();
782 ASSERT(!view->flowThreadController()->currentRenderFlowThread());
783 view->flowThreadController()->setCurrentRenderFlowThread(m_renderFlowThread);
786 CurrentRenderFlowThreadMaintainer::~CurrentRenderFlowThreadMaintainer()
788 if (!m_renderFlowThread)
790 RenderView* view = m_renderFlowThread->view();
791 ASSERT(view->flowThreadController()->currentRenderFlowThread() == m_renderFlowThread);
792 view->flowThreadController()->setCurrentRenderFlowThread(0);
796 } // namespace WebCore