OLD | NEW |
---|---|
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 || oldStyle.borderBottomWidth() != newStyle.borderBottomWidth() | 262 || oldStyle.borderBottomWidth() != newStyle.borderBottomWidth() |
263 || oldStyle.paddingTop() != newStyle.paddingTop() | 263 || oldStyle.paddingTop() != newStyle.paddingTop() |
264 || oldStyle.paddingBottom() != newStyle.paddingBottom(); | 264 || oldStyle.paddingBottom() != newStyle.paddingBottom(); |
265 } | 265 } |
266 | 266 |
267 void LayoutBlock::styleDidChange(StyleDifference diff, const ComputedStyle* oldS tyle) | 267 void LayoutBlock::styleDidChange(StyleDifference diff, const ComputedStyle* oldS tyle) |
268 { | 268 { |
269 LayoutBox::styleDidChange(diff, oldStyle); | 269 LayoutBox::styleDidChange(diff, oldStyle); |
270 | 270 |
271 if (isFloatingOrOutOfFlowPositioned() && oldStyle && !oldStyle->isFloating() && !oldStyle->hasOutOfFlowPosition() && parent() && parent()->isLayoutBlockFlow ()) { | 271 if (isFloatingOrOutOfFlowPositioned() && oldStyle && !oldStyle->isFloating() && !oldStyle->hasOutOfFlowPosition() && parent() && parent()->isLayoutBlockFlow ()) { |
272 toLayoutBlock(parent())->removeAnonymousWrappersIfRequired(); | 272 toLayoutBlock(parent())->makeChildrenInlineIfPossible(); |
mstensho (USE GERRIT)
2015/10/29 10:08:49
Note: I think this belongs in LayoutBox, not here
| |
273 // Reparent to an adjacent anonymous block if one is available. | 273 // Reparent to an adjacent anonymous block if one is available. |
274 if (previousSibling() && previousSibling()->isAnonymousBlock()) | 274 if (previousSibling() && previousSibling()->isAnonymousBlock()) |
275 toLayoutBlock(parent())->moveChildTo(toLayoutBlock(previousSibling() ), this, nullptr, false); | 275 toLayoutBlock(parent())->moveChildTo(toLayoutBlock(previousSibling() ), this, nullptr, false); |
276 else if (nextSibling() && nextSibling()->isAnonymousBlock()) | 276 else if (nextSibling() && nextSibling()->isAnonymousBlock()) |
277 toLayoutBlock(parent())->moveChildTo(toLayoutBlock(nextSibling()), t his, nextSibling()->slowFirstChild(), false); | 277 toLayoutBlock(parent())->moveChildTo(toLayoutBlock(nextSibling()), t his, nextSibling()->slowFirstChild(), false); |
278 } | 278 } |
279 | 279 |
280 const ComputedStyle& newStyle = styleRef(); | 280 const ComputedStyle& newStyle = styleRef(); |
281 | 281 |
282 if (oldStyle && parent()) { | 282 if (oldStyle && parent()) { |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 || (next && (!next->isAnonymousBlock() || toLayoutBlock(next)->continuat ion() || toLayoutBlock(next)->beingDestroyed()))) | 597 || (next && (!next->isAnonymousBlock() || toLayoutBlock(next)->continuat ion() || toLayoutBlock(next)->beingDestroyed()))) |
598 return false; | 598 return false; |
599 | 599 |
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::makeChildrenInlineIfPossible() |
608 { | 608 { |
609 ASSERT(isLayoutBlockFlow()); | 609 ASSERT(isLayoutBlockFlow()); |
610 Vector<LayoutBox*, 16> blocksToRemove; | 610 // Collapsing away anonymous wrappers isn't relevant for the children of ano nymous blocks. |
611 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { | 611 if (isAnonymousBlock()) |
612 return; | |
613 | |
614 Vector<LayoutBlock*, 3> blocksToRemove; | |
615 for (LayoutObject* child = firstChild(); child; child = child->nextSibling() ) { | |
612 if (child->isFloatingOrOutOfFlowPositioned()) | 616 if (child->isFloatingOrOutOfFlowPositioned()) |
613 continue; | 617 continue; |
614 | 618 |
615 // There are still block children in the container, so any anonymous wra ppers are still needed. | 619 // There are still block children in the container, so any anonymous wra ppers are still needed. |
616 if (!child->isAnonymousBlock()) | 620 if (!child->isAnonymousBlock()) |
617 return; | 621 return; |
618 // We can't remove anonymous wrappers if they contain continuations as t his means there are block children present. | 622 // 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()) | 623 if (child->isLayoutBlock() && toLayoutBlock(child)->continuation()) |
620 return; | 624 return; |
621 // We are only interested in removing anonymous wrappers if there are in line siblings underneath them. | 625 // We are only interested in removing anonymous wrappers if there are in line siblings underneath them. |
622 if (!child->childrenInline()) | 626 if (!child->childrenInline()) |
623 return; | 627 return; |
628 // Ruby elements use anonymous wrappers for ruby runs and ruby bases by design, so we don't remove them. | |
629 if (child->isRubyRun() || child->isRubyBase()) | |
630 return; | |
624 | 631 |
625 if (child->isAnonymousBlock()) | 632 blocksToRemove.append(toLayoutBlock(child)); |
626 blocksToRemove.append(child); | |
627 } | 633 } |
628 | 634 |
629 for (size_t i = 0; i < blocksToRemove.size(); i++) | 635 for (size_t i = 0; i < blocksToRemove.size(); i++) |
630 collapseAnonymousBlockChild(this, toLayoutBlock(blocksToRemove[i])); | 636 collapseAnonymousBlockChild(this, blocksToRemove[i]); |
637 setChildrenInline(true); | |
631 } | 638 } |
632 | 639 |
633 void LayoutBlock::collapseAnonymousBlockChild(LayoutBlock* parent, LayoutBlock* child) | 640 void LayoutBlock::collapseAnonymousBlockChild(LayoutBlock* parent, LayoutBlock* child) |
634 { | 641 { |
635 // It's possible that this block's destruction may have been triggered by th e | 642 // It's possible that this block's destruction may have been triggered by th e |
636 // child's removal. Just bail if the anonymous child block is already being | 643 // child's removal. Just bail if the anonymous child block is already being |
637 // destroyed. See crbug.com/282088 | 644 // destroyed. See crbug.com/282088 |
638 if (child->beingDestroyed()) | 645 if (child->beingDestroyed()) |
639 return; | 646 return; |
640 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInva lidationReason::ChildAnonymousBlockChanged); | 647 parent->setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(LayoutInva lidationReason::ChildAnonymousBlockChanged); |
641 | 648 |
642 child->moveAllChildrenTo(parent, child->nextSibling(), child->hasLayer()); | 649 child->moveAllChildrenTo(parent, child->nextSibling(), child->hasLayer()); |
643 parent->setChildrenInline(child->childrenInline()); | 650 parent->setChildrenInline(child->childrenInline()); |
644 | 651 |
645 parent->children()->removeChildNode(parent, child, child->hasLayer()); | 652 parent->children()->removeChildNode(parent, child, child->hasLayer()); |
646 child->destroy(); | 653 child->destroy(); |
647 } | 654 } |
648 | 655 |
649 static inline bool shouldMakeChildrenInline(const LayoutBlock* block) | |
650 { | |
651 if (!block->isLayoutBlockFlow()) | |
652 return false; | |
653 LayoutObject* child = block->firstChild(); | |
654 while (child) { | |
655 // TODO(rhogan): If we encounter anonymous blocks with inline children w e should fold them in here. | |
656 if (!child->isFloatingOrOutOfFlowPositioned()) | |
657 return false; | |
658 child = child->nextSibling(); | |
659 } | |
660 return true; | |
661 } | |
662 | |
663 void LayoutBlock::removeChild(LayoutObject* oldChild) | 656 void LayoutBlock::removeChild(LayoutObject* oldChild) |
664 { | 657 { |
665 // No need to waste time in merging or removing empty anonymous blocks. | 658 // No need to waste time in merging or removing empty anonymous blocks. |
666 // We can just bail out if our document is getting destroyed. | 659 // We can just bail out if our document is getting destroyed. |
667 if (documentBeingDestroyed()) { | 660 if (documentBeingDestroyed()) { |
668 LayoutBox::removeChild(oldChild); | 661 LayoutBox::removeChild(oldChild); |
669 return; | 662 return; |
670 } | 663 } |
671 | 664 |
672 // If this child is a block, and if our previous and next siblings are | 665 // If this child is a block, and if our previous and next siblings are |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 else if (curr->isLayoutBlock()) | 748 else if (curr->isLayoutBlock()) |
756 toLayoutBlock(curr)->setContinuation(nextContinuation); | 749 toLayoutBlock(curr)->setContinuation(nextContinuation); |
757 else | 750 else |
758 ASSERT_NOT_REACHED(); | 751 ASSERT_NOT_REACHED(); |
759 | 752 |
760 break; | 753 break; |
761 } | 754 } |
762 setContinuation(nullptr); | 755 setContinuation(nullptr); |
763 destroy(); | 756 destroy(); |
764 } | 757 } |
765 } else if (!beingDestroyed() && !oldChild->isFloatingOrOutOfFlowPositioned() && shouldMakeChildrenInline(this)) { | 758 } else if (!beingDestroyed() && !oldChild->isFloatingOrOutOfFlowPositioned() && isLayoutBlockFlow()) { |
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. | 759 // 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); | 760 makeChildrenInlineIfPossible(); |
768 } | 761 } |
769 } | 762 } |
770 | 763 |
771 bool LayoutBlock::isSelfCollapsingBlock() const | 764 bool LayoutBlock::isSelfCollapsingBlock() const |
772 { | 765 { |
773 // We are not self-collapsing if we | 766 // We are not self-collapsing if we |
774 // (a) have a non-zero height according to layout (an optimization to avoid wasting time) | 767 // (a) have a non-zero height according to layout (an optimization to avoid wasting time) |
775 // (b) are a table, | 768 // (b) are a table, |
776 // (c) have border/padding, | 769 // (c) have border/padding, |
777 // (d) have a min-height | 770 // (d) have a min-height |
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2880 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const | 2873 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const |
2881 { | 2874 { |
2882 showLayoutObject(); | 2875 showLayoutObject(); |
2883 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) | 2876 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) |
2884 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); | 2877 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); |
2885 } | 2878 } |
2886 | 2879 |
2887 #endif | 2880 #endif |
2888 | 2881 |
2889 } // namespace blink | 2882 } // namespace blink |
OLD | NEW |