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

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

Issue 185723005: Use correct container width as base for percentage margins. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added requested table test. Created 6 years, 9 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
Index: Source/core/rendering/RenderBox.cpp
diff --git a/Source/core/rendering/RenderBox.cpp b/Source/core/rendering/RenderBox.cpp
index 760eab0aad7d7832b5fed5c1e2a2aff48cfc7088..55bf74fa309f447994c956136a3344daaacce34e 100644
--- a/Source/core/rendering/RenderBox.cpp
+++ b/Source/core/rendering/RenderBox.cpp
@@ -2244,11 +2244,8 @@ void RenderBox::computeLogicalWidth(LogicalExtentComputedValues& computedValues)
computedValues.m_margins.m_start = minimumValueForLength(styleToUse->marginStart(), containerLogicalWidth);
computedValues.m_margins.m_end = minimumValueForLength(styleToUse->marginEnd(), containerLogicalWidth);
} else {
- LayoutUnit containerLogicalWidthForAutoMargins = containerLogicalWidth;
- if (avoidsFloats() && cb->containsFloats())
- containerLogicalWidthForAutoMargins = containingBlockAvailableLineWidth();
bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != style()->isLeftToRightDirection();
- computeInlineDirectionMargins(cb, containerLogicalWidthForAutoMargins, computedValues.m_extent,
+ computeInlineDirectionMargins(cb, containerLogicalWidth, computedValues.m_extent,
hasInvertedDirection ? computedValues.m_margins.m_end : computedValues.m_margins.m_start,
hasInvertedDirection ? computedValues.m_margins.m_start : computedValues.m_margins.m_end);
}
@@ -2445,31 +2442,35 @@ void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, Layo
marginEndLength.setValue(0);
}
+ LayoutUnit availableWidth = containerWidth;
+ if (avoidsFloats() && containingBlock->containsFloats())
+ availableWidth = containingBlockAvailableLineWidth();
+
// Case One: The object is being centered in the containing block's available logical width.
- if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < containerWidth)
+ if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < availableWidth)
|| (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containingBlock->style()->textAlign() == WEBKIT_CENTER)) {
// Other browsers center the margin box for align=center elements so we match them here.
LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, containerWidth);
LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, containerWidth);
- LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (containerWidth - childWidth - marginStartWidth - marginEndWidth) / 2);
+ LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (availableWidth - childWidth - marginStartWidth - marginEndWidth) / 2);
marginStart = centeredMarginBoxStart + marginStartWidth;
- marginEnd = containerWidth - childWidth - marginStart + marginEndWidth;
+ marginEnd = availableWidth - childWidth - marginStart + marginEndWidth;
return;
}
// Case Two: The object is being pushed to the start of the containing block's available logical width.
- if (marginEndLength.isAuto() && childWidth < containerWidth) {
+ if (marginEndLength.isAuto() && childWidth < availableWidth) {
marginStart = valueForLength(marginStartLength, containerWidth);
- marginEnd = containerWidth - childWidth - marginStart;
+ marginEnd = availableWidth - childWidth - marginStart;
return;
}
// Case Three: The object is being pushed to the end of the containing block's available logical width.
bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_LEFT)
|| (containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_RIGHT));
- if ((marginStartLength.isAuto() && childWidth < containerWidth) || pushToEndFromTextAlign) {
+ if ((marginStartLength.isAuto() && childWidth < availableWidth) || pushToEndFromTextAlign) {
marginEnd = valueForLength(marginEndLength, containerWidth);
- marginStart = containerWidth - childWidth - marginEnd;
+ marginStart = availableWidth - childWidth - marginEnd;
return;
}

Powered by Google App Engine
This is Rietveld 408576698