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

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

Issue 790943004: An align attribute should not be applied for wider children (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebaseline the failed testcase (reftest) Created 6 years 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 | « LayoutTests/tables/mozilla_expected_failures/marvin/table_overflow_td_align_right-expected.html ('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 7c0317be2904508c2c8bb47f8f9942dddf60f2b2..823c104db3c878619f1df2a1de3c951357e431bb 100644
--- a/Source/core/rendering/RenderBox.cpp
+++ b/Source/core/rendering/RenderBox.cpp
@@ -2131,39 +2131,43 @@ void RenderBox::computeMarginsForDirection(MarginDirection flowDirection, const
// values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
LayoutUnit marginBoxWidth = childWidth + (!style()->width().isAuto() ? marginStartWidth + marginEndWidth : LayoutUnit());
- // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element
- // with respect to the edges of the containing block."
- const RenderStyle* containingBlockStyle = containingBlock->style();
- if ((marginStartLength.isAuto() && marginEndLength.isAuto() && marginBoxWidth < availableWidth)
- || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containingBlockStyle->textAlign() == WEBKIT_CENTER)) {
- // Other browsers center the margin box for align=center elements so we match them here.
- LayoutUnit centeredMarginBoxStart = std::max(LayoutUnit(), (availableWidth - childWidth - marginStartWidth - marginEndWidth) / 2);
- marginStart = centeredMarginBoxStart + marginStartWidth;
- marginEnd = availableWidth - childWidth - marginStart + marginEndWidth;
- return;
- }
-
- // CSS 2.1: "If there is exactly one value specified as 'auto', its used value follows from the equality."
- if (marginEndLength.isAuto() && marginBoxWidth < availableWidth) {
- marginStart = marginStartWidth;
- marginEnd = availableWidth - childWidth - marginStart;
- return;
- }
+ if (marginBoxWidth < availableWidth) {
+ // CSS 2.1: "If both 'margin-left' and 'margin-right' are 'auto', their used values are equal. This horizontally centers the element
+ // with respect to the edges of the containing block."
+ const RenderStyle* containingBlockStyle = containingBlock->style();
+ if ((marginStartLength.isAuto() && marginEndLength.isAuto())
+ || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containingBlockStyle->textAlign() == WEBKIT_CENTER)) {
+ // Other browsers center the margin box for align=center elements so we match them here.
+ LayoutUnit centeredMarginBoxStart = std::max(LayoutUnit(), (availableWidth - childWidth - marginStartWidth - marginEndWidth) / 2);
+ marginStart = centeredMarginBoxStart + marginStartWidth;
+ marginEnd = availableWidth - childWidth - marginStart + marginEndWidth;
+ return;
+ }
- bool adjustFromTextAlign = !marginEndLength.isAuto() && ((!containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_LEFT)
- || (containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_RIGHT));
- bool hasInvertedDirection = containingBlockStyle->isLeftToRightDirection() != style()->isLeftToRightDirection();
+ // Adjust margins for the align attribute
+ if ((!containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_LEFT)
+ || (containingBlockStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_RIGHT)) {
+ if (containingBlockStyle->isLeftToRightDirection() != style()->isLeftToRightDirection()) {
+ if (!marginStartLength.isAuto())
+ marginEndLength = Length(Auto);
+ } else {
+ if (!marginEndLength.isAuto())
+ marginStartLength = Length(Auto);
+ }
+ }
- if ((marginStartLength.isAuto() && marginBoxWidth < availableWidth) || (adjustFromTextAlign && !hasInvertedDirection)) {
- marginEnd = marginEndWidth;
- marginStart = availableWidth - childWidth - marginEnd;
- return;
- }
+ // CSS 2.1: "If there is exactly one value specified as 'auto', its used value follows from the equality."
+ if (marginEndLength.isAuto()) {
+ marginStart = marginStartWidth;
+ marginEnd = availableWidth - childWidth - marginStart;
+ return;
+ }
- if (adjustFromTextAlign && hasInvertedDirection) {
- marginStart = marginStartWidth;
- marginEnd = availableWidth - childWidth - marginStart;
- return;
+ if (marginStartLength.isAuto()) {
+ marginEnd = marginEndWidth;
+ marginStart = availableWidth - childWidth - marginEnd;
+ return;
+ }
}
// Either no auto margins, or our margin box width is >= the container width, auto margins will just turn into 0.
« no previous file with comments | « LayoutTests/tables/mozilla_expected_failures/marvin/table_overflow_td_align_right-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698