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 sizingData.setAvailableSpace(availableSpace); | 411 sizingData.setAvailableSpace(availableSpace); |
412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0, direction == ForRows ? gridRowCount() : gridColumnCount()); | 412 sizingData.freeSpace(direction) = availableSpace - guttersSize(direction, 0, direction == ForRows ? gridRowCount() : gridColumnCount()); |
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) |
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 bool minContentContributionChanged = false; |
434 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | 434 for (auto* child : m_orthogonalChilds) { |
435 if (updateOverrideContainingBlockContentSizeForChild(*child, ForRows, si zingData)) | |
436 child->setNeedsLayout(LayoutInvalidationReason::GridChanged); | |
437 child->layoutIfNeeded(); | |
438 if (!minContentContributionChanged) { | |
svillar
2016/09/13 13:44:18
I don't get this. For example for the first orthog
jfernandez
2016/09/13 14:56:59
Umm, why "first orthogonal child" ? We definitivel
| |
439 LayoutUnit minContentInlineSize = child->hasOverrideContainingBlockL ogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit (); | |
440 minContentContributionChanged = child->logicalHeight() > minContentI nlineSize; | |
441 } | |
442 } | |
443 | |
444 if (minContentContributionChanged) { | |
445 setPreferredLogicalWidthsDirty(); | |
446 updateLogicalWidth(); | |
447 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); | |
448 resolveSizeOfGridRows(sizingData); | |
449 } | |
svillar
2016/09/13 13:44:18
I have many doubts about the above block. It's lik
jfernandez
2016/09/13 14:56:59
I understand your concerns. However, notice that w
| |
450 } | |
451 | |
452 void LayoutGrid::resolveSizeOfGridRows(GridSizingData& sizingData) | |
453 { | |
454 bool logicalHeightWasIndefinite = !hasDefiniteLogicalHeight(); | |
455 if (logicalHeightWasIndefinite) | |
456 computeIntrinsicLogicalHeight(sizingData); | |
457 else | |
458 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalHeigh t(ExcludeMarginBorderPadding)); | |
459 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndPaddi ngLogicalHeight() + scrollbarLogicalHeight()); | |
460 | |
461 updateLogicalHeight(); | |
462 | |
463 // The above call might have changed the grid's logical height depending on min|max height restrictions. | |
464 // Update the sizes of the rows whose size depends on the logical height (al so on definite|indefinite sizes). | |
465 LayoutUnit availableSpaceForRows = contentLogicalHeight(); | |
466 if (logicalHeightWasIndefinite) | |
435 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows ); | 467 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows ); |
436 } | |
437 } | 468 } |
438 | 469 |
439 void LayoutGrid::layoutBlock(bool relayoutChildren) | 470 void LayoutGrid::layoutBlock(bool relayoutChildren) |
440 { | 471 { |
441 ASSERT(needsLayout()); | 472 ASSERT(needsLayout()); |
442 | 473 |
443 if (!relayoutChildren && simplifiedLayout()) | 474 if (!relayoutChildren && simplifiedLayout()) |
444 return; | 475 return; |
445 | 476 |
446 SubtreeLayoutScope layoutScope(*this); | 477 SubtreeLayoutScope layoutScope(*this); |
447 | 478 |
448 { | 479 { |
449 // LayoutState needs this deliberate scope to pop before updating scroll information (which | 480 // LayoutState needs this deliberate scope to pop before updating scroll information (which |
450 // may trigger relayout). | 481 // may trigger relayout). |
451 LayoutState state(*this, locationOffset()); | 482 LayoutState state(*this, locationOffset()); |
452 | 483 |
453 LayoutSize previousSize = size(); | 484 LayoutSize previousSize = size(); |
454 | 485 |
455 updateLogicalWidth(); | 486 updateLogicalWidth(); |
456 bool logicalHeightWasIndefinite = !hasDefiniteLogicalHeight(); | |
457 | 487 |
458 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); | 488 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); |
459 | 489 |
460 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated | 490 // TODO(svillar): we won't need to do this once the intrinsic width comp utation is isolated |
461 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) | 491 // from the LayoutGrid object state (it should not touch any attribute) (see crbug.com/627812) |
462 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing)) | 492 if (m_autoRepeatColumns && m_autoRepeatColumns != computeAutoRepeatTrack sCount(ForColumns, TrackSizing)) |
463 dirtyGrid(); | 493 dirtyGrid(); |
464 placeItemsOnGrid(TrackSizing); | 494 placeItemsOnGrid(TrackSizing); |
465 | 495 |
466 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 496 GridSizingData sizingData(gridColumnCount(), gridRowCount()); |
467 | 497 |
468 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. | 498 // 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() | 499 // 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 | 500 // 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 | 501 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve |
472 // heights properly (like for positioned items for example). | 502 // heights properly (like for positioned items for example). |
473 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 503 computeTrackSizesForDirection(ForColumns, sizingData, availableLogicalWi dth()); |
474 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); | |
475 | 504 |
476 // 2- Next, the track sizing algorithm resolves the sizes of the grid ro ws, using the | 505 // 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. | 506 // grid column sizes calculated in the previous step. |
478 if (logicalHeightWasIndefinite) | |
479 computeIntrinsicLogicalHeight(sizingData); | |
480 else | |
481 computeTrackSizesForDirection(ForRows, sizingData, availableLogicalH eight(ExcludeMarginBorderPadding)); | |
482 setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndP addingLogicalHeight() + scrollbarLogicalHeight()); | |
483 | |
484 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); | 507 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); |
485 updateLogicalHeight(); | 508 resolveSizeOfGridRows(sizingData); |
486 | |
487 // The above call might have changed the grid's logical height depending on min|max height restrictions. | |
488 // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). | |
489 LayoutUnit availableSpaceForRows = contentLogicalHeight(); | |
490 if (logicalHeightWasIndefinite) | |
491 computeTrackSizesForDirection(ForRows, sizingData, availableSpaceFor Rows); | |
492 | 509 |
493 // 3- If the min-content contribution of any grid items have changed bas ed on the row | 510 // 3- If the min-content contribution of any grid items have changed bas ed on the row |
494 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content | 511 // sizes calculated in step 2, steps 1 and 2 are repeated with the new m in-content |
495 // contribution (once only). | 512 // contribution (once only). |
496 repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, availab leSpaceForRows); | 513 repeatTracksSizingIfNeeded(sizingData); |
497 | 514 |
498 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. | 515 // Grid container should have the minimum height of a line if it's edita ble. That doesn't affect track sizing though. |
499 if (hasLineIfEmpty()) | 516 if (hasLineIfEmpty()) |
500 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); | 517 setLogicalHeight(std::max(logicalHeight(), minimumLogicalHeightForEm ptyLine())); |
501 | 518 |
502 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); | 519 applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData); |
503 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); | 520 applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData); |
504 | 521 |
505 layoutGridItems(sizingData); | 522 layoutGridItems(sizingData); |
506 | 523 |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1558 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizingOpe ration); | 1575 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, sizingOpe ration); |
1559 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation); | 1576 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows, sizingOperation); |
1560 | 1577 |
1561 populateExplicitGridAndOrderIterator(); | 1578 populateExplicitGridAndOrderIterator(); |
1562 | 1579 |
1563 // We clear the dirty bit here as the grid sizes have been updated. | 1580 // We clear the dirty bit here as the grid sizes have been updated. |
1564 m_gridIsDirty = false; | 1581 m_gridIsDirty = false; |
1565 | 1582 |
1566 Vector<LayoutBox*> autoMajorAxisAutoGridItems; | 1583 Vector<LayoutBox*> autoMajorAxisAutoGridItems; |
1567 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; | 1584 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; |
1568 m_hasAnyOrthogonalChild = false; | 1585 m_orthogonalChilds.shrink(0); |
1569 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { | 1586 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) { |
1570 if (child->isOutOfFlowPositioned()) | 1587 if (child->isOutOfFlowPositioned()) |
1571 continue; | 1588 continue; |
1572 | 1589 |
1573 m_hasAnyOrthogonalChild = m_hasAnyOrthogonalChild || isOrthogonalChild(* child); | 1590 if (isOrthogonalChild(*child)) |
1591 m_orthogonalChilds.append(child); | |
1574 | 1592 |
1575 GridArea area = cachedGridArea(*child); | 1593 GridArea area = cachedGridArea(*child); |
1576 if (!area.rows.isIndefinite()) | 1594 if (!area.rows.isIndefinite()) |
1577 area.rows.translate(abs(m_smallestRowStart)); | 1595 area.rows.translate(abs(m_smallestRowStart)); |
1578 if (!area.columns.isIndefinite()) | 1596 if (!area.columns.isIndefinite()) |
1579 area.columns.translate(abs(m_smallestColumnStart)); | 1597 area.columns.translate(abs(m_smallestColumnStart)); |
1580 m_gridItemArea.set(child, area); | 1598 m_gridItemArea.set(child, area); |
1581 | 1599 |
1582 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { | 1600 if (area.rows.isIndefinite() || area.columns.isIndefinite()) { |
1583 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; | 1601 GridSpan majorAxisPositions = (autoPlacementMajorAxisDirection() == ForColumns) ? area.columns : area.rows; |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2656 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; | 2674 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; |
2657 } | 2675 } |
2658 | 2676 |
2659 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const | 2677 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const |
2660 { | 2678 { |
2661 if (!m_gridItemArea.isEmpty()) | 2679 if (!m_gridItemArea.isEmpty()) |
2662 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 2680 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
2663 } | 2681 } |
2664 | 2682 |
2665 } // namespace blink | 2683 } // namespace blink |
OLD | NEW |