• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/rendering/OrderIterator.h"
30 #include "core/rendering/RenderBlock.h"
31 #include "core/rendering/style/GridResolvedPosition.h"
32 
33 namespace WebCore {
34 
35 struct GridCoordinate;
36 struct GridSpan;
37 class GridTrack;
38 
39 class RenderGrid FINAL : public RenderBlock {
40 public:
41     RenderGrid(Element*);
42     virtual ~RenderGrid();
43 
44     virtual const char* renderName() const OVERRIDE;
45 
46     virtual void layoutBlock(bool relayoutChildren) OVERRIDE;
47 
avoidsFloats()48     virtual bool avoidsFloats() const OVERRIDE { return true; }
canCollapseAnonymousBlockChild()49     virtual bool canCollapseAnonymousBlockChild() const OVERRIDE { return false; }
50 
51     void dirtyGrid();
52 
columnPositions()53     const Vector<LayoutUnit>& columnPositions() const { return m_columnPositions; }
rowPositions()54     const Vector<LayoutUnit>& rowPositions() const { return m_rowPositions; }
55 
56 private:
isRenderGrid()57     virtual bool isRenderGrid() const OVERRIDE { return true; }
58     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
59     virtual void computePreferredLogicalWidths() OVERRIDE;
60 
61     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE;
62     void addChildToIndexesMap(RenderBox*);
63     virtual void removeChild(RenderObject*) OVERRIDE;
64 
65     virtual void styleDidChange(StyleDifference, const RenderStyle*) OVERRIDE;
66 
67     bool explicitGridDidResize(const RenderStyle*) const;
68     bool namedGridLinesDefinitionDidChange(const RenderStyle*) const;
69 
70     class GridIterator;
71     struct GridSizingData;
72     bool gridElementIsShrinkToFit();
73     void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData&);
74     void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData&, LayoutUnit& availableLogicalSpace);
75     LayoutUnit computeUsedBreadthOfMinLength(GridTrackSizingDirection, const GridLength&) const;
76     LayoutUnit computeUsedBreadthOfMaxLength(GridTrackSizingDirection, const GridLength&, LayoutUnit usedBreadth) const;
77     LayoutUnit computeUsedBreadthOfSpecifiedLength(GridTrackSizingDirection, const Length&) const;
78     void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, GridSizingData&, LayoutUnit& availableLogicalSpace);
79 
80     void ensureGridSize(size_t maximumRowIndex, size_t maximumColumnIndex);
81     void insertItemIntoGrid(RenderBox*, const GridCoordinate&);
82     void placeItemsOnGrid();
83     void populateExplicitGridAndOrderIterator();
84     PassOwnPtr<GridCoordinate> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(const RenderBox*, GridTrackSizingDirection, const GridSpan& specifiedPositions) const;
85     void placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>&);
86     void placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>&);
87     void placeAutoMajorAxisItemOnGrid(RenderBox*);
88     GridTrackSizingDirection autoPlacementMajorAxisDirection() const;
89     GridTrackSizingDirection autoPlacementMinorAxisDirection() const;
90 
91     void layoutGridItems();
92     void populateGridPositions(const GridSizingData&);
93 
94     typedef LayoutUnit (RenderGrid::* SizingFunction)(RenderBox*, GridTrackSizingDirection, Vector<GridTrack>&);
95     typedef LayoutUnit (GridTrack::* AccumulatorGetter)() const;
96     typedef void (GridTrack::* AccumulatorGrowFunction)(LayoutUnit);
97     typedef bool (GridTrackSize::* FilterFunction)() const;
98     void resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection, GridSizingData&, RenderBox*, FilterFunction, SizingFunction, AccumulatorGetter, AccumulatorGrowFunction);
99     void distributeSpaceToTracks(Vector<GridTrack*>&, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter, AccumulatorGrowFunction, GridSizingData&, LayoutUnit& availableLogicalSpace);
100 
101     double computeNormalizedFractionBreadth(Vector<GridTrack>&, const GridSpan& tracksSpan, GridTrackSizingDirection, LayoutUnit availableLogicalSpace) const;
102 
103     const GridTrackSize& gridTrackSize(GridTrackSizingDirection, size_t) const;
104 
105     LayoutUnit logicalHeightForChild(RenderBox*, Vector<GridTrack>&);
106     LayoutUnit minContentForChild(RenderBox*, GridTrackSizingDirection, Vector<GridTrack>& columnTracks);
107     LayoutUnit maxContentForChild(RenderBox*, GridTrackSizingDirection, Vector<GridTrack>& columnTracks);
108     LayoutUnit startOfColumnForChild(const RenderBox* child) const;
109     LayoutUnit endOfColumnForChild(const RenderBox* child) const;
110     LayoutUnit columnPositionAlignedWithGridContainerStart(const RenderBox*) const;
111     LayoutUnit columnPositionAlignedWithGridContainerEnd(const RenderBox*) const;
112     LayoutUnit centeredColumnPositionForChild(const RenderBox*) const;
113     LayoutUnit columnPositionForChild(const RenderBox*) const;
114     LayoutUnit rowPositionForChild(const RenderBox*) const;
115     LayoutPoint findChildLogicalPosition(const RenderBox*) const;
116     GridCoordinate cachedGridCoordinate(const RenderBox*) const;
117 
118     LayoutUnit gridAreaBreadthForChild(const RenderBox* child, GridTrackSizingDirection, const Vector<GridTrack>&) const;
119 
120     virtual void paintChildren(PaintInfo&, const LayoutPoint&) OVERRIDE;
121 
gridIsDirty()122     bool gridIsDirty() const { return m_gridIsDirty; }
123 
124 #ifndef NDEBUG
125     bool tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection, const Vector<GridTrack>&);
126 #endif
127 
gridColumnCount()128     size_t gridColumnCount() const
129     {
130         ASSERT(!gridIsDirty());
131         return m_grid[0].size();
132     }
gridRowCount()133     size_t gridRowCount() const
134     {
135         ASSERT(!gridIsDirty());
136         return m_grid.size();
137     }
138 
139     typedef Vector<RenderBox*, 1> GridCell;
140     typedef Vector<Vector<GridCell> > GridRepresentation;
141     GridRepresentation m_grid;
142     bool m_gridIsDirty;
143     Vector<LayoutUnit> m_rowPositions;
144     Vector<LayoutUnit> m_columnPositions;
145     HashMap<const RenderBox*, GridCoordinate> m_gridItemCoordinate;
146     OrderIterator m_orderIterator;
147     Vector<RenderBox*> m_gridItemsOverflowingGridArea;
148     HashMap<const RenderBox*, size_t> m_gridItemsIndexesMap;
149 };
150 
151 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderGrid, isRenderGrid());
152 
153 } // namespace WebCore
154 
155 #endif // RenderGrid_h
156