2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include "RenderBlock.h"
35 class RenderGrid : public RenderBlock {
38 virtual ~RenderGrid();
40 virtual const char* renderName() const OVERRIDE;
42 virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) OVERRIDE;
44 virtual bool avoidsFloats() const OVERRIDE { return true; }
45 virtual bool canCollapseAnonymousBlockChild() const OVERRIDE { return false; }
48 virtual bool isRenderGrid() const OVERRIDE { return true; }
49 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
50 virtual void computePreferredLogicalWidths() OVERRIDE;
52 LayoutUnit computePreferredTrackWidth(const Length&, size_t) const;
55 enum TrackSizingDirection { ForColumns, ForRows };
56 void computedUsedBreadthOfGridTracks(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks);
57 LayoutUnit computeUsedBreadthOfMinLength(TrackSizingDirection, const Length&) const;
58 LayoutUnit computeUsedBreadthOfMaxLength(TrackSizingDirection, const Length&) const;
59 LayoutUnit computeUsedBreadthOfSpecifiedLength(TrackSizingDirection, const Length&) const;
60 void resolveContentBasedTrackSizingFunctions(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, LayoutUnit& availableLogicalSpace);
61 void placeItemsOnGrid();
62 void layoutGridItems();
64 typedef LayoutUnit (RenderGrid::* SizingFunction)(RenderBox*, TrackSizingDirection, Vector<GridTrack>&);
65 typedef LayoutUnit (GridTrack::* AccumulatorGetter)() const;
66 typedef void (GridTrack::* AccumulatorGrowFunction)(LayoutUnit);
67 void resolveContentBasedTrackSizingFunctionsForItems(TrackSizingDirection, Vector<GridTrack>& columnTracks, Vector<GridTrack>& rowTracks, size_t, SizingFunction, AccumulatorGetter, AccumulatorGrowFunction);
68 void distributeSpaceToTracks(Vector<GridTrack*>&, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter, AccumulatorGrowFunction, LayoutUnit& availableLogicalSpace);
70 const GridTrackSize& gridTrackSize(TrackSizingDirection, size_t);
71 size_t maximumIndexInDirection(TrackSizingDirection) const;
73 LayoutUnit logicalContentHeightForChild(RenderBox*, Vector<GridTrack>&);
74 LayoutUnit minContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
75 LayoutUnit maxContentForChild(RenderBox*, TrackSizingDirection, Vector<GridTrack>& columnTracks);
76 LayoutPoint findChildLogicalPosition(RenderBox*, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks);
77 size_t resolveGridPosition(TrackSizingDirection, const RenderObject*) const;
78 size_t resolveGridPosition(const GridPosition&) const;
81 bool tracksAreWiderThanMinTrackBreadth(TrackSizingDirection, const Vector<GridTrack>&);
84 size_t gridColumnCount() const { return m_grid.isEmpty() ? 0 : m_grid[0].size(); }
85 size_t gridRowCount() const { return m_grid.size(); }
87 Vector<Vector<Vector<RenderBox*, 1> > > m_grid;
90 } // namespace WebCore
92 #endif // RenderGrid_h