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

Unified Diff: Source/core/rendering/RenderBox.cpp

Issue 24360004: Use shrink-to-fit for width for Button, input, select, textarea, and legend treat width value of 'a… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed review comments Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/RenderBox.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderBox.cpp
diff --git a/Source/core/rendering/RenderBox.cpp b/Source/core/rendering/RenderBox.cpp
index 84f11e672d2eb3c9686e9e5df2477c6fd974017a..015741bc42e0ad53d7407bda7799294288a9bef0 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) && autoWidthShouldFitContent())
return true;
if (isHorizontalWritingMode() != containingBlock()->isHorizontalWritingMode())
@@ -2357,6 +2356,15 @@ bool RenderBox::sizesLogicalWidthToFitContent(SizeType widthType) const
return false;
}
+bool RenderBox::autoWidthShouldFitContent() const
+{
+ 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,10 @@ 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));
+ if (autoWidthShouldFitContent())
+ 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);
« no previous file with comments | « Source/core/rendering/RenderBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698