OLD | NEW |
---|---|
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 | 411 |
412 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) | 412 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi on, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) |
413 { | 413 { |
414 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; | 414 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra cks : sizingData.rowTracks; |
415 Vector<size_t> flexibleSizedTracksIndex; | 415 Vector<size_t> flexibleSizedTracksIndex; |
416 sizingData.contentSizedTracksIndex.shrink(0); | 416 sizingData.contentSizedTracksIndex.shrink(0); |
417 | 417 |
418 // 1. Initialize per Grid track variables. | 418 // 1. Initialize per Grid track variables. |
419 for (size_t i = 0; i < tracks.size(); ++i) { | 419 for (size_t i = 0; i < tracks.size(); ++i) { |
420 GridTrack& track = tracks[i]; | 420 GridTrack& track = tracks[i]; |
421 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 421 GridTrackSize trackSize = gridTrackSize(direction, i); |
422 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 422 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
423 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); | 423 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); |
424 | 424 |
425 track.m_usedBreadth = computeUsedBreadthOfMinLength(direction, minTrackB readth); | 425 track.m_usedBreadth = computeUsedBreadthOfMinLength(direction, minTrackB readth); |
426 track.m_maxBreadth = computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.m_usedBreadth); | 426 track.m_maxBreadth = computeUsedBreadthOfMaxLength(direction, maxTrackBr eadth, track.m_usedBreadth); |
427 | 427 |
428 if (track.m_maxBreadth != infinity) | 428 if (track.m_maxBreadth != infinity) |
429 track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadt h); | 429 track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadt h); |
430 | 430 |
431 if (trackSize.isContentSized()) | 431 if (trackSize.isContentSized()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 if (flexibleSizedTracksIndex.isEmpty()) | 465 if (flexibleSizedTracksIndex.isEmpty()) |
466 return; | 466 return; |
467 | 467 |
468 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. | 468 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. |
469 double normalizedFractionBreadth = 0; | 469 double normalizedFractionBreadth = 0; |
470 if (!hasUndefinedRemainingSpace) { | 470 if (!hasUndefinedRemainingSpace) { |
471 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri dSpan(0, tracks.size() - 1), direction, availableLogicalSpace); | 471 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri dSpan(0, tracks.size() - 1), direction, availableLogicalSpace); |
472 } else { | 472 } else { |
473 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 473 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
474 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 474 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
475 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex ); | 475 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
476 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); | 476 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); |
477 } | 477 } |
478 | 478 |
479 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 479 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
480 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); | 480 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i] ); |
481 while (RenderBox* gridItem = iterator.nextGridItem()) { | 481 while (RenderBox* gridItem = iterator.nextGridItem()) { |
482 const GridCoordinate coordinate = cachedGridCoordinate(gridItem) ; | 482 const GridCoordinate coordinate = cachedGridCoordinate(gridItem) ; |
483 const GridSpan span = (direction == ForColumns) ? coordinate.col umns : coordinate.rows; | 483 const GridSpan span = (direction == ForColumns) ? coordinate.col umns : coordinate.rows; |
484 | 484 |
485 // Do not include already processed items. | 485 // Do not include already processed items. |
486 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz edTracksIndex[i - 1]) | 486 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz edTracksIndex[i - 1]) |
487 continue; | 487 continue; |
488 | 488 |
489 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea dth(tracks, span, direction, maxContentForChild(gridItem, direction, sizingData. columnTracks)); | 489 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea dth(tracks, span, direction, maxContentForChild(gridItem, direction, sizingData. columnTracks)); |
490 normalizedFractionBreadth = std::max(normalizedFractionBreadth, itemNormalizedFlexBreadth); | 490 normalizedFractionBreadth = std::max(normalizedFractionBreadth, itemNormalizedFlexBreadth); |
491 } | 491 } |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 495 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
496 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 496 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
497 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); | 497 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
498 | 498 |
499 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex() ); | 499 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex() ); |
500 } | 500 } |
501 } | 501 } |
502 | 502 |
503 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di rection, const GridLength& gridLength) const | 503 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di rection, const GridLength& gridLength) const |
504 { | 504 { |
505 if (gridLength.isFlex()) | 505 if (gridLength.isFlex()) |
506 return 0; | 506 return 0; |
507 | 507 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 { | 542 { |
543 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; | 543 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; |
544 } | 544 } |
545 | 545 |
546 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa bleLogicalSpace) const | 546 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa bleLogicalSpace) const |
547 { | 547 { |
548 // |availableLogicalSpace| already accounts for the used breadths so no need to remove it here. | 548 // |availableLogicalSpace| already accounts for the used breadths so no need to remove it here. |
549 | 549 |
550 Vector<GridTrackForNormalization> tracksForNormalization; | 550 Vector<GridTrackForNormalization> tracksForNormalization; |
551 for (GridSpan::iterator resolvedPosition = tracksSpan.begin(); resolvedPosit ion != tracksSpan.end(); ++resolvedPosition) { | 551 for (GridSpan::iterator resolvedPosition = tracksSpan.begin(); resolvedPosit ion != tracksSpan.end(); ++resolvedPosition) { |
552 const GridTrackSize& trackSize = gridTrackSize(direction, resolvedPositi on.toInt()); | 552 GridTrackSize trackSize = gridTrackSize(direction, resolvedPosition.toIn t()); |
553 if (!trackSize.maxTrackBreadth().isFlex()) | 553 if (!trackSize.maxTrackBreadth().isFlex()) |
554 continue; | 554 continue; |
555 | 555 |
556 tracksForNormalization.append(GridTrackForNormalization(tracks[resolvedP osition.toInt()], trackSize.maxTrackBreadth().flex())); | 556 tracksForNormalization.append(GridTrackForNormalization(tracks[resolvedP osition.toInt()], trackSize.maxTrackBreadth().flex())); |
557 } | 557 } |
558 | 558 |
559 // The function is not called if we don't have <flex> grid tracks | 559 // The function is not called if we don't have <flex> grid tracks |
560 ASSERT(!tracksForNormalization.isEmpty()); | 560 ASSERT(!tracksForNormalization.isEmpty()); |
561 | 561 |
562 std::sort(tracksForNormalization.begin(), tracksForNormalization.end(), sort ByGridNormalizedFlexValue); | 562 std::sort(tracksForNormalization.begin(), tracksForNormalization.end(), sort ByGridNormalizedFlexValue); |
(...skipping 17 matching lines...) Expand all Loading... | |
580 } | 580 } |
581 | 581 |
582 accumulatedFractions += track.m_flex; | 582 accumulatedFractions += track.m_flex; |
583 // This item was processed so we re-add its used breadth to the availabl e space to accurately count the remaining space. | 583 // This item was processed so we re-add its used breadth to the availabl e space to accurately count the remaining space. |
584 availableLogicalSpaceIgnoringFractionTracks += track.m_track->m_usedBrea dth; | 584 availableLogicalSpaceIgnoringFractionTracks += track.m_track->m_usedBrea dth; |
585 } | 585 } |
586 | 586 |
587 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; | 587 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; |
588 } | 588 } |
589 | 589 |
590 const GridTrackSize& RenderGrid::gridTrackSize(GridTrackSizingDirection directio n, size_t i) const | 590 GridTrackSize RenderGrid::gridTrackSize(GridTrackSizingDirection direction, size _t i) const |
591 { | 591 { |
592 const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style ()->gridTemplateColumns() : style()->gridTemplateRows(); | 592 bool isForColumns = direction == ForColumns; |
593 if (i >= trackStyles.size()) | 593 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl ateColumns() : style()->gridTemplateRows(); |
594 return (direction == ForColumns) ? style()->gridAutoColumns() : style()- >gridAutoRows(); | 594 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ? style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i]; |
595 | 595 |
596 const GridTrackSize& trackSize = trackStyles[i]; | 596 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto> (or in |
597 // If the logical width/height of the grid container is indefinite, percenta ge values are treated as <auto>. | 597 // the case of minmax() as min-content for the first position and max-conten t for the second). |
598 if (trackSize.isPercentage()) { | 598 Length logicalSize = isForColumns ? style()->logicalWidth() : style()->logic alHeight(); |
599 Length logicalSize = direction == ForColumns ? style()->logicalWidth() : style()->logicalHeight(); | 599 if (logicalSize.isIntrinsicOrAuto()) { |
Julien - ping for review
2014/09/10 01:00:17
Note that this is not the exact definition of 'ind
svillar
2014/09/10 15:03:09
Correct.
| |
600 if (logicalSize.isIntrinsicOrAuto()) { | 600 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); |
601 DEFINE_STATIC_LOCAL(GridTrackSize, autoTrackSize, (Length(Auto))); | 601 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); |
602 return autoTrackSize; | 602 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent) : oldMaxTrackBreadth); |
603 } | |
604 } | 603 } |
605 | 604 |
606 return trackSize; | 605 return trackSize; |
607 } | 606 } |
608 | 607 |
609 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox* child, Vector<GridTrack> & columnTracks) | 608 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox* child, Vector<GridTrack> & columnTracks) |
610 { | 609 { |
611 SubtreeLayoutScope layoutScope(*child); | 610 SubtreeLayoutScope layoutScope(*child); |
612 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOverrid eContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogicalWid th() : LayoutUnit(); | 611 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOverrid eContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogicalWid th() : LayoutUnit(); |
613 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); | 612 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh ild(child, ForColumns, columnTracks); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 } | 707 } |
709 | 708 |
710 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, RenderBox* gridItem, FilterFunc tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette r, AccumulatorGrowFunction trackGrowthFunction) | 709 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing Direction direction, GridSizingData& sizingData, RenderBox* gridItem, FilterFunc tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette r, AccumulatorGrowFunction trackGrowthFunction) |
711 { | 710 { |
712 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); | 711 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); |
713 const GridResolvedPosition initialTrackPosition = (direction == ForColumns) ? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo sition; | 712 const GridResolvedPosition initialTrackPosition = (direction == ForColumns) ? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo sition; |
714 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ? coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition ; | 713 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ? coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition ; |
715 | 714 |
716 sizingData.filteredTracks.shrink(0); | 715 sizingData.filteredTracks.shrink(0); |
717 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio n <= finalTrackPosition; ++trackPosition) { | 716 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio n <= finalTrackPosition; ++trackPosition) { |
718 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition. toInt()); | 717 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt() ); |
719 if (!(trackSize.*filterFunction)()) | 718 if (!(trackSize.*filterFunction)()) |
720 continue; | 719 continue; |
721 | 720 |
722 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; | 721 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t rackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; |
723 sizingData.filteredTracks.append(&track); | 722 sizingData.filteredTracks.append(&track); |
724 } | 723 } |
725 | 724 |
726 if (sizingData.filteredTracks.isEmpty()) | 725 if (sizingData.filteredTracks.isEmpty()) |
727 return; | 726 return; |
728 | 727 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 LayoutUnit growth = sizingData.distributeTrackVector[i] - (tracks[i]->*t rackGetter)(); | 785 LayoutUnit growth = sizingData.distributeTrackVector[i] - (tracks[i]->*t rackGetter)(); |
787 if (growth >= 0) | 786 if (growth >= 0) |
788 (tracks[i]->*trackGrowthFunction)(growth); | 787 (tracks[i]->*trackGrowthFunction)(growth); |
789 } | 788 } |
790 } | 789 } |
791 | 790 |
792 #if ENABLE(ASSERT) | 791 #if ENABLE(ASSERT) |
793 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, const Vector<GridTrack>& tracks) | 792 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire ction, const Vector<GridTrack>& tracks) |
794 { | 793 { |
795 for (size_t i = 0; i < tracks.size(); ++i) { | 794 for (size_t i = 0; i < tracks.size(); ++i) { |
796 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 795 GridTrackSize trackSize = gridTrackSize(direction, i); |
797 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 796 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
798 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].m_usedBreadth) | 797 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].m_usedBreadth) |
799 return false; | 798 return false; |
800 } | 799 } |
801 return true; | 800 return true; |
802 } | 801 } |
803 #endif | 802 #endif |
804 | 803 |
805 void RenderGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde x) | 804 void RenderGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde x) |
806 { | 805 { |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1423 if (isOutOfFlowPositioned()) | 1422 if (isOutOfFlowPositioned()) |
1424 return "RenderGrid (positioned)"; | 1423 return "RenderGrid (positioned)"; |
1425 if (isAnonymous()) | 1424 if (isAnonymous()) |
1426 return "RenderGrid (generated)"; | 1425 return "RenderGrid (generated)"; |
1427 if (isRelPositioned()) | 1426 if (isRelPositioned()) |
1428 return "RenderGrid (relative positioned)"; | 1427 return "RenderGrid (relative positioned)"; |
1429 return "RenderGrid"; | 1428 return "RenderGrid"; |
1430 } | 1429 } |
1431 | 1430 |
1432 } // namespace blink | 1431 } // namespace blink |
OLD | NEW |