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 944073006: Remove the concept of staticly positioned absolutes. (Closed) Base URL: git@github.com:domokit/mojo.git@position
Patch Set: Created 5 years, 10 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 } 94 }
95 95
96 RenderBoxModelObject::styleWillChange(diff, newStyle); 96 RenderBoxModelObject::styleWillChange(diff, newStyle);
97 } 97 }
98 98
99 void RenderBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle ) 99 void RenderBox::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle )
100 { 100 {
101 RenderBoxModelObject::styleDidChange(diff, oldStyle); 101 RenderBoxModelObject::styleDidChange(diff, oldStyle);
102 102
103 RenderStyle* newStyle = style(); 103 if (needsLayout() && oldStyle)
104 if (needsLayout() && oldStyle) {
105 RenderBlock::removePercentHeightDescendantIfNeeded(this); 104 RenderBlock::removePercentHeightDescendantIfNeeded(this);
106
107 // Normally we can do optimized positioning layout for absolute/fixed po sitioned objects. There is one special case, however, which is
108 // when the positioned object's margin-before is changed. In this case t he parent has to get a layout in order to run margin collapsing
109 // to determine the new static position.
110 if (isOutOfFlowPositioned() && newStyle->hasStaticBlockPosition() && old Style->marginBefore() != newStyle->marginBefore()
111 && parent() && !parent()->normalChildNeedsLayout())
112 parent()->setChildNeedsLayout();
113 }
114 } 105 }
115 106
116 void RenderBox::updateFromStyle() 107 void RenderBox::updateFromStyle()
117 { 108 {
118 RenderBoxModelObject::updateFromStyle(); 109 RenderBoxModelObject::updateFromStyle();
119 110
120 RenderStyle* styleToUse = style(); 111 RenderStyle* styleToUse = style();
121 112
122 if (isRenderView()) { 113 if (isRenderView()) {
123 setHasBoxDecorationBackground(true); 114 setHasBoxDecorationBackground(true);
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 m_rareData->m_inlineBoxWrapper = 0; 1110 m_rareData->m_inlineBoxWrapper = 0;
1120 } else { 1111 } else {
1121 inlineBoxWrapper()->dirtyLineBoxes(); 1112 inlineBoxWrapper()->dirtyLineBoxes();
1122 } 1113 }
1123 } 1114 }
1124 } 1115 }
1125 1116
1126 void RenderBox::positionLineBox(InlineBox* box) 1117 void RenderBox::positionLineBox(InlineBox* box)
1127 { 1118 {
1128 if (isOutOfFlowPositioned()) { 1119 if (isOutOfFlowPositioned()) {
1129 // Cache the x position only if we were an INLINE type originally.
1130 bool wasInline = style()->isOriginalDisplayInlineType();
1131 if (wasInline) {
1132 // The value is cached in the xPos of the box. We only need this va lue if
1133 // our object was inline originally, since otherwise it would have e nded up underneath
1134 // the inlines.
1135 RootInlineBox& root = box->root();
1136 root.block().setStaticInlinePositionForChild(this, LayoutUnit::fromF loatRound(box->logicalLeft()));
1137 if (style()->hasStaticInlinePosition())
1138 setChildNeedsLayout(MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
1139 } else {
1140 // Our object was a block originally, so we make our normal flow pos ition be
1141 // just below the line box (as though all the inlines that came befo re us got
1142 // wrapped in an anonymous block, which is what would have happened had we been
1143 // in flow). This value was cached in the y() of the box.
1144 layer()->setStaticBlockPosition(box->logicalTop());
1145 if (style()->hasStaticBlockPosition())
1146 setChildNeedsLayout(MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
1147 }
1148
1149 // Nuke the box.
1150 box->remove(DontMarkLineBoxes); 1120 box->remove(DontMarkLineBoxes);
1151 box->destroy(); 1121 box->destroy();
1152 } else if (isReplaced()) { 1122 } else if (isReplaced()) {
1153 setLocation(roundedLayoutPoint(box->topLeft())); 1123 setLocation(roundedLayoutPoint(box->topLeft()));
1154 setInlineBoxWrapper(box); 1124 setInlineBoxWrapper(box);
1155 } 1125 }
1156 } 1126 }
1157 1127
1158 void RenderBox::deleteLineBoxWrapper() 1128 void RenderBox::deleteLineBoxWrapper()
1159 { 1129 {
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 } 1744 }
1775 1745
1776 LayoutUnit RenderBox::containingBlockLogicalHeightForPositioned(const RenderBoxM odelObject* containingBlock) const 1746 LayoutUnit RenderBox::containingBlockLogicalHeightForPositioned(const RenderBoxM odelObject* containingBlock) const
1777 { 1747 {
1778 ASSERT(containingBlock->isBox()); 1748 ASSERT(containingBlock->isBox());
1779 const RenderBlock* cb = containingBlock->isRenderBlock() ? 1749 const RenderBlock* cb = containingBlock->isRenderBlock() ?
1780 toRenderBlock(containingBlock) : containingBlock->containingBlock(); 1750 toRenderBlock(containingBlock) : containingBlock->containingBlock();
1781 return cb->clientLogicalHeight(); 1751 return cb->clientLogicalHeight();
1782 } 1752 }
1783 1753
1784 static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh t, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUni t containerLogicalWidth) 1754 static void computePositionedStaticDistance(Length& leftOrTop, Length& rightOrBo ttom)
1785 { 1755 {
1786 if (!logicalLeft.isAuto() || !logicalRight.isAuto()) 1756 if (!leftOrTop.isAuto() || !rightOrBottom.isAuto())
1787 return; 1757 return;
1788 1758 leftOrTop.setValue(Fixed, 0);
1789 // FIXME: The static distance computation has not been patched for mixed wri ting modes yet.
1790 if (child->parent()->style()->direction() == LTR) {
1791 LayoutUnit staticPosition = child->layer()->staticInlinePosition() - con tainerBlock->borderLogicalLeft();
1792 for (RenderObject* curr = child->parent(); curr && curr != containerBloc k; curr = curr->container()) {
1793 if (curr->isBox())
1794 staticPosition += toRenderBox(curr)->logicalLeft();
1795 }
1796 logicalLeft.setValue(Fixed, staticPosition);
1797 } else {
1798 RenderBox* enclosingBox = child->parent()->enclosingBox();
1799 LayoutUnit staticPosition = child->layer()->staticInlinePosition() + con tainerLogicalWidth + containerBlock->borderLogicalLeft();
1800 for (RenderObject* curr = child->parent(); curr; curr = curr->container( )) {
1801 if (curr->isBox()) {
1802 if (curr != containerBlock)
1803 staticPosition -= toRenderBox(curr)->logicalLeft();
1804 if (curr == enclosingBox)
1805 staticPosition -= enclosingBox->logicalWidth();
1806 }
1807 if (curr == containerBlock)
1808 break;
1809 }
1810 logicalRight.setValue(Fixed, staticPosition);
1811 }
1812 } 1759 }
1813 1760
1814 void RenderBox::computePositionedLogicalWidth(LogicalExtentComputedValues& compu tedValues) const 1761 void RenderBox::computePositionedLogicalWidth(LogicalExtentComputedValues& compu tedValues) const
1815 { 1762 {
1816 if (isReplaced()) { 1763 if (isReplaced()) {
1817 computePositionedLogicalWidthReplaced(computedValues); 1764 computePositionedLogicalWidthReplaced(computedValues);
1818 return; 1765 return;
1819 } 1766 }
1820 1767
1821 // QUESTIONS 1768 // QUESTIONS
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 * user agents are free to make a guess at its probable position. 1818 * user agents are free to make a guess at its probable position.
1872 * 1819 *
1873 * For the purposes of calculating the static position, the containing block of 1820 * For the purposes of calculating the static position, the containing block of
1874 * fixed positioned elements is the initial containing block instead of the 1821 * fixed positioned elements is the initial containing block instead of the
1875 * viewport, and all scrollable boxes should be assumed to be scrolled to th eir 1822 * viewport, and all scrollable boxes should be assumed to be scrolled to th eir
1876 * origin. 1823 * origin.
1877 \*-------------------------------------------------------------------------- -*/ 1824 \*-------------------------------------------------------------------------- -*/
1878 1825
1879 // see FIXME 1 1826 // see FIXME 1
1880 // Calculate the static distance if needed. 1827 // Calculate the static distance if needed.
1881 computeInlineStaticDistance(logicalLeftLength, logicalRightLength, this, con tainerBlock, containerLogicalWidth); 1828 computePositionedStaticDistance(logicalLeftLength, logicalRightLength);
1882 1829
1883 // Calculate constraint equation values for 'width' case. 1830 // Calculate constraint equation values for 'width' case.
1884 computePositionedLogicalWidthUsing(style()->logicalWidth(), containerBlock, containerDirection, 1831 computePositionedLogicalWidthUsing(style()->logicalWidth(), containerBlock, containerDirection,
1885 containerLogicalWidth, bordersPlusPadding , 1832 containerLogicalWidth, bordersPlusPadding ,
1886 logicalLeftLength, logicalRightLength, ma rginLogicalLeft, marginLogicalRight, 1833 logicalLeftLength, logicalRightLength, ma rginLogicalLeft, marginLogicalRight,
1887 computedValues); 1834 computedValues);
1888 1835
1889 // Calculate constraint equation values for 'max-width' case. 1836 // Calculate constraint equation values for 'max-width' case.
1890 if (!style()->logicalMaxWidth().isMaxSizeNone()) { 1837 if (!style()->logicalMaxWidth().isMaxSizeNone()) {
1891 LogicalExtentComputedValues maxValues; 1838 LogicalExtentComputedValues maxValues;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 if (firstLine && lastLine && firstLine != lastLine) { 2055 if (firstLine && lastLine && firstLine != lastLine) {
2109 computedValues.m_position = logicalLeftValue + marginLogicalLeftValu e + lastLine->borderLogicalLeft() + (lastLine->logicalLeft() - firstLine->logica lLeft()); 2056 computedValues.m_position = logicalLeftValue + marginLogicalLeftValu e + lastLine->borderLogicalLeft() + (lastLine->logicalLeft() - firstLine->logica lLeft());
2110 return; 2057 return;
2111 } 2058 }
2112 } 2059 }
2113 2060
2114 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue; 2061 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue;
2115 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth); 2062 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth);
2116 } 2063 }
2117 2064
2118 static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom , const RenderBox* child, const RenderBoxModelObject* containerBlock)
2119 {
2120 if (!logicalTop.isAuto() || !logicalBottom.isAuto())
2121 return;
2122
2123 // FIXME: The static distance computation has not been patched for mixed wri ting modes.
2124 LayoutUnit staticLogicalTop = child->layer()->staticBlockPosition() - contai nerBlock->borderBefore();
2125 for (RenderObject* curr = child->parent(); curr && curr != containerBlock; c urr = curr->container()) {
2126 if (curr->isBox())
2127 staticLogicalTop += toRenderBox(curr)->logicalTop();
2128 }
2129 logicalTop.setValue(Fixed, staticLogicalTop);
2130 }
2131
2132 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const 2065 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const
2133 { 2066 {
2134 if (isReplaced()) { 2067 if (isReplaced()) {
2135 computePositionedLogicalHeightReplaced(computedValues); 2068 computePositionedLogicalHeightReplaced(computedValues);
2136 return; 2069 return;
2137 } 2070 }
2138 2071
2139 // The following is based off of the W3C Working Draft from April 11, 2006 o f 2072 // The following is based off of the W3C Working Draft from April 11, 2006 o f
2140 // CSS 2.1: Section 10.6.4 "Absolutely positioned, non-replaced elements" 2073 // CSS 2.1: Section 10.6.4 "Absolutely positioned, non-replaced elements"
2141 // <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-non-replace d-height> 2074 // <http://www.w3.org/TR/2005/WD-CSS21-20050613/visudet.html#abs-non-replace d-height>
(...skipping 25 matching lines...) Expand all
2167 * But rather than actually calculating the dimensions of that hypothetical 2100 * But rather than actually calculating the dimensions of that hypothetical
2168 * box, user agents are free to make a guess at its probable position. 2101 * box, user agents are free to make a guess at its probable position.
2169 * 2102 *
2170 * For the purposes of calculating the static position, the containing block 2103 * For the purposes of calculating the static position, the containing block
2171 * of fixed positioned elements is the initial containing block instead of 2104 * of fixed positioned elements is the initial containing block instead of
2172 * the viewport. 2105 * the viewport.
2173 \*-------------------------------------------------------------------------- -*/ 2106 \*-------------------------------------------------------------------------- -*/
2174 2107
2175 // see FIXME 1 2108 // see FIXME 1
2176 // Calculate the static distance if needed. 2109 // Calculate the static distance if needed.
2177 computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, cont ainerBlock); 2110 computePositionedStaticDistance(logicalTopLength, logicalBottomLength);
2178 2111
2179 // Calculate constraint equation values for 'height' case. 2112 // Calculate constraint equation values for 'height' case.
2180 LayoutUnit logicalHeight = computedValues.m_extent; 2113 LayoutUnit logicalHeight = computedValues.m_extent;
2181 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight, 2114 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight,
2182 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter, 2115 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter,
2183 computedValues); 2116 computedValues);
2184 2117
2185 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults). 2118 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults).
2186 // see FIXME 2 2119 // see FIXME 2
2187 2120
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 computedValues.m_extent = computeReplacedLogicalWidth() + borderAndPaddingLo gicalWidth(); 2321 computedValues.m_extent = computeReplacedLogicalWidth() + borderAndPaddingLo gicalWidth();
2389 2322
2390 const LayoutUnit availableSpace = containerLogicalWidth - computedValues.m_e xtent; 2323 const LayoutUnit availableSpace = containerLogicalWidth - computedValues.m_e xtent;
2391 2324
2392 /*-----------------------------------------------------------------------*\ 2325 /*-----------------------------------------------------------------------*\
2393 * 2. If both 'left' and 'right' have the value 'auto', then if 'direction' 2326 * 2. If both 'left' and 'right' have the value 'auto', then if 'direction'
2394 * of the containing block is 'ltr', set 'left' to the static position; 2327 * of the containing block is 'ltr', set 'left' to the static position;
2395 * else if 'direction' is 'rtl', set 'right' to the static position. 2328 * else if 'direction' is 'rtl', set 'right' to the static position.
2396 \*-----------------------------------------------------------------------*/ 2329 \*-----------------------------------------------------------------------*/
2397 // see FIXME 1 2330 // see FIXME 1
2398 computeInlineStaticDistance(logicalLeft, logicalRight, this, containerBlock, containerLogicalWidth); 2331 computePositionedStaticDistance(logicalLeft, logicalRight);
2399 2332
2400 /*-----------------------------------------------------------------------*\ 2333 /*-----------------------------------------------------------------------*\
2401 * 3. If 'left' or 'right' are 'auto', replace any 'auto' on 'margin-left' 2334 * 3. If 'left' or 'right' are 'auto', replace any 'auto' on 'margin-left'
2402 * or 'margin-right' with '0'. 2335 * or 'margin-right' with '0'.
2403 \*-----------------------------------------------------------------------*/ 2336 \*-----------------------------------------------------------------------*/
2404 if (logicalLeft.isAuto() || logicalRight.isAuto()) { 2337 if (logicalLeft.isAuto() || logicalRight.isAuto()) {
2405 if (marginLogicalLeft.isAuto()) 2338 if (marginLogicalLeft.isAuto())
2406 marginLogicalLeft.setValue(Fixed, 0); 2339 marginLogicalLeft.setValue(Fixed, 0);
2407 if (marginLogicalRight.isAuto()) 2340 if (marginLogicalRight.isAuto())
2408 marginLogicalRight.setValue(Fixed, 0); 2341 marginLogicalRight.setValue(Fixed, 0);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 // are dealt with in computeReplacedHeight(). This means that the steps to produce 2483 // are dealt with in computeReplacedHeight(). This means that the steps to produce
2551 // correct max/min in the non-replaced version, are not necessary. 2484 // correct max/min in the non-replaced version, are not necessary.
2552 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight(); 2485 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight();
2553 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent; 2486 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent;
2554 2487
2555 /*-----------------------------------------------------------------------*\ 2488 /*-----------------------------------------------------------------------*\
2556 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top' 2489 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top'
2557 * with the element's static position. 2490 * with the element's static position.
2558 \*-----------------------------------------------------------------------*/ 2491 \*-----------------------------------------------------------------------*/
2559 // see FIXME 1 2492 // see FIXME 1
2560 computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock); 2493 computePositionedStaticDistance(logicalTop, logicalBottom);
2561 2494
2562 /*-----------------------------------------------------------------------*\ 2495 /*-----------------------------------------------------------------------*\
2563 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or 2496 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or
2564 * 'margin-bottom' with '0'. 2497 * 'margin-bottom' with '0'.
2565 \*-----------------------------------------------------------------------*/ 2498 \*-----------------------------------------------------------------------*/
2566 // FIXME: The spec. says that this step should only be taken when bottom is 2499 // FIXME: The spec. says that this step should only be taken when bottom is
2567 // auto, but if only top is auto, this makes step 4 impossible. 2500 // auto, but if only top is auto, this makes step 4 impossible.
2568 if (logicalTop.isAuto() || logicalBottom.isAuto()) { 2501 if (logicalTop.isAuto() || logicalBottom.isAuto()) {
2569 if (marginBefore.isAuto()) 2502 if (marginBefore.isAuto())
2570 marginBefore.setValue(Fixed, 0); 2503 marginBefore.setValue(Fixed, 0);
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 2954
3022 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style) 2955 RenderBox::BoxDecorationData::BoxDecorationData(const RenderStyle& style)
3023 { 2956 {
3024 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor); 2957 backgroundColor = style.colorIncludingFallback(CSSPropertyBackgroundColor);
3025 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage(); 2958 hasBackground = backgroundColor.alpha() || style.hasBackgroundImage();
3026 ASSERT(hasBackground == style.hasBackground()); 2959 ASSERT(hasBackground == style.hasBackground());
3027 hasBorder = style.hasBorder(); 2960 hasBorder = style.hasBorder();
3028 } 2961 }
3029 2962
3030 } // namespace blink 2963 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698