Changeset 249433 in webkit
- Timestamp:
- Sep 3, 2019 11:21:41 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r249429 r249433 1 2019-09-03 Zalan Bujtas <zalan@apple.com> 2 3 [LFC][Floats] Move FloatingState::constraints to FloatingContext 4 https://bugs.webkit.org/show_bug.cgi?id=201393 5 <rdar://problem/54939361> 6 7 Reviewed by Antti Koivisto. 8 9 This is in preparation for transitioning the floating codebase to use the formatting context for 10 retrieving display boxes. Now FloatingContext (just like any other formatting context) holds on to the formatting 11 context root. 12 13 * layout/blockformatting/BlockFormattingContext.cpp: 14 (WebCore::Layout::BlockFormattingContext::layout): 15 (WebCore::Layout::BlockFormattingContext::usedAvailableWidthForFloatAvoider const): 16 (WebCore::Layout::BlockFormattingContext::computeEstimatedVerticalPositionForFloatClear): 17 (WebCore::Layout::BlockFormattingContext::computePositionToAvoidFloats): 18 * layout/floats/FloatingContext.cpp: 19 (WebCore::Layout::FloatingContext::FloatingContext): 20 (WebCore::Layout::FloatingContext::positionForFloat const): 21 (WebCore::Layout::FloatingContext::positionForFormattingContextRoot const): 22 (WebCore::Layout::FloatingContext::verticalPositionWithClearance const): 23 (WebCore::Layout::FloatingContext::constraints const): 24 * layout/floats/FloatingContext.h: 25 (WebCore::Layout::FloatingContext::isEmpty const): 26 (WebCore::Layout::FloatingContext::root const): 27 * layout/floats/FloatingState.cpp: 28 (WebCore::Layout::FloatingState::constraints const): Deleted. 29 * layout/floats/FloatingState.h: 30 (WebCore::Layout::FloatingState::last const): 31 (WebCore::Layout::FloatingState::isEmpty const): Deleted. 32 * layout/inlineformatting/InlineFormattingContextLineLayout.cpp: 33 (WebCore::Layout::InlineFormattingContext::InlineLayout::layout const): 34 (WebCore::Layout::InlineFormattingContext::InlineLayout::createDisplayRuns const): 35 1 36 2019-09-03 Chris Lord <clord@igalia.com> 2 37 -
trunk/Source/WebCore/layout/blockformatting/BlockFormattingContext.cpp
r249356 r249433 63 63 auto& formattingRoot = downcast<Container>(root()); 64 64 LayoutQueue layoutQueue; 65 FloatingContext floatingContext(formattingState().floatingState());65 auto floatingContext = FloatingContext { formattingRoot, formattingState().floatingState() }; 66 66 // This is a post-order tree traversal layout. 67 67 // The root container layout is done in the formatting context it lives in, not that one it creates, so let's start with the first child. … … 124 124 // However (and can't find it anywhere in the spec) non-floating positioned float avoider block level boxes are constrained by existing floats. 125 125 ASSERT(layoutBox.isFloatAvoider()); 126 auto& floatingState = floatingContext.floatingState(); 127 if (floatingState.isEmpty()) 126 if (floatingContext.isEmpty()) 128 127 return { }; 129 128 // Vertical static position is not computed yet, so let's just estimate it for now. 130 129 auto& formattingRoot = downcast<Container>(root()); 131 130 auto verticalPosition = FormattingContext::mapTopToAncestor(layoutState(), layoutBox, formattingRoot); 132 auto constraints = floating State.constraints({ verticalPosition }, formattingRoot);131 auto constraints = floatingContext.constraints({ verticalPosition }); 133 132 if (!constraints.left && !constraints.right) 134 133 return { }; … … 297 296 { 298 297 ASSERT(layoutBox.hasFloatClear()); 299 if (floatingContext. floatingState().isEmpty())298 if (floatingContext.isEmpty()) 300 299 return; 301 300 // The static position with clear requires margin esitmation to see if clearance is needed. … … 342 341 ASSERT(hasPrecomputedMarginBefore(layoutBox)); 343 342 344 if (floatingContext. floatingState().isEmpty())343 if (floatingContext.isEmpty()) 345 344 return; 346 345 -
trunk/Source/WebCore/layout/floats/FloatingContext.cpp
r248364 r249433 151 151 #endif 152 152 153 FloatingContext::FloatingContext(FloatingState& floatingState) 154 : m_floatingState(floatingState) 153 FloatingContext::FloatingContext(const Container& formattingContextRoot, FloatingState& floatingState) 154 : m_root(makeWeakPtr(formattingContextRoot)) 155 , m_floatingState(floatingState) 155 156 { 156 157 } … … 161 162 ASSERT(areFloatsHorizontallySorted(m_floatingState)); 162 163 163 if ( m_floatingState.isEmpty()) {164 if (isEmpty()) { 164 165 auto& displayBox = layoutState().displayBoxForLayoutBox(layoutBox); 165 166 … … 191 192 ASSERT(areFloatsHorizontallySorted(m_floatingState)); 192 193 193 if ( m_floatingState.isEmpty())194 if (isEmpty()) 194 195 return { }; 195 196 … … 205 206 ASSERT(areFloatsHorizontallySorted(m_floatingState)); 206 207 207 if ( m_floatingState.isEmpty())208 if (isEmpty()) 208 209 return { }; 209 210 … … 252 253 253 254 auto clear = layoutBox.style().clear(); 254 auto& formattingContextRoot = layoutBox.formattingContextRoot();255 256 255 if (clear == Clear::Left) 257 return bottom(m_floatingState.leftBottom( formattingContextRoot));256 return bottom(m_floatingState.leftBottom(root())); 258 257 259 258 if (clear == Clear::Right) 260 return bottom(m_floatingState.rightBottom( formattingContextRoot));259 return bottom(m_floatingState.rightBottom(root())); 261 260 262 261 if (clear == Clear::Both) 263 return bottom(m_floatingState.bottom( formattingContextRoot));262 return bottom(m_floatingState.bottom(root())); 264 263 265 264 ASSERT_NOT_REACHED(); 266 265 return { }; 266 } 267 268 FloatingContext::Constraints FloatingContext::constraints(PositionInContextRoot verticalPosition) const 269 { 270 if (isEmpty()) 271 return { }; 272 273 // 1. Convert vertical position if this floating context is inherited. 274 // 2. Find the inner left/right floats at verticalPosition. 275 // 3. Convert left/right positions back to formattingContextRoot's cooridnate system. 276 auto coordinateMappingIsRequired = &floatingState().root() != &root(); 277 auto adjustedPosition = Point { 0, verticalPosition }; 278 LayoutSize adjustingDelta; 279 280 if (coordinateMappingIsRequired) { 281 adjustedPosition = FormattingContext::mapPointToAncestor(layoutState(), adjustedPosition, root(), downcast<Container>(floatingState().root())); 282 adjustingDelta = { adjustedPosition.x, adjustedPosition.y - verticalPosition }; 283 } 284 285 Constraints constraints; 286 auto& floats = floatingState().floats(); 287 for (auto index = floats.size() - 1; --index;) { 288 auto& floatItem = floats[index]; 289 290 if (constraints.left && floatItem.isLeftPositioned()) 291 continue; 292 293 if (constraints.right && !floatItem.isLeftPositioned()) 294 continue; 295 296 auto rect = floatItem.rectWithMargin(); 297 if (!(rect.top() <= adjustedPosition.y && adjustedPosition.y < rect.bottom())) 298 continue; 299 300 if (floatItem.isLeftPositioned()) 301 constraints.left = PointInContextRoot { rect.right(), rect.bottom() }; 302 else 303 constraints.right = PointInContextRoot { rect.left(), rect.bottom() }; 304 305 if (constraints.left && constraints.right) 306 break; 307 } 308 309 if (coordinateMappingIsRequired) { 310 if (constraints.left) 311 constraints.left->move(-adjustingDelta); 312 313 if (constraints.right) 314 constraints.right->move(-adjustingDelta); 315 } 316 return constraints; 267 317 } 268 318 -
trunk/Source/WebCore/layout/floats/FloatingContext.h
r241869 r249433 47 47 WTF_MAKE_ISO_ALLOCATED(FloatingContext); 48 48 public: 49 FloatingContext( FloatingState&);49 FloatingContext(const Container& formattingContextRoot, FloatingState&); 50 50 51 51 FloatingState& floatingState() const { return m_floatingState; } … … 60 60 ClearancePosition verticalPositionWithClearance(const Box&) const; 61 61 62 bool isEmpty() const { return m_floatingState.floats().isEmpty(); } 63 64 struct Constraints { 65 Optional<PointInContextRoot> left; 66 Optional<PointInContextRoot> right; 67 }; 68 Constraints constraints(PositionInContextRoot verticalPosition) const; 69 62 70 private: 63 71 LayoutState& layoutState() const { return m_floatingState.layoutState(); } 72 const Container& root() const { return *m_root; } 64 73 65 74 void findPositionForFloatBox(FloatBox&) const; 66 75 void findPositionForFormattingContextRoot(FloatAvoider&) const; 67 76 77 WeakPtr<const Container> m_root; 68 78 FloatingState& m_floatingState; 69 79 }; -
trunk/Source/WebCore/layout/floats/FloatingState.cpp
r246482 r249433 110 110 } 111 111 112 FloatingState::Constraints FloatingState::constraints(PositionInContextRoot verticalPosition, const Box& formattingContextRoot) const113 {114 if (isEmpty())115 return { };116 117 // 1. Convert vertical position if this floating context is inherited.118 // 2. Find the inner left/right floats at verticalPosition.119 // 3. Convert left/right positions back to formattingContextRoot's cooridnate system.120 auto coordinateMappingIsRequired = &root() != &formattingContextRoot;121 auto adjustedPosition = Point { 0, verticalPosition };122 LayoutSize adjustingDelta;123 124 if (coordinateMappingIsRequired) {125 adjustedPosition = FormattingContext::mapPointToAncestor(m_layoutState, adjustedPosition, downcast<Container>(formattingContextRoot), downcast<Container>(root()));126 adjustingDelta = { adjustedPosition.x, adjustedPosition.y - verticalPosition };127 }128 129 Constraints constraints;130 for (int index = m_floats.size() - 1; index >= 0; --index) {131 auto& floatItem = m_floats[index];132 133 if (constraints.left && floatItem.isLeftPositioned())134 continue;135 136 if (constraints.right && !floatItem.isLeftPositioned())137 continue;138 139 auto rect = floatItem.rectWithMargin();140 if (!(rect.top() <= adjustedPosition.y && adjustedPosition.y < rect.bottom()))141 continue;142 143 if (floatItem.isLeftPositioned())144 constraints.left = PointInContextRoot { rect.right(), rect.bottom() };145 else146 constraints.right = PointInContextRoot { rect.left(), rect.bottom() };147 148 if (constraints.left && constraints.right)149 break;150 }151 152 if (coordinateMappingIsRequired) {153 if (constraints.left)154 constraints.left->move(-adjustingDelta);155 156 if (constraints.right)157 constraints.right->move(-adjustingDelta);158 }159 return constraints;160 }161 162 112 Optional<PositionInContextRoot> FloatingState::bottom(const Box& formattingContextRoot, Clear type) const 163 113 { -
trunk/Source/WebCore/layout/floats/FloatingState.h
r246482 r249433 51 51 void remove(const Box& layoutBox); 52 52 53 bool isEmpty() const { return m_floats.isEmpty(); }54 55 53 const Box& root() const { return *m_formattingContextRoot; } 56 54 … … 59 57 Optional<PositionInContextRoot> rightBottom(const Box& formattingContextRoot) const; 60 58 Optional<PositionInContextRoot> bottom(const Box& formattingContextRoot) const; 61 62 struct Constraints {63 Optional<PointInContextRoot> left;64 Optional<PointInContextRoot> right;65 };66 Constraints constraints(PositionInContextRoot verticalPosition, const Box& formattingContextRoot) const;67 59 68 60 class FloatItem { … … 84 76 using FloatList = Vector<FloatItem>; 85 77 const FloatList& floats() const { return m_floats; } 86 const FloatItem* last() const { return isEmpty() ? nullptr : &m_floats.last(); }78 const FloatItem* last() const { return floats().isEmpty() ? nullptr : &m_floats.last(); } 87 79 88 80 private: -
trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp
r249357 r249433 283 283 auto& formattingRoot = this->formattingRoot(); 284 284 auto& formattingRootDisplayBox = formattingContext.displayBoxForLayoutBox(formattingRoot); 285 auto & floatingState = layoutState.establishedFormattingState(formattingRoot).floatingState();285 auto floatingContext = FloatingContext { formattingRoot, layoutState.establishedFormattingState(formattingRoot).floatingState() }; 286 286 287 287 auto lineLogicalTop = formattingRootDisplayBox.contentBoxTop(); … … 290 290 auto applyFloatConstraint = [&](auto& lineInput) { 291 291 // Check for intruding floats and adjust logical left/available width for this line accordingly. 292 if (floating State.isEmpty())292 if (floatingContext.isEmpty()) 293 293 return; 294 294 auto availableWidth = lineInput.initialConstraints.availableLogicalWidth; 295 295 auto lineLogicalLeft = lineInput.initialConstraints.logicalTopLeft.x(); 296 auto floatConstraints = floating State.constraints({ lineLogicalTop }, formattingRoot);296 auto floatConstraints = floatingContext.constraints({ lineLogicalTop }); 297 297 // Check if these constraints actually put limitation on the line. 298 298 if (floatConstraints.left && floatConstraints.left->x <= formattingRootDisplayBox.contentBoxLeft()) … … 366 366 auto& formattingState = downcast<InlineFormattingState>(layoutState.establishedFormattingState(formattingRoot())); 367 367 auto& floatingState = formattingState.floatingState(); 368 auto floatingContext = FloatingContext { f loatingState };368 auto floatingContext = FloatingContext { formattingRoot(), floatingState }; 369 369 370 370 // Move floats to their final position.
Note: See TracChangeset
for help on using the changeset viewer.