| 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 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2318 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth,
marginStart, marginEnd); | 2318 LayoutUnit logicalWidthResult = fillAvailableMeasure(availableLogicalWidth,
marginStart, marginEnd); |
| 2319 | 2319 |
| 2320 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb
)->containsFloats()) | 2320 if (shrinkToAvoidFloats() && cb->isLayoutBlockFlow() && toLayoutBlockFlow(cb
)->containsFloats()) |
| 2321 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv
oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb))); | 2321 logicalWidthResult = std::min(logicalWidthResult, shrinkLogicalWidthToAv
oidFloats(marginStart, marginEnd, toLayoutBlockFlow(cb))); |
| 2322 | 2322 |
| 2323 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica
lWidth)) | 2323 if (widthType == MainOrPreferredSize && sizesLogicalWidthToFitContent(logica
lWidth)) |
| 2324 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical
Width(), logicalWidthResult)); | 2324 return std::max(minPreferredLogicalWidth(), std::min(maxPreferredLogical
Width(), logicalWidthResult)); |
| 2325 return logicalWidthResult; | 2325 return logicalWidthResult; |
| 2326 } | 2326 } |
| 2327 | 2327 |
| 2328 static bool columnFlexItemHasStretchAlignment(const LayoutObject* flexitem) | 2328 bool LayoutBox::columnFlexItemHasStretchAlignment() const |
| 2329 { | 2329 { |
| 2330 LayoutObject* parent = flexitem->parent(); | |
| 2331 // auto margins mean we don't stretch. Note that this function will only be
used for | 2330 // auto margins mean we don't stretch. Note that this function will only be
used for |
| 2332 // widths, so we don't have to check marginBefore/marginAfter. | 2331 // widths, so we don't have to check marginBefore/marginAfter. |
| 2333 ASSERT(parent->style()->isColumnFlexDirection()); | 2332 const auto& parentStyle = parent()->styleRef(); |
| 2334 if (flexitem->style()->marginStart().isAuto() || flexitem->style()->marginEn
d().isAuto()) | 2333 DCHECK(parentStyle.isColumnFlexDirection()); |
| 2334 if (styleRef().marginStart().isAuto() || styleRef().marginEnd().isAuto()) |
| 2335 return false; | 2335 return false; |
| 2336 return flexitem->style()->alignSelfPosition() == ItemPositionStretch || (fle
xitem->style()->alignSelfPosition() == ItemPositionAuto && parent->style()->alig
nItemsPosition() == ItemPositionStretch); | 2336 return styleRef().resolvedAlignSelf(containingBlock()->selfAlignmentNormalBe
havior(), isAnonymous() ? &parentStyle : nullptr).position() == ItemPositionStre
tch; |
| 2337 } | 2337 } |
| 2338 | 2338 |
| 2339 static bool isStretchingColumnFlexItem(const LayoutObject* flexitem) | 2339 bool LayoutBox::isStretchingColumnFlexItem() const |
| 2340 { | 2340 { |
| 2341 LayoutObject* parent = flexitem->parent(); | 2341 LayoutObject* parent = this->parent(); |
| 2342 if (parent->isDeprecatedFlexibleBox() && parent->style()->boxOrient() == VER
TICAL && parent->style()->boxAlign() == BSTRETCH) | 2342 if (parent->isDeprecatedFlexibleBox() && parent->style()->boxOrient() == VER
TICAL && parent->style()->boxAlign() == BSTRETCH) |
| 2343 return true; | 2343 return true; |
| 2344 | 2344 |
| 2345 // We don't stretch multiline flexboxes because they need to apply line spac
ing (align-content) first. | 2345 // We don't stretch multiline flexboxes because they need to apply line spac
ing (align-content) first. |
| 2346 if (parent->isFlexibleBox() && parent->style()->flexWrap() == FlexNoWrap &&
parent->style()->isColumnFlexDirection() && columnFlexItemHasStretchAlignment(fl
exitem)) | 2346 if (parent->isFlexibleBox() && parent->style()->flexWrap() == FlexNoWrap &&
parent->style()->isColumnFlexDirection() && columnFlexItemHasStretchAlignment()) |
| 2347 return true; | 2347 return true; |
| 2348 return false; | 2348 return false; |
| 2349 } | 2349 } |
| 2350 | 2350 |
| 2351 // TODO (lajava) Can/Should we move this inside specific layout classes (flex. g
rid)? Can we refactor columnFlexItemHasStretchAlignment logic? | 2351 // TODO (lajava) Can/Should we move this inside specific layout classes (flex. g
rid)? Can we refactor columnFlexItemHasStretchAlignment logic? |
| 2352 bool LayoutBox::hasStretchedLogicalWidth() const | 2352 bool LayoutBox::hasStretchedLogicalWidth() const |
| 2353 { | 2353 { |
| 2354 const ComputedStyle& style = styleRef(); | 2354 const ComputedStyle& style = styleRef(); |
| 2355 if (!style.logicalWidth().isAuto() || style.marginStart().isAuto() || style.
marginEnd().isAuto()) | 2355 if (!style.logicalWidth().isAuto() || style.marginStart().isAuto() || style.
marginEnd().isAuto()) |
| 2356 return false; | 2356 return false; |
| 2357 LayoutBlock* cb = containingBlock(); | 2357 LayoutBlock* cb = containingBlock(); |
| 2358 if (!cb) { | 2358 if (!cb) { |
| 2359 // We are evaluating align-self/justify-self, which default to 'normal'
for the root element. | 2359 // We are evaluating align-self/justify-self, which default to 'normal'
for the root element. |
| 2360 // The 'normal' value behaves like 'start' except for Flexbox Items, whi
ch obviously should have a container. | 2360 // The 'normal' value behaves like 'start' except for Flexbox Items, whi
ch obviously should have a container. |
| 2361 return false; | 2361 return false; |
| 2362 } | 2362 } |
| 2363 const ComputedStyle* parentStyle = isAnonymous() ? cb->style() : nullptr; |
| 2363 if (cb->isHorizontalWritingMode() != isHorizontalWritingMode()) | 2364 if (cb->isHorizontalWritingMode() != isHorizontalWritingMode()) |
| 2364 return ComputedStyle::resolveAlignment(cb->styleRef(), style, ItemPositi
onStretch) == ItemPositionStretch; | 2365 return style.resolvedAlignSelf(cb->selfAlignmentNormalBehavior(), parent
Style).position() == ItemPositionStretch; |
| 2365 return ComputedStyle::resolveJustification(cb->styleRef(), style, ItemPositi
onStretch) == ItemPositionStretch; | 2366 return style.resolvedJustifySelf(cb->selfAlignmentNormalBehavior(), parentSt
yle).position() == ItemPositionStretch; |
| 2366 } | 2367 } |
| 2367 | 2368 |
| 2368 bool LayoutBox::sizesLogicalWidthToFitContent(const Length& logicalWidth) const | 2369 bool LayoutBox::sizesLogicalWidthToFitContent(const Length& logicalWidth) const |
| 2369 { | 2370 { |
| 2370 if (isFloating() || isInlineBlockOrInlineTable()) | 2371 if (isFloating() || isInlineBlockOrInlineTable()) |
| 2371 return true; | 2372 return true; |
| 2372 | 2373 |
| 2373 if (isGridItem()) | 2374 if (isGridItem()) |
| 2374 return !hasStretchedLogicalWidth(); | 2375 return !hasStretchedLogicalWidth(); |
| 2375 | 2376 |
| 2376 // Flexible box items should shrink wrap, so we lay them out at their intrin
sic widths. | 2377 // Flexible box items should shrink wrap, so we lay them out at their intrin
sic widths. |
| 2377 // In the case of columns that have a stretch alignment, we go ahead and lay
out at the | 2378 // In the case of columns that have a stretch alignment, we go ahead and lay
out at the |
| 2378 // stretched size to avoid an extra layout when applying alignment. | 2379 // stretched size to avoid an extra layout when applying alignment. |
| 2379 if (parent()->isFlexibleBox()) { | 2380 if (parent()->isFlexibleBox()) { |
| 2380 // For multiline columns, we need to apply align-content first, so we ca
n't stretch now. | 2381 // For multiline columns, we need to apply align-content first, so we ca
n't stretch now. |
| 2381 if (!parent()->style()->isColumnFlexDirection() || parent()->style()->fl
exWrap() != FlexNoWrap) | 2382 if (!parent()->style()->isColumnFlexDirection() || parent()->style()->fl
exWrap() != FlexNoWrap) |
| 2382 return true; | 2383 return true; |
| 2383 if (!columnFlexItemHasStretchAlignment(this)) | 2384 if (!columnFlexItemHasStretchAlignment()) |
| 2384 return true; | 2385 return true; |
| 2385 } | 2386 } |
| 2386 | 2387 |
| 2387 // Flexible horizontal boxes lay out children at their intrinsic widths. Al
so vertical boxes | 2388 // Flexible horizontal boxes lay out children at their intrinsic widths. Al
so vertical boxes |
| 2388 // that don't stretch their kids lay out their children at their intrinsic w
idths. | 2389 // that don't stretch their kids lay out their children at their intrinsic w
idths. |
| 2389 // FIXME: Think about writing-mode here. | 2390 // FIXME: Think about writing-mode here. |
| 2390 // https://bugs.webkit.org/show_bug.cgi?id=46473 | 2391 // https://bugs.webkit.org/show_bug.cgi?id=46473 |
| 2391 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() =
= HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) | 2392 if (parent()->isDeprecatedFlexibleBox() && (parent()->style()->boxOrient() =
= HORIZONTAL || parent()->style()->boxAlign() != BSTRETCH)) |
| 2392 return true; | 2393 return true; |
| 2393 | 2394 |
| 2394 // Button, input, select, textarea, and legend treat width value of 'auto' a
s 'intrinsic' unless it's in a | 2395 // Button, input, select, textarea, and legend treat width value of 'auto' a
s 'intrinsic' unless it's in a |
| 2395 // stretching column flexbox. | 2396 // stretching column flexbox. |
| 2396 // FIXME: Think about writing-mode here. | 2397 // FIXME: Think about writing-mode here. |
| 2397 // https://bugs.webkit.org/show_bug.cgi?id=46473 | 2398 // https://bugs.webkit.org/show_bug.cgi?id=46473 |
| 2398 if (logicalWidth.isAuto() && !isStretchingColumnFlexItem(this) && autoWidthS
houldFitContent()) | 2399 if (logicalWidth.isAuto() && !isStretchingColumnFlexItem() && autoWidthShoul
dFitContent()) |
| 2399 return true; | 2400 return true; |
| 2400 | 2401 |
| 2401 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode(
)) | 2402 if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode(
)) |
| 2402 return true; | 2403 return true; |
| 2403 | 2404 |
| 2404 return false; | 2405 return false; |
| 2405 } | 2406 } |
| 2406 | 2407 |
| 2407 bool LayoutBox::autoWidthShouldFitContent() const | 2408 bool LayoutBox::autoWidthShouldFitContent() const |
| 2408 { | 2409 { |
| (...skipping 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4877 m_rareData->m_snapAreas->remove(&snapArea); | 4878 m_rareData->m_snapAreas->remove(&snapArea); |
| 4878 } | 4879 } |
| 4879 } | 4880 } |
| 4880 | 4881 |
| 4881 SnapAreaSet* LayoutBox::snapAreas() const | 4882 SnapAreaSet* LayoutBox::snapAreas() const |
| 4882 { | 4883 { |
| 4883 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; | 4884 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; |
| 4884 } | 4885 } |
| 4885 | 4886 |
| 4886 } // namespace blink | 4887 } // namespace blink |
| OLD | NEW |