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

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

Issue 1966153002: Turn mergeContiguousAnonymousBlocks() into a proper method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « third_party/WebKit/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: third_party/WebKit/Source/core/layout/LayoutBlock.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutBlock.cpp b/third_party/WebKit/Source/core/layout/LayoutBlock.cpp
index 2ef3c37559e0d29a34041f50adb818f5bc5297d8..c6a11610375126b4310219953ea71280596e3931 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBlock.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBlock.cpp
@@ -249,38 +249,33 @@ static bool borderOrPaddingLogicalDimensionChanged(const ComputedStyle& oldStyle
|| oldStyle.paddingBottom() != newStyle.paddingBottom();
}
-static bool canMergeContiguousAnonymousBlocks(LayoutObject* prev, LayoutObject* next)
+static bool isMergeableAnonymousBlock(const LayoutBlockFlow* block)
{
- if ((prev && (!prev->isAnonymousBlock() || toLayoutBlock(prev)->continuation() || toLayoutBlock(prev)->beingDestroyed()))
- || (next && (!next->isAnonymousBlock() || toLayoutBlock(next)->continuation() || toLayoutBlock(next)->beingDestroyed())))
- return false;
+ return block->isAnonymousBlock() && !block->continuation() && !block->beingDestroyed() && !block->isRubyRun() && !block->isRubyBase();
+}
- if ((prev && (prev->isRubyRun() || prev->isRubyBase()))
- || (next && (next->isRubyRun() || next->isRubyBase())))
+bool LayoutBlock::mergeSiblingContiguousAnonymousBlock(LayoutBlockFlow* siblingThatMayBeDeleted)
+{
+ if (!isLayoutBlockFlow())
return false;
- return true;
-}
+ // Note: |this| and |siblingThatMayBeDeleted| may not be adjacent siblings at this point. There
+ // may be an object between them which is about to be removed.
-static bool mergeContiguousAnonymousBlocks(LayoutObject* prev, LayoutObject*& next)
-{
- if (!prev || !next || !canMergeContiguousAnonymousBlocks(prev, next))
+ if (!isMergeableAnonymousBlock(toLayoutBlockFlow(this)) || !isMergeableAnonymousBlock(siblingThatMayBeDeleted))
return false;
- prev->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::AnonymousBlockChange);
- LayoutBlockFlow* nextBlock = toLayoutBlockFlow(next);
- LayoutBlockFlow* prevBlock = toLayoutBlockFlow(prev);
+ setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidationReason::AnonymousBlockChange);
// If the inlineness of children of the two block don't match, we'd need special code here
// (but there should be no need for it).
- ASSERT(nextBlock->childrenInline() == prevBlock->childrenInline());
+ ASSERT(siblingThatMayBeDeleted->childrenInline() == childrenInline());
// Take all the children out of the |next| block and put them in
// the |prev| block.
- nextBlock->moveAllChildrenIncludingFloatsTo(prevBlock, nextBlock->hasLayer() || prevBlock->hasLayer());
+ siblingThatMayBeDeleted->moveAllChildrenIncludingFloatsTo(this, siblingThatMayBeDeleted->hasLayer() || hasLayer());
// Delete the now-empty block's lines and nuke it.
- nextBlock->deleteLineBoxTree();
- nextBlock->destroy();
- next = nullptr;
+ siblingThatMayBeDeleted->deleteLineBoxTree();
+ siblingThatMayBeDeleted->destroy();
return true;
}
@@ -298,8 +293,10 @@ void LayoutBlock::reparentSubsequentFloatingOrOutOfFlowSiblings()
child = sibling;
}
- LayoutObject* next = nextSibling();
- mergeContiguousAnonymousBlocks(this, next);
+ if (LayoutObject* next = nextSibling()) {
+ if (next->isLayoutBlockFlow())
+ mergeSiblingContiguousAnonymousBlock(toLayoutBlockFlow(next));
+ }
}
void LayoutBlock::reparentPrecedingFloatingOrOutOfFlowSiblings()
@@ -662,7 +659,13 @@ void LayoutBlock::removeChild(LayoutObject* oldChild)
// fold the inline content back together.
LayoutObject* prev = oldChild->previousSibling();
LayoutObject* next = oldChild->nextSibling();
- bool mergedAnonymousBlocks = !oldChild->documentBeingDestroyed() && !oldChild->isInline() && !oldChild->virtualContinuation() && mergeContiguousAnonymousBlocks(prev, next);
+ bool mergedAnonymousBlocks = false;
+ if (prev && next && !oldChild->isInline() && !oldChild->virtualContinuation() && prev->isLayoutBlockFlow() && next->isLayoutBlockFlow()) {
+ if (toLayoutBlockFlow(prev)->mergeSiblingContiguousAnonymousBlock(toLayoutBlockFlow(next))) {
+ mergedAnonymousBlocks = true;
+ next = nullptr;
+ }
+ }
LayoutBox::removeChild(oldChild);
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlock.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698