Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: Source/core/rendering/RenderGrid.cpp

Issue 23463036: Positioning should account for the grid items' margins (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/css-grid-layout/grid-item-margin-resolution-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 placeItemsOnGrid(); 850 placeItemsOnGrid();
851 851
852 Vector<GridTrack> columnTracks(gridColumnCount()); 852 Vector<GridTrack> columnTracks(gridColumnCount());
853 Vector<GridTrack> rowTracks(gridRowCount()); 853 Vector<GridTrack> rowTracks(gridRowCount());
854 computedUsedBreadthOfGridTracks(ForColumns, columnTracks, rowTracks); 854 computedUsedBreadthOfGridTracks(ForColumns, columnTracks, rowTracks);
855 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, columnTracks)); 855 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, columnTracks));
856 computedUsedBreadthOfGridTracks(ForRows, columnTracks, rowTracks); 856 computedUsedBreadthOfGridTracks(ForRows, columnTracks, rowTracks);
857 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, rowTracks)); 857 ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, rowTracks));
858 858
859 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 859 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
860 LayoutPoint childPosition = findChildLogicalPosition(child, columnTracks , rowTracks);
861
862 // Because the grid area cannot be styled, we don't need to adjust 860 // Because the grid area cannot be styled, we don't need to adjust
863 // the grid breadth to account for 'box-sizing'. 861 // the grid breadth to account for 'box-sizing'.
864 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit(); 862 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child->hasOve rrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogica lWidth() : LayoutUnit();
865 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit(); 863 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOv errideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogi calHeight() : LayoutUnit();
866 864
867 // FIXME: For children in a content sized track, we clear the overrideCo ntainingBlockContentLogicalHeight
868 // in minContentForChild / maxContentForChild which means that we will a lways relayout the child.
869 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(child, ForColumns, columnTracks); 865 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthF orChild(child, ForColumns, columnTracks);
870 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(child, ForRows, rowTracks); 866 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadth ForChild(child, ForRows, rowTracks);
871 867
872 SubtreeLayoutScope layoutScope(child); 868 SubtreeLayoutScope layoutScope(child);
873 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (child->hasRelativeLogicalHeight() && oldOverrideCont ainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight)) 869 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (child->hasRelativeLogicalHeight() && oldOverrideCont ainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight))
874 layoutScope.setNeedsLayout(child); 870 layoutScope.setNeedsLayout(child);
875 871
876 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); 872 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth);
877 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); 873 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight);
878 874
879 LayoutRect oldChildRect = child->frameRect(); 875 LayoutRect oldChildRect = child->frameRect();
880 876
881 // FIXME: Grid items should stretch to fill their cells. Once we 877 // FIXME: Grid items should stretch to fill their cells. Once we
882 // implement grid-{column,row}-align, we can also shrink to fit. For 878 // implement grid-{column,row}-align, we can also shrink to fit. For
883 // now, just size as if we were a regular child. 879 // now, just size as if we were a regular child.
884 child->layoutIfNeeded(); 880 child->layoutIfNeeded();
885 881
886 // FIXME: Handle border & padding on the grid element. 882 child->setLogicalLocation(findChildLogicalPosition(child, columnTracks, rowTracks));
887 child->setLogicalLocation(childPosition);
888 883
889 // If the child moved, we have to repaint it as well as any floating/pos itioned 884 // If the child moved, we have to repaint it as well as any floating/pos itioned
890 // descendants. An exception is if we need a layout. In this case, we kn ow we're going to 885 // descendants. An exception is if we need a layout. In this case, we kn ow we're going to
891 // repaint ourselves (and the child) anyway. 886 // repaint ourselves (and the child) anyway.
892 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout()) 887 if (!selfNeedsLayout() && child->checkForRepaintDuringLayout())
893 child->repaintDuringLayoutIfMoved(oldChildRect); 888 child->repaintDuringLayoutIfMoved(oldChildRect);
894 } 889 }
895 890
896 for (size_t i = 0; i < rowTracks.size(); ++i) 891 for (size_t i = 0; i < rowTracks.size(); ++i)
897 setLogicalHeight(logicalHeight() + rowTracks[i].m_usedBreadth); 892 setLogicalHeight(logicalHeight() + rowTracks[i].m_usedBreadth);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 for (size_t trackIndex = span.initialPositionIndex; trackIndex <= span.final PositionIndex; ++trackIndex) 1116 for (size_t trackIndex = span.initialPositionIndex; trackIndex <= span.final PositionIndex; ++trackIndex)
1122 gridAreaBreadth += tracks[trackIndex].m_usedBreadth; 1117 gridAreaBreadth += tracks[trackIndex].m_usedBreadth;
1123 return gridAreaBreadth; 1118 return gridAreaBreadth;
1124 } 1119 }
1125 1120
1126 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector< GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks) 1121 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector< GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
1127 { 1122 {
1128 const GridCoordinate& coordinate = cachedGridCoordinate(child); 1123 const GridCoordinate& coordinate = cachedGridCoordinate(child);
1129 1124
1130 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted. 1125 // The grid items should be inside the grid container's border box, that's w hy they need to be shifted.
1131 LayoutPoint offset(borderAndPaddingStart(), borderAndPaddingBefore()); 1126 LayoutPoint offset(borderAndPaddingStart() + marginStartForChild(child), bor derAndPaddingBefore() + marginBeforeForChild(child));
1132 // FIXME: |columnTrack| and |rowTrack| should be smaller than our column / r ow count. 1127 // FIXME: |columnTrack| and |rowTrack| should be smaller than our column / r ow count.
1133 for (size_t i = 0; i < coordinate.columns.initialPositionIndex && i < column Tracks.size(); ++i) 1128 for (size_t i = 0; i < coordinate.columns.initialPositionIndex && i < column Tracks.size(); ++i)
1134 offset.setX(offset.x() + columnTracks[i].m_usedBreadth); 1129 offset.setX(offset.x() + columnTracks[i].m_usedBreadth);
1135 for (size_t i = 0; i < coordinate.rows.initialPositionIndex && i < rowTracks .size(); ++i) 1130 for (size_t i = 0; i < coordinate.rows.initialPositionIndex && i < rowTracks .size(); ++i)
1136 offset.setY(offset.y() + rowTracks[i].m_usedBreadth); 1131 offset.setY(offset.y() + rowTracks[i].m_usedBreadth);
1137 1132
1138 // FIXME: Handle margins on the grid item.
1139 return offset; 1133 return offset;
1140 } 1134 }
1141 1135
1142 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set) 1136 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff set)
1143 { 1137 {
1144 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next()) 1138 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera tor.next())
1145 paintChild(child, paintInfo, paintOffset); 1139 paintChild(child, paintInfo, paintOffset);
1146 } 1140 }
1147 1141
1148 const char* RenderGrid::renderName() const 1142 const char* RenderGrid::renderName() const
1149 { 1143 {
1150 if (isFloating()) 1144 if (isFloating())
1151 return "RenderGrid (floating)"; 1145 return "RenderGrid (floating)";
1152 if (isOutOfFlowPositioned()) 1146 if (isOutOfFlowPositioned())
1153 return "RenderGrid (positioned)"; 1147 return "RenderGrid (positioned)";
1154 if (isAnonymous()) 1148 if (isAnonymous())
1155 return "RenderGrid (generated)"; 1149 return "RenderGrid (generated)";
1156 if (isRelPositioned()) 1150 if (isRelPositioned())
1157 return "RenderGrid (relative positioned)"; 1151 return "RenderGrid (relative positioned)";
1158 return "RenderGrid"; 1152 return "RenderGrid";
1159 } 1153 }
1160 1154
1161 } // namespace WebCore 1155 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/css-grid-layout/grid-item-margin-resolution-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698