Chromium Code Reviews| Index: Source/core/rendering/RenderBox.cpp |
| diff --git a/Source/core/rendering/RenderBox.cpp b/Source/core/rendering/RenderBox.cpp |
| index 84f11e672d2eb3c9686e9e5df2477c6fd974017a..3c5eb95f809468d2f4fbb3d0d7c8c58e62f0a3fb 100644 |
| --- a/Source/core/rendering/RenderBox.cpp |
| +++ b/Source/core/rendering/RenderBox.cpp |
| @@ -2347,8 +2347,7 @@ bool RenderBox::sizesLogicalWidthToFitContent(SizeType widthType) const |
| // stretching column flexbox. |
| // FIXME: Think about block-flow here. |
| // https://bugs.webkit.org/show_bug.cgi?id=46473 |
| - if (logicalWidth.type() == Auto && !isStretchingColumnFlexItem(this) && node() && (node()->hasTagName(inputTag) |
| - || node()->hasTagName(selectTag) || node()->hasTagName(buttonTag) || isHTMLTextAreaElement(node()) || node()->hasTagName(legendTag))) |
| + if (logicalWidth.type() == Auto && !isStretchingColumnFlexItem(this) && isElementWithIntrinsicWidth()) |
| return true; |
| if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode()) |
| @@ -2357,6 +2356,15 @@ bool RenderBox::sizesLogicalWidthToFitContent(SizeType widthType) const |
| return false; |
| } |
| +bool RenderBox::isElementWithIntrinsicWidth() const |
|
ojan
2013/10/16 01:44:43
This name is too general. There are plenty of othe
pals
2013/10/16 07:10:05
Done.
|
| +{ |
| + if (node() && (node()->hasTagName(inputTag) || node()->hasTagName(selectTag) || node()->hasTagName(buttonTag) |
| + || isHTMLTextAreaElement(node()) || node()->hasTagName(legendTag))) |
| + return true; |
| + |
| + return false; |
| +} |
| + |
| void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, LayoutUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUnit& marginEnd) const |
| { |
| const RenderStyle* containingBlockStyle = containingBlock->style(); |
| @@ -3325,6 +3333,15 @@ static void computeLogicalLeftPositionedOffset(LayoutUnit& logicalLeftPos, const |
| logicalLeftPos += (child->isHorizontalWritingMode() ? containerBlock->borderLeft() : containerBlock->borderTop()); |
| } |
| +void RenderBox::shrinkToFitWidth(const LayoutUnit availableSpace, const LayoutUnit logicalLeftValue, const LayoutUnit bordersPlusPadding, LogicalExtentComputedValues& computedValues) const |
| +{ |
| + // FIXME: would it be better to have shrink-to-fit in one step? |
| + LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlusPadding; |
| + LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersPlusPadding; |
| + LayoutUnit availableWidth = availableSpace - logicalLeftValue; |
| + computedValues.m_extent = min(max(preferredMinWidth, availableWidth), preferredWidth); |
| +} |
| + |
| void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const RenderBoxModelObject* containerBlock, TextDirection containerDirection, |
| LayoutUnit containerLogicalWidth, LayoutUnit bordersPlusPadding, |
| Length logicalLeft, Length logicalRight, Length marginLogicalLeft, Length marginLogicalRight, |
| @@ -3467,11 +3484,7 @@ void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re |
| // RULE 3: (use shrink-to-fit for width, and no need solve of right) |
| logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth, renderView); |
| - // FIXME: would it be better to have shrink-to-fit in one step? |
| - LayoutUnit preferredWidth = maxPreferredLogicalWidth() - bordersPlusPadding; |
| - LayoutUnit preferredMinWidth = minPreferredLogicalWidth() - bordersPlusPadding; |
| - LayoutUnit availableWidth = availableSpace - logicalLeftValue; |
| - computedValues.m_extent = min(max(preferredMinWidth, availableWidth), preferredWidth); |
| + shrinkToFitWidth(availableSpace, logicalLeftValue, bordersPlusPadding, computedValues); |
| } else if (logicalLeftIsAuto && !logicalWidthIsAuto && !logicalRightIsAuto) { |
| // RULE 4: (solve for left) |
| computedValues.m_extent = adjustContentBoxLogicalWidthForBoxSizing(valueForLength(logicalWidth, containerLogicalWidth, renderView)); |
| @@ -3479,7 +3492,12 @@ void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re |
| } else if (!logicalLeftIsAuto && logicalWidthIsAuto && !logicalRightIsAuto) { |
| // RULE 5: (solve for width) |
| logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth, renderView); |
| - computedValues.m_extent = availableSpace - (logicalLeftValue + valueForLength(logicalRight, containerLogicalWidth, renderView)); |
| + // Use shrink-to-fit for width for Button, input, select, textarea, and legend treat width value of |
| + // 'auto' as 'intrinsic'. |
|
ojan
2013/10/16 01:44:43
I don't think this comment adds value. With the ne
pals
2013/10/16 07:10:05
Done.
|
| + if (isElementWithIntrinsicWidth()) |
| + shrinkToFitWidth(availableSpace, logicalLeftValue, bordersPlusPadding, computedValues); |
| + else |
| + computedValues.m_extent = availableSpace - (logicalLeftValue + valueForLength(logicalRight, containerLogicalWidth, renderView)); |
| } else if (!logicalLeftIsAuto && !logicalWidthIsAuto && logicalRightIsAuto) { |
| // RULE 6: (no need solve for right) |
| logicalLeftValue = valueForLength(logicalLeft, containerLogicalWidth, renderView); |