summaryrefslogtreecommitdiff
path: root/Source/WebCore/rendering/FloatingObjects.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/FloatingObjects.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/rendering/FloatingObjects.cpp')
-rw-r--r--Source/WebCore/rendering/FloatingObjects.cpp145
1 files changed, 63 insertions, 82 deletions
diff --git a/Source/WebCore/rendering/FloatingObjects.cpp b/Source/WebCore/rendering/FloatingObjects.cpp
index 77f6269ba..3c316cb26 100644
--- a/Source/WebCore/rendering/FloatingObjects.cpp
+++ b/Source/WebCore/rendering/FloatingObjects.cpp
@@ -85,15 +85,12 @@ std::unique_ptr<FloatingObject> FloatingObject::create(RenderBox& renderer)
std::unique_ptr<FloatingObject> FloatingObject::copyToNewContainer(LayoutSize offset, bool shouldPaint, bool isDescendant) const
{
- // FIXME: Use make_unique here, once we can get it to compile on all platforms we support.
- return std::unique_ptr<FloatingObject>(new FloatingObject(renderer(), type(), LayoutRect(frameRect().location() - offset, frameRect().size()), shouldPaint, isDescendant));
+ return std::make_unique<FloatingObject>(renderer(), type(), LayoutRect(frameRect().location() - offset, frameRect().size()), shouldPaint, isDescendant);
}
-std::unique_ptr<FloatingObject> FloatingObject::unsafeClone() const
+std::unique_ptr<FloatingObject> FloatingObject::cloneForNewParent() const
{
- // FIXME: Use make_unique here, once we can get it to compile on all platforms we support.
- std::unique_ptr<FloatingObject> cloneObject(new FloatingObject(renderer(), type(), m_frameRect, m_shouldPaint, m_isDescendant));
- cloneObject->m_originatingLine = m_originatingLine;
+ auto cloneObject = std::make_unique<FloatingObject>(renderer(), type(), m_frameRect, m_shouldPaint, m_isDescendant);
cloneObject->m_paginationStrut = m_paginationStrut;
cloneObject->m_isPlaced = m_isPlaced;
return cloneObject;
@@ -142,7 +139,7 @@ public:
LayoutUnit offset() const { return m_offset; }
protected:
- virtual bool updateOffsetIfNeeded(const FloatingObject*) = 0;
+ virtual bool updateOffsetIfNeeded(const FloatingObject&) = 0;
const RenderBlockFlow& m_renderer;
LayoutUnit m_lineTop;
@@ -152,7 +149,7 @@ protected:
};
template <FloatingObject::Type FloatTypeValue>
-class ComputeFloatOffsetForFloatLayoutAdapter : public ComputeFloatOffsetAdapter<FloatTypeValue> {
+class ComputeFloatOffsetForFloatLayoutAdapter : public ComputeFloatOffsetAdapter<FloatTypeValue> {
public:
ComputeFloatOffsetForFloatLayoutAdapter(const RenderBlockFlow& renderer, LayoutUnit lineTop, LayoutUnit lineBottom, LayoutUnit offset)
: ComputeFloatOffsetAdapter<FloatTypeValue>(renderer, lineTop, lineBottom, offset)
@@ -164,7 +161,7 @@ public:
LayoutUnit heightRemaining() const;
protected:
- virtual bool updateOffsetIfNeeded(const FloatingObject*) override final;
+ bool updateOffsetIfNeeded(const FloatingObject&) final;
};
template <FloatingObject::Type FloatTypeValue>
@@ -178,7 +175,7 @@ public:
virtual ~ComputeFloatOffsetForLineLayoutAdapter() { }
protected:
- virtual bool updateOffsetIfNeeded(const FloatingObject*) override final;
+ bool updateOffsetIfNeeded(const FloatingObject&) final;
};
class FindNextFloatLogicalBottomAdapter {
@@ -188,56 +185,51 @@ public:
FindNextFloatLogicalBottomAdapter(const RenderBlockFlow& renderer, LayoutUnit belowLogicalHeight)
: m_renderer(renderer)
, m_belowLogicalHeight(belowLogicalHeight)
- , m_aboveLogicalHeight(LayoutUnit::max())
- , m_nextLogicalBottom(LayoutUnit::max())
- , m_nextShapeLogicalBottom(LayoutUnit::max())
{
}
LayoutUnit lowValue() const { return m_belowLogicalHeight; }
- LayoutUnit highValue() const { return m_aboveLogicalHeight; }
+ LayoutUnit highValue() const { return LayoutUnit::max(); }
void collectIfNeeded(const IntervalType&);
- LayoutUnit nextLogicalBottom() { return m_nextLogicalBottom == LayoutUnit::max() ? LayoutUnit() : m_nextLogicalBottom; }
- LayoutUnit nextShapeLogicalBottom() { return m_nextShapeLogicalBottom == LayoutUnit::max() ? nextLogicalBottom() : m_nextShapeLogicalBottom; }
+ LayoutUnit nextLogicalBottom() const { return m_nextLogicalBottom.value_or(0); }
+ LayoutUnit nextShapeLogicalBottom() const { return m_nextShapeLogicalBottom.value_or(nextLogicalBottom()); }
private:
const RenderBlockFlow& m_renderer;
LayoutUnit m_belowLogicalHeight;
- LayoutUnit m_aboveLogicalHeight;
- LayoutUnit m_nextLogicalBottom;
- LayoutUnit m_nextShapeLogicalBottom;
+ std::optional<LayoutUnit> m_nextLogicalBottom;
+ std::optional<LayoutUnit> m_nextShapeLogicalBottom;
};
inline void FindNextFloatLogicalBottomAdapter::collectIfNeeded(const IntervalType& interval)
{
- const FloatingObject* floatingObject = interval.data();
- if (!rangesIntersect(interval.low(), interval.high(), m_belowLogicalHeight, m_aboveLogicalHeight))
+ const auto& floatingObject = *interval.data();
+ if (!rangesIntersect(interval.low(), interval.high(), m_belowLogicalHeight, LayoutUnit::max()))
return;
// All the objects returned from the tree should be already placed.
- ASSERT(floatingObject->isPlaced());
- ASSERT(rangesIntersect(m_renderer.logicalTopForFloat(floatingObject), m_renderer.logicalBottomForFloat(floatingObject), m_belowLogicalHeight, m_aboveLogicalHeight));
+ ASSERT(floatingObject.isPlaced());
+ ASSERT(rangesIntersect(m_renderer.logicalTopForFloat(floatingObject), m_renderer.logicalBottomForFloat(floatingObject), m_belowLogicalHeight, LayoutUnit::max()));
LayoutUnit floatBottom = m_renderer.logicalBottomForFloat(floatingObject);
- if (m_nextLogicalBottom < floatBottom)
+ if (m_nextLogicalBottom && m_nextLogicalBottom.value() < floatBottom)
return;
-#if ENABLE(CSS_SHAPES)
- if (ShapeOutsideInfo* shapeOutside = floatingObject->renderer().shapeOutsideInfo()) {
- LayoutUnit shapeBottom = m_renderer.logicalTopForFloat(floatingObject) + m_renderer.marginBeforeForChild(floatingObject->renderer()) + shapeOutside->shapeLogicalBottom();
+ if (ShapeOutsideInfo* shapeOutside = floatingObject.renderer().shapeOutsideInfo()) {
+ LayoutUnit shapeBottom = m_renderer.logicalTopForFloat(floatingObject) + m_renderer.marginBeforeForChild(floatingObject.renderer()) + shapeOutside->shapeLogicalBottom();
// Use the shapeBottom unless it extends outside of the margin box, in which case it is clipped.
m_nextShapeLogicalBottom = std::min(shapeBottom, floatBottom);
} else
m_nextShapeLogicalBottom = floatBottom;
-#endif
m_nextLogicalBottom = floatBottom;
}
LayoutUnit FloatingObjects::findNextFloatLogicalBottomBelow(LayoutUnit logicalHeight)
{
FindNextFloatLogicalBottomAdapter adapter(m_renderer, logicalHeight);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
return adapter.nextShapeLogicalBottom();
}
@@ -245,14 +237,14 @@ LayoutUnit FloatingObjects::findNextFloatLogicalBottomBelow(LayoutUnit logicalHe
LayoutUnit FloatingObjects::findNextFloatLogicalBottomBelowForBlock(LayoutUnit logicalHeight)
{
FindNextFloatLogicalBottomAdapter adapter(m_renderer, logicalHeight);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
return adapter.nextLogicalBottom();
}
FloatingObjects::FloatingObjects(const RenderBlockFlow& renderer)
- : m_placedFloatsTree(UninitializedTree)
- , m_leftObjectsCount(0)
+ : m_leftObjectsCount(0)
, m_rightObjectsCount(0)
, m_horizontalWritingMode(renderer.isHorizontalWritingMode())
, m_renderer(renderer)
@@ -275,7 +267,7 @@ void FloatingObjects::clearLineBoxTreePointers()
void FloatingObjects::clear()
{
m_set.clear();
- m_placedFloatsTree.clear();
+ m_placedFloatsTree = nullptr;
m_leftObjectsCount = 0;
m_rightObjectsCount = 0;
}
@@ -287,7 +279,7 @@ void FloatingObjects::moveAllToFloatInfoMap(RendererToFloatInfoMap& map)
// FIXME: The only reason it is safe to move these out of the set is that
// we are about to clear it. Otherwise it would break the hash table invariant.
// A clean way to do this would be to add a takeAll function to HashSet.
- map.add(&renderer, std::move(*it));
+ map.add(&renderer, WTFMove(*it));
}
clear();
}
@@ -322,8 +314,8 @@ void FloatingObjects::addPlacedObject(FloatingObject* floatingObject)
ASSERT(!floatingObject->isInPlacedTree());
floatingObject->setIsPlaced(true);
- if (m_placedFloatsTree.isInitialized())
- m_placedFloatsTree.add(intervalForFloatingObject(floatingObject));
+ if (m_placedFloatsTree)
+ m_placedFloatsTree->add(intervalForFloatingObject(floatingObject));
#ifndef NDEBUG
floatingObject->setIsInPlacedTree(true);
@@ -334,8 +326,8 @@ void FloatingObjects::removePlacedObject(FloatingObject* floatingObject)
{
ASSERT(floatingObject->isPlaced() && floatingObject->isInPlacedTree());
- if (m_placedFloatsTree.isInitialized()) {
- bool removed = m_placedFloatsTree.remove(intervalForFloatingObject(floatingObject));
+ if (m_placedFloatsTree) {
+ bool removed = m_placedFloatsTree->remove(intervalForFloatingObject(floatingObject));
ASSERT_UNUSED(removed, removed);
}
@@ -350,7 +342,7 @@ FloatingObject* FloatingObjects::add(std::unique_ptr<FloatingObject> floatingObj
increaseObjectsCount(floatingObject->type());
if (floatingObject->isPlaced())
addPlacedObject(floatingObject.get());
- return m_set.add(std::move(floatingObject)).iterator->get();
+ return m_set.add(WTFMove(floatingObject)).iterator->get();
}
void FloatingObjects::remove(FloatingObject* floatingObject)
@@ -369,28 +361,30 @@ void FloatingObjects::remove(FloatingObject* floatingObject)
void FloatingObjects::computePlacedFloatsTree()
{
- ASSERT(!m_placedFloatsTree.isInitialized());
+ ASSERT(!m_placedFloatsTree);
if (m_set.isEmpty())
return;
- m_placedFloatsTree.initIfNeeded(m_renderer.view().intervalArena());
+
+ m_placedFloatsTree = std::make_unique<FloatingObjectTree>();
for (auto it = m_set.begin(), end = m_set.end(); it != end; ++it) {
FloatingObject* floatingObject = it->get();
if (floatingObject->isPlaced())
- m_placedFloatsTree.add(intervalForFloatingObject(floatingObject));
+ m_placedFloatsTree->add(intervalForFloatingObject(floatingObject));
}
}
-inline const FloatingObjectTree& FloatingObjects::placedFloatsTree()
+inline const FloatingObjectTree* FloatingObjects::placedFloatsTree()
{
- if (!m_placedFloatsTree.isInitialized())
+ if (!m_placedFloatsTree)
computePlacedFloatsTree();
- return m_placedFloatsTree;
+ return m_placedFloatsTree.get();
}
LayoutUnit FloatingObjects::logicalLeftOffsetForPositioningFloat(LayoutUnit fixedOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining)
{
ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft> adapter(m_renderer, logicalTop, logicalTop, fixedOffset);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
if (heightRemaining)
*heightRemaining = adapter.heightRemaining();
@@ -401,7 +395,8 @@ LayoutUnit FloatingObjects::logicalLeftOffsetForPositioningFloat(LayoutUnit fixe
LayoutUnit FloatingObjects::logicalRightOffsetForPositioningFloat(LayoutUnit fixedOffset, LayoutUnit logicalTop, LayoutUnit *heightRemaining)
{
ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight> adapter(m_renderer, logicalTop, logicalTop, fixedOffset);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
if (heightRemaining)
*heightRemaining = adapter.heightRemaining();
@@ -412,7 +407,8 @@ LayoutUnit FloatingObjects::logicalRightOffsetForPositioningFloat(LayoutUnit fix
LayoutUnit FloatingObjects::logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop, LayoutUnit logicalHeight)
{
ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft> adapter(m_renderer, logicalTop, logicalTop + logicalHeight, fixedOffset);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
return adapter.offset();
}
@@ -420,13 +416,14 @@ LayoutUnit FloatingObjects::logicalLeftOffset(LayoutUnit fixedOffset, LayoutUnit
LayoutUnit FloatingObjects::logicalRightOffset(LayoutUnit fixedOffset, LayoutUnit logicalTop, LayoutUnit logicalHeight)
{
ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight> adapter(m_renderer, logicalTop, logicalTop + logicalHeight, fixedOffset);
- placedFloatsTree().allOverlapsWithAdapter(adapter);
+ if (const FloatingObjectTree* placedFloatsTree = this->placedFloatsTree())
+ placedFloatsTree->allOverlapsWithAdapter(adapter);
return std::min(fixedOffset, adapter.offset());
}
template<>
-inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>::updateOffsetIfNeeded(const FloatingObject* floatingObject)
+inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>::updateOffsetIfNeeded(const FloatingObject& floatingObject)
{
LayoutUnit logicalRight = m_renderer.logicalRightForFloat(floatingObject);
if (logicalRight > m_offset) {
@@ -437,7 +434,7 @@ inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatLeft>::
}
template<>
-inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>::updateOffsetIfNeeded(const FloatingObject* floatingObject)
+inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>::updateOffsetIfNeeded(const FloatingObject& floatingObject)
{
LayoutUnit logicalLeft = m_renderer.logicalLeftForFloat(floatingObject);
if (logicalLeft < m_offset) {
@@ -450,51 +447,36 @@ inline bool ComputeFloatOffsetForFloatLayoutAdapter<FloatingObject::FloatRight>:
template <FloatingObject::Type FloatTypeValue>
LayoutUnit ComputeFloatOffsetForFloatLayoutAdapter<FloatTypeValue>::heightRemaining() const
{
- return this->m_outermostFloat ? this->m_renderer.logicalBottomForFloat(this->m_outermostFloat) - this->m_lineTop : LayoutUnit::fromPixel(1);
+ return this->m_outermostFloat ? this->m_renderer.logicalBottomForFloat(*this->m_outermostFloat) - this->m_lineTop : LayoutUnit::fromPixel(1);
}
template <FloatingObject::Type FloatTypeValue>
inline void ComputeFloatOffsetAdapter<FloatTypeValue>::collectIfNeeded(const IntervalType& interval)
{
- const FloatingObject* floatingObject = interval.data();
- if (floatingObject->type() != FloatTypeValue || !rangesIntersect(interval.low(), interval.high(), m_lineTop, m_lineBottom))
+ const auto& floatingObject = *interval.data();
+ if (floatingObject.type() != FloatTypeValue || !rangesIntersect(interval.low(), interval.high(), m_lineTop, m_lineBottom))
return;
// All the objects returned from the tree should be already placed.
- ASSERT(floatingObject->isPlaced());
+ ASSERT(floatingObject.isPlaced());
ASSERT(rangesIntersect(m_renderer.logicalTopForFloat(floatingObject), m_renderer.logicalBottomForFloat(floatingObject), m_lineTop, m_lineBottom));
bool floatIsNewExtreme = updateOffsetIfNeeded(floatingObject);
if (floatIsNewExtreme)
- m_outermostFloat = floatingObject;
-}
-
-#if ENABLE(CSS_SHAPES)
-static inline ShapeOutsideInfo* shapeInfoForFloat(const FloatingObject* floatingObject, const RenderBlockFlow& containingBlock, LayoutUnit lineTop, LayoutUnit lineBottom)
-{
- if (floatingObject) {
- if (ShapeOutsideInfo* shapeOutside = floatingObject->renderer().shapeOutsideInfo()) {
- shapeOutside->updateDeltasForContainingBlockLine(containingBlock, *floatingObject, lineTop, lineBottom - lineTop);
- return shapeOutside;
- }
- }
-
- return nullptr;
+ m_outermostFloat = &floatingObject;
}
-#endif
template<>
-inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::updateOffsetIfNeeded(const FloatingObject* floatingObject)
+inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::updateOffsetIfNeeded(const FloatingObject& floatingObject)
{
LayoutUnit logicalRight = m_renderer.logicalRightForFloat(floatingObject);
-#if ENABLE(CSS_SHAPES)
- if (ShapeOutsideInfo* shapeOutside = shapeInfoForFloat(floatingObject, m_renderer, m_lineTop, m_lineBottom)) {
- if (!shapeOutside->lineOverlapsShape())
+ if (ShapeOutsideInfo* shapeOutside = floatingObject.renderer().shapeOutsideInfo()) {
+ ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainingBlockLine(m_renderer, floatingObject, m_lineTop, m_lineBottom - m_lineTop);
+ if (!shapeDeltas.lineOverlapsShape())
return false;
- logicalRight += shapeOutside->rightMarginBoxDelta();
+ logicalRight += shapeDeltas.rightMarginBoxDelta();
}
-#endif
if (logicalRight > m_offset) {
m_offset = logicalRight;
return true;
@@ -504,17 +486,16 @@ inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatLeft>::u
}
template<>
-inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight>::updateOffsetIfNeeded(const FloatingObject* floatingObject)
+inline bool ComputeFloatOffsetForLineLayoutAdapter<FloatingObject::FloatRight>::updateOffsetIfNeeded(const FloatingObject& floatingObject)
{
LayoutUnit logicalLeft = m_renderer.logicalLeftForFloat(floatingObject);
-#if ENABLE(CSS_SHAPES)
- if (ShapeOutsideInfo* shapeOutside = shapeInfoForFloat(floatingObject, m_renderer, m_lineTop, m_lineBottom)) {
- if (!shapeOutside->lineOverlapsShape())
+ if (ShapeOutsideInfo* shapeOutside = floatingObject.renderer().shapeOutsideInfo()) {
+ ShapeOutsideDeltas shapeDeltas = shapeOutside->computeDeltasForContainingBlockLine(m_renderer, floatingObject, m_lineTop, m_lineBottom - m_lineTop);
+ if (!shapeDeltas.lineOverlapsShape())
return false;
- logicalLeft += shapeOutside->leftMarginBoxDelta();
+ logicalLeft += shapeDeltas.leftMarginBoxDelta();
}
-#endif
if (logicalLeft < m_offset) {
m_offset = logicalLeft;
return true;