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

Side by Side 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 unified diff | Download patch
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 2226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 containerWidthInInlineDirection = perpendicularContainingBlockLogica lHeight(); 2237 containerWidthInInlineDirection = perpendicularContainingBlockLogica lHeight();
2238 LayoutUnit preferredWidth = computeLogicalWidthUsing(MainOrPreferredSize , styleToUse->logicalWidth(), containerWidthInInlineDirection, cb); 2238 LayoutUnit preferredWidth = computeLogicalWidthUsing(MainOrPreferredSize , styleToUse->logicalWidth(), containerWidthInInlineDirection, cb);
2239 computedValues.m_extent = constrainLogicalWidthByMinMax(preferredWidth, containerWidthInInlineDirection, cb); 2239 computedValues.m_extent = constrainLogicalWidthByMinMax(preferredWidth, containerWidthInInlineDirection, cb);
2240 } 2240 }
2241 2241
2242 // Margin calculations. 2242 // Margin calculations.
2243 if (hasPerpendicularContainingBlock || isFloating() || isInline()) { 2243 if (hasPerpendicularContainingBlock || isFloating() || isInline()) {
2244 computedValues.m_margins.m_start = minimumValueForLength(styleToUse->mar ginStart(), containerLogicalWidth); 2244 computedValues.m_margins.m_start = minimumValueForLength(styleToUse->mar ginStart(), containerLogicalWidth);
2245 computedValues.m_margins.m_end = minimumValueForLength(styleToUse->margi nEnd(), containerLogicalWidth); 2245 computedValues.m_margins.m_end = minimumValueForLength(styleToUse->margi nEnd(), containerLogicalWidth);
2246 } else { 2246 } else {
2247 LayoutUnit containerLogicalWidthForAutoMargins = containerLogicalWidth;
2248 if (avoidsFloats() && cb->containsFloats())
2249 containerLogicalWidthForAutoMargins = containingBlockAvailableLineWi dth();
2250 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); 2247 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection();
2251 computeInlineDirectionMargins(cb, containerLogicalWidthForAutoMargins, c omputedValues.m_extent, 2248 computeInlineDirectionMargins(cb, containerLogicalWidth, computedValues. m_extent,
2252 hasInvertedDirection ? computedValues.m_margins.m_end : computedValu es.m_margins.m_start, 2249 hasInvertedDirection ? computedValues.m_margins.m_end : computedValu es.m_margins.m_start,
2253 hasInvertedDirection ? computedValues.m_margins.m_start : computedVa lues.m_margins.m_end); 2250 hasInvertedDirection ? computedValues.m_margins.m_start : computedVa lues.m_margins.m_end);
2254 } 2251 }
2255 2252
2256 if (!hasPerpendicularContainingBlock && containerLogicalWidth && containerLo gicalWidth != (computedValues.m_extent + computedValues.m_margins.m_start + comp utedValues.m_margins.m_end) 2253 if (!hasPerpendicularContainingBlock && containerLogicalWidth && containerLo gicalWidth != (computedValues.m_extent + computedValues.m_margins.m_start + comp utedValues.m_margins.m_end)
2257 && !isFloating() && !isInline() && !cb->isFlexibleBoxIncludingDeprecated () && !cb->isRenderGrid()) { 2254 && !isFloating() && !isInline() && !cb->isFlexibleBoxIncludingDeprecated () && !cb->isRenderGrid()) {
2258 LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb->marginStartForChild(this); 2255 LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb->marginStartForChild(this);
2259 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); 2256 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection();
2260 if (hasInvertedDirection) 2257 if (hasInvertedDirection)
2261 computedValues.m_margins.m_start = newMargin; 2258 computedValues.m_margins.m_start = newMargin;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 if (containingBlock->isFlexibleBox()) { 2435 if (containingBlock->isFlexibleBox()) {
2439 // We need to let flexbox handle the margin adjustment - otherwise, flex box 2436 // We need to let flexbox handle the margin adjustment - otherwise, flex box
2440 // will think we're wider than we actually are and calculate line sizes wrong. 2437 // will think we're wider than we actually are and calculate line sizes wrong.
2441 // See also http://dev.w3.org/csswg/css-flexbox/#auto-margins 2438 // See also http://dev.w3.org/csswg/css-flexbox/#auto-margins
2442 if (marginStartLength.isAuto()) 2439 if (marginStartLength.isAuto())
2443 marginStartLength.setValue(0); 2440 marginStartLength.setValue(0);
2444 if (marginEndLength.isAuto()) 2441 if (marginEndLength.isAuto())
2445 marginEndLength.setValue(0); 2442 marginEndLength.setValue(0);
2446 } 2443 }
2447 2444
2445 LayoutUnit availableWidth = containerWidth;
2446 if (avoidsFloats() && containingBlock->containsFloats())
2447 availableWidth = containingBlockAvailableLineWidth();
2448
2448 // Case One: The object is being centered in the containing block's availabl e logical width. 2449 // Case One: The object is being centered in the containing block's availabl e logical width.
2449 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < containerWidth) 2450 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < availableWidth)
2450 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlock->style()->textAlign() == WEBKIT_CENTER)) { 2451 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlock->style()->textAlign() == WEBKIT_CENTER)) {
2451 // Other browsers center the margin box for align=center elements so we match them here. 2452 // Other browsers center the margin box for align=center elements so we match them here.
2452 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, c ontainerWidth); 2453 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, c ontainerWidth);
2453 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, conta inerWidth); 2454 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, conta inerWidth);
2454 LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (containerWidth - childWidth - marginStartWidth - marginEndWidth) / 2); 2455 LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (availableWidth - childWidth - marginStartWidth - marginEndWidth) / 2);
2455 marginStart = centeredMarginBoxStart + marginStartWidth; 2456 marginStart = centeredMarginBoxStart + marginStartWidth;
2456 marginEnd = containerWidth - childWidth - marginStart + marginEndWidth; 2457 marginEnd = availableWidth - childWidth - marginStart + marginEndWidth;
2457 return; 2458 return;
2458 } 2459 }
2459 2460
2460 // Case Two: The object is being pushed to the start of the containing block 's available logical width. 2461 // Case Two: The object is being pushed to the start of the containing block 's available logical width.
2461 if (marginEndLength.isAuto() && childWidth < containerWidth) { 2462 if (marginEndLength.isAuto() && childWidth < availableWidth) {
2462 marginStart = valueForLength(marginStartLength, containerWidth); 2463 marginStart = valueForLength(marginStartLength, containerWidth);
2463 marginEnd = containerWidth - childWidth - marginStart; 2464 marginEnd = availableWidth - childWidth - marginStart;
2464 return; 2465 return;
2465 } 2466 }
2466 2467
2467 // Case Three: The object is being pushed to the end of the containing block 's available logical width. 2468 // Case Three: The object is being pushed to the end of the containing block 's available logical width.
2468 bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBloc kStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_ LEFT) 2469 bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBloc kStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_ LEFT)
2469 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT)); 2470 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT));
2470 if ((marginStartLength.isAuto() && childWidth < containerWidth) || pushToEnd FromTextAlign) { 2471 if ((marginStartLength.isAuto() && childWidth < availableWidth) || pushToEnd FromTextAlign) {
2471 marginEnd = valueForLength(marginEndLength, containerWidth); 2472 marginEnd = valueForLength(marginEndLength, containerWidth);
2472 marginStart = containerWidth - childWidth - marginEnd; 2473 marginStart = availableWidth - childWidth - marginEnd;
2473 return; 2474 return;
2474 } 2475 }
2475 2476
2476 // Case Four: Either no auto margins, or our width is >= the container width (css2.1, 10.3.3). In that case 2477 // Case Four: Either no auto margins, or our width is >= the container width (css2.1, 10.3.3). In that case
2477 // auto margins will just turn into 0. 2478 // auto margins will just turn into 0.
2478 marginStart = minimumValueForLength(marginStartLength, containerWidth); 2479 marginStart = minimumValueForLength(marginStartLength, containerWidth);
2479 marginEnd = minimumValueForLength(marginEndLength, containerWidth); 2480 marginEnd = minimumValueForLength(marginEndLength, containerWidth);
2480 } 2481 }
2481 2482
2482 static bool shouldFlipBeforeAfterMargins(const RenderStyle* containingBlockStyle , const RenderStyle* childStyle) 2483 static bool shouldFlipBeforeAfterMargins(const RenderStyle* containingBlockStyle , const RenderStyle* childStyle)
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after
4692 return 0; 4693 return 0;
4693 4694
4694 if (!layoutState && !flowThreadContainingBlock()) 4695 if (!layoutState && !flowThreadContainingBlock())
4695 return 0; 4696 return 0;
4696 4697
4697 RenderBlock* containerBlock = containingBlock(); 4698 RenderBlock* containerBlock = containingBlock();
4698 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop(); 4699 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop();
4699 } 4700 }
4700 4701
4701 } // namespace WebCore 4702 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698