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

Side by Side Diff: Source/core/layout/LayoutFlexibleBox.cpp

Issue 1070143002: [Alignment] Single class for holding the alignment data. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased and got back previous setter names. Created 5 years, 7 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
« no previous file with comments | « Source/core/layout/LayoutBox.cpp ('k') | Source/core/layout/LayoutFullScreen.cpp » ('j') | 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 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 void LayoutFlexibleBox::removeChild(LayoutObject* child) 203 void LayoutFlexibleBox::removeChild(LayoutObject* child)
204 { 204 {
205 LayoutBlock::removeChild(child); 205 LayoutBlock::removeChild(child);
206 m_intrinsicSizeAlongMainAxis.remove(child); 206 m_intrinsicSizeAlongMainAxis.remove(child);
207 } 207 }
208 208
209 void LayoutFlexibleBox::styleDidChange(StyleDifference diff, const ComputedStyle * oldStyle) 209 void LayoutFlexibleBox::styleDidChange(StyleDifference diff, const ComputedStyle * oldStyle)
210 { 210 {
211 LayoutBlock::styleDidChange(diff, oldStyle); 211 LayoutBlock::styleDidChange(diff, oldStyle);
212 212
213 if (oldStyle && oldStyle->alignItems() == ItemPositionStretch && diff.needsF ullLayout()) { 213 if (oldStyle && oldStyle->alignItemsPosition() == ItemPositionStretch && dif f.needsFullLayout()) {
214 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space. 214 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space.
215 // This is only necessary for stretching since other alignment values do n't change the size of the box. 215 // This is only necessary for stretching since other alignment values do n't change the size of the box.
216 for (LayoutBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) { 216 for (LayoutBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) {
217 ItemPosition previousAlignment = ComputedStyle::resolveAlignment(*ol dStyle, child->styleRef(), ItemPositionStretch); 217 ItemPosition previousAlignment = ComputedStyle::resolveAlignment(*ol dStyle, child->styleRef(), ItemPositionStretch);
218 if (previousAlignment == ItemPositionStretch && previousAlignment != ComputedStyle::resolveAlignment(styleRef(), child->styleRef(), ItemPositionStre tch)) 218 if (previousAlignment == ItemPositionStretch && previousAlignment != ComputedStyle::resolveAlignment(styleRef(), child->styleRef(), ItemPositionStre tch))
219 child->setChildNeedsLayout(MarkOnlyThis); 219 child->setChildNeedsLayout(MarkOnlyThis);
220 } 220 }
221 } 221 }
222 } 222 }
223 223
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 return child.styleRef().overflowY(); 1113 return child.styleRef().overflowY();
1114 } 1114 }
1115 1115
1116 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts) 1116 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts)
1117 { 1117 {
1118 ASSERT(childSizes.size() == children.size()); 1118 ASSERT(childSizes.size() == children.size());
1119 1119
1120 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1120 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1121 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); 1121 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace);
1122 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; 1122 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ;
1123 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent); 1123 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContentPosition(), style()->justifyContentDistribution(), numberOfChildren ForJustifyContent);
1124 if (style()->flexDirection() == FlowRowReverse) 1124 if (style()->flexDirection() == FlowRowReverse)
1125 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); 1125 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight();
1126 1126
1127 LayoutUnit totalMainExtent = mainAxisExtent(); 1127 LayoutUnit totalMainExtent = mainAxisExtent();
1128 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline . 1128 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline .
1129 LayoutUnit maxChildCrossAxisExtent = 0; 1129 LayoutUnit maxChildCrossAxisExtent = 0;
1130 size_t seenInFlowPositionedChildren = 0; 1130 size_t seenInFlowPositionedChildren = 0;
1131 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); 1131 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow();
1132 for (size_t i = 0; i < children.size(); ++i) { 1132 for (size_t i = 0; i < children.size(); ++i) {
1133 LayoutBox* child = children[i]; 1133 LayoutBox* child = children[i];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 crossAxisOffset += maxChildCrossAxisExtent; 1204 crossAxisOffset += maxChildCrossAxisExtent;
1205 } 1205 }
1206 1206
1207 void LayoutFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) 1207 void LayoutFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace)
1208 { 1208 {
1209 // This is similar to the logic in layoutAndPlaceChildren, except we place t he children 1209 // This is similar to the logic in layoutAndPlaceChildren, except we place t he children
1210 // starting from the end of the flexbox. We also don't need to layout anythi ng since we're 1210 // starting from the end of the flexbox. We also don't need to layout anythi ng since we're
1211 // just moving the children to a new position. 1211 // just moving the children to a new position.
1212 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1212 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1213 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd(); 1213 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd();
1214 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent); 1214 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContentPosition(), style()->justifyContentDistribution(), numberOfChildren ForJustifyContent);
1215 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight(); 1215 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight();
1216 1216
1217 size_t seenInFlowPositionedChildren = 0; 1217 size_t seenInFlowPositionedChildren = 0;
1218 for (size_t i = 0; i < children.size(); ++i) { 1218 for (size_t i = 0; i < children.size(); ++i) {
1219 LayoutBox* child = children[i]; 1219 LayoutBox* child = children[i];
1220 1220
1221 if (child->isOutOfFlowPositioned()) { 1221 if (child->isOutOfFlowPositioned()) {
1222 child->layer()->setStaticBlockPosition(mainAxisOffset); 1222 child->layer()->setStaticBlockPosition(mainAxisOffset);
1223 continue; 1223 continue;
1224 } 1224 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 void LayoutFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts) 1265 void LayoutFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts)
1266 { 1266 {
1267 // If we have a single line flexbox or a multiline line flexbox with only on e flex line, 1267 // If we have a single line flexbox or a multiline line flexbox with only on e flex line,
1268 // the line height is all the available space. 1268 // the line height is all the available space.
1269 // For flex-direction: row, this means we need to use the height, so we do t his after calling updateLogicalHeight. 1269 // For flex-direction: row, this means we need to use the height, so we do t his after calling updateLogicalHeight.
1270 if (lineContexts.size() == 1) { 1270 if (lineContexts.size() == 1) {
1271 lineContexts[0].crossAxisExtent = crossAxisContentExtent(); 1271 lineContexts[0].crossAxisExtent = crossAxisContentExtent();
1272 return; 1272 return;
1273 } 1273 }
1274 1274
1275 if (style()->alignContent() == ContentPositionFlexStart) 1275 if (style()->alignContentPosition() == ContentPositionFlexStart)
1276 return; 1276 return;
1277 1277
1278 LayoutUnit availableCrossAxisSpace = crossAxisContentExtent(); 1278 LayoutUnit availableCrossAxisSpace = crossAxisContentExtent();
1279 for (size_t i = 0; i < lineContexts.size(); ++i) 1279 for (size_t i = 0; i < lineContexts.size(); ++i)
1280 availableCrossAxisSpace -= lineContexts[i].crossAxisExtent; 1280 availableCrossAxisSpace -= lineContexts[i].crossAxisExtent;
1281 1281
1282 LayoutBox* child = m_orderIterator.first(); 1282 LayoutBox* child = m_orderIterator.first();
1283 LayoutUnit lineOffset = initialAlignContentOffset(availableCrossAxisSpace, s tyle()->alignContent(), style()->alignContentDistribution(), lineContexts.size() ); 1283 LayoutUnit lineOffset = initialAlignContentOffset(availableCrossAxisSpace, s tyle()->alignContentPosition(), style()->alignContentDistribution(), lineContext s.size());
1284 for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber ) { 1284 for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber ) {
1285 lineContexts[lineNumber].crossAxisOffset += lineOffset; 1285 lineContexts[lineNumber].crossAxisOffset += lineOffset;
1286 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb erOfChildren; ++childNumber, child = m_orderIterator.next()) 1286 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb erOfChildren; ++childNumber, child = m_orderIterator.next())
1287 adjustAlignmentForChild(*child, lineOffset); 1287 adjustAlignmentForChild(*child, lineOffset);
1288 1288
1289 if (style()->alignContentDistribution() == ContentDistributionStretch && availableCrossAxisSpace > 0) 1289 if (style()->alignContentDistribution() == ContentDistributionStretch && availableCrossAxisSpace > 0)
1290 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size()); 1290 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size());
1291 1291
1292 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, style()->alignContentDistribution(), lineContexts.size()); 1292 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, style()->alignContentDistribution(), lineContexts.size());
1293 } 1293 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 ASSERT(child); 1456 ASSERT(child);
1457 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1457 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1458 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1458 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1459 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1459 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1460 adjustAlignmentForChild(*child, newOffset - originalOffset); 1460 adjustAlignmentForChild(*child, newOffset - originalOffset);
1461 } 1461 }
1462 } 1462 }
1463 } 1463 }
1464 1464
1465 } 1465 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutBox.cpp ('k') | Source/core/layout/LayoutFullScreen.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698