| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool LayoutGrid::namedGridLinesDefinitionDidChange( | 395 bool LayoutGrid::namedGridLinesDefinitionDidChange( |
| 396 const ComputedStyle& oldStyle) const { | 396 const ComputedStyle& oldStyle) const { |
| 397 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || | 397 return oldStyle.namedGridRowLines() != styleRef().namedGridRowLines() || |
| 398 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); | 398 oldStyle.namedGridColumnLines() != styleRef().namedGridColumnLines(); |
| 399 } | 399 } |
| 400 | 400 |
| 401 size_t LayoutGrid::gridColumnCount() const { | 401 size_t LayoutGrid::gridColumnCount() const { |
| 402 DCHECK(!m_gridIsDirty); | 402 DCHECK(!m_gridIsDirty); |
| 403 // Due to limitations in our internal representation, we cannot know the | 403 return m_grid.size() ? m_grid[0].size() : 0; |
| 404 // number of columns from m_grid *if* there is no row (because m_grid would be | |
| 405 // empty). That's why in that case we need to get it from the style. Note that | |
| 406 // we know for sure that there are't any implicit tracks, because not having | |
| 407 // rows implies that there are no "normal" children (out-of-flow children are | |
| 408 // not stored in m_grid). | |
| 409 return m_grid.size() ? m_grid[0].size() | |
| 410 : GridPositionsResolver::explicitGridColumnCount( | |
| 411 styleRef(), m_autoRepeatColumns); | |
| 412 } | 404 } |
| 413 | 405 |
| 414 size_t LayoutGrid::gridRowCount() const { | 406 size_t LayoutGrid::gridRowCount() const { |
| 415 DCHECK(!m_gridIsDirty); | 407 DCHECK(!m_gridIsDirty); |
| 416 return m_grid.size(); | 408 return m_grid.size(); |
| 417 } | 409 } |
| 418 | 410 |
| 419 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( | 411 LayoutUnit LayoutGrid::computeTrackBasedLogicalHeight( |
| 420 const GridSizingData& sizingData) const { | 412 const GridSizingData& sizingData) const { |
| 421 LayoutUnit logicalHeight; | 413 LayoutUnit logicalHeight; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 504 |
| 513 // TODO(svillar): we won't need to do this once the intrinsic width | 505 // TODO(svillar): we won't need to do this once the intrinsic width |
| 514 // computation is isolated from the LayoutGrid object state (it should not | 506 // computation is isolated from the LayoutGrid object state (it should not |
| 515 // touch any attribute) (see crbug.com/627812) | 507 // touch any attribute) (see crbug.com/627812) |
| 516 if (m_autoRepeatColumns && | 508 if (m_autoRepeatColumns && |
| 517 m_autoRepeatColumns != | 509 m_autoRepeatColumns != |
| 518 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) | 510 computeAutoRepeatTracksCount(ForColumns, TrackSizing)) |
| 519 dirtyGrid(); | 511 dirtyGrid(); |
| 520 placeItemsOnGrid(TrackSizing); | 512 placeItemsOnGrid(TrackSizing); |
| 521 | 513 |
| 522 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 514 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); |
| 523 | 515 |
| 524 // 1- First, the track sizing algorithm is used to resolve the sizes of the | 516 // 1- First, the track sizing algorithm is used to resolve the sizes of the |
| 525 // grid columns. | 517 // grid columns. |
| 526 // At this point the logical width is always definite as the above call to | 518 // At this point the logical width is always definite as the above call to |
| 527 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the | 519 // updateLogicalWidth() properly resolves intrinsic sizes. We cannot do the |
| 528 // same for heights though because many code paths inside | 520 // same for heights though because many code paths inside |
| 529 // updateLogicalHeight() require a previous call to setLogicalHeight() to | 521 // updateLogicalHeight() require a previous call to setLogicalHeight() to |
| 530 // resolve heights properly (like for positioned items for example). | 522 // resolve heights properly (like for positioned items for example). |
| 531 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 523 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
| 532 computeTrackSizesForDefiniteSize(ForColumns, sizingData, | 524 computeTrackSizesForDefiniteSize(ForColumns, sizingData, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 } | 680 } |
| 689 | 681 |
| 690 return gapAccumulator; | 682 return gapAccumulator; |
| 691 } | 683 } |
| 692 | 684 |
| 693 void LayoutGrid::computeIntrinsicLogicalWidths( | 685 void LayoutGrid::computeIntrinsicLogicalWidths( |
| 694 LayoutUnit& minLogicalWidth, | 686 LayoutUnit& minLogicalWidth, |
| 695 LayoutUnit& maxLogicalWidth) const { | 687 LayoutUnit& maxLogicalWidth) const { |
| 696 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); | 688 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation); |
| 697 | 689 |
| 698 GridSizingData sizingData(gridColumnCount(), gridRowCount()); | 690 GridSizingData sizingData(numTracks(ForColumns), numTracks(ForRows)); |
| 699 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, | 691 computeTrackSizesForIndefiniteSize(ForColumns, sizingData, minLogicalWidth, |
| 700 maxLogicalWidth); | 692 maxLogicalWidth); |
| 701 | 693 |
| 702 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); | 694 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); |
| 703 minLogicalWidth += scrollbarWidth; | 695 minLogicalWidth += scrollbarWidth; |
| 704 maxLogicalWidth += scrollbarWidth; | 696 maxLogicalWidth += scrollbarWidth; |
| 705 } | 697 } |
| 706 | 698 |
| 707 void LayoutGrid::computeTrackSizesForIndefiniteSize( | 699 void LayoutGrid::computeTrackSizesForIndefiniteSize( |
| 708 GridTrackSizingDirection direction, | 700 GridTrackSizingDirection direction, |
| (...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 : area.rows; | 2010 : area.rows; |
| 2019 if (majorAxisPositions.isIndefinite()) | 2011 if (majorAxisPositions.isIndefinite()) |
| 2020 autoMajorAxisAutoGridItems.append(child); | 2012 autoMajorAxisAutoGridItems.append(child); |
| 2021 else | 2013 else |
| 2022 specifiedMajorAxisAutoGridItems.append(child); | 2014 specifiedMajorAxisAutoGridItems.append(child); |
| 2023 continue; | 2015 continue; |
| 2024 } | 2016 } |
| 2025 insertItemIntoGrid(*child, area); | 2017 insertItemIntoGrid(*child, area); |
| 2026 } | 2018 } |
| 2027 | 2019 |
| 2028 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( | 2020 #if ENABLE(ASSERT) |
| 2029 *style(), m_autoRepeatRows)); | 2021 if (!m_gridItemArea.isEmpty()) { |
| 2030 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( | 2022 DCHECK_GE(gridRowCount(), GridPositionsResolver::explicitGridRowCount( |
| 2031 *style(), m_autoRepeatColumns)); | 2023 *style(), m_autoRepeatRows)); |
| 2024 DCHECK_GE(gridColumnCount(), GridPositionsResolver::explicitGridColumnCount( |
| 2025 *style(), m_autoRepeatColumns)); |
| 2026 } |
| 2027 #endif |
| 2032 | 2028 |
| 2033 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 2029 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
| 2034 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 2030 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
| 2035 | 2031 |
| 2036 m_grid.shrinkToFit(); | 2032 m_grid.shrinkToFit(); |
| 2037 | 2033 |
| 2038 // Compute collapsable tracks for auto-fit. | 2034 // Compute collapsable tracks for auto-fit. |
| 2039 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); | 2035 m_autoRepeatEmptyColumns = computeEmptyTracksForAutoRepeat(ForColumns); |
| 2040 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); | 2036 m_autoRepeatEmptyRows = computeEmptyTracksForAutoRepeat(ForRows); |
| 2041 | 2037 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2535 // tracks per spec. | 2531 // tracks per spec. |
| 2536 int smallestStart = | 2532 int smallestStart = |
| 2537 abs(isForColumns ? m_smallestColumnStart : m_smallestRowStart); | 2533 abs(isForColumns ? m_smallestColumnStart : m_smallestRowStart); |
| 2538 int startLine = positions.untranslatedStartLine() + smallestStart; | 2534 int startLine = positions.untranslatedStartLine() + smallestStart; |
| 2539 int endLine = positions.untranslatedEndLine() + smallestStart; | 2535 int endLine = positions.untranslatedEndLine() + smallestStart; |
| 2540 | 2536 |
| 2541 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() | 2537 GridPosition startPosition = isForColumns ? child.style()->gridColumnStart() |
| 2542 : child.style()->gridRowStart(); | 2538 : child.style()->gridRowStart(); |
| 2543 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() | 2539 GridPosition endPosition = isForColumns ? child.style()->gridColumnEnd() |
| 2544 : child.style()->gridRowEnd(); | 2540 : child.style()->gridRowEnd(); |
| 2545 int lastLine = isForColumns ? gridColumnCount() : gridRowCount(); | 2541 int lastLine = numTracks(direction); |
| 2546 | 2542 |
| 2547 bool startIsAuto = | 2543 bool startIsAuto = |
| 2548 startPosition.isAuto() || | 2544 startPosition.isAuto() || |
| 2549 (startPosition.isNamedGridArea() && | 2545 (startPosition.isNamedGridArea() && |
| 2550 !NamedLineCollection::isValidNamedLineOrArea( | 2546 !NamedLineCollection::isValidNamedLineOrArea( |
| 2551 startPosition.namedGridLine(), styleRef(), | 2547 startPosition.namedGridLine(), styleRef(), |
| 2552 GridPositionsResolver::initialPositionSide(direction))) || | 2548 GridPositionsResolver::initialPositionSide(direction))) || |
| 2553 (startLine < 0) || (startLine > lastLine); | 2549 (startLine < 0) || (startLine > lastLine); |
| 2554 bool endIsAuto = endPosition.isAuto() || | 2550 bool endIsAuto = endPosition.isAuto() || |
| 2555 (endPosition.isNamedGridArea() && | 2551 (endPosition.isNamedGridArea() && |
| (...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 const LayoutPoint& paintOffset) const { | 3487 const LayoutPoint& paintOffset) const { |
| 3492 if (!m_gridItemArea.isEmpty()) | 3488 if (!m_gridItemArea.isEmpty()) |
| 3493 GridPainter(*this).paintChildren(paintInfo, paintOffset); | 3489 GridPainter(*this).paintChildren(paintInfo, paintOffset); |
| 3494 } | 3490 } |
| 3495 | 3491 |
| 3496 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { | 3492 bool LayoutGrid::cachedHasDefiniteLogicalHeight() const { |
| 3497 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); | 3493 SECURITY_DCHECK(m_hasDefiniteLogicalHeight); |
| 3498 return m_hasDefiniteLogicalHeight.value(); | 3494 return m_hasDefiniteLogicalHeight.value(); |
| 3499 } | 3495 } |
| 3500 | 3496 |
| 3497 size_t LayoutGrid::numTracks(GridTrackSizingDirection direction) const { |
| 3498 // Due to limitations in our internal representation, we cannot know the |
| 3499 // number of columns from m_grid *if* there is no row (because m_grid would be |
| 3500 // empty). That's why in that case we need to get it from the style. Note that |
| 3501 // we know for sure that there are't any implicit tracks, because not having |
| 3502 // rows implies that there are no "normal" children (out-of-flow children are |
| 3503 // not stored in m_grid). |
| 3504 if (direction == ForRows) |
| 3505 return m_grid.size(); |
| 3506 |
| 3507 return m_grid.size() ? m_grid[0].size() |
| 3508 : GridPositionsResolver::explicitGridColumnCount( |
| 3509 styleRef(), m_autoRepeatColumns); |
| 3510 } |
| 3511 |
| 3501 } // namespace blink | 3512 } // namespace blink |
| OLD | NEW |