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

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

Issue 1317643005: [css-grid] Fix track sizing algo w/ size restrictions and intrinsic sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 minLogicalWidth += minTrackBreadth; 385 minLogicalWidth += minTrackBreadth;
386 maxLogicalWidth += maxTrackBreadth; 386 maxLogicalWidth += maxTrackBreadth;
387 } 387 }
388 388
389 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); 389 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth();
390 minLogicalWidth += scrollbarWidth; 390 minLogicalWidth += scrollbarWidth;
391 maxLogicalWidth += scrollbarWidth; 391 maxLogicalWidth += scrollbarWidth;
392 } 392 }
393 393
394 bool LayoutGrid::gridElementIsShrinkToFit() 394 static bool heightSizedUnderMinContentConstraint(const ComputedStyle& style)
395 { 395 {
396 return isFloatingOrOutOfFlowPositioned(); 396 return style.logicalMinHeight().isMinContent() || style.logicalHeight().isMi nContent() || style.logicalMaxHeight().isMinContent();
Manuel Rego 2015/09/17 11:04:03 What happens if it's not you, but it's an ancestor
svillar 2015/09/17 14:05:44 max-content |_min-content |_auto <- this is the
Manuel Rego 2015/09/18 10:52:07 Sorry but I'm not still 100% sure about this. :-/
svillar 2015/09/18 12:01:20 Well in this particular example the fact that heig
Manuel Rego 2015/09/22 10:12:34 My question is why the row is 100px tall and not 0
397 }
398
399 static bool heightSizedUnderMaxContentConstraint(const ComputedStyle& style)
400 {
401 return style.logicalMinHeight().isMaxContent() || style.logicalHeight().isMa xContent() || style.logicalMaxHeight().isMaxContent();
402 }
403
404 void LayoutGrid::maximizeTracks(Vector<GridTrack>& tracks, GridSizingData& sizin gData, LayoutUnit& spaceToDistribute)
405 {
406 if (spaceToDistribute <= 0)
407 return;
408
409 size_t tracksSize = tracks.size();
410 Vector<GridTrack*> tracksForDistribution(tracksSize);
411 for (size_t i = 0; i < tracksSize; ++i) {
412 tracksForDistribution[i] = tracks.data() + i;
413 tracksForDistribution[i]->setPlannedSize(tracksForDistribution[i]->baseS ize());
414 }
415
416 distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, nullptr, sizi ngData, spaceToDistribute);
417
418 for (auto* track : tracksForDistribution)
419 track->setBaseSize(track->plannedSize());
397 } 420 }
398 421
399 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& freeSpace) 422 void LayoutGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& freeSpace)
400 { 423 {
401 const LayoutUnit initialFreeSpace = freeSpace; 424 const LayoutUnit initialFreeSpace = freeSpace;
402 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; 425 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks;
403 Vector<size_t> flexibleSizedTracksIndex; 426 Vector<size_t> flexibleSizedTracksIndex;
404 sizingData.contentSizedTracksIndex.shrink(0); 427 sizingData.contentSizedTracksIndex.shrink(0);
405 428
406 // 1. Initialize per Grid track variables. 429 // 1. Initialize per Grid track variables.
(...skipping 15 matching lines...) Expand all
422 445
423 // 2. Resolve content-based TrackSizingFunctions. 446 // 2. Resolve content-based TrackSizingFunctions.
424 if (!sizingData.contentSizedTracksIndex.isEmpty()) 447 if (!sizingData.contentSizedTracksIndex.isEmpty())
425 resolveContentBasedTrackSizingFunctions(direction, sizingData); 448 resolveContentBasedTrackSizingFunctions(direction, sizingData);
426 449
427 for (const auto& track: tracks) { 450 for (const auto& track: tracks) {
428 ASSERT(!track.infiniteGrowthPotential()); 451 ASSERT(!track.infiniteGrowthPotential());
429 freeSpace -= track.baseSize(); 452 freeSpace -= track.baseSize();
430 } 453 }
431 454
432 const bool hasUndefinedRemainingSpace = (direction == ForRows) ? style()->lo gicalHeight().isAuto() : gridElementIsShrinkToFit(); 455 const bool hasDefiniteAvailableSpace = (direction == ForRows) ? hasDefiniteL ogicalHeight() : true;
jfernandez 2015/09/01 23:41:39 I don't get why hasDefiniteAvailableSpace is alway
svillar 2015/09/02 13:25:48 It's explained in the comment I added bellow, for
Manuel Rego 2015/09/17 11:04:02 Probably the comment should be before the variable
svillar 2015/09/17 14:05:44 Acknowledged.
433 456 if (hasDefiniteAvailableSpace && freeSpace <= 0)
434 if (!hasUndefinedRemainingSpace && freeSpace <= 0)
435 return; 457 return;
436 458
437 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted. 459 // 3. Grow all Grid tracks in GridTracks from their baseSize up to their gro wthLimit value until freeSpace is exhausted.
438 const size_t tracksSize = tracks.size(); 460 // We only need to check for the interactions of the track sizing algorithm with intrinsic sizes and min/max size
439 if (!hasUndefinedRemainingSpace) { 461 // restrictions **for rows**, as for columns we already have the right avail able space because the intrinsic sizes
440 Vector<GridTrack*> tracksForDistribution(tracksSize); 462 // were previously computed by computeIntrinsicLogicalWidths()
441 for (size_t i = 0; i < tracksSize; ++i) { 463 if (direction == ForColumns) {
442 tracksForDistribution[i] = tracks.data() + i; 464 maximizeTracks(tracks, sizingData, freeSpace);
443 tracksForDistribution[i]->setPlannedSize(tracksForDistribution[i]->b aseSize()); 465 } else {
466 if (heightSizedUnderMaxContentConstraint(styleRef())) {
467 if (styleRef().logicalMaxHeight().isMaxSizeNone()) {
468 for (auto& track : tracks)
469 track.setBaseSize(track.growthLimit());
470 } else {
471 LayoutUnit tracksBreadth = initialFreeSpace - freeSpace;
472 LayoutUnit spaceToDistribute = computeLogicalHeightUsing(MaxSize , styleRef().logicalMaxHeight(), contentLogicalHeight()) - tracksBreadth;
473 maximizeTracks(tracks, sizingData, spaceToDistribute);
474 }
475 } else if (heightSizedUnderMinContentConstraint(styleRef())) {
476 const Length& logicalMinSize = styleRef().logicalMinHeight();
477 if (!logicalMinSize.isZero() || logicalMinSize.isIntrinsic()) {
478 LayoutUnit tracksBreadth = initialFreeSpace - freeSpace;
479 LayoutUnit spaceToDistribute = computeLogicalHeightUsing(MinSize , styleRef().logicalMinHeight(), contentLogicalHeight()) - tracksBreadth;
480 maximizeTracks(tracks, sizingData, spaceToDistribute);
481 }
482 } else if (hasDefiniteAvailableSpace) {
483 maximizeTracks(tracks, sizingData, freeSpace);
484 } else {
485 for (auto& track : tracks)
486 track.setBaseSize(track.growthLimit());
444 } 487 }
Manuel Rego 2015/09/17 11:04:03 In order to try to simplify this "if-else", would
svillar 2015/09/17 14:05:44 If you mean the whole if-else thing the answer is
445
446 distributeSpaceToTracks<MaximizeTracks>(tracksForDistribution, nullptr, sizingData, freeSpace);
447
448 for (auto* track : tracksForDistribution)
449 track->setBaseSize(track->plannedSize());
450 } else {
451 for (auto& track : tracks)
452 track.setBaseSize(track.growthLimit());
453 } 488 }
454 489
455 if (flexibleSizedTracksIndex.isEmpty()) 490 if (flexibleSizedTracksIndex.isEmpty())
456 return; 491 return;
457 492
458 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. 493 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction.
459 double normalizedFractionBreadth = 0; 494 double normalizedFractionBreadth = 0;
460 if (!hasUndefinedRemainingSpace) { 495 if (hasDefiniteAvailableSpace) {
461 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri dSpan(0, tracks.size() - 1), direction, initialFreeSpace); 496 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri dSpan(0, tracks.size() - 1), direction, initialFreeSpace);
462 } else { 497 } else {
463 for (const auto& trackIndex : flexibleSizedTracksIndex) { 498 for (const auto& trackIndex : flexibleSizedTracksIndex) {
464 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); 499 GridTrackSize trackSize = gridTrackSize(direction, trackIndex);
465 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac ks[trackIndex].baseSize() / trackSize.maxTrackBreadth().flex()); 500 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac ks[trackIndex].baseSize() / trackSize.maxTrackBreadth().flex());
466 } 501 }
467 502
468 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { 503 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) {
469 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); 504 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] );
470 while (LayoutBox* gridItem = iterator.nextGridItem()) { 505 while (LayoutBox* gridItem = iterator.nextGridItem()) {
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 1955
1921 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child)); 1956 return LayoutPoint(rowAxisOffset, columnAxisOffsetForChild(child));
1922 } 1957 }
1923 1958
1924 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 1959 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
1925 { 1960 {
1926 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1961 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1927 } 1962 }
1928 1963
1929 } // namespace blink 1964 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698