Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.cpp

Issue 815833005: [css-grid] Handle min-content/max-content with orthogonal flows (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: New approach (Step3) - Assumed row track's breadth for intrinsic size computation. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 size_t m_columnIndex; 225 size_t m_columnIndex;
226 size_t m_childIndex; 226 size_t m_childIndex;
227 }; 227 };
228 228
229 struct LayoutGrid::GridSizingData { 229 struct LayoutGrid::GridSizingData {
230 WTF_MAKE_NONCOPYABLE(GridSizingData); 230 WTF_MAKE_NONCOPYABLE(GridSizingData);
231 STACK_ALLOCATED(); 231 STACK_ALLOCATED();
232 public: 232 public:
233 GridSizingData(size_t gridColumnCount, size_t gridRowCount) 233 GridSizingData(size_t gridColumnCount, size_t gridRowCount)
234 : columnTracks(gridColumnCount) 234 : columnTracks(gridColumnCount)
235 , rowTracks(gridRowCount) 235 , rowTracks(0)
236 { 236 {
237 } 237 }
238 238
239 Vector<GridTrack> columnTracks; 239 Vector<GridTrack> columnTracks;
240 Vector<GridTrack> rowTracks; 240 Vector<GridTrack> rowTracks;
241 Vector<size_t> contentSizedTracksIndex; 241 Vector<size_t> contentSizedTracksIndex;
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;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 352
353 updateLogicalWidth(); 353 updateLogicalWidth();
354 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), -1) == -1; 354 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), -1) == -1;
355 355
356 TextAutosizer::LayoutScope textAutosizerLayoutScope(this); 356 TextAutosizer::LayoutScope textAutosizerLayoutScope(this);
357 357
358 placeItemsOnGrid(); 358 placeItemsOnGrid();
359 359
360 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 360 GridSizingData sizingData(gridColumnCount(), gridRowCount());
361 361
362 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns.
362 // At this point the logical width is always definite as the above call to updateLogicalWidth() 363 // At this point the logical width is always definite as the above call to updateLogicalWidth()
363 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code 364 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
364 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve 365 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
365 // heights properly (like for positioned items for example). 366 // heights properly (like for positioned items for example).
366 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); 367 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
368 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns);
367 369
370 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the
371 // grid column sizes calculated in the previous step.
368 if (logicalHeightWasIndefinite) 372 if (logicalHeightWasIndefinite)
369 computeIntrinsicLogicalHeight(sizingData); 373 computeIntrinsicLogicalHeight(sizingData);
370 else 374 else
371 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); 375 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding));
372 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight()); 376 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight());
373 377
374 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 378 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
375 updateLogicalHeight(); 379 updateLogicalHeight();
376 380
377 // The above call might have changed the grid's logical height depending on min|max height restrictions. 381 // The above call might have changed the grid's logical height depending on min|max height restrictions.
378 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). 382 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes).
379 if (logicalHeightWasIndefinite) 383 if (logicalHeightWasIndefinite)
380 computeTrackSizesForDirection(ForRows, sizingData, logicalHeight()); 384 computeTrackSizesForDirection(ForRows, sizingData, logicalHeight());
381 385
382 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. 386 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though.
383 if (hasLineIfEmpty()) 387 if (hasLineIfEmpty())
384 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); 388 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine()));
385 389
390 // 3- If the min-content contribution of any grid items have changed bas ed on the row
391 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content
392 // contribution (once only).
393 // TODO (lajava): is enough just verifying whether there are any orthogo nal item ?
394 // TODO (lajava): Could we find better ways to fulfill such spec stateme nt ?
395 // TODO (lajava): Could we avoid iterating over all the grid items ?"
396 // TODO (lajava): Why we dont need to repeat row tracks sizing as spec s uggests (I was unable to find any test case needing so) ?"
svillar 2015/12/01 12:43:14 We need to do that for example if we have two item
397 if (hasAnyOrthogonalChild()) {
398 // In orthogonal flow cases column tracks size is determined based o n the computed
399 // row track sizes, hence we need to repeat computeUsedBreadthOfGrid Tracks for columns.
400 computeTrackSizesForDirection(ForColumns, sizingData, availableSpace ForColumns);
401 }
402
svillar 2015/12/01 12:43:14 This should be placed before the if (hasLineIfEmpt
jfernandez 2015/12/01 15:13:38 Acknowledged.
386 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); 403 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData);
387 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); 404 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData);
388 405
389 layoutGridItems(sizingData); 406 layoutGridItems(sizingData);
390 407
391 if (size() != previousSize) 408 if (size() != previousSize)
392 relayoutChildren = true; 409 relayoutChildren = true;
393 410
394 layoutPositionedObjects(relayoutChildren || isDocumentElement()); 411 layoutPositionedObjects(relayoutChildren || isDocumentElement());
395 412
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 487 }
471 488
472 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization, AvailableSpaceType availableSpaceType) 489 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& baseSizesWithoutMaximization, Layout Unit& growthLimitsWithoutMaximization, AvailableSpaceType availableSpaceType)
473 { 490 {
474 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction); 491 LayoutUnit& freeSpace = sizingData.freeSpaceForDirection(direction);
475 const LayoutUnit initialFreeSpace = freeSpace; 492 const LayoutUnit initialFreeSpace = freeSpace;
476 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 493 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
477 Vector<size_t> flexibleSizedTracksIndex; 494 Vector<size_t> flexibleSizedTracksIndex;
478 sizingData.contentSizedTracksIndex.shrink(0); 495 sizingData.contentSizedTracksIndex.shrink(0);
479 496
497 if (direction == ForRows && tracks.size() == 0)
498 tracks.grow(gridRowCount());
cbiesinger 2015/11/26 02:26:16 why is this now needed, when it wasn't before?
jfernandez 2015/11/26 08:58:27 Since I needed a way to detect we are using rowTra
499
480 const LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace); 500 const LayoutUnit maxSize = std::max(LayoutUnit(), initialFreeSpace);
481 // 1. Initialize per Grid track variables. 501 // 1. Initialize per Grid track variables.
482 for (size_t i = 0; i < tracks.size(); ++i) { 502 for (size_t i = 0; i < tracks.size(); ++i) {
483 GridTrack& track = tracks[i]; 503 GridTrack& track = tracks[i];
484 GridTrackSize trackSize = gridTrackSize(direction, i); 504 GridTrackSize trackSize = gridTrackSize(direction, i);
485 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); 505 const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
486 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); 506 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth();
487 507
488 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize )); 508 track.setBaseSize(computeUsedBreadthOfMinLength(minTrackBreadth, maxSize ));
489 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize)); 509 track.setGrowthLimit(computeUsedBreadthOfMaxLength(maxTrackBreadth, trac k.baseSize(), maxSize));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 563
544 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { 564 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
545 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); 565 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] );
546 while (LayoutBox* gridItem = iterator.nextGridItem()) { 566 while (LayoutBox* gridItem = iterator.nextGridItem()) {
547 const GridSpan span = cachedGridSpan(*gridItem, direction); 567 const GridSpan span = cachedGridSpan(*gridItem, direction);
548 568
549 // Do not include already processed items. 569 // Do not include already processed items.
550 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz edTracksIndex[i - 1]) 570 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz edTracksIndex[i - 1])
551 continue; 571 continue;
552 572
553 flexFraction = std::max(flexFraction, findFlexFactorUnitSize(tra cks, span, direction, maxContentForChild(*gridItem, direction, sizingData.column Tracks))); 573 flexFraction = std::max(flexFraction, findFlexFactorUnitSize(tra cks, span, direction, maxContentForChild(*gridItem, direction, sizingData)));
554 } 574 }
555 } 575 }
556 } 576 }
557 577
558 for (const auto& trackIndex : flexibleSizedTracksIndex) { 578 for (const auto& trackIndex : flexibleSizedTracksIndex) {
559 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); 579 GridTrackSize trackSize = gridTrackSize(direction, trackIndex);
560 580
561 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize(); 581 LayoutUnit oldBaseSize = tracks[trackIndex].baseSize();
562 LayoutUnit baseSize = std::max<LayoutUnit>(oldBaseSize, flexFraction * t rackSize.maxTrackBreadth().flex()); 582 LayoutUnit baseSize = std::max<LayoutUnit>(oldBaseSize, flexFraction * t rackSize.maxTrackBreadth().flex());
563 if (LayoutUnit increment = baseSize - oldBaseSize) { 583 if (LayoutUnit increment = baseSize - oldBaseSize) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 flexFactorSum += trackSize.maxTrackBreadth().flex(); 661 flexFactorSum += trackSize.maxTrackBreadth().flex();
642 } 662 }
643 } 663 }
644 664
645 // The function is not called if we don't have <flex> grid tracks 665 // The function is not called if we don't have <flex> grid tracks
646 ASSERT(!flexibleTracksIndexes.isEmpty()); 666 ASSERT(!flexibleTracksIndexes.isEmpty());
647 667
648 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes); 668 return computeFlexFactorUnitSize(tracks, direction, flexFactorSum, leftOverS pace, flexibleTracksIndexes);
649 } 669 }
650 670
671 bool LayoutGrid::hasAnyOrthogonalChild() const
672 {
673 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
674 if (child->isHorizontalWritingMode() != isHorizontalWritingMode())
675 return true;
676 }
677 return false;
678 }
679
651 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t 680 bool LayoutGrid::hasDefiniteLogicalSize(GridTrackSizingDirection direction) cons t
652 { 681 {
653 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth(); 682 return (direction == ForRows) ? hasDefiniteLogicalHeight() : hasDefiniteLogi calWidth();
654 } 683 }
655 684
685 LayoutUnit LayoutGrid::overrideContainingBlockBreadthForChild(const LayoutBox& c hild, GridTrackSizingDirection direction)
686 {
svillar 2015/12/01 12:43:14 I'd ASSERT() on hasOverrideContainingBlockXXX() an
jfernandez 2015/12/01 15:13:39 I really wanted to return 0 (actually, it was the
687 if (direction == ForRows)
688 return child.hasOverrideContainingBlockLogicalHeight() ? child.overrideC ontainingBlockContentLogicalHeight() : LayoutUnit();
689 return child.hasOverrideContainingBlockLogicalWidth() ? child.overrideContai ningBlockContentLogicalWidth() : LayoutUnit();
690 }
691
692 void LayoutGrid::setOverrideContainingBlockBreadthForChild(LayoutBox& child, Gri dTrackSizingDirection direction, LayoutUnit breadth)
693 {
694 if (direction == ForRows)
695 child.setOverrideContainingBlockContentLogicalHeight(breadth);
696 else
697 child.setOverrideContainingBlockContentLogicalWidth(breadth);
698 }
699
656 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const 700 GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const
657 { 701 {
658 bool isForColumns = direction == ForColumns; 702 bool isForColumns = direction == ForColumns;
659 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows(); 703 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows();
660 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ? style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i]; 704 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ? style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i];
661 705
662 GridLength minTrackBreadth = trackSize.minTrackBreadth(); 706 GridLength minTrackBreadth = trackSize.minTrackBreadth();
663 GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); 707 GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
664 708
665 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto> 709 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>
666 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { 710 if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) {
667 if (!hasDefiniteLogicalSize(direction)) { 711 if (!hasDefiniteLogicalSize(direction)) {
668 if (minTrackBreadth.hasPercentage()) 712 if (minTrackBreadth.hasPercentage())
669 minTrackBreadth = Length(Auto); 713 minTrackBreadth = Length(Auto);
670 if (maxTrackBreadth.hasPercentage()) 714 if (maxTrackBreadth.hasPercentage())
671 maxTrackBreadth = Length(Auto); 715 maxTrackBreadth = Length(Auto);
672 } 716 }
673 } 717 }
674 718
675 return GridTrackSize(minTrackBreadth, maxTrackBreadth); 719 return GridTrackSize(minTrackBreadth, maxTrackBreadth);
676 } 720 }
677 721
678 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, Vector<GridTrack> & columnTracks) 722 LayoutUnit LayoutGrid::logicalHeightForChild(LayoutBox& child, const GridSizingD ata& sizingData)
679 { 723 {
724 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
svillar 2015/12/01 12:43:14 This is repeated so many times that we should have
jfernandez 2015/12/01 15:13:39 Acknowledged.
725 GridTrackSizingDirection childInlineDirection = hasOrthogonalWritingMode ? F orRows : ForColumns;
680 SubtreeLayoutScope layoutScope(child); 726 SubtreeLayoutScope layoutScope(child);
681 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth () : LayoutUnit(); 727 // Child's min-content contribution depends on the container's size along th e child's inline-axis.
682 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); 728 LayoutUnit oldGridAreaBreadth = overrideContainingBlockBreadthForChild(child , childInlineDirection);
683 if (child.hasRelativeLogicalHeight() || oldOverrideContainingBlockContentLog icalWidth != overrideContainingBlockContentLogicalWidth) { 729 LayoutUnit gridAreaBreadth = gridAreaBreadthForChild(child, childInlineDirec tion, sizingData);
730 if (child.hasRelativeLogicalHeight() || oldGridAreaBreadth != gridAreaBreadt h) {
684 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged ); 731 layoutScope.setNeedsLayout(&child, LayoutInvalidationReason::GridChanged );
685 } 732 }
686 733
687 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight(); 734 bool hasOverrideHeight = child.hasOverrideLogicalContentHeight();
688 // We need to clear the stretched height to properly compute logical height during layout. 735 // We need to clear the stretched height to properly compute logical height during layout.
689 if (hasOverrideHeight && child.needsLayout()) 736 if (hasOverrideHeight && child.needsLayout())
690 child.clearOverrideLogicalContentHeight(); 737 child.clearOverrideLogicalContentHeight();
691 738
692 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockC ontentLogicalWidth); 739 setOverrideContainingBlockBreadthForChild(child, childInlineDirection, gridA reaBreadth);
693 // If |child| has a relative logical height, we shouldn't let it override it s intrinsic height, which is 740 // If |child| has a relative logical height, we shouldn't let it override it s intrinsic height, which is
694 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). 741 // what we are interested in here. Thus we need to set the block-axis overri de breadth to -1 (no possible resolution).
695 if (child.hasRelativeLogicalHeight()) 742 if (child.hasRelativeLogicalHeight())
696 child.setOverrideContainingBlockContentLogicalHeight(-1); 743 setOverrideContainingBlockBreadthForChild(child, childInlineDirection == ForColumns ? ForRows : ForColumns, -1);
697 child.layoutIfNeeded(); 744 child.layoutIfNeeded();
698 // If the child was stretched we should use its intrinsic height. 745 // If the child was stretched we should use its intrinsic height.
699 return (hasOverrideHeight ? childIntrinsicHeight(child) : child.logicalHeigh t()) + child.marginLogicalHeight(); 746 return (hasOverrideHeight ? childIntrinsicHeight(child) : child.logicalHeigh t()) + child.marginLogicalHeight();
700 } 747 }
701 748
702 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, Vector<GridTrack>& columnTracks) 749 static inline GridTrackSizingDirection flowAwareDirection(bool hasOrthogonalWrit ingMode, GridTrackSizingDirection direction)
750 {
751 if (hasOrthogonalWritingMode)
752 return direction == ForColumns ? ForRows : ForColumns;
753 return direction;
754 }
svillar 2015/12/01 12:43:14 With the private method I mentioned above we could
jfernandez 2015/12/01 15:13:39 We would change an static inline method for a clas
755
756 LayoutUnit LayoutGrid::minSizeForChild(LayoutBox& child, GridTrackSizingDirectio n direction, const GridSizingData& sizingData)
703 { 757 {
704 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 758 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
705 // TODO(svillar): Properly support orthogonal writing mode. 759 const Length& childMinSize = flowAwareDirection(hasOrthogonalWritingMode, di rection) == ForColumns ? child.style()->logicalMinWidth() : child.style()->logic alMinHeight();
706 if (hasOrthogonalWritingMode)
707 return LayoutUnit();
708
709 const Length& childMinSize = direction == ForColumns ? child.style()->logica lMinWidth() : child.style()->logicalMinHeight();
710 if (childMinSize.isAuto()) { 760 if (childMinSize.isAuto()) {
711 // TODO(svillar): Implement intrinsic aspect ratio support (transferred size in specs). 761 // TODO(svillar): Implement intrinsic aspect ratio support (transferred size in specs).
712 return minContentForChild(child, direction, columnTracks); 762 return minContentForChild(child, direction, sizingData);
713 } 763 }
714 764
715 if (direction == ForColumns) 765 if (flowAwareDirection(hasOrthogonalWritingMode, direction) == ForColumns)
716 return child.computeLogicalWidthUsing(MinSize, childMinSize, contentLogi calWidth(), this); 766 return child.computeLogicalWidthUsing(MinSize, childMinSize, contentLogi calWidth(), this);
717 767
718 return child.computeContentLogicalHeight(MinSize, childMinSize, child.logica lHeight()) + child.scrollbarLogicalHeight(); 768 return child.computeContentLogicalHeight(MinSize, childMinSize, child.logica lHeight()) + child.scrollbarLogicalHeight();
719 } 769 }
720 770
721 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& columnTracks) 771 LayoutUnit LayoutGrid::minContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, const GridSizingData& sizingData)
722 { 772 {
723 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 773 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
724 // FIXME: Properly support orthogonal writing mode. 774 if (flowAwareDirection(hasOrthogonalWritingMode, direction) == ForColumns) {
725 if (hasOrthogonalWritingMode)
726 return 0;
727
728 if (direction == ForColumns) {
729 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is 775 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
730 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). 776 // what we are interested in here. Thus we need to set the inline-axis o verride breadth to -1 (no possible resolution).
777 GridTrackSizingDirection childInlineDirection = hasOrthogonalWritingMode ? ForRows : ForColumns;
731 if (child.hasRelativeLogicalWidth()) 778 if (child.hasRelativeLogicalWidth())
732 child.setOverrideContainingBlockContentLogicalWidth(-1); 779 setOverrideContainingBlockBreadthForChild(child, childInlineDirectio n, -1);
733 780
734 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. 781 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width.
735 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 782 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
736 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); 783 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child);
737 } 784 }
738 785
739 return logicalHeightForChild(child, columnTracks); 786 return logicalHeightForChild(child, sizingData);
740 } 787 }
741 788
742 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, Vector<GridTrack>& columnTracks) 789 LayoutUnit LayoutGrid::maxContentForChild(LayoutBox& child, GridTrackSizingDirec tion direction, const GridSizingData& sizingData)
743 { 790 {
744 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 791 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
745 // FIXME: Properly support orthogonal writing mode. 792 if (flowAwareDirection(hasOrthogonalWritingMode, direction) == ForColumns) {
746 if (hasOrthogonalWritingMode)
747 return LayoutUnit();
748
749 if (direction == ForColumns) {
750 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is 793 // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
751 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution). 794 // what we are interested in here. Thus we need to set the override logi cal width to -1 (no possible resolution).
795 GridTrackSizingDirection childInlineDirection = hasOrthogonalWritingMode ? ForRows : ForColumns;
752 if (child.hasRelativeLogicalWidth()) 796 if (child.hasRelativeLogicalWidth())
753 child.setOverrideContainingBlockContentLogicalWidth(-1); 797 setOverrideContainingBlockBreadthForChild(child, childInlineDirectio n, -1);
754 798
755 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width. 799 // FIXME: It's unclear if we should return the intrinsic width or the pr eferred width.
756 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 800 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
757 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child); 801 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthFor Child(child);
758 } 802 }
759 803
760 return logicalHeightForChild(child, columnTracks); 804 return logicalHeightForChild(child, sizingData);
761 } 805 }
762 806
763 // We're basically using a class instead of a std::pair because of accessing gri dItem() or gridSpan() is much more 807 // We're basically using a class instead of a std::pair because of accessing gri dItem() or gridSpan() is much more
764 // self-explanatory that using .first or .second members in the pair. Having a s td::pair<LayoutBox*, size_t> 808 // self-explanatory that using .first or .second members in the pair. Having a s td::pair<LayoutBox*, size_t>
765 // does not work either because we still need the GridSpan so we'd have to add a n extra hash lookup for each item 809 // does not work either because we still need the GridSpan so we'd have to add a n extra hash lookup for each item
766 // at the beginning of LayoutGrid::resolveContentBasedTrackSizingFunctionsForIte ms(). 810 // at the beginning of LayoutGrid::resolveContentBasedTrackSizingFunctionsForIte ms().
767 class GridItemWithSpan { 811 class GridItemWithSpan {
768 public: 812 public:
769 GridItemWithSpan(LayoutBox& gridItem, const GridSpan& gridSpan) 813 GridItemWithSpan(LayoutBox& gridItem, const GridSpan& gridSpan)
770 : m_gridItem(&gridItem) 814 : m_gridItem(&gridItem)
(...skipping 26 matching lines...) Expand all
797 { 841 {
798 sizingData.itemsSortedByIncreasingSpan.shrink(0); 842 sizingData.itemsSortedByIncreasingSpan.shrink(0);
799 HashSet<LayoutBox*> itemsSet; 843 HashSet<LayoutBox*> itemsSet;
800 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 844 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
801 GridIterator iterator(m_grid, direction, trackIndex); 845 GridIterator iterator(m_grid, direction, trackIndex);
802 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; 846 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex];
803 while (LayoutBox* gridItem = iterator.nextGridItem()) { 847 while (LayoutBox* gridItem = iterator.nextGridItem()) {
804 if (itemsSet.add(gridItem).isNewEntry) { 848 if (itemsSet.add(gridItem).isNewEntry) {
805 const GridSpan& span = cachedGridSpan(*gridItem, direction); 849 const GridSpan& span = cachedGridSpan(*gridItem, direction);
806 if (span.integerSpan() == 1) { 850 if (span.integerSpan() == 1) {
807 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, span, *gridItem, track, sizingData.columnTracks); 851 resolveContentBasedTrackSizingFunctionsForNonSpanningItems(d irection, span, *gridItem, track, sizingData);
808 } else if (!spanningItemCrossesFlexibleSizedTracks(span, directi on)) { 852 } else if (!spanningItemCrossesFlexibleSizedTracks(span, directi on)) {
809 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, span)); 853 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSp an(*gridItem, span));
810 } 854 }
811 } 855 }
812 } 856 }
813 } 857 }
814 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end()); 858 std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSo rtedByIncreasingSpan.end());
815 859
816 auto it = sizingData.itemsSortedByIncreasingSpan.begin(); 860 auto it = sizingData.itemsSortedByIncreasingSpan.begin();
817 auto end = sizingData.itemsSortedByIncreasingSpan.end(); 861 auto end = sizingData.itemsSortedByIncreasingSpan.end();
818 while (it != end) { 862 while (it != end) {
819 GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) }; 863 GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) };
820 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange); 864 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMinimums >(direction, sizingData, spanGroupRange);
821 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange); 865 resolveContentBasedTrackSizingFunctionsForItems<ResolveContentBasedMinim ums>(direction, sizingData, spanGroupRange);
822 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange); 866 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMinimum s>(direction, sizingData, spanGroupRange);
823 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange); 867 resolveContentBasedTrackSizingFunctionsForItems<ResolveIntrinsicMaximums >(direction, sizingData, spanGroupRange);
824 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange); 868 resolveContentBasedTrackSizingFunctionsForItems<ResolveMaxContentMaximum s>(direction, sizingData, spanGroupRange);
825 it = spanGroupRange.rangeEnd; 869 it = spanGroupRange.rangeEnd;
826 } 870 }
827 871
828 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 872 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
829 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex]; 873 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackIndex] : sizingData.rowTracks[trackIndex];
830 if (track.growthLimitIsInfinite()) 874 if (track.growthLimitIsInfinite())
831 track.setGrowthLimit(track.baseSize()); 875 track.setGrowthLimit(track.baseSize());
832 } 876 }
833 } 877 }
834 878
835 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, Vector<GridTrack>& columnTracks) 879 void LayoutGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(Grid TrackSizingDirection direction, const GridSpan& span, LayoutBox& gridItem, GridT rack& track, const GridSizingData& sizingData)
836 { 880 {
837 const GridResolvedPosition trackPosition = span.resolvedInitialPosition; 881 const GridResolvedPosition trackPosition = span.resolvedInitialPosition;
838 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()); 882 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt());
839 883
840 if (trackSize.hasMinContentMinTrackBreadth()) 884 if (trackSize.hasMinContentMinTrackBreadth())
841 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, columnTracks))); 885 track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem , direction, sizingData)));
842 else if (trackSize.hasMaxContentMinTrackBreadth()) 886 else if (trackSize.hasMaxContentMinTrackBreadth())
843 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, columnTracks))); 887 track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem , direction, sizingData)));
844 else if (trackSize.hasAutoMinTrackBreadth()) 888 else if (trackSize.hasAutoMinTrackBreadth())
845 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, columnTracks))); 889 track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, d irection, sizingData)));
846 890
847 if (trackSize.hasMinContentMaxTrackBreadth()) 891 if (trackSize.hasMinContentMaxTrackBreadth())
848 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, columnTracks))); 892 track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gr idItem, direction, sizingData)));
849 else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) 893 else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth())
850 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, columnTracks))); 894 track.setGrowthLimit(std::max(track.growthLimit(), maxContentForChild(gr idItem, direction, sizingData)));
851 } 895 }
852 896
853 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction) 897 static const LayoutUnit& trackSizeForTrackSizeComputationPhase(TrackSizeComputat ionPhase phase, const GridTrack& track, TrackSizeRestriction restriction)
854 { 898 {
855 switch (phase) { 899 switch (phase) {
856 case ResolveIntrinsicMinimums: 900 case ResolveIntrinsicMinimums:
857 case ResolveContentBasedMinimums: 901 case ResolveContentBasedMinimums:
858 case ResolveMaxContentMinimums: 902 case ResolveMaxContentMinimums:
859 case MaximizeTracks: 903 case MaximizeTracks:
860 return track.baseSize(); 904 return track.baseSize();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 track.setGrowthLimit(track.plannedSize()); 992 track.setGrowthLimit(track.plannedSize());
949 return; 993 return;
950 case MaximizeTracks: 994 case MaximizeTracks:
951 ASSERT_NOT_REACHED(); 995 ASSERT_NOT_REACHED();
952 return; 996 return;
953 } 997 }
954 998
955 ASSERT_NOT_REACHED(); 999 ASSERT_NOT_REACHED();
956 } 1000 }
957 1001
958 LayoutUnit LayoutGrid::currentItemSizeForTrackSizeComputationPhase(TrackSizeComp utationPhase phase, LayoutBox& gridItem, GridTrackSizingDirection direction, Vec tor<GridTrack>& columnTracks) 1002 LayoutUnit LayoutGrid::currentItemSizeForTrackSizeComputationPhase(TrackSizeComp utationPhase phase, LayoutBox& gridItem, GridTrackSizingDirection direction, con st GridSizingData& sizingData)
959 { 1003 {
960 switch (phase) { 1004 switch (phase) {
961 case ResolveIntrinsicMinimums: 1005 case ResolveIntrinsicMinimums:
962 return minSizeForChild(gridItem, direction, columnTracks); 1006 return minSizeForChild(gridItem, direction, sizingData);
963 case ResolveContentBasedMinimums: 1007 case ResolveContentBasedMinimums:
964 case ResolveIntrinsicMaximums: 1008 case ResolveIntrinsicMaximums:
965 return minContentForChild(gridItem, direction, columnTracks); 1009 return minContentForChild(gridItem, direction, sizingData);
966 case ResolveMaxContentMinimums: 1010 case ResolveMaxContentMinimums:
967 case ResolveMaxContentMaximums: 1011 case ResolveMaxContentMaximums:
968 return maxContentForChild(gridItem, direction, columnTracks); 1012 return maxContentForChild(gridItem, direction, sizingData);
969 case MaximizeTracks: 1013 case MaximizeTracks:
970 ASSERT_NOT_REACHED(); 1014 ASSERT_NOT_REACHED();
971 return 0; 1015 return 0;
972 } 1016 }
973 1017
974 ASSERT_NOT_REACHED(); 1018 ASSERT_NOT_REACHED();
975 return 0; 1019 return 0;
976 } 1020 }
977 1021
978 template <TrackSizeComputationPhase phase> 1022 template <TrackSizeComputationPhase phase>
(...skipping 24 matching lines...) Expand all
1003 1047
1004 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize)) 1048 if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(ph ase, trackSize))
1005 sizingData.growBeyondGrowthLimitsTracks.append(&track); 1049 sizingData.growBeyondGrowthLimitsTracks.append(&track);
1006 } 1050 }
1007 1051
1008 if (sizingData.filteredTracks.isEmpty()) 1052 if (sizingData.filteredTracks.isEmpty())
1009 continue; 1053 continue;
1010 1054
1011 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan()); 1055 spanningTracksSize += guttersSize(direction, itemSpan.integerSpan());
1012 1056
1013 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTr acksSize; 1057 LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phas e, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize;
1014 extraSpace = std::max<LayoutUnit>(extraSpace, 0); 1058 extraSpace = std::max<LayoutUnit>(extraSpace, 0);
1015 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks; 1059 auto& tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimits Tracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimits Tracks;
1016 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace); 1060 distributeSpaceToTracks<phase>(sizingData.filteredTracks, &tracksToGrowB eyondGrowthLimits, sizingData, extraSpace);
1017 } 1061 }
1018 1062
1019 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) { 1063 for (const auto& trackIndex : sizingData.contentSizedTracksIndex) {
1020 GridTrack& track = tracks[trackIndex]; 1064 GridTrack& track = tracks[trackIndex];
1021 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track); 1065 markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
1022 updateTrackSizeForTrackSizeComputationPhase(phase, track); 1066 updateTrackSizeForTrackSizeComputationPhase(phase, track);
1023 } 1067 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 ASSERT(m_gridItemCoordinate.contains(&gridItem)); 1565 ASSERT(m_gridItemCoordinate.contains(&gridItem));
1522 return m_gridItemCoordinate.get(&gridItem); 1566 return m_gridItemCoordinate.get(&gridItem);
1523 } 1567 }
1524 1568
1525 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const 1569 GridSpan LayoutGrid::cachedGridSpan(const LayoutBox& gridItem, GridTrackSizingDi rection direction) const
1526 { 1570 {
1527 GridCoordinate coordinate = cachedGridCoordinate(gridItem); 1571 GridCoordinate coordinate = cachedGridCoordinate(gridItem);
1528 return direction == ForColumns ? coordinate.columns : coordinate.rows; 1572 return direction == ForColumns ? coordinate.columns : coordinate.rows;
1529 } 1573 }
1530 1574
1531 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const Vector<GridTrack>& tracks) const 1575 bool LayoutGrid::gridLengthIsIndefinite(const GridLength& length, GridTrackSizin gDirection direction) const
1532 { 1576 {
1577 return length.isContentSized() || length.isFlex() || (length.hasPercentage() && !hasDefiniteLogicalSize(direction));
1578 }
svillar 2015/12/01 12:43:14 I panicked when I saw this one :). We should not u
jfernandez 2015/12/01 15:13:39 Umm, can you confirm that checking that out is eno
1579
1580 LayoutUnit LayoutGrid::assumedRowsBreadthForOrthogonalChild(const LayoutBox& chi ld) const
1581 {
1582 ASSERT(child.isHorizontalWritingMode() != isHorizontalWritingMode());
1583 const GridSpan& span = cachedGridSpan(child, ForRows);
1584 LayoutUnit gridAreaBreadth = 0;
1585 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) {
svillar 2015/12/01 12:43:14 Better do: for (auto trackPosition : span) since
jfernandez 2015/12/01 15:13:39 Acknowledged.
1586 const GridLength& maxTrackBreadth = gridTrackSize(ForRows, trackPosition .toInt()).maxTrackBreadth();
1587 if (gridLengthIsIndefinite(maxTrackBreadth, ForRows)) {
1588 gridAreaBreadth = child.maxPreferredLogicalWidth() + marginIntrinsic LogicalWidthForChild(child);
1589 break;
1590 }
1591 gridAreaBreadth += valueForLength(maxTrackBreadth.length(), 0);
1592 }
1593
1594 gridAreaBreadth += guttersSize(ForRows, span.integerSpan());
1595
1596 return gridAreaBreadth;
1597 }
1598
1599 LayoutUnit LayoutGrid::gridAreaBreadthForChild(const LayoutBox& child, GridTrack SizingDirection direction, const GridSizingData& sizingData) const
1600 {
1601 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1602 if (child.isHorizontalWritingMode() != isHorizontalWritingMode() && tracks.i sEmpty())
svillar 2015/12/01 12:43:14 Don't get why you need the isEmpty().
jfernandez 2015/12/01 15:13:39 I needed a way to detect whether row tracks were a
1603 return assumedRowsBreadthForOrthogonalChild(child);
1533 const GridSpan& span = cachedGridSpan(child, direction); 1604 const GridSpan& span = cachedGridSpan(child, direction);
1534 LayoutUnit gridAreaBreadth = 0; 1605 LayoutUnit gridAreaBreadth = 0;
1535 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition) 1606 for (GridSpan::iterator trackPosition = span.begin(); trackPosition != span. end(); ++trackPosition)
1536 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize(); 1607 gridAreaBreadth += tracks[trackPosition.toInt()].baseSize();
1537 1608
1538 gridAreaBreadth += guttersSize(direction, span.integerSpan()); 1609 gridAreaBreadth += guttersSize(direction, span.integerSpan());
1539 1610
1540 return gridAreaBreadth; 1611 return gridAreaBreadth;
1541 } 1612 }
1542 1613
(...skipping 19 matching lines...) Expand all
1562 // using these positions to compute them. 1633 // using these positions to compute them.
1563 1634
1564 unsigned numberOfTracks = sizingData.columnTracks.size(); 1635 unsigned numberOfTracks = sizingData.columnTracks.size();
1565 unsigned numberOfLines = numberOfTracks + 1; 1636 unsigned numberOfLines = numberOfTracks + 1;
1566 unsigned lastLine = numberOfLines - 1; 1637 unsigned lastLine = numberOfLines - 1;
1567 unsigned nextToLastLine = numberOfLines - 2; 1638 unsigned nextToLastLine = numberOfLines - 2;
1568 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(Fo rColumns, sizingData.freeSpaceForDirection(ForColumns), numberOfTracks); 1639 ContentAlignmentData offset = computeContentPositionAndDistributionOffset(Fo rColumns, sizingData.freeSpaceForDirection(ForColumns), numberOfTracks);
1569 LayoutUnit trackGap = guttersSize(ForColumns, 2); 1640 LayoutUnit trackGap = guttersSize(ForColumns, 2);
1570 m_columnPositions.resize(numberOfLines); 1641 m_columnPositions.resize(numberOfLines);
1571 m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset; 1642 m_columnPositions[0] = borderAndPaddingStart() + offset.positionOffset;
1572 for (unsigned i = 0; i < lastLine; ++i) 1643 for (unsigned i = 0; i < nextToLastLine; ++i)
cbiesinger 2015/11/26 02:26:16 Why this change now?
jfernandez 2015/11/26 08:58:27 I admit that this change is unrelated to the issue
1573 m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOff set + sizingData.columnTracks[i].baseSize() + trackGap; 1644 m_columnPositions[i + 1] = m_columnPositions[i] + offset.distributionOff set + sizingData.columnTracks[i].baseSize() + trackGap;
1574 m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData .columnTracks[nextToLastLine].baseSize(); 1645 m_columnPositions[lastLine] = m_columnPositions[nextToLastLine] + sizingData .columnTracks[nextToLastLine].baseSize();
1575 1646
1576 numberOfTracks = sizingData.rowTracks.size(); 1647 numberOfTracks = sizingData.rowTracks.size();
1577 numberOfLines = numberOfTracks + 1; 1648 numberOfLines = numberOfTracks + 1;
1578 lastLine = numberOfLines - 1; 1649 lastLine = numberOfLines - 1;
1579 nextToLastLine = numberOfLines - 2; 1650 nextToLastLine = numberOfLines - 2;
1580 offset = computeContentPositionAndDistributionOffset(ForRows, sizingData.fre eSpaceForDirection(ForRows), numberOfTracks); 1651 offset = computeContentPositionAndDistributionOffset(ForRows, sizingData.fre eSpaceForDirection(ForRows), numberOfTracks);
1581 trackGap = guttersSize(ForRows, 2); 1652 trackGap = guttersSize(ForRows, 2);
1582 m_rowPositions.resize(numberOfLines); 1653 m_rowPositions.resize(numberOfLines);
1583 m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset; 1654 m_rowPositions[0] = borderAndPaddingBefore() + offset.positionOffset;
1584 for (unsigned i = 0; i < lastLine; ++i) 1655 for (unsigned i = 0; i < nextToLastLine; ++i)
1585 m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset + sizingData.rowTracks[i].baseSize() + trackGap; 1656 m_rowPositions[i + 1] = m_rowPositions[i] + offset.distributionOffset + sizingData.rowTracks[i].baseSize() + trackGap;
1586 m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTr acks[nextToLastLine].baseSize(); 1657 m_rowPositions[lastLine] = m_rowPositions[nextToLastLine] + sizingData.rowTr acks[nextToLastLine].baseSize();
1587 } 1658 }
1588 1659
1589 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth) 1660 static LayoutUnit computeOverflowAlignmentOffset(OverflowAlignment overflow, Lay outUnit trackBreadth, LayoutUnit childBreadth)
1590 { 1661 {
1591 LayoutUnit offset = trackBreadth - childBreadth; 1662 LayoutUnit offset = trackBreadth - childBreadth;
1592 switch (overflow) { 1663 switch (overflow) {
1593 case OverflowAlignmentSafe: 1664 case OverflowAlignmentSafe:
1594 // If overflow is 'safe', we have to make sure we don't overflow the 'st art' 1665 // If overflow is 'safe', we have to make sure we don't overflow the 'st art'
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 case ContentPositionAuto: 2097 case ContentPositionAuto:
2027 break; 2098 break;
2028 } 2099 }
2029 2100
2030 ASSERT_NOT_REACHED(); 2101 ASSERT_NOT_REACHED();
2031 return {0, 0}; 2102 return {0, 0};
2032 } 2103 }
2033 2104
2034 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const 2105 LayoutPoint LayoutGrid::findChildLogicalPosition(const LayoutBox& child, GridSiz ingData& sizingData) const
2035 { 2106 {
2107 LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child);
2036 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child); 2108 LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child);
2037 // We stored m_columnPosition s's data ignoring the direction, hence we migh t need now 2109 // We stored m_columnPositions's data ignoring the direction, hence we might need now
2038 // to translate positions from RTL to LTR, as it's more convenient for paint ing. 2110 // to translate positions from RTL to LTR, as it's more convenient for paint ing.
2039 if (!style()->isLeftToRightDirection()) { 2111 if (!style()->isLeftToRightDirection()) {
2040 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt(); 2112 LayoutUnit alignmentOffset = m_columnPositions[0] - borderAndPaddingSta rt();
2041 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft(); 2113 LayoutUnit rightGridEdgePosition = m_columnPositions[m_columnPositions.s ize() - 1] + alignmentOffset + borderAndPaddingLogicalLeft();
2042 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth()); 2114 rowAxisOffset = rightGridEdgePosition - (rowAxisOffset + child.logicalWi dth());
2043 } 2115 }
2044 2116
2045 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); 2117 // "In the positioning phase [...] calculations are performed according to t he writing mode
2118 // of the containing block of the box establishing the orthogonal flow." How ever, the
2119 // resulting LayoutPoint will be used in 'setLogicalPosition' in order to se t the child's
2120 // logical position, which will only take into account the child's writing-m ode.
2121 LayoutPoint childLocation(rowAxisOffset, columnAxisOffset);
2122 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
2123 return hasOrthogonalWritingMode ? childLocation.transposedPoint() : childLoc ation;
2046 } 2124 }
2047 2125
2048 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2126 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2049 { 2127 {
2050 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2128 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2051 } 2129 }
2052 2130
2053 } // namespace blink 2131 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698