Cleanup friends of LayoutObject

The friends of LayoutObject only need to access the layout tree mutation
methods, but get access to all LayoutObject private members.

Add LayoutObject::setDangerousOneWayParent() to avoid friends.

Expose several private/protected members to public which were accessed
using friend relationship.

Review URL: https://codereview.chromium.org/1306993002

git-svn-id: svn://svn.chromium.org/blink/trunk@201265 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d032a261
...@@ -554,27 +554,6 @@ void LayoutBlock::makeChildrenNonInline(LayoutObject *insertionPoint) ...@@ -554,27 +554,6 @@ void LayoutBlock::makeChildrenNonInline(LayoutObject *insertionPoint)
setShouldDoFullPaintInvalidation(); setShouldDoFullPaintInvalidation();
} }
void LayoutBlock::promoteAllChildrenAndInsertAfter()
{
LayoutObject* firstPromotee = firstChild();
if (!firstPromotee)
return;
LayoutObject* lastPromotee = lastChild();
LayoutBlock* parent = toLayoutBlock(this->parent());
LayoutObject* nextSiblingOfPromotees = nextSibling();
for (LayoutObject* o = firstPromotee; o; o = o->nextSibling())
o->setParent(parent);
children()->setFirstChild(nullptr);
children()->setLastChild(nullptr);
firstPromotee->setPreviousSibling(this);
setNextSibling(firstPromotee);
lastPromotee->setNextSibling(nextSiblingOfPromotees);
if (nextSiblingOfPromotees)
nextSiblingOfPromotees->setPreviousSibling(lastPromotee);
if (parent->children()->lastChild() == this)
parent->children()->setLastChild(lastPromotee);
}
void LayoutBlock::removeLeftoverAnonymousBlock(LayoutBlock* child) void LayoutBlock::removeLeftoverAnonymousBlock(LayoutBlock* child)
{ {
ASSERT(child->isAnonymousBlock()); ASSERT(child->isAnonymousBlock());
...@@ -587,7 +566,7 @@ void LayoutBlock::removeLeftoverAnonymousBlock(LayoutBlock* child) ...@@ -587,7 +566,7 @@ void LayoutBlock::removeLeftoverAnonymousBlock(LayoutBlock* child)
// Promote all the leftover anonymous block's children (to become children of this block // Promote all the leftover anonymous block's children (to become children of this block
// instead). We still want to keep the leftover block in the tree for a moment, for notification // instead). We still want to keep the leftover block in the tree for a moment, for notification
// purposes done further below (flow threads and grids). // purposes done further below (flow threads and grids).
child->promoteAllChildrenAndInsertAfter(); child->moveAllChildrenTo(this, child->nextSibling());
// Remove all the information in the flow thread associated with the leftover anonymous block. // Remove all the information in the flow thread associated with the leftover anonymous block.
child->removeFromLayoutFlowThread(); child->removeFromLayoutFlowThread();
...@@ -2785,7 +2764,7 @@ static bool recalcNormalFlowChildOverflowIfNeeded(LayoutObject* layoutObject) ...@@ -2785,7 +2764,7 @@ static bool recalcNormalFlowChildOverflowIfNeeded(LayoutObject* layoutObject)
bool LayoutBlock::recalcChildOverflowAfterStyleChange() bool LayoutBlock::recalcChildOverflowAfterStyleChange()
{ {
ASSERT(childNeedsOverflowRecalcAfterStyleChange()); ASSERT(childNeedsOverflowRecalcAfterStyleChange());
setChildNeedsOverflowRecalcAfterStyleChange(false); clearChildNeedsOverflowRecalcAfterStyleChange();
bool childrenOverflowChanged = false; bool childrenOverflowChanged = false;
...@@ -2841,7 +2820,7 @@ bool LayoutBlock::recalcOverflowAfterStyleChange() ...@@ -2841,7 +2820,7 @@ bool LayoutBlock::recalcOverflowAfterStyleChange()
if (!selfNeedsOverflowRecalcAfterStyleChange() && !childrenOverflowChanged) if (!selfNeedsOverflowRecalcAfterStyleChange() && !childrenOverflowChanged)
return false; return false;
setSelfNeedsOverflowRecalcAfterStyleChange(false); clearSelfNeedsOverflowRecalcAfterStyleChange();
// If the current block needs layout, overflow will be recalculated during // If the current block needs layout, overflow will be recalculated during
// layout time anyway. We can safely exit here. // layout time anyway. We can safely exit here.
if (needsLayout()) if (needsLayout())
......
...@@ -308,9 +308,6 @@ private: ...@@ -308,9 +308,6 @@ private:
void makeChildrenNonInline(LayoutObject* insertionPoint = nullptr); void makeChildrenNonInline(LayoutObject* insertionPoint = nullptr);
// Promote all children and make them siblings that come right after this block.
void promoteAllChildrenAndInsertAfter();
virtual void removeLeftoverAnonymousBlock(LayoutBlock* child); virtual void removeLeftoverAnonymousBlock(LayoutBlock* child);
static void collapseAnonymousBlockChild(LayoutBlock* parent, LayoutBlock* child); static void collapseAnonymousBlockChild(LayoutBlock* parent, LayoutBlock* child);
......
...@@ -315,7 +315,7 @@ void LayoutBlockFlow::layoutBlock(bool relayoutChildren) ...@@ -315,7 +315,7 @@ void LayoutBlockFlow::layoutBlock(bool relayoutChildren)
hasVisibleContent = layer->hasVisibleContent(); hasVisibleContent = layer->hasVisibleContent();
} }
if (hasVisibleContent) if (hasVisibleContent)
setShouldInvalidateOverflowForPaint(true); setShouldInvalidateOverflowForPaint();
} }
if (isHTMLDialogElement(node()) && isOutOfFlowPositioned()) if (isHTMLDialogElement(node()) && isOutOfFlowPositioned())
...@@ -386,7 +386,7 @@ inline bool LayoutBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit & ...@@ -386,7 +386,7 @@ inline bool LayoutBlockFlow::layoutBlockFlow(bool relayoutChildren, LayoutUnit &
} }
if (shouldBreakAtLineToAvoidWidow()) { if (shouldBreakAtLineToAvoidWidow()) {
setEverHadLayout(true); setEverHadLayout();
return false; return false;
} }
......
...@@ -361,6 +361,14 @@ void LayoutObject::removeChild(LayoutObject* oldChild) ...@@ -361,6 +361,14 @@ void LayoutObject::removeChild(LayoutObject* oldChild)
children->removeChildNode(this, oldChild); children->removeChildNode(this, oldChild);
} }
void LayoutObject::setDangerousOneWayParent(LayoutObject* parent)
{
ASSERT(!previousSibling());
ASSERT(!nextSibling());
ASSERT(!parent || !m_parent);
setParent(parent);
}
void LayoutObject::registerSubtreeChangeListenerOnDescendants(bool value) void LayoutObject::registerSubtreeChangeListenerOnDescendants(bool value)
{ {
// If we're set to the same value then we're done as that means it's // If we're set to the same value then we're done as that means it's
...@@ -1762,13 +1770,13 @@ void LayoutObject::firstLineStyleDidChange(const ComputedStyle& oldStyle, const ...@@ -1762,13 +1770,13 @@ void LayoutObject::firstLineStyleDidChange(const ComputedStyle& oldStyle, const
void LayoutObject::markContainingBlocksForOverflowRecalc() void LayoutObject::markContainingBlocksForOverflowRecalc()
{ {
for (LayoutBlock* container = containingBlock(); container && !container->childNeedsOverflowRecalcAfterStyleChange(); container = container->containingBlock()) for (LayoutBlock* container = containingBlock(); container && !container->childNeedsOverflowRecalcAfterStyleChange(); container = container->containingBlock())
container->setChildNeedsOverflowRecalcAfterStyleChange(true); container->setChildNeedsOverflowRecalcAfterStyleChange();
} }
void LayoutObject::setNeedsOverflowRecalcAfterStyleChange() void LayoutObject::setNeedsOverflowRecalcAfterStyleChange()
{ {
bool neededRecalc = needsOverflowRecalcAfterStyleChange(); bool neededRecalc = needsOverflowRecalcAfterStyleChange();
setSelfNeedsOverflowRecalcAfterStyleChange(true); setSelfNeedsOverflowRecalcAfterStyleChange();
if (!neededRecalc) if (!neededRecalc)
markContainingBlocksForOverflowRecalc(); markContainingBlocksForOverflowRecalc();
} }
......
...@@ -117,10 +117,6 @@ const int showTreeCharacterOffset = 39; ...@@ -117,10 +117,6 @@ const int showTreeCharacterOffset = 39;
// Base class for all layout tree objects. // Base class for all layout tree objects.
class CORE_EXPORT LayoutObject : public ImageResourceClient { class CORE_EXPORT LayoutObject : public ImageResourceClient {
friend class LayoutBlock;
friend class LayoutBlockFlow;
friend class DeprecatedPaintLayerReflectionInfo; // For setParent
friend class DeprecatedPaintLayerScrollableArea; // For setParent.
friend class LayoutObjectChildList; friend class LayoutObjectChildList;
WTF_MAKE_NONCOPYABLE(LayoutObject); WTF_MAKE_NONCOPYABLE(LayoutObject);
public: public:
...@@ -265,7 +261,10 @@ public: ...@@ -265,7 +261,10 @@ public:
virtual bool createsAnonymousWrapper() const { return false; } virtual bool createsAnonymousWrapper() const { return false; }
////////////////////////////////////////// //////////////////////////////////////////
protected: // Sets the parent of this object but doesn't add it as a child of the parent.
void setDangerousOneWayParent(LayoutObject*);
private:
////////////////////////////////////////// //////////////////////////////////////////
// Helper functions. Dangerous to use! // Helper functions. Dangerous to use!
void setPreviousSibling(LayoutObject* previous) { m_previous = previous; } void setPreviousSibling(LayoutObject* previous) { m_previous = previous; }
...@@ -1053,6 +1052,9 @@ public: ...@@ -1053,6 +1052,9 @@ public:
// FIXME: should we hook up scrollbar parts in the layout tree? crbug.com/484263. // FIXME: should we hook up scrollbar parts in the layout tree? crbug.com/484263.
void invalidateDisplayItemClientForNonCompositingDescendantsOf(const LayoutObject&) const; void invalidateDisplayItemClientForNonCompositingDescendantsOf(const LayoutObject&) const;
// Called before anonymousChild.setStyle(). Override to set custom styles for the child.
virtual void updateAnonymousChildStyle(const LayoutObject& anonymousChild, ComputedStyle& style) const { }
protected: protected:
enum LayoutObjectType { enum LayoutObjectType {
LayoutObjectBr, LayoutObjectBr,
...@@ -1133,7 +1135,6 @@ protected: ...@@ -1133,7 +1135,6 @@ protected:
// time this function is called. // time this function is called.
virtual void styleDidChange(StyleDifference, const ComputedStyle* oldStyle); virtual void styleDidChange(StyleDifference, const ComputedStyle* oldStyle);
void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false); void propagateStyleToAnonymousChildren(bool blockChildrenOnly = false);
virtual void updateAnonymousChildStyle(const LayoutObject& child, ComputedStyle& style) const { }
protected: protected:
virtual void willBeDestroyed(); virtual void willBeDestroyed();
...@@ -1183,6 +1184,14 @@ protected: ...@@ -1183,6 +1184,14 @@ protected:
void setIsSlowRepaintObject(bool); void setIsSlowRepaintObject(bool);
void clearSelfNeedsOverflowRecalcAfterStyleChange() { m_bitfields.setSelfNeedsOverflowRecalcAfterStyleChange(false); }
void clearChildNeedsOverflowRecalcAfterStyleChange() { m_bitfields.setChildNeedsOverflowRecalcAfterStyleChange(false); }
void setShouldInvalidateOverflowForPaint() { m_bitfields.setShouldInvalidateOverflowForPaint(true); }
void setEverHadLayout() { m_bitfields.setEverHadLayout(true); }
// Remove this object and all descendants from the containing LayoutFlowThread.
void removeFromLayoutFlowThread();
private: private:
const LayoutRect& previousPaintInvalidationRect() const { return m_previousPaintInvalidationRect; } const LayoutRect& previousPaintInvalidationRect() const { return m_previousPaintInvalidationRect; }
...@@ -1222,7 +1231,6 @@ private: ...@@ -1222,7 +1231,6 @@ private:
const LayoutBoxModelObject* enclosingCompositedContainer() const; const LayoutBoxModelObject* enclosingCompositedContainer() const;
LayoutFlowThread* locateFlowThreadContainingBlock() const; LayoutFlowThread* locateFlowThreadContainingBlock() const;
void removeFromLayoutFlowThread();
void removeFromLayoutFlowThreadRecursive(LayoutFlowThread*); void removeFromLayoutFlowThreadRecursive(LayoutFlowThread*);
ComputedStyle* cachedFirstLineStyle() const; ComputedStyle* cachedFirstLineStyle() const;
...@@ -1410,10 +1418,9 @@ private: ...@@ -1410,10 +1418,9 @@ private:
void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); } void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); }
void setNeedsSimplifiedNormalFlowLayout(bool b) { m_bitfields.setNeedsSimplifiedNormalFlowLayout(b); } void setNeedsSimplifiedNormalFlowLayout(bool b) { m_bitfields.setNeedsSimplifiedNormalFlowLayout(b); }
void setIsDragging(bool b) { m_bitfields.setIsDragging(b); } void setIsDragging(bool b) { m_bitfields.setIsDragging(b); }
void setEverHadLayout(bool b) { m_bitfields.setEverHadLayout(b); } void clearShouldInvalidateOverflowForPaint() { m_bitfields.setShouldInvalidateOverflowForPaint(false); }
void setShouldInvalidateOverflowForPaint(bool b) { m_bitfields.setShouldInvalidateOverflowForPaint(b); } void setSelfNeedsOverflowRecalcAfterStyleChange() { m_bitfields.setSelfNeedsOverflowRecalcAfterStyleChange(true); }
void setSelfNeedsOverflowRecalcAfterStyleChange(bool b) { m_bitfields.setSelfNeedsOverflowRecalcAfterStyleChange(b); } void setChildNeedsOverflowRecalcAfterStyleChange() { m_bitfields.setChildNeedsOverflowRecalcAfterStyleChange(true); }
void setChildNeedsOverflowRecalcAfterStyleChange(bool b) { m_bitfields.setChildNeedsOverflowRecalcAfterStyleChange(b); }
private: private:
// Store state between styleWillChange and styleDidChange // Store state between styleWillChange and styleDidChange
...@@ -1512,7 +1519,7 @@ inline void LayoutObject::setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidat ...@@ -1512,7 +1519,7 @@ inline void LayoutObject::setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidat
inline void LayoutObject::clearNeedsLayout() inline void LayoutObject::clearNeedsLayout()
{ {
// Set flags for later stages/cycles. // Set flags for later stages/cycles.
setEverHadLayout(true); setEverHadLayout();
setMayNeedPaintInvalidation(); setMayNeedPaintInvalidation();
m_bitfields.setNeededLayoutBecauseOfChildren(needsLayoutBecauseOfChildren()); m_bitfields.setNeededLayoutBecauseOfChildren(needsLayoutBecauseOfChildren());
......
...@@ -63,7 +63,7 @@ DeprecatedPaintLayerReflectionInfo::DeprecatedPaintLayerReflectionInfo(LayoutBox ...@@ -63,7 +63,7 @@ DeprecatedPaintLayerReflectionInfo::DeprecatedPaintLayerReflectionInfo(LayoutBox
UseCounter::count(box().document(), UseCounter::Reflection); UseCounter::count(box().document(), UseCounter::Reflection);
m_reflection = LayoutReplica::createAnonymous(&box().document()); m_reflection = LayoutReplica::createAnonymous(&box().document());
m_reflection->setParent(m_box); // We create a 1-way connection. m_reflection->setDangerousOneWayParent(m_box);
} }
void DeprecatedPaintLayerReflectionInfo::destroy() void DeprecatedPaintLayerReflectionInfo::destroy()
...@@ -71,7 +71,7 @@ void DeprecatedPaintLayerReflectionInfo::destroy() ...@@ -71,7 +71,7 @@ void DeprecatedPaintLayerReflectionInfo::destroy()
if (!m_reflection->documentBeingDestroyed()) if (!m_reflection->documentBeingDestroyed())
m_reflection->removeLayers(box().layer()); m_reflection->removeLayers(box().layer());
m_reflection->setParent(0); m_reflection->setDangerousOneWayParent(nullptr);
m_reflection->destroy(); m_reflection->destroy();
m_reflection = nullptr; m_reflection = nullptr;
} }
......
...@@ -1136,7 +1136,7 @@ void DeprecatedPaintLayerScrollableArea::updateScrollCornerStyle() ...@@ -1136,7 +1136,7 @@ void DeprecatedPaintLayerScrollableArea::updateScrollCornerStyle()
if (corner) { if (corner) {
if (!m_scrollCorner) { if (!m_scrollCorner) {
m_scrollCorner = LayoutScrollbarPart::createAnonymous(&box().document()); m_scrollCorner = LayoutScrollbarPart::createAnonymous(&box().document());
m_scrollCorner->setParent(&box()); m_scrollCorner->setDangerousOneWayParent(&box());
} }
m_scrollCorner->setStyle(corner.release()); m_scrollCorner->setStyle(corner.release());
} else if (m_scrollCorner) { } else if (m_scrollCorner) {
...@@ -1264,7 +1264,7 @@ void DeprecatedPaintLayerScrollableArea::updateResizerStyle() ...@@ -1264,7 +1264,7 @@ void DeprecatedPaintLayerScrollableArea::updateResizerStyle()
if (resizer) { if (resizer) {
if (!m_resizer) { if (!m_resizer) {
m_resizer = LayoutScrollbarPart::createAnonymous(&box().document()); m_resizer = LayoutScrollbarPart::createAnonymous(&box().document());
m_resizer->setParent(&box()); m_resizer->setDangerousOneWayParent(&box());
} }
m_resizer->setStyle(resizer.release()); m_resizer->setStyle(resizer.release());
} else if (m_resizer) { } else if (m_resizer) {
......
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