Changeset 239267 in webkit
- Timestamp:
- Dec 17, 2018 7:44:55 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r239266 r239267 1 2018-12-17 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][BFC][MarginCollapsing] Unify margin collapse function naming 4 https://bugs.webkit.org/show_bug.cgi?id=192747 5 6 Reviewed by Antti Koivisto. 7 8 Rename some margin collapse getters. 9 10 * layout/blockformatting/BlockFormattingContext.h: 11 * layout/blockformatting/BlockFormattingContextGeometry.cpp: 12 (WebCore::Layout::BlockFormattingContext::Geometry::inFlowNonReplacedHeightAndMargin): 13 * layout/blockformatting/BlockMarginCollapse.cpp: 14 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginBefore): 15 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter): 16 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginBefore): 17 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginAfter): 18 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginBeforeFromFirstChild): 19 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginAfterFromLastChild): 20 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginAfter): 21 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore): 22 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter): 23 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithPreviousSibling): 24 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithNextSibling): 25 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginsCollapseThrough): 26 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginBefore): 27 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::marginAfter): 28 (WebCore::Layout::isMarginBeforeCollapsedWithSibling): Deleted. 29 (WebCore::Layout::isMarginAfterCollapsedWithSibling): Deleted. 30 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::isMarginBeforeCollapsedWithParent): Deleted. 31 (WebCore::Layout::isMarginAfterCollapsedThrough): Deleted. 32 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::isMarginAfterCollapsedWithParent): Deleted. 33 (WebCore::Layout::BlockFormattingContext::Geometry::MarginCollapse::isMarginBeforeCollapsedWithParentMarginAfter): Deleted. 34 1 35 2018-12-17 David Kilzer <ddkilzer@apple.com> 2 36 -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h
r239206 r239267 90 90 static LayoutUnit marginAfter(const LayoutState&, const Box&); 91 91 92 static bool isMarginAfterCollapsedWithParent(const Box&);93 static bool isMarginBeforeCollapsedWithParentMarginAfter(const Box&);92 static bool marginBeforeCollapsesWithParentMarginAfter(const Box&); 93 static bool marginAfterCollapsesWithParentMarginAfter(const Box&); 94 94 95 95 private: … … 103 103 static LayoutUnit nonCollapsedMarginBefore(const LayoutState&, const Box&); 104 104 105 static bool isMarginBeforeCollapsedWithParent(const LayoutState&, const Box&); 105 static bool marginBeforeCollapsesWithParentMarginBefore(const LayoutState&, const Box&); 106 static bool marginBeforeCollapsesWithPreviousSibling(const Box&); 107 static bool marginAfterCollapsesWithNextSibling(const Box&); 108 static bool marginsCollapseThrough(const Box&); 106 109 }; 107 110 -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContextGeometry.cpp
r239206 r239267 85 85 auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild(); 86 86 ASSERT(lastInFlowChild); 87 if (!MarginCollapse:: isMarginAfterCollapsedWithParent(*lastInFlowChild)) {87 if (!MarginCollapse::marginAfterCollapsesWithParentMarginAfter(*lastInFlowChild)) { 88 88 auto& lastInFlowDisplayBox = layoutState.displayBoxForLayoutBox(*lastInFlowChild); 89 89 return { lastInFlowDisplayBox.bottom() + lastInFlowDisplayBox.marginAfter() - borderAndPaddingTop, { nonCollapsedMargin, collapsedMargin } }; … … 92 92 // 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin 93 93 auto* inFlowChild = lastInFlowChild; 94 while (inFlowChild && MarginCollapse:: isMarginBeforeCollapsedWithParentMarginAfter(*inFlowChild))94 while (inFlowChild && MarginCollapse::marginBeforeCollapsesWithParentMarginAfter(*inFlowChild)) 95 95 inFlowChild = inFlowChild->previousInFlowSibling(); 96 96 if (inFlowChild) { -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r239206 r239267 95 95 } 96 96 97 static bool isMarginBeforeCollapsedWithSibling(const Box& layoutBox) 97 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginBefore(const LayoutState& layoutState, const Box& layoutBox) 98 { 99 ASSERT(layoutBox.isBlockLevelBox()); 100 101 return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).before; 102 } 103 104 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox) 105 { 106 ASSERT(layoutBox.isBlockLevelBox()); 107 108 return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).after; 109 } 110 111 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginBefore(const LayoutState& layoutState, const Box& layoutBox) 112 { 113 ASSERT(layoutBox.isBlockLevelBox()); 114 115 // Non collapsed margin top includes collapsed margin from inflow first child. 116 return marginValue(computedNonCollapsedMarginBefore(layoutState, layoutBox), collapsedMarginBeforeFromFirstChild(layoutState, layoutBox)); 117 } 118 119 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox) 120 { 121 ASSERT(layoutBox.isBlockLevelBox()); 122 123 // Non collapsed margin bottom includes collapsed margin from inflow last child. 124 return marginValue(computedNonCollapsedMarginAfter(layoutState, layoutBox), collapsedMarginAfterFromLastChild(layoutState, layoutBox)); 125 } 126 127 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginBeforeFromFirstChild(const LayoutState& layoutState, const Box& layoutBox) 128 { 129 ASSERT(layoutBox.isBlockLevelBox()); 130 131 // Check if the first child collapses its margin top. 132 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild()) 133 return 0; 134 135 // Do not collapse margin with a box from a non-block formatting context <div><span>foobar</span></div>. 136 if (layoutBox.establishesFormattingContext() && !layoutBox.establishesBlockFormattingContextOnly()) 137 return 0; 138 139 // FIXME: Take collapsed through margin into account. 140 auto& firstInFlowChild = *downcast<Container>(layoutBox).firstInFlowChild(); 141 if (!marginBeforeCollapsesWithParentMarginBefore(layoutState, firstInFlowChild)) 142 return 0; 143 // Collect collapsed margin top recursively. 144 return marginValue(computedNonCollapsedMarginBefore(layoutState, firstInFlowChild), collapsedMarginBeforeFromFirstChild(layoutState, firstInFlowChild)); 145 } 146 147 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginAfterFromLastChild(const LayoutState& layoutState, const Box& layoutBox) 148 { 149 ASSERT(layoutBox.isBlockLevelBox()); 150 151 // Check if the last child propagates its margin bottom. 152 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild()) 153 return 0; 154 155 // Do not collapse margin with a box from a non-block formatting context <div><span>foobar</span></div>. 156 if (layoutBox.establishesFormattingContext() && !layoutBox.establishesBlockFormattingContextOnly()) 157 return 0; 158 159 // FIXME: Check for collapsed through margin. 160 auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild(); 161 if (!marginAfterCollapsesWithParentMarginAfter(lastInFlowChild)) 162 return 0; 163 164 // Collect collapsed margin bottom recursively. 165 return marginValue(computedNonCollapsedMarginAfter(layoutState, lastInFlowChild), collapsedMarginAfterFromLastChild(layoutState, lastInFlowChild)); 166 } 167 168 bool BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginAfter(const Box&) 169 { 170 return false; 171 } 172 173 bool BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithParentMarginBefore(const LayoutState& layoutState, const Box& layoutBox) 174 { 175 // The first inflow child could propagate its top margin to parent. 176 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins 177 if (layoutBox.isAnonymous()) 178 return false; 179 180 ASSERT(layoutBox.isBlockLevelBox()); 181 182 if (layoutBox.isFloatingOrOutOfFlowPositioned()) 183 return false; 184 185 // Only the first inlflow child collapses with parent. 186 if (layoutBox.previousInFlowSibling()) 187 return false; 188 189 auto& parent = *layoutBox.parent(); 190 // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children 191 if (establishesBlockFormattingContext(parent)) 192 return false; 193 194 if (hasBorderBefore(parent)) 195 return false; 196 197 if (hasPaddingBefore(parent)) 198 return false; 199 200 if (BlockFormattingContext::Quirks::shouldIgnoreMarginBefore(layoutState, layoutBox)) 201 return false; 202 203 return true; 204 } 205 206 bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithParentMarginAfter(const Box& layoutBox) 207 { 208 // last inflow box to parent. 209 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins 210 if (layoutBox.isAnonymous()) 211 return false; 212 213 ASSERT(layoutBox.isBlockLevelBox()); 214 215 if (layoutBox.isFloatingOrOutOfFlowPositioned()) 216 return false; 217 218 if (marginsCollapseThrough(layoutBox)) 219 return false; 220 221 // Only the last inlflow child collapses with parent. 222 if (layoutBox.nextInFlowSibling()) 223 return false; 224 225 auto& parent = *layoutBox.parent(); 226 // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children 227 if (establishesBlockFormattingContext(parent)) 228 return false; 229 230 if (hasBorderBefore(parent)) 231 return false; 232 233 if (hasPaddingBefore(parent)) 234 return false; 235 236 if (!parent.style().height().isAuto()) 237 return false; 238 239 return true; 240 } 241 242 bool BlockFormattingContext::Geometry::MarginCollapse::marginBeforeCollapsesWithPreviousSibling(const Box& layoutBox) 98 243 { 99 244 ASSERT(layoutBox.isBlockLevelBox()); … … 110 255 } 111 256 112 static bool isMarginAfterCollapsedWithSibling(const Box& layoutBox)257 bool BlockFormattingContext::Geometry::MarginCollapse::marginAfterCollapsesWithNextSibling(const Box& layoutBox) 113 258 { 114 259 ASSERT(layoutBox.isBlockLevelBox()); … … 125 270 } 126 271 127 bool BlockFormattingContext::Geometry::MarginCollapse::isMarginBeforeCollapsedWithParent(const LayoutState& layoutState, const Box& layoutBox) 128 { 129 // The first inflow child could propagate its top margin to parent. 130 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins 131 if (layoutBox.isAnonymous()) 132 return false; 133 134 ASSERT(layoutBox.isBlockLevelBox()); 135 136 if (layoutBox.isFloatingOrOutOfFlowPositioned()) 137 return false; 138 139 // Only the first inlflow child collapses with parent. 140 if (layoutBox.previousInFlowSibling()) 141 return false; 142 143 auto& parent = *layoutBox.parent(); 144 // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children 145 if (establishesBlockFormattingContext(parent)) 146 return false; 147 148 if (hasBorderBefore(parent)) 149 return false; 150 151 if (hasPaddingBefore(parent)) 152 return false; 153 154 if (BlockFormattingContext::Quirks::shouldIgnoreMarginBefore(layoutState, layoutBox)) 155 return false; 156 157 return true; 158 } 159 160 static bool isMarginAfterCollapsedThrough(const Box& layoutBox) 272 bool BlockFormattingContext::Geometry::MarginCollapse::marginsCollapseThrough(const Box& layoutBox) 161 273 { 162 274 ASSERT(layoutBox.isBlockLevelBox()); … … 182 294 } 183 295 184 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginBeforeFromFirstChild(const LayoutState& layoutState, const Box& layoutBox)185 {186 ASSERT(layoutBox.isBlockLevelBox());187 188 // Check if the first child collapses its margin top.189 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild())190 return 0;191 192 // Do not collapse margin with a box from a non-block formatting context <div><span>foobar</span></div>.193 if (layoutBox.establishesFormattingContext() && !layoutBox.establishesBlockFormattingContextOnly())194 return 0;195 196 // FIXME: Take collapsed through margin into account.197 auto& firstInFlowChild = *downcast<Container>(layoutBox).firstInFlowChild();198 if (!isMarginBeforeCollapsedWithParent(layoutState, firstInFlowChild))199 return 0;200 // Collect collapsed margin top recursively.201 return marginValue(computedNonCollapsedMarginBefore(layoutState, firstInFlowChild), collapsedMarginBeforeFromFirstChild(layoutState, firstInFlowChild));202 }203 204 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginBefore(const LayoutState& layoutState, const Box& layoutBox)205 {206 ASSERT(layoutBox.isBlockLevelBox());207 208 // Non collapsed margin top includes collapsed margin from inflow first child.209 return marginValue(computedNonCollapsedMarginBefore(layoutState, layoutBox), collapsedMarginBeforeFromFirstChild(layoutState, layoutBox));210 }211 212 /*static bool hasAdjoiningMarginBeforeAndAfter(const Box&)213 {214 // Two margins are adjoining if and only if:215 // 1. both belong to in-flow block-level boxes that participate in the same block formatting context216 // 2. no line boxes, no clearance, no padding and no border separate them (Note that certain zero-height line boxes (see 9.4.2) are ignored for this purpose.)217 // 3. both belong to vertically-adjacent box edges, i.e. form one of the following pairs:218 // top margin of a box and top margin of its first in-flow child219 // bottom margin of box and top margin of its next in-flow following sibling220 // bottom margin of a last in-flow child and bottom margin of its parent if the parent has 'auto' computed height221 // top and bottom margins of a box that does not establish a new block formatting context and that has zero computed 'min-height',222 // zero or 'auto' computed 'height', and no in-flow children223 // A collapsed margin is considered adjoining to another margin if any of its component margins is adjoining to that margin.224 return false;225 }*/226 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginBefore(const LayoutState& layoutState, const Box& layoutBox)227 {228 ASSERT(layoutBox.isBlockLevelBox());229 230 return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).before;231 }232 233 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::computedNonCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox)234 {235 ASSERT(layoutBox.isBlockLevelBox());236 237 return computedNonCollapsedVerticalMarginValue(layoutState, layoutBox).after;238 }239 240 296 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::marginBefore(const LayoutState& layoutState, const Box& layoutBox) 241 297 { … … 246 302 247 303 // TODO: take _hasAdjoiningMarginBeforeAndAfter() into account. 248 if ( isMarginBeforeCollapsedWithParent(layoutState, layoutBox))304 if (marginBeforeCollapsesWithParentMarginBefore(layoutState, layoutBox)) 249 305 return 0; 250 306 … … 253 309 return 0; 254 310 255 if (! isMarginBeforeCollapsedWithSibling(layoutBox)) {256 if (! isMarginAfterCollapsedThrough(layoutBox))311 if (!marginBeforeCollapsesWithPreviousSibling(layoutBox)) { 312 if (!marginsCollapseThrough(layoutBox)) 257 313 return nonCollapsedMarginBefore(layoutState, layoutBox); 258 314 // Compute the collapsed through value. … … 281 337 282 338 // TODO: take _hasAdjoiningMarginBeforeAndBottom() into account. 283 if ( isMarginAfterCollapsedWithParent(layoutBox))284 return 0; 285 286 if ( isMarginAfterCollapsedThrough(layoutBox))339 if (marginAfterCollapsesWithParentMarginAfter(layoutBox)) 340 return 0; 341 342 if (marginsCollapseThrough(layoutBox)) 287 343 return 0; 288 344 289 345 // Floats and out of flow positioned boxes do not collapse their margins. 290 if (! isMarginAfterCollapsedWithSibling(layoutBox))346 if (!marginAfterCollapsesWithNextSibling(layoutBox)) 291 347 return nonCollapsedMarginAfter(layoutState, layoutBox); 292 348 … … 298 354 } 299 355 300 bool BlockFormattingContext::Geometry::MarginCollapse::isMarginAfterCollapsedWithParent(const Box& layoutBox)301 {302 // last inflow box to parent.303 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins304 if (layoutBox.isAnonymous())305 return false;306 307 ASSERT(layoutBox.isBlockLevelBox());308 309 if (layoutBox.isFloatingOrOutOfFlowPositioned())310 return false;311 312 if (isMarginAfterCollapsedThrough(layoutBox))313 return false;314 315 // Only the last inlflow child collapses with parent.316 if (layoutBox.nextInFlowSibling())317 return false;318 319 auto& parent = *layoutBox.parent();320 // Margins of elements that establish new block formatting contexts do not collapse with their in-flow children321 if (establishesBlockFormattingContext(parent))322 return false;323 324 if (hasBorderBefore(parent))325 return false;326 327 if (hasPaddingBefore(parent))328 return false;329 330 if (!parent.style().height().isAuto())331 return false;332 333 return true;334 }335 336 bool BlockFormattingContext::Geometry::MarginCollapse::isMarginBeforeCollapsedWithParentMarginAfter(const Box&)337 {338 return false;339 }340 341 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::collapsedMarginAfterFromLastChild(const LayoutState& layoutState, const Box& layoutBox)342 {343 ASSERT(layoutBox.isBlockLevelBox());344 345 // Check if the last child propagates its margin bottom.346 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild())347 return 0;348 349 // Do not collapse margin with a box from a non-block formatting context <div><span>foobar</span></div>.350 if (layoutBox.establishesFormattingContext() && !layoutBox.establishesBlockFormattingContextOnly())351 return 0;352 353 // FIXME: Check for collapsed through margin.354 auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild();355 if (!isMarginAfterCollapsedWithParent(lastInFlowChild))356 return 0;357 358 // Collect collapsed margin bottom recursively.359 return marginValue(computedNonCollapsedMarginAfter(layoutState, lastInFlowChild), collapsedMarginAfterFromLastChild(layoutState, lastInFlowChild));360 }361 362 LayoutUnit BlockFormattingContext::Geometry::MarginCollapse::nonCollapsedMarginAfter(const LayoutState& layoutState, const Box& layoutBox)363 {364 ASSERT(layoutBox.isBlockLevelBox());365 366 // Non collapsed margin bottom includes collapsed margin from inflow last child.367 return marginValue(computedNonCollapsedMarginAfter(layoutState, layoutBox), collapsedMarginAfterFromLastChild(layoutState, layoutBox));368 }369 370 356 } 371 357 }
Note: See TracChangeset
for help on using the changeset viewer.