Changeset 231847 in webkit
- Timestamp:
- May 16, 2018 7:51:39 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r231846 r231847 1 2018-05-16 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Implement width computation for replaced inflow elements. 4 https://bugs.webkit.org/show_bug.cgi?id=185672 5 6 Reviewed by Antti Koivisto. 7 8 Replaced width for block, inline and float elements compute the same way. 9 10 * layout/FormattingContext.cpp: 11 (WebCore::Layout::FormattingContext::computeWidth const): 12 (WebCore::Layout::FormattingContext::computeFloatingWidth const): 13 (WebCore::Layout::FormattingContext::computeInFlowReplacedWidth const): 14 * layout/FormattingContext.h: 15 * layout/blockformatting/BlockFormattingContext.cpp: 16 (WebCore::Layout::BlockFormattingContext::computeInFlowWidth const): 17 * layout/layouttree/LayoutBox.cpp: 18 (WebCore::Layout::Box::hasIntrinsicWidth const): 19 (WebCore::Layout::Box::hasIntrinsicHeight const): 20 (WebCore::Layout::Box::hasIntrinsicRatio const): 21 (WebCore::Layout::Box::intrinsicWidth const): 22 (WebCore::Layout::Box::intrinsicHeight const): 23 (WebCore::Layout::Box::intrinsicRatio const): 24 * layout/layouttree/LayoutBox.h: 25 1 26 2018-05-16 Zalan Bujtas <zalan@apple.com> 2 27 -
trunk/Source/WebCore/layout/FormattingContext.cpp
r231786 r231847 66 66 return computeOutOfFlowWidth(layoutContext, layoutBox, displayBox); 67 67 if (layoutBox.isFloatingPositioned()) 68 return computeFloatingWidth(layout Box, displayBox);68 return computeFloatingWidth(layoutContext, layoutBox, displayBox); 69 69 return computeInFlowWidth(layoutContext, layoutBox, displayBox); 70 70 } … … 88 88 } 89 89 90 void FormattingContext::computeFloatingWidth(const Box&, Display::Box&) const 91 { 90 void FormattingContext::computeFloatingWidth(LayoutContext& layoutContext, const Box& layoutBox, Display::Box& displayBox) const 91 { 92 if (!layoutBox.isReplaced()) { 93 ASSERT_NOT_REACHED(); 94 return; 95 } 96 computeInFlowReplacedWidth(layoutContext, layoutBox, displayBox); 92 97 } 93 98 … … 204 209 } 205 210 211 void FormattingContext::computeInFlowReplacedWidth(LayoutContext&, const Box& layoutBox, Display::Box& displayBox) const 212 { 213 // 10.3.4 Block-level, replaced elements in normal flow: The used value of 'width' is determined as for inline replaced elements 214 // 10.3.6 Floating, replaced elements: The used value of 'width' is determined as for inline replaced elements. 215 216 // 10.3.2 Inline, replaced elements 217 // 218 // 1. If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width, then that intrinsic width is the used value of 'width'. 219 // 220 // 2. If 'height' and 'width' both have computed values of 'auto' and the element has no intrinsic width, but does have an intrinsic height and intrinsic ratio; 221 // or if 'width' has a computed value of 'auto', 'height' has some other computed value, and the element does have an intrinsic ratio; 222 // then the used value of 'width' is: (used height) * (intrinsic ratio) 223 // 224 // 3. If 'height' and 'width' both have computed values of 'auto' and the element has an intrinsic ratio but no intrinsic height or width, 225 // then the used value of 'width' is undefined in CSS 2.2. However, it is suggested that, if the containing block's width does not itself depend on the replaced 226 // element's width, then the used value of 'width' is calculated from the constraint equation used for block-level, non-replaced elements in normal flow. 227 // 228 // 4. Otherwise, if 'width' has a computed value of 'auto', and the element has an intrinsic width, then that intrinsic width is the used value of 'width'. 229 // 230 // 5. Otherwise, if 'width' has a computed value of 'auto', but none of the conditions above are met, then the used value of 'width' becomes 300px. 231 // If 300px is too wide to fit the device, UAs should use the width of the largest rectangle that has a 2:1 ratio and fits the device instead. 232 auto& style = layoutBox.style(); 233 auto width = style.logicalWidth(); 234 auto height = style.logicalHeight(); 235 236 LayoutUnit computedWidthValue; 237 238 if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicWidth()) { 239 // #1 240 computedWidthValue = layoutBox.intrinsicWidth(); 241 } else if (width.isAuto() && (height.isCalculated() || layoutBox.hasIntrinsicHeight()) && layoutBox.hasIntrinsicRatio()) { 242 // #2 243 auto usedHeight = height.isCalculated() ? LayoutUnit(height.value()) : layoutBox.intrinsicHeight(); 244 computedWidthValue = usedHeight * layoutBox.intrinsicRatio(); 245 } else if (width.isAuto() && height.isAuto() && layoutBox.hasIntrinsicRatio()) { 246 // #3 247 // FIXME: undefined but surely doable. 248 ASSERT_NOT_REACHED(); 249 } else if (width.isAuto() && layoutBox.hasIntrinsicWidth()) { 250 // #4 251 computedWidthValue = layoutBox.intrinsicWidth(); 252 } else { 253 // #5 254 computedWidthValue = 300; 255 } 256 257 displayBox.setWidth(computedWidthValue); 258 } 259 206 260 LayoutUnit FormattingContext::contentHeightForFormattingContextRoot(LayoutContext& layoutContext, const Box& layoutBox) const 207 261 { -
trunk/Source/WebCore/layout/FormattingContext.h
r231786 r231847 73 73 74 74 virtual void computeOutOfFlowWidth(LayoutContext&, const Box&, Display::Box&) const; 75 virtual void computeFloatingWidth( const Box&, Display::Box&) const;75 virtual void computeFloatingWidth(LayoutContext&, const Box&, Display::Box&) const; 76 76 virtual void computeInFlowWidth(LayoutContext&, const Box&, Display::Box&) const = 0; 77 77 … … 88 88 void layoutOutOfFlowDescendants(LayoutContext&s) const; 89 89 90 void computeInFlowReplacedWidth(LayoutContext&, const Box&, Display::Box&) const; 91 90 92 private: 91 93 void computeOutOfFlowNonReplacedHeight(LayoutContext&, const Box&, Display::Box&) const; -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
r231786 r231847 150 150 return; 151 151 } 152 ASSERT_NOT_REACHED();152 computeInFlowReplacedWidth(layoutContext, layoutBox, displayBox); 153 153 } 154 154 -
trunk/Source/WebCore/layout/layouttree/LayoutBox.cpp
r231642 r231847 231 231 } 232 232 233 bool Box::hasIntrinsicWidth() const 234 { 235 return false; 236 } 237 238 bool Box::hasIntrinsicHeight() const 239 { 240 return false; 241 } 242 243 bool Box::hasIntrinsicRatio() const 244 { 245 return false; 246 } 247 248 LayoutUnit Box::intrinsicWidth() const 249 { 250 ASSERT(hasIntrinsicWidth()); 251 return { }; 252 } 253 254 LayoutUnit Box::intrinsicHeight() const 255 { 256 ASSERT(hasIntrinsicHeight()); 257 return { }; 258 } 259 260 LayoutUnit Box::intrinsicRatio() const 261 { 262 ASSERT(hasIntrinsicRatio()); 263 return { }; 264 } 265 233 266 } 234 267 } -
trunk/Source/WebCore/layout/layouttree/LayoutBox.h
r231642 r231847 73 73 bool isBlockContainerBox() const; 74 74 bool isInitialContainingBlock() const; 75 bool isReplaced() const;76 75 77 76 const Container* parent() const { return m_parent; } … … 91 90 const RenderStyle& style() const { return m_style; } 92 91 auto& weakPtrFactory() const { return m_weakFactory; } 92 93 bool isReplaced() const; 94 // FIXME: find out how to not pollute the Box interface 95 bool hasIntrinsicWidth() const; 96 bool hasIntrinsicHeight() const; 97 bool hasIntrinsicRatio() const; 98 LayoutUnit intrinsicWidth() const; 99 LayoutUnit intrinsicHeight() const; 100 LayoutUnit intrinsicRatio() const; 93 101 94 102 protected:
Note: See TracChangeset
for help on using the changeset viewer.