Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 2100463002: Fix sizing of intrinsic size keywords in combination with box-sizing: border-box (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css-intrinsic-dimensions/border-box-sizing.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 // TODO(cbiesinger): We should probably return something other than just bor der + padding, but for now 2618 // TODO(cbiesinger): We should probably return something other than just bor der + padding, but for now
2619 // we have no good way to do anything else without layout, so we just use th at. 2619 // we have no good way to do anything else without layout, so we just use th at.
2620 LogicalExtentComputedValues computedValues; 2620 LogicalExtentComputedValues computedValues;
2621 computeLogicalHeight(borderAndPaddingLogicalHeight(), LayoutUnit(), computed Values); 2621 computeLogicalHeight(borderAndPaddingLogicalHeight(), LayoutUnit(), computed Values);
2622 return computedValues.m_extent; 2622 return computedValues.m_extent;
2623 } 2623 }
2624 2624
2625 LayoutUnit LayoutBox::computeLogicalHeightUsing(SizeType heightType, const Lengt h& height, LayoutUnit intrinsicContentHeight) const 2625 LayoutUnit LayoutBox::computeLogicalHeightUsing(SizeType heightType, const Lengt h& height, LayoutUnit intrinsicContentHeight) const
2626 { 2626 {
2627 LayoutUnit logicalHeight = computeContentAndScrollbarLogicalHeightUsing(heig htType, height, intrinsicContentHeight); 2627 LayoutUnit logicalHeight = computeContentAndScrollbarLogicalHeightUsing(heig htType, height, intrinsicContentHeight);
2628 if (logicalHeight != -1) 2628 if (logicalHeight != -1) {
2629 logicalHeight = adjustBorderBoxLogicalHeightForBoxSizing(logicalHeight); 2629 if (height.isSpecified())
2630 logicalHeight = adjustBorderBoxLogicalHeightForBoxSizing(logicalHeig ht);
2631 else
2632 logicalHeight += borderAndPaddingLogicalHeight();
2633 }
2630 return logicalHeight; 2634 return logicalHeight;
2631 } 2635 }
2632 2636
2633 LayoutUnit LayoutBox::computeContentLogicalHeight(SizeType heightType, const Len gth& height, LayoutUnit intrinsicContentHeight) const 2637 LayoutUnit LayoutBox::computeContentLogicalHeight(SizeType heightType, const Len gth& height, LayoutUnit intrinsicContentHeight) const
2634 { 2638 {
2635 LayoutUnit heightIncludingScrollbar = computeContentAndScrollbarLogicalHeigh tUsing(heightType, height, intrinsicContentHeight); 2639 LayoutUnit heightIncludingScrollbar = computeContentAndScrollbarLogicalHeigh tUsing(heightType, height, intrinsicContentHeight);
2636 if (heightIncludingScrollbar == -1) 2640 if (heightIncludingScrollbar == -1)
2637 return LayoutUnit(-1); 2641 return LayoutUnit(-1);
2638 return std::max(LayoutUnit(), adjustContentBoxLogicalHeightForBoxSizing(heig htIncludingScrollbar) - scrollbarLogicalHeight()); 2642 LayoutUnit adjusted = heightIncludingScrollbar;
2643 if (height.isSpecified()) {
2644 // Keywords don't get adjusted for box-sizing
2645 adjusted = adjustContentBoxLogicalHeightForBoxSizing(heightIncludingScro llbar);
2646 }
2647 return std::max(LayoutUnit(), adjusted - scrollbarLogicalHeight());
2639 } 2648 }
2640 2649
2641 LayoutUnit LayoutBox::computeIntrinsicLogicalContentHeightUsing(const Length& lo gicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddin g) const 2650 LayoutUnit LayoutBox::computeIntrinsicLogicalContentHeightUsing(const Length& lo gicalHeightLength, LayoutUnit intrinsicContentHeight, LayoutUnit borderAndPaddin g) const
2642 { 2651 {
2643 // FIXME(cbiesinger): The css-sizing spec is considering changing what min-c ontent/max-content should resolve to. 2652 // FIXME(cbiesinger): The css-sizing spec is considering changing what min-c ontent/max-content should resolve to.
2644 // If that happens, this code will have to change. 2653 // If that happens, this code will have to change.
2645 if (logicalHeightLength.isMinContent() || logicalHeightLength.isMaxContent() || logicalHeightLength.isFitContent()) { 2654 if (logicalHeightLength.isMinContent() || logicalHeightLength.isMaxContent() || logicalHeightLength.isFitContent()) {
2646 if (isAtomicInlineLevel()) 2655 if (isAtomicInlineLevel())
2647 return intrinsicSize().height(); 2656 return intrinsicSize().height();
2648 return intrinsicContentHeight; 2657 return intrinsicContentHeight;
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
3304 LayoutUnit preferredLogicalWidth = maxPreferredLogicalWidth() - bordersPlusP adding; 3313 LayoutUnit preferredLogicalWidth = maxPreferredLogicalWidth() - bordersPlusP adding;
3305 LayoutUnit preferredMinLogicalWidth = minPreferredLogicalWidth() - bordersPl usPadding; 3314 LayoutUnit preferredMinLogicalWidth = minPreferredLogicalWidth() - bordersPl usPadding;
3306 return std::min(std::max(preferredMinLogicalWidth, availableLogicalWidth), p referredLogicalWidth); 3315 return std::min(std::max(preferredMinLogicalWidth, availableLogicalWidth), p referredLogicalWidth);
3307 } 3316 }
3308 3317
3309 void LayoutBox::computePositionedLogicalWidthUsing(SizeType widthSizeType, Lengt h logicalWidth, const LayoutBoxModelObject* containerBlock, TextDirection contai nerDirection, 3318 void LayoutBox::computePositionedLogicalWidthUsing(SizeType widthSizeType, Lengt h logicalWidth, const LayoutBoxModelObject* containerBlock, TextDirection contai nerDirection,
3310 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding, 3319 LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding,
3311 const Length& logicalLeft, const Length& logicalRight, const Length& marginL ogicalLeft, 3320 const Length& logicalLeft, const Length& logicalRight, const Length& marginL ogicalLeft,
3312 const Length& marginLogicalRight, LogicalExtentComputedValues& computedValue s) const 3321 const Length& marginLogicalRight, LogicalExtentComputedValues& computedValue s) const
3313 { 3322 {
3323 LayoutUnit logicalWidthValue;
3324
3314 ASSERT(widthSizeType == MinSize || widthSizeType == MainOrPreferredSize || ! logicalWidth.isAuto()); 3325 ASSERT(widthSizeType == MinSize || widthSizeType == MainOrPreferredSize || ! logicalWidth.isAuto());
3315 if (widthSizeType == MinSize && logicalWidth.isAuto()) 3326 if (widthSizeType == MinSize && logicalWidth.isAuto())
3316 logicalWidth = Length(0, Fixed); 3327 logicalWidthValue = LayoutUnit();
3317 else if (logicalWidth.isIntrinsic()) 3328 else if (logicalWidth.isIntrinsic())
3318 logicalWidth = Length(computeIntrinsicLogicalWidthUsing(logicalWidth, co ntainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding, Fixed); 3329 logicalWidthValue = computeIntrinsicLogicalWidthUsing(logicalWidth, cont ainerLogicalWidth, bordersPlusPadding) - bordersPlusPadding;
3330 else
3331 logicalWidthValue = adjustContentBoxLogicalWidthForBoxSizing(valueForLen gth(logicalWidth, containerLogicalWidth));
3319 3332
3320 // 'left' and 'right' cannot both be 'auto' because one would of been 3333 // 'left' and 'right' cannot both be 'auto' because one would of been
3321 // converted to the static position already 3334 // converted to the static position already
3322 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto())); 3335 ASSERT(!(logicalLeft.isAuto() && logicalRight.isAuto()));
3323 3336
3324 // minimumValueForLength will convert 'auto' to 0 so that it doesn't impact the available space computation below. 3337 // minimumValueForLength will convert 'auto' to 0 so that it doesn't impact the available space computation below.
3325 LayoutUnit logicalLeftValue = minimumValueForLength(logicalLeft, containerLo gicalWidth); 3338 LayoutUnit logicalLeftValue = minimumValueForLength(logicalLeft, containerLo gicalWidth);
3326 LayoutUnit logicalRightValue = minimumValueForLength(logicalRight, container LogicalWidth); 3339 LayoutUnit logicalRightValue = minimumValueForLength(logicalRight, container LogicalWidth);
3327 3340
3328 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false); 3341 const LayoutUnit containerRelativeLogicalWidth = containingBlockLogicalWidth ForPositioned(containerBlock, false);
3329 3342
3330 bool logicalWidthIsAuto = logicalWidth.isIntrinsicOrAuto(); 3343 bool logicalWidthIsAuto = logicalWidth.isAuto();
3331 bool logicalLeftIsAuto = logicalLeft.isAuto(); 3344 bool logicalLeftIsAuto = logicalLeft.isAuto();
3332 bool logicalRightIsAuto = logicalRight.isAuto(); 3345 bool logicalRightIsAuto = logicalRight.isAuto();
3333 LayoutUnit& marginLogicalLeftValue = style()->isLeftToRightDirection() ? com putedValues.m_margins.m_start : computedValues.m_margins.m_end; 3346 LayoutUnit& marginLogicalLeftValue = style()->isLeftToRightDirection() ? com putedValues.m_margins.m_start : computedValues.m_margins.m_end;
3334 LayoutUnit& marginLogicalRightValue = style()->isLeftToRightDirection() ? co mputedValues.m_margins.m_end : computedValues.m_margins.m_start; 3347 LayoutUnit& marginLogicalRightValue = style()->isLeftToRightDirection() ? co mputedValues.m_margins.m_end : computedValues.m_margins.m_start;
3335 if (!logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAuto) { 3348 if (!logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAuto) {
3336 /*---------------------------------------------------------------------- -*\ 3349 /*---------------------------------------------------------------------- -*\
3337 * If none of the three is 'auto': If both 'margin-left' and 'margin- 3350 * If none of the three is 'auto': If both 'margin-left' and 'margin-
3338 * right' are 'auto', solve the equation under the extra constraint that 3351 * right' are 'auto', solve the equation under the extra constraint that
3339 * the two margins get equal values, unless this would make them negativ e, 3352 * the two margins get equal values, unless this would make them negativ e,
3340 * in which case when direction of the containing block is 'ltr' ('rtl') , 3353 * in which case when direction of the containing block is 'ltr' ('rtl') ,
3341 * set 'margin-left' ('margin-right') to zero and solve for 'margin-righ t' 3354 * set 'margin-left' ('margin-right') to zero and solve for 'margin-righ t'
3342 * ('margin-left'). If one of 'margin-left' or 'margin-right' is 'auto', 3355 * ('margin-left'). If one of 'margin-left' or 'margin-right' is 'auto',
3343 * solve the equation for that value. If the values are over-constrained , 3356 * solve the equation for that value. If the values are over-constrained ,
3344 * ignore the value for 'left' (in case the 'direction' property of the 3357 * ignore the value for 'left' (in case the 'direction' property of the
3345 * containing block is 'rtl') or 'right' (in case 'direction' is 'ltr') 3358 * containing block is 'rtl') or 'right' (in case 'direction' is 'ltr')
3346 * and solve for that value. 3359 * and solve for that value.
3347 \*---------------------------------------------------------------------- -*/ 3360 \*---------------------------------------------------------------------- -*/
3348 // NOTE: It is not necessary to solve for 'right' in the over constrain ed 3361 // NOTE: It is not necessary to solve for 'right' in the over constrain ed
3349 // case because the value is not used for any further calculations. 3362 // case because the value is not used for any further calculations.
3350 3363
3351 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(value ForLength(logicalWidth, containerLogicalWidth)); 3364 computedValues.m_extent = logicalWidthValue;
3352 3365
3353 const LayoutUnit availableSpace = containerLogicalWidth - (logicalLeftVa lue + computedValues.m_extent + logicalRightValue + bordersPlusPadding); 3366 const LayoutUnit availableSpace = containerLogicalWidth - (logicalLeftVa lue + computedValues.m_extent + logicalRightValue + bordersPlusPadding);
3354 3367
3355 // Margins are now the only unknown 3368 // Margins are now the only unknown
3356 if (marginLogicalLeft.isAuto() && marginLogicalRight.isAuto()) { 3369 if (marginLogicalLeft.isAuto() && marginLogicalRight.isAuto()) {
3357 // Both margins auto, solve for equality 3370 // Both margins auto, solve for equality
3358 if (availableSpace >= 0) { 3371 if (availableSpace >= 0) {
3359 marginLogicalLeftValue = availableSpace / 2; // split the differ ence 3372 marginLogicalLeftValue = availableSpace / 2; // split the differ ence
3360 marginLogicalRightValue = availableSpace - marginLogicalLeftValu e; // account for odd valued differences 3373 marginLogicalRightValue = availableSpace - marginLogicalLeftValu e; // account for odd valued differences
3361 } else { 3374 } else {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 // Use rule/case that applies. 3452 // Use rule/case that applies.
3440 if (logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAuto) { 3453 if (logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAuto) {
3441 // RULE 1: (use shrink-to-fit for width, and solve of left) 3454 // RULE 1: (use shrink-to-fit for width, and solve of left)
3442 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace, bo rdersPlusPadding); 3455 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace, bo rdersPlusPadding);
3443 logicalLeftValue = availableSpace - computedValues.m_extent; 3456 logicalLeftValue = availableSpace - computedValues.m_extent;
3444 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && logicalRightIsAut o) { 3457 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && logicalRightIsAut o) {
3445 // RULE 3: (use shrink-to-fit for width, and no need solve of right) 3458 // RULE 3: (use shrink-to-fit for width, and no need solve of right)
3446 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace, bo rdersPlusPadding); 3459 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace, bo rdersPlusPadding);
3447 } else if (logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAu to) { 3460 } else if (logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAu to) {
3448 // RULE 4: (solve for left) 3461 // RULE 4: (solve for left)
3449 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth)); 3462 computedValues.m_extent = logicalWidthValue;
3450 logicalLeftValue = availableSpace - computedValues.m_extent; 3463 logicalLeftValue = availableSpace - computedValues.m_extent;
3451 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAu to) { 3464 } else if (!logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAu to) {
3452 // RULE 5: (solve for width) 3465 // RULE 5: (solve for width)
3453 if (autoWidthShouldFitContent()) 3466 if (autoWidthShouldFitContent())
3454 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace , bordersPlusPadding); 3467 computedValues.m_extent = shrinkToFitLogicalWidth(availableSpace , bordersPlusPadding);
3455 else 3468 else
3456 computedValues.m_extent = std::max(LayoutUnit(), availableSpace) ; 3469 computedValues.m_extent = std::max(LayoutUnit(), availableSpace) ;
3457 } else if (!logicalLeftIsAuto && !logicalWidthIsAuto && logicalRightIsAu to) { 3470 } else if (!logicalLeftIsAuto && !logicalWidthIsAuto && logicalRightIsAu to) {
3458 // RULE 6: (no need solve for right) 3471 // RULE 6: (no need solve for right)
3459 computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(v alueForLength(logicalWidth, containerLogicalWidth)); 3472 computedValues.m_extent = logicalWidthValue;
3460 } 3473 }
3461 } 3474 }
3462 3475
3463 // Use computed values to calculate the horizontal position. 3476 // Use computed values to calculate the horizontal position.
3464 3477
3465 // FIXME: This hack is needed to calculate the logical left position for a 'rtl' relatively 3478 // FIXME: This hack is needed to calculate the logical left position for a 'rtl' relatively
3466 // positioned, inline because right now, it is using the logical left positi on 3479 // positioned, inline because right now, it is using the logical left positi on
3467 // of the first line box when really it should use the last line box. When 3480 // of the first line box when really it should use the last line box. When
3468 // this is fixed elsewhere, this block should be removed. 3481 // this is fixed elsewhere, this block should be removed.
3469 if (containerBlock->isLayoutInline() && !containerBlock->style()->isLeftToRi ghtDirection()) { 3482 if (containerBlock->isLayoutInline() && !containerBlock->style()->isLeftToRi ghtDirection()) {
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
4886 m_rareData->m_snapAreas->remove(&snapArea); 4899 m_rareData->m_snapAreas->remove(&snapArea);
4887 } 4900 }
4888 } 4901 }
4889 4902
4890 SnapAreaSet* LayoutBox::snapAreas() const 4903 SnapAreaSet* LayoutBox::snapAreas() const
4891 { 4904 {
4892 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr; 4905 return m_rareData ? m_rareData->m_snapAreas.get() : nullptr;
4893 } 4906 }
4894 4907
4895 } // namespace blink 4908 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css-intrinsic-dimensions/border-box-sizing.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698