Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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; | 2247 LayoutUnit containerLogicalWidthForAutoMargins = containerLogicalWidth; |
| 2248 if (avoidsFloats() && cb->containsFloats()) | 2248 if (avoidsFloats() && cb->containsFloats()) |
| 2249 containerLogicalWidthForAutoMargins = containingBlockAvailableLineWi dth(); | 2249 containerLogicalWidthForAutoMargins = containingBlockAvailableLineWi dth(); |
| 2250 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); | 2250 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); |
| 2251 computeInlineDirectionMargins(cb, containerLogicalWidthForAutoMargins, c omputedValues.m_extent, | 2251 computeInlineDirectionMargins(cb, containerLogicalWidth, containerLogica lWidthForAutoMargins, computedValues.m_extent, |
| 2252 hasInvertedDirection ? computedValues.m_margins.m_end : computedValu es.m_margins.m_start, | 2252 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); | 2253 hasInvertedDirection ? computedValues.m_margins.m_start : computedVa lues.m_margins.m_end); |
| 2254 } | 2254 } |
| 2255 | 2255 |
| 2256 if (!hasPerpendicularContainingBlock && containerLogicalWidth && containerLo gicalWidth != (computedValues.m_extent + computedValues.m_margins.m_start + comp utedValues.m_margins.m_end) | 2256 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()) { | 2257 && !isFloating() && !isInline() && !cb->isFlexibleBoxIncludingDeprecated () && !cb->isRenderGrid()) { |
| 2258 LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb->marginStartForChild(this); | 2258 LayoutUnit newMargin = containerLogicalWidth - computedValues.m_extent - cb->marginStartForChild(this); |
| 2259 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); | 2259 bool hasInvertedDirection = cb->style()->isLeftToRightDirection() != sty le()->isLeftToRightDirection(); |
| 2260 if (hasInvertedDirection) | 2260 if (hasInvertedDirection) |
| 2261 computedValues.m_margins.m_start = newMargin; | 2261 computedValues.m_margins.m_start = newMargin; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2415 | 2415 |
| 2416 return false; | 2416 return false; |
| 2417 } | 2417 } |
| 2418 | 2418 |
| 2419 bool RenderBox::autoWidthShouldFitContent() const | 2419 bool RenderBox::autoWidthShouldFitContent() const |
| 2420 { | 2420 { |
| 2421 return node() && (node()->hasTagName(inputTag) || node()->hasTagName(selectT ag) || node()->hasTagName(buttonTag) | 2421 return node() && (node()->hasTagName(inputTag) || node()->hasTagName(selectT ag) || node()->hasTagName(buttonTag) |
| 2422 || node()->hasTagName(textareaTag) || (node()->hasTagName(legendTag) && !style()->hasOutOfFlowPosition())); | 2422 || node()->hasTagName(textareaTag) || (node()->hasTagName(legendTag) && !style()->hasOutOfFlowPosition())); |
| 2423 } | 2423 } |
| 2424 | 2424 |
| 2425 void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, Layo utUnit containerWidth, LayoutUnit childWidth, LayoutUnit& marginStart, LayoutUni t& marginEnd) const | 2425 void RenderBox::computeInlineDirectionMargins(RenderBlock* containingBlock, Layo utUnit containerWidth, LayoutUnit availableWidth, LayoutUnit childWidth, LayoutU nit& marginStart, LayoutUnit& marginEnd) const |
| 2426 { | 2426 { |
| 2427 const RenderStyle* containingBlockStyle = containingBlock->style(); | 2427 const RenderStyle* containingBlockStyle = containingBlock->style(); |
| 2428 Length marginStartLength = style()->marginStartUsing(containingBlockStyle); | 2428 Length marginStartLength = style()->marginStartUsing(containingBlockStyle); |
| 2429 Length marginEndLength = style()->marginEndUsing(containingBlockStyle); | 2429 Length marginEndLength = style()->marginEndUsing(containingBlockStyle); |
| 2430 | 2430 |
| 2431 if (isFloating() || isInline()) { | 2431 if (isFloating() || isInline()) { |
| 2432 // Inline blocks/tables and floats don't have their margins increased. | 2432 // Inline blocks/tables and floats don't have their margins increased. |
| 2433 marginStart = minimumValueForLength(marginStartLength, containerWidth); | 2433 marginStart = minimumValueForLength(marginStartLength, containerWidth); |
| 2434 marginEnd = minimumValueForLength(marginEndLength, containerWidth); | 2434 marginEnd = minimumValueForLength(marginEndLength, containerWidth); |
| 2435 return; | 2435 return; |
| 2436 } | 2436 } |
| 2437 | 2437 |
| 2438 if (containingBlock->isFlexibleBox()) { | 2438 if (containingBlock->isFlexibleBox()) { |
| 2439 // We need to let flexbox handle the margin adjustment - otherwise, flex box | 2439 // 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. | 2440 // 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 | 2441 // See also http://dev.w3.org/csswg/css-flexbox/#auto-margins |
| 2442 if (marginStartLength.isAuto()) | 2442 if (marginStartLength.isAuto()) |
| 2443 marginStartLength.setValue(0); | 2443 marginStartLength.setValue(0); |
| 2444 if (marginEndLength.isAuto()) | 2444 if (marginEndLength.isAuto()) |
| 2445 marginEndLength.setValue(0); | 2445 marginEndLength.setValue(0); |
| 2446 } | 2446 } |
| 2447 | 2447 |
| 2448 // Case One: The object is being centered in the containing block's availabl e logical width. | 2448 // Case One: The object is being centered in the containing block's availabl e logical width. |
| 2449 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < containerWidth) | 2449 if ((marginStartLength.isAuto() && marginEndLength.isAuto() && childWidth < availableWidth) |
| 2450 || (!marginStartLength.isAuto() && !marginEndLength.isAuto() && containi ngBlock->style()->textAlign() == WEBKIT_CENTER)) { | 2450 || (!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. | 2451 // Other browsers center the margin box for align=center elements so we match them here. |
| 2452 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, c ontainerWidth); | 2452 LayoutUnit marginStartWidth = minimumValueForLength(marginStartLength, c ontainerWidth); |
| 2453 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, conta inerWidth); | 2453 LayoutUnit marginEndWidth = minimumValueForLength(marginEndLength, conta inerWidth); |
| 2454 LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (containerWidth - childWidth - marginStartWidth - marginEndWidth) / 2); | 2454 LayoutUnit centeredMarginBoxStart = max<LayoutUnit>(0, (availableWidth - childWidth - marginStartWidth - marginEndWidth) / 2); |
| 2455 marginStart = centeredMarginBoxStart + marginStartWidth; | 2455 marginStart = centeredMarginBoxStart + marginStartWidth; |
| 2456 marginEnd = containerWidth - childWidth - marginStart + marginEndWidth; | 2456 marginEnd = availableWidth - childWidth - marginStart + marginEndWidth; |
| 2457 return; | 2457 return; |
| 2458 } | 2458 } |
| 2459 | 2459 |
| 2460 // Case Two: The object is being pushed to the start of the containing block 's available logical width. | 2460 // Case Two: The object is being pushed to the start of the containing block 's available logical width. |
| 2461 if (marginEndLength.isAuto() && childWidth < containerWidth) { | 2461 if (marginEndLength.isAuto() && childWidth < availableWidth) { |
| 2462 marginStart = valueForLength(marginStartLength, containerWidth); | 2462 marginStart = valueForLength(marginStartLength, containerWidth); |
| 2463 marginEnd = containerWidth - childWidth - marginStart; | 2463 marginEnd = availableWidth - childWidth - marginStart; |
| 2464 return; | 2464 return; |
| 2465 } | 2465 } |
| 2466 | 2466 |
| 2467 // Case Three: The object is being pushed to the end of the containing block 's available logical width. | 2467 // 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) | 2468 bool pushToEndFromTextAlign = !marginEndLength.isAuto() && ((!containingBloc kStyle->isLeftToRightDirection() && containingBlockStyle->textAlign() == WEBKIT_ LEFT) |
| 2469 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT)); | 2469 || (containingBlockStyle->isLeftToRightDirection() && containingBlockSty le->textAlign() == WEBKIT_RIGHT)); |
| 2470 if ((marginStartLength.isAuto() && childWidth < containerWidth) || pushToEnd FromTextAlign) { | 2470 if ((marginStartLength.isAuto() && childWidth < availableWidth) || pushToEnd FromTextAlign) { |
| 2471 marginEnd = valueForLength(marginEndLength, containerWidth); | 2471 marginEnd = valueForLength(marginEndLength, containerWidth); |
| 2472 marginStart = containerWidth - childWidth - marginEnd; | 2472 marginStart = availableWidth - childWidth - marginEnd; |
| 2473 return; | 2473 return; |
| 2474 } | 2474 } |
| 2475 | 2475 |
| 2476 // Case Four: Either no auto margins, or our width is >= the container width (css2.1, 10.3.3). In that case | 2476 // 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. | 2477 // auto margins will just turn into 0. |
| 2478 marginStart = minimumValueForLength(marginStartLength, containerWidth); | 2478 marginStart = minimumValueForLength(marginStartLength, containerWidth); |
| 2479 marginEnd = minimumValueForLength(marginEndLength, containerWidth); | 2479 marginEnd = minimumValueForLength(marginEndLength, containerWidth); |
| 2480 } | 2480 } |
| 2481 | 2481 |
| 2482 static bool shouldFlipBeforeAfterMargins(const RenderStyle* containingBlockStyle , const RenderStyle* childStyle) | 2482 static bool shouldFlipBeforeAfterMargins(const RenderStyle* containingBlockStyle , const RenderStyle* childStyle) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2538 bool shouldFlipBeforeAfter = cb->style()->writingMode() != style()-> writingMode(); | 2538 bool shouldFlipBeforeAfter = cb->style()->writingMode() != style()-> writingMode(); |
| 2539 computeBlockDirectionMargins(cb, | 2539 computeBlockDirectionMargins(cb, |
| 2540 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : compu tedValues.m_margins.m_before, | 2540 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : compu tedValues.m_margins.m_before, |
| 2541 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : comp utedValues.m_margins.m_after); | 2541 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : comp utedValues.m_margins.m_after); |
| 2542 } | 2542 } |
| 2543 | 2543 |
| 2544 // For tables, calculate margins only. | 2544 // For tables, calculate margins only. |
| 2545 if (isTable()) { | 2545 if (isTable()) { |
| 2546 if (hasPerpendicularContainingBlock) { | 2546 if (hasPerpendicularContainingBlock) { |
| 2547 bool shouldFlipBeforeAfter = shouldFlipBeforeAfterMargins(cb->st yle(), style()); | 2547 bool shouldFlipBeforeAfter = shouldFlipBeforeAfterMargins(cb->st yle(), style()); |
| 2548 computeInlineDirectionMargins(cb, containingBlockLogicalWidthFor Content(), computedValues.m_extent, | 2548 LayoutUnit containerLogicalWidth = containingBlockLogicalWidthFo rContent(); |
|
Julien - ping for review
2014/03/06 23:05:05
I seems weird that we always use containingBlockLo
rune
2014/03/07 14:20:24
Done that now. I also added a layout test showing
| |
| 2549 computeInlineDirectionMargins(cb, containerLogicalWidth, contain erLogicalWidth, computedValues.m_extent, | |
| 2549 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : c omputedValues.m_margins.m_before, | 2550 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : c omputedValues.m_margins.m_before, |
| 2550 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : computedValues.m_margins.m_after); | 2551 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : computedValues.m_margins.m_after); |
| 2551 } | 2552 } |
| 2552 return; | 2553 return; |
| 2553 } | 2554 } |
| 2554 | 2555 |
| 2555 // FIXME: Account for block-flow in flexible boxes. | 2556 // FIXME: Account for block-flow in flexible boxes. |
| 2556 // https://bugs.webkit.org/show_bug.cgi?id=46418 | 2557 // https://bugs.webkit.org/show_bug.cgi?id=46418 |
| 2557 bool inHorizontalBox = parent()->isDeprecatedFlexibleBox() && parent()-> style()->boxOrient() == HORIZONTAL; | 2558 bool inHorizontalBox = parent()->isDeprecatedFlexibleBox() && parent()-> style()->boxOrient() == HORIZONTAL; |
| 2558 bool stretching = parent()->style()->boxAlign() == BSTRETCH; | 2559 bool stretching = parent()->style()->boxAlign() == BSTRETCH; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2591 // been given as an override. Just use that. The value has already been adjusted | 2592 // been given as an override. Just use that. The value has already been adjusted |
| 2592 // for box-sizing. | 2593 // for box-sizing. |
| 2593 ASSERT(h.isFixed()); | 2594 ASSERT(h.isFixed()); |
| 2594 heightResult = h.value() + borderAndPaddingLogicalHeight(); | 2595 heightResult = h.value() + borderAndPaddingLogicalHeight(); |
| 2595 } | 2596 } |
| 2596 | 2597 |
| 2597 computedValues.m_extent = heightResult; | 2598 computedValues.m_extent = heightResult; |
| 2598 | 2599 |
| 2599 if (hasPerpendicularContainingBlock) { | 2600 if (hasPerpendicularContainingBlock) { |
| 2600 bool shouldFlipBeforeAfter = shouldFlipBeforeAfterMargins(cb->style( ), style()); | 2601 bool shouldFlipBeforeAfter = shouldFlipBeforeAfterMargins(cb->style( ), style()); |
| 2601 computeInlineDirectionMargins(cb, containingBlockLogicalWidthForCont ent(), heightResult, | 2602 LayoutUnit containerLogicalWidth = containingBlockLogicalWidthForCon tent(); |
| 2603 computeInlineDirectionMargins(cb, containerLogicalWidth, containerLo gicalWidth, heightResult, | |
| 2602 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : compu tedValues.m_margins.m_before, | 2604 shouldFlipBeforeAfter ? computedValues.m_margins.m_after : compu tedValues.m_margins.m_before, |
| 2603 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : comp utedValues.m_margins.m_after); | 2605 shouldFlipBeforeAfter ? computedValues.m_margins.m_before : comp utedValues.m_margins.m_after); |
| 2604 } | 2606 } |
| 2605 } | 2607 } |
| 2606 | 2608 |
| 2607 // WinIE quirk: The <html> block always fills the entire canvas in quirks mo de. The <body> always fills the | 2609 // WinIE quirk: The <html> block always fills the entire canvas in quirks mo de. The <body> always fills the |
| 2608 // <html> block in quirks mode. Only apply this quirk if the block is norma l flow and no height | 2610 // <html> block in quirks mode. Only apply this quirk if the block is norma l flow and no height |
| 2609 // is specified. When we're printing, we also need this quirk if the body or root has a percentage | 2611 // is specified. When we're printing, we also need this quirk if the body or root has a percentage |
| 2610 // height since we don't set a height in RenderView when we're printing. So without this quirk, the | 2612 // height since we don't set a height in RenderView when we're printing. So without this quirk, the |
| 2611 // height has nothing to be a percentage of, and it ends up being 0. That is bad. | 2613 // height has nothing to be a percentage of, and it ends up being 0. That is bad. |
| (...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4692 return 0; | 4694 return 0; |
| 4693 | 4695 |
| 4694 if (!layoutState && !flowThreadContainingBlock()) | 4696 if (!layoutState && !flowThreadContainingBlock()) |
| 4695 return 0; | 4697 return 0; |
| 4696 | 4698 |
| 4697 RenderBlock* containerBlock = containingBlock(); | 4699 RenderBlock* containerBlock = containingBlock(); |
| 4698 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop(); | 4700 return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop(); |
| 4699 } | 4701 } |
| 4700 | 4702 |
| 4701 } // namespace WebCore | 4703 } // namespace WebCore |
| OLD | NEW |