Changeset 234083 in webkit
- Timestamp:
- Jul 21, 2018 8:00:30 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r234078 r234083 1 2018-07-21 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][BFC] Do not collapse top/bottom margin with first/last inflow child from a non-block formatting context. 4 https://bugs.webkit.org/show_bug.cgi?id=187867 5 6 Reviewed by Antti Koivisto. 7 8 The box's top/bottom margin never collapses with a non-block inflow child. 9 10 * layout/blockformatting/BlockMarginCollapse.cpp: 11 (WebCore::Layout::isMarginTopCollapsedWithSibling): 12 (WebCore::Layout::isMarginBottomCollapsedWithSibling): 13 (WebCore::Layout::isMarginTopCollapsedWithParent): 14 (WebCore::Layout::isMarginBottomCollapsedThrough): 15 (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginTopFromFirstChild): 16 (WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginTop): 17 (WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginTop): 18 (WebCore::Layout::BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginBottom): 19 (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginTop): 20 (WebCore::Layout::BlockFormattingContext::MarginCollapse::marginBottom): 21 (WebCore::Layout::BlockFormattingContext::MarginCollapse::isMarginBottomCollapsedWithParent): 22 (WebCore::Layout::BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild): 23 (WebCore::Layout::BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom): 24 * layout/layouttree/LayoutBox.cpp: 25 (WebCore::Layout::Box::establishesBlockFormattingContextOnly const): <div style="overflow: hidden">foobar</div> establishes both inline and block formatting context (inline wins though). 26 * layout/layouttree/LayoutBox.h: establishesBlockFormattingContext() does not need to be virtual since we can determine it by looking at the box's style. -while in case 27 of inline formatting context, it is about the content. 28 1 29 2018-07-20 Jer Noble <jer.noble@apple.com> 2 30 -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r233398 r234083 55 55 static bool isMarginTopCollapsedWithSibling(const Box& layoutBox) 56 56 { 57 ASSERT(layoutBox.isBlockLevelBox()); 58 57 59 if (layoutBox.isFloatingPositioned()) 58 60 return false; … … 68 70 static bool isMarginBottomCollapsedWithSibling(const Box& layoutBox) 69 71 { 72 ASSERT(layoutBox.isBlockLevelBox()); 73 70 74 if (layoutBox.isFloatingPositioned()) 71 75 return false; … … 85 89 if (layoutBox.isAnonymous()) 86 90 return false; 91 92 ASSERT(layoutBox.isBlockLevelBox()); 87 93 88 94 if (layoutBox.isFloatingOrOutOfFlowPositioned()) … … 115 121 static bool isMarginBottomCollapsedThrough(const LayoutContext& layoutContext, const Box& layoutBox) 116 122 { 123 ASSERT(layoutBox.isBlockLevelBox()); 124 117 125 // If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. 118 126 auto& displayBox = *layoutContext.displayBoxForLayoutBox(layoutBox); … … 139 147 LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginTopFromFirstChild(const LayoutContext& layoutContext, const Box& layoutBox) 140 148 { 149 ASSERT(layoutBox.isBlockLevelBox()); 150 141 151 // Check if the first child collapses its margin top. 142 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()) 143 157 return 0; 144 158 … … 153 167 LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginTop(const LayoutContext& layoutContext, const Box& layoutBox) 154 168 { 169 ASSERT(layoutBox.isBlockLevelBox()); 170 155 171 // Non collapsed margin top includes collapsed margin from inflow first child. 156 172 return marginValue(computedNonCollapsedMarginTop(layoutContext, layoutBox), collapsedMarginTopFromFirstChild(layoutContext, layoutBox)); … … 173 189 LayoutUnit BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginTop(const LayoutContext& layoutContext, const Box& layoutBox) 174 190 { 191 ASSERT(layoutBox.isBlockLevelBox()); 192 175 193 return FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox).top; 176 194 } … … 178 196 LayoutUnit BlockFormattingContext::MarginCollapse::computedNonCollapsedMarginBottom(const LayoutContext& layoutContext, const Box& layoutBox) 179 197 { 198 ASSERT(layoutBox.isBlockLevelBox()); 199 180 200 return FormattingContext::Geometry::computedNonCollapsedVerticalMarginValue(layoutContext, layoutBox).bottom; 181 201 } … … 185 205 if (layoutBox.isAnonymous()) 186 206 return 0; 207 208 ASSERT(layoutBox.isBlockLevelBox()); 187 209 188 210 // TODO: take _hasAdjoiningMarginTopAndBottom() into account. … … 215 237 return 0; 216 238 239 ASSERT(layoutBox.isBlockLevelBox()); 240 217 241 // TODO: take _hasAdjoiningMarginTopAndBottom() into account. 218 242 if (isMarginBottomCollapsedWithParent(layoutContext, layoutBox)) … … 239 263 if (layoutBox.isAnonymous()) 240 264 return false; 265 266 ASSERT(layoutBox.isBlockLevelBox()); 241 267 242 268 if (layoutBox.isFloatingOrOutOfFlowPositioned()) … … 280 306 LayoutUnit BlockFormattingContext::MarginCollapse::collapsedMarginBottomFromLastChild(const LayoutContext& layoutContext, const Box& layoutBox) 281 307 { 308 ASSERT(layoutBox.isBlockLevelBox()); 309 282 310 // Check if the last child propagates its margin bottom. 283 311 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild()) 312 return 0; 313 314 // Do not collapse margin with a box from a non-block formatting context <div><span>foobar</span></div>. 315 if (layoutBox.establishesFormattingContext() && !layoutBox.establishesBlockFormattingContextOnly()) 284 316 return 0; 285 317 … … 295 327 LayoutUnit BlockFormattingContext::MarginCollapse::nonCollapsedMarginBottom(const LayoutContext& layoutContext, const Box& layoutBox) 296 328 { 329 ASSERT(layoutBox.isBlockLevelBox()); 330 297 331 // Non collapsed margin bottom includes collapsed margin from inflow last child. 298 332 return marginValue(computedNonCollapsedMarginBottom(layoutContext, layoutBox), collapsedMarginBottomFromLastChild(layoutContext, layoutBox)); -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r234048 r234083 71 71 } 72 72 73 bool Box::establishesBlockFormattingContextOnly() const 74 { 75 return establishesBlockFormattingContext() && !establishesInlineFormattingContext(); 76 } 77 73 78 bool Box::isRelativelyPositioned() const 74 79 { -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r234048 r234083 48 48 49 49 bool establishesFormattingContext() const; 50 virtual bool establishesBlockFormattingContext() const; 50 bool establishesBlockFormattingContext() const; 51 bool establishesBlockFormattingContextOnly() const; 51 52 virtual bool establishesInlineFormattingContext() const { return false; } 52 53
Note: See TracChangeset
for help on using the changeset viewer.