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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 { | 52 { |
53 } | 53 } |
54 | 54 |
55 LayoutUnit crossAxisOffset; | 55 LayoutUnit crossAxisOffset; |
56 LayoutUnit crossAxisExtent; | 56 LayoutUnit crossAxisExtent; |
57 size_t numberOfChildren; | 57 size_t numberOfChildren; |
58 LayoutUnit maxAscent; | 58 LayoutUnit maxAscent; |
59 }; | 59 }; |
60 | 60 |
61 struct RenderFlexibleBox::Violation { | 61 struct RenderFlexibleBox::Violation { |
62 Violation(RenderBox* child, LayoutUnit childSize) | 62 Violation(LayoutBox* child, LayoutUnit childSize) |
63 : child(child) | 63 : child(child) |
64 , childSize(childSize) | 64 , childSize(childSize) |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
68 RenderBox* child; | 68 LayoutBox* child; |
69 LayoutUnit childSize; | 69 LayoutUnit childSize; |
70 }; | 70 }; |
71 | 71 |
72 | 72 |
73 RenderFlexibleBox::RenderFlexibleBox(Element* element) | 73 RenderFlexibleBox::RenderFlexibleBox(Element* element) |
74 : RenderBlock(element) | 74 : RenderBlock(element) |
75 , m_orderIterator(this) | 75 , m_orderIterator(this) |
76 , m_numberOfInFlowChildrenOnFirstLine(-1) | 76 , m_numberOfInFlowChildrenOnFirstLine(-1) |
77 { | 77 { |
78 ASSERT(!childrenInline()); | 78 ASSERT(!childrenInline()); |
(...skipping 13 matching lines...) Expand all Loading... |
92 const char* RenderFlexibleBox::renderName() const | 92 const char* RenderFlexibleBox::renderName() const |
93 { | 93 { |
94 return "RenderFlexibleBox"; | 94 return "RenderFlexibleBox"; |
95 } | 95 } |
96 | 96 |
97 void RenderFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt
h, LayoutUnit& maxLogicalWidth) const | 97 void RenderFlexibleBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidt
h, LayoutUnit& maxLogicalWidth) const |
98 { | 98 { |
99 // FIXME: We're ignoring flex-basis here and we shouldn't. We can't start ho
noring it though until | 99 // FIXME: We're ignoring flex-basis here and we shouldn't. We can't start ho
noring it though until |
100 // the flex shorthand stops setting it to 0. | 100 // the flex shorthand stops setting it to 0. |
101 // See https://bugs.webkit.org/show_bug.cgi?id=116117 and http://crbug.com/2
40765. | 101 // See https://bugs.webkit.org/show_bug.cgi?id=116117 and http://crbug.com/2
40765. |
102 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 102 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
103 if (child->isOutOfFlowPositioned()) | 103 if (child->isOutOfFlowPositioned()) |
104 continue; | 104 continue; |
105 | 105 |
106 LayoutUnit margin = marginIntrinsicLogicalWidthForChild(*child); | 106 LayoutUnit margin = marginIntrinsicLogicalWidthForChild(*child); |
107 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHo
rizontalWritingMode(); | 107 bool hasOrthogonalWritingMode = child->isHorizontalWritingMode() != isHo
rizontalWritingMode(); |
108 LayoutUnit minPreferredLogicalWidth = hasOrthogonalWritingMode ? child->
logicalHeight() : child->minPreferredLogicalWidth(); | 108 LayoutUnit minPreferredLogicalWidth = hasOrthogonalWritingMode ? child->
logicalHeight() : child->minPreferredLogicalWidth(); |
109 LayoutUnit maxPreferredLogicalWidth = hasOrthogonalWritingMode ? child->
logicalHeight() : child->maxPreferredLogicalWidth(); | 109 LayoutUnit maxPreferredLogicalWidth = hasOrthogonalWritingMode ? child->
logicalHeight() : child->maxPreferredLogicalWidth(); |
110 minPreferredLogicalWidth += margin; | 110 minPreferredLogicalWidth += margin; |
111 maxPreferredLogicalWidth += margin; | 111 maxPreferredLogicalWidth += margin; |
112 if (!isColumnFlow()) { | 112 if (!isColumnFlow()) { |
113 maxLogicalWidth += maxPreferredLogicalWidth; | 113 maxLogicalWidth += maxPreferredLogicalWidth; |
114 if (isMultiline()) { | 114 if (isMultiline()) { |
115 // For multiline, the min preferred width is if you put a break
between each item. | 115 // For multiline, the min preferred width is if you put a break
between each item. |
116 minLogicalWidth = std::max(minLogicalWidth, minPreferredLogicalW
idth); | 116 minLogicalWidth = std::max(minLogicalWidth, minPreferredLogicalW
idth); |
117 } else | 117 } else |
118 minLogicalWidth += minPreferredLogicalWidth; | 118 minLogicalWidth += minPreferredLogicalWidth; |
119 } else { | 119 } else { |
120 minLogicalWidth = std::max(minPreferredLogicalWidth, minLogicalWidth
); | 120 minLogicalWidth = std::max(minPreferredLogicalWidth, minLogicalWidth
); |
121 maxLogicalWidth = std::max(maxPreferredLogicalWidth, maxLogicalWidth
); | 121 maxLogicalWidth = std::max(maxPreferredLogicalWidth, maxLogicalWidth
); |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); | 125 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); |
126 | 126 |
127 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); | 127 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); |
128 maxLogicalWidth += scrollbarWidth; | 128 maxLogicalWidth += scrollbarWidth; |
129 minLogicalWidth += scrollbarWidth; | 129 minLogicalWidth += scrollbarWidth; |
130 } | 130 } |
131 | 131 |
132 static int synthesizedBaselineFromContentBox(const RenderBox& box, LineDirection
Mode direction) | 132 static int synthesizedBaselineFromContentBox(const LayoutBox& box, LineDirection
Mode direction) |
133 { | 133 { |
134 if (direction == HorizontalLine) { | 134 if (direction == HorizontalLine) { |
135 return box.size().height() - box.borderBottom() - box.paddingBottom() -
box.verticalScrollbarWidth(); | 135 return box.size().height() - box.borderBottom() - box.paddingBottom() -
box.verticalScrollbarWidth(); |
136 } | 136 } |
137 return box.size().width() - box.borderLeft() - box.paddingLeft() - box.horiz
ontalScrollbarHeight(); | 137 return box.size().width() - box.borderLeft() - box.paddingLeft() - box.horiz
ontalScrollbarHeight(); |
138 } | 138 } |
139 | 139 |
140 int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di
rection, LinePositionMode mode) const | 140 int RenderFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di
rection, LinePositionMode mode) const |
141 { | 141 { |
142 ASSERT(mode == PositionOnContainingLine); | 142 ASSERT(mode == PositionOnContainingLine); |
143 int baseline = firstLineBoxBaseline(); | 143 int baseline = firstLineBoxBaseline(); |
144 if (baseline == -1) | 144 if (baseline == -1) |
145 baseline = synthesizedBaselineFromContentBox(*this, direction); | 145 baseline = synthesizedBaselineFromContentBox(*this, direction); |
146 | 146 |
147 return beforeMarginInLineDirection(direction) + baseline; | 147 return beforeMarginInLineDirection(direction) + baseline; |
148 } | 148 } |
149 | 149 |
150 int RenderFlexibleBox::firstLineBoxBaseline() const | 150 int RenderFlexibleBox::firstLineBoxBaseline() const |
151 { | 151 { |
152 if (isWritingModeRoot() || m_numberOfInFlowChildrenOnFirstLine <= 0) | 152 if (isWritingModeRoot() || m_numberOfInFlowChildrenOnFirstLine <= 0) |
153 return -1; | 153 return -1; |
154 RenderBox* baselineChild = 0; | 154 LayoutBox* baselineChild = 0; |
155 int childNumber = 0; | 155 int childNumber = 0; |
156 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 156 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
157 if (child->isOutOfFlowPositioned()) | 157 if (child->isOutOfFlowPositioned()) |
158 continue; | 158 continue; |
159 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMargins
InCrossAxis(*child)) { | 159 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMargins
InCrossAxis(*child)) { |
160 baselineChild = child; | 160 baselineChild = child; |
161 break; | 161 break; |
162 } | 162 } |
163 if (!baselineChild) | 163 if (!baselineChild) |
164 baselineChild = child; | 164 baselineChild = child; |
165 | 165 |
166 ++childNumber; | 166 ++childNumber; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 m_intrinsicSizeAlongMainAxis.remove(child); | 203 m_intrinsicSizeAlongMainAxis.remove(child); |
204 } | 204 } |
205 | 205 |
206 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const LayoutStyle*
oldStyle) | 206 void RenderFlexibleBox::styleDidChange(StyleDifference diff, const LayoutStyle*
oldStyle) |
207 { | 207 { |
208 RenderBlock::styleDidChange(diff, oldStyle); | 208 RenderBlock::styleDidChange(diff, oldStyle); |
209 | 209 |
210 if (oldStyle && oldStyle->alignItems() == ItemPositionStretch && diff.needsF
ullLayout()) { | 210 if (oldStyle && oldStyle->alignItems() == ItemPositionStretch && diff.needsF
ullLayout()) { |
211 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. | 211 // Flex items that were previously stretching need to be relayed out so
we can compute new available cross axis space. |
212 // This is only necessary for stretching since other alignment values do
n't change the size of the box. | 212 // This is only necessary for stretching since other alignment values do
n't change the size of the box. |
213 for (RenderBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { | 213 for (LayoutBox* child = firstChildBox(); child; child = child->nextSibli
ngBox()) { |
214 ItemPosition previousAlignment = LayoutStyle::resolveAlignment(*oldS
tyle, child->styleRef(), ItemPositionStretch); | 214 ItemPosition previousAlignment = LayoutStyle::resolveAlignment(*oldS
tyle, child->styleRef(), ItemPositionStretch); |
215 if (previousAlignment == ItemPositionStretch && previousAlignment !=
LayoutStyle::resolveAlignment(styleRef(), child->styleRef(), ItemPositionStretc
h)) | 215 if (previousAlignment == ItemPositionStretch && previousAlignment !=
LayoutStyle::resolveAlignment(styleRef(), child->styleRef(), ItemPositionStretc
h)) |
216 child->setChildNeedsLayout(MarkOnlyThis); | 216 child->setChildNeedsLayout(MarkOnlyThis); |
217 } | 217 } |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void RenderFlexibleBox::layoutBlock(bool relayoutChildren) | 221 void RenderFlexibleBox::layoutBlock(bool relayoutChildren) |
222 { | 222 { |
223 ASSERT(needsLayout()); | 223 ASSERT(needsLayout()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 // Update our scroll information if we're overflow:auto/scroll/hidden now th
at we know if | 262 // Update our scroll information if we're overflow:auto/scroll/hidden now th
at we know if |
263 // we overflow or not. | 263 // we overflow or not. |
264 updateScrollInfoAfterLayout(); | 264 updateScrollInfoAfterLayout(); |
265 | 265 |
266 clearNeedsLayout(); | 266 clearNeedsLayout(); |
267 } | 267 } |
268 | 268 |
269 void RenderFlexibleBox::appendChildFrameRects(ChildFrameRects& childFrameRects) | 269 void RenderFlexibleBox::appendChildFrameRects(ChildFrameRects& childFrameRects) |
270 { | 270 { |
271 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 271 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
272 if (!child->isOutOfFlowPositioned()) | 272 if (!child->isOutOfFlowPositioned()) |
273 childFrameRects.append(child->frameRect()); | 273 childFrameRects.append(child->frameRect()); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void RenderFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) | 277 void RenderFlexibleBox::paintChildren(const PaintInfo& paintInfo, const LayoutPo
int& paintOffset) |
278 { | 278 { |
279 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); | 279 BlockPainter::paintChildrenOfFlexibleBox(*this, paintInfo, paintOffset); |
280 } | 280 } |
281 | 281 |
282 void RenderFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon
text>& lineContexts) | 282 void RenderFlexibleBox::repositionLogicalHeightDependentFlexItems(Vector<LineCon
text>& lineContexts) |
283 { | 283 { |
284 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line
Contexts[0].crossAxisOffset; | 284 LayoutUnit crossAxisStartEdge = lineContexts.isEmpty() ? LayoutUnit() : line
Contexts[0].crossAxisOffset; |
285 alignFlexLines(lineContexts); | 285 alignFlexLines(lineContexts); |
286 | 286 |
287 alignChildren(lineContexts); | 287 alignChildren(lineContexts); |
288 | 288 |
289 if (style()->flexWrap() == FlexWrapReverse) | 289 if (style()->flexWrap() == FlexWrapReverse) |
290 flipForWrapReverse(lineContexts, crossAxisStartEdge); | 290 flipForWrapReverse(lineContexts, crossAxisStartEdge); |
291 | 291 |
292 // direction:rtl + flex-direction:column means the cross-axis direction is f
lipped. | 292 // direction:rtl + flex-direction:column means the cross-axis direction is f
lipped. |
293 flipForRightToLeftColumn(); | 293 flipForRightToLeftColumn(); |
294 } | 294 } |
295 | 295 |
296 LayoutUnit RenderFlexibleBox::clientLogicalBottomAfterRepositioning() | 296 LayoutUnit RenderFlexibleBox::clientLogicalBottomAfterRepositioning() |
297 { | 297 { |
298 LayoutUnit maxChildLogicalBottom = 0; | 298 LayoutUnit maxChildLogicalBottom = 0; |
299 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 299 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
300 if (child->isOutOfFlowPositioned()) | 300 if (child->isOutOfFlowPositioned()) |
301 continue; | 301 continue; |
302 LayoutUnit childLogicalBottom = logicalTopForChild(*child) + logicalHeig
htForChild(*child) + marginAfterForChild(*child); | 302 LayoutUnit childLogicalBottom = logicalTopForChild(*child) + logicalHeig
htForChild(*child) + marginAfterForChild(*child); |
303 maxChildLogicalBottom = std::max(maxChildLogicalBottom, childLogicalBott
om); | 303 maxChildLogicalBottom = std::max(maxChildLogicalBottom, childLogicalBott
om); |
304 } | 304 } |
305 return std::max(clientLogicalBottom(), maxChildLogicalBottom + paddingAfter(
)); | 305 return std::max(clientLogicalBottom(), maxChildLogicalBottom + paddingAfter(
)); |
306 } | 306 } |
307 | 307 |
308 bool RenderFlexibleBox::hasOrthogonalFlow(RenderBox& child) const | 308 bool RenderFlexibleBox::hasOrthogonalFlow(LayoutBox& child) const |
309 { | 309 { |
310 // FIXME: If the child is a flexbox, then we need to check isHorizontalFlow. | 310 // FIXME: If the child is a flexbox, then we need to check isHorizontalFlow. |
311 return isHorizontalFlow() != child.isHorizontalWritingMode(); | 311 return isHorizontalFlow() != child.isHorizontalWritingMode(); |
312 } | 312 } |
313 | 313 |
314 bool RenderFlexibleBox::isColumnFlow() const | 314 bool RenderFlexibleBox::isColumnFlow() const |
315 { | 315 { |
316 return style()->isColumnFlexDirection(); | 316 return style()->isColumnFlexDirection(); |
317 } | 317 } |
318 | 318 |
319 bool RenderFlexibleBox::isHorizontalFlow() const | 319 bool RenderFlexibleBox::isHorizontalFlow() const |
320 { | 320 { |
321 if (isHorizontalWritingMode()) | 321 if (isHorizontalWritingMode()) |
322 return !isColumnFlow(); | 322 return !isColumnFlow(); |
323 return isColumnFlow(); | 323 return isColumnFlow(); |
324 } | 324 } |
325 | 325 |
326 bool RenderFlexibleBox::isLeftToRightFlow() const | 326 bool RenderFlexibleBox::isLeftToRightFlow() const |
327 { | 327 { |
328 if (isColumnFlow()) | 328 if (isColumnFlow()) |
329 return style()->writingMode() == TopToBottomWritingMode || style()->writ
ingMode() == LeftToRightWritingMode; | 329 return style()->writingMode() == TopToBottomWritingMode || style()->writ
ingMode() == LeftToRightWritingMode; |
330 return style()->isLeftToRightDirection() ^ (style()->flexDirection() == Flow
RowReverse); | 330 return style()->isLeftToRightDirection() ^ (style()->flexDirection() == Flow
RowReverse); |
331 } | 331 } |
332 | 332 |
333 bool RenderFlexibleBox::isMultiline() const | 333 bool RenderFlexibleBox::isMultiline() const |
334 { | 334 { |
335 return style()->flexWrap() != FlexNoWrap; | 335 return style()->flexWrap() != FlexNoWrap; |
336 } | 336 } |
337 | 337 |
338 Length RenderFlexibleBox::flexBasisForChild(RenderBox& child) const | 338 Length RenderFlexibleBox::flexBasisForChild(LayoutBox& child) const |
339 { | 339 { |
340 Length flexLength = child.style()->flexBasis(); | 340 Length flexLength = child.style()->flexBasis(); |
341 if (flexLength.isAuto()) | 341 if (flexLength.isAuto()) |
342 flexLength = isHorizontalFlow() ? child.style()->width() : child.style()
->height(); | 342 flexLength = isHorizontalFlow() ? child.style()->width() : child.style()
->height(); |
343 return flexLength; | 343 return flexLength; |
344 } | 344 } |
345 | 345 |
346 LayoutUnit RenderFlexibleBox::crossAxisExtentForChild(RenderBox& child) const | 346 LayoutUnit RenderFlexibleBox::crossAxisExtentForChild(LayoutBox& child) const |
347 { | 347 { |
348 return isHorizontalFlow() ? child.size().height() : child.size().width(); | 348 return isHorizontalFlow() ? child.size().height() : child.size().width(); |
349 } | 349 } |
350 | 350 |
351 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(RenderBox
& child) | 351 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(LayoutBox
& child) |
352 { | 352 { |
353 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); | 353 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
354 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 354 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
355 } | 355 } |
356 | 356 |
357 LayoutUnit RenderFlexibleBox::childIntrinsicHeight(RenderBox& child) const | 357 LayoutUnit RenderFlexibleBox::childIntrinsicHeight(LayoutBox& child) const |
358 { | 358 { |
359 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) | 359 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) |
360 return constrainedChildIntrinsicContentLogicalHeight(child); | 360 return constrainedChildIntrinsicContentLogicalHeight(child); |
361 return child.size().height(); | 361 return child.size().height(); |
362 } | 362 } |
363 | 363 |
364 LayoutUnit RenderFlexibleBox::childIntrinsicWidth(RenderBox& child) const | 364 LayoutUnit RenderFlexibleBox::childIntrinsicWidth(LayoutBox& child) const |
365 { | 365 { |
366 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) | 366 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) |
367 return constrainedChildIntrinsicContentLogicalHeight(child); | 367 return constrainedChildIntrinsicContentLogicalHeight(child); |
368 return child.size().width(); | 368 return child.size().width(); |
369 } | 369 } |
370 | 370 |
371 LayoutUnit RenderFlexibleBox::crossAxisIntrinsicExtentForChild(RenderBox& child)
const | 371 LayoutUnit RenderFlexibleBox::crossAxisIntrinsicExtentForChild(LayoutBox& child)
const |
372 { | 372 { |
373 return isHorizontalFlow() ? childIntrinsicHeight(child) : childIntrinsicWidt
h(child); | 373 return isHorizontalFlow() ? childIntrinsicHeight(child) : childIntrinsicWidt
h(child); |
374 } | 374 } |
375 | 375 |
376 LayoutUnit RenderFlexibleBox::mainAxisExtentForChild(RenderBox& child) const | 376 LayoutUnit RenderFlexibleBox::mainAxisExtentForChild(LayoutBox& child) const |
377 { | 377 { |
378 return isHorizontalFlow() ? child.size().width() : child.size().height(); | 378 return isHorizontalFlow() ? child.size().width() : child.size().height(); |
379 } | 379 } |
380 | 380 |
381 LayoutUnit RenderFlexibleBox::crossAxisExtent() const | 381 LayoutUnit RenderFlexibleBox::crossAxisExtent() const |
382 { | 382 { |
383 return isHorizontalFlow() ? size().height() : size().width(); | 383 return isHorizontalFlow() ? size().height() : size().width(); |
384 } | 384 } |
385 | 385 |
386 LayoutUnit RenderFlexibleBox::mainAxisExtent() const | 386 LayoutUnit RenderFlexibleBox::mainAxisExtent() const |
(...skipping 13 matching lines...) Expand all Loading... |
400 LayoutUnit borderPaddingAndScrollbar = borderAndPaddingLogicalHeight() +
scrollbarLogicalHeight(); | 400 LayoutUnit borderPaddingAndScrollbar = borderAndPaddingLogicalHeight() +
scrollbarLogicalHeight(); |
401 LayoutUnit borderBoxLogicalHeight = contentLogicalHeight + borderPadding
AndScrollbar; | 401 LayoutUnit borderBoxLogicalHeight = contentLogicalHeight + borderPadding
AndScrollbar; |
402 computeLogicalHeight(borderBoxLogicalHeight, logicalTop(), computedValue
s); | 402 computeLogicalHeight(borderBoxLogicalHeight, logicalTop(), computedValue
s); |
403 if (computedValues.m_extent == LayoutUnit::max()) | 403 if (computedValues.m_extent == LayoutUnit::max()) |
404 return computedValues.m_extent; | 404 return computedValues.m_extent; |
405 return std::max(LayoutUnit(0), computedValues.m_extent - borderPaddingAn
dScrollbar); | 405 return std::max(LayoutUnit(0), computedValues.m_extent - borderPaddingAn
dScrollbar); |
406 } | 406 } |
407 return contentLogicalWidth(); | 407 return contentLogicalWidth(); |
408 } | 408 } |
409 | 409 |
410 LayoutUnit RenderFlexibleBox::computeMainAxisExtentForChild(RenderBox& child, Si
zeType sizeType, const Length& size) | 410 LayoutUnit RenderFlexibleBox::computeMainAxisExtentForChild(LayoutBox& child, Si
zeType sizeType, const Length& size) |
411 { | 411 { |
412 // FIXME: This is wrong for orthogonal flows. It should use the flexbox's wr
iting-mode, not the child's in order | 412 // FIXME: This is wrong for orthogonal flows. It should use the flexbox's wr
iting-mode, not the child's in order |
413 // to figure out the logical height/width. | 413 // to figure out the logical height/width. |
414 if (isColumnFlow()) { | 414 if (isColumnFlow()) { |
415 // We don't have to check for "auto" here - computeContentLogicalHeight
will just return -1 for that case anyway. | 415 // We don't have to check for "auto" here - computeContentLogicalHeight
will just return -1 for that case anyway. |
416 if (size.isIntrinsic()) | 416 if (size.isIntrinsic()) |
417 child.layoutIfNeeded(); | 417 child.layoutIfNeeded(); |
418 return child.computeContentLogicalHeight(size, child.logicalHeight() - c
hild.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight(); | 418 return child.computeContentLogicalHeight(size, child.logicalHeight() - c
hild.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight(); |
419 } | 419 } |
420 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(),
this) - child.borderAndPaddingLogicalWidth(); | 420 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(),
this) - child.borderAndPaddingLogicalWidth(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 return paddingTop(); | 523 return paddingTop(); |
524 case LeftToRightWritingMode: | 524 case LeftToRightWritingMode: |
525 return paddingRight(); | 525 return paddingRight(); |
526 case RightToLeftWritingMode: | 526 case RightToLeftWritingMode: |
527 return paddingLeft(); | 527 return paddingLeft(); |
528 } | 528 } |
529 ASSERT_NOT_REACHED(); | 529 ASSERT_NOT_REACHED(); |
530 return paddingTop(); | 530 return paddingTop(); |
531 } | 531 } |
532 | 532 |
533 LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(RenderBox& child) con
st | 533 LayoutUnit RenderFlexibleBox::flowAwareMarginStartForChild(LayoutBox& child) con
st |
534 { | 534 { |
535 if (isHorizontalFlow()) | 535 if (isHorizontalFlow()) |
536 return isLeftToRightFlow() ? child.marginLeft() : child.marginRight(); | 536 return isLeftToRightFlow() ? child.marginLeft() : child.marginRight(); |
537 return isLeftToRightFlow() ? child.marginTop() : child.marginBottom(); | 537 return isLeftToRightFlow() ? child.marginTop() : child.marginBottom(); |
538 } | 538 } |
539 | 539 |
540 LayoutUnit RenderFlexibleBox::flowAwareMarginEndForChild(RenderBox& child) const | 540 LayoutUnit RenderFlexibleBox::flowAwareMarginEndForChild(LayoutBox& child) const |
541 { | 541 { |
542 if (isHorizontalFlow()) | 542 if (isHorizontalFlow()) |
543 return isLeftToRightFlow() ? child.marginRight() : child.marginLeft(); | 543 return isLeftToRightFlow() ? child.marginRight() : child.marginLeft(); |
544 return isLeftToRightFlow() ? child.marginBottom() : child.marginTop(); | 544 return isLeftToRightFlow() ? child.marginBottom() : child.marginTop(); |
545 } | 545 } |
546 | 546 |
547 LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(RenderBox& child) co
nst | 547 LayoutUnit RenderFlexibleBox::flowAwareMarginBeforeForChild(LayoutBox& child) co
nst |
548 { | 548 { |
549 switch (transformedWritingMode()) { | 549 switch (transformedWritingMode()) { |
550 case TopToBottomWritingMode: | 550 case TopToBottomWritingMode: |
551 return child.marginTop(); | 551 return child.marginTop(); |
552 case BottomToTopWritingMode: | 552 case BottomToTopWritingMode: |
553 return child.marginBottom(); | 553 return child.marginBottom(); |
554 case LeftToRightWritingMode: | 554 case LeftToRightWritingMode: |
555 return child.marginLeft(); | 555 return child.marginLeft(); |
556 case RightToLeftWritingMode: | 556 case RightToLeftWritingMode: |
557 return child.marginRight(); | 557 return child.marginRight(); |
558 } | 558 } |
559 ASSERT_NOT_REACHED(); | 559 ASSERT_NOT_REACHED(); |
560 return marginTop(); | 560 return marginTop(); |
561 } | 561 } |
562 | 562 |
563 LayoutUnit RenderFlexibleBox::crossAxisMarginExtentForChild(RenderBox& child) co
nst | 563 LayoutUnit RenderFlexibleBox::crossAxisMarginExtentForChild(LayoutBox& child) co
nst |
564 { | 564 { |
565 return isHorizontalFlow() ? child.marginHeight() : child.marginWidth(); | 565 return isHorizontalFlow() ? child.marginHeight() : child.marginWidth(); |
566 } | 566 } |
567 | 567 |
568 LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const | 568 LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtent() const |
569 { | 569 { |
570 return isHorizontalFlow() ? horizontalScrollbarHeight() : verticalScrollbarW
idth(); | 570 return isHorizontalFlow() ? horizontalScrollbarHeight() : verticalScrollbarW
idth(); |
571 } | 571 } |
572 | 572 |
573 LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtentForChild(RenderBox& child)
const | 573 LayoutUnit RenderFlexibleBox::crossAxisScrollbarExtentForChild(LayoutBox& child)
const |
574 { | 574 { |
575 return isHorizontalFlow() ? child.horizontalScrollbarHeight() : child.vertic
alScrollbarWidth(); | 575 return isHorizontalFlow() ? child.horizontalScrollbarHeight() : child.vertic
alScrollbarWidth(); |
576 } | 576 } |
577 | 577 |
578 LayoutPoint RenderFlexibleBox::flowAwareLocationForChild(RenderBox& child) const | 578 LayoutPoint RenderFlexibleBox::flowAwareLocationForChild(LayoutBox& child) const |
579 { | 579 { |
580 return isHorizontalFlow() ? child.location() : child.location().transposedPo
int(); | 580 return isHorizontalFlow() ? child.location() : child.location().transposedPo
int(); |
581 } | 581 } |
582 | 582 |
583 void RenderFlexibleBox::setFlowAwareLocationForChild(RenderBox& child, const Lay
outPoint& location) | 583 void RenderFlexibleBox::setFlowAwareLocationForChild(LayoutBox& child, const Lay
outPoint& location) |
584 { | 584 { |
585 if (isHorizontalFlow()) | 585 if (isHorizontalFlow()) |
586 child.setLocation(location); | 586 child.setLocation(location); |
587 else | 587 else |
588 child.setLocation(location.transposedPoint()); | 588 child.setLocation(location.transposedPoint()); |
589 } | 589 } |
590 | 590 |
591 LayoutUnit RenderFlexibleBox::mainAxisBorderAndPaddingExtentForChild(RenderBox&
child) const | 591 LayoutUnit RenderFlexibleBox::mainAxisBorderAndPaddingExtentForChild(LayoutBox&
child) const |
592 { | 592 { |
593 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP
addingHeight(); | 593 return isHorizontalFlow() ? child.borderAndPaddingWidth() : child.borderAndP
addingHeight(); |
594 } | 594 } |
595 | 595 |
596 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi
s, bool hasInfiniteLineLength) | 596 static inline bool preferredMainAxisExtentDependsOnLayout(const Length& flexBasi
s, bool hasInfiniteLineLength) |
597 { | 597 { |
598 return flexBasis.isAuto() || (flexBasis.isPercent() && hasInfiniteLineLength
); | 598 return flexBasis.isAuto() || (flexBasis.isPercent() && hasInfiniteLineLength
); |
599 } | 599 } |
600 | 600 |
601 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Render
Box& child, bool hasInfiniteLineLength) const | 601 bool RenderFlexibleBox::childPreferredMainAxisContentExtentRequiresLayout(Layout
Box& child, bool hasInfiniteLineLength) const |
602 { | 602 { |
603 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI
nfiniteLineLength) && hasOrthogonalFlow(child); | 603 return preferredMainAxisExtentDependsOnLayout(flexBasisForChild(child), hasI
nfiniteLineLength) && hasOrthogonalFlow(child); |
604 } | 604 } |
605 | 605 |
606 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(RenderBox&
child, bool hasInfiniteLineLength, bool relayoutChildren) | 606 LayoutUnit RenderFlexibleBox::preferredMainAxisContentExtentForChild(LayoutBox&
child, bool hasInfiniteLineLength, bool relayoutChildren) |
607 { | 607 { |
608 child.clearOverrideSize(); | 608 child.clearOverrideSize(); |
609 | 609 |
610 if (child.isImage() || child.isVideo() || child.isCanvas()) | 610 if (child.isImage() || child.isVideo() || child.isCanvas()) |
611 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); | 611 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); |
612 | 612 |
613 Length flexBasis = flexBasisForChild(child); | 613 Length flexBasis = flexBasisForChild(child); |
614 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)
) { | 614 if (preferredMainAxisExtentDependsOnLayout(flexBasis, hasInfiniteLineLength)
) { |
615 LayoutUnit mainAxisExtent; | 615 LayoutUnit mainAxisExtent; |
616 if (hasOrthogonalFlow(child)) { | 616 if (hasOrthogonalFlow(child)) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 } | 673 } |
674 | 674 |
675 LayoutUnit RenderFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi
st& children, LayoutUnit& availableFreeSpace) | 675 LayoutUnit RenderFlexibleBox::autoMarginOffsetInMainAxis(const OrderedFlexItemLi
st& children, LayoutUnit& availableFreeSpace) |
676 { | 676 { |
677 if (availableFreeSpace <= 0) | 677 if (availableFreeSpace <= 0) |
678 return 0; | 678 return 0; |
679 | 679 |
680 int numberOfAutoMargins = 0; | 680 int numberOfAutoMargins = 0; |
681 bool isHorizontal = isHorizontalFlow(); | 681 bool isHorizontal = isHorizontalFlow(); |
682 for (size_t i = 0; i < children.size(); ++i) { | 682 for (size_t i = 0; i < children.size(); ++i) { |
683 RenderBox* child = children[i]; | 683 LayoutBox* child = children[i]; |
684 if (child->isOutOfFlowPositioned()) | 684 if (child->isOutOfFlowPositioned()) |
685 continue; | 685 continue; |
686 if (isHorizontal) { | 686 if (isHorizontal) { |
687 if (child->style()->marginLeft().isAuto()) | 687 if (child->style()->marginLeft().isAuto()) |
688 ++numberOfAutoMargins; | 688 ++numberOfAutoMargins; |
689 if (child->style()->marginRight().isAuto()) | 689 if (child->style()->marginRight().isAuto()) |
690 ++numberOfAutoMargins; | 690 ++numberOfAutoMargins; |
691 } else { | 691 } else { |
692 if (child->style()->marginTop().isAuto()) | 692 if (child->style()->marginTop().isAuto()) |
693 ++numberOfAutoMargins; | 693 ++numberOfAutoMargins; |
694 if (child->style()->marginBottom().isAuto()) | 694 if (child->style()->marginBottom().isAuto()) |
695 ++numberOfAutoMargins; | 695 ++numberOfAutoMargins; |
696 } | 696 } |
697 } | 697 } |
698 if (!numberOfAutoMargins) | 698 if (!numberOfAutoMargins) |
699 return 0; | 699 return 0; |
700 | 700 |
701 LayoutUnit sizeOfAutoMargin = availableFreeSpace / numberOfAutoMargins; | 701 LayoutUnit sizeOfAutoMargin = availableFreeSpace / numberOfAutoMargins; |
702 availableFreeSpace = 0; | 702 availableFreeSpace = 0; |
703 return sizeOfAutoMargin; | 703 return sizeOfAutoMargin; |
704 } | 704 } |
705 | 705 |
706 void RenderFlexibleBox::updateAutoMarginsInMainAxis(RenderBox& child, LayoutUnit
autoMarginOffset) | 706 void RenderFlexibleBox::updateAutoMarginsInMainAxis(LayoutBox& child, LayoutUnit
autoMarginOffset) |
707 { | 707 { |
708 ASSERT(autoMarginOffset >= 0); | 708 ASSERT(autoMarginOffset >= 0); |
709 | 709 |
710 if (isHorizontalFlow()) { | 710 if (isHorizontalFlow()) { |
711 if (child.style()->marginLeft().isAuto()) | 711 if (child.style()->marginLeft().isAuto()) |
712 child.setMarginLeft(autoMarginOffset); | 712 child.setMarginLeft(autoMarginOffset); |
713 if (child.style()->marginRight().isAuto()) | 713 if (child.style()->marginRight().isAuto()) |
714 child.setMarginRight(autoMarginOffset); | 714 child.setMarginRight(autoMarginOffset); |
715 } else { | 715 } else { |
716 if (child.style()->marginTop().isAuto()) | 716 if (child.style()->marginTop().isAuto()) |
717 child.setMarginTop(autoMarginOffset); | 717 child.setMarginTop(autoMarginOffset); |
718 if (child.style()->marginBottom().isAuto()) | 718 if (child.style()->marginBottom().isAuto()) |
719 child.setMarginBottom(autoMarginOffset); | 719 child.setMarginBottom(autoMarginOffset); |
720 } | 720 } |
721 } | 721 } |
722 | 722 |
723 bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(RenderBox& child) const | 723 bool RenderFlexibleBox::hasAutoMarginsInCrossAxis(LayoutBox& child) const |
724 { | 724 { |
725 if (isHorizontalFlow()) | 725 if (isHorizontalFlow()) |
726 return child.style()->marginTop().isAuto() || child.style()->marginBotto
m().isAuto(); | 726 return child.style()->marginTop().isAuto() || child.style()->marginBotto
m().isAuto(); |
727 return child.style()->marginLeft().isAuto() || child.style()->marginRight().
isAuto(); | 727 return child.style()->marginLeft().isAuto() || child.style()->marginRight().
isAuto(); |
728 } | 728 } |
729 | 729 |
730 LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChild(LayoutUnit lineCro
ssAxisExtent, RenderBox& child) | 730 LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChild(LayoutUnit lineCro
ssAxisExtent, LayoutBox& child) |
731 { | 731 { |
732 ASSERT(!child.isOutOfFlowPositioned()); | 732 ASSERT(!child.isOutOfFlowPositioned()); |
733 LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAx
isExtentForChild(child); | 733 LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAx
isExtentForChild(child); |
734 return lineCrossAxisExtent - childCrossExtent; | 734 return lineCrossAxisExtent - childCrossExtent; |
735 } | 735 } |
736 | 736 |
737 LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChildBeforeStretching(La
youtUnit lineCrossAxisExtent, RenderBox& child) | 737 LayoutUnit RenderFlexibleBox::availableAlignmentSpaceForChildBeforeStretching(La
youtUnit lineCrossAxisExtent, LayoutBox& child) |
738 { | 738 { |
739 ASSERT(!child.isOutOfFlowPositioned()); | 739 ASSERT(!child.isOutOfFlowPositioned()); |
740 LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAx
isIntrinsicExtentForChild(child); | 740 LayoutUnit childCrossExtent = crossAxisMarginExtentForChild(child) + crossAx
isIntrinsicExtentForChild(child); |
741 return lineCrossAxisExtent - childCrossExtent; | 741 return lineCrossAxisExtent - childCrossExtent; |
742 } | 742 } |
743 | 743 |
744 bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(RenderBox& child, LayoutUni
t availableAlignmentSpace) | 744 bool RenderFlexibleBox::updateAutoMarginsInCrossAxis(LayoutBox& child, LayoutUni
t availableAlignmentSpace) |
745 { | 745 { |
746 ASSERT(!child.isOutOfFlowPositioned()); | 746 ASSERT(!child.isOutOfFlowPositioned()); |
747 ASSERT(availableAlignmentSpace >= 0); | 747 ASSERT(availableAlignmentSpace >= 0); |
748 | 748 |
749 bool isHorizontal = isHorizontalFlow(); | 749 bool isHorizontal = isHorizontalFlow(); |
750 Length topOrLeft = isHorizontal ? child.style()->marginTop() : child.style()
->marginLeft(); | 750 Length topOrLeft = isHorizontal ? child.style()->marginTop() : child.style()
->marginLeft(); |
751 Length bottomOrRight = isHorizontal ? child.style()->marginBottom() : child.
style()->marginRight(); | 751 Length bottomOrRight = isHorizontal ? child.style()->marginBottom() : child.
style()->marginRight(); |
752 if (topOrLeft.isAuto() && bottomOrRight.isAuto()) { | 752 if (topOrLeft.isAuto() && bottomOrRight.isAuto()) { |
753 adjustAlignmentForChild(child, availableAlignmentSpace / 2); | 753 adjustAlignmentForChild(child, availableAlignmentSpace / 2); |
754 if (isHorizontal) { | 754 if (isHorizontal) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 | 788 |
789 if (isHorizontal) | 789 if (isHorizontal) |
790 child.setMarginBottom(availableAlignmentSpace); | 790 child.setMarginBottom(availableAlignmentSpace); |
791 else | 791 else |
792 child.setMarginRight(availableAlignmentSpace); | 792 child.setMarginRight(availableAlignmentSpace); |
793 return true; | 793 return true; |
794 } | 794 } |
795 return false; | 795 return false; |
796 } | 796 } |
797 | 797 |
798 LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(RenderBox& child) | 798 LayoutUnit RenderFlexibleBox::marginBoxAscentForChild(LayoutBox& child) |
799 { | 799 { |
800 LayoutUnit ascent = child.firstLineBoxBaseline(); | 800 LayoutUnit ascent = child.firstLineBoxBaseline(); |
801 if (ascent == -1) | 801 if (ascent == -1) |
802 ascent = crossAxisExtentForChild(child); | 802 ascent = crossAxisExtentForChild(child); |
803 return ascent + flowAwareMarginBeforeForChild(child); | 803 return ascent + flowAwareMarginBeforeForChild(child); |
804 } | 804 } |
805 | 805 |
806 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin) | 806 LayoutUnit RenderFlexibleBox::computeChildMarginValue(Length margin) |
807 { | 807 { |
808 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. | 808 // When resolving the margins, we use the content size for resolving percent
and calc (for percents in calc expressions) margins. |
809 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. | 809 // Fortunately, percent margins are always computed with respect to the bloc
k's width, even for margin-top and margin-bottom. |
810 LayoutUnit availableSize = contentLogicalWidth(); | 810 LayoutUnit availableSize = contentLogicalWidth(); |
811 return minimumValueForLength(margin, availableSize); | 811 return minimumValueForLength(margin, availableSize); |
812 } | 812 } |
813 | 813 |
814 void RenderFlexibleBox::prepareOrderIteratorAndMargins() | 814 void RenderFlexibleBox::prepareOrderIteratorAndMargins() |
815 { | 815 { |
816 OrderIteratorPopulator populator(m_orderIterator); | 816 OrderIteratorPopulator populator(m_orderIterator); |
817 | 817 |
818 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 818 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
819 populator.collectChild(child); | 819 populator.collectChild(child); |
820 | 820 |
821 if (child->isOutOfFlowPositioned()) | 821 if (child->isOutOfFlowPositioned()) |
822 continue; | 822 continue; |
823 | 823 |
824 // Before running the flex algorithm, 'auto' has a margin of 0. | 824 // Before running the flex algorithm, 'auto' has a margin of 0. |
825 // Also, if we're not auto sizing, we don't do a layout that computes th
e start/end margins. | 825 // Also, if we're not auto sizing, we don't do a layout that computes th
e start/end margins. |
826 if (isHorizontalFlow()) { | 826 if (isHorizontalFlow()) { |
827 child->setMarginLeft(computeChildMarginValue(child->style()->marginL
eft())); | 827 child->setMarginLeft(computeChildMarginValue(child->style()->marginL
eft())); |
828 child->setMarginRight(computeChildMarginValue(child->style()->margin
Right())); | 828 child->setMarginRight(computeChildMarginValue(child->style()->margin
Right())); |
829 } else { | 829 } else { |
830 child->setMarginTop(computeChildMarginValue(child->style()->marginTo
p())); | 830 child->setMarginTop(computeChildMarginValue(child->style()->marginTo
p())); |
831 child->setMarginBottom(computeChildMarginValue(child->style()->margi
nBottom())); | 831 child->setMarginBottom(computeChildMarginValue(child->style()->margi
nBottom())); |
832 } | 832 } |
833 } | 833 } |
834 } | 834 } |
835 | 835 |
836 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(RenderBox& child, Layo
utUnit childSize) | 836 LayoutUnit RenderFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, Layo
utUnit childSize) |
837 { | 837 { |
838 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()-
>maxHeight(); | 838 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()-
>maxHeight(); |
839 if (max.isSpecifiedOrIntrinsic()) { | 839 if (max.isSpecifiedOrIntrinsic()) { |
840 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max
); | 840 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max
); |
841 if (maxExtent != -1 && childSize > maxExtent) | 841 if (maxExtent != -1 && childSize > maxExtent) |
842 childSize = maxExtent; | 842 childSize = maxExtent; |
843 } | 843 } |
844 | 844 |
845 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()-
>minHeight(); | 845 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()-
>minHeight(); |
846 LayoutUnit minExtent = 0; | 846 LayoutUnit minExtent = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
857 sumHypotheticalMainSize = 0; | 857 sumHypotheticalMainSize = 0; |
858 | 858 |
859 if (!m_orderIterator.currentChild()) | 859 if (!m_orderIterator.currentChild()) |
860 return false; | 860 return false; |
861 | 861 |
862 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); | 862 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); |
863 hasInfiniteLineLength = lineBreakLength == LayoutUnit::max(); | 863 hasInfiniteLineLength = lineBreakLength == LayoutUnit::max(); |
864 | 864 |
865 bool lineHasInFlowItem = false; | 865 bool lineHasInFlowItem = false; |
866 | 866 |
867 for (RenderBox* child = m_orderIterator.currentChild(); child; child = m_ord
erIterator.next()) { | 867 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord
erIterator.next()) { |
868 if (child->isOutOfFlowPositioned()) { | 868 if (child->isOutOfFlowPositioned()) { |
869 orderedChildren.append(child); | 869 orderedChildren.append(child); |
870 continue; | 870 continue; |
871 } | 871 } |
872 | 872 |
873 LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild(
*child, hasInfiniteLineLength, relayoutChildren); | 873 LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild(
*child, hasInfiniteLineLength, relayoutChildren); |
874 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx
tentForChild(*child) | 874 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx
tentForChild(*child) |
875 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight()
); | 875 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight()
); |
876 LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMargin
BorderPadding; | 876 LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMargin
BorderPadding; |
877 | 877 |
878 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa
x(*child, childMainAxisExtent); | 878 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa
x(*child, childMainAxisExtent); |
879 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent
+ childMainAxisMarginBorderPadding; | 879 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent
+ childMainAxisMarginBorderPadding; |
880 | 880 |
881 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize
> lineBreakLength && lineHasInFlowItem) | 881 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize
> lineBreakLength && lineHasInFlowItem) |
882 break; | 882 break; |
883 orderedChildren.append(child); | 883 orderedChildren.append(child); |
884 lineHasInFlowItem = true; | 884 lineHasInFlowItem = true; |
885 sumFlexBaseSize += childFlexBaseSize; | 885 sumFlexBaseSize += childFlexBaseSize; |
886 totalFlexGrow += child->style()->flexGrow(); | 886 totalFlexGrow += child->style()->flexGrow(); |
887 totalWeightedFlexShrink += child->style()->flexShrink() * childMainAxisE
xtent; | 887 totalWeightedFlexShrink += child->style()->flexShrink() * childMainAxisE
xtent; |
888 sumHypotheticalMainSize += childHypotheticalMainSize; | 888 sumHypotheticalMainSize += childHypotheticalMainSize; |
889 } | 889 } |
890 return true; | 890 return true; |
891 } | 891 } |
892 | 892 |
893 void RenderFlexibleBox::freezeViolations(const Vector<Violation>& violations, La
youtUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexSh
rink, InflexibleFlexItemSize& inflexibleItems, bool hasInfiniteLineLength) | 893 void RenderFlexibleBox::freezeViolations(const Vector<Violation>& violations, La
youtUnit& availableFreeSpace, double& totalFlexGrow, double& totalWeightedFlexSh
rink, InflexibleFlexItemSize& inflexibleItems, bool hasInfiniteLineLength) |
894 { | 894 { |
895 for (size_t i = 0; i < violations.size(); ++i) { | 895 for (size_t i = 0; i < violations.size(); ++i) { |
896 RenderBox* child = violations[i].child; | 896 LayoutBox* child = violations[i].child; |
897 LayoutUnit childSize = violations[i].childSize; | 897 LayoutUnit childSize = violations[i].childSize; |
898 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(*
child, hasInfiniteLineLength); | 898 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChild(*
child, hasInfiniteLineLength); |
899 availableFreeSpace -= childSize - preferredChildSize; | 899 availableFreeSpace -= childSize - preferredChildSize; |
900 totalFlexGrow -= child->style()->flexGrow(); | 900 totalFlexGrow -= child->style()->flexGrow(); |
901 totalWeightedFlexShrink -= child->style()->flexShrink() * preferredChild
Size; | 901 totalWeightedFlexShrink -= child->style()->flexShrink() * preferredChild
Size; |
902 inflexibleItems.set(child, childSize); | 902 inflexibleItems.set(child, childSize); |
903 } | 903 } |
904 } | 904 } |
905 | 905 |
906 // Returns true if we successfully ran the algorithm and sized the flex items. | 906 // Returns true if we successfully ran the algorithm and sized the flex items. |
907 bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF
lexItemList& children, LayoutUnit& availableFreeSpace, double& totalFlexGrow, do
uble& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems, Vector<L
ayoutUnit, 16>& childSizes, bool hasInfiniteLineLength) | 907 bool RenderFlexibleBox::resolveFlexibleLengths(FlexSign flexSign, const OrderedF
lexItemList& children, LayoutUnit& availableFreeSpace, double& totalFlexGrow, do
uble& totalWeightedFlexShrink, InflexibleFlexItemSize& inflexibleItems, Vector<L
ayoutUnit, 16>& childSizes, bool hasInfiniteLineLength) |
908 { | 908 { |
909 childSizes.resize(0); | 909 childSizes.resize(0); |
910 LayoutUnit totalViolation = 0; | 910 LayoutUnit totalViolation = 0; |
911 LayoutUnit usedFreeSpace = 0; | 911 LayoutUnit usedFreeSpace = 0; |
912 Vector<Violation> minViolations; | 912 Vector<Violation> minViolations; |
913 Vector<Violation> maxViolations; | 913 Vector<Violation> maxViolations; |
914 for (size_t i = 0; i < children.size(); ++i) { | 914 for (size_t i = 0; i < children.size(); ++i) { |
915 RenderBox* child = children[i]; | 915 LayoutBox* child = children[i]; |
916 if (child->isOutOfFlowPositioned()) { | 916 if (child->isOutOfFlowPositioned()) { |
917 childSizes.append(0); | 917 childSizes.append(0); |
918 continue; | 918 continue; |
919 } | 919 } |
920 | 920 |
921 if (inflexibleItems.contains(child)) | 921 if (inflexibleItems.contains(child)) |
922 childSizes.append(inflexibleItems.get(child)); | 922 childSizes.append(inflexibleItems.get(child)); |
923 else { | 923 else { |
924 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi
ld(*child, hasInfiniteLineLength); | 924 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi
ld(*child, hasInfiniteLineLength); |
925 LayoutUnit childSize = preferredChildSize; | 925 LayoutUnit childSize = preferredChildSize; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 { | 971 { |
972 if (availableFreeSpace > 0 && numberOfChildren > 1) { | 972 if (availableFreeSpace > 0 && numberOfChildren > 1) { |
973 if (justifyContentDistribution == ContentDistributionSpaceBetween) | 973 if (justifyContentDistribution == ContentDistributionSpaceBetween) |
974 return availableFreeSpace / (numberOfChildren - 1); | 974 return availableFreeSpace / (numberOfChildren - 1); |
975 if (justifyContentDistribution == ContentDistributionSpaceAround) | 975 if (justifyContentDistribution == ContentDistributionSpaceAround) |
976 return availableFreeSpace / numberOfChildren; | 976 return availableFreeSpace / numberOfChildren; |
977 } | 977 } |
978 return 0; | 978 return 0; |
979 } | 979 } |
980 | 980 |
981 void RenderFlexibleBox::setOverrideMainAxisSizeForChild(RenderBox& child, Layout
Unit childPreferredSize) | 981 void RenderFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout
Unit childPreferredSize) |
982 { | 982 { |
983 if (hasOrthogonalFlow(child)) | 983 if (hasOrthogonalFlow(child)) |
984 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); | 984 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); |
985 else | 985 else |
986 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn
dPaddingLogicalWidth()); | 986 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn
dPaddingLogicalWidth()); |
987 } | 987 } |
988 | 988 |
989 void RenderFlexibleBox::prepareChildForPositionedLayout(RenderBox& child, Layout
Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode
) | 989 void RenderFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child, Layout
Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode
) |
990 { | 990 { |
991 ASSERT(child.isOutOfFlowPositioned()); | 991 ASSERT(child.isOutOfFlowPositioned()); |
992 child.containingBlock()->insertPositionedObject(&child); | 992 child.containingBlock()->insertPositionedObject(&child); |
993 Layer* childLayer = child.layer(); | 993 Layer* childLayer = child.layer(); |
994 LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffse
t; | 994 LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffse
t; |
995 if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowRe
verse) | 995 if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowRe
verse) |
996 inlinePosition = mainAxisExtent() - mainAxisOffset; | 996 inlinePosition = mainAxisExtent() - mainAxisOffset; |
997 childLayer->setStaticInlinePosition(inlinePosition); | 997 childLayer->setStaticInlinePosition(inlinePosition); |
998 | 998 |
999 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis
Offset; | 999 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis
Offset; |
1000 if (childLayer->staticBlockPosition() != staticBlockPosition) { | 1000 if (childLayer->staticBlockPosition() != staticBlockPosition) { |
1001 childLayer->setStaticBlockPosition(staticBlockPosition); | 1001 childLayer->setStaticBlockPosition(staticBlockPosition); |
1002 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo
de())) | 1002 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo
de())) |
1003 child.setChildNeedsLayout(MarkOnlyThis); | 1003 child.setChildNeedsLayout(MarkOnlyThis); |
1004 } | 1004 } |
1005 } | 1005 } |
1006 | 1006 |
1007 ItemPosition RenderFlexibleBox::alignmentForChild(RenderBox& child) const | 1007 ItemPosition RenderFlexibleBox::alignmentForChild(LayoutBox& child) const |
1008 { | 1008 { |
1009 ItemPosition align = LayoutStyle::resolveAlignment(styleRef(), child.styleRe
f(), ItemPositionStretch); | 1009 ItemPosition align = LayoutStyle::resolveAlignment(styleRef(), child.styleRe
f(), ItemPositionStretch); |
1010 | 1010 |
1011 if (align == ItemPositionBaseline && hasOrthogonalFlow(child)) | 1011 if (align == ItemPositionBaseline && hasOrthogonalFlow(child)) |
1012 align = ItemPositionFlexStart; | 1012 align = ItemPositionFlexStart; |
1013 | 1013 |
1014 if (style()->flexWrap() == FlexWrapReverse) { | 1014 if (style()->flexWrap() == FlexWrapReverse) { |
1015 if (align == ItemPositionFlexStart) | 1015 if (align == ItemPositionFlexStart) |
1016 align = ItemPositionFlexEnd; | 1016 align = ItemPositionFlexEnd; |
1017 else if (align == ItemPositionFlexEnd) | 1017 else if (align == ItemPositionFlexEnd) |
1018 align = ItemPositionFlexStart; | 1018 align = ItemPositionFlexStart; |
1019 } | 1019 } |
1020 | 1020 |
1021 return align; | 1021 return align; |
1022 } | 1022 } |
1023 | 1023 |
1024 size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem
List& children) const | 1024 size_t RenderFlexibleBox::numberOfInFlowPositionedChildren(const OrderedFlexItem
List& children) const |
1025 { | 1025 { |
1026 size_t count = 0; | 1026 size_t count = 0; |
1027 for (size_t i = 0; i < children.size(); ++i) { | 1027 for (size_t i = 0; i < children.size(); ++i) { |
1028 RenderBox* child = children[i]; | 1028 LayoutBox* child = children[i]; |
1029 if (!child->isOutOfFlowPositioned()) | 1029 if (!child->isOutOfFlowPositioned()) |
1030 ++count; | 1030 ++count; |
1031 } | 1031 } |
1032 return count; | 1032 return count; |
1033 } | 1033 } |
1034 | 1034 |
1035 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(RenderBox& chil
d) | 1035 void RenderFlexibleBox::resetAutoMarginsAndLogicalTopInCrossAxis(LayoutBox& chil
d) |
1036 { | 1036 { |
1037 if (hasAutoMarginsInCrossAxis(child)) { | 1037 if (hasAutoMarginsInCrossAxis(child)) { |
1038 child.updateLogicalHeight(); | 1038 child.updateLogicalHeight(); |
1039 if (isHorizontalFlow()) { | 1039 if (isHorizontalFlow()) { |
1040 if (child.style()->marginTop().isAuto()) | 1040 if (child.style()->marginTop().isAuto()) |
1041 child.setMarginTop(0); | 1041 child.setMarginTop(0); |
1042 if (child.style()->marginBottom().isAuto()) | 1042 if (child.style()->marginBottom().isAuto()) |
1043 child.setMarginBottom(0); | 1043 child.setMarginBottom(0); |
1044 } else { | 1044 } else { |
1045 if (child.style()->marginLeft().isAuto()) | 1045 if (child.style()->marginLeft().isAuto()) |
1046 child.setMarginLeft(0); | 1046 child.setMarginLeft(0); |
1047 if (child.style()->marginRight().isAuto()) | 1047 if (child.style()->marginRight().isAuto()) |
1048 child.setMarginRight(0); | 1048 child.setMarginRight(0); |
1049 } | 1049 } |
1050 } | 1050 } |
1051 } | 1051 } |
1052 | 1052 |
1053 bool RenderFlexibleBox::needToStretchChildLogicalHeight(RenderBox& child) const | 1053 bool RenderFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const |
1054 { | 1054 { |
1055 if (alignmentForChild(child) != ItemPositionStretch) | 1055 if (alignmentForChild(child) != ItemPositionStretch) |
1056 return false; | 1056 return false; |
1057 | 1057 |
1058 return isHorizontalFlow() && child.style()->height().isAuto(); | 1058 return isHorizontalFlow() && child.style()->height().isAuto(); |
1059 } | 1059 } |
1060 | 1060 |
1061 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) | 1061 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) |
1062 { | 1062 { |
1063 ASSERT(childSizes.size() == children.size()); | 1063 ASSERT(childSizes.size() == children.size()); |
1064 | 1064 |
1065 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1065 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
1066 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); | 1066 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available
FreeSpace); |
1067 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; | 1067 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart()
; |
1068 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); | 1068 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
1069 if (style()->flexDirection() == FlowRowReverse) | 1069 if (style()->flexDirection() == FlowRowReverse) |
1070 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); | 1070 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo
ntalScrollbarHeight(); |
1071 | 1071 |
1072 LayoutUnit totalMainExtent = mainAxisExtent(); | 1072 LayoutUnit totalMainExtent = mainAxisExtent(); |
1073 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. | 1073 LayoutUnit maxAscent = 0, maxDescent = 0; // Used when align-items: baseline
. |
1074 LayoutUnit maxChildCrossAxisExtent = 0; | 1074 LayoutUnit maxChildCrossAxisExtent = 0; |
1075 size_t seenInFlowPositionedChildren = 0; | 1075 size_t seenInFlowPositionedChildren = 0; |
1076 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); | 1076 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); |
1077 for (size_t i = 0; i < children.size(); ++i) { | 1077 for (size_t i = 0; i < children.size(); ++i) { |
1078 RenderBox* child = children[i]; | 1078 LayoutBox* child = children[i]; |
1079 | 1079 |
1080 if (child->isOutOfFlowPositioned()) { | 1080 if (child->isOutOfFlowPositioned()) { |
1081 prepareChildForPositionedLayout(*child, mainAxisOffset, crossAxisOff
set, FlipForRowReverse); | 1081 prepareChildForPositionedLayout(*child, mainAxisOffset, crossAxisOff
set, FlipForRowReverse); |
1082 continue; | 1082 continue; |
1083 } | 1083 } |
1084 | 1084 |
1085 // FIXME Investigate if this can be removed based on other flags. crbug.
com/370010 | 1085 // FIXME Investigate if this can be removed based on other flags. crbug.
com/370010 |
1086 child->setMayNeedPaintInvalidation(); | 1086 child->setMayNeedPaintInvalidation(); |
1087 | 1087 |
1088 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding
ExtentForChild(*child); | 1088 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding
ExtentForChild(*child); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children | 1154 // This is similar to the logic in layoutAndPlaceChildren, except we place t
he children |
1155 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're | 1155 // starting from the end of the flexbox. We also don't need to layout anythi
ng since we're |
1156 // just moving the children to a new position. | 1156 // just moving the children to a new position. |
1157 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); | 1157 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren(
children); |
1158 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); | 1158 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa
rePaddingEnd(); |
1159 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); | 1159 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, style()->j
ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti
fyContent); |
1160 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); | 1160 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal
ScrollbarHeight(); |
1161 | 1161 |
1162 size_t seenInFlowPositionedChildren = 0; | 1162 size_t seenInFlowPositionedChildren = 0; |
1163 for (size_t i = 0; i < children.size(); ++i) { | 1163 for (size_t i = 0; i < children.size(); ++i) { |
1164 RenderBox* child = children[i]; | 1164 LayoutBox* child = children[i]; |
1165 | 1165 |
1166 if (child->isOutOfFlowPositioned()) { | 1166 if (child->isOutOfFlowPositioned()) { |
1167 child->layer()->setStaticBlockPosition(mainAxisOffset); | 1167 child->layer()->setStaticBlockPosition(mainAxisOffset); |
1168 continue; | 1168 continue; |
1169 } | 1169 } |
1170 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); | 1170 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor
Child(*child); |
1171 | 1171 |
1172 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); | 1172 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx
isOffset + flowAwareMarginBeforeForChild(*child))); |
1173 | 1173 |
1174 mainAxisOffset -= flowAwareMarginStartForChild(*child); | 1174 mainAxisOffset -= flowAwareMarginStartForChild(*child); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1217 return; | 1217 return; |
1218 } | 1218 } |
1219 | 1219 |
1220 if (style()->alignContent() == ContentPositionFlexStart) | 1220 if (style()->alignContent() == ContentPositionFlexStart) |
1221 return; | 1221 return; |
1222 | 1222 |
1223 LayoutUnit availableCrossAxisSpace = crossAxisContentExtent(); | 1223 LayoutUnit availableCrossAxisSpace = crossAxisContentExtent(); |
1224 for (size_t i = 0; i < lineContexts.size(); ++i) | 1224 for (size_t i = 0; i < lineContexts.size(); ++i) |
1225 availableCrossAxisSpace -= lineContexts[i].crossAxisExtent; | 1225 availableCrossAxisSpace -= lineContexts[i].crossAxisExtent; |
1226 | 1226 |
1227 RenderBox* child = m_orderIterator.first(); | 1227 LayoutBox* child = m_orderIterator.first(); |
1228 LayoutUnit lineOffset = initialAlignContentOffset(availableCrossAxisSpace, s
tyle()->alignContent(), style()->alignContentDistribution(), lineContexts.size()
); | 1228 LayoutUnit lineOffset = initialAlignContentOffset(availableCrossAxisSpace, s
tyle()->alignContent(), style()->alignContentDistribution(), lineContexts.size()
); |
1229 for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber
) { | 1229 for (unsigned lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber
) { |
1230 lineContexts[lineNumber].crossAxisOffset += lineOffset; | 1230 lineContexts[lineNumber].crossAxisOffset += lineOffset; |
1231 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) | 1231 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) |
1232 adjustAlignmentForChild(*child, lineOffset); | 1232 adjustAlignmentForChild(*child, lineOffset); |
1233 | 1233 |
1234 if (style()->alignContentDistribution() == ContentDistributionStretch &&
availableCrossAxisSpace > 0) | 1234 if (style()->alignContentDistribution() == ContentDistributionStretch &&
availableCrossAxisSpace > 0) |
1235 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace
/ static_cast<unsigned>(lineContexts.size()); | 1235 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace
/ static_cast<unsigned>(lineContexts.size()); |
1236 | 1236 |
1237 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace,
style()->alignContentDistribution(), lineContexts.size()); | 1237 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace,
style()->alignContentDistribution(), lineContexts.size()); |
1238 } | 1238 } |
1239 } | 1239 } |
1240 | 1240 |
1241 void RenderFlexibleBox::adjustAlignmentForChild(RenderBox& child, LayoutUnit del
ta) | 1241 void RenderFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del
ta) |
1242 { | 1242 { |
1243 if (child.isOutOfFlowPositioned()) { | 1243 if (child.isOutOfFlowPositioned()) { |
1244 LayoutUnit staticInlinePosition = child.layer()->staticInlinePosition(); | 1244 LayoutUnit staticInlinePosition = child.layer()->staticInlinePosition(); |
1245 LayoutUnit staticBlockPosition = child.layer()->staticBlockPosition(); | 1245 LayoutUnit staticBlockPosition = child.layer()->staticBlockPosition(); |
1246 LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlin
ePosition; | 1246 LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlin
ePosition; |
1247 LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlo
ckPosition; | 1247 LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlo
ckPosition; |
1248 crossAxis += delta; | 1248 crossAxis += delta; |
1249 prepareChildForPositionedLayout(child, mainAxis, crossAxis, NoFlipForRow
Reverse); | 1249 prepareChildForPositionedLayout(child, mainAxis, crossAxis, NoFlipForRow
Reverse); |
1250 return; | 1250 return; |
1251 } | 1251 } |
1252 | 1252 |
1253 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou
tSize(0, delta)); | 1253 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou
tSize(0, delta)); |
1254 } | 1254 } |
1255 | 1255 |
1256 void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) | 1256 void RenderFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) |
1257 { | 1257 { |
1258 // Keep track of the space between the baseline edge and the after edge of t
he box for each line. | 1258 // Keep track of the space between the baseline edge and the after edge of t
he box for each line. |
1259 Vector<LayoutUnit> minMarginAfterBaselines; | 1259 Vector<LayoutUnit> minMarginAfterBaselines; |
1260 | 1260 |
1261 RenderBox* child = m_orderIterator.first(); | 1261 LayoutBox* child = m_orderIterator.first(); |
1262 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ | 1262 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ |
1263 LayoutUnit minMarginAfterBaseline = LayoutUnit::max(); | 1263 LayoutUnit minMarginAfterBaseline = LayoutUnit::max(); |
1264 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten
t; | 1264 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisExten
t; |
1265 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent; | 1265 LayoutUnit maxAscent = lineContexts[lineNumber].maxAscent; |
1266 | 1266 |
1267 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { | 1267 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { |
1268 ASSERT(child); | 1268 ASSERT(child); |
1269 if (child->isOutOfFlowPositioned()) { | 1269 if (child->isOutOfFlowPositioned()) { |
1270 if (style()->flexWrap() == FlexWrapReverse) | 1270 if (style()->flexWrap() == FlexWrapReverse) |
1271 adjustAlignmentForChild(*child, lineCrossAxisExtent); | 1271 adjustAlignmentForChild(*child, lineCrossAxisExtent); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ | 1330 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ |
1331 LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber]; | 1331 LayoutUnit minMarginAfterBaseline = minMarginAfterBaselines[lineNumber]; |
1332 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { | 1332 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { |
1333 ASSERT(child); | 1333 ASSERT(child); |
1334 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMar
ginsInCrossAxis(*child) && minMarginAfterBaseline) | 1334 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMar
ginsInCrossAxis(*child) && minMarginAfterBaseline) |
1335 adjustAlignmentForChild(*child, minMarginAfterBaseline); | 1335 adjustAlignmentForChild(*child, minMarginAfterBaseline); |
1336 } | 1336 } |
1337 } | 1337 } |
1338 } | 1338 } |
1339 | 1339 |
1340 void RenderFlexibleBox::applyStretchAlignmentToChild(RenderBox& child, LayoutUni
t lineCrossAxisExtent) | 1340 void RenderFlexibleBox::applyStretchAlignmentToChild(LayoutBox& child, LayoutUni
t lineCrossAxisExtent) |
1341 { | 1341 { |
1342 if (!isColumnFlow() && child.style()->logicalHeight().isAuto()) { | 1342 if (!isColumnFlow() && child.style()->logicalHeight().isAuto()) { |
1343 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. | 1343 // FIXME: If the child has orthogonal flow, then it already has an overr
ide height set, so use it. |
1344 if (!hasOrthogonalFlow(child)) { | 1344 if (!hasOrthogonalFlow(child)) { |
1345 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(
child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei
ght(); | 1345 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(
child) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHei
ght(); |
1346 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab
leAlignmentSpaceForChildBeforeStretching(lineCrossAxisExtent, child); | 1346 LayoutUnit stretchedLogicalHeight = heightBeforeStretching + availab
leAlignmentSpaceForChildBeforeStretching(lineCrossAxisExtent, child); |
1347 ASSERT(!child.needsLayout()); | 1347 ASSERT(!child.needsLayout()); |
1348 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica
lHeight()); | 1348 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM
ax(stretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogica
lHeight()); |
1349 | 1349 |
1350 // FIXME: Can avoid laying out here in some cases. See https://webki
t.org/b/87905. | 1350 // FIXME: Can avoid laying out here in some cases. See https://webki
t.org/b/87905. |
1351 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeigh
t(); | 1351 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeigh
t(); |
1352 if (childNeedsRelayout || !child.hasOverrideHeight()) | 1352 if (childNeedsRelayout || !child.hasOverrideHeight()) |
1353 child.setOverrideLogicalContentHeight(desiredLogicalHeight - chi
ld.borderAndPaddingLogicalHeight()); | 1353 child.setOverrideLogicalContentHeight(desiredLogicalHeight - chi
ld.borderAndPaddingLogicalHeight()); |
1354 if (childNeedsRelayout) { | 1354 if (childNeedsRelayout) { |
1355 child.setLogicalHeight(0); | 1355 child.setLogicalHeight(0); |
1356 // We cache the child's intrinsic content logical height to avoi
d it being reset to the stretched height. | 1356 // We cache the child's intrinsic content logical height to avoi
d it being reset to the stretched height. |
1357 // FIXME: This is fragile. RenderBoxes should be smart enough to
determine their intrinsic content logical | 1357 // FIXME: This is fragile. LayoutBoxes should be smart enough to
determine their intrinsic content logical |
1358 // height correctly even when there's an overrideHeight. | 1358 // height correctly even when there's an overrideHeight. |
1359 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicC
ontentLogicalHeight(); | 1359 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicC
ontentLogicalHeight(); |
1360 child.forceChildLayout(); | 1360 child.forceChildLayout(); |
1361 child.setIntrinsicContentLogicalHeight(childIntrinsicContentLogi
calHeight); | 1361 child.setIntrinsicContentLogicalHeight(childIntrinsicContentLogi
calHeight); |
1362 } | 1362 } |
1363 } | 1363 } |
1364 } else if (isColumnFlow() && child.style()->logicalWidth().isAuto()) { | 1364 } else if (isColumnFlow() && child.style()->logicalWidth().isAuto()) { |
1365 // FIXME: If the child doesn't have orthogonal flow, then it already has
an override width set, so use it. | 1365 // FIXME: If the child doesn't have orthogonal flow, then it already has
an override width set, so use it. |
1366 if (hasOrthogonalFlow(child)) { | 1366 if (hasOrthogonalFlow(child)) { |
1367 LayoutUnit childWidth = std::max<LayoutUnit>(0, lineCrossAxisExtent
- crossAxisMarginExtentForChild(child)); | 1367 LayoutUnit childWidth = std::max<LayoutUnit>(0, lineCrossAxisExtent
- crossAxisMarginExtentForChild(child)); |
1368 childWidth = child.constrainLogicalWidthByMinMax(childWidth, childWi
dth, this); | 1368 childWidth = child.constrainLogicalWidthByMinMax(childWidth, childWi
dth, this); |
1369 | 1369 |
1370 if (childWidth != child.logicalWidth()) { | 1370 if (childWidth != child.logicalWidth()) { |
1371 child.setOverrideLogicalContentWidth(childWidth - child.borderAn
dPaddingLogicalWidth()); | 1371 child.setOverrideLogicalContentWidth(childWidth - child.borderAn
dPaddingLogicalWidth()); |
1372 child.forceChildLayout(); | 1372 child.forceChildLayout(); |
1373 } | 1373 } |
1374 } | 1374 } |
1375 } | 1375 } |
1376 } | 1376 } |
1377 | 1377 |
1378 void RenderFlexibleBox::flipForRightToLeftColumn() | 1378 void RenderFlexibleBox::flipForRightToLeftColumn() |
1379 { | 1379 { |
1380 if (style()->isLeftToRightDirection() || !isColumnFlow()) | 1380 if (style()->isLeftToRightDirection() || !isColumnFlow()) |
1381 return; | 1381 return; |
1382 | 1382 |
1383 LayoutUnit crossExtent = crossAxisExtent(); | 1383 LayoutUnit crossExtent = crossAxisExtent(); |
1384 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 1384 for (LayoutBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
1385 if (child->isOutOfFlowPositioned()) | 1385 if (child->isOutOfFlowPositioned()) |
1386 continue; | 1386 continue; |
1387 LayoutPoint location = flowAwareLocationForChild(*child); | 1387 LayoutPoint location = flowAwareLocationForChild(*child); |
1388 // For vertical flows, setFlowAwareLocationForChild will transpose x and
y, | 1388 // For vertical flows, setFlowAwareLocationForChild will transpose x and
y, |
1389 // so using the y axis for a column cross axis extent is correct. | 1389 // so using the y axis for a column cross axis extent is correct. |
1390 location.setY(crossExtent - crossAxisExtentForChild(*child) - location.y
()); | 1390 location.setY(crossExtent - crossAxisExtentForChild(*child) - location.y
()); |
1391 setFlowAwareLocationForChild(*child, location); | 1391 setFlowAwareLocationForChild(*child, location); |
1392 } | 1392 } |
1393 } | 1393 } |
1394 | 1394 |
1395 void RenderFlexibleBox::flipForWrapReverse(const Vector<LineContext>& lineContex
ts, LayoutUnit crossAxisStartEdge) | 1395 void RenderFlexibleBox::flipForWrapReverse(const Vector<LineContext>& lineContex
ts, LayoutUnit crossAxisStartEdge) |
1396 { | 1396 { |
1397 LayoutUnit contentExtent = crossAxisContentExtent(); | 1397 LayoutUnit contentExtent = crossAxisContentExtent(); |
1398 RenderBox* child = m_orderIterator.first(); | 1398 LayoutBox* child = m_orderIterator.first(); |
1399 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ | 1399 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber)
{ |
1400 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { | 1400 for (size_t childNumber = 0; childNumber < lineContexts[lineNumber].numb
erOfChildren; ++childNumber, child = m_orderIterator.next()) { |
1401 ASSERT(child); | 1401 ASSERT(child); |
1402 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1402 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
1403 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1403 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
1404 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1404 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
1405 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1405 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1406 } | 1406 } |
1407 } | 1407 } |
1408 } | 1408 } |
1409 | 1409 |
1410 } | 1410 } |
OLD | NEW |