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 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 } else { | 845 } else { |
846 // We will reach here when beforeChild is a run-in element. | 846 // We will reach here when beforeChild is a run-in element. |
847 // If run-in element precedes a block-level element, it becomes the | 847 // If run-in element precedes a block-level element, it becomes the |
848 // the first inline child of that block level element. The insertion | 848 // the first inline child of that block level element. The insertion |
849 // point will be before that block-level element. | 849 // point will be before that block-level element. |
850 ASSERT(beforeChild->isRunIn()); | 850 ASSERT(beforeChild->isRunIn()); |
851 beforeChild = beforeChildContainer; | 851 beforeChild = beforeChildContainer; |
852 } | 852 } |
853 } | 853 } |
854 | 854 |
| 855 // Nothing goes before the intruded run-in. |
| 856 if (beforeChild && beforeChild->isRunIn() && runInIsPlacedIntoSiblingBlock(b
eforeChild)) |
| 857 beforeChild = beforeChild->nextSibling(); |
| 858 |
855 // Check for a spanning element in columns. | 859 // Check for a spanning element in columns. |
856 RenderBlock* columnsBlockAncestor = columnsBlockForSpanningElement(newChild)
; | 860 RenderBlock* columnsBlockAncestor = columnsBlockForSpanningElement(newChild)
; |
857 if (columnsBlockAncestor) { | 861 if (columnsBlockAncestor) { |
858 // We are placing a column-span element inside a block. | 862 // We are placing a column-span element inside a block. |
859 RenderBlock* newBox = createAnonymousColumnSpanBlock(); | 863 RenderBlock* newBox = createAnonymousColumnSpanBlock(); |
860 | 864 |
861 if (columnsBlockAncestor != this) { | 865 if (columnsBlockAncestor != this) { |
862 // We are nested inside a multi-column element and are being split b
y the span. We have to break up | 866 // We are nested inside a multi-column element and are being split b
y the span. We have to break up |
863 // our block into continuations. | 867 // our block into continuations. |
864 RenderBoxModelObject* oldContinuation = continuation(); | 868 RenderBoxModelObject* oldContinuation = continuation(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 // No suitable existing anonymous box - create a new one. | 930 // No suitable existing anonymous box - create a new one. |
927 RenderBlock* newBox = createAnonymousBlock(); | 931 RenderBlock* newBox = createAnonymousBlock(); |
928 RenderBox::addChild(newBox, beforeChild); | 932 RenderBox::addChild(newBox, beforeChild); |
929 newBox->addChild(newChild); | 933 newBox->addChild(newChild); |
930 return; | 934 return; |
931 } | 935 } |
932 } | 936 } |
933 | 937 |
934 RenderBox::addChild(newChild, beforeChild); | 938 RenderBox::addChild(newChild, beforeChild); |
935 | 939 |
936 // Handle positioning of run-ins. | 940 // Handle placement of run-ins. |
937 if (newChild->isRunIn()) | 941 placeRunInIfNeeded(newChild, DoNotPlaceGeneratedRunIn); |
938 moveRunInUnderSiblingBlockIfNeeded(newChild); | |
939 else if (RenderObject* prevSibling = newChild->previousSibling()) { | |
940 if (prevSibling->isRunIn()) | |
941 moveRunInUnderSiblingBlockIfNeeded(prevSibling); | |
942 } | |
943 | 942 |
944 if (madeBoxesNonInline && parent() && isAnonymousBlock() && parent()->isRend
erBlock()) | 943 if (madeBoxesNonInline && parent() && isAnonymousBlock() && parent()->isRend
erBlock()) |
945 toRenderBlock(parent())->removeLeftoverAnonymousBlock(this); | 944 toRenderBlock(parent())->removeLeftoverAnonymousBlock(this); |
946 // this object may be dead here | 945 // this object may be dead here |
947 } | 946 } |
948 | 947 |
949 void RenderBlock::addChild(RenderObject* newChild, RenderObject* beforeChild) | 948 void RenderBlock::addChild(RenderObject* newChild, RenderObject* beforeChild) |
950 { | 949 { |
951 if (continuation() && !isAnonymousBlock()) | 950 if (continuation() && !isAnonymousBlock()) |
952 addChildToContinuation(newChild, beforeChild); | 951 addChildToContinuation(newChild, beforeChild); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 // splitting them. | 1038 // splitting them. |
1040 ASSERT(isInlineBlockOrInlineTable() || !isInline()); | 1039 ASSERT(isInlineBlockOrInlineTable() || !isInline()); |
1041 ASSERT(!insertionPoint || insertionPoint->parent() == this); | 1040 ASSERT(!insertionPoint || insertionPoint->parent() == this); |
1042 | 1041 |
1043 setChildrenInline(false); | 1042 setChildrenInline(false); |
1044 | 1043 |
1045 RenderObject *child = firstChild(); | 1044 RenderObject *child = firstChild(); |
1046 if (!child) | 1045 if (!child) |
1047 return; | 1046 return; |
1048 | 1047 |
| 1048 deleteLineBoxTree(); |
| 1049 |
1049 // Since we are going to have block children, we have to move | 1050 // Since we are going to have block children, we have to move |
1050 // back the run-in to its original place. | 1051 // back the run-in to its original place. |
1051 if (child->isRunIn()) { | 1052 if (child->isRunIn()) { |
1052 moveRunInToOriginalPosition(child); | 1053 moveRunInToOriginalPosition(child); |
1053 child = firstChild(); | 1054 child = firstChild(); |
1054 } | 1055 } |
1055 | 1056 |
1056 deleteLineBoxTree(); | |
1057 | |
1058 while (child) { | 1057 while (child) { |
1059 RenderObject *inlineRunStart, *inlineRunEnd; | 1058 RenderObject *inlineRunStart, *inlineRunEnd; |
1060 getInlineRun(child, insertionPoint, inlineRunStart, inlineRunEnd); | 1059 getInlineRun(child, insertionPoint, inlineRunStart, inlineRunEnd); |
1061 | 1060 |
1062 if (!inlineRunStart) | 1061 if (!inlineRunStart) |
1063 break; | 1062 break; |
1064 | 1063 |
1065 child = inlineRunEnd->nextSibling(); | 1064 child = inlineRunEnd->nextSibling(); |
1066 | 1065 |
1067 RenderBlock* block = createAnonymousBlock(); | 1066 RenderBlock* block = createAnonymousBlock(); |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 return true; | 1760 return true; |
1762 } | 1761 } |
1763 return false; | 1762 return false; |
1764 } | 1763 } |
1765 | 1764 |
1766 static void destroyRunIn(RenderBoxModelObject* runIn) | 1765 static void destroyRunIn(RenderBoxModelObject* runIn) |
1767 { | 1766 { |
1768 ASSERT(runIn->isRunIn()); | 1767 ASSERT(runIn->isRunIn()); |
1769 ASSERT(!runIn->firstChild()); | 1768 ASSERT(!runIn->firstChild()); |
1770 | 1769 |
1771 // If it is a block run-in, delete its line box tree as well. This is needed
as our | 1770 // Delete our line box tree. This is needed as our children got moved |
1772 // children got moved and our line box tree is no longer valid. | 1771 // and our line box tree is no longer valid. |
1773 if (runIn->isRenderBlock()) | 1772 if (runIn->isRenderBlock()) |
1774 toRenderBlock(runIn)->deleteLineBoxTree(); | 1773 toRenderBlock(runIn)->deleteLineBoxTree(); |
| 1774 else if (runIn->isRenderInline()) |
| 1775 toRenderInline(runIn)->deleteLineBoxTree(); |
| 1776 else |
| 1777 ASSERT_NOT_REACHED(); |
| 1778 |
1775 runIn->destroy(); | 1779 runIn->destroy(); |
1776 } | 1780 } |
1777 | 1781 |
| 1782 void RenderBlock::placeRunInIfNeeded(RenderObject* newChild, PlaceGeneratedRunIn
Flag flag) |
| 1783 { |
| 1784 if (newChild->isRunIn() && (flag == PlaceGeneratedRunIn || !newChild->isBefo
reOrAfterContent())) |
| 1785 moveRunInUnderSiblingBlockIfNeeded(newChild); |
| 1786 else if (RenderObject* prevSibling = newChild->previousSibling()) { |
| 1787 if (prevSibling->isRunIn() && (flag == PlaceGeneratedRunIn || !newChild-
>isBeforeOrAfterContent())) |
| 1788 moveRunInUnderSiblingBlockIfNeeded(prevSibling); |
| 1789 } |
| 1790 } |
| 1791 |
1778 RenderBoxModelObject* RenderBlock::createReplacementRunIn(RenderBoxModelObject*
runIn) | 1792 RenderBoxModelObject* RenderBlock::createReplacementRunIn(RenderBoxModelObject*
runIn) |
1779 { | 1793 { |
1780 ASSERT(runIn->isRunIn()); | 1794 ASSERT(runIn->isRunIn()); |
1781 | 1795 |
1782 // First we destroy any :before/:after content. It will be regenerated by th
e new run-in. | 1796 // First we destroy any :before/:after content. It will be regenerated by th
e new run-in. |
1783 // Exception is if the run-in itself is generated. | 1797 // Exception is if the run-in itself is generated. |
1784 if (runIn->style()->styleType() != BEFORE && runIn->style()->styleType() !=
AFTER) { | 1798 if (runIn->style()->styleType() != BEFORE && runIn->style()->styleType() !=
AFTER) { |
1785 RenderObject* generatedContent; | 1799 RenderObject* generatedContent; |
1786 if (runIn->getCachedPseudoStyle(BEFORE) && (generatedContent = runIn->be
forePseudoElementRenderer())) | 1800 if (runIn->getCachedPseudoStyle(BEFORE) && (generatedContent = runIn->be
forePseudoElementRenderer())) |
1787 generatedContent->destroy(); | 1801 generatedContent->destroy(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 return; | 1858 return; |
1845 | 1859 |
1846 RenderBoxModelObject* oldRunIn = toRenderBoxModelObject(runIn); | 1860 RenderBoxModelObject* oldRunIn = toRenderBoxModelObject(runIn); |
1847 RenderBoxModelObject* newRunIn = createReplacementRunIn(oldRunIn); | 1861 RenderBoxModelObject* newRunIn = createReplacementRunIn(oldRunIn); |
1848 destroyRunIn(oldRunIn); | 1862 destroyRunIn(oldRunIn); |
1849 | 1863 |
1850 // Now insert the new child under |curr| block. Use addChild instead of inse
rtChildNode | 1864 // Now insert the new child under |curr| block. Use addChild instead of inse
rtChildNode |
1851 // since it handles correct placement of the children, especially where we c
annot insert | 1865 // since it handles correct placement of the children, especially where we c
annot insert |
1852 // anything before the first child. e.g. details tag. See https://bugs.webki
t.org/show_bug.cgi?id=58228. | 1866 // anything before the first child. e.g. details tag. See https://bugs.webki
t.org/show_bug.cgi?id=58228. |
1853 curr->addChild(newRunIn, curr->firstChild()); | 1867 curr->addChild(newRunIn, curr->firstChild()); |
| 1868 |
| 1869 // Make sure that |this| get a layout since its run-in child moved. |
| 1870 curr->setNeedsLayoutAndPrefWidthsRecalc(); |
| 1871 } |
| 1872 |
| 1873 bool RenderBlock::runInIsPlacedIntoSiblingBlock(RenderObject* runIn) |
| 1874 { |
| 1875 ASSERT(runIn->isRunIn()); |
| 1876 |
| 1877 // If we don't have a parent, we can't be moved into our sibling block. |
| 1878 if (!parent()) |
| 1879 return false; |
| 1880 |
| 1881 // An intruded run-in needs to be an inline. |
| 1882 if (!runIn->isRenderInline()) |
| 1883 return false; |
| 1884 |
| 1885 return true; |
1854 } | 1886 } |
1855 | 1887 |
1856 void RenderBlock::moveRunInToOriginalPosition(RenderObject* runIn) | 1888 void RenderBlock::moveRunInToOriginalPosition(RenderObject* runIn) |
1857 { | 1889 { |
1858 ASSERT(runIn->isRunIn()); | 1890 ASSERT(runIn->isRunIn()); |
1859 | 1891 |
1860 // If we don't have a parent, there is nothing to move. This might | 1892 if (!runInIsPlacedIntoSiblingBlock(runIn)) |
1861 // happen if |this| got detached from parent after |runIn| run into |this|. | |
1862 if (!parent()) | |
1863 return; | |
1864 | |
1865 // An intruded run-in needs to be an inline. | |
1866 if (!runIn->isRenderInline()) | |
1867 return; | 1893 return; |
1868 | 1894 |
1869 RenderBoxModelObject* oldRunIn = toRenderBoxModelObject(runIn); | 1895 RenderBoxModelObject* oldRunIn = toRenderBoxModelObject(runIn); |
1870 RenderBoxModelObject* newRunIn = createReplacementRunIn(oldRunIn); | 1896 RenderBoxModelObject* newRunIn = createReplacementRunIn(oldRunIn); |
1871 destroyRunIn(oldRunIn); | 1897 destroyRunIn(oldRunIn); |
1872 | 1898 |
1873 // Add the run-in block as our previous sibling. | 1899 // Add the run-in block as our previous sibling. |
1874 parent()->addChild(newRunIn, this); | 1900 parent()->addChild(newRunIn, this); |
| 1901 |
| 1902 // Make sure that the parent holding the new run-in gets layout. |
| 1903 parent()->setNeedsLayoutAndPrefWidthsRecalc(); |
1875 } | 1904 } |
1876 | 1905 |
1877 LayoutUnit RenderBlock::collapseMargins(RenderBox* child, MarginInfo& marginInfo
) | 1906 LayoutUnit RenderBlock::collapseMargins(RenderBox* child, MarginInfo& marginInfo
) |
1878 { | 1907 { |
1879 // Get the four margin values for the child and cache them. | 1908 // Get the four margin values for the child and cache them. |
1880 const MarginValues childMargins = marginValuesForChild(child); | 1909 const MarginValues childMargins = marginValuesForChild(child); |
1881 | 1910 |
1882 // Get our max pos and neg top margins. | 1911 // Get our max pos and neg top margins. |
1883 LayoutUnit posTop = childMargins.positiveMarginBefore(); | 1912 LayoutUnit posTop = childMargins.positiveMarginBefore(); |
1884 LayoutUnit negTop = childMargins.negativeMarginBefore(); | 1913 LayoutUnit negTop = childMargins.negativeMarginBefore(); |
(...skipping 5467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7352 } | 7381 } |
7353 | 7382 |
7354 String ValueToString<RenderBlock::FloatingObject*>::string(const RenderBlock::Fl
oatingObject* floatingObject) | 7383 String ValueToString<RenderBlock::FloatingObject*>::string(const RenderBlock::Fl
oatingObject* floatingObject) |
7355 { | 7384 { |
7356 return String::format("%p (%dx%d %dx%d)", floatingObject, floatingObject->pi
xelSnappedX(), floatingObject->pixelSnappedY(), floatingObject->pixelSnappedMaxX
(), floatingObject->pixelSnappedMaxY()); | 7385 return String::format("%p (%dx%d %dx%d)", floatingObject, floatingObject->pi
xelSnappedX(), floatingObject->pixelSnappedY(), floatingObject->pixelSnappedMaxX
(), floatingObject->pixelSnappedMaxY()); |
7357 } | 7386 } |
7358 | 7387 |
7359 #endif | 7388 #endif |
7360 | 7389 |
7361 } // namespace WebCore | 7390 } // namespace WebCore |
OLD | NEW |