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 stateTransition() | |
svillar
2016/06/02 14:39:40
Nit: what about nextState() ?
jfernandez
2016/06/02 21:39:25
Done.
| |
255 { | |
256 switch (sizingState) { | |
257 case ColumnSizingFirstIteration: | |
258 sizingState = RowSizingFirstIteration; | |
259 return; | |
260 case RowSizingFirstIteration: | |
261 sizingState = ColumnSizingSecondIteration; | |
262 return; | |
263 case ColumnSizingSecondIteration: | |
264 sizingState = RowSizingSecondIteration; | |
265 return; | |
266 case RowSizingSecondIteration: | |
267 sizingState = ColumnSizingFirstIteration; | |
268 return; | |
269 } | |
270 NOTREACHED(); | |
271 sizingState = ColumnSizingFirstIteration; | |
272 } | |
273 #if DCHECK_IS_ON() | |
274 bool isValidTransitionForDirection(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 } | |
291 #endif | |
253 private: | 292 private: |
254 LayoutUnit freeSpaceForColumns { }; | 293 LayoutUnit freeSpaceForColumns { }; |
255 LayoutUnit freeSpaceForRows { }; | 294 LayoutUnit freeSpaceForRows { }; |
256 }; | 295 }; |
257 | 296 |
258 struct GridItemsSpanGroupRange { | 297 struct GridItemsSpanGroupRange { |
259 Vector<GridItemWithSpan>::iterator rangeStart; | 298 Vector<GridItemWithSpan>::iterator rangeStart; |
260 Vector<GridItemWithSpan>::iterator rangeEnd; | 299 Vector<GridItemWithSpan>::iterator rangeEnd; |
261 }; | 300 }; |
262 | 301 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 logicalHeight += row.baseSize(); | 369 logicalHeight += row.baseSize(); |
331 | 370 |
332 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); | 371 logicalHeight += guttersSize(ForRows, sizingData.rowTracks.size()); |
333 | 372 |
334 return logicalHeight; | 373 return logicalHeight; |
335 } | 374 } |
336 | 375 |
337 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) | 376 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit freeSpace) |
338 { | 377 { |
339 ASSERT(freeSpace >= 0); | 378 ASSERT(freeSpace >= 0); |
379 DCHECK(sizingData.isValidTransitionForDirection(direction)); | |
340 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); | 380 sizingData.freeSpaceForDirection(direction) = freeSpace - guttersSize(direct ion, direction == ForRows ? gridRowCount() : gridColumnCount()); |
341 sizingData.sizingOperation = GridSizingData::TrackSizing; | 381 sizingData.sizingOperation = GridSizingData::TrackSizing; |
342 | 382 |
343 LayoutUnit baseSizes, growthLimits; | 383 LayoutUnit baseSizes, growthLimits; |
344 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s, AvailableSpaceDefinite); | 384 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s, AvailableSpaceDefinite); |
345 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); | 385 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); |
386 sizingData.stateTransition(); | |
387 } | |
388 | |
389 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) | |
390 { | |
391 DCHECK(sizingData.sizingState > GridSizingData::RowSizingFirstIteration); | |
392 | |
393 // In orthogonal flow cases column track's size is determined by using the c omputed | |
394 // row track's size, which it was estimated during the first cycle of the si zing | |
395 // algorithm. Hence we need to repeat computeUsedBreadthOfGridTracks for bot h, | |
396 // columns and rows, to determine the final values. | |
397 // TODO (lajava): orthogonal flows is just one of the cases which may requir e | |
398 // a new cycle of the sizing algorithm; there may be more. In addition, not all the | |
399 // cases with orthogonal flows require this extra cycle; we need a more spec ific | |
400 // condition to detect whether child's min-content contribution has changed or not. | |
401 if (m_hasAnyOrthogonalChild) { | |
402 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | |
403 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows ); | |
404 } | |
svillar
2016/06/02 14:39:40
I think we don't need this, see my comment bellow.
jfernandez
2016/06/02 21:39:25
I disagree, I think the function adds value, see m
| |
346 } | 405 } |
347 | 406 |
348 void LayoutGrid::layoutBlock(bool relayoutChildren) | 407 void LayoutGrid::layoutBlock(bool relayoutChildren) |
349 { | 408 { |
350 ASSERT(needsLayout()); | 409 ASSERT(needsLayout()); |
351 | 410 |
352 if (!relayoutChildren && simplifiedLayout()) | 411 if (!relayoutChildren && simplifiedLayout()) |
353 return; | 412 return; |
354 | 413 |
355 SubtreeLayoutScope layoutScope(*this); | 414 SubtreeLayoutScope layoutScope(*this); |
(...skipping 12 matching lines...) Expand all Loading... | |
368 | 427 |
369 placeItemsOnGrid(); | 428 placeItemsOnGrid(); |
370 | 429 |
371 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 430 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
372 | 431 |
373 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. | 432 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. |
374 // At this point the logical width is always definite as the above call to updateLogicalWidth() | 433 // At this point the logical width is always definite as the above call to updateLogicalWidth() |
375 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code | 434 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code |
376 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve | 435 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve |
377 // heights properly (like for positioned items for example). | 436 // heights properly (like for positioned items for example). |
378 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); | 437 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
438 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | |
379 | 439 |
380 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the | 440 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the |
381 // grid column sizes calculated in the previous step. | 441 // grid column sizes calculated in the previous step. |
382 if (logicalHeightWasIndefinite) | 442 if (logicalHeightWasIndefinite) |
383 computeIntrinsicLogicalHeight(sizingData); | 443 computeIntrinsicLogicalHeight(sizingData); |
384 else | 444 else |
385 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); | 445 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); |
386 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); | 446 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); |
387 | 447 |
388 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); | 448 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
389 updateLogicalHeight(); | 449 updateLogicalHeight(); |
390 | 450 |
391 // The above call might have changed the grid's logical height depending on min|max height restrictions. | 451 // The above call might have changed the grid's logical height depending on min|max height restrictions. |
392 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). | 452 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). |
453 LayoutUnit availableSpaceForRows = contentLogicalHeight(); | |
393 if (logicalHeightWasIndefinite) | 454 if (logicalHeightWasIndefinite) |
394 computeTrackSizesForDirection(ForRows, sizingData, contentLogicalHei ght()); | 455 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); |
456 | |
457 // 3- If the min-content contribution of any grid items have changed bas ed on the row | |
458 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content | |
459 // contribution (once only). | |
460 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); | |
395 | 461 |
396 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. | 462 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. |
397 if (hasLineIfEmpty()) | 463 if (hasLineIfEmpty()) |
398 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); | 464 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); |
399 | 465 |
400 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); | 466 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); |
401 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); | 467 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); |
402 | 468 |
403 layoutGridItems(sizingData); | 469 layoutGridItems(sizingData); |
404 | 470 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); | 733 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); |
668 } | 734 } |
669 | 735 |
670 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t | 736 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t |
671 { | 737 { |
672 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth(); | 738 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth(); |
673 } | 739 } |
674 | 740 |
675 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) | 741 static bool hasOverrideContainingBlockContentSizeForChild(const LayoutBox& child , GridTrackSizingDirection direction) |
676 { | 742 { |
677 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.overrideContainingBlockContentLogicalHeight(); | 743 return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidt h() : child.hasOverrideContainingBlockLogicalHeight(); |
678 } | 744 } |
679 | 745 |
680 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) | 746 static LayoutUnit overrideContainingBlockContentSizeForChild(const LayoutBox& ch ild, GridTrackSizingDirection direction) |
681 { | 747 { |
682 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); | 748 return direction == ForColumns ? child.overrideContainingBlockContentLogical Width() : child.overrideContainingBlockContentLogicalHeight(); |
683 } | 749 } |
684 | 750 |
685 static void setOverrideContainingBlockContentSizeForChild(LayoutBox& child, Grid TrackSizingDirection direction, LayoutUnit size) | 751 static void setOverrideContainingBlockContentSizeForChild(LayoutBox& child, Grid TrackSizingDirection direction, LayoutUnit size) |
686 { | 752 { |
687 if (direction == ForColumns) | 753 if (direction == ForColumns) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
777 return child.logicalHeight() + child.marginLogicalHeight(); | 843 return child.logicalHeight() + child.marginLogicalHeight(); |
778 } | 844 } |
779 | 845 |
780 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild(const LayoutBox& child, GridTrackSizingDirection direction) const | 846 GridTrackSizingDirection LayoutGrid::flowAwareDirectionForChild(const LayoutBox& child, GridTrackSizingDirection direction) const |
781 { | 847 { |
782 return !isOrthogonalChild(child) ? direction : (direction == ForColumns ? Fo rRows : ForColumns); | 848 return !isOrthogonalChild(child) ? direction : (direction == ForColumns ? Fo rRows : ForColumns); |
783 } | 849 } |
784 | 850 |
785 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, GridSizingData& sizingData) | 851 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, GridSizingData& sizingData) |
786 { | 852 { |
787 // TODO(svillar): Properly support orthogonal writing mode. | |
788 if (isOrthogonalChild(child)) | |
789 return LayoutUnit(); | |
790 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 853 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
791 bool isRowAxis = direction == childInlineDirection; | 854 bool isRowAxis = direction == childInlineDirection; |
792 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth() : chil d.styleRef().logicalHeight(); | 855 const Length& childSize = isRowAxis ? child.styleRef().logicalWidth() : chil d.styleRef().logicalHeight(); |
793 const Length& childMinSize = isRowAxis ? child.styleRef().logicalMinWidth() : child.styleRef().logicalMinHeight(); | 856 const Length& childMinSize = isRowAxis ? child.styleRef().logicalMinWidth() : child.styleRef().logicalMinHeight(); |
794 if (!childSize.isAuto() || childMinSize.isAuto()) | 857 if (!childSize.isAuto() || childMinSize.isAuto()) |
795 return minContentForChild(child, direction, sizingData); | 858 return minContentForChild(child, direction, sizingData); |
796 | 859 |
797 bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChi ld(child, childInlineDirection, sizingData); | 860 bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChi ld(child, childInlineDirection, sizingData); |
798 if (isRowAxis) { | 861 if (isRowAxis) { |
799 LayoutUnit marginLogicalWidth = sizingData.sizingOperation == GridSizing Data::TrackSizing ? computeMarginLogicalSizeForChild(InlineDirection, child) : m arginIntrinsicLogicalWidthForChild(child); | 862 LayoutUnit marginLogicalWidth = sizingData.sizingOperation == GridSizing Data::TrackSizing ? computeMarginLogicalSizeForChild(InlineDirection, child) : m arginIntrinsicLogicalWidthForChild(child); |
(...skipping 11 matching lines...) Expand all Loading... | |
811 LayoutUnit overrideSize = gridAreaBreadthForChild(child, direction, sizingDa ta); | 874 LayoutUnit overrideSize = gridAreaBreadthForChild(child, direction, sizingDa ta); |
812 if (hasOverrideContainingBlockContentSizeForChild(child, direction) && overr ideContainingBlockContentSizeForChild(child, direction) == overrideSize) | 875 if (hasOverrideContainingBlockContentSizeForChild(child, direction) && overr ideContainingBlockContentSizeForChild(child, direction) == overrideSize) |
813 return false; | 876 return false; |
814 | 877 |
815 setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize ); | 878 setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize ); |
816 return true; | 879 return true; |
817 } | 880 } |
818 | 881 |
819 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) | 882 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) |
820 { | 883 { |
821 // FIXME: Properly support orthogonal writing mode. | |
822 if (isOrthogonalChild(child)) | |
823 return LayoutUnit(); | |
824 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 884 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
825 if (direction == childInlineDirection) { | 885 if (direction == childInlineDirection) { |
826 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 886 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
827 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). | 887 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). |
828 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) | 888 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) |
829 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); | 889 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); |
830 | 890 |
831 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 891 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
832 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 892 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
833 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 893 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
834 } | 894 } |
835 | 895 |
836 SubtreeLayoutScope layouter(child); | 896 SubtreeLayoutScope layouter(child); |
837 if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirec tion, sizingData)) | 897 if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirec tion, sizingData)) |
838 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); | 898 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); |
839 return logicalHeightForChild(child, sizingData); | 899 return logicalHeightForChild(child, sizingData); |
840 } | 900 } |
841 | 901 |
842 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) | 902 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, GridSizingData& sizingData) |
843 { | 903 { |
844 if (isOrthogonalChild(child)) | |
845 return LayoutUnit(); | |
846 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); | 904 GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(c hild, ForColumns); |
847 if (direction == childInlineDirection) { | 905 if (direction == childInlineDirection) { |
848 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is | 906 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is |
849 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). | 907 // what we are interested in here. Thus we need to set the inline-axis o verride size to -1 (no possible resolution). |
850 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) | 908 if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColu mns)) |
851 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); | 909 setOverrideContainingBlockContentSizeForChild(child, childInlineDire ction, LayoutUnit(-1)); |
852 | 910 |
853 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. | 911 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. |
854 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html | 912 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html |
855 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); | 913 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1300 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); | 1358 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); |
1301 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); | 1359 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); |
1302 | 1360 |
1303 populateExplicitGridAndOrderIterator(); | 1361 populateExplicitGridAndOrderIterator(); |
1304 | 1362 |
1305 // We clear the dirty bit here as the grid sizes have been updated. | 1363 // We clear the dirty bit here as the grid sizes have been updated. |
1306 m_gridIsDirty = false; | 1364 m_gridIsDirty = false; |
1307 | 1365 |
1308 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 1366 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
1309 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 1367 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
1368 m_hasAnyOrthogonalChild = false; | |
1310 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { | 1369 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { |
1311 if (child->isOutOfFlowPositioned()) | 1370 if (child->isOutOfFlowPositioned()) |
1312 continue; | 1371 continue; |
1313 | 1372 |
1373 m_hasAnyOrthogonalChild = m_hasAnyOrthogonalChild || isOrthogonalChild(* child); | |
svillar
2016/06/02 14:39:40
That is not enough. Note that you could dynamicall
jfernandez
2016/06/02 21:39:25
I see, I'll change how I identify orthogonality.
| |
1374 | |
1314 GridArea area = cachedGridArea(*child); | 1375 GridArea area = cachedGridArea(*child); |
1315 if (!area.rows.isIndefinite()) | 1376 if (!area.rows.isIndefinite()) |
1316 area.rows.translate(abs(m_smallestRowStart)); | 1377 area.rows.translate(abs(m_smallestRowStart)); |
1317 if (!area.columns.isIndefinite()) | 1378 if (!area.columns.isIndefinite()) |
1318 area.columns.translate(abs(m_smallestColumnStart)); | 1379 area.columns.translate(abs(m_smallestColumnStart)); |
1319 m_gridItemArea.set(child, area); | 1380 m_gridItemArea.set(child, area); |
1320 | 1381 |
1321 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 1382 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
1322 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; | 1383 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; |
1323 if (majorAxisPositions.isIndefinite()) | 1384 if (majorAxisPositions.isIndefinite()) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1586 | 1647 |
1587 // Because the grid area cannot be styled, we don't need to adjust | 1648 // Because the grid area cannot be styled, we don't need to adjust |
1588 // the grid breadth to account for 'box-sizing'. | 1649 // the grid breadth to account for 'box-sizing'. |
1589 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); | 1650 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); |
1590 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); | 1651 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); |
1591 | 1652 |
1592 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); | 1653 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChildIncludingAlignmentOffsets(*child, ForColumns, sizingData); |
1593 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); | 1654 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChildIncludingAlignmentOffsets(*child, ForRows, sizingData); |
1594 | 1655 |
1595 SubtreeLayoutScope layoutScope(*child); | 1656 SubtreeLayoutScope layoutScope(*child); |
1596 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) | 1657 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && (child->hasRelativeLogicalHeight() || isOrthogonalChild(*child)))) |
1597 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); | 1658 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); |
1598 | 1659 |
1599 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); | 1660 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); |
1600 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); | 1661 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); |
1601 | 1662 |
1602 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded | 1663 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded |
1603 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly | 1664 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly |
1604 // determine the available space before stretching, are not set yet. | 1665 // determine the available space before stretching, are not set yet. |
1605 applyStretchAlignmentToChildIfNeeded(*child); | 1666 applyStretchAlignmentToChildIfNeeded(*child); |
1606 | 1667 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1756 ASSERT(m_gridItemArea.contains(&gridItem)); | 1817 ASSERT(m_gridItemArea.contains(&gridItem)); |
1757 return m_gridItemArea.get(&gridItem); | 1818 return m_gridItemArea.get(&gridItem); |
1758 } | 1819 } |
1759 | 1820 |
1760 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const | 1821 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const |
1761 { | 1822 { |
1762 GridArea area = cachedGridArea(gridItem); | 1823 GridArea area = cachedGridArea(gridItem); |
1763 return direction == ForColumns ? area.columns : area.rows; | 1824 return direction == ForColumns ? area.columns : area.rows; |
1764 } | 1825 } |
1765 | 1826 |
1827 LayoutUnit LayoutGrid::assumedRowsSizeForOrthogonalChild(const LayoutBox& child) const | |
1828 { | |
1829 DCHECK(isOrthogonalChild(child)); | |
1830 const GridSpan& span = cachedGridSpan(child, ForRows); | |
1831 LayoutUnit gridAreaSize; | |
1832 bool gridAreaIsIndefinite = false; | |
1833 LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForCon tent(ExcludeMarginBorderPadding); | |
1834 for (auto trackPosition : span) { | |
1835 const GridLength& maxTrackSize = gridTrackSize(ForRows, trackPosition).m axTrackBreadth(); | |
1836 if (maxTrackSize.isContentSized() || maxTrackSize.isFlex()) | |
svillar
2016/06/02 14:39:40
I think this is still not correct for percentages
jfernandez
2016/06/02 21:39:25
I don't understand what you mean; as far as I know
svillar
2016/06/10 08:08:35
Yes you're right, sorry for the noise.
| |
1837 gridAreaIsIndefinite = true; | |
1838 else | |
1839 gridAreaSize += valueForLength(maxTrackSize.length(), containingBloc kAvailableSize); | |
1840 } | |
1841 | |
1842 gridAreaSize += guttersSize(ForRows, span.integerSpan()); | |
1843 | |
1844 return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gri dAreaSize) : gridAreaSize; | |
1845 } | |
1846 | |
1766 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const | 1847 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const |
1767 { | 1848 { |
1849 // To determine the column track's size based on an orthogonal grid item we need it's logical height, which | |
1850 // may depend on the row track's size. It's possible that the row tracks siz ing logic has not been performed yet, | |
1851 // so we will need to do an estimation. | |
1852 if (direction == ForRows && sizingData.sizingState == GridSizingData::Column SizingFirstIteration) | |
1853 return assumedRowsSizeForOrthogonalChild(child); | |
svillar
2016/06/02 14:39:40
So assumedRowsSizeForOrthogonalChild() has an asse
jfernandez
2016/06/02 21:39:25
If we are determining column track's size in the F
svillar
2016/06/10 08:08:35
OK. In any case as we depend on the value of an st
jfernandez
2016/06/21 21:50:03
Done.
| |
1854 | |
1768 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; | 1855 const Vector<GridTrack>& tracks = direction == ForColumns ? sizingData.colum nTracks : sizingData.rowTracks; |
1769 const GridSpan& span = cachedGridSpan(child, direction); | 1856 const GridSpan& span = cachedGridSpan(child, direction); |
1770 LayoutUnit gridAreaBreadth; | 1857 LayoutUnit gridAreaBreadth; |
1771 for (const auto& trackPosition : span) | 1858 for (const auto& trackPosition : span) |
1772 gridAreaBreadth += tracks[trackPosition].baseSize(); | 1859 gridAreaBreadth += tracks[trackPosition].baseSize(); |
1773 | 1860 |
1774 gridAreaBreadth += guttersSize(direction, span.integerSpan()); | 1861 gridAreaBreadth += guttersSize(direction, span.integerSpan()); |
1775 | 1862 |
1776 return gridAreaBreadth; | 1863 return gridAreaBreadth; |
1777 } | 1864 } |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2225 { | 2312 { |
2226 ASSERT(!styleRef().isLeftToRightDirection()); | 2313 ASSERT(!styleRef().isLeftToRightDirection()); |
2227 | 2314 |
2228 LayoutUnit alignmentOffset = m_columnPositions[0]; | 2315 LayoutUnit alignmentOffset = m_columnPositions[0]; |
2229 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.size( ) - 1]; | 2316 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.size( ) - 1]; |
2230 return rightGridEdgePosition + alignmentOffset - coordinate; | 2317 return rightGridEdgePosition + alignmentOffset - coordinate; |
2231 } | 2318 } |
2232 | 2319 |
2233 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const | 2320 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const |
2234 { | 2321 { |
2322 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData); | |
2235 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); | 2323 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData); |
2236 // We stored m_columnPosition's data ignoring the direction, hence we might need now | 2324 // We stored m_columnPosition's data ignoring the direction, hence we might need now |
2237 // to translate positions from RTL to LTR, as it's more convenient for paint ing. | 2325 // to translate positions from RTL to LTR, as it's more convenient for paint ing. |
2238 if (!style()->isLeftToRightDirection()) | 2326 if (!style()->isLeftToRightDirection()) |
2239 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - child.logicalWid th(); | 2327 rowAxisOffset = translateRTLCoordinate(rowAxisOffset) - child.logicalWid th(); |
2240 | 2328 |
2241 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child, sizingData )); | 2329 // "In the positioning phase [...] calculations are performed according to t he writing mode |
2330 // of the containing block of the box establishing the orthogonal flow." How ever, the | |
2331 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's | |
2332 // logical position, which will only take into account the child's writing-m ode. | |
2333 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset); | |
2334 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | |
2242 } | 2335 } |
2243 | 2336 |
2244 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2337 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2245 { | 2338 { |
2246 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2339 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2247 } | 2340 } |
2248 | 2341 |
2249 } // namespace blink | 2342 } // namespace blink |
OLD | NEW |