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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBlock.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 || oldStyle.paddingLeft() != newStyle.paddingLeft() 242 || oldStyle.paddingLeft() != newStyle.paddingLeft()
243 || oldStyle.paddingRight() != newStyle.paddingRight(); 243 || oldStyle.paddingRight() != newStyle.paddingRight();
244 } 244 }
245 245
246 return oldStyle.borderTopWidth() != newStyle.borderTopWidth() 246 return oldStyle.borderTopWidth() != newStyle.borderTopWidth()
247 || oldStyle.borderBottomWidth() != newStyle.borderBottomWidth() 247 || oldStyle.borderBottomWidth() != newStyle.borderBottomWidth()
248 || oldStyle.paddingTop() != newStyle.paddingTop() 248 || oldStyle.paddingTop() != newStyle.paddingTop()
249 || oldStyle.paddingBottom() != newStyle.paddingBottom(); 249 || oldStyle.paddingBottom() != newStyle.paddingBottom();
250 } 250 }
251 251
252 static bool canMergeContiguousAnonymousBlocks(LayoutObject* prev, LayoutObject* next) 252 static bool isMergeableAnonymousBlock(const LayoutBlockFlow* block)
253 { 253 {
254 if ((prev && (!prev->isAnonymousBlock() || toLayoutBlock(prev)->continuation () || toLayoutBlock(prev)->beingDestroyed())) 254 return block->isAnonymousBlock() && !block->continuation() && !block->beingD estroyed() && !block->isRubyRun() && !block->isRubyBase();
255 || (next && (!next->isAnonymousBlock() || toLayoutBlock(next)->continuat ion() || toLayoutBlock(next)->beingDestroyed()))) 255 }
256
257 bool LayoutBlock::mergeSiblingContiguousAnonymousBlock(LayoutBlockFlow* siblingT hatMayBeDeleted)
258 {
259 if (!isLayoutBlockFlow())
256 return false; 260 return false;
257 261
258 if ((prev && (prev->isRubyRun() || prev->isRubyBase())) 262 // Note: |this| and |siblingThatMayBeDeleted| may not be adjacent siblings a t this point. There
259 || (next && (next->isRubyRun() || next->isRubyBase()))) 263 // may be an object between them which is about to be removed.
264
265 if (!isMergeableAnonymousBlock(toLayoutBlockFlow(this)) || !isMergeableAnony mousBlock(siblingThatMayBeDeleted))
260 return false; 266 return false;
261 267
268 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvalidation Reason::AnonymousBlockChange);
269
270 // If the inlineness of children of the two block don't match, we'd need spe cial code here
271 // (but there should be no need for it).
272 ASSERT(siblingThatMayBeDeleted->childrenInline() == childrenInline());
273 // Take all the children out of the |next| block and put them in
274 // the |prev| block.
275 siblingThatMayBeDeleted->moveAllChildrenIncludingFloatsTo(this, siblingThatM ayBeDeleted->hasLayer() || hasLayer());
276 // Delete the now-empty block's lines and nuke it.
277 siblingThatMayBeDeleted->deleteLineBoxTree();
278 siblingThatMayBeDeleted->destroy();
262 return true; 279 return true;
263 } 280 }
264 281
265 static bool mergeContiguousAnonymousBlocks(LayoutObject* prev, LayoutObject*& ne xt)
266 {
267 if (!prev || !next || !canMergeContiguousAnonymousBlocks(prev, next))
268 return false;
269
270 prev->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInvali dationReason::AnonymousBlockChange);
271 LayoutBlockFlow* nextBlock = toLayoutBlockFlow(next);
272 LayoutBlockFlow* prevBlock = toLayoutBlockFlow(prev);
273
274 // If the inlineness of children of the two block don't match, we'd need spe cial code here
275 // (but there should be no need for it).
276 ASSERT(nextBlock->childrenInline() == prevBlock->childrenInline());
277 // Take all the children out of the |next| block and put them in
278 // the |prev| block.
279 nextBlock->moveAllChildrenIncludingFloatsTo(prevBlock, nextBlock->hasLayer() || prevBlock->hasLayer());
280 // Delete the now-empty block's lines and nuke it.
281 nextBlock->deleteLineBoxTree();
282 nextBlock->destroy();
283 next = nullptr;
284 return true;
285 }
286
287 void LayoutBlock::reparentSubsequentFloatingOrOutOfFlowSiblings() 282 void LayoutBlock::reparentSubsequentFloatingOrOutOfFlowSiblings()
288 { 283 {
289 if (!parent() || !parent()->isLayoutBlockFlow()) 284 if (!parent() || !parent()->isLayoutBlockFlow())
290 return; 285 return;
291 if (beingDestroyed() || documentBeingDestroyed()) 286 if (beingDestroyed() || documentBeingDestroyed())
292 return; 287 return;
293 LayoutBlockFlow* parentBlockFlow = toLayoutBlockFlow(parent()); 288 LayoutBlockFlow* parentBlockFlow = toLayoutBlockFlow(parent());
294 LayoutObject* child = nextSibling(); 289 LayoutObject* child = nextSibling();
295 while (child && child->isFloatingOrOutOfFlowPositioned()) { 290 while (child && child->isFloatingOrOutOfFlowPositioned()) {
296 LayoutObject* sibling = child->nextSibling(); 291 LayoutObject* sibling = child->nextSibling();
297 parentBlockFlow->moveChildTo(this, child, nullptr, false); 292 parentBlockFlow->moveChildTo(this, child, nullptr, false);
298 child = sibling; 293 child = sibling;
299 } 294 }
300 295
301 LayoutObject* next = nextSibling(); 296 if (LayoutObject* next = nextSibling()) {
302 mergeContiguousAnonymousBlocks(this, next); 297 if (next->isLayoutBlockFlow())
298 mergeSiblingContiguousAnonymousBlock(toLayoutBlockFlow(next));
299 }
303 } 300 }
304 301
305 void LayoutBlock::reparentPrecedingFloatingOrOutOfFlowSiblings() 302 void LayoutBlock::reparentPrecedingFloatingOrOutOfFlowSiblings()
306 { 303 {
307 if (!parent() || !parent()->isLayoutBlockFlow()) 304 if (!parent() || !parent()->isLayoutBlockFlow())
308 return; 305 return;
309 if (beingDestroyed() || documentBeingDestroyed()) 306 if (beingDestroyed() || documentBeingDestroyed())
310 return; 307 return;
311 LayoutBlockFlow* parentBlockFlow = toLayoutBlockFlow(parent()); 308 LayoutBlockFlow* parentBlockFlow = toLayoutBlockFlow(parent());
312 LayoutObject* child = previousSibling(); 309 LayoutObject* child = previousSibling();
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 if (documentBeingDestroyed()) { 652 if (documentBeingDestroyed()) {
656 LayoutBox::removeChild(oldChild); 653 LayoutBox::removeChild(oldChild);
657 return; 654 return;
658 } 655 }
659 656
660 // If this child is a block, and if our previous and next siblings are 657 // If this child is a block, and if our previous and next siblings are
661 // both anonymous blocks with inline content, then we can go ahead and 658 // both anonymous blocks with inline content, then we can go ahead and
662 // fold the inline content back together. 659 // fold the inline content back together.
663 LayoutObject* prev = oldChild->previousSibling(); 660 LayoutObject* prev = oldChild->previousSibling();
664 LayoutObject* next = oldChild->nextSibling(); 661 LayoutObject* next = oldChild->nextSibling();
665 bool mergedAnonymousBlocks = !oldChild->documentBeingDestroyed() && !oldChil d->isInline() && !oldChild->virtualContinuation() && mergeContiguousAnonymousBlo cks(prev, next); 662 bool mergedAnonymousBlocks = false;
663 if (prev && next && !oldChild->isInline() && !oldChild->virtualContinuation( ) && prev->isLayoutBlockFlow() && next->isLayoutBlockFlow()) {
664 if (toLayoutBlockFlow(prev)->mergeSiblingContiguousAnonymousBlock(toLayo utBlockFlow(next))) {
665 mergedAnonymousBlocks = true;
666 next = nullptr;
667 }
668 }
666 669
667 LayoutBox::removeChild(oldChild); 670 LayoutBox::removeChild(oldChild);
668 671
669 LayoutObject* child = prev ? prev : next; 672 LayoutObject* child = prev ? prev : next;
670 if (mergedAnonymousBlocks && child && !child->previousSibling() && !child->n extSibling()) { 673 if (mergedAnonymousBlocks && child && !child->previousSibling() && !child->n extSibling()) {
671 // The removal has knocked us down to containing only a single anonymous 674 // The removal has knocked us down to containing only a single anonymous
672 // box. We can go ahead and pull the content right back up into our 675 // box. We can go ahead and pull the content right back up into our
673 // box. 676 // box.
674 collapseAnonymousBlockChild(this, toLayoutBlock(child)); 677 collapseAnonymousBlockChild(this, toLayoutBlock(child));
675 } 678 }
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 for (TrackedLayoutBoxListHashSet::const_iterator it = positionedDescenda ntSet->begin(); it != end; ++it) { 2256 for (TrackedLayoutBoxListHashSet::const_iterator it = positionedDescenda ntSet->begin(); it != end; ++it) {
2254 LayoutBox* currBox = *it; 2257 LayoutBox* currBox = *it;
2255 ASSERT(!currBox->needsLayout()); 2258 ASSERT(!currBox->needsLayout());
2256 } 2259 }
2257 } 2260 }
2258 } 2261 }
2259 2262
2260 #endif 2263 #endif
2261 2264
2262 } // namespace blink 2265 } // namespace blink
OLDNEW
« 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