summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/RenderRegion.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/RenderRegion.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/RenderRegion.cpp')
-rw-r--r--Source/WebCore/rendering/RenderRegion.cpp208
1 files changed, 86 insertions, 122 deletions
diff --git a/Source/WebCore/rendering/RenderRegion.cpp b/Source/WebCore/rendering/RenderRegion.cpp
index 93f519c57..9c429e57a 100644
--- a/Source/WebCore/rendering/RenderRegion.cpp
+++ b/Source/WebCore/rendering/RenderRegion.cpp
@@ -35,7 +35,6 @@
#include "HitTestResult.h"
#include "IntRect.h"
#include "LayoutRepainter.h"
-#include "PaintInfo.h"
#include "Range.h"
#include "RenderBoxRegionInfo.h"
#include "RenderInline.h"
@@ -48,18 +47,18 @@
namespace WebCore {
-RenderRegion::RenderRegion(Element& element, PassRef<RenderStyle> style, RenderFlowThread* flowThread)
- : RenderBlockFlow(element, std::move(style))
+RenderRegion::RenderRegion(Element& element, RenderStyle&& style, RenderFlowThread* flowThread)
+ : RenderBlockFlow(element, WTFMove(style))
, m_flowThread(flowThread)
- , m_parentNamedFlowThread(0)
+ , m_parentNamedFlowThread(nullptr)
, m_isValid(false)
{
}
-RenderRegion::RenderRegion(Document& document, PassRef<RenderStyle> style, RenderFlowThread* flowThread)
- : RenderBlockFlow(document, std::move(style))
+RenderRegion::RenderRegion(Document& document, RenderStyle&& style, RenderFlowThread* flowThread)
+ : RenderBlockFlow(document, WTFMove(style))
, m_flowThread(flowThread)
- , m_parentNamedFlowThread(0)
+ , m_parentNamedFlowThread(nullptr)
, m_isValid(false)
{
}
@@ -104,24 +103,23 @@ LayoutPoint RenderRegion::mapRegionPointIntoFlowThreadCoordinates(const LayoutPo
return isHorizontalWritingMode() ? pointInThread : pointInThread.transposedPoint();
}
-VisiblePosition RenderRegion::positionForPoint(const LayoutPoint& point)
+VisiblePosition RenderRegion::positionForPoint(const LayoutPoint& point, const RenderRegion* region)
{
- ASSERT(m_flowThread);
if (!isValid() || !m_flowThread->firstChild()) // checking for empty region blocks.
- return RenderBlock::positionForPoint(point);
+ return RenderBlock::positionForPoint(point, region);
- return toRenderBlock(m_flowThread->firstChild())->positionForPoint(mapRegionPointIntoFlowThreadCoordinates(point));
+ return m_flowThread->positionForPoint(mapRegionPointIntoFlowThreadCoordinates(point), this);
}
LayoutUnit RenderRegion::pageLogicalWidth() const
{
- ASSERT(m_flowThread);
+ ASSERT(isValid());
return m_flowThread->isHorizontalWritingMode() ? contentWidth() : contentHeight();
}
LayoutUnit RenderRegion::pageLogicalHeight() const
{
- ASSERT(m_flowThread);
+ ASSERT(isValid());
return m_flowThread->isHorizontalWritingMode() ? contentHeight() : contentWidth();
}
@@ -150,61 +148,32 @@ LayoutPoint RenderRegion::flowThreadPortionLocation() const
return portionLocation;
}
-RenderLayer* RenderRegion::regionContainerLayer() const
-{
- ASSERT(parent() && parent()->isRenderNamedFlowFragmentContainer());
- return toRenderBlockFlow(parent())->layer();
-}
-
LayoutRect RenderRegion::overflowRectForFlowThreadPortion(const LayoutRect& flowThreadPortionRect, bool isFirstPortion, bool isLastPortion, OverflowType overflowType)
{
ASSERT(isValid());
-
- bool isLastRegionWithRegionFragmentBreak = (isLastPortion && (style().regionFragment() == BreakRegionFragment));
- if (hasOverflowClip() || isLastRegionWithRegionFragmentBreak)
+ if (shouldClipFlowThreadContent())
return flowThreadPortionRect;
- LayoutRect flowThreadOverflow = overflowType == VisualOverflow ? visualOverflowRectForBox(m_flowThread) : layoutOverflowRectForBox(m_flowThread);
-
- // We are interested about the outline size only when computing the visual overflow.
- LayoutUnit outlineSize = overflowType == VisualOverflow ? LayoutUnit(maximalOutlineSize(PaintPhaseOutline)) : LayoutUnit();
+ LayoutRect flowThreadOverflow = overflowType == VisualOverflow ? visualOverflowRectForBox(*m_flowThread) : layoutOverflowRectForBox(m_flowThread);
LayoutRect clipRect;
if (m_flowThread->isHorizontalWritingMode()) {
- LayoutUnit minY = isFirstPortion ? (flowThreadOverflow.y() - outlineSize) : flowThreadPortionRect.y();
- LayoutUnit maxY = isLastPortion ? std::max(flowThreadPortionRect.maxY(), flowThreadOverflow.maxY()) + outlineSize : flowThreadPortionRect.maxY();
+ LayoutUnit minY = isFirstPortion ? flowThreadOverflow.y() : flowThreadPortionRect.y();
+ LayoutUnit maxY = isLastPortion ? std::max(flowThreadPortionRect.maxY(), flowThreadOverflow.maxY()) : flowThreadPortionRect.maxY();
bool clipX = style().overflowX() != OVISIBLE;
- LayoutUnit minX = clipX ? flowThreadPortionRect.x() : std::min(flowThreadPortionRect.x(), flowThreadOverflow.x() - outlineSize);
- LayoutUnit maxX = clipX ? flowThreadPortionRect.maxX() : std::max(flowThreadPortionRect.maxX(), (flowThreadOverflow.maxX() + outlineSize));
+ LayoutUnit minX = clipX ? flowThreadPortionRect.x() : std::min(flowThreadPortionRect.x(), flowThreadOverflow.x());
+ LayoutUnit maxX = clipX ? flowThreadPortionRect.maxX() : std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX());
clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
} else {
- LayoutUnit minX = isFirstPortion ? (flowThreadOverflow.x() - outlineSize) : flowThreadPortionRect.x();
- LayoutUnit maxX = isLastPortion ? std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()) + outlineSize : flowThreadPortionRect.maxX();
+ LayoutUnit minX = isFirstPortion ? flowThreadOverflow.x() : flowThreadPortionRect.x();
+ LayoutUnit maxX = isLastPortion ? std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()) : flowThreadPortionRect.maxX();
bool clipY = style().overflowY() != OVISIBLE;
- LayoutUnit minY = clipY ? flowThreadPortionRect.y() : std::min(flowThreadPortionRect.y(), (flowThreadOverflow.y() - outlineSize));
- LayoutUnit maxY = clipY ? flowThreadPortionRect.maxY() : std::max(flowThreadPortionRect.y(), (flowThreadOverflow.maxY() + outlineSize));
+ LayoutUnit minY = clipY ? flowThreadPortionRect.y() : std::min(flowThreadPortionRect.y(), flowThreadOverflow.y());
+ LayoutUnit maxY = clipY ? flowThreadPortionRect.maxY() : std::max(flowThreadPortionRect.y(), flowThreadOverflow.maxY());
clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
}
-
return clipRect;
}
-RegionOversetState RenderRegion::regionOversetState() const
-{
- ASSERT(generatingElement());
-
- if (!isValid())
- return RegionUndefined;
-
- return generatingElement()->regionOversetState();
-}
-
-void RenderRegion::setRegionOversetState(RegionOversetState state)
-{
- ASSERT(generatingElement());
-
- generatingElement()->setRegionOversetState(state);
-}
-
LayoutUnit RenderRegion::pageLogicalTopForOffset(LayoutUnit /* offset */) const
{
return flowThread()->isHorizontalWritingMode() ? flowThreadPortionRect().y() : flowThreadPortionRect().x();
@@ -223,12 +192,17 @@ bool RenderRegion::isLastRegion() const
return m_flowThread->lastRegion() == this;
}
-
+
+bool RenderRegion::shouldClipFlowThreadContent() const
+{
+ return hasOverflowClip();
+}
+
void RenderRegion::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBlockFlow::styleDidChange(diff, oldStyle);
- if (!m_flowThread)
+ if (!isValid())
return;
if (oldStyle && oldStyle->writingMode() != style().writingMode())
@@ -238,15 +212,8 @@ void RenderRegion::styleDidChange(StyleDifference diff, const RenderStyle* oldSt
void RenderRegion::computeOverflowFromFlowThread()
{
ASSERT(isValid());
-
- LayoutRect layoutRect;
- {
- // When getting the overflow from the flow thread we need to temporarly reset the current flow thread because
- // we're changing flows.
- CurrentRenderFlowThreadMaintainer flowThreadMaintainer(m_flowThread);
- layoutRect = layoutOverflowRectForBox(m_flowThread);
- }
+ LayoutRect layoutRect = layoutOverflowRectForBox(m_flowThread);
layoutRect.setLocation(contentBoxRect().location() + (layoutRect.location() - m_flowThreadPortionRect.location()));
// FIXME: Correctly adjust the layout overflow for writing modes.
@@ -259,12 +226,12 @@ void RenderRegion::computeOverflowFromFlowThread()
updateScrollInfoAfterLayout();
}
-void RenderRegion::repaintFlowThreadContent(const LayoutRect& repaintRect, bool immediate)
+void RenderRegion::repaintFlowThreadContent(const LayoutRect& repaintRect)
{
- repaintFlowThreadContentRectangle(repaintRect, immediate, flowThreadPortionRect(), contentBoxRect().location());
+ repaintFlowThreadContentRectangle(repaintRect, flowThreadPortionRect(), contentBoxRect().location());
}
-void RenderRegion::repaintFlowThreadContentRectangle(const LayoutRect& repaintRect, bool immediate, const LayoutRect& flowThreadPortionRect, const LayoutPoint& regionLocation, const LayoutRect* flowThreadPortionClipRect)
+void RenderRegion::repaintFlowThreadContentRectangle(const LayoutRect& repaintRect, const LayoutRect& flowThreadPortionRect, const LayoutPoint& regionLocation, const LayoutRect* flowThreadPortionClipRect)
{
ASSERT(isValid());
@@ -290,7 +257,7 @@ void RenderRegion::repaintFlowThreadContentRectangle(const LayoutRect& repaintRe
flipForWritingMode(clippedRect);
// Issue the repaint.
- repaintRectangle(clippedRect, immediate);
+ repaintRectangle(clippedRect);
}
void RenderRegion::installFlowThread()
@@ -308,16 +275,11 @@ void RenderRegion::installFlowThread()
}
m_parentNamedFlowThread = &*closestFlowThreadAncestor;
-
- // Do not take into account a region that links a flow with itself. The dependency
- // cannot change, so it is not worth adding it to the list.
- if (m_flowThread == m_parentNamedFlowThread)
- m_flowThread = nullptr;
}
void RenderRegion::attachRegion()
{
- if (documentBeingDestroyed())
+ if (renderTreeBeingDestroyed())
return;
// A region starts off invalid.
@@ -328,7 +290,7 @@ void RenderRegion::attachRegion()
// and we are attaching the region to the flow thread.
installFlowThread();
- if (!m_flowThread)
+ if (m_flowThread == m_parentNamedFlowThread)
return;
// Only after adding the region to the thread, the region is marked to be valid.
@@ -339,7 +301,7 @@ void RenderRegion::detachRegion()
{
if (m_flowThread)
m_flowThread->removeRegionFromThread(this);
- m_flowThread = 0;
+ m_flowThread = nullptr;
}
RenderBoxRegionInfo* RenderRegion::renderBoxRegionInfo(const RenderBox* box) const
@@ -353,18 +315,18 @@ RenderBoxRegionInfo* RenderRegion::setRenderBoxRegionInfo(const RenderBox* box,
{
ASSERT(isValid());
- OwnPtr<RenderBoxRegionInfo>& boxInfo = m_renderBoxRegionInfo.add(box, adoptPtr(new RenderBoxRegionInfo(logicalLeftInset, logicalRightInset, containingBlockChainIsInset))).iterator->value;
+ std::unique_ptr<RenderBoxRegionInfo>& boxInfo = m_renderBoxRegionInfo.add(box, std::make_unique<RenderBoxRegionInfo>(logicalLeftInset, logicalRightInset, containingBlockChainIsInset)).iterator->value;
return boxInfo.get();
}
-OwnPtr<RenderBoxRegionInfo> RenderRegion::takeRenderBoxRegionInfo(const RenderBox* box)
+std::unique_ptr<RenderBoxRegionInfo> RenderRegion::takeRenderBoxRegionInfo(const RenderBox* box)
{
return m_renderBoxRegionInfo.take(box);
}
-void RenderRegion::removeRenderBoxRegionInfo(const RenderBox* box)
+void RenderRegion::removeRenderBoxRegionInfo(const RenderBox& box)
{
- m_renderBoxRegionInfo.remove(box);
+ m_renderBoxRegionInfo.remove(&box);
}
void RenderRegion::deleteAllRenderBoxRegionInfo()
@@ -444,26 +406,18 @@ void RenderRegion::computePreferredLogicalWidths()
setPreferredLogicalWidthsDirty(false);
}
-void RenderRegion::getRanges(Vector<RefPtr<Range>>& rangeObjects) const
-{
- const RenderNamedFlowThread& namedFlow = view().flowThreadController().ensureRenderFlowThreadWithName(style().regionThread());
- namedFlow.getRanges(rangeObjects, this);
-}
-
-void RenderRegion::adjustRegionBoundsFromFlowThreadPortionRect(const IntPoint& layerOffset, IntRect& regionBounds)
+void RenderRegion::adjustRegionBoundsFromFlowThreadPortionRect(LayoutRect& regionBounds) const
{
LayoutRect flippedFlowThreadPortionRect = flowThreadPortionRect();
flowThread()->flipForWritingMode(flippedFlowThreadPortionRect);
- regionBounds.moveBy(roundedIntPoint(flippedFlowThreadPortionRect.location()));
-
- UNUSED_PARAM(layerOffset);
+ regionBounds.moveBy(flippedFlowThreadPortionRect.location());
}
void RenderRegion::ensureOverflowForBox(const RenderBox* box, RefPtr<RenderOverflow>& overflow, bool forceCreation)
{
- RenderFlowThread* flowThread = this->flowThread();
- ASSERT(flowThread);
-
+ ASSERT(m_flowThread->renderRegionList().contains(this));
+ ASSERT(isValid());
+
RenderBoxRegionInfo* boxInfo = renderBoxRegionInfo(box);
if (!boxInfo && !forceCreation)
return;
@@ -475,7 +429,7 @@ void RenderRegion::ensureOverflowForBox(const RenderBox* box, RefPtr<RenderOverf
LayoutRect borderBox = box->borderBoxRectInRegion(this);
LayoutRect clientBox;
- ASSERT(flowThread->objectShouldPaintInFlowRegion(box, this));
+ ASSERT(m_flowThread->objectShouldFragmentInFlowRegion(box, this));
if (!borderBox.isEmpty()) {
borderBox = rectFlowPortionForBox(box, borderBox);
@@ -483,8 +437,8 @@ void RenderRegion::ensureOverflowForBox(const RenderBox* box, RefPtr<RenderOverf
clientBox = box->clientBoxRectInRegion(this);
clientBox = rectFlowPortionForBox(box, clientBox);
- flowThread->flipForWritingModeLocalCoordinates(borderBox);
- flowThread->flipForWritingModeLocalCoordinates(clientBox);
+ m_flowThread->flipForWritingModeLocalCoordinates(borderBox);
+ m_flowThread->flipForWritingModeLocalCoordinates(clientBox);
}
if (boxInfo) {
@@ -496,30 +450,25 @@ void RenderRegion::ensureOverflowForBox(const RenderBox* box, RefPtr<RenderOverf
LayoutRect RenderRegion::rectFlowPortionForBox(const RenderBox* box, const LayoutRect& rect) const
{
- RenderRegion* startRegion = 0;
- RenderRegion* endRegion = 0;
- m_flowThread->getRegionRangeForBox(box, startRegion, endRegion);
-
LayoutRect mappedRect = m_flowThread->mapFromLocalToFlowThread(box, rect);
- if (flowThread()->isHorizontalWritingMode()) {
- if (this != startRegion)
- mappedRect.shiftYEdgeTo(std::max<LayoutUnit>(logicalTopForFlowThreadContent(), mappedRect.y()));
- if (this != endRegion)
- mappedRect.setHeight(std::max<LayoutUnit>(0, std::min<LayoutUnit>(logicalBottomForFlowThreadContent() - mappedRect.y(), mappedRect.height())));
- } else {
- if (this != startRegion)
- mappedRect.shiftXEdgeTo(std::max<LayoutUnit>(logicalTopForFlowThreadContent(), mappedRect.x()));
-
- if (this != endRegion)
- mappedRect.setWidth(std::max<LayoutUnit>(0, std::min<LayoutUnit>(logicalBottomForFlowThreadContent() - mappedRect.x(), mappedRect.width())));
+ RenderRegion* startRegion = nullptr;
+ RenderRegion* endRegion = nullptr;
+ if (m_flowThread->getRegionRangeForBox(box, startRegion, endRegion)) {
+ if (flowThread()->isHorizontalWritingMode()) {
+ if (this != startRegion)
+ mappedRect.shiftYEdgeTo(std::max<LayoutUnit>(logicalTopForFlowThreadContent(), mappedRect.y()));
+ if (this != endRegion)
+ mappedRect.setHeight(std::max<LayoutUnit>(0, std::min<LayoutUnit>(logicalBottomForFlowThreadContent() - mappedRect.y(), mappedRect.height())));
+ } else {
+ if (this != startRegion)
+ mappedRect.shiftXEdgeTo(std::max<LayoutUnit>(logicalTopForFlowThreadContent(), mappedRect.x()));
+ if (this != endRegion)
+ mappedRect.setWidth(std::max<LayoutUnit>(0, std::min<LayoutUnit>(logicalBottomForFlowThreadContent() - mappedRect.x(), mappedRect.width())));
+ }
}
- bool isLastRegionWithRegionFragmentBreak = (isLastRegion() && (style().regionFragment() == BreakRegionFragment));
- if (hasOverflowClip() || isLastRegionWithRegionFragmentBreak)
- mappedRect.intersect(flowThreadPortionRect());
-
- return mappedRect.isEmpty() ? mappedRect : m_flowThread->mapFromFlowThreadToLocal(box, mappedRect);
+ return m_flowThread->mapFromFlowThreadToLocal(box, mappedRect);
}
void RenderRegion::addLayoutOverflowForBox(const RenderBox* box, const LayoutRect& rect)
@@ -561,16 +510,16 @@ LayoutRect RenderRegion::layoutOverflowRectForBox(const RenderBox* box)
return overflow->layoutOverflowRect();
}
-LayoutRect RenderRegion::visualOverflowRectForBox(const RenderBoxModelObject* box)
+LayoutRect RenderRegion::visualOverflowRectForBox(const RenderBoxModelObject& box)
{
- if (box->isRenderInline()) {
- const RenderInline* inlineBox = toRenderInline(box);
- return inlineBox->linesVisualOverflowBoundingBoxInRegion(this);
+ if (is<RenderInline>(box)) {
+ const RenderInline& inlineBox = downcast<RenderInline>(box);
+ return inlineBox.linesVisualOverflowBoundingBoxInRegion(this);
}
- if (box->isBox()) {
+ if (is<RenderBox>(box)) {
RefPtr<RenderOverflow> overflow;
- ensureOverflowForBox(toRenderBox(box), overflow, true);
+ ensureOverflowForBox(&downcast<RenderBox>(box), overflow, true);
ASSERT(overflow);
return overflow->visualOverflowRect();
@@ -589,7 +538,7 @@ LayoutRect RenderRegion::layoutOverflowRectForBoxForPropagation(const RenderBox*
if (!box->hasOverflowClip())
rect.unite(layoutOverflowRectForBox(box));
- bool hasTransform = box->hasLayer() && box->layer()->transform();
+ bool hasTransform = box->hasTransform();
if (box->isInFlowPositioned() || hasTransform) {
if (hasTransform)
rect = box->layer()->currentTransform().mapRect(rect);
@@ -601,7 +550,7 @@ LayoutRect RenderRegion::layoutOverflowRectForBoxForPropagation(const RenderBox*
return rect;
}
-LayoutRect RenderRegion::visualOverflowRectForBoxForPropagation(const RenderBoxModelObject* box)
+LayoutRect RenderRegion::visualOverflowRectForBoxForPropagation(const RenderBoxModelObject& box)
{
LayoutRect rect = visualOverflowRectForBox(box);
flowThread()->flipForWritingModeLocalCoordinates(rect);
@@ -609,4 +558,19 @@ LayoutRect RenderRegion::visualOverflowRectForBoxForPropagation(const RenderBoxM
return rect;
}
+CurrentRenderRegionMaintainer::CurrentRenderRegionMaintainer(RenderRegion& region)
+ : m_region(region)
+{
+ RenderFlowThread* flowThread = region.flowThread();
+ // A flow thread can have only one current region.
+ ASSERT(!flowThread->currentRegion());
+ flowThread->setCurrentRegionMaintainer(this);
+}
+
+CurrentRenderRegionMaintainer::~CurrentRenderRegionMaintainer()
+{
+ RenderFlowThread* flowThread = m_region.flowThread();
+ flowThread->setCurrentRegionMaintainer(nullptr);
+}
+
} // namespace WebCore