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

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

Issue 2347613003: [css-grid] Refactor intrinsic size computation code (Closed)
Patch Set: 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/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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 LayoutUnit logicalHeight; 398 LayoutUnit logicalHeight;
399 399
400 for (const auto& row : sizingData.rowTracks) 400 for (const auto& row : sizingData.rowTracks)
401 logicalHeight += row.baseSize(); 401 logicalHeight += row.baseSize();
402 402
403 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), sizing Data.sizingOperation); 403 logicalHeight += guttersSize(ForRows, 0, sizingData.rowTracks.size(), sizing Data.sizingOperation);
404 404
405 return logicalHeight; 405 return logicalHeight;
406 } 406 }
407 407
408 void LayoutGrid::computeTrackSizesForDirection(GridTrackSizingDirection directio n, GridSizingData& sizingData, LayoutUnit availableSpace) 408 void LayoutGrid::computeTrackSizesForDefiniteSize(GridTrackSizingDirection direc tion, GridSizingData& sizingData, LayoutUnit availableSpace)
jfernandez 2016/09/15 21:47:28 Any reason why this method is not declared 'const'
svillar 2016/09/16 12:23:31 Good point, I think we can do it.
409 { 409 {
410 DCHECK(sizingData.isValidTransition(direction)); 410 DCHECK(sizingData.isValidTransition(direction));
411 sizingData.setAvailableSpace(availableSpace); 411 sizingData.setAvailableSpace(availableSpace);
412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0, direction == ForRows ? gridRowCount() : gridColumnCount(), sizingData.sizingOpe ration); 412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0, direction == ForRows ? gridRowCount() : gridColumnCount(), sizingData.sizingOpe ration);
413 sizingData.sizingOperation = TrackSizing; 413 sizingData.sizingOperation = TrackSizing;
414 414
415 LayoutUnit baseSizes, growthLimits; 415 LayoutUnit baseSizes, growthLimits;
416 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s); 416 computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimit s);
417 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData)); 417 ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
418 sizingData.nextState(); 418 sizingData.nextState();
419 } 419 }
420 420
421 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows) 421 void LayoutGrid::repeatTracksSizingIfNeeded(GridSizingData& sizingData, LayoutUn it availableSpaceForColumns, LayoutUnit availableSpaceForRows)
422 { 422 {
423 DCHECK(sizingData.sizingState > GridSizingData::RowSizingFirstIteration); 423 DCHECK(sizingData.sizingState > GridSizingData::RowSizingFirstIteration);
424 424
425 // In orthogonal flow cases column track's size is determined by using the c omputed 425 // In orthogonal flow cases column track's size is determined by using the c omputed
426 // row track's size, which it was estimated during the first cycle of the si zing 426 // row track's size, which it was estimated during the first cycle of the si zing
427 // algorithm. Hence we need to repeat computeUsedBreadthOfGridTracks for bot h, 427 // algorithm. Hence we need to repeat computeUsedBreadthOfGridTracks for bot h,
428 // columns and rows, to determine the final values. 428 // columns and rows, to determine the final values.
429 // TODO (lajava): orthogonal flows is just one of the cases which may requir e 429 // TODO (lajava): orthogonal flows is just one of the cases which may requir e
430 // a new cycle of the sizing algorithm; there may be more. In addition, not all the 430 // a new cycle of the sizing algorithm; there may be more. In addition, not all the
431 // cases with orthogonal flows require this extra cycle; we need a more spec ific 431 // cases with orthogonal flows require this extra cycle; we need a more spec ific
432 // condition to detect whether child's min-content contribution has changed or not. 432 // condition to detect whether child's min-content contribution has changed or not.
433 if (m_hasAnyOrthogonalChild) { 433 if (m_hasAnyOrthogonalChild) {
434 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); 434 computeTrackSizesForDefiniteSize(ForColumns, sizingData, availableSpaceF orColumns);
435 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows ); 435 computeTrackSizesForDefiniteSize(ForRows, sizingData, availableSpaceForR ows);
436 } 436 }
437 } 437 }
438 438
439 void LayoutGrid::layoutBlock(bool relayoutChildren) 439 void LayoutGrid::layoutBlock(bool relayoutChildren)
440 { 440 {
441 ASSERT(needsLayout()); 441 ASSERT(needsLayout());
442 442
443 if (!relayoutChildren && simplifiedLayout()) 443 if (!relayoutChildren && simplifiedLayout())
444 return; 444 return;
445 445
(...skipping 18 matching lines...) Expand all
464 placeItemsOnGrid(TrackSizing); 464 placeItemsOnGrid(TrackSizing);
465 465
466 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 466 GridSizingData sizingData(gridColumnCount(), gridRowCount());
467 467
468 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 468 // 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() 469 // 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 470 // 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 471 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
472 // heights properly (like for positioned items for example). 472 // heights properly (like for positioned items for example).
473 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 473 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
474 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); 474 computeTrackSizesForDefiniteSize(ForColumns, sizingData, availableSpaceF orColumns);
475 475
476 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the 476 // 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. 477 // grid column sizes calculated in the previous step.
478 if (cachedHasDefiniteLogicalHeight()) 478 if (cachedHasDefiniteLogicalHeight()) {
479 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); 479 computeTrackSizesForDefiniteSize(ForRows, sizingData, availableLogic alHeight(ExcludeMarginBorderPadding));
480 else 480 } else {
481 computeIntrinsicLogicalHeight(sizingData); 481 computeTrackSizesForIndefiniteSize(ForRows, sizingData, m_minContent Height, m_maxContentHeight);
482 sizingData.nextState();
483 sizingData.sizingOperation = TrackSizing;
484 }
482 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); 485 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight());
483 486
484 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 487 LayoutUnit oldClientAfterEdge = clientLogicalBottom();
485 updateLogicalHeight(); 488 updateLogicalHeight();
486 489
487 // 3- If the min-content contribution of any grid items have changed bas ed on the row 490 // 3- If the min-content contribution of any grid items have changed bas ed on the row
488 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content 491 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content
489 // contribution (once only). 492 // contribution (once only).
490 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, content LogicalHeight()); 493 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, content LogicalHeight());
491 494
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 597 }
595 598
596 return gapAccumulator; 599 return gapAccumulator;
597 } 600 }
598 601
599 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 602 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
600 { 603 {
601 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); 604 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation);
602 605
603 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 606 GridSizingData sizingData(gridColumnCount(), gridRowCount());
604 sizingData.setAvailableSpace(LayoutUnit()); 607 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, maxLogicalWidth);
605 sizingData.freeSpace(ForColumns) = LayoutUnit();
606 sizingData.sizingOperation = IntrinsicSizeComputation;
607 computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxL ogicalWidth);
608
609 LayoutUnit totalGuttersSize = guttersSize(ForColumns, 0, sizingData.columnTr acks.size(), sizingData.sizingOperation);
610 minLogicalWidth += totalGuttersSize;
611 maxLogicalWidth += totalGuttersSize;
612 608
613 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 609 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
614 minLogicalWidth += scrollbarWidth; 610 minLogicalWidth += scrollbarWidth;
615 maxLogicalWidth += scrollbarWidth; 611 maxLogicalWidth += scrollbarWidth;
616 } 612 }
617 613
618 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) 614 void LayoutGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingDirection dir ection, GridSizingData& sizingData, LayoutUnit& minIntrinsicSize, LayoutUnit& ma xIntrinsicSize) const
619 { 615 {
620 DCHECK(sizingData.isValidTransition(ForRows)); 616 DCHECK(sizingData.isValidTransition(direction));
621 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData));
622 sizingData.setAvailableSpace(LayoutUnit()); 617 sizingData.setAvailableSpace(LayoutUnit());
623 sizingData.freeSpace(ForRows) = LayoutUnit(); 618 sizingData.freeSpace(ForRows) = LayoutUnit();
jfernandez 2016/09/15 21:47:28 Shouldn't we use 'direction' here, instead of 'For
svillar 2016/09/16 12:23:31 Uhu, right
624 sizingData.sizingOperation = IntrinsicSizeComputation; 619 sizingData.sizingOperation = IntrinsicSizeComputation;
625 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight);
626 620
627 LayoutUnit totalGuttersSize = guttersSize(ForRows, 0, gridRowCount(), sizing Data.sizingOperation); 621 computeUsedBreadthOfGridTracks(direction, sizingData, minIntrinsicSize, maxI ntrinsicSize);
628 m_minContentHeight += totalGuttersSize;
629 m_maxContentHeight += totalGuttersSize;
630 622
631 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData)); 623 size_t numberOfTracks = direction == ForColumns ? sizingData.columnTracks.si ze() : sizingData.rowTracks.size();
632 sizingData.nextState(); 624 LayoutUnit totalGuttersSize = guttersSize(direction, 0, numberOfTracks, sizi ngData.sizingOperation);
633 sizingData.sizingOperation = TrackSizing; 625 minIntrinsicSize += totalGuttersSize;
626 maxIntrinsicSize += totalGuttersSize;
627
628 DCHECK(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
634 } 629 }
635 630
636 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const 631 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const
637 { 632 {
638 if (logicalHeightLength.isMinContent()) 633 if (logicalHeightLength.isMinContent())
639 return m_minContentHeight; 634 return m_minContentHeight;
640 635
641 if (logicalHeightLength.isMaxContent()) 636 if (logicalHeightLength.isMaxContent())
642 return m_maxContentHeight; 637 return m_maxContentHeight;
643 638
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 track->growSizeDuringDistribution(growthShare); 1392 track->growSizeDuringDistribution(growthShare);
1398 availableLogicalSpace -= growthShare; 1393 availableLogicalSpace -= growthShare;
1399 } 1394 }
1400 } 1395 }
1401 1396
1402 for (auto* track : tracks) 1397 for (auto* track : tracks)
1403 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); 1398 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( )));
1404 } 1399 }
1405 1400
1406 #if ENABLE(ASSERT) 1401 #if ENABLE(ASSERT)
1407 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) 1402 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) const
jfernandez 2016/09/15 21:47:28 sizingData should be const here.
svillar 2016/09/16 12:23:31 It should but we cannot do it right now because fr
1408 { 1403 {
1409 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; 1404 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1410 LayoutUnit& maxSize = sizingData.freeSpace(direction); 1405 LayoutUnit& maxSize = sizingData.freeSpace(direction);
1411 for (size_t i = 0; i < tracks.size(); ++i) { 1406 for (size_t i = 0; i < tracks.size(); ++i) {
1412 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); 1407 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration);
1413 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze()) 1408 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze())
1414 return false; 1409 return false;
1415 } 1410 }
1416 return true; 1411 return true;
1417 } 1412 }
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2665 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2671 } 2666 }
2672 2667
2673 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const 2668 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const
2674 { 2669 {
2675 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 2670 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
2676 return m_hasDefiniteLogicalHeight.value(); 2671 return m_hasDefiniteLogicalHeight.value();
2677 } 2672 }
2678 2673
2679 } // namespace blink 2674 } // 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