Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 | 242 |
| 243 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. | 243 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. |
| 244 Vector<GridTrack*> filteredTracks; | 244 Vector<GridTrack*> filteredTracks; |
| 245 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 245 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
| 246 Vector<GridTrack*> growBeyondGrowthLimitsTracks; | 246 Vector<GridTrack*> growBeyondGrowthLimitsTracks; |
| 247 | 247 |
| 248 LayoutUnit& freeSpaceForDirection(GridTrackSizingDirection direction) { retu rn direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } | 248 LayoutUnit& freeSpaceForDirection(GridTrackSizingDirection direction) { retu rn direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; } |
| 249 | 249 |
| 250 enum SizingOperation { TrackSizing, IntrinsicSizeComputation }; | 250 enum SizingOperation { TrackSizing, IntrinsicSizeComputation }; |
| 251 SizingOperation sizingOperation { TrackSizing }; | 251 SizingOperation sizingOperation { TrackSizing }; |
| 252 | 252 enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, Colu mnSizingSecondIteration, RowSizingSecondIteration}; |
| 253 SizingState sizingState { ColumnSizingFirstIteration }; | |
| 254 void nextState() | |
| 255 { | |
| 256 switch (sizingState) { | |
| 257 case ColumnSizingFirstIteration: | |
| 258 sizingState = RowSizingFirstIteration; | |
| 259 break; | |
| 260 case RowSizingFirstIteration: | |
| 261 sizingState = ColumnSizingSecondIteration; | |
| 262 break; | |
| 263 case ColumnSizingSecondIteration: | |
| 264 sizingState = RowSizingSecondIteration; | |
| 265 break; | |
| 266 case RowSizingSecondIteration: | |
| 267 sizingState = ColumnSizingFirstIteration; | |
| 268 break; | |
| 269 default: | |
| 270 NOTREACHED(); | |
| 271 sizingState = ColumnSizingFirstIteration; | |
| 272 } | |
| 273 } | |
|
svillar
2016/04/14 08:58:42
I think it's better to merge SizingOperation and S
jfernandez
2016/05/18 10:31:40
I'm not sure about this, for several reasons. Firs
| |
| 274 bool sanityCheck(GridTrackSizingDirection direction) | |
| 275 { | |
| 276 switch (sizingState) { | |
| 277 case ColumnSizingFirstIteration: | |
| 278 return direction == ForColumns ? true : false; | |
| 279 case RowSizingFirstIteration: | |
| 280 return direction == ForRows ? true : false; | |
| 281 case ColumnSizingSecondIteration: | |
| 282 if (direction == ForRows) | |
| 283 sizingState = RowSizingFirstIteration; | |
| 284 return true; | |
| 285 case RowSizingSecondIteration: | |
| 286 return direction == ForRows ? true : false; | |
| 287 } | |
| 288 NOTREACHED(); | |
| 289 return false; | |
| 290 } | |
|
svillar
2016/04/14 08:58:41
Let's enclose this in debugging guards as it's mea
jfernandez
2016/05/18 10:31:40
Done.
| |
| 253 private: | 291 private: |
| 254 LayoutUnit freeSpaceForColumns { }; | 292 LayoutUnit freeSpaceForColumns { }; |
| 255 LayoutUnit freeSpaceForRows { }; | 293 LayoutUnit freeSpaceForRows { }; |
| 256 }; | 294 }; |
| 257 | 295 |
| 258 struct GridItemsSpanGroupRange { | 296 struct GridItemsSpanGroupRange { |
| 259 Vector<GridItemWithSpan>::iterator rangeStart; | 297 Vector<GridItemWithSpan>::iterator rangeStart; |
| 260 Vector<GridItemWithSpan>::iterator rangeEnd; | 298 Vector<GridItemWithSpan>::iterator rangeEnd; |
| 261 }; | 299 }; |
| 262 | 300 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 logicalHeight += row.baseSize(); | 363 logicalHeight += row.baseSize(); |
| 326 | 364 |
| 327 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); | 365 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); |
| 328 | 366 |
| 329 return logicalHeight; | 367 return logicalHeight; |
| 330 } | 368 } |
| 331 | 369 |
| 332 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) | 370 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) |
| 333 { | 371 { |
| 334 ASSERT(freeSpace >= 0); | 372 ASSERT(freeSpace >= 0); |
| 373 DCHECK(sizingData.sanityCheck(direction)); | |
| 335 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); | 374 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); |
| 336 sizingData.sizingOperation = GridSizingData::TrackSizing; | 375 sizingData.sizingOperation = GridSizingData::TrackSizing; |
| 337 | 376 |
| 338 LayoutUnit baseSizes, growthLimits; | 377 LayoutUnit baseSizes, growthLimits; |
| 339 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s, AvailableSpaceDefinite); | 378 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s, AvailableSpaceDefinite); |
| 340 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 379 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
| 380 sizingData.nextState(); | |
| 381 } | |
| 382 | |
| 383 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) | |
| 384 { | |
| 385 DCHECK(sizingData.sizingState > GridSizingData::RowSizingFirstIteration); | |
| 386 | |
| 387 // In orthogonal flow cases column track's size is determined by using the c omputed | |
| 388 // row track's size, which it was estimated during the first cycle of the si zing | |
| 389 // algorithm. Hence we need to repeat computeUsedBreadthOfGridTracks for bot h, | |
| 390 // columns and rows, to determine the final values. | |
| 391 // TODO (lajava): orthogonal flows is just one of the cases which may requir e | |
|
svillar
2016/04/14 08:58:41
which other cases?
jfernandez
2016/05/18 10:31:40
Well, the spec states the following on this regard
| |
| 392 // a new cycle of the sizing algorithm; there may be more. In addition, not all the | |
| 393 // cases with orthogonal flows require this extra cycle; we need a more spec ific | |
| 394 // condition to detect whether child's min-content contribution has changed or not. | |
| 395 if (m_hasAnyOrthogonalChild) { | |
| 396 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | |
| 397 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows ); | |
| 398 } | |
| 341 } | 399 } |
| 342 | 400 |
| 343 void LayoutGrid::layoutBlock(bool relayoutChildren) | 401 void LayoutGrid::layoutBlock(bool relayoutChildren) |
| 344 { | 402 { |
| 345 ASSERT(needsLayout()); | 403 ASSERT(needsLayout()); |
| 346 | 404 |
| 347 if (!relayoutChildren && simplifiedLayout()) | 405 if (!relayoutChildren && simplifiedLayout()) |
| 348 return; | 406 return; |
| 349 | 407 |
| 350 { | 408 { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 361 | 419 |
| 362 placeItemsOnGrid(); | 420 placeItemsOnGrid(); |
| 363 | 421 |
| 364 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 422 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
| 365 | 423 |
| 366 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. | 424 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. |
| 367 // At this point the logical width is always definite as the above call to updateLogicalWidth() | 425 // At this point the logical width is always definite as the above call to updateLogicalWidth() |
| 368 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code | 426 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code |
| 369 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve | 427 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve |
| 370 // heights properly (like for positioned items for example). | 428 // heights properly (like for positioned items for example). |
| 371 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); | 429 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| 430 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | |
| 372 | 431 |
| 373 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the | 432 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the |
| 374 // grid column sizes calculated in the previous step. | 433 // grid column sizes calculated in the previous step. |
| 434 LayoutUnit availableSpaceForRows = availableLogicalHeight(ExcludeMarginB orderPadding); | |
|
svillar
2016/04/14 08:58:41
Better not do this. Calling availableXXX only make
jfernandez
2016/05/18 10:31:40
Done.
| |
| 375 if (logicalHeightWasIndefinite) | 435 if (logicalHeightWasIndefinite) |
| 376 computeIntrinsicLogicalHeight(sizingData); | 436 computeIntrinsicLogicalHeight(sizingData); |
| 377 else | 437 else |
| 378 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); | 438 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); |
| 379 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight()); | 439 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight()); |
| 380 | 440 |
| 381 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); | 441 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
| 382 updateLogicalHeight(); | 442 updateLogicalHeight(); |
| 383 | 443 |
| 384 // The above call might have changed the grid's logical height depending on min|max height restrictions. | 444 // The above call might have changed the grid's logical height depending on min|max height restrictions. |
| 385 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). | 445 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). |
| 446 availableSpaceForRows = contentLogicalHeight(); | |
|
svillar
2016/04/14 08:58:41
Instead you can define this variable right here.
jfernandez
2016/05/18 10:31:40
Done.
| |
| 386 if (logicalHeightWasIndefinite) | 447 if (logicalHeightWasIndefinite) |
| 387 computeTrackSizesForDirection(ForRows, sizingData, contentLogicalHei ght()); | 448 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); |
| 449 | |
| 450 // 3- If the min-content contribution of any grid items have changed bas ed on the row | |
| 451 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content | |
| 452 // contribution (once only). | |
| 453 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); | |
| 388 | 454 |
| 389 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. | 455 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. |
| 390 if (hasLineIfEmpty()) | 456 if (hasLineIfEmpty()) |
| 391 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); | 457 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); |
| 392 | 458 |
| 393 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); | 459 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); |
| 394 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); | 460 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); |
| 395 | 461 |
| 396 layoutGridItems(sizingData); | 462 layoutGridItems(sizingData); |
| 397 | 463 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); | 726 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); |
| 661 } | 727 } |
| 662 | 728 |
| 663 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t | 729 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t |
| 664 { | 730 { |
| 665 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth(); | 731 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth(); |
| 666 } | 732 } |
| 667 | 733 |
| 668 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) | 734 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) |
| 669 { | 735 { |
| 670 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.overrideContainingBlockContentLogicalHeight(); | 736 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.hasOverrideContainingBlockLogicalHeight(); |
|
svillar
2016/04/14 08:58:41
Ups, this is a bug per se. Let's do it separately
| |
| 671 } | 737 } |
| 672 | 738 |
| 673 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) | 739 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) |
| 674 { | 740 { |
| 675 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); | 741 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); |
| 676 } | 742 } |
| 677 | 743 |
| 678 static void setOverrideContainingBlockContentSizeForChild(LayoutBox& child, Grid TrackSizingDirection direction, LayoutUnit size) | 744 static void setOverrideContainingBlockContentSizeForChild(LayoutBox& child, Grid TrackSizingDirection direction, LayoutUnit size) |
| 679 { | 745 { |
| 680 if (direction == ForColumns) | 746 if (direction == ForColumns) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 return child.logicalHeight() + child.marginLogicalHeight(); | 804 return child.logicalHeight() + child.marginLogicalHeight(); |
| 739 } | 805 } |
| 740 | 806 |
| 741 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild(const LayoutBox& child, GridTrackSizingDirection direction) const | 807 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild(const LayoutBox& child, GridTrackSizingDirection direction) const |
| 742 { | 808 { |
| 743 return !isOrthogonalChild(child) ? direction : (direction == ForColumns ? Fo rRows : ForColumns); | 809 return !isOrthogonalChild(child) ? direction : (direction == ForColumns ? Fo rRows : ForColumns); |
| 744 } | 810 } |
| 745 | 811 |
| 746 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, GridSizingData& sizingData) | 812 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, GridSizingData& sizingData) |
| 747 { | 813 { |
| 748 // TODO(svillar): Properly support orthogonal writing mode. | |
| 749 if (isOrthogonalChild(child)) | |
| 750 return LayoutUnit(); | |
| 751 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 814 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
| 752 bool isRowAxis = direction == childInlineDirection; | 815 bool isRowAxis = direction == childInlineDirection; |
| 753 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth() : chil d.styleRef().logicalHeight(); | 816 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth() : chil d.styleRef().logicalHeight(); |
| 754 const Length& childMinSize = isRowAxis ? child.styleRef().logicalMinWidth() : child.styleRef().logicalMinHeight(); | 817 const Length& childMinSize = isRowAxis ? child.styleRef().logicalMinWidth() : child.styleRef().logicalMinHeight(); |
| 755 if (!childSize.isAuto() || childMinSize.isAuto()) | 818 if (!childSize.isAuto() || childMinSize.isAuto()) |
| 756 return minContentForChild(child, direction, sizingData); | 819 return minContentForChild(child, direction, sizingData); |
| 757 | 820 |
| 758 bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChi ld(child, childInlineDirection, sizingData); | 821 bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChi ld(child, childInlineDirection, sizingData); |
| 759 if (isRowAxis) { | 822 if (isRowAxis) { |
| 760 LayoutUnit marginLogicalWidth = sizingData.sizingOperation == GridSizing Data::TrackSizing ? computeMarginLogicalSizeForChild(InlineDirection, child) : m arginIntrinsicLogicalWidthForChild(child); | 823 LayoutUnit marginLogicalWidth = sizingData.sizingOperation == GridSizing Data::TrackSizing ? computeMarginLogicalSizeForChild(InlineDirection, child) : m arginIntrinsicLogicalWidthForChild(child); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 772 LayoutUnit overrideSize = gridAreaBreadthForChild(child, direction, sizingDa ta); | 835 LayoutUnit overrideSize = gridAreaBreadthForChild(child, direction, sizingDa ta); |
| 773 if (hasOverrideContainingBlockContentSizeForChild(child, direction) && overr ideContainingBlockContentSizeForChild(child, direction) == overrideSize) | 836 if (hasOverrideContainingBlockContentSizeForChild(child, direction) && overr ideContainingBlockContentSizeForChild(child, direction) == overrideSize) |
| 774 return false; | 837 return false; |
| 775 | 838 |
| 776 setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize ); | 839 setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize ); |
| 777 return true; | 840 return true; |
| 778 } | 841 } |
| 779 | 842 |
| 780 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) | 843 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) |
| 781 { | 844 { |
| 782 // FIXME: Properly support orthogonal writing mode. | |
| 783 if (isOrthogonalChild(child)) | |
| 784 return LayoutUnit(); | |
| 785 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 845 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
| 786 if (direction == childInlineDirection) { | 846 if (direction == childInlineDirection) { |
| 787 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 847 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
| 788 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). | 848 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). |
| 789 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) | 849 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) |
| 790 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); | 850 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); |
| 791 | 851 |
| 792 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 852 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
| 793 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 853 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
| 794 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 854 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
| 795 } | 855 } |
| 796 | 856 |
| 797 SubtreeLayoutScope layouter(child); | 857 SubtreeLayoutScope layouter(child); |
| 798 if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirec tion, sizingData)) | 858 if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirec tion, sizingData)) |
| 799 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 859 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
| 800 return logicalHeightForChild(child, sizingData); | 860 return logicalHeightForChild(child, sizingData); |
| 801 } | 861 } |
| 802 | 862 |
| 803 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) | 863 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) |
| 804 { | 864 { |
| 805 if (isOrthogonalChild(child)) | |
| 806 return LayoutUnit(); | |
| 807 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 865 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
| 808 if (direction == childInlineDirection) { | 866 if (direction == childInlineDirection) { |
| 809 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 867 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
| 810 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). | 868 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). |
| 811 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) | 869 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) |
| 812 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); | 870 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); |
| 813 | 871 |
| 814 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 872 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
| 815 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 873 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
| 816 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 874 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1183 | 1241 |
| 1184 ASSERT(m_gridItemArea.isEmpty()); | 1242 ASSERT(m_gridItemArea.isEmpty()); |
| 1185 | 1243 |
| 1186 populateExplicitGridAndOrderIterator(); | 1244 populateExplicitGridAndOrderIterator(); |
| 1187 | 1245 |
| 1188 // We clear the dirty bit here as the grid sizes have been updated. | 1246 // We clear the dirty bit here as the grid sizes have been updated. |
| 1189 m_gridIsDirty = false; | 1247 m_gridIsDirty = false; |
| 1190 | 1248 |
| 1191 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 1249 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
| 1192 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 1250 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
| 1251 m_hasAnyOrthogonalChild = false; | |
| 1193 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { | 1252 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { |
| 1194 if (child->isOutOfFlowPositioned()) | 1253 if (child->isOutOfFlowPositioned()) |
| 1195 continue; | 1254 continue; |
| 1196 | 1255 |
| 1256 m_hasAnyOrthogonalChild = m_hasAnyOrthogonalChild || isOrthogonalChild(* child); | |
| 1257 | |
| 1197 GridArea area = cachedGridArea(*child); | 1258 GridArea area = cachedGridArea(*child); |
| 1198 if (!area.rows.isIndefinite()) | 1259 if (!area.rows.isIndefinite()) |
| 1199 area.rows.translate(abs(m_smallestRowStart)); | 1260 area.rows.translate(abs(m_smallestRowStart)); |
| 1200 if (!area.columns.isIndefinite()) | 1261 if (!area.columns.isIndefinite()) |
| 1201 area.columns.translate(abs(m_smallestColumnStart)); | 1262 area.columns.translate(abs(m_smallestColumnStart)); |
| 1202 m_gridItemArea.set(child, area); | 1263 m_gridItemArea.set(child, area); |
| 1203 | 1264 |
| 1204 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 1265 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
| 1205 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; | 1266 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; |
| 1206 if (majorAxisPositions.isIndefinite()) | 1267 if (majorAxisPositions.isIndefinite()) |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1469 | 1530 |
| 1470 // Because the grid area cannot be styled, we don't need to adjust | 1531 // Because the grid area cannot be styled, we don't need to adjust |
| 1471 // the grid breadth to account for 'box-sizing'. | 1532 // the grid breadth to account for 'box-sizing'. |
| 1472 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); | 1533 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); |
| 1473 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); | 1534 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); |
| 1474 | 1535 |
| 1475 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); | 1536 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); |
| 1476 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); | 1537 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); |
| 1477 | 1538 |
| 1478 SubtreeLayoutScope layoutScope(*child); | 1539 SubtreeLayoutScope layoutScope(*child); |
| 1479 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1540 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && (child->hasRelativeLogicalHeight() || isOrthogonalChild(*child)))) |
| 1480 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); | 1541 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); |
| 1481 | 1542 |
| 1482 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 1543 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
| 1483 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 1544 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
| 1484 | 1545 |
| 1485 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded | 1546 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded |
| 1486 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly | 1547 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly |
| 1487 // determine the available space before stretching, are not set yet. | 1548 // determine the available space before stretching, are not set yet. |
| 1488 applyStretchAlignmentToChildIfNeeded(*child); | 1549 applyStretchAlignmentToChildIfNeeded(*child); |
| 1489 | 1550 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 ASSERT(m_gridItemArea.contains(&gridItem)); | 1692 ASSERT(m_gridItemArea.contains(&gridItem)); |
| 1632 return m_gridItemArea.get(&gridItem); | 1693 return m_gridItemArea.get(&gridItem); |
| 1633 } | 1694 } |
| 1634 | 1695 |
| 1635 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const | 1696 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const |
| 1636 { | 1697 { |
| 1637 GridArea area = cachedGridArea(gridItem); | 1698 GridArea area = cachedGridArea(gridItem); |
| 1638 return direction == ForColumns ? area.columns : area.rows; | 1699 return direction == ForColumns ? area.columns : area.rows; |
| 1639 } | 1700 } |
| 1640 | 1701 |
| 1702 bool LayoutGrid::gridLengthIsIndefinite(const GridLength& length, GridTrackSizin gDirection direction) const | |
|
svillar
2016/04/14 08:58:41
The name suggests that you're checking the length
jfernandez
2016/05/18 10:31:40
Acknowledged.
| |
| 1703 { | |
| 1704 return length.isContentSized() || length.isFlex() || !hasDefiniteLogicalSize (direction); | |
|
svillar
2016/04/14 08:58:42
This usage of hasDefiniteLogicalSize() is not corr
jfernandez
2016/05/18 10:31:40
I don't think there is anything wrong with current
svillar
2016/05/26 08:49:02
BTW you are considering percentages as definite si
jfernandez
2016/05/27 09:41:22
Note that the GridLength is extracted suing the gr
| |
| 1705 } | |
| 1706 | |
| 1707 LayoutUnit LayoutGrid::assumedRowsBreadthForOrthogonalChild(const LayoutBox& chi ld) const | |
|
svillar
2016/04/14 08:58:41
Breadth -> Size
jfernandez
2016/05/18 10:31:40
Done.
| |
| 1708 { | |
| 1709 ASSERT(isOrthogonalChild(child)); | |
|
svillar
2016/04/14 08:58:41
DCHECK
jfernandez
2016/05/18 10:31:40
Done.
| |
| 1710 const GridSpan& span = cachedGridSpan(child, ForRows); | |
| 1711 LayoutUnit gridAreaBreadth; | |
| 1712 for (auto trackPosition : span) { | |
| 1713 const GridLength& maxTrackBreadth = gridTrackSize(ForRows, trackPosition ).maxTrackBreadth(); | |
| 1714 if (gridLengthIsIndefinite(maxTrackBreadth, ForRows)) { | |
| 1715 gridAreaBreadth = child.maxPreferredLogicalWidth() + marginIntrinsic LogicalWidthForChild(child); | |
| 1716 break; | |
|
svillar
2016/04/14 08:58:41
This looks wrong, because the final value of gridA
jfernandez
2016/05/18 10:31:40
I understand your concerns, however, I think that
svillar
2016/05/26 08:49:02
If this is the case then we should have some ASSER
jfernandez
2016/05/27 09:41:22
I don't think ASSERT that makes sense. One should
| |
| 1717 } | |
| 1718 gridAreaBreadth += valueForLength(maxTrackBreadth.length(), LayoutUnit() ); | |
|
svillar
2016/04/14 08:58:41
If I am not wrong the second value is the maximum
jfernandez
2016/05/18 10:31:40
Your assumption on the usage of such second argume
svillar
2016/05/26 08:49:02
Yes I expect it to work for all the potential case
jfernandez
2016/05/27 09:41:22
Ill fix the case of percentage sizes for tracks an
| |
| 1719 } | |
| 1720 | |
| 1721 gridAreaBreadth += guttersSize(ForRows, span.integerSpan()); | |
| 1722 | |
| 1723 return gridAreaBreadth; | |
| 1724 } | |
| 1725 | |
| 1641 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const | 1726 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const |
| 1642 { | 1727 { |
| 1643 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; | 1728 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which |
| 1729 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet, | |
| 1730 // so we will need to do an estimation. | |
| 1731 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration) | |
| 1732 return assumedRowsBreadthForOrthogonalChild(child); | |
| 1733 | |
| 1734 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; | |
|
svillar
2016/04/14 08:58:41
No need for parentheses.
jfernandez
2016/05/18 10:31:40
Done.
| |
| 1644 const GridSpan& span = cachedGridSpan(child, direction); | 1735 const GridSpan& span = cachedGridSpan(child, direction); |
| 1645 LayoutUnit gridAreaBreadth; | 1736 LayoutUnit gridAreaBreadth; |
| 1646 for (const auto& trackPosition : span) | 1737 for (const auto& trackPosition : span) |
| 1647 gridAreaBreadth += tracks[trackPosition].baseSize(); | 1738 gridAreaBreadth += tracks[trackPosition].baseSize(); |
| 1648 | 1739 |
| 1649 gridAreaBreadth += guttersSize(direction, span.integerSpan()); | 1740 gridAreaBreadth += guttersSize(direction, span.integerSpan()); |
| 1650 | 1741 |
| 1651 return gridAreaBreadth; | 1742 return gridAreaBreadth; |
| 1652 } | 1743 } |
| 1653 | 1744 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2101 case ContentPositionNormal: | 2192 case ContentPositionNormal: |
| 2102 break; | 2193 break; |
| 2103 } | 2194 } |
| 2104 | 2195 |
| 2105 ASSERT_NOT_REACHED(); | 2196 ASSERT_NOT_REACHED(); |
| 2106 return {LayoutUnit(), LayoutUnit()}; | 2197 return {LayoutUnit(), LayoutUnit()}; |
| 2107 } | 2198 } |
| 2108 | 2199 |
| 2109 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const | 2200 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const |
| 2110 { | 2201 { |
| 2202 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); | |
| 2111 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); | 2203 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); |
| 2112 // We stored m_columnPosition's data ignoring the direction, hence we might need now | 2204 // We stored m_columnPosition's data ignoring the direction, hence we might need now |
| 2113 // to translate positions from RTL to LTR, as it's more convenient for paint ing. | 2205 // to translate positions from RTL to LTR, as it's more convenient for paint ing. |
| 2114 if (!style()->isLeftToRightDirection()) { | 2206 if (!style()->isLeftToRightDirection()) { |
| 2115 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); | 2207 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); |
| 2116 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); | 2208 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); |
| 2117 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); | 2209 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); |
| 2118 } | 2210 } |
| 2119 | 2211 |
| 2120 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); | 2212 // "In the positioning phase [...] calculations are performed according to t he writing mode |
| 2213 // of the containing block of the box establishing the orthogonal flow." How ever, the | |
| 2214 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's | |
| 2215 // logical position, which will only take into account the child's writing-m ode. | |
| 2216 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); | |
| 2217 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | |
| 2121 } | 2218 } |
| 2122 | 2219 |
| 2123 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2220 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
| 2124 { | 2221 { |
| 2125 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2222 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 2126 } | 2223 } |
| 2127 | 2224 |
| 2128 } // namespace blink | 2225 } // namespace blink |
| OLD | NEW |