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

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

Issue 2339983002: [css-grid] Remove the 2x computation of row sizes w/ indefinite heights (Closed)
Patch Set: Now with perf test Created 4 years, 3 months 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/PerformanceTests/Layout/nested-grid.html ('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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 SubtreeLayoutScope layoutScope(*this); 446 SubtreeLayoutScope layoutScope(*this);
447 447
448 { 448 {
449 // LayoutState needs this deliberate scope to pop before updating scroll information (which 449 // LayoutState needs this deliberate scope to pop before updating scroll information (which
450 // may trigger relayout). 450 // may trigger relayout).
451 LayoutState state(*this, locationOffset()); 451 LayoutState state(*this, locationOffset());
452 452
453 LayoutSize previousSize = size(); 453 LayoutSize previousSize = size();
454 454
455 updateLogicalWidth(); 455 updateLogicalWidth();
456 bool logicalHeightWasIndefinite = !hasDefiniteLogicalHeight();
457 456
458 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); 457 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
459 458
460 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated 459 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated
461 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) 460 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812)
462 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing)) 461 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing))
463 dirtyGrid(); 462 dirtyGrid();
464 placeItemsOnGrid(TrackSizing); 463 placeItemsOnGrid(TrackSizing);
465 464
466 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 465 GridSizingData sizingData(gridColumnCount(), gridRowCount());
467 466
468 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 467 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns.
469 // At this point the logical width is always definite as the above call to updateLogicalWidth() 468 // At this point the logical width is always definite as the above call to updateLogicalWidth()
470 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code 469 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
471 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve 470 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
472 // heights properly (like for positioned items for example). 471 // heights properly (like for positioned items for example).
473 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 472 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
474 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); 473 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns);
475 474
476 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the 475 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the
477 // grid column sizes calculated in the previous step. 476 // grid column sizes calculated in the previous step.
478 if (logicalHeightWasIndefinite) 477 if (!hasDefiniteLogicalHeight())
479 computeIntrinsicLogicalHeight(sizingData); 478 computeIntrinsicLogicalHeight(sizingData);
480 else 479 else
481 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); 480 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding));
482 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); 481 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight());
483 482
484 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 483 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
485 updateLogicalHeight(); 484 updateLogicalHeight();
486 485
487 // The above call might have changed the grid's logical height depending on min|max height restrictions.
488 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes).
489 LayoutUnit availableSpaceForRows = contentLogicalHeight();
490 if (logicalHeightWasIndefinite)
491 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows);
492
493 // 3- If the min-content contribution of any grid items have changed bas ed on the row 486 // 3- If the min-content contribution of any grid items have changed bas ed on the row
494 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content 487 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content
495 // contribution (once only). 488 // contribution (once only).
496 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); 489 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, content LogicalHeight());
497 490
498 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. 491 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though.
499 if (hasLineIfEmpty()) 492 if (hasLineIfEmpty())
500 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); 493 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine()));
501 494
502 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); 495 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData);
503 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); 496 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData);
504 497
505 layoutGridItems(sizingData); 498 layoutGridItems(sizingData);
506 499
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 minLogicalWidth += totalGuttersSize; 609 minLogicalWidth += totalGuttersSize;
617 maxLogicalWidth += totalGuttersSize; 610 maxLogicalWidth += totalGuttersSize;
618 611
619 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 612 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
620 minLogicalWidth += scrollbarWidth; 613 minLogicalWidth += scrollbarWidth;
621 maxLogicalWidth += scrollbarWidth; 614 maxLogicalWidth += scrollbarWidth;
622 } 615 }
623 616
624 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) 617 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData)
625 { 618 {
619 DCHECK(sizingData.isValidTransition(ForRows));
626 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); 620 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData));
627 sizingData.setAvailableSpace(LayoutUnit()); 621 sizingData.setAvailableSpace(LayoutUnit());
628 sizingData.freeSpace(ForRows) = LayoutUnit(); 622 sizingData.freeSpace(ForRows) = LayoutUnit();
629 sizingData.sizingOperation = IntrinsicSizeComputation; 623 sizingData.sizingOperation = IntrinsicSizeComputation;
630 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); 624 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight);
631 625
632 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount(), sizing Data.sizingOperation); 626 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount(), sizing Data.sizingOperation);
633 m_minContentHeight += totalGuttersSize; 627 m_minContentHeight += totalGuttersSize;
634 m_maxContentHeight += totalGuttersSize; 628 m_maxContentHeight += totalGuttersSize;
635 629
636 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); 630 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData));
631 sizingData.nextState();
jfernandez 2016/09/14 21:54:46 It's a bit confusing/peculiar that intrinsic size
637 } 632 }
638 633
639 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const 634 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const
640 { 635 {
641 if (logicalHeightLength.isMinContent()) 636 if (logicalHeightLength.isMinContent())
642 return m_minContentHeight; 637 return m_minContentHeight;
643 638
644 if (logicalHeightLength.isMaxContent()) 639 if (logicalHeightLength.isMaxContent())
645 return m_maxContentHeight; 640 return m_maxContentHeight;
646 641
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 for (const auto& trackIndex : autoSizedTracksIndex) { 1883 for (const auto& trackIndex : autoSizedTracksIndex) {
1889 GridTrack* track = tracks.data() + trackIndex; 1884 GridTrack* track = tracks.data() + trackIndex;
1890 LayoutUnit baseSize = track->baseSize() + sizeToIncrease; 1885 LayoutUnit baseSize = track->baseSize() + sizeToIncrease;
1891 track->setBaseSize(baseSize); 1886 track->setBaseSize(baseSize);
1892 } 1887 }
1893 availableSpace = LayoutUnit(); 1888 availableSpace = LayoutUnit();
1894 } 1889 }
1895 1890
1896 void LayoutGrid::layoutGridItems(GridSizingData& sizingData) 1891 void LayoutGrid::layoutGridItems(GridSizingData& sizingData)
1897 { 1892 {
1893 sizingData.sizingOperation = TrackSizing;
jfernandez 2016/09/14 21:54:46 Why we need to do this ? Wouldn't be better place
svillar 2016/09/15 10:04:34 We need this because the layout of the items invol
1898 populateGridPositionsForDirection(sizingData, ForColumns); 1894 populateGridPositionsForDirection(sizingData, ForColumns);
1899 populateGridPositionsForDirection(sizingData, ForRows); 1895 populateGridPositionsForDirection(sizingData, ForRows);
1900 m_gridItemsOverflowingGridArea.resize(0); 1896 m_gridItemsOverflowingGridArea.resize(0);
1901 1897
1902 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 1898 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
1903 if (child->isOutOfFlowPositioned()) { 1899 if (child->isOutOfFlowPositioned()) {
1904 prepareChildForPositionedLayout(*child); 1900 prepareChildForPositionedLayout(*child);
1905 continue; 1901 continue;
1906 } 1902 }
1907 1903
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; 2666 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation;
2671 } 2667 }
2672 2668
2673 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2669 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2674 { 2670 {
2675 if (!m_gridItemArea.isEmpty()) 2671 if (!m_gridItemArea.isEmpty())
2676 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2672 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2677 } 2673 }
2678 2674
2679 } // namespace blink 2675 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/PerformanceTests/Layout/nested-grid.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698