| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #ifndef RenderGrid_h | |
| 27 #define RenderGrid_h | |
| 28 | |
| 29 #include "core/layout/OrderIterator.h" | |
| 30 #include "core/layout/style/GridResolvedPosition.h" | |
| 31 #include "core/rendering/RenderBlock.h" | |
| 32 | |
| 33 namespace blink { | |
| 34 | |
| 35 struct GridCoordinate; | |
| 36 struct GridSpan; | |
| 37 class GridTrack; | |
| 38 class GridItemWithSpan; | |
| 39 | |
| 40 class RenderGrid final : public RenderBlock { | |
| 41 public: | |
| 42 RenderGrid(Element*); | |
| 43 virtual ~RenderGrid(); | |
| 44 | |
| 45 virtual const char* renderName() const override; | |
| 46 | |
| 47 virtual void layoutBlock(bool relayoutChildren) override; | |
| 48 | |
| 49 virtual bool canCollapseAnonymousBlockChild() const override { return false;
} | |
| 50 | |
| 51 void dirtyGrid(); | |
| 52 | |
| 53 const Vector<LayoutUnit>& columnPositions() const { return m_columnPositions
; } | |
| 54 const Vector<LayoutUnit>& rowPositions() const { return m_rowPositions; } | |
| 55 | |
| 56 typedef Vector<LayoutBox*, 1> GridCell; | |
| 57 const GridCell& gridCell(int row, int column) { return m_grid[row][column];
} | |
| 58 const Vector<LayoutBox*>& itemsOverflowingGridArea() { return m_gridItemsOve
rflowingGridArea; } | |
| 59 int paintIndexForGridItem(const LayoutBox* layoutBox) { return m_gridItemsIn
dexesMap.get(layoutBox); } | |
| 60 | |
| 61 bool gridIsDirty() const { return m_gridIsDirty; } | |
| 62 | |
| 63 typedef void (GridTrack::* AccumulatorGrowFunction)(LayoutUnit); | |
| 64 private: | |
| 65 virtual bool isOfType(LayoutObjectType type) const override { return type ==
LayoutObjectRenderGrid || RenderBlock::isOfType(type); } | |
| 66 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
utUnit& maxLogicalWidth) const override; | |
| 67 virtual void computePreferredLogicalWidths() override; | |
| 68 | |
| 69 virtual void addChild(LayoutObject* newChild, LayoutObject* beforeChild = 0)
override; | |
| 70 virtual void removeChild(LayoutObject*) override; | |
| 71 | |
| 72 virtual void styleDidChange(StyleDifference, const LayoutStyle*) override; | |
| 73 | |
| 74 bool explicitGridDidResize(const LayoutStyle&) const; | |
| 75 bool namedGridLinesDefinitionDidChange(const LayoutStyle&) const; | |
| 76 | |
| 77 class GridIterator; | |
| 78 struct GridSizingData; | |
| 79 bool gridElementIsShrinkToFit(); | |
| 80 void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData
&); | |
| 81 void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData
&, LayoutUnit& availableLogicalSpace); | |
| 82 LayoutUnit computeUsedBreadthOfMinLength(GridTrackSizingDirection, const Gri
dLength&) const; | |
| 83 LayoutUnit computeUsedBreadthOfMaxLength(GridTrackSizingDirection, const Gri
dLength&, LayoutUnit usedBreadth) const; | |
| 84 LayoutUnit computeUsedBreadthOfSpecifiedLength(GridTrackSizingDirection, con
st Length&) const; | |
| 85 void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, GridS
izingData&, LayoutUnit& availableLogicalSpace); | |
| 86 | |
| 87 void ensureGridSize(size_t maximumRowIndex, size_t maximumColumnIndex); | |
| 88 void insertItemIntoGrid(LayoutBox&, const GridCoordinate&); | |
| 89 void placeItemsOnGrid(); | |
| 90 void populateExplicitGridAndOrderIterator(); | |
| 91 PassOwnPtr<GridCoordinate> createEmptyGridAreaAtSpecifiedPositionsOutsideGri
d(const LayoutBox&, GridTrackSizingDirection, const GridSpan& specifiedPositions
) const; | |
| 92 void placeSpecifiedMajorAxisItemsOnGrid(const Vector<LayoutBox*>&); | |
| 93 void placeAutoMajorAxisItemsOnGrid(const Vector<LayoutBox*>&); | |
| 94 void placeAutoMajorAxisItemOnGrid(LayoutBox&, std::pair<size_t, size_t>& aut
oPlacementCursor); | |
| 95 GridTrackSizingDirection autoPlacementMajorAxisDirection() const; | |
| 96 GridTrackSizingDirection autoPlacementMinorAxisDirection() const; | |
| 97 | |
| 98 void layoutGridItems(); | |
| 99 void layoutPositionedObjects(bool relayoutChildren, PositionedLayoutBehavior
= DefaultLayout); | |
| 100 void offsetAndBreadthForPositionedChild(const LayoutBox&, GridTrackSizingDir
ection, bool startIsAuto, bool endIsAuto, LayoutUnit& offset, LayoutUnit& breadt
h); | |
| 101 void populateGridPositions(const GridSizingData&, LayoutUnit availableSpaceF
orColumns, LayoutUnit availableSpaceForRows); | |
| 102 | |
| 103 typedef LayoutUnit (RenderGrid::* SizingFunction)(LayoutBox&, GridTrackSizin
gDirection, Vector<GridTrack>&); | |
| 104 typedef const LayoutUnit& (GridTrack::* AccumulatorGetter)() const; | |
| 105 typedef bool (GridTrackSize::* FilterFunction)() const; | |
| 106 void resolveContentBasedTrackSizingFunctionsForNonSpanningItems(GridTrackSiz
ingDirection, const GridCoordinate&, LayoutBox& gridItem, GridTrack&, Vector<Gri
dTrack>& columnTracks); | |
| 107 void resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirectio
n, GridSizingData&, GridItemWithSpan&, FilterFunction, SizingFunction, Accumulat
orGetter, AccumulatorGrowFunction, FilterFunction growAboveMaxBreadthFilterFunct
ion = nullptr); | |
| 108 void distributeSpaceToTracks(Vector<GridTrack*>&, const Vector<GridTrack*>*
growBeyondGrowthLimitsTracks, AccumulatorGetter, AccumulatorGrowFunction, GridSi
zingData&, LayoutUnit& availableLogicalSpace); | |
| 109 | |
| 110 double computeNormalizedFractionBreadth(Vector<GridTrack>&, const GridSpan&
tracksSpan, GridTrackSizingDirection, LayoutUnit availableLogicalSpace) const; | |
| 111 | |
| 112 GridTrackSize gridTrackSize(GridTrackSizingDirection, size_t) const; | |
| 113 | |
| 114 LayoutUnit logicalHeightForChild(LayoutBox&, Vector<GridTrack>&); | |
| 115 LayoutUnit minContentForChild(LayoutBox&, GridTrackSizingDirection, Vector<G
ridTrack>& columnTracks); | |
| 116 LayoutUnit maxContentForChild(LayoutBox&, GridTrackSizingDirection, Vector<G
ridTrack>& columnTracks); | |
| 117 LayoutUnit startOfColumnForChild(const LayoutBox& child) const; | |
| 118 LayoutUnit endOfColumnForChild(const LayoutBox& child) const; | |
| 119 LayoutUnit columnPositionLeft(const LayoutBox&) const; | |
| 120 LayoutUnit columnPositionRight(const LayoutBox&) const; | |
| 121 LayoutUnit centeredColumnPositionForChild(const LayoutBox&) const; | |
| 122 LayoutUnit columnPositionForChild(const LayoutBox&) const; | |
| 123 LayoutUnit startOfRowForChild(const LayoutBox& child) const; | |
| 124 LayoutUnit endOfRowForChild(const LayoutBox& child) const; | |
| 125 LayoutUnit centeredRowPositionForChild(const LayoutBox&) const; | |
| 126 LayoutUnit rowPositionForChild(const LayoutBox&) const; | |
| 127 LayoutUnit contentPositionAndDistributionColumnOffset(LayoutUnit availableFr
eeSpace, ContentPosition, ContentDistributionType, OverflowAlignment, unsigned n
umberOfItems) const; | |
| 128 LayoutUnit contentPositionAndDistributionRowOffset(LayoutUnit availableFreeS
pace, ContentPosition, ContentDistributionType, OverflowAlignment, unsigned numb
erOfItems) const; | |
| 129 LayoutPoint findChildLogicalPosition(const LayoutBox&, LayoutSize contentAli
gnmentOffset) const; | |
| 130 GridCoordinate cachedGridCoordinate(const LayoutBox&) const; | |
| 131 | |
| 132 LayoutUnit gridAreaBreadthForChild(const LayoutBox& child, GridTrackSizingDi
rection, const Vector<GridTrack>&) const; | |
| 133 | |
| 134 virtual void paintChildren(const PaintInfo&, const LayoutPoint&) override; | |
| 135 bool allowedToStretchLogicalHeightForChild(const LayoutBox& child) const; | |
| 136 bool needToStretchChildLogicalHeight(const LayoutBox&) const; | |
| 137 LayoutUnit childIntrinsicHeight(const LayoutBox&) const; | |
| 138 LayoutUnit childIntrinsicWidth(const LayoutBox&) const; | |
| 139 LayoutUnit intrinsicLogicalHeightForChild(const LayoutBox&) const; | |
| 140 LayoutUnit marginLogicalHeightForChild(const LayoutBox&) const; | |
| 141 LayoutUnit computeMarginLogicalHeightForChild(const LayoutBox&) const; | |
| 142 LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAr
eaBreadthForChild, const LayoutBox&) const; | |
| 143 void applyStretchAlignmentToChildIfNeeded(LayoutBox&, LayoutUnit gridAreaBre
adthForChild); | |
| 144 | |
| 145 #if ENABLE(ASSERT) | |
| 146 bool tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection, const Vecto
r<GridTrack>&); | |
| 147 #endif | |
| 148 | |
| 149 size_t gridItemSpan(const LayoutBox&, GridTrackSizingDirection); | |
| 150 bool spanningItemCrossesFlexibleSizedTracks(const GridCoordinate&, GridTrack
SizingDirection) const; | |
| 151 | |
| 152 size_t gridColumnCount() const | |
| 153 { | |
| 154 ASSERT(!gridIsDirty()); | |
| 155 return m_grid[0].size(); | |
| 156 } | |
| 157 size_t gridRowCount() const | |
| 158 { | |
| 159 ASSERT(!gridIsDirty()); | |
| 160 return m_grid.size(); | |
| 161 } | |
| 162 | |
| 163 bool hasDefiniteLogicalSize(GridTrackSizingDirection) const; | |
| 164 | |
| 165 typedef Vector<Vector<GridCell> > GridRepresentation; | |
| 166 GridRepresentation m_grid; | |
| 167 bool m_gridIsDirty; | |
| 168 Vector<LayoutUnit> m_rowPositions; | |
| 169 Vector<LayoutUnit> m_columnPositions; | |
| 170 HashMap<const LayoutBox*, GridCoordinate> m_gridItemCoordinate; | |
| 171 OrderIterator m_orderIterator; | |
| 172 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; | |
| 173 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap; | |
| 174 }; | |
| 175 | |
| 176 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(RenderGrid, isRenderGrid()); | |
| 177 | |
| 178 } // namespace blink | |
| 179 | |
| 180 #endif // RenderGrid_h | |
| OLD | NEW |