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

Side by Side Diff: Source/core/rendering/RenderBox.cpp

Issue 637033003: [CSS Grid Layout] Fix positioned grid children position and size (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove "if else" Created 6 years, 1 month 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 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 2610
2611 // Use viewport as container for top-level fixed-position elements. 2611 // Use viewport as container for top-level fixed-position elements.
2612 if (style()->position() == FixedPosition && containingBlock->isRenderView()) { 2612 if (style()->position() == FixedPosition && containingBlock->isRenderView()) {
2613 const RenderView* view = toRenderView(containingBlock); 2613 const RenderView* view = toRenderView(containingBlock);
2614 if (FrameView* frameView = view->frameView()) { 2614 if (FrameView* frameView = view->frameView()) {
2615 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect(); 2615 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect();
2616 return containingBlock->isHorizontalWritingMode() ? viewportRect.wid th() : viewportRect.height(); 2616 return containingBlock->isHorizontalWritingMode() ? viewportRect.wid th() : viewportRect.height();
2617 } 2617 }
2618 } 2618 }
2619 2619
2620 if (hasOverrideContainingBlockLogicalWidth())
2621 return overrideContainingBlockContentLogicalWidth();
2622
2620 if (containingBlock->isBox()) 2623 if (containingBlock->isBox())
2621 return toRenderBox(containingBlock)->clientLogicalWidth(); 2624 return toRenderBox(containingBlock)->clientLogicalWidth();
2622 2625
2623 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ()); 2626 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ());
2624 2627
2625 const RenderInline* flow = toRenderInline(containingBlock); 2628 const RenderInline* flow = toRenderInline(containingBlock);
2626 InlineFlowBox* first = flow->firstLineBox(); 2629 InlineFlowBox* first = flow->firstLineBox();
2627 InlineFlowBox* last = flow->lastLineBox(); 2630 InlineFlowBox* last = flow->lastLineBox();
2628 2631
2629 // If the containing block is empty, return a width of 0. 2632 // If the containing block is empty, return a width of 0.
(...skipping 20 matching lines...) Expand all
2650 2653
2651 // Use viewport as container for top-level fixed-position elements. 2654 // Use viewport as container for top-level fixed-position elements.
2652 if (style()->position() == FixedPosition && containingBlock->isRenderView()) { 2655 if (style()->position() == FixedPosition && containingBlock->isRenderView()) {
2653 const RenderView* view = toRenderView(containingBlock); 2656 const RenderView* view = toRenderView(containingBlock);
2654 if (FrameView* frameView = view->frameView()) { 2657 if (FrameView* frameView = view->frameView()) {
2655 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect(); 2658 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect();
2656 return containingBlock->isHorizontalWritingMode() ? viewportRect.hei ght() : viewportRect.width(); 2659 return containingBlock->isHorizontalWritingMode() ? viewportRect.hei ght() : viewportRect.width();
2657 } 2660 }
2658 } 2661 }
2659 2662
2663 if (hasOverrideContainingBlockLogicalHeight())
2664 return overrideContainingBlockContentLogicalHeight();
2665
2660 if (containingBlock->isBox()) { 2666 if (containingBlock->isBox()) {
2661 const RenderBlock* cb = containingBlock->isRenderBlock() ? 2667 const RenderBlock* cb = containingBlock->isRenderBlock() ?
2662 toRenderBlock(containingBlock) : containingBlock->containingBlock(); 2668 toRenderBlock(containingBlock) : containingBlock->containingBlock();
2663 return cb->clientLogicalHeight(); 2669 return cb->clientLogicalHeight();
2664 } 2670 }
2665 2671
2666 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ()); 2672 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ());
2667 2673
2668 const RenderInline* flow = toRenderInline(containingBlock); 2674 const RenderInline* flow = toRenderInline(containingBlock);
2669 InlineFlowBox* first = flow->firstLineBox(); 2675 InlineFlowBox* first = flow->firstLineBox();
2670 InlineFlowBox* last = flow->lastLineBox(); 2676 InlineFlowBox* last = flow->lastLineBox();
2671 2677
2672 // If the containing block is empty, return a height of 0. 2678 // If the containing block is empty, return a height of 0.
2673 if (!first || !last) 2679 if (!first || !last)
2674 return 0; 2680 return 0;
2675 2681
2676 LayoutUnit heightResult; 2682 LayoutUnit heightResult;
2677 LayoutRect boundingBox = flow->linesBoundingBox(); 2683 LayoutRect boundingBox = flow->linesBoundingBox();
2678 if (containingBlock->isHorizontalWritingMode()) 2684 if (containingBlock->isHorizontalWritingMode())
2679 heightResult = boundingBox.height(); 2685 heightResult = boundingBox.height();
2680 else 2686 else
2681 heightResult = boundingBox.width(); 2687 heightResult = boundingBox.width();
2682 heightResult -= (containingBlock->borderBefore() + containingBlock->borderAf ter()); 2688 heightResult -= (containingBlock->borderBefore() + containingBlock->borderAf ter());
2683 return heightResult; 2689 return heightResult;
2684 } 2690 }
2685 2691
2692 static LayoutUnit computeInlineStaticPositionForGridChild(Length& logicalLeft, L ength& logicalRight, const RenderBox* child, const RenderBoxModelObject* contain erBlock, LayoutUnit containerLogicalWidth)
2693 {
2694 ASSERT(containerBlock->isRenderGrid());
2695 LayoutUnit staticPosition = 0;
2696
2697 if (containerBlock->style()->direction() == LTR) {
2698 if (!logicalLeft.isAuto())
2699 staticPosition += valueForLength(logicalLeft, containerLogicalWidth) ;
2700 else if (!logicalRight.isAuto())
2701 staticPosition -= valueForLength(logicalRight, containerLogicalWidth );
2702 } else {
2703 if (!logicalRight.isAuto())
2704 staticPosition += valueForLength(logicalRight, containerLogicalWidth );
2705 else if (!logicalLeft.isAuto())
2706 staticPosition -= valueForLength(logicalLeft, containerLogicalWidth) ;
2707 }
2708 return staticPosition;
2709 }
2710
2686 static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh t, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUni t containerLogicalWidth) 2711 static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh t, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUni t containerLogicalWidth)
2687 { 2712 {
2688 if (!logicalLeft.isAuto() || !logicalRight.isAuto()) 2713 if ((!logicalLeft.isAuto() || !logicalRight.isAuto()) && (!containerBlock->i sRenderGrid() || (containerBlock->isRenderGrid() && child->style()->gridColumnSt art().isAuto())))
2689 return; 2714 return;
2690 2715
2716 LayoutUnit staticPosition = 0;
2717 if (containerBlock->isRenderGrid())
2718 staticPosition = computeInlineStaticPositionForGridChild(logicalLeft, lo gicalRight, child, containerBlock, containerLogicalWidth);
2719
2691 // FIXME: The static distance computation has not been patched for mixed wri ting modes yet. 2720 // FIXME: The static distance computation has not been patched for mixed wri ting modes yet.
2692 if (child->parent()->style()->direction() == LTR) { 2721 if (child->parent()->style()->direction() == LTR) {
2693 LayoutUnit staticPosition = child->layer()->staticInlinePosition() - con tainerBlock->borderLogicalLeft(); 2722 staticPosition += child->layer()->staticInlinePosition() - containerBloc k->borderLogicalLeft();
2694 for (RenderObject* curr = child->parent(); curr && curr != containerBloc k; curr = curr->container()) { 2723 for (RenderObject* curr = child->parent(); curr && curr != containerBloc k; curr = curr->container()) {
2695 if (curr->isBox()) { 2724 if (curr->isBox()) {
2696 staticPosition += toRenderBox(curr)->logicalLeft(); 2725 staticPosition += toRenderBox(curr)->logicalLeft();
2697 if (toRenderBox(curr)->isRelPositioned()) 2726 if (toRenderBox(curr)->isRelPositioned())
2698 staticPosition += toRenderBox(curr)->relativePositionOffset( ).width(); 2727 staticPosition += toRenderBox(curr)->relativePositionOffset( ).width();
2699 } else if (curr->isInline()) { 2728 } else if (curr->isInline()) {
2700 if (curr->isRelPositioned()) { 2729 if (curr->isRelPositioned()) {
2701 if (!curr->style()->logicalLeft().isAuto()) 2730 if (!curr->style()->logicalLeft().isAuto())
2702 staticPosition += curr->style()->logicalLeft().value(); 2731 staticPosition += curr->style()->logicalLeft().value();
2703 else 2732 else
2704 staticPosition -= curr->style()->logicalRight().value(); 2733 staticPosition -= curr->style()->logicalRight().value();
2705 } 2734 }
2706 } 2735 }
2707 } 2736 }
2708 logicalLeft.setValue(Fixed, staticPosition); 2737 logicalLeft.setValue(Fixed, staticPosition);
2709 } else { 2738 } else {
2710 RenderBox* enclosingBox = child->parent()->enclosingBox(); 2739 RenderBox* enclosingBox = child->parent()->enclosingBox();
2711 LayoutUnit staticPosition = child->layer()->staticInlinePosition() + con tainerLogicalWidth + containerBlock->borderLogicalLeft(); 2740 staticPosition += child->layer()->staticInlinePosition() + containerLogi calWidth + containerBlock->borderLogicalLeft();
2712 for (RenderObject* curr = child->parent(); curr; curr = curr->container( )) { 2741 for (RenderObject* curr = child->parent(); curr; curr = curr->container( )) {
2713 if (curr->isBox()) { 2742 if (curr->isBox()) {
2714 if (curr != containerBlock) { 2743 if (curr != containerBlock) {
2715 staticPosition -= toRenderBox(curr)->logicalLeft(); 2744 staticPosition -= toRenderBox(curr)->logicalLeft();
2716 if (toRenderBox(curr)->isRelPositioned()) 2745 if (toRenderBox(curr)->isRelPositioned())
2717 staticPosition -= toRenderBox(curr)->relativePositionOff set().width(); 2746 staticPosition -= toRenderBox(curr)->relativePositionOff set().width();
2718 } 2747 }
2719 if (curr == enclosingBox) 2748 if (curr == enclosingBox)
2720 staticPosition -= enclosingBox->logicalWidth(); 2749 staticPosition -= enclosingBox->logicalWidth();
2721 } else if (curr->isInline()) { 2750 } else if (curr->isInline()) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
3044 } 3073 }
3045 3074
3046 if (containerBlock->isBox() && toRenderBox(containerBlock)->scrollsOverflowY () && containerBlock->style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ) { 3075 if (containerBlock->isBox() && toRenderBox(containerBlock)->scrollsOverflowY () && containerBlock->style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ) {
3047 logicalLeftValue = logicalLeftValue + toRenderBox(containerBlock)->verti calScrollbarWidth(); 3076 logicalLeftValue = logicalLeftValue + toRenderBox(containerBlock)->verti calScrollbarWidth();
3048 } 3077 }
3049 3078
3050 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue; 3079 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue;
3051 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth); 3080 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth);
3052 } 3081 }
3053 3082
3054 static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom , const RenderBox* child, const RenderBoxModelObject* containerBlock) 3083 static LayoutUnit computeBlockStaticPositionForGridItem(Length& logicalTop, Leng th& logicalBottom, const RenderBox* child, const RenderBoxModelObject* container Block, LayoutUnit containerLogicalHeight)
3055 { 3084 {
3056 if (!logicalTop.isAuto() || !logicalBottom.isAuto()) 3085 ASSERT(containerBlock->isRenderGrid());
3086
3087 LayoutUnit staticPosition = 0;
3088 if (!logicalTop.isAuto())
3089 staticPosition += valueForLength(logicalTop, containerLogicalHeight);
3090 else if (!logicalBottom.isAuto())
Julien - ping for review 2014/11/24 21:44:40 Shoudn't we remove the logical bottom even if we h
Manuel Rego 2014/12/01 11:10:36 Yeah, thanks for your comment. I was testing this
3091 staticPosition -= valueForLength(logicalBottom, containerLogicalHeight);
3092 return staticPosition;
3093 }
3094
3095 static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom , const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight)
3096 {
3097 if ((!logicalTop.isAuto() || !logicalBottom.isAuto()) && (!containerBlock->i sRenderGrid() || (containerBlock->isRenderGrid() && child->style()->gridRowStart ().isAuto())))
3057 return; 3098 return;
3058 3099
3100 LayoutUnit staticLogicalTop = 0;
3101 if (containerBlock->isRenderGrid())
3102 staticLogicalTop = computeBlockStaticPositionForGridItem(logicalTop, log icalBottom, child, containerBlock, containerLogicalHeight);
3103
3059 // FIXME: The static distance computation has not been patched for mixed wri ting modes. 3104 // FIXME: The static distance computation has not been patched for mixed wri ting modes.
3060 LayoutUnit staticLogicalTop = child->layer()->staticBlockPosition() - contai nerBlock->borderBefore(); 3105 staticLogicalTop += child->layer()->staticBlockPosition() - containerBlock-> borderBefore();
3061 for (RenderObject* curr = child->parent(); curr && curr != containerBlock; c urr = curr->container()) { 3106 for (RenderObject* curr = child->parent(); curr && curr != containerBlock; c urr = curr->container()) {
3062 if (curr->isBox() && !curr->isTableRow()) 3107 if (curr->isBox() && !curr->isTableRow())
3063 staticLogicalTop += toRenderBox(curr)->logicalTop(); 3108 staticLogicalTop += toRenderBox(curr)->logicalTop();
3064 } 3109 }
3065 logicalTop.setValue(Fixed, staticLogicalTop); 3110 logicalTop.setValue(Fixed, staticLogicalTop);
3066 } 3111 }
3067 3112
3068 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const 3113 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const
3069 { 3114 {
3070 if (isReplaced()) { 3115 if (isReplaced()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 * But rather than actually calculating the dimensions of that hypothetical 3148 * But rather than actually calculating the dimensions of that hypothetical
3104 * box, user agents are free to make a guess at its probable position. 3149 * box, user agents are free to make a guess at its probable position.
3105 * 3150 *
3106 * For the purposes of calculating the static position, the containing block 3151 * For the purposes of calculating the static position, the containing block
3107 * of fixed positioned elements is the initial containing block instead of 3152 * of fixed positioned elements is the initial containing block instead of
3108 * the viewport. 3153 * the viewport.
3109 \*-------------------------------------------------------------------------- -*/ 3154 \*-------------------------------------------------------------------------- -*/
3110 3155
3111 // see FIXME 1 3156 // see FIXME 1
3112 // Calculate the static distance if needed. 3157 // Calculate the static distance if needed.
3113 computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, cont ainerBlock); 3158 computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, cont ainerBlock, containerLogicalHeight);
3114 3159
3115 // Calculate constraint equation values for 'height' case. 3160 // Calculate constraint equation values for 'height' case.
3116 LayoutUnit logicalHeight = computedValues.m_extent; 3161 LayoutUnit logicalHeight = computedValues.m_extent;
3117 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight, 3162 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight,
3118 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter, 3163 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter,
3119 computedValues); 3164 computedValues);
3120 3165
3121 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults). 3166 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults).
3122 // see FIXME 2 3167 // see FIXME 2
3123 3168
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
3509 // are dealt with in computeReplacedHeight(). This means that the steps to produce 3554 // are dealt with in computeReplacedHeight(). This means that the steps to produce
3510 // correct max/min in the non-replaced version, are not necessary. 3555 // correct max/min in the non-replaced version, are not necessary.
3511 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight(); 3556 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight();
3512 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent; 3557 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent;
3513 3558
3514 /*-----------------------------------------------------------------------*\ 3559 /*-----------------------------------------------------------------------*\
3515 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top' 3560 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top'
3516 * with the element's static position. 3561 * with the element's static position.
3517 \*-----------------------------------------------------------------------*/ 3562 \*-----------------------------------------------------------------------*/
3518 // see FIXME 1 3563 // see FIXME 1
3519 computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock); 3564 computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock, containerLogicalHeight);
3520 3565
3521 /*-----------------------------------------------------------------------*\ 3566 /*-----------------------------------------------------------------------*\
3522 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or 3567 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or
3523 * 'margin-bottom' with '0'. 3568 * 'margin-bottom' with '0'.
3524 \*-----------------------------------------------------------------------*/ 3569 \*-----------------------------------------------------------------------*/
3525 // FIXME: The spec. says that this step should only be taken when bottom is 3570 // FIXME: The spec. says that this step should only be taken when bottom is
3526 // auto, but if only top is auto, this makes step 4 impossible. 3571 // auto, but if only top is auto, this makes step 4 impossible.
3527 if (logicalTop.isAuto() || logicalBottom.isAuto()) { 3572 if (logicalTop.isAuto() || logicalBottom.isAuto()) {
3528 if (marginBefore.isAuto()) 3573 if (marginBefore.isAuto())
3529 marginBefore.setValue(Fixed, 0); 3574 marginBefore.setValue(Fixed, 0);
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
4439 4484
4440 setLogicalTop(oldLogicalTop); 4485 setLogicalTop(oldLogicalTop);
4441 setLogicalWidth(oldLogicalWidth); 4486 setLogicalWidth(oldLogicalWidth);
4442 setMarginLeft(oldMarginLeft); 4487 setMarginLeft(oldMarginLeft);
4443 setMarginRight(oldMarginRight); 4488 setMarginRight(oldMarginRight);
4444 4489
4445 return borderBox; 4490 return borderBox;
4446 } 4491 }
4447 4492
4448 } // namespace blink 4493 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698