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

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

Issue 2347613003: [css-grid] Refactor intrinsic size computation code (Closed)
Patch Set: Build fix 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) const
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(direction) = LayoutUnit();
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 #if ENABLE(ASSERT)
629 DCHECK(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
630 #endif
634 } 631 }
635 632
636 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const 633 LayoutUnit LayoutGrid::computeIntrinsicLogicalContentHeightUsing(const Length& l ogicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddi ng) const
637 { 634 {
638 if (logicalHeightLength.isMinContent()) 635 if (logicalHeightLength.isMinContent())
639 return m_minContentHeight; 636 return m_minContentHeight;
640 637
641 if (logicalHeightLength.isMaxContent()) 638 if (logicalHeightLength.isMaxContent())
642 return m_maxContentHeight; 639 return m_maxContentHeight;
643 640
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 track->growSizeDuringDistribution(growthShare); 1394 track->growSizeDuringDistribution(growthShare);
1398 availableLogicalSpace -= growthShare; 1395 availableLogicalSpace -= growthShare;
1399 } 1396 }
1400 } 1397 }
1401 1398
1402 for (auto* track : tracks) 1399 for (auto* track : tracks)
1403 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( ))); 1400 track->setPlannedSize(track->plannedSize() == infinity ? track->sizeDuri ngDistribution() : std::max(track->plannedSize(), track->sizeDuringDistribution( )));
1404 } 1401 }
1405 1402
1406 #if ENABLE(ASSERT) 1403 #if ENABLE(ASSERT)
1407 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) 1404 bool LayoutGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, GridSizingData& sizingData) const
1408 { 1405 {
1409 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks; 1406 const Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.col umnTracks : sizingData.rowTracks;
1410 LayoutUnit& maxSize = sizingData.freeSpace(direction); 1407 LayoutUnit& maxSize = sizingData.freeSpace(direction);
1411 for (size_t i = 0; i < tracks.size(); ++i) { 1408 for (size_t i = 0; i < tracks.size(); ++i) {
1412 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration); 1409 GridTrackSize trackSize = gridTrackSize(direction, i, sizingData.sizingO peration);
1413 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze()) 1410 if (computeUsedBreadthOfMinLength(trackSize, maxSize) > tracks[i].baseSi ze())
1414 return false; 1411 return false;
1415 } 1412 }
1416 return true; 1413 return true;
1417 } 1414 }
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2667 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2671 } 2668 }
2672 2669
2673 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const 2670 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const
2674 { 2671 {
2675 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); 2672 SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
2676 return m_hasDefiniteLogicalHeight.value(); 2673 return m_hasDefiniteLogicalHeight.value();
2677 } 2674 }
2678 2675
2679 } // namespace blink 2676 } // 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