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

Side by Side Diff: sky/engine/core/rendering/RenderBox.cpp

Issue 692563004: Remove more support for floats from RenderBlockFlow. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
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) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 RenderBoxModelObject::willBeDestroyed(); 87 RenderBoxModelObject::willBeDestroyed();
88 } 88 }
89 89
90 void RenderBox::removeFloatingOrPositionedChildFromBlockLists() 90 void RenderBox::removeFloatingOrPositionedChildFromBlockLists()
91 { 91 {
92 ASSERT(isFloatingOrOutOfFlowPositioned()); 92 ASSERT(isFloatingOrOutOfFlowPositioned());
93 93
94 if (documentBeingDestroyed()) 94 if (documentBeingDestroyed())
95 return; 95 return;
96 96
97 if (isFloating()) {
98 RenderBlockFlow* parentBlockFlow = 0;
99 for (RenderObject* curr = parent(); curr && !curr->isRenderView(); curr = curr->parent()) {
100 if (curr->isRenderBlockFlow()) {
101 RenderBlockFlow* currBlockFlow = toRenderBlockFlow(curr);
102 if (!parentBlockFlow || currBlockFlow->containsFloat(this))
103 parentBlockFlow = currBlockFlow;
104 }
105 }
106
107 if (parentBlockFlow) {
108 parentBlockFlow->markSiblingsWithFloatsForLayout(this);
109 parentBlockFlow->markAllDescendantsWithFloatsForLayout(this, false);
110 }
111 }
112
113 if (isOutOfFlowPositioned()) 97 if (isOutOfFlowPositioned())
114 RenderBlock::removePositionedObject(this); 98 RenderBlock::removePositionedObject(this);
115 } 99 }
116 100
117 void RenderBox::styleWillChange(StyleDifference diff, const RenderStyle& newStyl e) 101 void RenderBox::styleWillChange(StyleDifference diff, const RenderStyle& newStyl e)
118 { 102 {
119 RenderStyle* oldStyle = style(); 103 RenderStyle* oldStyle = style();
120 if (oldStyle) { 104 if (oldStyle) {
121 // When a layout hint happens and an object's position style changes, we have to do a layout 105 // When a layout hint happens and an object's position style changes, we have to do a layout
122 // to dirty the render tree using the old position value now. 106 // to dirty the render tree using the old position value now.
123 if (diff.needsFullLayout() && parent() && oldStyle->position() != newSty le.position()) { 107 if (diff.needsFullLayout() && parent() && oldStyle->position() != newSty le.position()) {
124 markContainingBlocksForLayout(); 108 markContainingBlocksForLayout();
125 if (oldStyle->position() == StaticPosition) 109 if (oldStyle->position() == StaticPosition)
126 setShouldDoFullPaintInvalidation(true); 110 setShouldDoFullPaintInvalidation(true);
127 else if (newStyle.hasOutOfFlowPosition()) 111 else if (newStyle.hasOutOfFlowPosition())
128 parent()->setChildNeedsLayout(); 112 parent()->setChildNeedsLayout();
129 if (isFloating() && !isOutOfFlowPositioned() && newStyle.hasOutOfFlo wPosition())
130 removeFloatingOrPositionedChildFromBlockLists();
131 } 113 }
132 } 114 }
133 115
134 RenderBoxModelObject::styleWillChange(diff, newStyle); 116 RenderBoxModelObject::styleWillChange(diff, newStyle);
135 } 117 }
136 118
137 void RenderBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle ) 119 void RenderBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle )
138 { 120 {
139 RenderBoxModelObject::styleDidChange(diff, oldStyle); 121 RenderBoxModelObject::styleDidChange(diff, oldStyle);
140 122
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 else 1697 else
1716 o->mapRectToPaintInvalidationBacking(paintInvalidationContainer, rect, p aintInvalidationState); 1698 o->mapRectToPaintInvalidationBacking(paintInvalidationContainer, rect, p aintInvalidationState);
1717 } 1699 }
1718 1700
1719 void RenderBox::inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect& p aintInvalidationRect) const 1701 void RenderBox::inflatePaintInvalidationRectForReflectionAndFilter(LayoutRect& p aintInvalidationRect) const
1720 { 1702 {
1721 if (style()->hasFilter()) 1703 if (style()->hasFilter())
1722 style()->filterOutsets().expandRect(paintInvalidationRect); 1704 style()->filterOutsets().expandRect(paintInvalidationRect);
1723 } 1705 }
1724 1706
1725 void RenderBox::invalidatePaintForOverhangingFloats(bool)
1726 {
1727 }
1728
1729 void RenderBox::updateLogicalWidth() 1707 void RenderBox::updateLogicalWidth()
1730 { 1708 {
1731 LogicalExtentComputedValues computedValues; 1709 LogicalExtentComputedValues computedValues;
1732 computeLogicalWidth(computedValues); 1710 computeLogicalWidth(computedValues);
1733 1711
1734 setLogicalWidth(computedValues.m_extent); 1712 setLogicalWidth(computedValues.m_extent);
1735 setLogicalLeft(computedValues.m_position); 1713 setLogicalLeft(computedValues.m_position);
1736 setMarginStart(computedValues.m_margins.m_start); 1714 setMarginStart(computedValues.m_margins.m_start);
1737 setMarginEnd(computedValues.m_margins.m_end); 1715 setMarginEnd(computedValues.m_margins.m_end);
1738 } 1716 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); 1782 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection();
1805 if (hasInvertedDirection) 1783 if (hasInvertedDirection)
1806 computedValues.m_margins.m_start = newMargin; 1784 computedValues.m_margins.m_start = newMargin;
1807 else 1785 else
1808 computedValues.m_margins.m_end = newMargin; 1786 computedValues.m_margins.m_end = newMargin;
1809 } 1787 }
1810 } 1788 }
1811 1789
1812 LayoutUnit RenderBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth) con st 1790 LayoutUnit RenderBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth) con st
1813 { 1791 {
1814 LayoutUnit marginStart = 0; 1792 LayoutUnit marginStart = minimumValueForLength(style()->marginStart(), avail ableLogicalWidth);
1815 LayoutUnit marginEnd = 0; 1793 LayoutUnit marginEnd = minimumValueForLength(style()->marginEnd(), available LogicalWidth);
1816 return fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd);
1817 }
1818
1819 LayoutUnit RenderBox::fillAvailableMeasure(LayoutUnit availableLogicalWidth, Lay outUnit& marginStart, LayoutUnit& marginEnd) const
1820 {
1821 marginStart = minimumValueForLength(style()->marginStart(), availableLogical Width);
1822 marginEnd = minimumValueForLength(style()->marginEnd(), availableLogicalWidt h);
1823 return availableLogicalWidth - marginStart - marginEnd; 1794 return availableLogicalWidth - marginStart - marginEnd;
1824 } 1795 }
1825 1796
1826 LayoutUnit RenderBox::computeIntrinsicLogicalWidthUsing(const Length& logicalWid thLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const 1797 LayoutUnit RenderBox::computeIntrinsicLogicalWidthUsing(const Length& logicalWid thLength, LayoutUnit availableLogicalWidth, LayoutUnit borderAndPadding) const
1827 { 1798 {
1828 if (logicalWidthLength.type() == FillAvailable) 1799 if (logicalWidthLength.type() == FillAvailable)
1829 return fillAvailableMeasure(availableLogicalWidth); 1800 return fillAvailableMeasure(availableLogicalWidth);
1830 1801
1831 LayoutUnit minLogicalWidth = 0; 1802 LayoutUnit minLogicalWidth = 0;
1832 LayoutUnit maxLogicalWidth = 0; 1803 LayoutUnit maxLogicalWidth = 0;
(...skipping 18 matching lines...) Expand all
1851 LayoutUnit RenderBox::computeLogicalWidthUsing(SizeType widthType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* cb) const 1822 LayoutUnit RenderBox::computeLogicalWidthUsing(SizeType widthType, const Length& logicalWidth, LayoutUnit availableLogicalWidth, const RenderBlock* cb) const
1852 { 1823 {
1853 if (!logicalWidth.isIntrinsicOrAuto()) { 1824 if (!logicalWidth.isIntrinsicOrAuto()) {
1854 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead. 1825 // FIXME: If the containing block flow is perpendicular to our direction we need to use the available logical height instead.
1855 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth)); 1826 return adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(logicalWid th, availableLogicalWidth));
1856 } 1827 }
1857 1828
1858 if (logicalWidth.isIntrinsic()) 1829 if (logicalWidth.isIntrinsic())
1859 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth()); 1830 return computeIntrinsicLogicalWidthUsing(logicalWidth, availableLogicalW idth, borderAndPaddingLogicalWidth());
1860 1831
1861 LayoutUnit marginStart = 0; 1832 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth);
1862 LayoutUnit marginEnd = 0;
1863 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth, marginStart, marginEnd);
1864
1865 if (shrinkToAvoidFloats() && cb->isRenderBlockFlow() && toRenderBlockFlow(cb )->containsFloats())
1866 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv oidFloats(marginStart, marginEnd, toRenderBlockFlow(cb)));
1867 1833
1868 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica lWidth)) 1834 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica lWidth))
1869 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical Width(), logicalWidthResult)); 1835 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical Width(), logicalWidthResult));
1870 return logicalWidthResult; 1836 return logicalWidthResult;
1871 } 1837 }
1872 1838
1873 static bool columnFlexItemHasStretchAlignment(const RenderObject* flexitem) 1839 static bool columnFlexItemHasStretchAlignment(const RenderObject* flexitem)
1874 { 1840 {
1875 RenderObject* parent = flexitem->parent(); 1841 RenderObject* parent = flexitem->parent();
1876 // auto margins mean we don't stretch. Note that this function will only be used for 1842 // auto margins mean we don't stretch. Note that this function will only be used for
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 // See also http://dev.w3.org/csswg/css-flexbox/#auto-margins 1888 // See also http://dev.w3.org/csswg/css-flexbox/#auto-margins
1923 if (marginStartLength.isAuto()) 1889 if (marginStartLength.isAuto())
1924 marginStartLength.setValue(0); 1890 marginStartLength.setValue(0);
1925 if (marginEndLength.isAuto()) 1891 if (marginEndLength.isAuto())
1926 marginEndLength.setValue(0); 1892 marginEndLength.setValue(0);
1927 } 1893 }
1928 1894
1929 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, conta inerWidth); 1895 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, conta inerWidth);
1930 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, container Width); 1896 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, container Width);
1931 1897
1932 LayoutUnit availableWidth = containerWidth;
1933 if (avoidsFloats() && containingBlock->isRenderBlockFlow() && toRenderBlockF low(containingBlock)->containsFloats()) {
1934 availableWidth = containingBlockAvailableLineWidth();
1935 if (shrinkToAvoidFloats() && availableWidth < containerWidth) {
1936 marginStart = std::max<LayoutUnit>(0, marginStartWidth);
1937 marginEnd = std::max<LayoutUnit>(0, marginEndWidth);
1938 }
1939 }
1940
1941 // CSS 2.1 (10.3.3): "If 'width' is not 'auto' and 'border-left-width' + 'pa dding-left' + 'width' + 'padding-right' + 'border-right-width' 1898 // CSS 2.1 (10.3.3): "If 'width' is not 'auto' and 'border-left-width' + 'pa dding-left' + 'width' + 'padding-right' + 'border-right-width'
1942 // (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larg er than the width of the containing block, then any 'auto' 1899 // (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larg er than the width of the containing block, then any 'auto'
1943 // values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero. 1900 // values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
1944 LayoutUnit marginBoxWidth = childWidth + (!style()->width().isAuto() ? margi nStartWidth + marginEndWidth : LayoutUnit()); 1901 LayoutUnit marginBoxWidth = childWidth + (!style()->width().isAuto() ? margi nStartWidth + marginEndWidth : LayoutUnit());
1945 1902
1946 // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element 1903 // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element
1947 // with respect to the edges of the containing block." 1904 // with respect to the edges of the containing block."
1948 const RenderStyle* containingBlockStyle = containingBlock->style(); 1905 const RenderStyle* containingBlockStyle = containingBlock->style();
1949 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && marginBoxWidt h < availableWidth) 1906 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && marginBoxWidt h < containerWidth)
1950 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlockStyle->textAlign() == WEBKIT_CENTER)) { 1907 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlockStyle->textAlign() == WEBKIT_CENTER)) {
1951 // Other browsers center the margin box for align=center elements so we match them here. 1908 // Other browsers center the margin box for align=center elements so we match them here.
1952 LayoutUnit centeredMarginBoxStart = std::max<LayoutUnit>(0, (availableWi dth - childWidth - marginStartWidth - marginEndWidth) / 2); 1909 LayoutUnit centeredMarginBoxStart = std::max<LayoutUnit>(0, (containerWi dth - childWidth - marginStartWidth - marginEndWidth) / 2);
1953 marginStart = centeredMarginBoxStart + marginStartWidth; 1910 marginStart = centeredMarginBoxStart + marginStartWidth;
1954 marginEnd = availableWidth - childWidth - marginStart + marginEndWidth; 1911 marginEnd = containerWidth - childWidth - marginStart + marginEndWidth;
1955 return; 1912 return;
1956 } 1913 }
1957 1914
1958 // CSS 2.1: "If there is exactly one value specified as 'auto', its used val ue follows from the equality." 1915 // CSS 2.1: "If there is exactly one value specified as 'auto', its used val ue follows from the equality."
1959 if (marginEndLength.isAuto() && marginBoxWidth < availableWidth) { 1916 if (marginEndLength.isAuto() && marginBoxWidth < containerWidth) {
1960 marginStart = marginStartWidth; 1917 marginStart = marginStartWidth;
1961 marginEnd = availableWidth - childWidth - marginStart; 1918 marginEnd = containerWidth - childWidth - marginStart;
1962 return; 1919 return;
1963 } 1920 }
1964 1921
1965 bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBloc kStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_ LEFT) 1922 bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBloc kStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_ LEFT)
1966 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT)); 1923 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT));
1967 if ((marginStartLength.isAuto() && marginBoxWidth < availableWidth) || pushT oEndFromTextAlign) { 1924 if ((marginStartLength.isAuto() && marginBoxWidth < containerWidth) || pushT oEndFromTextAlign) {
1968 marginEnd = marginEndWidth; 1925 marginEnd = marginEndWidth;
1969 marginStart = availableWidth - childWidth - marginEnd; 1926 marginStart = containerWidth - childWidth - marginEnd;
1970 return; 1927 return;
1971 } 1928 }
1972 1929
1973 // Either no auto margins, or our margin box width is >= the container width , auto margins will just turn into 0. 1930 // Either no auto margins, or our margin box width is >= the container width , auto margins will just turn into 0.
1974 marginStart = marginStartWidth; 1931 marginStart = marginStartWidth;
1975 marginEnd = marginEndWidth; 1932 marginEnd = marginEndWidth;
1976 } 1933 }
1977 1934
1978 void RenderBox::updateLogicalHeight() 1935 void RenderBox::updateLogicalHeight()
1979 { 1936 {
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 closestRenderer = renderer; 3373 closestRenderer = renderer;
3417 minDist = dist; 3374 minDist = dist;
3418 } 3375 }
3419 } 3376 }
3420 3377
3421 if (closestRenderer) 3378 if (closestRenderer)
3422 return closestRenderer->positionForPoint(adjustedPoint - closestRenderer ->locationOffset()); 3379 return closestRenderer->positionForPoint(adjustedPoint - closestRenderer ->locationOffset());
3423 return createPositionWithAffinity(firstPositionInOrBeforeNode(nonPseudoNode( ))); 3380 return createPositionWithAffinity(firstPositionInOrBeforeNode(nonPseudoNode( )));
3424 } 3381 }
3425 3382
3426 bool RenderBox::shrinkToAvoidFloats() const
3427 {
3428 // Floating objects don't shrink. Objects that don't avoid floats don't shr ink. Marquees don't shrink.
3429 if (isInline() || !avoidsFloats() || isFloating())
3430 return false;
3431
3432 // Only auto width objects can possibly shrink to avoid floats.
3433 return style()->width().isAuto();
3434 }
3435
3436 static bool isReplacedElement(Node* node) 3383 static bool isReplacedElement(Node* node)
3437 { 3384 {
3438 // FIXME(sky): Remove this. 3385 // FIXME(sky): Remove this.
3439 return false; 3386 return false;
3440 } 3387 }
3441 3388
3442 bool RenderBox::avoidsFloats() const 3389 bool RenderBox::avoidsFloats() const
3443 { 3390 {
3444 return isReplaced() || isReplacedElement(node()) || hasOverflowClip() || isF lexItemIncludingDeprecated(); 3391 return isReplaced() || isReplacedElement(node()) || hasOverflowClip() || isF lexItemIncludingDeprecated();
3445 } 3392 }
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 3903
3957 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style) 3904 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style)
3958 { 3905 {
3959 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor); 3906 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor);
3960 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage(); 3907 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage();
3961 ASSERT(hasBackground == style.hasBackground()); 3908 ASSERT(hasBackground == style.hasBackground());
3962 hasBorder = style.hasBorder(); 3909 hasBorder = style.hasBorder();
3963 } 3910 }
3964 3911
3965 } // namespace blink 3912 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698