| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 static LayoutGrid* createAnonymous(Document*); | 56 static LayoutGrid* createAnonymous(Document*); |
| 57 const char* name() const override { return "LayoutGrid"; } | 57 const char* name() const override { return "LayoutGrid"; } |
| 58 | 58 |
| 59 void layoutBlock(bool relayoutChildren) override; | 59 void layoutBlock(bool relayoutChildren) override; |
| 60 | 60 |
| 61 void dirtyGrid(); | 61 void dirtyGrid(); |
| 62 | 62 |
| 63 Vector<LayoutUnit> trackSizesForComputedStyle(GridTrackSizingDirection) const; | 63 Vector<LayoutUnit> trackSizesForComputedStyle(GridTrackSizingDirection) const; |
| 64 | 64 |
| 65 const Vector<LayoutUnit>& columnPositions() const { | 65 const Vector<LayoutUnit>& columnPositions() const { |
| 66 ASSERT(!m_gridIsDirty); | 66 DCHECK(!m_grid.needsItemsPlacement()); |
| 67 return m_columnPositions; | 67 return m_columnPositions; |
| 68 } | 68 } |
| 69 | 69 |
| 70 const Vector<LayoutUnit>& rowPositions() const { | 70 const Vector<LayoutUnit>& rowPositions() const { |
| 71 ASSERT(!m_gridIsDirty); | 71 DCHECK(!m_grid.needsItemsPlacement()); |
| 72 return m_rowPositions; | 72 return m_rowPositions; |
| 73 } | 73 } |
| 74 | 74 |
| 75 typedef Vector<LayoutBox*, 1> GridCell; | 75 typedef Vector<LayoutBox*, 1> GridCell; |
| 76 const GridCell& gridCell(int row, int column) const { | 76 const GridCell& gridCell(int row, int column) const { |
| 77 SECURITY_DCHECK(!m_gridIsDirty); | 77 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); |
| 78 return m_grid.cell(row, column); | 78 return m_grid.cell(row, column); |
| 79 } | 79 } |
| 80 | 80 |
| 81 const Vector<LayoutBox*>& itemsOverflowingGridArea() const { | 81 const Vector<LayoutBox*>& itemsOverflowingGridArea() const { |
| 82 SECURITY_DCHECK(!m_gridIsDirty); | 82 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); |
| 83 return m_gridItemsOverflowingGridArea; | 83 return m_gridItemsOverflowingGridArea; |
| 84 } | 84 } |
| 85 | 85 |
| 86 int paintIndexForGridItem(const LayoutBox* layoutBox) const { | 86 int paintIndexForGridItem(const LayoutBox* layoutBox) const { |
| 87 SECURITY_DCHECK(!m_gridIsDirty); | 87 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); |
| 88 return m_grid.gridItemPaintOrder(*layoutBox); | 88 return m_grid.gridItemPaintOrder(*layoutBox); |
| 89 } | 89 } |
| 90 | 90 |
| 91 size_t autoRepeatCountForDirection(GridTrackSizingDirection direction) const { | 91 size_t autoRepeatCountForDirection(GridTrackSizingDirection direction) const { |
| 92 return m_grid.autoRepeatTracks(direction); | 92 return m_grid.autoRepeatTracks(direction); |
| 93 } | 93 } |
| 94 | 94 |
| 95 LayoutUnit translateRTLCoordinate(LayoutUnit) const; | 95 LayoutUnit translateRTLCoordinate(LayoutUnit) const; |
| 96 | 96 |
| 97 private: | 97 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 109 | 109 |
| 110 void addChild(LayoutObject* newChild, | 110 void addChild(LayoutObject* newChild, |
| 111 LayoutObject* beforeChild = nullptr) override; | 111 LayoutObject* beforeChild = nullptr) override; |
| 112 void removeChild(LayoutObject*) override; | 112 void removeChild(LayoutObject*) override; |
| 113 | 113 |
| 114 void styleDidChange(StyleDifference, const ComputedStyle*) override; | 114 void styleDidChange(StyleDifference, const ComputedStyle*) override; |
| 115 | 115 |
| 116 bool explicitGridDidResize(const ComputedStyle&) const; | 116 bool explicitGridDidResize(const ComputedStyle&) const; |
| 117 bool namedGridLinesDefinitionDidChange(const ComputedStyle&) const; | 117 bool namedGridLinesDefinitionDidChange(const ComputedStyle&) const; |
| 118 | 118 |
| 119 class Grid; |
| 119 class GridIterator; | 120 class GridIterator; |
| 120 struct GridSizingData; | 121 struct GridSizingData; |
| 121 enum SizingOperation { TrackSizing, IntrinsicSizeComputation }; | 122 enum SizingOperation { TrackSizing, IntrinsicSizeComputation }; |
| 122 void computeUsedBreadthOfGridTracks( | 123 void computeUsedBreadthOfGridTracks( |
| 123 GridTrackSizingDirection, | 124 GridTrackSizingDirection, |
| 124 GridSizingData&, | 125 GridSizingData&, |
| 125 LayoutUnit& baseSizesWithoutMaximization, | 126 LayoutUnit& baseSizesWithoutMaximization, |
| 126 LayoutUnit& growthLimitsWithoutMaximization) const; | 127 LayoutUnit& growthLimitsWithoutMaximization) const; |
| 127 void computeFlexSizedTracksGrowth( | 128 void computeFlexSizedTracksGrowth( |
| 128 GridTrackSizingDirection, | 129 GridTrackSizingDirection, |
| 129 Vector<GridTrack>&, | 130 Vector<GridTrack>&, |
| 130 const Vector<size_t>& flexibleSizedTracksIndex, | 131 const Vector<size_t>& flexibleSizedTracksIndex, |
| 131 double flexFraction, | 132 double flexFraction, |
| 132 Vector<LayoutUnit>& increments, | 133 Vector<LayoutUnit>& increments, |
| 133 LayoutUnit& totalGrowth) const; | 134 LayoutUnit& totalGrowth) const; |
| 134 LayoutUnit computeUsedBreadthOfMinLength(const GridTrackSize&, | 135 LayoutUnit computeUsedBreadthOfMinLength(const GridTrackSize&, |
| 135 LayoutUnit maxBreadth) const; | 136 LayoutUnit maxBreadth) const; |
| 136 LayoutUnit computeUsedBreadthOfMaxLength(const GridTrackSize&, | 137 LayoutUnit computeUsedBreadthOfMaxLength(const GridTrackSize&, |
| 137 LayoutUnit usedBreadth, | 138 LayoutUnit usedBreadth, |
| 138 LayoutUnit maxBreadth) const; | 139 LayoutUnit maxBreadth) const; |
| 139 void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, | 140 void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, |
| 140 GridSizingData&) const; | 141 GridSizingData&) const; |
| 141 | 142 |
| 142 size_t computeAutoRepeatTracksCount(GridTrackSizingDirection, | 143 size_t computeAutoRepeatTracksCount(GridTrackSizingDirection, |
| 143 SizingOperation) const; | 144 SizingOperation) const; |
| 144 | 145 |
| 145 typedef ListHashSet<size_t> OrderedTrackIndexSet; | 146 typedef ListHashSet<size_t> OrderedTrackIndexSet; |
| 146 std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat( | 147 std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat( |
| 148 Grid&, |
| 147 GridTrackSizingDirection) const; | 149 GridTrackSizingDirection) const; |
| 148 | 150 |
| 149 class Grid; | |
| 150 void placeItemsOnGrid(Grid&, SizingOperation); | 151 void placeItemsOnGrid(Grid&, SizingOperation); |
| 151 void populateExplicitGridAndOrderIterator(Grid&) const; | 152 void populateExplicitGridAndOrderIterator(Grid&) const; |
| 152 std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( | 153 std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( |
| 154 const Grid&, |
| 153 const LayoutBox&, | 155 const LayoutBox&, |
| 154 GridTrackSizingDirection, | 156 GridTrackSizingDirection, |
| 155 const GridSpan& specifiedPositions) const; | 157 const GridSpan& specifiedPositions) const; |
| 156 void placeSpecifiedMajorAxisItemsOnGrid(Grid&, | 158 void placeSpecifiedMajorAxisItemsOnGrid(Grid&, |
| 157 const Vector<LayoutBox*>&) const; | 159 const Vector<LayoutBox*>&) const; |
| 158 void placeAutoMajorAxisItemsOnGrid(Grid&, const Vector<LayoutBox*>&) const; | 160 void placeAutoMajorAxisItemsOnGrid(Grid&, const Vector<LayoutBox*>&) const; |
| 159 void placeAutoMajorAxisItemOnGrid( | 161 void placeAutoMajorAxisItemOnGrid( |
| 160 Grid&, | 162 Grid&, |
| 161 LayoutBox&, | 163 LayoutBox&, |
| 162 std::pair<size_t, size_t>& autoPlacementCursor) const; | 164 std::pair<size_t, size_t>& autoPlacementCursor) const; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 GridTrackSizingDirection, | 332 GridTrackSizingDirection, |
| 331 SizingOperation) const; | 333 SizingOperation) const; |
| 332 | 334 |
| 333 bool isOrthogonalChild(const LayoutBox&) const; | 335 bool isOrthogonalChild(const LayoutBox&) const; |
| 334 GridTrackSizingDirection flowAwareDirectionForChild( | 336 GridTrackSizingDirection flowAwareDirectionForChild( |
| 335 const LayoutBox&, | 337 const LayoutBox&, |
| 336 GridTrackSizingDirection) const; | 338 GridTrackSizingDirection) const; |
| 337 | 339 |
| 338 bool cachedHasDefiniteLogicalHeight() const; | 340 bool cachedHasDefiniteLogicalHeight() const; |
| 339 | 341 |
| 340 size_t numTracks(GridTrackSizingDirection) const; | 342 size_t numTracks(GridTrackSizingDirection, const Grid&) const; |
| 341 | 343 |
| 342 // TODO(svillar): move into this class once GridIterator is added. | 344 // TODO(svillar): move into this class once GridIterator is added. |
| 343 typedef Vector<Vector<GridCell>> GridAsMatrix; | 345 typedef Vector<Vector<GridCell>> GridAsMatrix; |
| 344 class Grid final { | 346 class Grid final { |
| 345 public: | 347 public: |
| 346 Grid(LayoutGrid* grid) : m_orderIterator(grid) {} | 348 Grid(LayoutGrid* grid) : m_orderIterator(grid) {} |
| 347 | 349 |
| 348 size_t numTracks(GridTrackSizingDirection) const; | 350 size_t numTracks(GridTrackSizingDirection) const; |
| 349 | 351 |
| 350 void ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize); | 352 void ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 380 void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>); | 382 void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>); |
| 381 | 383 |
| 382 size_t autoRepeatEmptyTracksCount(GridTrackSizingDirection) const; | 384 size_t autoRepeatEmptyTracksCount(GridTrackSizingDirection) const; |
| 383 bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const; | 385 bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const; |
| 384 bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, size_t) const; | 386 bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, size_t) const; |
| 385 | 387 |
| 386 OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const; | 388 OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const; |
| 387 | 389 |
| 388 OrderIterator& orderIterator() { return m_orderIterator; } | 390 OrderIterator& orderIterator() { return m_orderIterator; } |
| 389 | 391 |
| 390 void shrinkToFit() { m_grid.shrinkToFit(); } | 392 void setNeedsItemsPlacement(bool); |
| 391 void clear(); | 393 bool needsItemsPlacement() const { return m_needsItemsPlacement; }; |
| 392 | 394 |
| 393 #if ENABLE(ASSERT) | 395 #if ENABLE(ASSERT) |
| 394 bool hasAnyGridItemPaintOrder() const; | 396 bool hasAnyGridItemPaintOrder() const; |
| 395 #endif | 397 #endif |
| 396 | 398 |
| 397 private: | 399 private: |
| 398 friend class GridIterator; | 400 friend class GridIterator; |
| 399 | 401 |
| 400 OrderIterator m_orderIterator; | 402 OrderIterator m_orderIterator; |
| 401 | 403 |
| 402 int m_smallestColumnStart{0}; | 404 int m_smallestColumnStart{0}; |
| 403 int m_smallestRowStart{0}; | 405 int m_smallestRowStart{0}; |
| 404 | 406 |
| 405 size_t m_autoRepeatColumns{0}; | 407 size_t m_autoRepeatColumns{0}; |
| 406 size_t m_autoRepeatRows{0}; | 408 size_t m_autoRepeatRows{0}; |
| 407 | 409 |
| 408 bool m_hasAnyOrthogonalGridItem{false}; | 410 bool m_hasAnyOrthogonalGridItem{false}; |
| 411 bool m_needsItemsPlacement{true}; |
| 412 |
| 409 GridAsMatrix m_grid; | 413 GridAsMatrix m_grid; |
| 410 | 414 |
| 411 HashMap<const LayoutBox*, GridArea> m_gridItemArea; | 415 HashMap<const LayoutBox*, GridArea> m_gridItemArea; |
| 412 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap; | 416 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap; |
| 413 | 417 |
| 414 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns{nullptr}; | 418 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns{nullptr}; |
| 415 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows{nullptr}; | 419 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows{nullptr}; |
| 416 }; | 420 }; |
| 417 Grid m_grid; | 421 Grid m_grid; |
| 418 | 422 |
| 419 bool m_gridIsDirty; | |
| 420 Vector<LayoutUnit> m_rowPositions; | 423 Vector<LayoutUnit> m_rowPositions; |
| 421 Vector<LayoutUnit> m_columnPositions; | 424 Vector<LayoutUnit> m_columnPositions; |
| 422 LayoutUnit m_offsetBetweenColumns; | 425 LayoutUnit m_offsetBetweenColumns; |
| 423 LayoutUnit m_offsetBetweenRows; | 426 LayoutUnit m_offsetBetweenRows; |
| 424 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; | 427 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; |
| 425 | 428 |
| 426 LayoutUnit m_minContentHeight{-1}; | 429 LayoutUnit m_minContentHeight{-1}; |
| 427 LayoutUnit m_maxContentHeight{-1}; | 430 LayoutUnit m_maxContentHeight{-1}; |
| 428 | 431 |
| 429 Optional<bool> m_hasDefiniteLogicalHeight; | 432 Optional<bool> m_hasDefiniteLogicalHeight; |
| 430 }; | 433 }; |
| 431 | 434 |
| 432 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); | 435 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); |
| 433 | 436 |
| 434 } // namespace blink | 437 } // namespace blink |
| 435 | 438 |
| 436 #endif // LayoutGrid_h | 439 #endif // LayoutGrid_h |
| OLD | NEW |