Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Unified Diff: Source/core/layout/LayoutBlock.cpp

Issue 1310253005: Strip anonymous wrappers when a block flow no longer requires them (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/layout/LayoutBlock.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/LayoutBlock.cpp
diff --git a/Source/core/layout/LayoutBlock.cpp b/Source/core/layout/LayoutBlock.cpp
index 272ce512f78950e1eb1368b7cd47f9fbc454c5f9..86db6cd30a8c1287139c724058741c230bb1009c 100644
--- a/Source/core/layout/LayoutBlock.cpp
+++ b/Source/core/layout/LayoutBlock.cpp
@@ -271,8 +271,14 @@ void LayoutBlock::styleDidChange(StyleDifference diff, const ComputedStyle* oldS
{
LayoutBox::styleDidChange(diff, oldStyle);
- if (isFloatingOrOutOfFlowPositioned() && oldStyle && !oldStyle->isFloating() && !oldStyle->hasOutOfFlowPosition() && parent() && parent()->isLayoutBlockFlow())
+ if (isFloatingOrOutOfFlowPositioned() && oldStyle && !oldStyle->isFloating() && !oldStyle->hasOutOfFlowPosition() && parent() && parent()->isLayoutBlockFlow()) {
toLayoutBlock(parent())->removeAnonymousWrappersIfRequired();
+ // Reparent to an adjacent anonymous block if one is available.
+ if (previousSibling() && previousSibling()->isAnonymousBlock())
+ toLayoutBlock(parent())->moveChildTo(toLayoutBlock(previousSibling()), this, 0, false);
+ if (nextSibling() && nextSibling()->isAnonymousBlock())
+ toLayoutBlock(parent())->moveChildTo(toLayoutBlock(nextSibling()), this, nextSibling()->slowFirstChild(), false);
+ }
const ComputedStyle& newStyle = styleRef();
@@ -376,6 +382,17 @@ void LayoutBlock::invalidateDisplayItemClients(const LayoutBoxModelObject& paint
invalidateDisplayItemClientForStartOfContinuationsIfNeeded(*this);
}
+void LayoutBlock::addAdjacentSiblingsToAnonymousBox(AdjacentSiblings siblings, LayoutBlock* anonymousBox)
+{
+ bool previousSiblings = siblings == PreviousSiblings;
+ LayoutObject* child = previousSiblings ? anonymousBox->previousSibling() : anonymousBox->nextSibling();
+ while (child && child->isFloatingOrOutOfFlowPositioned()) {
+ LayoutObject* sibling = previousSiblings ? child->previousSibling() : child->nextSibling();
+ moveChildTo(anonymousBox, child, previousSiblings ? anonymousBox->firstChild() : 0, false);
+ child = sibling;
+ }
+}
+
void LayoutBlock::addChildIgnoringContinuation(LayoutObject* newChild, LayoutObject* beforeChild)
{
if (beforeChild && beforeChild->parent() != this) {
@@ -439,17 +456,36 @@ void LayoutBlock::addChildIgnoringContinuation(LayoutObject* newChild, LayoutObj
// it is put into an anomyous block box. We try to use an existing anonymous box if possible, otherwise
// a new one is created and inserted into our list of children in the appropriate position.
LayoutObject* afterChild = beforeChild ? beforeChild->previousSibling() : lastChild();
-
if (afterChild && afterChild->isAnonymousBlock()) {
afterChild->addChild(newChild);
return;
}
+ // If we are a block that allows inline children and the child we're adding means that
mstensho (USE GERRIT) 2015/09/07 14:01:47 But we are not a block that allows inline children
+ // we can now treat all children as inline without the need for anonymous blocks, then do that.
+ LayoutObject* nextChild = firstChild();
+ bool childrenAllInline = !isFlexibleBoxIncludingDeprecated() && !isLayoutGrid();
+ while (nextChild && childrenAllInline) {
+ if (!nextChild->isFloatingOrOutOfFlowPositioned()) {
+ childrenAllInline = false;
+ break;
+ }
+ nextChild = nextChild->nextSibling();
+ }
+ if (childrenAllInline) {
+ LayoutBox::addChild(newChild, beforeChild);
+ setChildrenInline(true);
+ return;
+ }
+
if (newChild->isInline()) {
// No suitable existing anonymous box - create a new one.
LayoutBlock* newBox = createAnonymousBlock();
LayoutBox::addChild(newBox, beforeChild);
+ // Reparent adjacent inline siblings to the new box.
+ addAdjacentSiblingsToAnonymousBox(PreviousSiblings, newBox);
newBox->addChild(newChild);
+ addAdjacentSiblingsToAnonymousBox(NextSiblings, newBox);
return;
}
}
« no previous file with comments | « Source/core/layout/LayoutBlock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698