| 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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 return flexLength; | 471 return flexLength; |
| 472 } | 472 } |
| 473 | 473 |
| 474 LayoutUnit LayoutFlexibleBox::crossAxisExtentForChild(const LayoutBox& child) co
nst | 474 LayoutUnit LayoutFlexibleBox::crossAxisExtentForChild(const LayoutBox& child) co
nst |
| 475 { | 475 { |
| 476 return isHorizontalFlow() ? child.size().height() : child.size().width(); | 476 return isHorizontalFlow() ? child.size().height() : child.size().width(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) | 479 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay
outBox& child) |
| 480 { | 480 { |
| 481 // TODO(cbiesinger): scrollbar height? |
| 481 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); | 482 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica
lHeight(); |
| 482 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); | 483 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig
ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); |
| 483 } | 484 } |
| 484 | 485 |
| 485 LayoutUnit LayoutFlexibleBox::childIntrinsicHeight(const LayoutBox& child) const | 486 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalHeight(const LayoutBox& child
) const |
| 486 { | 487 { |
| 487 if (child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(child
)) | 488 // This should only be called if the logical height is the cross size |
| 489 DCHECK(!hasOrthogonalFlow(child)); |
| 490 if (needToStretchChildLogicalHeight(child)) |
| 488 return constrainedChildIntrinsicContentLogicalHeight(child); | 491 return constrainedChildIntrinsicContentLogicalHeight(child); |
| 489 // If our height is auto, make sure that our returned height is unaffected b
y earlier layouts by | 492 return child.logicalHeight(); |
| 490 // returning the max preferred height (=logical width) | |
| 491 if (!child.isHorizontalWritingMode() && child.styleRef().height().isAuto()) | |
| 492 return child.maxPreferredLogicalWidth(); | |
| 493 return child.size().height(); | |
| 494 } | 493 } |
| 495 | 494 |
| 496 LayoutUnit LayoutFlexibleBox::childIntrinsicWidth(const LayoutBox& child) const | 495 LayoutUnit LayoutFlexibleBox::childIntrinsicLogicalWidth(const LayoutBox& child)
const |
| 497 { | 496 { |
| 498 if (!child.isHorizontalWritingMode() && needToStretchChildLogicalHeight(chil
d)) | 497 // This should only be called if the logical width is the cross size |
| 499 return constrainedChildIntrinsicContentLogicalHeight(child); | 498 DCHECK(hasOrthogonalFlow(child)); |
| 500 if (child.isHorizontalWritingMode() && child.styleRef().width().isAuto()) { | 499 // If our height is auto, make sure that our returned height is unaffected b
y earlier layouts by |
| 501 // This value is already clamped by min/max-width | 500 // returning the max preferred logical width |
| 501 if (!crossAxisLengthIsDefinite(child, child.styleRef().logicalWidth())) |
| 502 return child.maxPreferredLogicalWidth(); | 502 return child.maxPreferredLogicalWidth(); |
| 503 } | 503 |
| 504 return child.size().width(); | 504 return child.logicalWidth(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 LayoutUnit LayoutFlexibleBox::crossAxisIntrinsicExtentForChild(const LayoutBox&
child) const | 507 LayoutUnit LayoutFlexibleBox::crossAxisIntrinsicExtentForChild(const LayoutBox&
child) const |
| 508 { | 508 { |
| 509 return isHorizontalFlow() ? childIntrinsicHeight(child) : childIntrinsicWidt
h(child); | 509 return hasOrthogonalFlow(child) ? childIntrinsicLogicalWidth(child) : childI
ntrinsicLogicalHeight(child); |
| 510 } | 510 } |
| 511 | 511 |
| 512 LayoutUnit LayoutFlexibleBox::mainAxisExtentForChild(const LayoutBox& child) con
st | 512 LayoutUnit LayoutFlexibleBox::mainAxisExtentForChild(const LayoutBox& child) con
st |
| 513 { | 513 { |
| 514 return isHorizontalFlow() ? child.size().width() : child.size().height(); | 514 return isHorizontalFlow() ? child.size().width() : child.size().height(); |
| 515 } | 515 } |
| 516 | 516 |
| 517 LayoutUnit LayoutFlexibleBox::mainAxisContentExtentForChild(const LayoutBox& chi
ld) const | 517 LayoutUnit LayoutFlexibleBox::mainAxisContentExtentForChild(const LayoutBox& chi
ld) const |
| 518 { | 518 { |
| 519 return isHorizontalFlow() ? child.contentWidth() : child.contentHeight(); | 519 return isHorizontalFlow() ? child.contentWidth() : child.contentHeight(); |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 // So the child will automatically stretch if our cross axis is the child's
inline axis. That's the case if: | 1562 // So the child will automatically stretch if our cross axis is the child's
inline axis. That's the case if: |
| 1563 // - We are horizontal and the child is in vertical writing mode | 1563 // - We are horizontal and the child is in vertical writing mode |
| 1564 // - We are vertical and the child is in horizontal writing mode | 1564 // - We are vertical and the child is in horizontal writing mode |
| 1565 // Otherwise, we need to stretch if the cross axis size is auto. | 1565 // Otherwise, we need to stretch if the cross axis size is auto. |
| 1566 if (alignmentForChild(child) != ItemPositionStretch) | 1566 if (alignmentForChild(child) != ItemPositionStretch) |
| 1567 return false; | 1567 return false; |
| 1568 | 1568 |
| 1569 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) | 1569 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) |
| 1570 return false; | 1570 return false; |
| 1571 | 1571 |
| 1572 // TODO(cbiesinger): what about indefinite percentage heights? | 1572 return child.styleRef().logicalHeight().isAuto(); |
| 1573 return isHorizontalFlow() ? child.styleRef().height().isAuto() : child.style
Ref().width().isAuto(); | |
| 1574 } | 1573 } |
| 1575 | 1574 |
| 1576 bool LayoutFlexibleBox::childHasIntrinsicMainAxisSize(const LayoutBox& child) co
nst | 1575 bool LayoutFlexibleBox::childHasIntrinsicMainAxisSize(const LayoutBox& child) co
nst |
| 1577 { | 1576 { |
| 1578 bool result = false; | 1577 bool result = false; |
| 1579 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { | 1578 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { |
| 1580 Length childFlexBasis = flexBasisForChild(child); | 1579 Length childFlexBasis = flexBasisForChild(child); |
| 1581 Length childMinSize = isHorizontalFlow() ? child.style()->minWidth() : c
hild.style()->minHeight(); | 1580 Length childMinSize = isHorizontalFlow() ? child.style()->minWidth() : c
hild.style()->minHeight(); |
| 1582 Length childMaxSize = isHorizontalFlow() ? child.style()->maxWidth() : c
hild.style()->maxHeight(); | 1581 Length childMaxSize = isHorizontalFlow() ? child.style()->maxWidth() : c
hild.style()->maxHeight(); |
| 1583 if (childFlexBasis.isIntrinsic() || childMinSize.isIntrinsicOrAuto() ||
childMaxSize.isIntrinsic()) | 1582 if (childFlexBasis.isIntrinsic() || childMinSize.isIntrinsicOrAuto() ||
childMaxSize.isIntrinsic()) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 DCHECK(child); | 1851 DCHECK(child); |
| 1853 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMar
ginsInCrossAxis(*child) && minMarginAfterBaseline) | 1852 if (alignmentForChild(*child) == ItemPositionBaseline && !hasAutoMar
ginsInCrossAxis(*child) && minMarginAfterBaseline) |
| 1854 adjustAlignmentForChild(*child, minMarginAfterBaseline); | 1853 adjustAlignmentForChild(*child, minMarginAfterBaseline); |
| 1855 } | 1854 } |
| 1856 } | 1855 } |
| 1857 } | 1856 } |
| 1858 | 1857 |
| 1859 void LayoutFlexibleBox::applyStretchAlignmentToChild(LayoutBox& child, LayoutUni
t lineCrossAxisExtent) | 1858 void LayoutFlexibleBox::applyStretchAlignmentToChild(LayoutBox& child, LayoutUni
t lineCrossAxisExtent) |
| 1860 { | 1859 { |
| 1861 if (!hasOrthogonalFlow(child) && child.style()->logicalHeight().isAuto()) { | 1860 if (!hasOrthogonalFlow(child) && child.style()->logicalHeight().isAuto()) { |
| 1862 LayoutUnit heightBeforeStretching = needToStretchChildLogicalHeight(chil
d) ? constrainedChildIntrinsicContentLogicalHeight(child) : child.logicalHeight(
); | 1861 LayoutUnit heightBeforeStretching = childIntrinsicLogicalHeight(child); |
| 1863 LayoutUnit stretchedLogicalHeight = std::max(child.borderAndPaddingLogic
alHeight(), heightBeforeStretching + availableAlignmentSpaceForChildBeforeStretc
hing(lineCrossAxisExtent, child)); | 1862 LayoutUnit stretchedLogicalHeight = std::max(child.borderAndPaddingLogic
alHeight(), heightBeforeStretching + availableAlignmentSpaceForChildBeforeStretc
hing(lineCrossAxisExtent, child)); |
| 1864 DCHECK(!child.needsLayout()); | 1863 DCHECK(!child.needsLayout()); |
| 1865 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s
tretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogicalHei
ght()); | 1864 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s
tretchedLogicalHeight, heightBeforeStretching - child.borderAndPaddingLogicalHei
ght()); |
| 1866 | 1865 |
| 1867 // FIXME: Can avoid laying out here in some cases. See https://webkit.or
g/b/87905. | 1866 // FIXME: Can avoid laying out here in some cases. See https://webkit.or
g/b/87905. |
| 1868 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); | 1867 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); |
| 1869 if (child.isLayoutBlock() && toLayoutBlock(child).hasPercentHeightDescen
dants() && m_relaidOutChildren.contains(&child)) { | 1868 if (child.isLayoutBlock() && toLayoutBlock(child).hasPercentHeightDescen
dants() && m_relaidOutChildren.contains(&child)) { |
| 1870 // Have to force another relayout even though the child is sized cor
rectly, because | 1869 // Have to force another relayout even though the child is sized cor
rectly, because |
| 1871 // its descendants are not sized correctly yet. Our previous layout
of the child was | 1870 // its descendants are not sized correctly yet. Our previous layout
of the child was |
| 1872 // done without an override height set. So, redo it here. | 1871 // done without an override height set. So, redo it here. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 DCHECK(child); | 1921 DCHECK(child); |
| 1923 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1922 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1924 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1923 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1925 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1924 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1926 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1925 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1927 } | 1926 } |
| 1928 } | 1927 } |
| 1929 } | 1928 } |
| 1930 | 1929 |
| 1931 } // namespace blink | 1930 } // namespace blink |
| OLD | NEW |