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.
27
#include "RenderGrid.h"
29
#include "LayoutRepainter.h"
30
#include "NotImplemented.h"
31
#include "RenderLayer.h"
32
#include "RenderView.h"
36
class RenderGrid::GridTrack {
43
LayoutUnit m_usedBreadth;
46
RenderGrid::RenderGrid(Node* node)
49
// All of our children must be block level.
50
setChildrenInline(false);
53
RenderGrid::~RenderGrid()
57
void RenderGrid::layoutBlock(bool relayoutChildren, LayoutUnit)
59
ASSERT(needsLayout());
61
if (!relayoutChildren && simplifiedLayout())
64
// FIXME: Much of this method is boiler plate that matches RenderBox::layoutBlock and Render*FlexibleBox::layoutBlock.
65
// It would be nice to refactor some of the duplicate code.
66
LayoutRepainter repainter(*this, checkForRepaintDuringLayout());
67
LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode());
69
if (inRenderFlowThread()) {
70
// Regions changing widths can force us to relayout our children.
71
if (logicalWidthChangedInRegions())
72
relayoutChildren = true;
74
updateRegionsAndExclusionsLogicalSize();
76
LayoutSize previousSize = size();
85
LayoutUnit oldClientAfterEdge = clientLogicalBottom();
86
updateLogicalHeight();
88
if (size() != previousSize)
89
relayoutChildren = true;
91
layoutPositionedObjects(relayoutChildren || isRoot());
93
computeRegionRangeForBlock();
95
computeOverflow(oldClientAfterEdge);
98
updateLayerTransform();
100
// Update our scroll information if we're overflow:auto/scroll/hidden now that we know if
101
// we overflow or not.
102
if (hasOverflowClip())
103
layer()->updateScrollInfoAfterLayout();
105
repainter.repaintAfterLayout();
107
setNeedsLayout(false);
110
void RenderGrid::computePreferredLogicalWidths()
112
ASSERT(preferredLogicalWidthsDirty());
114
m_minPreferredLogicalWidth = 0;
115
m_maxPreferredLogicalWidth = 0;
117
// FIXME: We don't take our own logical width into account.
119
const Vector<GridTrackSize>& trackStyles = style()->gridColumns();
121
for (size_t i = 0; i < trackStyles.size(); ++i) {
122
Length trackLength = trackStyles[i].length();
123
if (!trackLength.isFixed()) {
128
m_minPreferredLogicalWidth += trackLength.intValue();
129
m_maxPreferredLogicalWidth += trackLength.intValue();
132
// FIXME: We should account for min / max logical width.
134
// FIXME: Include borders and paddings in inline direction.
136
setPreferredLogicalWidthsDirty(false);
139
void RenderGrid::computedUsedBreadthOfGridTracks(TrackSizingDirection direction, Vector<GridTrack>& tracks)
141
const Vector<GridTrackSize>& trackStyles = (direction == ForColumns) ? style()->gridColumns() : style()->gridRows();
142
for (size_t i = 0; i < trackStyles.size(); ++i) {
144
if (trackStyles[i].length().isFixed())
145
track.m_usedBreadth = trackStyles[i].length().getFloatValue();
149
tracks.append(track);
153
void RenderGrid::layoutGridItems()
155
Vector<GridTrack> columnTracks, rowTracks;
156
computedUsedBreadthOfGridTracks(ForColumns, columnTracks);
157
// FIXME: The logical width of Grid Columns from the prior step is used in
158
// the formatting of Grid items in content-sized Grid Rows to determine
159
// their required height. We will probably need to pass columns through.
160
computedUsedBreadthOfGridTracks(ForRows, rowTracks);
162
for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
163
LayoutPoint childPosition = findChildLogicalPosition(child, columnTracks, rowTracks);
165
size_t columnTrack = resolveGridPosition(child->style()->gridItemColumn());
166
size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
168
// FIXME: Properly support implicit rows and columns (bug 103573).
169
if (columnTrack < columnTracks.size() && rowTrack < rowTracks.size()) {
170
// Because the grid area cannot be styled, we don't need to adjust
171
// the grid breadth to account for 'box-sizing'.
172
child->setOverrideContainingBlockContentLogicalWidth(columnTracks[columnTrack].m_usedBreadth);
173
child->setOverrideContainingBlockContentLogicalHeight(rowTracks[rowTrack].m_usedBreadth);
176
// FIXME: Grid items should stretch to fill their cells. Once we
177
// implement grid-{column,row}-align, we can also shrink to fit. For
178
// now, just size as if we were a regular child.
179
child->layoutIfNeeded();
181
// FIXME: Handle border & padding on the grid element.
182
child->setLogicalLocation(childPosition);
185
// FIXME: Handle border & padding on the grid element.
186
for (size_t i = 0; i < rowTracks.size(); ++i)
187
setLogicalHeight(logicalHeight() + rowTracks[i].m_usedBreadth);
190
size_t RenderGrid::resolveGridPosition(const GridPosition& position) const
192
// FIXME: Handle other values for grid-{row,column} like ranges or line names.
193
switch (position.type()) {
194
case IntegerPosition:
195
// FIXME: What does a non-positive integer mean for a column/row?
196
if (!position.isPositive())
199
return position.integerPosition() - 1;
201
// FIXME: We should follow 'grid-auto-flow' for resolution.
202
// Until then, we use the 'grid-auto-flow: none' behavior (which is the default)
203
// and resolve 'auto' as the first row / column.
206
ASSERT_NOT_REACHED();
210
LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
212
size_t columnTrack = resolveGridPosition(child->style()->gridItemColumn());
213
size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
216
// FIXME: |columnTrack| and |rowTrack| should be smaller than our column / row count.
217
for (size_t i = 0; i < columnTrack && i < columnTracks.size(); ++i)
218
offset.setX(offset.x() + columnTracks[i].m_usedBreadth);
219
for (size_t i = 0; i < rowTrack && i < rowTracks.size(); ++i)
220
offset.setY(offset.y() + rowTracks[i].m_usedBreadth);
222
// FIXME: Handle margins on the grid item.
226
const char* RenderGrid::renderName() const
229
return "RenderGrid (floating)";
230
if (isOutOfFlowPositioned())
231
return "RenderGrid (positioned)";
233
return "RenderGrid (generated)";
234
if (isRelPositioned())
235
return "RenderGrid (relative positioned)";
239
} // namespace WebCore