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 15 matching lines...) Expand all Loading... | |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/rendering/RenderGrid.h" | 27 #include "core/rendering/RenderGrid.h" |
28 | 28 |
29 #include "core/paint/GridPainter.h" | 29 #include "core/paint/GridPainter.h" |
30 #include "core/rendering/RenderLayer.h" | 30 #include "core/rendering/RenderLayer.h" |
31 #include "core/rendering/RenderView.h" | 31 #include "core/rendering/RenderView.h" |
32 #include "core/rendering/TextAutosizer.h" | 32 #include "core/rendering/TextAutosizer.h" |
33 #include "core/rendering/style/GridCoordinate.h" | 33 #include "core/rendering/style/GridCoordinate.h" |
34 #include "core/rendering/style/RenderStyle.h" | 34 #include "core/rendering/style/RenderStyle.h" |
35 #include "platform/LengthFunctions.h" | 35 #include "platform/LengthFunctions.h" |
36 #include "wtf/VectorTraits.h" | |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 static const int infinity = -1; | 40 static const int infinity = -1; |
40 | 41 |
41 class GridTrack { | 42 class GridTrack { |
42 public: | 43 public: |
43 GridTrack() | 44 GridTrack() |
44 : m_usedBreadth(0) | 45 : m_usedBreadth(0) |
45 , m_maxBreadth(0) | 46 , m_maxBreadth(0) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 private: | 166 private: |
166 const GridRepresentation& m_grid; | 167 const GridRepresentation& m_grid; |
167 GridTrackSizingDirection m_direction; | 168 GridTrackSizingDirection m_direction; |
168 size_t m_rowIndex; | 169 size_t m_rowIndex; |
169 size_t m_columnIndex; | 170 size_t m_columnIndex; |
170 size_t m_childIndex; | 171 size_t m_childIndex; |
171 }; | 172 }; |
172 | 173 |
173 struct RenderGrid::GridSizingData { | 174 struct RenderGrid::GridSizingData { |
174 WTF_MAKE_NONCOPYABLE(GridSizingData); | 175 WTF_MAKE_NONCOPYABLE(GridSizingData); |
176 STACK_ALLOCATED(); | |
175 public: | 177 public: |
176 GridSizingData(size_t gridColumnCount, size_t gridRowCount) | 178 GridSizingData(size_t gridColumnCount, size_t gridRowCount) |
177 : columnTracks(gridColumnCount) | 179 : columnTracks(gridColumnCount) |
178 , rowTracks(gridRowCount) | 180 , rowTracks(gridRowCount) |
179 { | 181 { |
180 } | 182 } |
181 | 183 |
182 Vector<GridTrack> columnTracks; | 184 Vector<GridTrack> columnTracks; |
183 Vector<GridTrack> rowTracks; | 185 Vector<GridTrack> rowTracks; |
184 Vector<size_t> contentSizedTracksIndex; | 186 Vector<size_t> contentSizedTracksIndex; |
185 | 187 |
186 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. | 188 // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free. |
187 Vector<LayoutUnit> distributeTrackVector; | 189 Vector<LayoutUnit> distributeTrackVector; |
188 Vector<GridTrack*> filteredTracks; | 190 Vector<GridTrack*> filteredTracks; |
189 Vector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 191 WillBeHeapVector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
190 }; | 192 }; |
191 | 193 |
192 RenderGrid::RenderGrid(Element* element) | 194 RenderGrid::RenderGrid(Element* element) |
193 : RenderBlock(element) | 195 : RenderBlock(element) |
194 , m_gridIsDirty(true) | 196 , m_gridIsDirty(true) |
195 , m_orderIterator(this) | 197 , m_orderIterator(this) |
196 { | 198 { |
197 ASSERT(!childrenInline()); | 199 ASSERT(!childrenInline()); |
198 } | 200 } |
199 | 201 |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 | 663 |
662 return logicalHeightForChild(child, columnTracks); | 664 return logicalHeightForChild(child, columnTracks); |
663 } | 665 } |
664 | 666 |
665 // We're basically using a class instead of a std::pair for two reasons. First o f all, accessing gridItem() or | 667 // We're basically using a class instead of a std::pair for two reasons. First o f all, accessing gridItem() or |
666 // coordinate() is much more self-explanatory that using .first or .second membe rs in the pair. Secondly the class | 668 // coordinate() is much more self-explanatory that using .first or .second membe rs in the pair. Secondly the class |
667 // allows us to precompute the value of the span, something which is quite conve nient for the sorting. Having a | 669 // allows us to precompute the value of the span, something which is quite conve nient for the sorting. Having a |
668 // std::pair<RenderBox*, size_t> does not work either because we still need the GridCoordinate so we'd have to add an | 670 // std::pair<RenderBox*, size_t> does not work either because we still need the GridCoordinate so we'd have to add an |
669 // extra hash lookup for each item at the beginning of RenderGrid::resolveConten tBasedTrackSizingFunctionsForItems(). | 671 // extra hash lookup for each item at the beginning of RenderGrid::resolveConten tBasedTrackSizingFunctionsForItems(). |
670 class GridItemWithSpan { | 672 class GridItemWithSpan { |
673 ALLOW_ONLY_INLINE_ALLOCATION(); | |
671 public: | 674 public: |
672 GridItemWithSpan(RenderBox& gridItem, const GridCoordinate& coordinate, Grid TrackSizingDirection direction) | 675 GridItemWithSpan(RenderBox& gridItem, const GridCoordinate& coordinate, Grid TrackSizingDirection direction) |
673 : m_gridItem(gridItem) | 676 : m_gridItem(gridItem) |
674 , m_coordinate(coordinate) | 677 , m_coordinate(coordinate) |
675 { | 678 { |
676 const GridSpan& span = (direction == ForRows) ? coordinate.rows : coordi nate.columns; | 679 const GridSpan& span = (direction == ForRows) ? coordinate.rows : coordi nate.columns; |
677 m_span = span.resolvedFinalPosition.toInt() - span.resolvedInitialPositi on.toInt() + 1; | 680 m_span = span.resolvedFinalPosition.toInt() - span.resolvedInitialPositi on.toInt() + 1; |
678 } | 681 } |
679 | 682 |
680 RenderBox& gridItem() const { return *m_gridItem; } | 683 RenderBox& gridItem() const { return *m_gridItem; } |
681 GridCoordinate coordinate() const { return m_coordinate; } | 684 GridCoordinate coordinate() const { return m_coordinate; } |
682 | 685 |
683 bool operator<(const GridItemWithSpan other) const { return m_span < other.m _span; } | 686 bool operator<(const GridItemWithSpan other) const { return m_span < other.m _span; } |
684 | 687 |
688 void trace(Visitor* visitor) | |
689 { | |
690 visitor->trace(m_gridItem); | |
691 } | |
692 | |
685 private: | 693 private: |
686 RawPtrWillBeMember<RenderBox> m_gridItem; | 694 RawPtrWillBeMember<RenderBox> m_gridItem; |
687 GridCoordinate m_coordinate; | 695 GridCoordinate m_coordinate; |
688 size_t m_span; | 696 size_t m_span; |
689 }; | 697 }; |
690 | 698 |
699 } // namespace blink | |
700 | |
701 namespace WTF { | |
702 | |
703 template<> | |
704 struct VectorTraits<blink::GridItemWithSpan> : SimpleClassVectorTraits<blink::Gr idItemWithSpan> { | |
705 // needsDestruction is by default defined in terms of IsPod<>, but as | |
706 // it doesn't handle embedded structs/enums (e.g., GridCoordinate), | |
707 // override it here. | |
708 static const bool needsDestruction = false; | |
709 }; | |
haraken
2014/10/14 11:41:30
Can't we use WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS ins
sof
2014/10/14 11:47:21
Same as for GradientStop, the reason why not is th
| |
710 | |
711 } // namespace WTF | |
712 | |
713 namespace blink { | |
714 | |
691 void RenderGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) | 715 void RenderGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirectio n direction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace) |
692 { | 716 { |
693 sizingData.itemsSortedByIncreasingSpan.shrink(0); | 717 sizingData.itemsSortedByIncreasingSpan.shrink(0); |
694 HashSet<RenderBox*> itemsSet; | 718 HashSet<RenderBox*> itemsSet; |
695 size_t contentSizedTracksCount = sizingData.contentSizedTracksIndex.size(); | 719 size_t contentSizedTracksCount = sizingData.contentSizedTracksIndex.size(); |
696 for (size_t i = 0; i < contentSizedTracksCount; ++i) { | 720 for (size_t i = 0; i < contentSizedTracksCount; ++i) { |
697 GridIterator iterator(m_grid, direction, sizingData.contentSizedTracksIn dex[i]); | 721 GridIterator iterator(m_grid, direction, sizingData.contentSizedTracksIn dex[i]); |
698 while (RenderBox* gridItem = iterator.nextGridItem()) { | 722 while (RenderBox* gridItem = iterator.nextGridItem()) { |
699 if (itemsSet.add(gridItem).isNewEntry) | 723 if (itemsSet.add(gridItem).isNewEntry) |
700 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSpan(* gridItem, cachedGridCoordinate(*gridItem), direction)); | 724 sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSpan(* gridItem, cachedGridCoordinate(*gridItem), direction)); |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 if (isOutOfFlowPositioned()) | 1418 if (isOutOfFlowPositioned()) |
1395 return "RenderGrid (positioned)"; | 1419 return "RenderGrid (positioned)"; |
1396 if (isAnonymous()) | 1420 if (isAnonymous()) |
1397 return "RenderGrid (generated)"; | 1421 return "RenderGrid (generated)"; |
1398 if (isRelPositioned()) | 1422 if (isRelPositioned()) |
1399 return "RenderGrid (relative positioned)"; | 1423 return "RenderGrid (relative positioned)"; |
1400 return "RenderGrid"; | 1424 return "RenderGrid"; |
1401 } | 1425 } |
1402 | 1426 |
1403 } // namespace blink | 1427 } // namespace blink |
OLD | NEW |