Changeset 95856 in webkit
- Timestamp:
- Sep 23, 2011 1:32:18 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r95855 r95856 1 2011-09-22 Ojan Vafai <ojan@chromium.org> 2 3 refactor RenderFlexibleBox to use flex-flow aware methods 4 https://bugs.webkit.org/show_bug.cgi?id=68665 5 6 Reviewed by Tony Chang. 7 8 This is just a refactor. Just move the all the code that needs to 9 be flow aware into helper functions. Actually making them flow-aware 10 can be done in a followup patch. 11 12 * rendering/RenderBlock.cpp: 13 * rendering/RenderBlock.h: 14 Moved setLogicalLocationForChild into RenderFlexibleBox since that was the only caller. 15 * rendering/RenderFlexibleBox.cpp: 16 (WebCore::RenderFlexibleBox::hasOrthogonalFlow): 17 (WebCore::RenderFlexibleBox::isHorizontalFlow): 18 (WebCore::RenderFlexibleBox::isLeftToRightFlow): 19 (WebCore::RenderFlexibleBox::setFlowAwareLogicalHeight): 20 (WebCore::RenderFlexibleBox::flowAwareLogicalHeightForChild): 21 (WebCore::RenderFlexibleBox::flowAwareLogicalWidthForChild): 22 (WebCore::RenderFlexibleBox::flowAwareLogicalHeight): 23 (WebCore::RenderFlexibleBox::flowAwareContentLogicalWidth): 24 (WebCore::RenderFlexibleBox::flowAwareAvailableLogicalWidth): 25 (WebCore::RenderFlexibleBox::flowAwareBorderStart): 26 (WebCore::RenderFlexibleBox::flowAwareBorderBefore): 27 (WebCore::RenderFlexibleBox::flowAwareBorderAfter): 28 (WebCore::RenderFlexibleBox::flowAwarePaddingStart): 29 (WebCore::RenderFlexibleBox::flowAwarePaddingBefore): 30 (WebCore::RenderFlexibleBox::flowAwarePaddingAfter): 31 (WebCore::RenderFlexibleBox::flowAwareMarginStartForChild): 32 (WebCore::RenderFlexibleBox::flowAwareMarginBeforeForChild): 33 (WebCore::RenderFlexibleBox::flowAwareMarginAfterForChild): 34 (WebCore::RenderFlexibleBox::setFlowAwareMarginStartForChild): 35 (WebCore::RenderFlexibleBox::setFlowAwareMarginEndForChild): 36 (WebCore::RenderFlexibleBox::setFlowAwareLogicalLocationForChild): 37 (WebCore::RenderFlexibleBox::logicalBorderAndPaddingWidthForChild): 38 (WebCore::RenderFlexibleBox::logicalScrollbarHeightForChild): 39 (WebCore::RenderFlexibleBox::marginStartStyleForChild): 40 (WebCore::RenderFlexibleBox::marginEndStyleForChild): 41 (WebCore::RenderFlexibleBox::preferredLogicalContentWidthForFlexItem): 42 (WebCore::RenderFlexibleBox::layoutInlineDirection): 43 (WebCore::RenderFlexibleBox::logicalPositiveFlexForChild): 44 (WebCore::RenderFlexibleBox::logicalNegativeFlexForChild): 45 (WebCore::RenderFlexibleBox::computePreferredLogicalWidth): 46 (WebCore::RenderFlexibleBox::runFreeSpaceAllocationAlgorithmInlineDirection): 47 (WebCore::RenderFlexibleBox::setLogicalOverrideSize): 48 (WebCore::RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection): 49 * rendering/RenderFlexibleBox.h: 50 1 51 2011-09-23 David Hyatt <hyatt@apple.com> 2 52 -
trunk/Source/WebCore/rendering/RenderBlock.cpp
r95855 r95856 1862 1862 // Update our bottom collapsed margin info. 1863 1863 setCollapsedBottomMargin(marginInfo); 1864 }1865 1866 void RenderBlock::setLogicalLocationForChild(RenderBox* child, const LayoutPoint& location)1867 {1868 if (style()->isHorizontalWritingMode())1869 child->setLocation(location);1870 else1871 child->setLocation(location.transposedPoint());1872 1864 } 1873 1865 -
trunk/Source/WebCore/rendering/RenderBlock.h
r95855 r95856 210 210 LayoutUnit logicalTopForChild(RenderBox* child) { return isHorizontalWritingMode() ? child->y() : child->x(); } 211 211 LayoutUnit logicalLeftForChild(RenderBox* child) { return isHorizontalWritingMode() ? child->x() : child->y(); } 212 // FIXME: Supporting layout deltas.213 void setLogicalLocationForChild(RenderBox* child, const LayoutPoint&);214 212 void setLogicalLeftForChild(RenderBox* child, LayoutUnit logicalLeft, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta); 215 213 void setLogicalTopForChild(RenderBox* child, LayoutUnit logicalTop, ApplyLayoutDeltaMode = DoNotApplyLayoutDelta); -
trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp
r95783 r95856 188 188 } 189 189 190 LayoutUnit RenderFlexibleBox::logicalBorderAndPaddingWidthForChild(RenderBox* child) 191 { 192 return isHorizontalWritingMode() ? child->borderAndPaddingWidth() : child->borderAndPaddingHeight(); 193 } 194 195 LayoutUnit RenderFlexibleBox::logicalScrollbarHeightForChild(RenderBox* child) 196 { 197 return isHorizontalWritingMode() ? child->verticalScrollbarWidth() : child->horizontalScrollbarHeight(); 198 } 199 200 Length RenderFlexibleBox::marginStartStyleForChild(RenderBox* child) 201 { 202 if (isHorizontalWritingMode()) 203 return style()->isLeftToRightDirection() ? child->style()->marginLeft() : child->style()->marginRight(); 204 return style()->isLeftToRightDirection() ? child->style()->marginTop() : child->style()->marginBottom(); 205 } 206 207 Length RenderFlexibleBox::marginEndStyleForChild(RenderBox* child) 208 { 209 if (isHorizontalWritingMode()) 210 return style()->isLeftToRightDirection() ? child->style()->marginRight() : child->style()->marginLeft(); 211 return style()->isLeftToRightDirection() ? child->style()->marginBottom() : child->style()->marginTop(); 212 } 213 214 LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) 215 { 216 Length width = isHorizontalWritingMode() ? child->style()->width() : child->style()->height(); 190 bool RenderFlexibleBox::hasOrthogonalFlow(RenderBox* child) const 191 { 192 // FIXME: Is the child->isHorizontalWritingMode() check correct if the child is a flexbox? 193 // Should it be using child->isHorizontalFlow in that case? 194 // Or do we only care about the parent's writing mode? 195 return isHorizontalFlow() != child->isHorizontalWritingMode(); 196 } 197 198 bool RenderFlexibleBox::isHorizontalFlow() const 199 { 200 // FIXME: Take flex-flow value into account. 201 return isHorizontalWritingMode(); 202 } 203 204 bool RenderFlexibleBox::isLeftToRightFlow() const 205 { 206 // FIXME: Take flex-flow value into account. 207 return style()->isLeftToRightDirection(); 208 } 209 210 // FIXME: Make all these flow aware methods actually be flow aware. 211 212 void RenderFlexibleBox::setFlowAwareLogicalHeight(LayoutUnit size) 213 { 214 setLogicalHeight(size); 215 } 216 217 LayoutUnit RenderFlexibleBox::flowAwareLogicalHeightForChild(RenderBox* child) 218 { 219 return logicalHeightForChild(child); 220 } 221 222 LayoutUnit RenderFlexibleBox::flowAwareLogicalWidthForChild(RenderBox* child) 223 { 224 return logicalWidthForChild(child); 225 } 226 227 LayoutUnit RenderFlexibleBox::flowAwareLogicalHeight() const 228 { 229 return logicalHeight(); 230 } 231 232 LayoutUnit RenderFlexibleBox::flowAwareContentLogicalWidth() const 233 { 234 return contentLogicalWidth(); 235 } 236 237 LayoutUnit RenderFlexibleBox::flowAwareAvailableLogicalWidth() const 238 { 239 return availableLogicalWidth(); 240 } 241 242 LayoutUnit RenderFlexibleBox::flowAwareBorderStart() const 243 { 244 return borderStart(); 245 } 246 247 LayoutUnit RenderFlexibleBox::flowAwareBorderBefore() const 248 { 249 return borderBefore(); 250 } 251 252 LayoutUnit RenderFlexibleBox::flowAwareBorderAfter() const 253 { 254 return borderAfter(); 255 } 256 257 LayoutUnit RenderFlexibleBox::flowAwarePaddingStart() const 258 { 259 return paddingStart(); 260 } 261 262 LayoutUnit RenderFlexibleBox::flowAwarePaddingBefore() const 263 { 264 return paddingBefore(); 265 } 266 267 LayoutUnit RenderFlexibleBox::flowAwarePaddingAfter() const 268 { 269 return paddingAfter(); 270 } 271 272 LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(RenderBox* child) const 273 { 274 return marginStartForChild(child); 275 } 276 277 LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(RenderBox* child) const 278 { 279 return marginBeforeForChild(child); 280 } 281 282 LayoutUnit RenderFlexibleBox::flowAwareMarginAfterForChild(RenderBox* child) const 283 { 284 return marginAfterForChild(child); 285 } 286 287 void RenderFlexibleBox::setFlowAwareMarginStartForChild(RenderBox* child, LayoutUnit margin) 288 { 289 setMarginStartForChild(child, margin); 290 } 291 292 void RenderFlexibleBox::setFlowAwareMarginEndForChild(RenderBox* child, LayoutUnit margin) 293 { 294 setMarginEndForChild(child, margin); 295 } 296 297 void RenderFlexibleBox::setFlowAwareLogicalLocationForChild(RenderBox* child, const LayoutPoint& location) 298 { 299 if (isHorizontalFlow()) 300 child->setLocation(location); 301 else 302 child->setLocation(location.transposedPoint()); 303 } 304 305 LayoutUnit RenderFlexibleBox::logicalBorderAndPaddingWidthForChild(RenderBox* child) const 306 { 307 return isHorizontalFlow() ? child->borderAndPaddingWidth() : child->borderAndPaddingHeight(); 308 } 309 310 LayoutUnit RenderFlexibleBox::logicalScrollbarHeightForChild(RenderBox* child) const 311 { 312 return isHorizontalFlow() ? child->verticalScrollbarWidth() : child->horizontalScrollbarHeight(); 313 } 314 315 Length RenderFlexibleBox::marginStartStyleForChild(RenderBox* child) const 316 { 317 if (isHorizontalFlow()) 318 return isLeftToRightFlow() ? child->style()->marginLeft() : child->style()->marginRight(); 319 return isLeftToRightFlow() ? child->style()->marginTop() : child->style()->marginBottom(); 320 } 321 322 Length RenderFlexibleBox::marginEndStyleForChild(RenderBox* child) const 323 { 324 if (isHorizontalFlow()) 325 return isLeftToRightFlow() ? child->style()->marginRight() : child->style()->marginLeft(); 326 return isLeftToRightFlow() ? child->style()->marginBottom() : child->style()->marginTop(); 327 } 328 329 LayoutUnit RenderFlexibleBox::preferredLogicalContentWidthForFlexItem(RenderBox* child) const 330 { 331 Length width = isHorizontalFlow() ? child->style()->width() : child->style()->height(); 217 332 if (width.isAuto()) { 218 LayoutUnit logicalWidth = isHorizontalWritingMode() == child->isHorizontalWritingMode() ? child->maxPreferredLogicalWidth() : child->logicalHeight();333 LayoutUnit logicalWidth = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth(); 219 334 return logicalWidth - logicalBorderAndPaddingWidthForChild(child) - logicalScrollbarHeightForChild(child); 220 335 } 221 return isHorizontal WritingMode() ? child->contentWidth() : child->contentHeight();336 return isHorizontalFlow() ? child->contentWidth() : child->contentHeight(); 222 337 } 223 338 … … 230 345 231 346 computePreferredLogicalWidth(relayoutChildren, treeIterator, preferredLogicalWidth, totalPositiveFlexibility, totalNegativeFlexibility); 232 LayoutUnit availableFreeSpace = contentLogicalWidth() - preferredLogicalWidth;347 LayoutUnit availableFreeSpace = flowAwareContentLogicalWidth() - preferredLogicalWidth; 233 348 234 349 FlexOrderIterator flexIterator(this, treeIterator.flexOrderValues()); … … 245 360 } 246 361 247 float RenderFlexibleBox::logicalPositiveFlexForChild(RenderBox* child) 248 { 249 return isHorizontal WritingMode() ? child->style()->flexboxWidthPositiveFlex() : child->style()->flexboxHeightPositiveFlex();250 } 251 252 float RenderFlexibleBox::logicalNegativeFlexForChild(RenderBox* child) 253 { 254 return isHorizontal WritingMode() ? child->style()->flexboxWidthNegativeFlex() : child->style()->flexboxHeightNegativeFlex();362 float RenderFlexibleBox::logicalPositiveFlexForChild(RenderBox* child) const 363 { 364 return isHorizontalFlow() ? child->style()->flexboxWidthPositiveFlex() : child->style()->flexboxHeightPositiveFlex(); 365 } 366 367 float RenderFlexibleBox::logicalNegativeFlexForChild(RenderBox* child) const 368 { 369 return isHorizontalFlow() ? child->style()->flexboxWidthNegativeFlex() : child->style()->flexboxHeightNegativeFlex(); 255 370 } 256 371 … … 260 375 totalPositiveFlexibility = totalNegativeFlexibility = 0; 261 376 262 LayoutUnit flexboxAvailableLogicalWidth = availableLogicalWidth();377 LayoutUnit flexboxAvailableLogicalWidth = flowAwareAvailableLogicalWidth(); 263 378 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 264 379 // We always have to lay out flexible objects again, since the flex distribution … … 270 385 271 386 // We can't just use marginStartForChild, et. al. because "auto" needs to be treated as 0. 272 if (isHorizontal WritingMode()) {387 if (isHorizontalFlow()) { 273 388 preferredLogicalWidth += child->style()->marginLeft().calcMinValue(flexboxAvailableLogicalWidth); 274 389 preferredLogicalWidth += child->style()->marginRight().calcMinValue(flexboxAvailableLogicalWidth); … … 296 411 childSizes.clear(); 297 412 298 LayoutUnit flexboxAvailableLogicalWidth = availableLogicalWidth();413 LayoutUnit flexboxAvailableLogicalWidth = flowAwareAvailableLogicalWidth(); 299 414 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 300 415 LayoutUnit childPreferredSize; … … 306 421 childPreferredSize += lroundf(availableFreeSpace * logicalPositiveFlexForChild(child) / totalPositiveFlexibility); 307 422 308 Length childLogicalMaxWidth = isHorizontal WritingMode() ? child->style()->maxWidth() : child->style()->maxHeight();423 Length childLogicalMaxWidth = isHorizontalFlow() ? child->style()->maxWidth() : child->style()->maxHeight(); 309 424 if (!childLogicalMaxWidth.isUndefined() && childLogicalMaxWidth.isSpecified() && childPreferredSize > childLogicalMaxWidth.calcValue(flexboxAvailableLogicalWidth)) { 310 425 childPreferredSize = childLogicalMaxWidth.calcValue(flexboxAvailableLogicalWidth); … … 318 433 childPreferredSize += lroundf(availableFreeSpace * logicalNegativeFlexForChild(child) / totalNegativeFlexibility); 319 434 320 Length childLogicalMinWidth = isHorizontal WritingMode() ? child->style()->minWidth() : child->style()->minHeight();435 Length childLogicalMinWidth = isHorizontalFlow() ? child->style()->minWidth() : child->style()->minHeight(); 321 436 if (!childLogicalMinWidth.isUndefined() && childLogicalMinWidth.isSpecified() && childPreferredSize < childLogicalMinWidth.calcValue(flexboxAvailableLogicalWidth)) { 322 437 childPreferredSize = childLogicalMinWidth.calcValue(flexboxAvailableLogicalWidth); … … 342 457 { 343 458 // FIXME: Rename setOverrideWidth/setOverrideHeight to setOverrideLogicalWidth/setOverrideLogicalHeight. 344 if ( isHorizontalWritingMode())345 child-> isHorizontalWritingMode() ? child->setOverrideWidth(childPreferredSize) : child->setOverrideHeight(childPreferredSize);459 if (hasOrthogonalFlow(child)) 460 child->setOverrideHeight(childPreferredSize); 346 461 else 347 child-> isHorizontalWritingMode() ? child->setOverrideHeight(childPreferredSize) : child->setOverrideWidth(childPreferredSize);462 child->setOverrideWidth(childPreferredSize); 348 463 } 349 464 350 465 void RenderFlexibleBox::layoutAndPlaceChildrenInlineDirection(FlexOrderIterator& iterator, const WTF::Vector<LayoutUnit>& childSizes, LayoutUnit availableFreeSpace, float totalPositiveFlexibility) 351 466 { 352 LayoutUnit startEdge = borderStart() + paddingStart();467 LayoutUnit startEdge = flowAwareBorderStart() + flowAwarePaddingStart(); 353 468 354 469 if (hasPackingSpace(availableFreeSpace, totalPositiveFlexibility)) { … … 359 474 } 360 475 361 LayoutUnit logicalTop = borderBefore() + paddingBefore();362 LayoutUnit totalAvailableLogicalWidth = availableLogicalWidth();363 set LogicalHeight(0);476 LayoutUnit logicalTop = flowAwareBorderBefore() + flowAwarePaddingBefore(); 477 LayoutUnit totalAvailableLogicalWidth = flowAwareAvailableLogicalWidth(); 478 setFlowAwareLogicalHeight(0); 364 479 size_t i = 0; 365 480 for (RenderBox* child = iterator.first(); child; child = iterator.next(), ++i) { … … 370 485 child->layoutIfNeeded(); 371 486 372 set LogicalHeight(std::max(logicalHeight(), borderBefore() + paddingBefore() + marginBeforeForChild(child) + logicalHeightForChild(child) + marginAfterForChild(child) + paddingAfter() + borderAfter() + scrollbarLogicalHeight()));487 setFlowAwareLogicalHeight(std::max(flowAwareLogicalHeight(), flowAwareBorderBefore() + flowAwarePaddingBefore() + flowAwareMarginBeforeForChild(child) + flowAwareLogicalHeightForChild(child) + flowAwareMarginAfterForChild(child) + flowAwarePaddingAfter() + flowAwareBorderAfter() + scrollbarLogicalHeight())); 373 488 374 489 if (marginStartStyleForChild(child).isAuto()) 375 set MarginStartForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);490 setFlowAwareMarginStartForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0); 376 491 if (marginEndStyleForChild(child).isAuto()) 377 set MarginEndForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0);378 379 startEdge += marginStartForChild(child);380 381 LayoutUnit childLogicalWidth = logicalWidthForChild(child);382 LayoutUnit logicalLeft = style()->isLeftToRightDirection() ? startEdge : totalAvailableLogicalWidth - startEdge - childLogicalWidth;492 setFlowAwareMarginEndForChild(child, availableFreeSpace > 0 ? lroundf(availableFreeSpace / totalPositiveFlexibility) : 0); 493 494 startEdge += flowAwareMarginStartForChild(child); 495 496 LayoutUnit childLogicalWidth = flowAwareLogicalWidthForChild(child); 497 LayoutUnit logicalLeft = isLeftToRightFlow() ? startEdge : totalAvailableLogicalWidth - startEdge - childLogicalWidth; 383 498 // FIXME: Do repaintDuringLayoutIfMoved. 384 499 // FIXME: Supporting layout deltas. 385 set LogicalLocationForChild(child, IntPoint(logicalLeft, logicalTop));500 setFlowAwareLogicalLocationForChild(child, IntPoint(logicalLeft, logicalTop)); 386 501 startEdge += childLogicalWidth + marginEndForChild(child); 387 502 -
trunk/Source/WebCore/rendering/RenderFlexibleBox.h
r95783 r95856 54 54 typedef WTF::HashMap<const RenderBox*, LayoutUnit> InflexibleFlexItemSize; 55 55 56 LayoutUnit logicalBorderAndPaddingWidthForChild(RenderBox* child); 57 LayoutUnit logicalScrollbarHeightForChild(RenderBox* child); 58 Length marginStartStyleForChild(RenderBox* child); 59 Length marginEndStyleForChild(RenderBox* child); 60 LayoutUnit preferredLogicalContentWidthForFlexItem(RenderBox* child); 56 bool hasOrthogonalFlow(RenderBox* child) const; 57 bool isHorizontalFlow() const; 58 bool isLeftToRightFlow() const; 59 void setFlowAwareLogicalHeight(LayoutUnit); 60 LayoutUnit flowAwareLogicalHeightForChild(RenderBox* child); 61 LayoutUnit flowAwareLogicalWidthForChild(RenderBox* child); 62 LayoutUnit flowAwareLogicalHeight() const; 63 LayoutUnit flowAwareContentLogicalWidth() const; 64 LayoutUnit flowAwareAvailableLogicalWidth() const; 65 LayoutUnit flowAwareBorderStart() const; 66 LayoutUnit flowAwareBorderBefore() const; 67 LayoutUnit flowAwareBorderAfter() const; 68 LayoutUnit flowAwarePaddingStart() const; 69 LayoutUnit flowAwarePaddingBefore() const; 70 LayoutUnit flowAwarePaddingAfter() const; 71 LayoutUnit flowAwareMarginStartForChild(RenderBox* child) const; 72 LayoutUnit flowAwareMarginBeforeForChild(RenderBox* child) const; 73 LayoutUnit flowAwareMarginAfterForChild(RenderBox* child) const; 74 void setFlowAwareMarginStartForChild(RenderBox* child, LayoutUnit); 75 void setFlowAwareMarginEndForChild(RenderBox* child, LayoutUnit); 76 // FIXME: Supporting layout deltas. 77 void setFlowAwareLogicalLocationForChild(RenderBox* child, const LayoutPoint&); 78 LayoutUnit logicalBorderAndPaddingWidthForChild(RenderBox* child) const; 79 LayoutUnit logicalScrollbarHeightForChild(RenderBox* child) const; 80 Length marginStartStyleForChild(RenderBox* child) const; 81 Length marginEndStyleForChild(RenderBox* child) const; 82 LayoutUnit preferredLogicalContentWidthForFlexItem(RenderBox* child) const; 61 83 62 84 void layoutInlineDirection(bool relayoutChildren); 63 85 64 float logicalPositiveFlexForChild(RenderBox* child) ;65 float logicalNegativeFlexForChild(RenderBox* child) ;86 float logicalPositiveFlexForChild(RenderBox* child) const; 87 float logicalNegativeFlexForChild(RenderBox* child) const; 66 88 67 89 void computePreferredLogicalWidth(bool relayoutChildren, TreeOrderIterator&, LayoutUnit&, float& totalPositiveFlexibility, float& totalNegativeFlexibility);
Note: See TracChangeset
for help on using the changeset viewer.