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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 417 |
418 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) | 418 void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection directi
on, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) |
419 { | 419 { |
420 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; | 420 Vector<GridTrack>& tracks = (direction == ForColumns) ? sizingData.columnTra
cks : sizingData.rowTracks; |
421 Vector<size_t> flexibleSizedTracksIndex; | 421 Vector<size_t> flexibleSizedTracksIndex; |
422 sizingData.contentSizedTracksIndex.shrink(0); | 422 sizingData.contentSizedTracksIndex.shrink(0); |
423 | 423 |
424 // 1. Initialize per Grid track variables. | 424 // 1. Initialize per Grid track variables. |
425 for (size_t i = 0; i < tracks.size(); ++i) { | 425 for (size_t i = 0; i < tracks.size(); ++i) { |
426 GridTrack& track = tracks[i]; | 426 GridTrack& track = tracks[i]; |
427 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 427 GridTrackSize trackSize = gridTrackSize(direction, i); |
428 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 428 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
429 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); | 429 const GridLength& maxTrackBreadth = trackSize.maxTrackBreadth(); |
430 | 430 |
431 track.m_usedBreadth = computeUsedBreadthOfMinLength(direction, minTrackB
readth); | 431 track.m_usedBreadth = computeUsedBreadthOfMinLength(direction, minTrackB
readth); |
432 track.m_maxBreadth = computeUsedBreadthOfMaxLength(direction, maxTrackBr
eadth, track.m_usedBreadth); | 432 track.m_maxBreadth = computeUsedBreadthOfMaxLength(direction, maxTrackBr
eadth, track.m_usedBreadth); |
433 | 433 |
434 if (track.m_maxBreadth != infinity) | 434 if (track.m_maxBreadth != infinity) |
435 track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadt
h); | 435 track.m_maxBreadth = std::max(track.m_maxBreadth, track.m_usedBreadt
h); |
436 | 436 |
437 if (trackSize.isContentSized()) | 437 if (trackSize.isContentSized()) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 if (flexibleSizedTracksIndex.isEmpty()) | 471 if (flexibleSizedTracksIndex.isEmpty()) |
472 return; | 472 return; |
473 | 473 |
474 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. | 474 // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction. |
475 double normalizedFractionBreadth = 0; | 475 double normalizedFractionBreadth = 0; |
476 if (!hasUndefinedRemainingSpace) { | 476 if (!hasUndefinedRemainingSpace) { |
477 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri
dSpan(0, tracks.size() - 1), direction, availableLogicalSpace); | 477 normalizedFractionBreadth = computeNormalizedFractionBreadth(tracks, Gri
dSpan(0, tracks.size() - 1), direction, availableLogicalSpace); |
478 } else { | 478 } else { |
479 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 479 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
480 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 480 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
481 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex
); | 481 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
482 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac
ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); | 482 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac
ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); |
483 } | 483 } |
484 | 484 |
485 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 485 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
486 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]
); | 486 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]
); |
487 while (RenderBox* gridItem = iterator.nextGridItem()) { | 487 while (RenderBox* gridItem = iterator.nextGridItem()) { |
488 const GridCoordinate coordinate = cachedGridCoordinate(*gridItem
); | 488 const GridCoordinate coordinate = cachedGridCoordinate(*gridItem
); |
489 const GridSpan span = (direction == ForColumns) ? coordinate.col
umns : coordinate.rows; | 489 const GridSpan span = (direction == ForColumns) ? coordinate.col
umns : coordinate.rows; |
490 | 490 |
491 // Do not include already processed items. | 491 // Do not include already processed items. |
492 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz
edTracksIndex[i - 1]) | 492 if (i > 0 && span.resolvedInitialPosition.toInt() <= flexibleSiz
edTracksIndex[i - 1]) |
493 continue; | 493 continue; |
494 | 494 |
495 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea
dth(tracks, span, direction, maxContentForChild(*gridItem, direction, sizingData
.columnTracks)); | 495 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea
dth(tracks, span, direction, maxContentForChild(*gridItem, direction, sizingData
.columnTracks)); |
496 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); | 496 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); |
497 } | 497 } |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 501 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
502 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 502 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
503 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); | 503 GridTrackSize trackSize = gridTrackSize(direction, trackIndex); |
504 | 504 |
505 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde
x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()
); | 505 tracks[trackIndex].m_usedBreadth = std::max<LayoutUnit>(tracks[trackInde
x].m_usedBreadth, normalizedFractionBreadth * trackSize.maxTrackBreadth().flex()
); |
506 } | 506 } |
507 } | 507 } |
508 | 508 |
509 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const | 509 LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(GridTrackSizingDirection di
rection, const GridLength& gridLength) const |
510 { | 510 { |
511 if (gridLength.isFlex()) | 511 if (gridLength.isFlex()) |
512 return 0; | 512 return 0; |
513 | 513 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 { | 548 { |
549 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; | 549 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; |
550 } | 550 } |
551 | 551 |
552 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa
bleLogicalSpace) const | 552 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa
bleLogicalSpace) const |
553 { | 553 { |
554 // |availableLogicalSpace| already accounts for the used breadths so no need
to remove it here. | 554 // |availableLogicalSpace| already accounts for the used breadths so no need
to remove it here. |
555 | 555 |
556 Vector<GridTrackForNormalization> tracksForNormalization; | 556 Vector<GridTrackForNormalization> tracksForNormalization; |
557 for (GridSpan::iterator resolvedPosition = tracksSpan.begin(); resolvedPosit
ion != tracksSpan.end(); ++resolvedPosition) { | 557 for (GridSpan::iterator resolvedPosition = tracksSpan.begin(); resolvedPosit
ion != tracksSpan.end(); ++resolvedPosition) { |
558 const GridTrackSize& trackSize = gridTrackSize(direction, resolvedPositi
on.toInt()); | 558 GridTrackSize trackSize = gridTrackSize(direction, resolvedPosition.toIn
t()); |
559 if (!trackSize.maxTrackBreadth().isFlex()) | 559 if (!trackSize.maxTrackBreadth().isFlex()) |
560 continue; | 560 continue; |
561 | 561 |
562 tracksForNormalization.append(GridTrackForNormalization(tracks[resolvedP
osition.toInt()], trackSize.maxTrackBreadth().flex())); | 562 tracksForNormalization.append(GridTrackForNormalization(tracks[resolvedP
osition.toInt()], trackSize.maxTrackBreadth().flex())); |
563 } | 563 } |
564 | 564 |
565 // The function is not called if we don't have <flex> grid tracks | 565 // The function is not called if we don't have <flex> grid tracks |
566 ASSERT(!tracksForNormalization.isEmpty()); | 566 ASSERT(!tracksForNormalization.isEmpty()); |
567 | 567 |
568 std::sort(tracksForNormalization.begin(), tracksForNormalization.end(), sort
ByGridNormalizedFlexValue); | 568 std::sort(tracksForNormalization.begin(), tracksForNormalization.end(), sort
ByGridNormalizedFlexValue); |
(...skipping 17 matching lines...) Expand all Loading... |
586 } | 586 } |
587 | 587 |
588 accumulatedFractions += track.m_flex; | 588 accumulatedFractions += track.m_flex; |
589 // This item was processed so we re-add its used breadth to the availabl
e space to accurately count the remaining space. | 589 // This item was processed so we re-add its used breadth to the availabl
e space to accurately count the remaining space. |
590 availableLogicalSpaceIgnoringFractionTracks += track.m_track->m_usedBrea
dth; | 590 availableLogicalSpaceIgnoringFractionTracks += track.m_track->m_usedBrea
dth; |
591 } | 591 } |
592 | 592 |
593 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; | 593 return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions; |
594 } | 594 } |
595 | 595 |
596 const GridTrackSize& RenderGrid::gridTrackSize(GridTrackSizingDirection directio
n, size_t i) const | 596 GridTrackSize RenderGrid::gridTrackSize(GridTrackSizingDirection direction, size
_t i) const |
597 { | 597 { |
598 const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style
()->gridTemplateColumns() : style()->gridTemplateRows(); | 598 bool isForColumns = direction == ForColumns; |
599 if (i >= trackStyles.size()) | 599 const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTempl
ateColumns() : style()->gridTemplateRows(); |
600 return (direction == ForColumns) ? style()->gridAutoColumns() : style()-
>gridAutoRows(); | 600 const GridTrackSize& trackSize = (i >= trackStyles.size()) ? (isForColumns ?
style()->gridAutoColumns() : style()->gridAutoRows()) : trackStyles[i]; |
601 | 601 |
602 const GridTrackSize& trackSize = trackStyles[i]; | 602 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto> (or in |
603 // If the logical width/height of the grid container is indefinite, percenta
ge values are treated as <auto>. | 603 // the case of minmax() as min-content for the first position and max-conten
t for the second). |
604 if (trackSize.isPercentage()) { | 604 Length logicalSize = isForColumns ? style()->logicalWidth() : style()->logic
alHeight(); |
605 Length logicalSize = direction == ForColumns ? style()->logicalWidth() :
style()->logicalHeight(); | 605 // FIXME: isIntrinsicOrAuto() does not fulfil the 'indefinite size' descript
ion as it does not include <percentage> |
606 if (logicalSize.isIntrinsicOrAuto()) { | 606 // of indefinite sizes. This is a broather issue as Length does not have the
required context to support it. |
607 DEFINE_STATIC_LOCAL(GridTrackSize, autoTrackSize, (Length(Auto))); | 607 if (logicalSize.isIntrinsicOrAuto()) { |
608 return autoTrackSize; | 608 const GridLength& oldMinTrackBreadth = trackSize.minTrackBreadth(); |
609 } | 609 const GridLength& oldMaxTrackBreadth = trackSize.maxTrackBreadth(); |
| 610 return GridTrackSize(oldMinTrackBreadth.isPercentage() ? Length(MinConte
nt) : oldMinTrackBreadth, oldMaxTrackBreadth.isPercentage() ? Length(MaxContent)
: oldMaxTrackBreadth); |
610 } | 611 } |
611 | 612 |
612 return trackSize; | 613 return trackSize; |
613 } | 614 } |
614 | 615 |
615 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack>
& columnTracks) | 616 LayoutUnit RenderGrid::logicalHeightForChild(RenderBox& child, Vector<GridTrack>
& columnTracks) |
616 { | 617 { |
617 SubtreeLayoutScope layoutScope(child); | 618 SubtreeLayoutScope layoutScope(child); |
618 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); | 619 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverride
ContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth
() : LayoutUnit(); |
619 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); | 620 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForCh
ild(child, ForColumns, columnTracks); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 } | 715 } |
715 | 716 |
716 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, RenderBox& gridItem, FilterFunc
tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette
r, AccumulatorGrowFunction trackGrowthFunction) | 717 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, RenderBox& gridItem, FilterFunc
tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette
r, AccumulatorGrowFunction trackGrowthFunction) |
717 { | 718 { |
718 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); | 719 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); |
719 const GridResolvedPosition initialTrackPosition = (direction == ForColumns)
? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo
sition; | 720 const GridResolvedPosition initialTrackPosition = (direction == ForColumns)
? coordinate.columns.resolvedInitialPosition : coordinate.rows.resolvedInitialPo
sition; |
720 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ?
coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition
; | 721 const GridResolvedPosition finalTrackPosition = (direction == ForColumns) ?
coordinate.columns.resolvedFinalPosition : coordinate.rows.resolvedFinalPosition
; |
721 | 722 |
722 sizingData.filteredTracks.shrink(0); | 723 sizingData.filteredTracks.shrink(0); |
723 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio
n <= finalTrackPosition; ++trackPosition) { | 724 for (GridResolvedPosition trackPosition = initialTrackPosition; trackPositio
n <= finalTrackPosition; ++trackPosition) { |
724 const GridTrackSize& trackSize = gridTrackSize(direction, trackPosition.
toInt()); | 725 GridTrackSize trackSize = gridTrackSize(direction, trackPosition.toInt()
); |
725 if (!(trackSize.*filterFunction)()) | 726 if (!(trackSize.*filterFunction)()) |
726 continue; | 727 continue; |
727 | 728 |
728 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; | 729 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackPosition.toInt()] : sizingData.rowTracks[trackPosition.toInt()]; |
729 sizingData.filteredTracks.append(&track); | 730 sizingData.filteredTracks.append(&track); |
730 } | 731 } |
731 | 732 |
732 if (sizingData.filteredTracks.isEmpty()) | 733 if (sizingData.filteredTracks.isEmpty()) |
733 return; | 734 return; |
734 | 735 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 LayoutUnit growth = sizingData.distributeTrackVector[i] - (tracks[i]->*t
rackGetter)(); | 795 LayoutUnit growth = sizingData.distributeTrackVector[i] - (tracks[i]->*t
rackGetter)(); |
795 if (growth >= 0) | 796 if (growth >= 0) |
796 (tracks[i]->*trackGrowthFunction)(growth); | 797 (tracks[i]->*trackGrowthFunction)(growth); |
797 } | 798 } |
798 } | 799 } |
799 | 800 |
800 #if ENABLE(ASSERT) | 801 #if ENABLE(ASSERT) |
801 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire
ction, const Vector<GridTrack>& tracks) | 802 bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection dire
ction, const Vector<GridTrack>& tracks) |
802 { | 803 { |
803 for (size_t i = 0; i < tracks.size(); ++i) { | 804 for (size_t i = 0; i < tracks.size(); ++i) { |
804 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 805 GridTrackSize trackSize = gridTrackSize(direction, i); |
805 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); | 806 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); |
806 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].m_usedBreadth) | 807 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i
].m_usedBreadth) |
807 return false; | 808 return false; |
808 } | 809 } |
809 return true; | 810 return true; |
810 } | 811 } |
811 #endif | 812 #endif |
812 | 813 |
813 void RenderGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde
x) | 814 void RenderGrid::ensureGridSize(size_t maximumRowIndex, size_t maximumColumnInde
x) |
814 { | 815 { |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 if (isOutOfFlowPositioned()) | 1455 if (isOutOfFlowPositioned()) |
1455 return "RenderGrid (positioned)"; | 1456 return "RenderGrid (positioned)"; |
1456 if (isAnonymous()) | 1457 if (isAnonymous()) |
1457 return "RenderGrid (generated)"; | 1458 return "RenderGrid (generated)"; |
1458 if (isRelPositioned()) | 1459 if (isRelPositioned()) |
1459 return "RenderGrid (relative positioned)"; | 1460 return "RenderGrid (relative positioned)"; |
1460 return "RenderGrid"; | 1461 return "RenderGrid"; |
1461 } | 1462 } |
1462 | 1463 |
1463 } // namespace blink | 1464 } // namespace blink |
OLD | NEW |