| 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 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 } | 952 } |
| 953 | 953 |
| 954 if (totalViolation) | 954 if (totalViolation) |
| 955 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, ava
ilableFreeSpace, totalFlexGrow, totalWeightedFlexShrink, inflexibleItems, hasInf
initeLineLength); | 955 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, ava
ilableFreeSpace, totalFlexGrow, totalWeightedFlexShrink, inflexibleItems, hasInf
initeLineLength); |
| 956 else | 956 else |
| 957 availableFreeSpace -= usedFreeSpace; | 957 availableFreeSpace -= usedFreeSpace; |
| 958 | 958 |
| 959 return !totalViolation; | 959 return !totalViolation; |
| 960 } | 960 } |
| 961 | 961 |
| 962 static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, EJu
stifyContent justifyContent, unsigned numberOfChildren) | 962 static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, Con
tentPosition justifyContent, ContentDistributionType justifyContentDistribution,
unsigned numberOfChildren) |
| 963 { | 963 { |
| 964 if (justifyContent == JustifyFlexEnd) | 964 if (justifyContent == ContentPositionFlexEnd) |
| 965 return availableFreeSpace; | 965 return availableFreeSpace; |
| 966 if (justifyContent == JustifyCenter) | 966 if (justifyContent == ContentPositionCenter) |
| 967 return availableFreeSpace / 2; | 967 return availableFreeSpace / 2; |
| 968 if (justifyContent == JustifySpaceAround) { | 968 if (justifyContentDistribution == ContentDistributionSpaceAround) { |
| 969 if (availableFreeSpace > 0 && numberOfChildren) | 969 if (availableFreeSpace > 0 && numberOfChildren) |
| 970 return availableFreeSpace / (2 * numberOfChildren); | 970 return availableFreeSpace / (2 * numberOfChildren); |
| 971 else | 971 else |
| 972 return availableFreeSpace / 2; | 972 return availableFreeSpace / 2; |
| 973 } | 973 } |
| 974 return 0; | 974 return 0; |
| 975 } | 975 } |
| 976 | 976 |
| 977 static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpa
ce, EJustifyContent justifyContent, unsigned numberOfChildren) | 977 static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpa
ce, ContentDistributionType justifyContentDistribution, unsigned numberOfChildre
n) |
| 978 { | 978 { |
| 979 if (availableFreeSpace > 0 && numberOfChildren > 1) { | 979 if (availableFreeSpace > 0 && numberOfChildren > 1) { |
| 980 if (justifyContent == JustifySpaceBetween) | 980 if (justifyContentDistribution == ContentDistributionSpaceBetween) |
| 981 return availableFreeSpace / (numberOfChildren - 1); | 981 return availableFreeSpace / (numberOfChildren - 1); |
| 982 if (justifyContent == JustifySpaceAround) | 982 if (justifyContentDistribution == ContentDistributionSpaceAround) |
| 983 return availableFreeSpace / numberOfChildren; | 983 return availableFreeSpace / numberOfChildren; |
| 984 } | 984 } |
| 985 return 0; | 985 return 0; |
| 986 } | 986 } |
| 987 | 987 |
| 988 void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil
dPreferredSize) | 988 void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil
dPreferredSize) |
| 989 { | 989 { |
| 990 if (hasOrthogonalFlow(child)) | 990 if (hasOrthogonalFlow(child)) |
| 991 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); | 991 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); |
| 992 else | 992 else |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 return isHorizontalFlow() && child.style()->height().isAuto(); | 1073 return isHorizontalFlow() && child.style()->height().isAuto(); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou
tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex
ts, bool hasInfiniteLineLength) | 1076 void RenderFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons
t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou
tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex
ts, bool hasInfiniteLineLength) |
| 1077 { | 1077 { |
| 1078 ASSERT(childSizes.size() == children.size()); | 1078 ASSERT(childSizes.size() == children.size()); |
| 1079 | 1079 |
| 1080 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1080 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
| 1081 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); | 1081 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); |
| 1082 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; | 1082 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; |
| 1083 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1083 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
| 1084 if (style()->flexDirection() == FlowRowReverse) | 1084 if (style()->flexDirection() == FlowRowReverse) |
| 1085 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); | 1085 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); |
| 1086 | 1086 |
| 1087 LayoutUnit totalMainExtent = mainAxisExtent(); | 1087 LayoutUnit totalMainExtent = mainAxisExtent(); |
| 1088 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. | 1088 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. |
| 1089 LayoutUnit maxChildCrossAxisExtent = 0; | 1089 LayoutUnit maxChildCrossAxisExtent = 0; |
| 1090 size_t seenInFlowPositionedChildren = 0; | 1090 size_t seenInFlowPositionedChildren = 0; |
| 1091 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); | 1091 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); |
| 1092 for (size_t i = 0; i < children.size(); ++i) { | 1092 for (size_t i = 0; i < children.size(); ++i) { |
| 1093 RenderBox* child = children[i]; | 1093 RenderBox* child = children[i]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1138 // This will be fixed later in flipForRightToLeftColumn. | 1138 // This will be fixed later in flipForRightToLeftColumn. |
| 1139 LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxi
sOffset - childMainExtent : mainAxisOffset, | 1139 LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxi
sOffset - childMainExtent : mainAxisOffset, |
| 1140 crossAxisOffset + flowAwareMarginBeforeForChild(*child)); | 1140 crossAxisOffset + flowAwareMarginBeforeForChild(*child)); |
| 1141 | 1141 |
| 1142 // FIXME: Supporting layout deltas. | 1142 // FIXME: Supporting layout deltas. |
| 1143 setFlowAwareLocationForChild(*child, childLocation); | 1143 setFlowAwareLocationForChild(*child, childLocation); |
| 1144 mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(*child); | 1144 mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(*child); |
| 1145 | 1145 |
| 1146 ++seenInFlowPositionedChildren; | 1146 ++seenInFlowPositionedChildren; |
| 1147 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) | 1147 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) |
| 1148 mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContent(), numberOfChildrenForJustifyContent); | 1148 mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent); |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 if (isColumnFlow()) | 1151 if (isColumnFlow()) |
| 1152 setLogicalHeight(mainAxisOffset + flowAwareBorderEnd() + flowAwarePaddin
gEnd() + scrollbarLogicalHeight()); | 1152 setLogicalHeight(mainAxisOffset + flowAwareBorderEnd() + flowAwarePaddin
gEnd() + scrollbarLogicalHeight()); |
| 1153 | 1153 |
| 1154 if (style()->flexDirection() == FlowColumnReverse) { | 1154 if (style()->flexDirection() == FlowColumnReverse) { |
| 1155 // We have to do an extra pass for column-reverse to reposition the flex
items since the start depends | 1155 // We have to do an extra pass for column-reverse to reposition the flex
items since the start depends |
| 1156 // on the height of the flexbox, which we only know after we've position
ed all the flex items. | 1156 // on the height of the flexbox, which we only know after we've position
ed all the flex items. |
| 1157 updateLogicalHeight(); | 1157 updateLogicalHeight(); |
| 1158 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); | 1158 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); |
| 1159 } | 1159 } |
| 1160 | 1160 |
| 1161 if (m_numberOfInFlowChildrenOnFirstLine == -1) | 1161 if (m_numberOfInFlowChildrenOnFirstLine == -1) |
| 1162 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren; | 1162 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren; |
| 1163 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch
ildren.size(), maxAscent)); | 1163 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch
ildren.size(), maxAscent)); |
| 1164 crossAxisOffset += maxChildCrossAxisExtent; | 1164 crossAxisOffset += maxChildCrossAxisExtent; |
| 1165 } | 1165 } |
| 1166 | 1166 |
| 1167 void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children,
LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) | 1167 void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children,
LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) |
| 1168 { | 1168 { |
| 1169 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children | 1169 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children |
| 1170 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're | 1170 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're |
| 1171 // just moving the children to a new position. | 1171 // just moving the children to a new position. |
| 1172 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1172 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
| 1173 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); | 1173 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); |
| 1174 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1174 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
| 1175 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); | 1175 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); |
| 1176 | 1176 |
| 1177 size_t seenInFlowPositionedChildren = 0; | 1177 size_t seenInFlowPositionedChildren = 0; |
| 1178 for (size_t i = 0; i < children.size(); ++i) { | 1178 for (size_t i = 0; i < children.size(); ++i) { |
| 1179 RenderBox* child = children[i]; | 1179 RenderBox* child = children[i]; |
| 1180 | 1180 |
| 1181 if (child->isOutOfFlowPositioned()) { | 1181 if (child->isOutOfFlowPositioned()) { |
| 1182 child->layer()->setStaticBlockPosition(mainAxisOffset); | 1182 child->layer()->setStaticBlockPosition(mainAxisOffset); |
| 1183 continue; | 1183 continue; |
| 1184 } | 1184 } |
| 1185 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); | 1185 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); |
| 1186 | 1186 |
| 1187 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); | 1187 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); |
| 1188 | 1188 |
| 1189 mainAxisOffset -= flowAwareMarginStartForChild(*child); | 1189 mainAxisOffset -= flowAwareMarginStartForChild(*child); |
| 1190 | 1190 |
| 1191 ++seenInFlowPositionedChildren; | 1191 ++seenInFlowPositionedChildren; |
| 1192 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) | 1192 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) |
| 1193 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContent(), numberOfChildrenForJustifyContent); | 1193 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent); |
| 1194 } | 1194 } |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 static LayoutUnit initialAlignContentOffset(LayoutUnit availableFreeSpace, EAlig
nContent alignContent, unsigned numberOfLines) | 1197 static LayoutUnit initialAlignContentOffset(LayoutUnit availableFreeSpace, EAlig
nContent alignContent, unsigned numberOfLines) |
| 1198 { | 1198 { |
| 1199 if (numberOfLines <= 1) | 1199 if (numberOfLines <= 1) |
| 1200 return 0; | 1200 return 0; |
| 1201 if (alignContent == AlignContentFlexEnd) | 1201 if (alignContent == AlignContentFlexEnd) |
| 1202 return availableFreeSpace; | 1202 return availableFreeSpace; |
| 1203 if (alignContent == AlignContentCenter) | 1203 if (alignContent == AlignContentCenter) |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 ASSERT(child); | 1410 ASSERT(child); |
| 1411 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1411 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1412 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1412 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1413 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1413 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1414 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1414 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1415 } | 1415 } |
| 1416 } | 1416 } |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 } | 1419 } |
| OLD | NEW |