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 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 } | 942 } |
943 | 943 |
944 if (totalViolation) | 944 if (totalViolation) |
945 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, ava
ilableFreeSpace, totalFlexGrow, totalWeightedFlexShrink, inflexibleItems, hasInf
initeLineLength); | 945 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, ava
ilableFreeSpace, totalFlexGrow, totalWeightedFlexShrink, inflexibleItems, hasInf
initeLineLength); |
946 else | 946 else |
947 availableFreeSpace -= usedFreeSpace; | 947 availableFreeSpace -= usedFreeSpace; |
948 | 948 |
949 return !totalViolation; | 949 return !totalViolation; |
950 } | 950 } |
951 | 951 |
952 static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, EJu
stifyContent justifyContent, unsigned numberOfChildren) | 952 static LayoutUnit initialJustifyContentOffset(LayoutUnit availableFreeSpace, Con
tentPosition justifyContent, ContentDistributionType justifyContentDistribution,
unsigned numberOfChildren) |
953 { | 953 { |
954 if (justifyContent == JustifyFlexEnd) | 954 if (justifyContent == ContentPositionFlexEnd) |
955 return availableFreeSpace; | 955 return availableFreeSpace; |
956 if (justifyContent == JustifyCenter) | 956 if (justifyContent == ContentPositionCenter) |
957 return availableFreeSpace / 2; | 957 return availableFreeSpace / 2; |
958 if (justifyContent == JustifySpaceAround) { | 958 if (justifyContentDistribution == ContentDistributionSpaceAround) { |
959 if (availableFreeSpace > 0 && numberOfChildren) | 959 if (availableFreeSpace > 0 && numberOfChildren) |
960 return availableFreeSpace / (2 * numberOfChildren); | 960 return availableFreeSpace / (2 * numberOfChildren); |
961 else | 961 else |
962 return availableFreeSpace / 2; | 962 return availableFreeSpace / 2; |
963 } | 963 } |
964 return 0; | 964 return 0; |
965 } | 965 } |
966 | 966 |
967 static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpa
ce, EJustifyContent justifyContent, unsigned numberOfChildren) | 967 static LayoutUnit justifyContentSpaceBetweenChildren(LayoutUnit availableFreeSpa
ce, ContentDistributionType justifyContentDistribution, unsigned numberOfChildre
n) |
968 { | 968 { |
969 if (availableFreeSpace > 0 && numberOfChildren > 1) { | 969 if (availableFreeSpace > 0 && numberOfChildren > 1) { |
970 if (justifyContent == JustifySpaceBetween) | 970 if (justifyContentDistribution == ContentDistributionSpaceBetween) |
971 return availableFreeSpace / (numberOfChildren - 1); | 971 return availableFreeSpace / (numberOfChildren - 1); |
972 if (justifyContent == JustifySpaceAround) | 972 if (justifyContentDistribution == ContentDistributionSpaceAround) |
973 return availableFreeSpace / numberOfChildren; | 973 return availableFreeSpace / numberOfChildren; |
974 } | 974 } |
975 return 0; | 975 return 0; |
976 } | 976 } |
977 | 977 |
978 void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil
dPreferredSize) | 978 void RenderFlexibleBox::setLogicalOverrideSize(RenderBox& child, LayoutUnit chil
dPreferredSize) |
979 { | 979 { |
980 if (hasOrthogonalFlow(child)) | 980 if (hasOrthogonalFlow(child)) |
981 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); | 981 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); |
982 else | 982 else |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 return isHorizontalFlow() && child.style()->height().isAuto(); | 1055 return isHorizontalFlow() && child.style()->height().isAuto(); |
1056 } | 1056 } |
1057 | 1057 |
1058 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) | 1058 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) |
1059 { | 1059 { |
1060 ASSERT(childSizes.size() == children.size()); | 1060 ASSERT(childSizes.size() == children.size()); |
1061 | 1061 |
1062 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1062 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
1063 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); | 1063 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); |
1064 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; | 1064 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; |
1065 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1065 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
1066 if (style()->flexDirection() == FlowRowReverse) | 1066 if (style()->flexDirection() == FlowRowReverse) |
1067 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); | 1067 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); |
1068 | 1068 |
1069 LayoutUnit totalMainExtent = mainAxisExtent(); | 1069 LayoutUnit totalMainExtent = mainAxisExtent(); |
1070 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. | 1070 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. |
1071 LayoutUnit maxChildCrossAxisExtent = 0; | 1071 LayoutUnit maxChildCrossAxisExtent = 0; |
1072 size_t seenInFlowPositionedChildren = 0; | 1072 size_t seenInFlowPositionedChildren = 0; |
1073 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); | 1073 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); |
1074 for (size_t i = 0; i < children.size(); ++i) { | 1074 for (size_t i = 0; i < children.size(); ++i) { |
1075 RenderBox* child = children[i]; | 1075 RenderBox* child = children[i]; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 // This will be fixed later in flipForRightToLeftColumn. | 1120 // This will be fixed later in flipForRightToLeftColumn. |
1121 LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxi
sOffset - childMainExtent : mainAxisOffset, | 1121 LayoutPoint childLocation(shouldFlipMainAxis ? totalMainExtent - mainAxi
sOffset - childMainExtent : mainAxisOffset, |
1122 crossAxisOffset + flowAwareMarginBeforeForChild(*child)); | 1122 crossAxisOffset + flowAwareMarginBeforeForChild(*child)); |
1123 | 1123 |
1124 // FIXME: Supporting layout deltas. | 1124 // FIXME: Supporting layout deltas. |
1125 setFlowAwareLocationForChild(*child, childLocation); | 1125 setFlowAwareLocationForChild(*child, childLocation); |
1126 mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(*child); | 1126 mainAxisOffset += childMainExtent + flowAwareMarginEndForChild(*child); |
1127 | 1127 |
1128 ++seenInFlowPositionedChildren; | 1128 ++seenInFlowPositionedChildren; |
1129 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) | 1129 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) |
1130 mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContent(), numberOfChildrenForJustifyContent); | 1130 mainAxisOffset += justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent); |
1131 } | 1131 } |
1132 | 1132 |
1133 if (isColumnFlow()) | 1133 if (isColumnFlow()) |
1134 setLogicalHeight(mainAxisOffset + flowAwareBorderEnd() + flowAwarePaddin
gEnd() + scrollbarLogicalHeight()); | 1134 setLogicalHeight(mainAxisOffset + flowAwareBorderEnd() + flowAwarePaddin
gEnd() + scrollbarLogicalHeight()); |
1135 | 1135 |
1136 if (style()->flexDirection() == FlowColumnReverse) { | 1136 if (style()->flexDirection() == FlowColumnReverse) { |
1137 // We have to do an extra pass for column-reverse to reposition the flex
items since the start depends | 1137 // We have to do an extra pass for column-reverse to reposition the flex
items since the start depends |
1138 // on the height of the flexbox, which we only know after we've position
ed all the flex items. | 1138 // on the height of the flexbox, which we only know after we've position
ed all the flex items. |
1139 updateLogicalHeight(); | 1139 updateLogicalHeight(); |
1140 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); | 1140 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); |
1141 } | 1141 } |
1142 | 1142 |
1143 if (m_numberOfInFlowChildrenOnFirstLine == -1) | 1143 if (m_numberOfInFlowChildrenOnFirstLine == -1) |
1144 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren; | 1144 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren; |
1145 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch
ildren.size(), maxAscent)); | 1145 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch
ildren.size(), maxAscent)); |
1146 crossAxisOffset += maxChildCrossAxisExtent; | 1146 crossAxisOffset += maxChildCrossAxisExtent; |
1147 } | 1147 } |
1148 | 1148 |
1149 void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children,
LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) | 1149 void RenderFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children,
LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) |
1150 { | 1150 { |
1151 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children | 1151 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children |
1152 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're | 1152 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're |
1153 // just moving the children to a new position. | 1153 // just moving the children to a new position. |
1154 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1154 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
1155 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); | 1155 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); |
1156 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), numberOfChildrenForJustifyContent); | 1156 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
1157 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); | 1157 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); |
1158 | 1158 |
1159 size_t seenInFlowPositionedChildren = 0; | 1159 size_t seenInFlowPositionedChildren = 0; |
1160 for (size_t i = 0; i < children.size(); ++i) { | 1160 for (size_t i = 0; i < children.size(); ++i) { |
1161 RenderBox* child = children[i]; | 1161 RenderBox* child = children[i]; |
1162 | 1162 |
1163 if (child->isOutOfFlowPositioned()) { | 1163 if (child->isOutOfFlowPositioned()) { |
1164 child->layer()->setStaticBlockPosition(mainAxisOffset); | 1164 child->layer()->setStaticBlockPosition(mainAxisOffset); |
1165 continue; | 1165 continue; |
1166 } | 1166 } |
1167 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); | 1167 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); |
1168 | 1168 |
1169 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); | 1169 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); |
1170 | 1170 |
1171 mainAxisOffset -= flowAwareMarginStartForChild(*child); | 1171 mainAxisOffset -= flowAwareMarginStartForChild(*child); |
1172 | 1172 |
1173 ++seenInFlowPositionedChildren; | 1173 ++seenInFlowPositionedChildren; |
1174 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) | 1174 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) |
1175 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContent(), numberOfChildrenForJustifyContent); | 1175 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp
ace, style()->justifyContentDistribution(), numberOfChildrenForJustifyContent); |
1176 } | 1176 } |
1177 } | 1177 } |
1178 | 1178 |
1179 static LayoutUnit initialAlignContentOffset(LayoutUnit availableFreeSpace, EAlig
nContent alignContent, unsigned numberOfLines) | 1179 static LayoutUnit initialAlignContentOffset(LayoutUnit availableFreeSpace, EAlig
nContent alignContent, unsigned numberOfLines) |
1180 { | 1180 { |
1181 if (numberOfLines <= 1) | 1181 if (numberOfLines <= 1) |
1182 return 0; | 1182 return 0; |
1183 if (alignContent == AlignContentFlexEnd) | 1183 if (alignContent == AlignContentFlexEnd) |
1184 return availableFreeSpace; | 1184 return availableFreeSpace; |
1185 if (alignContent == AlignContentCenter) | 1185 if (alignContent == AlignContentCenter) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 ASSERT(child); | 1393 ASSERT(child); |
1394 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1394 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1395 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1395 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1396 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1396 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1397 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1397 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1398 } | 1398 } |
1399 } | 1399 } |
1400 } | 1400 } |
1401 | 1401 |
1402 } | 1402 } |
OLD | NEW |