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
31 #include "core/rendering/RenderRegion.h"
33 #include "core/css/resolver/StyleResolver.h"
34 #include "core/rendering/FlowThreadController.h"
35 #include "core/rendering/HitTestLocation.h"
36 #include "core/rendering/PaintInfo.h"
37 #include "core/rendering/RenderFlowThread.h"
38 #include "core/rendering/RenderView.h"
42 RenderRegion::RenderRegion(Element* element, RenderFlowThread* flowThread)
43 : RenderBlockFlow(element)
44 , m_flowThread(flowThread)
49 LayoutUnit RenderRegion::pageLogicalWidth() const
52 return m_flowThread->isHorizontalWritingMode() ? contentWidth() : contentHeight();
55 LayoutUnit RenderRegion::pageLogicalHeight() const
58 return m_flowThread->isHorizontalWritingMode() ? contentHeight() : contentWidth();
61 LayoutRect RenderRegion::flowThreadPortionOverflowRect() const
63 return overflowRectForFlowThreadPortion(flowThreadPortionRect(), isFirstRegion(), isLastRegion());
66 LayoutRect RenderRegion::overflowRectForFlowThreadPortion(const LayoutRect& flowThreadPortionRect, bool isFirstPortion, bool isLastPortion) const
70 if (hasOverflowClip())
71 return flowThreadPortionRect;
73 LayoutRect flowThreadOverflow = m_flowThread->visualOverflowRect();
75 // Only clip along the flow thread axis.
77 if (m_flowThread->isHorizontalWritingMode()) {
78 LayoutUnit minY = isFirstPortion ? flowThreadOverflow.y() : flowThreadPortionRect.y();
79 LayoutUnit maxY = isLastPortion ? std::max(flowThreadPortionRect.maxY(), flowThreadOverflow.maxY()) : flowThreadPortionRect.maxY();
80 LayoutUnit minX = std::min(flowThreadPortionRect.x(), flowThreadOverflow.x());
81 LayoutUnit maxX = std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX());
82 clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
84 LayoutUnit minX = isFirstPortion ? flowThreadOverflow.x() : flowThreadPortionRect.x();
85 LayoutUnit maxX = isLastPortion ? std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()) : flowThreadPortionRect.maxX();
86 LayoutUnit minY = std::min(flowThreadPortionRect.y(), (flowThreadOverflow.y()));
87 LayoutUnit maxY = std::max(flowThreadPortionRect.y(), (flowThreadOverflow.maxY()));
88 clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
94 bool RenderRegion::isFirstRegion() const
98 return m_flowThread->firstRegion() == this;
101 bool RenderRegion::isLastRegion() const
105 return m_flowThread->lastRegion() == this;
108 void RenderRegion::layoutBlock(bool relayoutChildren)
110 RenderBlockFlow::layoutBlock(relayoutChildren);
112 // FIXME: We need to find a way to set up overflow properly. Our flow thread hasn't gotten a layout
113 // yet, so we can't look to it for correct information. It's possible we could wait until after the RenderFlowThread
114 // gets a layout, and then try to propagate overflow information back to the region, and then mark for a second layout.
115 // That second layout would then be able to use the information from the RenderFlowThread to set up overflow.
117 // The big problem though is that overflow needs to be region-specific. We can't simply use the RenderFlowThread's global
118 // overflow values, since then we'd always think any narrow region had huge overflow (all the way to the width of the
119 // RenderFlowThread itself).
122 void RenderRegion::paintInvalidationOfFlowThreadContentRectangle(const LayoutRect& paintInvalidationRect, const LayoutRect& flowThreadPortionRect, const LayoutRect& flowThreadPortionOverflowRect, const LayoutPoint& regionLocation) const
126 // We only have to issue a paint invalidation in this region if the region rect intersects the paint invalidation rect.
127 LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect);
128 LayoutRect flippedFlowThreadPortionOverflowRect(flowThreadPortionOverflowRect);
129 flowThread()->flipForWritingMode(flippedFlowThreadPortionRect); // Put the region rects into physical coordinates.
130 flowThread()->flipForWritingMode(flippedFlowThreadPortionOverflowRect);
132 LayoutRect clippedRect(paintInvalidationRect);
133 clippedRect.intersect(flippedFlowThreadPortionOverflowRect);
134 if (clippedRect.isEmpty())
137 // Put the region rect into the region's physical coordinate space.
138 clippedRect.setLocation(regionLocation + (clippedRect.location() - flippedFlowThreadPortionRect.location()));
140 // Now switch to the region's writing mode coordinate space and let it issue paint invalidations itself.
141 flipForWritingMode(clippedRect);
143 invalidatePaintRectangle(clippedRect);
146 void RenderRegion::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
149 RenderBlockFlow::computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
153 minLogicalWidth = m_flowThread->minPreferredLogicalWidth();
154 maxLogicalWidth = m_flowThread->maxPreferredLogicalWidth();