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

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

Issue 2287533002: [css-grid] Remove a duplicated auto repeat computation for intrinsic sizes (Closed)
Patch Set: Patch Created 4 years, 2 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
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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight(); 456 m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight();
457 457
458 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); 458 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
459 459
460 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated 460 updateAutoRepeatTracksAndSetDirtyIfNeeded(TrackSizing);
461 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) 461 placeItemsOnGrid();
462 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing))
463 dirtyGrid();
464 placeItemsOnGrid(TrackSizing);
465 462
466 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 463 GridSizingData sizingData(gridColumnCount(), gridRowCount());
467 464
468 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 465 // 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() 466 // 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 467 // 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 468 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
472 // heights properly (like for positioned items for example). 469 // heights properly (like for positioned items for example).
473 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 470 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
474 computeTrackSizesForDefiniteSize(ForColumns, sizingData, availableSpaceF orColumns); 471 computeTrackSizesForDefiniteSize(ForColumns, sizingData, availableSpaceF orColumns);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 591 }
595 if (nonEmptyTracksAfterEndLine) 592 if (nonEmptyTracksAfterEndLine)
596 gapAccumulator += gap; 593 gapAccumulator += gap;
597 } 594 }
598 595
599 return gapAccumulator; 596 return gapAccumulator;
600 } 597 }
601 598
602 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 599 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
603 { 600 {
604 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); 601 updateAutoRepeatTracksAndSetDirtyIfNeeded(IntrinsicSizeComputation);
602 const_cast<LayoutGrid*>(this)->placeItemsOnGrid();
cbiesinger 2016/10/05 22:22:13 You still have a const_cast here. Instead of makin
svillar 2016/10/06 08:17:19 I personally dislike those const_cast a lot, actua
605 603
606 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 604 GridSizingData sizingData(gridColumnCount(), gridRowCount());
607 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, maxLogicalWidth); 605 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, maxLogicalWidth);
608 606
609 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 607 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
610 minLogicalWidth += scrollbarWidth; 608 minLogicalWidth += scrollbarWidth;
611 maxLogicalWidth += scrollbarWidth; 609 maxLogicalWidth += scrollbarWidth;
612 } 610 }
613 611
614 void LayoutGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingDirection dir ection, GridSizingData& sizingData, LayoutUnit& minIntrinsicSize, LayoutUnit& ma xIntrinsicSize) const 612 void LayoutGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingDirection dir ection, GridSizingData& sizingData, LayoutUnit& minIntrinsicSize, LayoutUnit& ma xIntrinsicSize) const
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 { 1431 {
1434 RELEASE_ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslated Definite()); 1432 RELEASE_ASSERT(area.rows.isTranslatedDefinite() && area.columns.isTranslated Definite());
1435 ensureGridSize(area.rows.endLine(), area.columns.endLine()); 1433 ensureGridSize(area.rows.endLine(), area.columns.endLine());
1436 1434
1437 for (const auto& row : area.rows) { 1435 for (const auto& row : area.rows) {
1438 for (const auto& column: area.columns) 1436 for (const auto& column: area.columns)
1439 m_grid[row][column].append(&child); 1437 m_grid[row][column].append(&child);
1440 } 1438 }
1441 } 1439 }
1442 1440
1441 void LayoutGrid::updateAutoRepeatTracksAndSetDirtyIfNeeded(SizingOperation sizin gOperation) const
1442 {
1443 size_t newAutoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizin gOperation);
cbiesinger 2016/10/05 22:22:13 Why are you computing this differently now, if siz
svillar 2016/10/06 08:17:19 Actually I'm going back to the original implementa
1444 size_t newAutoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOpera tion);
1445
1446 if (m_autoRepeatColumns != newAutoRepeatColumns || m_autoRepeatRows != newAu toRepeatRows)
1447 dirtyGrid();
1448
1449 m_autoRepeatColumns = newAutoRepeatColumns;
1450 m_autoRepeatRows = newAutoRepeatRows;
1451 }
1452
1443 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on, SizingOperation sizingOperation) const 1453 size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi on, SizingOperation sizingOperation) const
1444 { 1454 {
1445 bool isRowAxis = direction == ForColumns; 1455 bool isRowAxis = direction == ForColumns;
1446 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns( ) : styleRef().gridAutoRepeatRows(); 1456 const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns( ) : styleRef().gridAutoRepeatRows();
1447 size_t autoRepeatTrackListLength = autoRepeatTracks.size(); 1457 size_t autoRepeatTrackListLength = autoRepeatTracks.size();
1448 1458
1449 if (!autoRepeatTrackListLength) 1459 if (!autoRepeatTrackListLength)
1450 return 0; 1460 return 0;
1451 1461
1452 LayoutUnit availableSize; 1462 LayoutUnit availableSize;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 if (!iterator.nextGridItem()) { 1550 if (!iterator.nextGridItem()) {
1541 if (!emptyTrackIndexes) 1551 if (!emptyTrackIndexes)
1542 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet); 1552 emptyTrackIndexes = wrapUnique(new OrderedTrackIndexSet);
1543 emptyTrackIndexes->add(trackIndex); 1553 emptyTrackIndexes->add(trackIndex);
1544 } 1554 }
1545 } 1555 }
1546 } 1556 }
1547 return emptyTrackIndexes; 1557 return emptyTrackIndexes;
1548 } 1558 }
1549 1559
1550 void LayoutGrid::placeItemsOnGrid(SizingOperation sizingOperation) 1560 void LayoutGrid::placeItemsOnGrid()
1551 { 1561 {
1552 if (!m_gridIsDirty) 1562 if (!m_gridIsDirty)
1553 return; 1563 return;
1554 1564
1555 DCHECK(m_gridItemArea.isEmpty()); 1565 DCHECK(m_gridItemArea.isEmpty());
1556 DCHECK(m_gridItemsIndexesMap.isEmpty()); 1566 DCHECK(m_gridItemsIndexesMap.isEmpty());
1557 1567
1558 if (sizingOperation == IntrinsicSizeComputation)
1559 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().size();
cbiesinger 2016/10/05 22:22:13 (...as compared to this one)
1560 else
1561 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizingOpe ration);
1562 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation);
1563
1564 populateExplicitGridAndOrderIterator(); 1568 populateExplicitGridAndOrderIterator();
1565 1569
1566 // We clear the dirty bit here as the grid sizes have been updated. 1570 // We clear the dirty bit here as the grid sizes have been updated.
1567 m_gridIsDirty = false; 1571 m_gridIsDirty = false;
1568 1572
1569 Vector<LayoutBox*> autoMajorAxisAutoGridItems; 1573 Vector<LayoutBox*> autoMajorAxisAutoGridItems;
1570 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; 1574 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems;
1571 m_hasAnyOrthogonalChild = false; 1575 m_hasAnyOrthogonalChild = false;
1572 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { 1576 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) {
1573 if (child->isOutOfFlowPositioned()) 1577 if (child->isOutOfFlowPositioned())
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const 1783 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const
1780 { 1784 {
1781 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; 1785 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows;
1782 } 1786 }
1783 1787
1784 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const 1788 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const
1785 { 1789 {
1786 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; 1790 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns;
1787 } 1791 }
1788 1792
1789 void LayoutGrid::dirtyGrid() 1793 void LayoutGrid::dirtyGrid() const
1790 { 1794 {
1791 if (m_gridIsDirty) 1795 if (m_gridIsDirty)
1792 return; 1796 return;
1793 1797
1794 m_grid.resize(0); 1798 m_grid.resize(0);
1795 m_gridItemArea.clear(); 1799 m_gridItemArea.clear();
1796 m_gridItemsOverflowingGridArea.resize(0); 1800 m_gridItemsOverflowingGridArea.resize(0);
1797 m_gridItemsIndexesMap.clear(); 1801 m_gridItemsIndexesMap.clear();
1798 m_autoRepeatColumns = 0; 1802 m_autoRepeatColumns = 0;
1799 m_autoRepeatRows = 0; 1803 m_autoRepeatRows = 0;
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2674 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2671 } 2675 }
2672 2676
2673 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const 2677 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const
2674 { 2678 {
2675 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 2679 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
2676 return m_hasDefiniteLogicalHeight.value(); 2680 return m_hasDefiniteLogicalHeight.value();
2677 } 2681 }
2678 2682
2679 } // namespace blink 2683 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698