| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. |
| 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 2381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2392 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth,
marginStart, marginEnd); | 2392 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth,
marginStart, marginEnd); |
| 2393 | 2393 |
| 2394 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb
)->containsFloats()) | 2394 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb
)->containsFloats()) |
| 2395 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv
oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb))); | 2395 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv
oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb))); |
| 2396 | 2396 |
| 2397 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica
lWidth)) | 2397 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica
lWidth)) |
| 2398 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical
Width(), logicalWidthResult)); | 2398 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical
Width(), logicalWidthResult)); |
| 2399 return logicalWidthResult; | 2399 return logicalWidthResult; |
| 2400 } | 2400 } |
| 2401 | 2401 |
| 2402 static bool columnFlexItemHasStretchAlignment(const LayoutObject* flexitem) | 2402 bool LayoutBox::columnFlexItemHasStretchAlignment() const |
| 2403 { | 2403 { |
| 2404 LayoutObject* parent = flexitem->parent(); | |
| 2405 // auto margins mean we don't stretch. Note that this function will only be
used for | 2404 // auto margins mean we don't stretch. Note that this function will only be
used for |
| 2406 // widths, so we don't have to check marginBefore/marginAfter. | 2405 // widths, so we don't have to check marginBefore/marginAfter. |
| 2407 ASSERT(parent->style()->isColumnFlexDirection()); | 2406 const auto& parentStyle = parent()->styleRef(); |
| 2408 if (flexitem->style()->marginStart().isAuto() || flexitem->style()->marginEn
d().isAuto()) | 2407 DCHECK(parentStyle.isColumnFlexDirection()); |
| 2408 if (styleRef().marginStart().isAuto() || styleRef().marginEnd().isAuto()) |
| 2409 return false; | 2409 return false; |
| 2410 return flexitem->style()->alignSelfPosition() == ItemPositionStretch || (fle
xitem->style()->alignSelfPosition() == ItemPositionAuto && parent->style()->alig
nItemsPosition() == ItemPositionStretch); | 2410 return styleRef().resolvedAlignSelf(containingBlock()->selfAlignmentNormalBe
havior(), isAnonymous() ? &parentStyle : nullptr).position() == ItemPositionStre
tch; |
| 2411 } | 2411 } |
| 2412 | 2412 |
| 2413 static bool isStretchingColumnFlexItem(const LayoutObject* flexitem) | 2413 bool LayoutBox::isStretchingColumnFlexItem() const |
| 2414 { | 2414 { |
| 2415 LayoutObject* parent = flexitem->parent(); | 2415 LayoutObject* parent = this->parent(); |
| 2416 if (parent->isDeprecatedFlexibleBox() && parent->style()->boxOrient() == VER
TICAL && parent->style()->boxAlign() == BSTRETCH) | 2416 if (parent->isDeprecatedFlexibleBox() && parent->style()->boxOrient() == VER
TICAL && parent->style()->boxAlign() == BSTRETCH) |
| 2417 return true; | 2417 return true; |
| 2418 | 2418 |
| 2419 // We don't stretch multiline flexboxes because they need to apply line spac
ing (align-content) first. | 2419 // We don't stretch multiline flexboxes because they need to apply line spac
ing (align-content) first. |
| 2420 if (parent->isFlexibleBox() && parent->style()->flexWrap() == FlexNoWrap &&
parent->style()->isColumnFlexDirection() && columnFlexItemHasStretchAlignment(fl
exitem)) | 2420 if (parent->isFlexibleBox() && parent->style()->flexWrap() == FlexNoWrap &&
parent->style()->isColumnFlexDirection() && columnFlexItemHasStretchAlignment()) |
| 2421 return true; | 2421 return true; |
| 2422 return false; | 2422 return false; |
| 2423 } | 2423 } |
| 2424 | 2424 |
| 2425 // TODO (lajava) Can/Should we move this inside specific layout classes (flex. g
rid)? Can we refactor columnFlexItemHasStretchAlignment logic? | 2425 // TODO (lajava) Can/Should we move this inside specific layout classes (flex. g
rid)? Can we refactor columnFlexItemHasStretchAlignment logic? |
| 2426 bool LayoutBox::hasStretchedLogicalWidth() const | 2426 bool LayoutBox::hasStretchedLogicalWidth() const |
| 2427 { | 2427 { |
| 2428 const ComputedStyle& style = styleRef(); | 2428 const ComputedStyle& style = styleRef(); |
| 2429 if (!style.logicalWidth().isAuto() || style.marginStart().isAuto() || style.
marginEnd().isAuto()) | 2429 if (!style.logicalWidth().isAuto() || style.marginStart().isAuto() || style.
marginEnd().isAuto()) |
| 2430 return false; | 2430 return false; |
| 2431 LayoutBlock* cb = containingBlock(); | 2431 LayoutBlock* cb = containingBlock(); |
| 2432 if (!cb) { | 2432 if (!cb) { |
| 2433 // We are evaluating align-self/justify-self, which default to 'normal'
for the root element. | 2433 // We are evaluating align-self/justify-self, which default to 'normal'
for the root element. |
| 2434 // The 'normal' value behaves like 'start' except for Flexbox Items, whi
ch obviously should have a container. | 2434 // The 'normal' value behaves like 'start' except for Flexbox Items, whi
ch obviously should have a container. |
| 2435 return false; | 2435 return false; |
| 2436 } | 2436 } |
| 2437 const ComputedStyle* parentStyle = isAnonymous() ? cb->style() : nullptr; |
| 2437 if (cb->isHorizontalWritingMode() != isHorizontalWritingMode()) | 2438 if (cb->isHorizontalWritingMode() != isHorizontalWritingMode()) |
| 2438 return ComputedStyle::resolveAlignment(cb->styleRef(), style, ItemPositi
onStretch) == ItemPositionStretch; | 2439 return style.resolvedAlignSelf(cb->selfAlignmentNormalBehavior(), parent
Style).position() == ItemPositionStretch; |
| 2439 return ComputedStyle::resolveJustification(cb->styleRef(), style, ItemPositi
onStretch) == ItemPositionStretch; | 2440 return style.resolvedJustifySelf(cb->selfAlignmentNormalBehavior(), parentSt
yle).position() == ItemPositionStretch; |
| 2440 } | 2441 } |
| 2441 | 2442 |
| 2442 bool LayoutBox::sizesLogicalWidthToFitContent(const Length& logicalWidth) const | 2443 bool LayoutBox::sizesLogicalWidthToFitContent(const Length& logicalWidth) const |
| 2443 { | 2444 { |
| 2444 if (isFloating() || isInlineBlockOrInlineTable()) | 2445 if (isFloating() || isInlineBlockOrInlineTable()) |
| 2445 return true; | 2446 return true; |
| 2446 | 2447 |
| 2447 if (isGridItem()) | 2448 if (isGridItem()) |
| 2448 return !hasStretchedLogicalWidth(); | 2449 return !hasStretchedLogicalWidth(); |
| 2449 | 2450 |
| 2450 // Flexible box items should shrink wrap, so we lay them out at their intrin
sic widths. | 2451 // Flexible box items should shrink wrap, so we lay them out at their intrin
sic widths. |
| 2451 // In the case of columns that have a stretch alignment, we go ahead and lay
out at the | 2452 // In the case of columns that have a stretch alignment, we go ahead and lay
out at the |
| 2452 // stretched size to avoid an extra layout when applying alignment. | 2453 // stretched size to avoid an extra layout when applying alignment. |
| 2453 if (parent()->isFlexibleBox()) { | 2454 if (parent()->isFlexibleBox()) { |
| 2454 // For multiline columns, we need to apply align-content first, so we ca
n't stretch now. | 2455 // For multiline columns, we need to apply align-content first, so we ca
n't stretch now. |
| 2455 if (!parent()->style()->isColumnFlexDirection() || parent()->style()->fl
exWrap() != FlexNoWrap) | 2456 if (!parent()->style()->isColumnFlexDirection() || parent()->style()->fl
exWrap() != FlexNoWrap) |
| 2456 return true; | 2457 return true; |
| 2457 if (!columnFlexItemHasStretchAlignment(this)) | 2458 if (!columnFlexItemHasStretchAlignment()) |
| 2458 return true; | 2459 return true; |
| 2459 } | 2460 } |
| 2460 | 2461 |
| 2461 // Flexible horizontal boxes lay out children at their intrinsic widths. Al
so vertical boxes | 2462 // Flexible horizontal boxes lay out children at their intrinsic widths. Al
so vertical boxes |
| 2462 // that don't stretch their kids lay out their children at their intrinsic w
idths. | 2463 // that don't stretch their kids lay out their children at their intrinsic w
idths. |
| 2463 // FIXME: Think about writing-mode here. | 2464 // FIXME: Think about writing-mode here. |
| 2464 // https://bugs.webkit.org/show_bug.cgi?id=46473 | 2465 // https://bugs.webkit.org/show_bug.cgi?id=46473 |
| 2465 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() =
= HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) | 2466 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() =
= HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) |
| 2466 return true; | 2467 return true; |
| 2467 | 2468 |
| 2468 // Button, input, select, textarea, and legend treat width value of 'auto' a
s 'intrinsic' unless it's in a | 2469 // Button, input, select, textarea, and legend treat width value of 'auto' a
s 'intrinsic' unless it's in a |
| 2469 // stretching column flexbox. | 2470 // stretching column flexbox. |
| 2470 // FIXME: Think about writing-mode here. | 2471 // FIXME: Think about writing-mode here. |
| 2471 // https://bugs.webkit.org/show_bug.cgi?id=46473 | 2472 // https://bugs.webkit.org/show_bug.cgi?id=46473 |
| 2472 if (logicalWidth.isAuto() && !isStretchingColumnFlexItem(this) && autoWidthS
houldFitContent()) | 2473 if (logicalWidth.isAuto() && !isStretchingColumnFlexItem() && autoWidthShoul
dFitContent()) |
| 2473 return true; | 2474 return true; |
| 2474 | 2475 |
| 2475 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode(
)) | 2476 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode(
)) |
| 2476 return true; | 2477 return true; |
| 2477 | 2478 |
| 2478 return false; | 2479 return false; |
| 2479 } | 2480 } |
| 2480 | 2481 |
| 2481 bool LayoutBox::autoWidthShouldFitContent() const | 2482 bool LayoutBox::autoWidthShouldFitContent() const |
| 2482 { | 2483 { |
| (...skipping 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4797 m_rareData->m_snapAreas->remove(&snapArea); | 4798 m_rareData->m_snapAreas->remove(&snapArea); |
| 4798 } | 4799 } |
| 4799 } | 4800 } |
| 4800 | 4801 |
| 4801 SnapAreaSet* LayoutBox::snapAreas() const | 4802 SnapAreaSet* LayoutBox::snapAreas() const |
| 4802 { | 4803 { |
| 4803 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; | 4804 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; |
| 4804 } | 4805 } |
| 4805 | 4806 |
| 4806 } // namespace blink | 4807 } // namespace blink |
| OLD | NEW |