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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 ASSERT(!specifiedMajorAxisAutoGridItems.size()); | 655 ASSERT(!specifiedMajorAxisAutoGridItems.size()); |
656 return; | 656 return; |
657 } | 657 } |
658 | 658 |
659 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 659 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
660 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 660 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
661 } | 661 } |
662 | 662 |
663 void RenderGrid::populateExplicitGridAndOrderIterator() | 663 void RenderGrid::populateExplicitGridAndOrderIterator() |
664 { | 664 { |
665 // FIXME: We should find a way to share OrderIterator's Vector's | 665 OrderIteratorPopulator populator(m_orderIterator); |
666 // initialization code with RenderFlexibleBox. | |
667 Vector<int> orderValues; | |
668 bool anyChildHasDefaultOrderValue = false; | |
669 | 666 |
670 size_t maximumRowIndex = std::max<size_t>(1, explicitGridRowCount()); | 667 size_t maximumRowIndex = std::max<size_t>(1, explicitGridRowCount()); |
671 size_t maximumColumnIndex = std::max<size_t>(1, explicitGridColumnCount()); | 668 size_t maximumColumnIndex = std::max<size_t>(1, explicitGridColumnCount()); |
672 | 669 |
673 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 670 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
674 // Avoid growing the vector for the common-case default value of 0. | 671 populator.collectChild(child); |
675 if (int order = child->style()->order()) | |
676 orderValues.append(child->style()->order()); | |
677 else | |
678 anyChildHasDefaultOrderValue = true; | |
679 | 672 |
680 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. | 673 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. |
681 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(child, For
Rows); | 674 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(child, For
Rows); |
682 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(child,
ForColumns); | 675 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(child,
ForColumns); |
683 | 676 |
684 // |positions| is 0 if we need to run the auto-placement algorithm. Our
estimation ignores | 677 // |positions| is 0 if we need to run the auto-placement algorithm. Our
estimation ignores |
685 // this case as the auto-placement algorithm will grow the grid as neede
d. | 678 // this case as the auto-placement algorithm will grow the grid as neede
d. |
686 if (rowPositions) | 679 if (rowPositions) |
687 maximumRowIndex = std::max(maximumRowIndex, rowPositions->finalPosit
ionIndex + 1); | 680 maximumRowIndex = std::max(maximumRowIndex, rowPositions->finalPosit
ionIndex + 1); |
688 if (columnPositions) | 681 if (columnPositions) |
689 maximumColumnIndex = std::max(maximumColumnIndex, columnPositions->f
inalPositionIndex + 1); | 682 maximumColumnIndex = std::max(maximumColumnIndex, columnPositions->f
inalPositionIndex + 1); |
690 } | 683 } |
691 | 684 |
692 m_grid.grow(maximumRowIndex); | 685 m_grid.grow(maximumRowIndex); |
693 for (size_t i = 0; i < m_grid.size(); ++i) | 686 for (size_t i = 0; i < m_grid.size(); ++i) |
694 m_grid[i].grow(maximumColumnIndex); | 687 m_grid[i].grow(maximumColumnIndex); |
695 | |
696 if (anyChildHasDefaultOrderValue) { | |
697 // Avoid growing the vector to the default capacity of 16 if we're only
going to put one item in it. | |
698 if (orderValues.isEmpty()) | |
699 orderValues.reserveInitialCapacity(1); | |
700 orderValues.append(0); | |
701 } | |
702 | |
703 m_orderIterator.setOrderValues(orderValues); | |
704 } | 688 } |
705 | 689 |
706 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(Vector<RenderBox*> autoGridI
tems) | 690 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(Vector<RenderBox*> autoGridI
tems) |
707 { | 691 { |
708 for (size_t i = 0; i < autoGridItems.size(); ++i) { | 692 for (size_t i = 0; i < autoGridItems.size(); ++i) { |
709 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); | 693 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); |
710 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex); | 694 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex); |
711 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ | 695 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ |
712 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex, emptyGridArea->columns.initialPositionIndex); | 696 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex, emptyGridArea->columns.initialPositionIndex); |
713 continue; | 697 continue; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 if (isOutOfFlowPositioned()) | 1051 if (isOutOfFlowPositioned()) |
1068 return "RenderGrid (positioned)"; | 1052 return "RenderGrid (positioned)"; |
1069 if (isAnonymous()) | 1053 if (isAnonymous()) |
1070 return "RenderGrid (generated)"; | 1054 return "RenderGrid (generated)"; |
1071 if (isRelPositioned()) | 1055 if (isRelPositioned()) |
1072 return "RenderGrid (relative positioned)"; | 1056 return "RenderGrid (relative positioned)"; |
1073 return "RenderGrid"; | 1057 return "RenderGrid"; |
1074 } | 1058 } |
1075 | 1059 |
1076 } // namespace WebCore | 1060 } // namespace WebCore |
OLD | NEW |