Changeset 231642 in webkit
- Timestamp:
- May 10, 2018 9:46:54 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r231638 r231642 1 2018-05-10 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Implement height computation for non-replaced inflow elements. 4 https://bugs.webkit.org/show_bug.cgi?id=185474 5 6 Reviewed by Antti Koivisto. 7 8 Initial implementation. Does not cover all the cases. 9 10 * layout/FormattingContext.cpp: 11 (WebCore::Layout::FormattingContext::computeHeight const): 12 * layout/FormattingContext.h: 13 * layout/blockformatting/BlockFormattingContext.cpp: 14 (WebCore::Layout::BlockFormattingContext::layout const): 15 (WebCore::Layout::BlockFormattingContext::computeInFlowHeight const): 16 (WebCore::Layout::BlockFormattingContext::computeInFlowNonReplacedHeight const): 17 * layout/blockformatting/BlockFormattingContext.h: 18 * layout/blockformatting/BlockMarginCollapse.cpp: 19 (WebCore::Layout::collapsedMarginBottomFromLastChild): 20 (WebCore::Layout::BlockMarginCollapse::isMarginBottomCollapsedWithParent): 21 (WebCore::Layout::BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom): 22 (WebCore::Layout::isMarginBottomCollapsedWithParent): Deleted. 23 * layout/blockformatting/BlockMarginCollapse.h: 24 * layout/inlineformatting/InlineFormattingContext.cpp: 25 (WebCore::Layout::InlineFormattingContext::computeInFlowHeight const): 26 * layout/inlineformatting/InlineFormattingContext.h: 27 * layout/layouttree/LayoutBox.cpp: 28 (WebCore::Layout::Box::isReplaced const): 29 * layout/layouttree/LayoutBox.h: 30 1 31 2018-05-10 Thibault Saunier <tsaunier@igalia.com> 2 32 -
trunk/Source/WebCore/layout/FormattingContext.cpp
r231480 r231642 69 69 } 70 70 71 void FormattingContext::computeHeight( const Box& layoutBox, Display::Box& displayBox) const71 void FormattingContext::computeHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const 72 72 { 73 73 if (layoutBox.isOutOfFlowPositioned()) … … 75 75 if (layoutBox.isFloatingPositioned()) 76 76 return computeFloatingHeight(layoutBox, displayBox); 77 return computeInFlowHeight(layout Box, displayBox);77 return computeInFlowHeight(layoutContext, layoutBox, displayBox); 78 78 } 79 79 -
trunk/Source/WebCore/layout/FormattingContext.h
r231480 r231642 70 70 71 71 virtual void computeWidth(const Box&, Display::Box&) const; 72 virtual void computeHeight( const Box&, Display::Box&) const;72 virtual void computeHeight(LayoutContext&, const Box&, Display::Box&) const; 73 73 74 74 virtual void computeOutOfFlowWidth(const Box&, Display::Box&) const; … … 78 78 virtual void computeOutOfFlowHeight(const Box&, Display::Box&) const; 79 79 virtual void computeFloatingHeight(const Box&, Display::Box&) const; 80 virtual void computeInFlowHeight( const Box&, Display::Box&) const = 0;80 virtual void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const = 0; 81 81 82 82 virtual LayoutUnit marginTop(const Box&) const; -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
r231487 r231642 95 95 auto& displayBox = layoutPair->displayBox; 96 96 97 computeHeight(layout Box, displayBox);97 computeHeight(layoutContext, layoutBox, displayBox); 98 98 // Adjust position now that we have all the previous floats placed in this context -if needed. 99 99 floatingContext.computePosition(layoutBox, displayBox); … … 148 148 } 149 149 150 void BlockFormattingContext::computeInFlowHeight(const Box&, Display::Box&) const 151 { 150 void BlockFormattingContext::computeInFlowHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const 151 { 152 if (!layoutBox.isReplaced()) { 153 computeInFlowNonReplacedHeight(layoutContext, layoutBox, displayBox); 154 return; 155 } 156 ASSERT_NOT_REACHED(); 152 157 } 153 158 … … 162 167 } 163 168 169 void BlockFormattingContext::computeInFlowNonReplacedHeight(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const 170 { 171 // https://www.w3.org/TR/CSS22/visudet.html 172 // If 'height' is 'auto', the height depends on whether the element has any block-level children and whether it has padding or borders: 173 // The element's height is the distance from its top content edge to the first applicable of the following: 174 // 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines 175 // 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin 176 // does not collapse with the element's bottom margin 177 // 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin 178 // 4. zero, otherwise 179 // Only children in the normal flow are taken into account (i.e., floating boxes and absolutely positioned boxes are ignored, 180 // and relatively positioned boxes are considered without their offset). Note that the child box may be an anonymous block box. 181 if (!layoutBox.style().logicalHeight().isAuto()) { 182 // FIXME: Only fixed values yet. 183 displayBox.setHeight(layoutBox.style().logicalHeight().value()); 184 return; 185 } 186 187 if (!is<Container>(layoutBox) || !downcast<Container>(layoutBox).hasInFlowChild()) { 188 displayBox.setHeight(0); 189 return; 190 } 191 192 // 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines 193 if (layoutBox.establishesInlineFormattingContext()) { 194 // height = lastLineBox().bottom(); 195 displayBox.setHeight(0); 196 return; 197 } 198 199 // 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin... 200 auto* lastInFlowChild = downcast<Container>(layoutBox).lastInFlowChild(); 201 ASSERT(lastInFlowChild); 202 if (!BlockMarginCollapse::isMarginBottomCollapsedWithParent(*lastInFlowChild)) { 203 auto* lastInFlowDisplayBox = layoutContext.displayBoxForLayoutBox(*lastInFlowChild); 204 ASSERT(lastInFlowDisplayBox); 205 displayBox.setHeight(lastInFlowDisplayBox->bottom() + lastInFlowDisplayBox->marginBottom()); 206 return; 207 } 208 209 // 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin 210 auto* inFlowChild = lastInFlowChild; 211 while (inFlowChild && BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom(*inFlowChild)) 212 inFlowChild = inFlowChild->previousInFlowSibling(); 213 if (inFlowChild) { 214 auto* inFlowDisplayBox = layoutContext.displayBoxForLayoutBox(*inFlowChild); 215 ASSERT(inFlowDisplayBox); 216 displayBox.setHeight(inFlowDisplayBox->top() + inFlowDisplayBox->borderBox().height()); 217 return; 218 } 219 220 // 4. zero, otherwise 221 displayBox.setHeight(0); 222 } 223 164 224 } 165 225 } -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.h
r231480 r231642 50 50 Ref<FloatingState> createOrFindFloatingState(LayoutContext&) const override; 51 51 52 pr otected:52 private: 53 53 void computeStaticPosition(LayoutContext&, const Box&, Display::Box&) const override; 54 54 void computeInFlowWidth(const Box&, Display::Box&) const override; 55 void computeInFlowHeight(const Box&, Display::Box&) const override; 55 void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override; 56 void computeInFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const; 56 57 57 58 LayoutUnit marginTop(const Box&) const override; -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.cpp
r231487 r231642 115 115 } 116 116 117 static bool isMarginBottomCollapsedWithParent(const Box& layoutBox)118 {119 // last inflow box to parent.120 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins121 if (layoutBox.isAnonymous())122 return false;123 124 if (layoutBox.isFloatingOrOutOfFlowPositioned())125 return false;126 127 // We never margin collapse the initial containing block.128 ASSERT(layoutBox.parent());129 auto& parent = *layoutBox.parent();130 // Is this the last inlflow child?131 if (parent.lastInFlowChild() != &layoutBox)132 return false;133 134 if (parent.establishesBlockFormattingContext())135 return false;136 137 // Margins of the root element's box do not collapse.138 if (parent.isInitialContainingBlock())139 return false;140 141 if (!parent.style().borderTop().nonZero())142 return false;143 144 if (!parent.style().paddingTop().isZero())145 return false;146 147 if (!parent.style().height().isAuto())148 return false;149 150 return true;151 }152 153 117 static LayoutUnit collapsedMarginTopFromFirstChild(const Box& layoutBox) 154 118 { … … 172 136 173 137 auto& lastInFlowChild = *downcast<Container>(layoutBox).lastInFlowChild(); 174 if (! isMarginBottomCollapsedWithParent(lastInFlowChild))138 if (!BlockMarginCollapse::isMarginBottomCollapsedWithParent(lastInFlowChild)) 175 139 return 0; 176 140 … … 250 214 } 251 215 216 bool BlockMarginCollapse::isMarginBottomCollapsedWithParent(const Box& layoutBox) 217 { 218 // last inflow box to parent. 219 // https://www.w3.org/TR/CSS21/box.html#collapsing-margins 220 if (layoutBox.isAnonymous()) 221 return false; 222 223 if (layoutBox.isFloatingOrOutOfFlowPositioned()) 224 return false; 225 226 // We never margin collapse the initial containing block. 227 ASSERT(layoutBox.parent()); 228 auto& parent = *layoutBox.parent(); 229 // Is this the last inlflow child? 230 if (parent.lastInFlowChild() != &layoutBox) 231 return false; 232 233 if (parent.establishesBlockFormattingContext()) 234 return false; 235 236 // Margins of the root element's box do not collapse. 237 if (parent.isInitialContainingBlock()) 238 return false; 239 240 if (!parent.style().borderTop().nonZero()) 241 return false; 242 243 if (!parent.style().paddingTop().isZero()) 244 return false; 245 246 if (!parent.style().height().isAuto()) 247 return false; 248 249 return true; 250 } 251 252 bool BlockMarginCollapse::isMarginTopCollapsedWithParentMarginBottom(const Box&) 253 { 254 return false; 255 } 256 252 257 } 253 258 } -
trunk/Source/WebCore/layout/blockformatting/BlockMarginCollapse.h
r231487 r231642 43 43 static LayoutUnit marginTop(const Box&); 44 44 static LayoutUnit marginBottom(const Box&); 45 46 static bool isMarginBottomCollapsedWithParent(const Box&); 47 static bool isMarginTopCollapsedWithParentMarginBottom(const Box&); 45 48 }; 46 49 -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp
r231480 r231642 71 71 } 72 72 73 void InlineFormattingContext::computeInFlowHeight( const Box&, Display::Box&) const73 void InlineFormattingContext::computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const 74 74 { 75 75 } -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.h
r231480 r231642 50 50 private: 51 51 void computeInFlowWidth(const Box&, Display::Box&) const override; 52 void computeInFlowHeight( const Box&, Display::Box&) const override;52 void computeInFlowHeight(LayoutContext&, const Box&, Display::Box&) const override; 53 53 54 54 }; -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r231096 r231642 180 180 } 181 181 182 bool Box::isReplaced() const 183 { 184 // HTMLAudioElement || HTMLCanvasElement || HTMLEmbedElement || HTMLIFrameElement || HTMLImageElement || HTMLInputElement || HTMLObjectElement || HTMLVideoElement 185 return false; 186 } 187 182 188 const Box* Box::nextInFlowSibling() const 183 189 { -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r231141 r231642 73 73 bool isBlockContainerBox() const; 74 74 bool isInitialContainingBlock() const; 75 bool isReplaced() const; 75 76 76 77 const Container* parent() const { return m_parent; }
Note: See TracChangeset
for help on using the changeset viewer.