| OLD | NEW |
| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 int RenderFlexibleBox::firstLineBoxBaseline() const | 149 int RenderFlexibleBox::firstLineBoxBaseline() const |
| 150 { | 150 { |
| 151 if (isWritingModeRoot() || m_numberOfInFlowChildrenOnFirstLine <= 0) | 151 if (isWritingModeRoot() || m_numberOfInFlowChildrenOnFirstLine <= 0) |
| 152 return -1; | 152 return -1; |
| 153 RenderBox* baselineChild = 0; | 153 RenderBox* baselineChild = 0; |
| 154 int childNumber = 0; | 154 int childNumber = 0; |
| 155 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 155 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
| 156 if (child->isOutOfFlowPositioned()) | 156 if (child->isOutOfFlowPositioned()) |
| 157 continue; | 157 continue; |
| 158 if (alignmentForChild(child) == AlignBaseline && !hasAutoMarginsInCrossA
xis(child)) { | 158 if (alignmentForChild(child) == ItemPositionBaseline && !hasAutoMarginsI
nCrossAxis(child)) { |
| 159 baselineChild = child; | 159 baselineChild = child; |
| 160 break; | 160 break; |
| 161 } | 161 } |
| 162 if (!baselineChild) | 162 if (!baselineChild) |
| 163 baselineChild = child; | 163 baselineChild = child; |
| 164 | 164 |
| 165 ++childNumber; | 165 ++childNumber; |
| 166 if (childNumber == m_numberOfInFlowChildrenOnFirstLine) | 166 if (childNumber == m_numberOfInFlowChildrenOnFirstLine) |
| 167 break; | 167 break; |
| 168 } | 168 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 189 int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const | 189 int RenderFlexibleBox::inlineBlockBaseline(LineDirectionMode direction) const |
| 190 { | 190 { |
| 191 int baseline = firstLineBoxBaseline(); | 191 int baseline = firstLineBoxBaseline(); |
| 192 if (baseline != -1) | 192 if (baseline != -1) |
| 193 return baseline; | 193 return baseline; |
| 194 | 194 |
| 195 int marginAscent = direction == HorizontalLine ? marginTop() : marginRight()
; | 195 int marginAscent = direction == HorizontalLine ? marginTop() : marginRight()
; |
| 196 return synthesizedBaselineFromContentBox(this, direction) + marginAscent; | 196 return synthesizedBaselineFromContentBox(this, direction) + marginAscent; |
| 197 } | 197 } |
| 198 | 198 |
| 199 static EAlignItems resolveAlignment(const RenderStyle* parentStyle, const Render
Style* childStyle) | 199 static ItemPosition resolveAlignment(const RenderStyle* parentStyle, const Rende
rStyle* childStyle) |
| 200 { | 200 { |
| 201 EAlignItems align = childStyle->alignSelf(); | 201 ItemPosition align = childStyle->alignSelf(); |
| 202 if (align == AlignAuto) | 202 if (align == ItemPositionAuto) |
| 203 align = parentStyle->alignItems(); | 203 align = parentStyle->alignItems(); |
| 204 return align; | 204 return align; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) | 207 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const RenderStyle*
oldStyle) |
| 208 { | 208 { |
| 209 RenderBlock::styleDidChange(diff, oldStyle); | 209 RenderBlock::styleDidChange(diff, oldStyle); |
| 210 | 210 |
| 211 if (oldStyle && oldStyle->alignItems() == AlignStretch && diff == StyleDiffe
renceLayout) { | 211 if (oldStyle && oldStyle->alignItems() == ItemPositionStretch && diff == Sty
leDifferenceLayout) { |
| 212 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. | 212 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. |
| 213 // This is only necessary for stretching since other alignment values do
n't change the size of the box. | 213 // This is only necessary for stretching since other alignment values do
n't change the size of the box. |
| 214 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { | 214 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { |
| 215 EAlignItems previousAlignment = resolveAlignment(oldStyle, child->st
yle()); | 215 ItemPosition previousAlignment = resolveAlignment(oldStyle, child->s
tyle()); |
| 216 if (previousAlignment == AlignStretch && previousAlignment != resolv
eAlignment(style(), child->style())) | 216 if (previousAlignment == ItemPositionStretch && previousAlignment !=
resolveAlignment(style(), child->style())) |
| 217 child->setChildNeedsLayout(MarkOnlyThis); | 217 child->setChildNeedsLayout(MarkOnlyThis); |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit) | 222 void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit) |
| 223 { | 223 { |
| 224 ASSERT(needsLayout()); | 224 ASSERT(needsLayout()); |
| 225 | 225 |
| 226 if (!relayoutChildren && simplifiedLayout()) | 226 if (!relayoutChildren && simplifiedLayout()) |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 childLayer->setStaticInlinePosition(inlinePosition); // FIXME: Not right for
regions. | 1009 childLayer->setStaticInlinePosition(inlinePosition); // FIXME: Not right for
regions. |
| 1010 | 1010 |
| 1011 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis
Offset; | 1011 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis
Offset; |
| 1012 if (childLayer->staticBlockPosition() != staticBlockPosition) { | 1012 if (childLayer->staticBlockPosition() != staticBlockPosition) { |
| 1013 childLayer->setStaticBlockPosition(staticBlockPosition); | 1013 childLayer->setStaticBlockPosition(staticBlockPosition); |
| 1014 if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingM
ode())) | 1014 if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingM
ode())) |
| 1015 child->setChildNeedsLayout(MarkOnlyThis); | 1015 child->setChildNeedsLayout(MarkOnlyThis); |
| 1016 } | 1016 } |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 EAlignItems RenderFlexibleBox::alignmentForChild(RenderBox* child) const | 1019 ItemPosition RenderFlexibleBox::alignmentForChild(RenderBox* child) const |
| 1020 { | 1020 { |
| 1021 EAlignItems align = resolveAlignment(style(), child->style()); | 1021 ItemPosition align = resolveAlignment(style(), child->style()); |
| 1022 | 1022 |
| 1023 if (align == AlignBaseline && hasOrthogonalFlow(child)) | 1023 if (align == ItemPositionBaseline && hasOrthogonalFlow(child)) |
| 1024 align = AlignFlexStart; | 1024 align = ItemPositionFlexStart; |
| 1025 | 1025 |
| 1026 if (style()->flexWrap() == FlexWrapReverse) { | 1026 if (style()->flexWrap() == FlexWrapReverse) { |
| 1027 if (align == AlignFlexStart) | 1027 if (align == ItemPositionFlexStart) |
| 1028 align = AlignFlexEnd; | 1028 align = ItemPositionFlexEnd; |
| 1029 else if (align == AlignFlexEnd) | 1029 else if (align == ItemPositionFlexEnd) |
| 1030 align = AlignFlexStart; | 1030 align = ItemPositionFlexStart; |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 return align; | 1033 return align; |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem
List& children) const | 1036 size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem
List& children) const |
| 1037 { | 1037 { |
| 1038 size_t count = 0; | 1038 size_t count = 0; |
| 1039 for (size_t i = 0; i < children.size(); ++i) { | 1039 for (size_t i = 0; i < children.size(); ++i) { |
| 1040 RenderBox* child = children[i]; | 1040 RenderBox* child = children[i]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } else { | 1080 } else { |
| 1081 // To avoid double applying margin changes in updateAutoMarginsInCro
ssAxis, we reset the margins here. | 1081 // To avoid double applying margin changes in updateAutoMarginsInCro
ssAxis, we reset the margins here. |
| 1082 resetAutoMarginsAndLogicalTopInCrossAxis(child); | 1082 resetAutoMarginsAndLogicalTopInCrossAxis(child); |
| 1083 } | 1083 } |
| 1084 updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); | 1084 updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child); |
| 1085 child->layoutIfNeeded(); | 1085 child->layoutIfNeeded(); |
| 1086 | 1086 |
| 1087 updateAutoMarginsInMainAxis(child, autoMarginOffset); | 1087 updateAutoMarginsInMainAxis(child, autoMarginOffset); |
| 1088 | 1088 |
| 1089 LayoutUnit childCrossAxisMarginBoxExtent; | 1089 LayoutUnit childCrossAxisMarginBoxExtent; |
| 1090 if (alignmentForChild(child) == AlignBaseline && !hasAutoMarginsInCrossA
xis(child)) { | 1090 if (alignmentForChild(child) == ItemPositionBaseline && !hasAutoMarginsI
nCrossAxis(child)) { |
| 1091 LayoutUnit ascent = marginBoxAscentForChild(child); | 1091 LayoutUnit ascent = marginBoxAscentForChild(child); |
| 1092 LayoutUnit descent = (crossAxisMarginExtentForChild(child) + crossAx
isExtentForChild(child)) - ascent; | 1092 LayoutUnit descent = (crossAxisMarginExtentForChild(child) + crossAx
isExtentForChild(child)) - ascent; |
| 1093 | 1093 |
| 1094 maxAscent = std::max(maxAscent, ascent); | 1094 maxAscent = std::max(maxAscent, ascent); |
| 1095 maxDescent = std::max(maxDescent, descent); | 1095 maxDescent = std::max(maxDescent, descent); |
| 1096 | 1096 |
| 1097 childCrossAxisMarginBoxExtent = maxAscent + maxDescent; | 1097 childCrossAxisMarginBoxExtent = maxAscent + maxDescent; |
| 1098 } else | 1098 } else |
| 1099 childCrossAxisMarginBoxExtent = crossAxisExtentForChild(child) + cro
ssAxisMarginExtentForChild(child); | 1099 childCrossAxisMarginBoxExtent = crossAxisExtentForChild(child) + cro
ssAxisMarginExtentForChild(child); |
| 1100 if (!isColumnFlow()) | 1100 if (!isColumnFlow()) |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 if (child->isOutOfFlowPositioned()) { | 1243 if (child->isOutOfFlowPositioned()) { |
| 1244 if (style()->flexWrap() == FlexWrapReverse) | 1244 if (style()->flexWrap() == FlexWrapReverse) |
| 1245 adjustAlignmentForChild(child, lineCrossAxisExtent); | 1245 adjustAlignmentForChild(child, lineCrossAxisExtent); |
| 1246 continue; | 1246 continue; |
| 1247 } | 1247 } |
| 1248 | 1248 |
| 1249 if (updateAutoMarginsInCrossAxis(child, std::max(LayoutUnit(0), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, child)))) | 1249 if (updateAutoMarginsInCrossAxis(child, std::max(LayoutUnit(0), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, child)))) |
| 1250 continue; | 1250 continue; |
| 1251 | 1251 |
| 1252 switch (alignmentForChild(child)) { | 1252 switch (alignmentForChild(child)) { |
| 1253 case AlignAuto: | 1253 case ItemPositionAuto: |
| 1254 ASSERT_NOT_REACHED(); | 1254 ASSERT_NOT_REACHED(); |
| 1255 break; | 1255 break; |
| 1256 case AlignStretch: { | 1256 case ItemPositionStretch: { |
| 1257 applyStretchAlignmentToChild(child, lineCrossAxisExtent); | 1257 applyStretchAlignmentToChild(child, lineCrossAxisExtent); |
| 1258 // Since wrap-reverse flips cross start and cross end, strech ch
ildren should be aligned with the cross end. | 1258 // Since wrap-reverse flips cross start and cross end, strech ch
ildren should be aligned with the cross end. |
| 1259 if (style()->flexWrap() == FlexWrapReverse) | 1259 if (style()->flexWrap() == FlexWrapReverse) |
| 1260 adjustAlignmentForChild(child, availableAlignmentSpaceForChi
ld(lineCrossAxisExtent, child)); | 1260 adjustAlignmentForChild(child, availableAlignmentSpaceForChi
ld(lineCrossAxisExtent, child)); |
| 1261 break; | 1261 break; |
| 1262 } | 1262 } |
| 1263 case AlignFlexStart: | 1263 case ItemPositionFlexStart: |
| 1264 break; | 1264 break; |
| 1265 case AlignFlexEnd: | 1265 case ItemPositionFlexEnd: |
| 1266 adjustAlignmentForChild(child, availableAlignmentSpaceForChild(l
ineCrossAxisExtent, child)); | 1266 adjustAlignmentForChild(child, availableAlignmentSpaceForChild(l
ineCrossAxisExtent, child)); |
| 1267 break; | 1267 break; |
| 1268 case AlignCenter: | 1268 case ItemPositionCenter: |
| 1269 adjustAlignmentForChild(child, availableAlignmentSpaceForChild(l
ineCrossAxisExtent, child) / 2); | 1269 adjustAlignmentForChild(child, availableAlignmentSpaceForChild(l
ineCrossAxisExtent, child) / 2); |
| 1270 break; | 1270 break; |
| 1271 case AlignBaseline: { | 1271 case ItemPositionBaseline: { |
| 1272 // FIXME: If we get here in columns, we want the use the descent
, except we currently can't get the ascent/descent of orthogonal children. | 1272 // FIXME: If we get here in columns, we want the use the descent
, except we currently can't get the ascent/descent of orthogonal children. |
| 1273 // https://bugs.webkit.org/show_bug.cgi?id=98076 | 1273 // https://bugs.webkit.org/show_bug.cgi?id=98076 |
| 1274 LayoutUnit ascent = marginBoxAscentForChild(child); | 1274 LayoutUnit ascent = marginBoxAscentForChild(child); |
| 1275 LayoutUnit startOffset = maxAscent - ascent; | 1275 LayoutUnit startOffset = maxAscent - ascent; |
| 1276 adjustAlignmentForChild(child, startOffset); | 1276 adjustAlignmentForChild(child, startOffset); |
| 1277 | 1277 |
| 1278 if (style()->flexWrap() == FlexWrapReverse) | 1278 if (style()->flexWrap() == FlexWrapReverse) |
| 1279 minMarginAfterBaseline = std::min(minMarginAfterBaseline, av
ailableAlignmentSpaceForChild(lineCrossAxisExtent, child) - startOffset); | 1279 minMarginAfterBaseline = std::min(minMarginAfterBaseline, av
ailableAlignmentSpaceForChild(lineCrossAxisExtent, child) - startOffset); |
| 1280 break; | 1280 break; |
| 1281 } | 1281 } |
| 1282 case ItemPositionSelfStart: |
| 1283 case ItemPositionSelfEnd: |
| 1284 case ItemPositionStart: |
| 1285 case ItemPositionEnd: |
| 1286 case ItemPositionLeft: |
| 1287 case ItemPositionRight: |
| 1288 // FIXME: File a bug about implementing that. The extended gramm
ar |
| 1289 // is not enabled by default so we shouldn't hit this codepath. |
| 1290 ASSERT_NOT_REACHED(); |
| 1291 break; |
| 1282 } | 1292 } |
| 1283 } | 1293 } |
| 1284 minMarginAfterBaselines.append(minMarginAfterBaseline); | 1294 minMarginAfterBaselines.append(minMarginAfterBaseline); |
| 1285 } | 1295 } |
| 1286 | 1296 |
| 1287 if (style()->flexWrap() != FlexWrapReverse) | 1297 if (style()->flexWrap() != FlexWrapReverse) |
| 1288 return; | 1298 return; |
| 1289 | 1299 |
| 1290 // wrap-reverse flips the cross axis start and end. For baseline alignment,
this means we | 1300 // wrap-reverse flips the cross axis start and end. For baseline alignment,
this means we |
| 1291 // need to align the after edge of baseline elements with the after edge of
the flex line. | 1301 // need to align the after edge of baseline elements with the after edge of
the flex line. |
| 1292 child = m_orderIterator.first(); | 1302 child = m_orderIterator.first(); |
| 1293 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ | 1303 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ |
| 1294 LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber]; | 1304 LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber]; |
| 1295 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { | 1305 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { |
| 1296 ASSERT(child); | 1306 ASSERT(child); |
| 1297 if (alignmentForChild(child) == AlignBaseline && !hasAutoMarginsInCr
ossAxis(child) && minMarginAfterBaseline) | 1307 if (alignmentForChild(child) == ItemPositionBaseline && !hasAutoMarg
insInCrossAxis(child) && minMarginAfterBaseline) |
| 1298 adjustAlignmentForChild(child, minMarginAfterBaseline); | 1308 adjustAlignmentForChild(child, minMarginAfterBaseline); |
| 1299 } | 1309 } |
| 1300 } | 1310 } |
| 1301 } | 1311 } |
| 1302 | 1312 |
| 1303 void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox* child, LayoutUni
t lineCrossAxisExtent) | 1313 void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox* child, LayoutUni
t lineCrossAxisExtent) |
| 1304 { | 1314 { |
| 1305 if (!isColumnFlow() && child->style()->logicalHeight().isAuto()) { | 1315 if (!isColumnFlow() && child->style()->logicalHeight().isAuto()) { |
| 1306 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. | 1316 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. |
| 1307 if (!hasOrthogonalFlow(child)) { | 1317 if (!hasOrthogonalFlow(child)) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 ASSERT(child); | 1366 ASSERT(child); |
| 1357 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1367 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1358 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1368 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1359 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1369 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1360 adjustAlignmentForChild(child, newOffset - originalOffset); | 1370 adjustAlignmentForChild(child, newOffset - originalOffset); |
| 1361 } | 1371 } |
| 1362 } | 1372 } |
| 1363 } | 1373 } |
| 1364 | 1374 |
| 1365 } | 1375 } |
| OLD | NEW |