| 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 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP
addingHeight(); | 754 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP
addingHeight(); |
| 755 } | 755 } |
| 756 | 756 |
| 757 bool LayoutFlexibleBox::mainAxisLengthIsDefinite(const LayoutBox& child, const L
ength& flexBasis) const | 757 bool LayoutFlexibleBox::mainAxisLengthIsDefinite(const LayoutBox& child, const L
ength& flexBasis) const |
| 758 { | 758 { |
| 759 if (flexBasis.isAuto()) | 759 if (flexBasis.isAuto()) |
| 760 return false; | 760 return false; |
| 761 if (flexBasis.hasPercent()) { | 761 if (flexBasis.hasPercent()) { |
| 762 return isColumnFlow() ? | 762 return isColumnFlow() ? |
| 763 child.computePercentageLogicalHeight(flexBasis) != -1 : | 763 child.computePercentageLogicalHeight(flexBasis) != -1 : |
| 764 hasDefiniteLogicalWidth(); | 764 true; |
| 765 } | 765 } |
| 766 return true; | 766 return true; |
| 767 } | 767 } |
| 768 | 768 |
| 769 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, const
Length& length) const | 769 bool LayoutFlexibleBox::crossAxisLengthIsDefinite(const LayoutBox& child, const
Length& length) const |
| 770 { | 770 { |
| 771 if (length.isAuto()) | 771 if (length.isAuto()) |
| 772 return false; | 772 return false; |
| 773 if (length.hasPercent()) { | 773 if (length.hasPercent()) { |
| 774 return hasOrthogonalFlow(child) ? | 774 return hasOrthogonalFlow(child) ? |
| 775 hasDefiniteLogicalWidth() : | 775 true : |
| 776 child.computePercentageLogicalHeight(length) != -1; | 776 child.computePercentageLogicalHeight(length) != -1; |
| 777 } | 777 } |
| 778 // TODO(cbiesinger): Eventually we should support other types of sizes here.
Requires updating | 778 // TODO(cbiesinger): Eventually we should support other types of sizes here.
Requires updating |
| 779 // computeMainSizeFromAspectRatioUsing. | 779 // computeMainSizeFromAspectRatioUsing. |
| 780 return length.isFixed(); | 780 return length.isFixed(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(const LayoutBox& child)
const | 783 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(const LayoutBox& child)
const |
| 784 { | 784 { |
| 785 return !mainAxisLengthIsDefinite(child, flexBasisForChild(child)) && ( | 785 return !mainAxisLengthIsDefinite(child, flexBasisForChild(child)) && ( |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 transferredSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(ch
ild, transferredSize); | 1100 transferredSize = adjustChildSizeForAspectRatioCrossAxisMinAndMax(ch
ild, transferredSize); |
| 1101 minExtent = std::min(transferredSize, contentSize); | 1101 minExtent = std::min(transferredSize, contentSize); |
| 1102 } else { | 1102 } else { |
| 1103 minExtent = contentSize; | 1103 minExtent = contentSize; |
| 1104 } | 1104 } |
| 1105 } | 1105 } |
| 1106 ASSERT(minExtent >= 0); | 1106 ASSERT(minExtent >= 0); |
| 1107 return std::max(childSize, minExtent); | 1107 return std::max(childSize, minExtent); |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 LayoutUnit LayoutFlexibleBox::computeDefiniteLogicalWidth() | |
| 1111 { | |
| 1112 const Length& widthLength = styleRef().logicalWidth(); | |
| 1113 if (widthLength.hasPercent() && !hasDefiniteLogicalWidth()) | |
| 1114 return LayoutUnit(-1); | |
| 1115 | |
| 1116 if (widthLength.isAuto()) { | |
| 1117 // We can still have a definite width even with width: auto if we're a f
lex item ourselves | |
| 1118 if (!isFlexItem()) | |
| 1119 return LayoutUnit(-1); | |
| 1120 return toLayoutFlexibleBox(parent())->childLogicalWidthForPercentageReso
lution(*this); | |
| 1121 } | |
| 1122 LogicalExtentComputedValues computedValues; | |
| 1123 computeLogicalWidth(computedValues); | |
| 1124 return computedValues.m_extent; | |
| 1125 } | |
| 1126 | |
| 1127 LayoutUnit LayoutFlexibleBox::computeDefiniteLogicalHeight() | |
| 1128 { | |
| 1129 const Length& heightLength = styleRef().logicalHeight(); | |
| 1130 if (heightLength.hasPercent()) { | |
| 1131 return computePercentageLogicalHeight(heightLength); | |
| 1132 } | |
| 1133 if (heightLength.isAuto()) { | |
| 1134 // We can still have a definite height even with height: auto if we're a
flex item ourselves | |
| 1135 if (!isFlexItem()) | |
| 1136 return LayoutUnit(-1); | |
| 1137 return toLayoutFlexibleBox(parent())->childLogicalHeightForPercentageRes
olution(*this); | |
| 1138 } | |
| 1139 LogicalExtentComputedValues computedValues; | |
| 1140 computeLogicalHeight(LayoutUnit(-1), LayoutUnit(), computedValues); | |
| 1141 return computedValues.m_extent; | |
| 1142 } | |
| 1143 | |
| 1144 LayoutUnit LayoutFlexibleBox::crossSizeForPercentageResolution(const LayoutBox&
child) | 1110 LayoutUnit LayoutFlexibleBox::crossSizeForPercentageResolution(const LayoutBox&
child) |
| 1145 { | 1111 { |
| 1146 if (alignmentForChild(child) != ItemPositionStretch) | 1112 if (alignmentForChild(child) != ItemPositionStretch) |
| 1147 return LayoutUnit(-1); | 1113 return LayoutUnit(-1); |
| 1148 | 1114 |
| 1149 // Here we implement https://drafts.csswg.org/css-flexbox/#algo-stretch | 1115 // Here we implement https://drafts.csswg.org/css-flexbox/#algo-stretch |
| 1150 if (hasOrthogonalFlow(child) && child.hasOverrideLogicalContentWidth()) | 1116 if (hasOrthogonalFlow(child) && child.hasOverrideLogicalContentWidth()) |
| 1151 return child.overrideLogicalContentWidth(); | 1117 return child.overrideLogicalContentWidth(); |
| 1152 if (!hasOrthogonalFlow(child) && child.hasOverrideLogicalContentHeight()) | 1118 if (!hasOrthogonalFlow(child) && child.hasOverrideLogicalContentHeight()) |
| 1153 return child.overrideLogicalContentHeight(); | 1119 return child.overrideLogicalContentHeight(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1182 return child.hasOverrideLogicalContentWidth() ? child.overrideLogicalContent
Width() : LayoutUnit(-1); | 1148 return child.hasOverrideLogicalContentWidth() ? child.overrideLogicalContent
Width() : LayoutUnit(-1); |
| 1183 } | 1149 } |
| 1184 | 1150 |
| 1185 LayoutUnit LayoutFlexibleBox::childLogicalHeightForPercentageResolution(const La
youtBox& child) | 1151 LayoutUnit LayoutFlexibleBox::childLogicalHeightForPercentageResolution(const La
youtBox& child) |
| 1186 { | 1152 { |
| 1187 if (!hasOrthogonalFlow(child)) | 1153 if (!hasOrthogonalFlow(child)) |
| 1188 return crossSizeForPercentageResolution(child); | 1154 return crossSizeForPercentageResolution(child); |
| 1189 return mainSizeForPercentageResolution(child); | 1155 return mainSizeForPercentageResolution(child); |
| 1190 } | 1156 } |
| 1191 | 1157 |
| 1192 LayoutUnit LayoutFlexibleBox::childLogicalWidthForPercentageResolution(const Lay
outBox& child) | |
| 1193 { | |
| 1194 if (hasOrthogonalFlow(child)) | |
| 1195 return crossSizeForPercentageResolution(child); | |
| 1196 return mainSizeForPercentageResolution(child); | |
| 1197 } | |
| 1198 | |
| 1199 LayoutUnit LayoutFlexibleBox::adjustChildSizeForAspectRatioCrossAxisMinAndMax(co
nst LayoutBox& child, LayoutUnit childSize) | 1158 LayoutUnit LayoutFlexibleBox::adjustChildSizeForAspectRatioCrossAxisMinAndMax(co
nst LayoutBox& child, LayoutUnit childSize) |
| 1200 { | 1159 { |
| 1201 Length crossMin = isHorizontalFlow() ? child.style()->minHeight() : child.st
yle()->minWidth(); | 1160 Length crossMin = isHorizontalFlow() ? child.style()->minHeight() : child.st
yle()->minWidth(); |
| 1202 Length crossMax = isHorizontalFlow() ? child.style()->maxHeight() : child.st
yle()->maxWidth(); | 1161 Length crossMax = isHorizontalFlow() ? child.style()->maxHeight() : child.st
yle()->maxWidth(); |
| 1203 | 1162 |
| 1204 | 1163 |
| 1205 if (crossAxisLengthIsDefinite(child, crossMax)) { | 1164 if (crossAxisLengthIsDefinite(child, crossMax)) { |
| 1206 LayoutUnit maxValue = computeMainSizeFromAspectRatioUsing(child, crossMa
x); | 1165 LayoutUnit maxValue = computeMainSizeFromAspectRatioUsing(child, crossMa
x); |
| 1207 childSize = std::min(maxValue, childSize); | 1166 childSize = std::min(maxValue, childSize); |
| 1208 } | 1167 } |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 ASSERT(child); | 1862 ASSERT(child); |
| 1904 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1863 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1905 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1864 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1906 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1865 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1907 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1866 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1908 } | 1867 } |
| 1909 } | 1868 } |
| 1910 } | 1869 } |
| 1911 | 1870 |
| 1912 } // namespace blink | 1871 } // namespace blink |
| OLD | NEW |