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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBlock.cpp

Issue 1423573002: Remove anonymous block wrapper when all children become inline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated Created 5 years, 1 month 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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 if ((prev && (prev->isRubyRun() || prev->isRubyBase())) 600 if ((prev && (prev->isRubyRun() || prev->isRubyBase()))
601 || (next && (next->isRubyRun() || next->isRubyBase()))) 601 || (next && (next->isRubyRun() || next->isRubyBase())))
602 return false; 602 return false;
603 603
604 return true; 604 return true;
605 } 605 }
606 606
607 void LayoutBlock::removeAnonymousWrappersIfRequired() 607 void LayoutBlock::removeAnonymousWrappersIfRequired()
608 { 608 {
609 ASSERT(isLayoutBlockFlow()); 609 ASSERT(isLayoutBlockFlow());
610 Vector<LayoutBox*, 16> blocksToRemove; 610 Vector<LayoutBox*, 3> blocksToRemove;
611 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 611 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
612 if (child->isFloatingOrOutOfFlowPositioned()) 612 if (child->isFloatingOrOutOfFlowPositioned())
613 continue; 613 continue;
614 614
615 // There are still block children in the container, so any anonymous wra ppers are still needed. 615 // There are still block children in the container, so any anonymous wra ppers are still needed.
616 if (!child->isAnonymousBlock()) 616 if (!child->isAnonymousBlock())
617 return; 617 return;
618 // We can't remove anonymous wrappers if they contain continuations as t his means there are block children present. 618 // We can't remove anonymous wrappers if they contain continuations as t his means there are block children present.
619 if (child->isLayoutBlock() && toLayoutBlock(child)->continuation()) 619 if (child->isLayoutBlock() && toLayoutBlock(child)->continuation())
620 return; 620 return;
(...skipping 18 matching lines...) Expand all
639 return; 639 return;
640 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInva lidationReason::ChildAnonymousBlockChanged); 640 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInva lidationReason::ChildAnonymousBlockChanged);
641 641
642 child->moveAllChildrenTo(parent, child->nextSibling(), child->hasLayer()); 642 child->moveAllChildrenTo(parent, child->nextSibling(), child->hasLayer());
643 parent->setChildrenInline(child->childrenInline()); 643 parent->setChildrenInline(child->childrenInline());
644 644
645 parent->children()->removeChildNode(parent, child, child->hasLayer()); 645 parent->children()->removeChildNode(parent, child, child->hasLayer());
646 child->destroy(); 646 child->destroy();
647 } 647 }
648 648
649 static inline bool shouldMakeChildrenInline(const LayoutBlock* block) 649 void LayoutBlock::makeChildrenInlineIfPossible()
mstensho (USE GERRIT) 2015/10/26 13:42:46 Before doing anything (object type checks and esta
650 { 650 {
651 if (!block->isLayoutBlockFlow()) 651 if (!isLayoutBlockFlow() || isRubyRun())
mstensho (USE GERRIT) 2015/10/26 13:42:46 I'm wondering if we need more checks here. What ab
652 return false; 652 return;
653 LayoutObject* child = block->firstChild(); 653 Vector<LayoutBlock*, 3> blocksToRemove;
654 LayoutObject* child = firstChild();
654 while (child) { 655 while (child) {
655 // TODO(rhogan): If we encounter anonymous blocks with inline children w e should fold them in here. 656 if (child->isAnonymousBlock() && child->childrenInline())
656 if (!child->isFloatingOrOutOfFlowPositioned()) 657 blocksToRemove.append(toLayoutBlock(child));
657 return false; 658 else if (!child->isFloatingOrOutOfFlowPositioned())
659 return;
658 child = child->nextSibling(); 660 child = child->nextSibling();
659 } 661 }
660 return true; 662 for (size_t i = 0; i < blocksToRemove.size(); i++)
663 collapseAnonymousBlockChild(this, blocksToRemove[i]);
664 setChildrenInline(true);
661 } 665 }
662 666
663 void LayoutBlock::removeChild(LayoutObject* oldChild) 667 void LayoutBlock::removeChild(LayoutObject* oldChild)
664 { 668 {
665 // No need to waste time in merging or removing empty anonymous blocks. 669 // No need to waste time in merging or removing empty anonymous blocks.
666 // We can just bail out if our document is getting destroyed. 670 // We can just bail out if our document is getting destroyed.
667 if (documentBeingDestroyed()) { 671 if (documentBeingDestroyed()) {
668 LayoutBox::removeChild(oldChild); 672 LayoutBox::removeChild(oldChild);
669 return; 673 return;
670 } 674 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 else if (curr->isLayoutBlock()) 759 else if (curr->isLayoutBlock())
756 toLayoutBlock(curr)->setContinuation(nextContinuation); 760 toLayoutBlock(curr)->setContinuation(nextContinuation);
757 else 761 else
758 ASSERT_NOT_REACHED(); 762 ASSERT_NOT_REACHED();
759 763
760 break; 764 break;
761 } 765 }
762 setContinuation(nullptr); 766 setContinuation(nullptr);
763 destroy(); 767 destroy();
764 } 768 }
765 } else if (!beingDestroyed() && !oldChild->isFloatingOrOutOfFlowPositioned() && shouldMakeChildrenInline(this)) { 769 } else if (!beingDestroyed() && !oldChild->isFloatingOrOutOfFlowPositioned() ) {
766 // If the child we're removing means that we can now treat all children as inline without the need for anonymous blocks, then do that. 770 // If the child we're removing means that we can now treat all children as inline without the need for anonymous blocks, then do that.
767 setChildrenInline(true); 771 makeChildrenInlineIfPossible();
768 } 772 }
769 } 773 }
770 774
771 bool LayoutBlock::isSelfCollapsingBlock() const 775 bool LayoutBlock::isSelfCollapsingBlock() const
772 { 776 {
773 // We are not self-collapsing if we 777 // We are not self-collapsing if we
774 // (a) have a non-zero height according to layout (an optimization to avoid wasting time) 778 // (a) have a non-zero height according to layout (an optimization to avoid wasting time)
775 // (b) are a table, 779 // (b) are a table,
776 // (c) have border/padding, 780 // (c) have border/padding,
777 // (d) have a min-height 781 // (d) have a min-height
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const 2884 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const
2881 { 2885 {
2882 showLayoutObject(); 2886 showLayoutObject();
2883 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 2887 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
2884 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 2888 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
2885 } 2889 }
2886 2890
2887 #endif 2891 #endif
2888 2892
2889 } // namespace blink 2893 } // 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