Commit f8d77f33 authored by weinig@apple.com's avatar weinig@apple.com

LayoutStateMaintainer should use references where possible

https://bugs.webkit.org/show_bug.cgi?id=124471

Reviewed by Dan Bernstein.

* page/FrameView.cpp:
(WebCore::FrameView::layout):
* rendering/LayoutState.cpp:
(WebCore::LayoutState::LayoutState):
* rendering/LayoutState.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::simplifiedLayout):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutBlock):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::layout):
* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::RenderDeprecatedFlexibleBox::layoutBlock):
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::layout):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutBlock):
* rendering/RenderFlowThread.cpp:
(WebCore::RenderFlowThread::pushFlowThreadLayoutState):
* rendering/RenderFlowThread.h:
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock):
* rendering/RenderMedia.cpp:
(WebCore::RenderMedia::layout):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::layout):
* rendering/RenderTableRow.cpp:
(WebCore::RenderTableRow::layout):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::calcRowLogicalHeight):
(WebCore::RenderTableSection::layout):
(WebCore::RenderTableSection::layoutRows):
* rendering/RenderTextTrackCue.cpp:
(WebCore::RenderTextTrackCue::layout):
* rendering/RenderView.cpp:
(WebCore::RenderView::pushLayoutState):
(WebCore::RenderView::pushLayoutStateForCurrentFlowThread):
* rendering/RenderView.h:
(WebCore::LayoutStateMaintainer::LayoutStateMaintainer):
(WebCore::LayoutStateMaintainer::push):
(WebCore::LayoutStateMaintainer::pop):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159391 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f37f9b40
2013-11-17 Sam Weinig <sam@webkit.org>
LayoutStateMaintainer should use references where possible
https://bugs.webkit.org/show_bug.cgi?id=124471
Reviewed by Dan Bernstein.
* page/FrameView.cpp:
(WebCore::FrameView::layout):
* rendering/LayoutState.cpp:
(WebCore::LayoutState::LayoutState):
* rendering/LayoutState.h:
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::simplifiedLayout):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::layoutBlock):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::layout):
* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::RenderDeprecatedFlexibleBox::layoutBlock):
* rendering/RenderEmbeddedObject.cpp:
(WebCore::RenderEmbeddedObject::layout):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutBlock):
* rendering/RenderFlowThread.cpp:
(WebCore::RenderFlowThread::pushFlowThreadLayoutState):
* rendering/RenderFlowThread.h:
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock):
* rendering/RenderMedia.cpp:
(WebCore::RenderMedia::layout):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::layout):
* rendering/RenderTableRow.cpp:
(WebCore::RenderTableRow::layout):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::calcRowLogicalHeight):
(WebCore::RenderTableSection::layout):
(WebCore::RenderTableSection::layoutRows):
* rendering/RenderTextTrackCue.cpp:
(WebCore::RenderTextTrackCue::layout):
* rendering/RenderView.cpp:
(WebCore::RenderView::pushLayoutState):
(WebCore::RenderView::pushLayoutStateForCurrentFlowThread):
* rendering/RenderView.h:
(WebCore::LayoutStateMaintainer::LayoutStateMaintainer):
(WebCore::LayoutStateMaintainer::push):
(WebCore::LayoutStateMaintainer::pop):
2013-11-16 Alexey Proskuryakov <ap@apple.com>
Use uint8_t vectors for WebCrypto data
......
......@@ -1246,7 +1246,7 @@ void FrameView::layout(bool allowSubtree)
bool disableLayoutState = false;
if (subtree) {
disableLayoutState = root->view().shouldDisableLayoutStateForSubtree(root);
root->view().pushLayoutState(root);
root->view().pushLayoutState(*root);
}
LayoutStateDisabler layoutStateDisabler(disableLayoutState ? &root->view() : 0);
......@@ -1278,7 +1278,7 @@ void FrameView::layout(bool allowSubtree)
ASSERT(m_layoutPhase == InLayout);
if (subtree)
root->view().popLayoutState(root);
root->view().popLayoutState(*root);
m_layoutRoot = 0;
......
......@@ -136,7 +136,7 @@ LayoutState::LayoutState(std::unique_ptr<LayoutState> next, RenderBox* renderer,
// FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
}
LayoutState::LayoutState(RenderObject* root)
LayoutState::LayoutState(RenderObject& root)
: m_clipped(false)
, m_isPaginated(false)
, m_pageLogicalHeightChanged(false)
......@@ -151,10 +151,10 @@ LayoutState::LayoutState(RenderObject* root)
#endif
, m_pageLogicalHeight(0)
#ifndef NDEBUG
, m_renderer(root)
, m_renderer(&root)
#endif
{
RenderElement* container = root->container();
RenderElement* container = root.container();
FloatPoint absContentPoint = container->localToAbsolute(FloatPoint(), UseTransforms);
m_paintOffset = LayoutSize(absContentPoint.x(), absContentPoint.y());
......
......@@ -65,7 +65,7 @@ public:
}
LayoutState(std::unique_ptr<LayoutState> state, RenderBox*, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, ColumnInfo*);
explicit LayoutState(RenderObject*);
explicit LayoutState(RenderObject&);
void clearPaginationInformation();
bool isPaginatingColumns() const { return m_columnInfo && m_columnInfo->paginationUnit() == ColumnInfo::Column; }
......
......@@ -2003,7 +2003,7 @@ bool RenderBlock::simplifiedLayout()
if ((!posChildNeedsLayout() && !needsSimplifiedNormalFlowLayout()) || normalChildNeedsLayout() || selfNeedsLayout())
return false;
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasColumns() || hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasColumns() || hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
if (needsPositionedMovementLayout() && !tryLayoutDoingPositionedMovementOnly())
return false;
......
......@@ -322,7 +322,7 @@ void RenderBlockFlow::layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalH
checkForPaginationLogicalHeightChange(pageLogicalHeight, pageLogicalHeightChanged, hasSpecifiedPageLogicalHeight);
const RenderStyle& styleToUse = style();
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasColumns() || hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged, columnInfo());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasColumns() || hasTransform() || hasReflection() || styleToUse.isFlippedBlocksWritingMode(), pageLogicalHeight, pageLogicalHeightChanged, columnInfo());
prepareShapesAndPaginationBeforeBlockLayout(relayoutChildren);
if (!relayoutChildren)
......
......@@ -468,7 +468,7 @@ void RenderBox::layout()
return;
}
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), style().isFlippedBlocksWritingMode());
while (child) {
if (child->needsLayout())
toRenderElement(child)->layout();
......
......@@ -283,7 +283,7 @@ void RenderDeprecatedFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
return;
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
prepareShapesAndPaginationBeforeBlockLayout(relayoutChildren);
......
......@@ -513,7 +513,7 @@ void RenderEmbeddedObject::layout()
// When calling layout() on a child node, a parent must either push a LayoutStateMaintainter, or
// instantiate LayoutStateDisabler. Since using a LayoutStateMaintainer is slightly more efficient,
// and this method will be called many times per second during playback, use a LayoutStateMaintainer:
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
childBox->setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
childBox->style().setHeight(Length(newSize.height(), Fixed));
......
......@@ -280,7 +280,7 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
LayoutUnit previousHeight = logicalHeight();
setLogicalHeight(borderAndPaddingLogicalHeight() + scrollbarLogicalHeight());
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
prepareShapesAndPaginationBeforeBlockLayout(relayoutChildren);
......
......@@ -1213,7 +1213,7 @@ const RenderBox* RenderFlowThread::currentActiveRenderBox() const
return currentObject->isBox() ? toRenderBox(currentObject) : 0;
}
void RenderFlowThread::pushFlowThreadLayoutState(const RenderObject* object)
void RenderFlowThread::pushFlowThreadLayoutState(const RenderObject& object)
{
if (const RenderBox* currentBoxDescendant = currentActiveRenderBox()) {
LayoutState* layoutState = currentBoxDescendant->view().layoutState();
......@@ -1224,7 +1224,7 @@ void RenderFlowThread::pushFlowThreadLayoutState(const RenderObject* object)
}
}
m_activeObjectsStack.add(object);
m_activeObjectsStack.add(&object);
}
void RenderFlowThread::popFlowThreadLayoutState()
......
......@@ -200,7 +200,7 @@ public:
#endif
virtual bool collectsGraphicsLayersUnderRegions() const;
void pushFlowThreadLayoutState(const RenderObject*);
void pushFlowThreadLayoutState(const RenderObject&);
void popFlowThreadLayoutState();
LayoutUnit offsetFromLogicalTopOfFirstRegion(const RenderBlock*) const;
void clearRenderBoxRegionInfoAndCustomStyle(const RenderBox*, const RenderRegion*, const RenderRegion*, const RenderRegion*, const RenderRegion*);
......
......@@ -163,7 +163,7 @@ void RenderGrid::layoutBlock(bool relayoutChildren, LayoutUnit)
// FIXME: Much of this method is boiler plate that matches RenderBox::layoutBlock and Render*FlexibleBox::layoutBlock.
// It would be nice to refactor some of the duplicate code.
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
prepareShapesAndPaginationBeforeBlockLayout(relayoutChildren);
......
......@@ -78,7 +78,7 @@ void RenderMedia::layout()
// When calling layout() on a child node, a parent must either push a LayoutStateMaintainter, or
// instantiate LayoutStateDisabler. Since using a LayoutStateMaintainer is slightly more efficient,
// and this method will be called many times per second during playback, use a LayoutStateMaintainer:
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
controlsRenderer->setLocation(LayoutPoint(borderLeft(), borderTop()) + LayoutSize(paddingLeft(), paddingTop()));
controlsRenderer->style().setHeight(Length(newSize.height(), Fixed));
......
......@@ -423,7 +423,7 @@ void RenderTable::layout()
recalcBordersInRowDirection();
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
setLogicalHeight(0);
......
......@@ -163,7 +163,7 @@ void RenderTableRow::layout()
ASSERT(needsLayout());
// Table rows do not add translation.
LayoutStateMaintainer statePusher(&view(), this, LayoutSize(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, LayoutSize(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
bool paginated = view().layoutState()->isPaginated();
......
......@@ -278,7 +278,7 @@ int RenderTableSection::calcRowLogicalHeight()
int spacing = table()->vBorderSpacing();
LayoutStateMaintainer statePusher(&view());
LayoutStateMaintainer statePusher(view());
m_rowPos.resize(m_grid.size() + 1);
m_rowPos[0] = spacing;
......@@ -332,7 +332,7 @@ int RenderTableSection::calcRowLogicalHeight()
if (!statePusher.didPush()) {
// Technically, we should also push state for the row, but since
// rows don't push a coordinate transform, that's not necessary.
statePusher.push(this, locationOffset());
statePusher.push(*this, locationOffset());
}
cell->clearIntrinsicPadding();
cell->clearOverrideSize();
......@@ -385,7 +385,7 @@ void RenderTableSection::layout()
// can be called in a loop (e.g during parsing). Doing it now ensures we have a stable-enough structure.
m_grid.shrinkToFit();
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
const Vector<int>& columnPos = table()->columnPositions();
......@@ -530,7 +530,7 @@ void RenderTableSection::layoutRows()
int vspacing = table()->vBorderSpacing();
unsigned nEffCols = table()->numEffCols();
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || style().isFlippedBlocksWritingMode());
for (unsigned r = 0; r < totalRows; r++) {
// Set the row's x/y position and width/height.
......
......@@ -48,7 +48,7 @@ void RenderTextTrackCue::layout()
StackStats::LayoutCheckPoint layoutCheckPoint;
RenderBlockFlow::layout();
LayoutStateMaintainer statePusher(&view(), this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
LayoutStateMaintainer statePusher(view(), *this, locationOffset(), hasTransform() || hasReflection() || style().isFlippedBlocksWritingMode());
if (m_cue->cueType()== TextTrackCue::WebVTT) {
if (m_cue->snapToLines())
......
......@@ -1028,7 +1028,7 @@ float RenderView::zoomFactor() const
return frameView().frame().pageZoomFactor();
}
void RenderView::pushLayoutState(RenderObject* root)
void RenderView::pushLayoutState(RenderObject& root)
{
ASSERT(m_layoutStateDisableCount == 0);
ASSERT(m_layoutState == 0);
......@@ -1155,7 +1155,7 @@ FlowThreadController& RenderView::flowThreadController()
return *m_flowThreadController;
}
void RenderView::pushLayoutStateForCurrentFlowThread(const RenderObject* object)
void RenderView::pushLayoutStateForCurrentFlowThread(const RenderObject& object)
{
if (!m_flowThreadController)
return;
......
......@@ -142,8 +142,8 @@ public:
bool doingFullRepaint() const { return frameView().needsFullRepaint(); }
// Subtree push/pop
void pushLayoutState(RenderObject*);
void popLayoutState(RenderObject*) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
void pushLayoutState(RenderObject&);
void popLayoutState(RenderObject&) { return popLayoutState(); } // Just doing this to keep popLayoutState() private and to make the subtree calls symmetrical.
bool shouldDisableLayoutStateForSubtree(RenderObject*) const;
......@@ -249,18 +249,18 @@ private:
bool shouldRepaint(const LayoutRect&) const;
// These functions may only be accessed by LayoutStateMaintainer.
bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
bool pushLayoutState(RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = nullptr)
{
// We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer->hasColumns() || renderer->flowThreadContainingBlock()
|| m_layoutState->lineGrid() || (renderer->style().lineGrid() != RenderStyle::initialLineGrid() && renderer->isRenderBlockFlow())
if (!doingFullRepaint() || m_layoutState->isPaginated() || renderer.hasColumns() || renderer.flowThreadContainingBlock()
|| m_layoutState->lineGrid() || (renderer.style().lineGrid() != RenderStyle::initialLineGrid() && renderer.isRenderBlockFlow())
#if ENABLE(CSS_SHAPES)
|| (renderer->isRenderBlock() && toRenderBlock(renderer)->shapeInsideInfo())
|| (m_layoutState->shapeInsideInfo() && renderer->isRenderBlock() && !toRenderBlock(renderer)->allowsShapeInsideInfoSharing())
|| (renderer.isRenderBlock() && toRenderBlock(renderer).shapeInsideInfo())
|| (m_layoutState->shapeInsideInfo() && renderer.isRenderBlock() && !toRenderBlock(renderer).allowsShapeInsideInfoSharing())
#endif
) {
pushLayoutStateForCurrentFlowThread(renderer);
m_layoutState = std::make_unique<LayoutState>(std::move(m_layoutState), renderer, offset, pageHeight, pageHeightChanged, colInfo);
m_layoutState = std::make_unique<LayoutState>(std::move(m_layoutState), &renderer, offset, pageHeight, pageHeightChanged, colInfo);
return true;
}
return false;
......@@ -287,7 +287,7 @@ private:
void checkLayoutState(const LayoutState&);
#endif
void pushLayoutStateForCurrentFlowThread(const RenderObject*);
void pushLayoutStateForCurrentFlowThread(const RenderObject&);
void popLayoutStateForCurrentFlowThread();
friend class LayoutStateMaintainer;
......@@ -354,8 +354,8 @@ RENDER_OBJECT_TYPE_CASTS(RenderView, isRenderView());
class LayoutStateMaintainer {
WTF_MAKE_NONCOPYABLE(LayoutStateMaintainer);
public:
// ctor to push now
LayoutStateMaintainer(RenderView* view, RenderBox* root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
// Constructor to push now.
explicit LayoutStateMaintainer(RenderView& view, RenderBox& root, LayoutSize offset, bool disableState = false, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = nullptr)
: m_view(view)
, m_disabled(disableState)
, m_didStart(false)
......@@ -364,9 +364,9 @@ public:
{
push(root, offset, pageHeight, pageHeightChanged, colInfo);
}
// ctor to maybe push later
LayoutStateMaintainer(RenderView* view)
// Constructor to maybe push later.
explicit LayoutStateMaintainer(RenderView& view)
: m_view(view)
, m_disabled(false)
, m_didStart(false)
......@@ -380,13 +380,13 @@ public:
ASSERT(m_didStart == m_didEnd); // if this fires, it means that someone did a push(), but forgot to pop().
}
void push(RenderBox* root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
void push(RenderBox& root, LayoutSize offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = nullptr)
{
ASSERT(!m_didStart);
// We push state even if disabled, because we still need to store layoutDelta
m_didCreateLayoutState = m_view->pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
m_didCreateLayoutState = m_view.pushLayoutState(root, offset, pageHeight, pageHeightChanged, colInfo);
if (m_disabled && m_didCreateLayoutState)
m_view->disableLayoutState();
m_view.disableLayoutState();
m_didStart = true;
}
......@@ -395,9 +395,9 @@ public:
if (m_didStart) {
ASSERT(!m_didEnd);
if (m_didCreateLayoutState) {
m_view->popLayoutState();
m_view.popLayoutState();
if (m_disabled)
m_view->enableLayoutState();
m_view.enableLayoutState();
}
m_didEnd = true;
......@@ -407,7 +407,7 @@ public:
bool didPush() const { return m_didStart; }
private:
RenderView* m_view;
RenderView& m_view;
bool m_disabled : 1; // true if the offset and clip part of layoutState is disabled
bool m_didStart : 1; // true if we did a push or disable
bool m_didEnd : 1; // true if we popped or re-enabled
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment