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

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: Minor fix in a comment Created 6 years, 2 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 2651 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 2662
2663 // Use viewport as container for top-level fixed-position elements. 2663 // Use viewport as container for top-level fixed-position elements.
2664 if (style()->position() == FixedPosition && containingBlock->isRenderView()) { 2664 if (style()->position() == FixedPosition && containingBlock->isRenderView()) {
2665 const RenderView* view = toRenderView(containingBlock); 2665 const RenderView* view = toRenderView(containingBlock);
2666 if (FrameView* frameView = view->frameView()) { 2666 if (FrameView* frameView = view->frameView()) {
2667 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect(); 2667 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect();
2668 return containingBlock->isHorizontalWritingMode() ? viewportRect.wid th() : viewportRect.height(); 2668 return containingBlock->isHorizontalWritingMode() ? viewportRect.wid th() : viewportRect.height();
2669 } 2669 }
2670 } 2670 }
2671 2671
2672 if (hasOverrideContainingBlockLogicalWidth())
2673 return overrideContainingBlockContentLogicalWidth();
2674
2672 if (containingBlock->isBox()) 2675 if (containingBlock->isBox())
2673 return toRenderBox(containingBlock)->clientLogicalWidth(); 2676 return toRenderBox(containingBlock)->clientLogicalWidth();
2674 2677
2675 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ()); 2678 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ());
2676 2679
2677 const RenderInline* flow = toRenderInline(containingBlock); 2680 const RenderInline* flow = toRenderInline(containingBlock);
2678 InlineFlowBox* first = flow->firstLineBox(); 2681 InlineFlowBox* first = flow->firstLineBox();
2679 InlineFlowBox* last = flow->lastLineBox(); 2682 InlineFlowBox* last = flow->lastLineBox();
2680 2683
2681 // If the containing block is empty, return a width of 0. 2684 // If the containing block is empty, return a width of 0.
(...skipping 20 matching lines...) Expand all
2702 2705
2703 // Use viewport as container for top-level fixed-position elements. 2706 // Use viewport as container for top-level fixed-position elements.
2704 if (style()->position() == FixedPosition && containingBlock->isRenderView()) { 2707 if (style()->position() == FixedPosition && containingBlock->isRenderView()) {
2705 const RenderView* view = toRenderView(containingBlock); 2708 const RenderView* view = toRenderView(containingBlock);
2706 if (FrameView* frameView = view->frameView()) { 2709 if (FrameView* frameView = view->frameView()) {
2707 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect(); 2710 LayoutRect viewportRect = frameView->viewportConstrainedVisibleConte ntRect();
2708 return containingBlock->isHorizontalWritingMode() ? viewportRect.hei ght() : viewportRect.width(); 2711 return containingBlock->isHorizontalWritingMode() ? viewportRect.hei ght() : viewportRect.width();
2709 } 2712 }
2710 } 2713 }
2711 2714
2715 if (hasOverrideContainingBlockLogicalHeight())
2716 return overrideContainingBlockContentLogicalHeight();
2717
2712 if (containingBlock->isBox()) { 2718 if (containingBlock->isBox()) {
2713 const RenderBlock* cb = containingBlock->isRenderBlock() ? 2719 const RenderBlock* cb = containingBlock->isRenderBlock() ?
2714 toRenderBlock(containingBlock) : containingBlock->containingBlock(); 2720 toRenderBlock(containingBlock) : containingBlock->containingBlock();
2715 return cb->clientLogicalHeight(); 2721 return cb->clientLogicalHeight();
2716 } 2722 }
2717 2723
2718 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ()); 2724 ASSERT(containingBlock->isRenderInline() && containingBlock->isRelPositioned ());
2719 2725
2720 const RenderInline* flow = toRenderInline(containingBlock); 2726 const RenderInline* flow = toRenderInline(containingBlock);
2721 InlineFlowBox* first = flow->firstLineBox(); 2727 InlineFlowBox* first = flow->firstLineBox();
2722 InlineFlowBox* last = flow->lastLineBox(); 2728 InlineFlowBox* last = flow->lastLineBox();
2723 2729
2724 // If the containing block is empty, return a height of 0. 2730 // If the containing block is empty, return a height of 0.
2725 if (!first || !last) 2731 if (!first || !last)
2726 return 0; 2732 return 0;
2727 2733
2728 LayoutUnit heightResult; 2734 LayoutUnit heightResult;
2729 LayoutRect boundingBox = flow->linesBoundingBox(); 2735 LayoutRect boundingBox = flow->linesBoundingBox();
2730 if (containingBlock->isHorizontalWritingMode()) 2736 if (containingBlock->isHorizontalWritingMode())
2731 heightResult = boundingBox.height(); 2737 heightResult = boundingBox.height();
2732 else 2738 else
2733 heightResult = boundingBox.width(); 2739 heightResult = boundingBox.width();
2734 heightResult -= (containingBlock->borderBefore() + containingBlock->borderAf ter()); 2740 heightResult -= (containingBlock->borderBefore() + containingBlock->borderAf ter());
2735 return heightResult; 2741 return heightResult;
2736 } 2742 }
2737 2743
2744 static LayoutUnit computeInlineStaticPositionForGridItem(Length& logicalLeft, Le ngth& logicalRight, const RenderBox* child, LayoutUnit containerLogicalWidth)
2745 {
2746 ASSERT(child->parent()->isRenderGrid());
Julien - ping for review 2014/11/11 17:27:35 I think this should be child->containingBlock()->i
2747
2748 LayoutUnit staticPosition = 0;
2749 if (child->parent()->style()->direction() == LTR) {
Julien - ping for review 2014/11/11 17:27:35 Same comment.
2750 if (!logicalLeft.isAuto())
2751 staticPosition += valueForLength(logicalLeft, containerLogicalWidth) ;
2752 else if (!logicalRight.isAuto())
2753 staticPosition -= valueForLength(logicalRight, containerLogicalWidth );
2754 } else {
2755 if (!logicalRight.isAuto())
2756 staticPosition += valueForLength(logicalRight, containerLogicalWidth );
2757 else if (!logicalLeft.isAuto())
2758 staticPosition -= valueForLength(logicalLeft, containerLogicalWidth) ;
2759 }
2760 return staticPosition;
2761 }
2762
2738 static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh t, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUni t containerLogicalWidth) 2763 static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh t, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUni t containerLogicalWidth)
2739 { 2764 {
2740 if (!logicalLeft.isAuto() || !logicalRight.isAuto()) 2765 if ((!logicalLeft.isAuto() || !logicalRight.isAuto()) && !child->parent()->i sRenderGrid())
2741 return; 2766 return;
2742 2767
2768 LayoutUnit staticPosition = 0;
2769 if (child->parent()->isRenderGrid())
2770 staticPosition = computeInlineStaticPositionForGridItem(logicalLeft, log icalRight, child, containerLogicalWidth);
2771
2743 // FIXME: The static distance computation has not been patched for mixed wri ting modes yet. 2772 // FIXME: The static distance computation has not been patched for mixed wri ting modes yet.
2744 if (child->parent()->style()->direction() == LTR) { 2773 if (child->parent()->style()->direction() == LTR) {
2745 LayoutUnit staticPosition = child->layer()->staticInlinePosition() - con tainerBlock->borderLogicalLeft(); 2774 staticPosition += child->layer()->staticInlinePosition() - containerBloc k->borderLogicalLeft();
2746 for (RenderObject* curr = child->parent(); curr && curr != containerBloc k; curr = curr->container()) { 2775 for (RenderObject* curr = child->parent(); curr && curr != containerBloc k; curr = curr->container()) {
2747 if (curr->isBox()) { 2776 if (curr->isBox()) {
2748 staticPosition += toRenderBox(curr)->logicalLeft(); 2777 staticPosition += toRenderBox(curr)->logicalLeft();
2749 if (toRenderBox(curr)->isRelPositioned()) 2778 if (toRenderBox(curr)->isRelPositioned())
2750 staticPosition += toRenderBox(curr)->relativePositionOffset( ).width(); 2779 staticPosition += toRenderBox(curr)->relativePositionOffset( ).width();
2751 } else if (curr->isInline()) { 2780 } else if (curr->isInline()) {
2752 if (curr->isRelPositioned()) { 2781 if (curr->isRelPositioned()) {
2753 if (!curr->style()->logicalLeft().isAuto()) 2782 if (!curr->style()->logicalLeft().isAuto())
2754 staticPosition += curr->style()->logicalLeft().value(); 2783 staticPosition += curr->style()->logicalLeft().value();
2755 else 2784 else
2756 staticPosition -= curr->style()->logicalRight().value(); 2785 staticPosition -= curr->style()->logicalRight().value();
2757 } 2786 }
2758 } 2787 }
2759 } 2788 }
2760 logicalLeft.setValue(Fixed, staticPosition); 2789 logicalLeft.setValue(Fixed, staticPosition);
2761 } else { 2790 } else {
2762 RenderBox* enclosingBox = child->parent()->enclosingBox(); 2791 RenderBox* enclosingBox = child->parent()->enclosingBox();
2763 LayoutUnit staticPosition = child->layer()->staticInlinePosition() + con tainerLogicalWidth + containerBlock->borderLogicalLeft(); 2792 staticPosition += child->layer()->staticInlinePosition() + containerLogi calWidth + containerBlock->borderLogicalLeft();
2764 for (RenderObject* curr = child->parent(); curr; curr = curr->container( )) { 2793 for (RenderObject* curr = child->parent(); curr; curr = curr->container( )) {
2765 if (curr->isBox()) { 2794 if (curr->isBox()) {
2766 if (curr != containerBlock) { 2795 if (curr != containerBlock) {
2767 staticPosition -= toRenderBox(curr)->logicalLeft(); 2796 staticPosition -= toRenderBox(curr)->logicalLeft();
2768 if (toRenderBox(curr)->isRelPositioned()) 2797 if (toRenderBox(curr)->isRelPositioned())
2769 staticPosition -= toRenderBox(curr)->relativePositionOff set().width(); 2798 staticPosition -= toRenderBox(curr)->relativePositionOff set().width();
2770 } 2799 }
2771 if (curr == enclosingBox) 2800 if (curr == enclosingBox)
2772 staticPosition -= enclosingBox->logicalWidth(); 2801 staticPosition -= enclosingBox->logicalWidth();
2773 } else if (curr->isInline()) { 2802 } else if (curr->isInline()) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
3096 } 3125 }
3097 3126
3098 if (containerBlock->isBox() && toRenderBox(containerBlock)->scrollsOverflowY () && containerBlock->style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ) { 3127 if (containerBlock->isBox() && toRenderBox(containerBlock)->scrollsOverflowY () && containerBlock->style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ) {
3099 logicalLeftValue = logicalLeftValue + toRenderBox(containerBlock)->verti calScrollbarWidth(); 3128 logicalLeftValue = logicalLeftValue + toRenderBox(containerBlock)->verti calScrollbarWidth();
3100 } 3129 }
3101 3130
3102 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue; 3131 computedValues.m_position = logicalLeftValue + marginLogicalLeftValue;
3103 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth); 3132 computeLogicalLeftPositionedOffset(computedValues.m_position, this, computed Values.m_extent, containerBlock, containerLogicalWidth);
3104 } 3133 }
3105 3134
3106 static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom , const RenderBox* child, const RenderBoxModelObject* containerBlock) 3135 static LayoutUnit computeBlockStaticPositionForGridItem(Length& logicalTop, Leng th& logicalBottom, const RenderBox* child, LayoutUnit containerLogicalHeight)
3107 { 3136 {
3108 if (!logicalTop.isAuto() || !logicalBottom.isAuto()) 3137 ASSERT(child->parent()->isRenderGrid());
3138
3139 LayoutUnit staticPosition = 0;
3140 if (!logicalTop.isAuto())
3141 staticPosition += valueForLength(logicalTop, containerLogicalHeight);
3142 else if (!logicalBottom.isAuto())
3143 staticPosition -= valueForLength(logicalBottom, containerLogicalHeight);
3144 return staticPosition;
3145 }
3146
3147 static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom , const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight)
3148 {
3149 if ((!logicalTop.isAuto() || !logicalBottom.isAuto()) && !child->parent()->i sRenderGrid())
3109 return; 3150 return;
3110 3151
3152 LayoutUnit staticLogicalTop = 0;
3153 if (child->parent()->isRenderGrid())
3154 staticLogicalTop = computeBlockStaticPositionForGridItem(logicalTop, log icalBottom, child, containerLogicalHeight);
3155
3111 // FIXME: The static distance computation has not been patched for mixed wri ting modes. 3156 // FIXME: The static distance computation has not been patched for mixed wri ting modes.
3112 LayoutUnit staticLogicalTop = child->layer()->staticBlockPosition() - contai nerBlock->borderBefore(); 3157 staticLogicalTop += child->layer()->staticBlockPosition() - containerBlock-> borderBefore();
3113 for (RenderObject* curr = child->parent(); curr && curr != containerBlock; c urr = curr->container()) { 3158 for (RenderObject* curr = child->parent(); curr && curr != containerBlock; c urr = curr->container()) {
3114 if (curr->isBox() && !curr->isTableRow()) 3159 if (curr->isBox() && !curr->isTableRow())
3115 staticLogicalTop += toRenderBox(curr)->logicalTop(); 3160 staticLogicalTop += toRenderBox(curr)->logicalTop();
3116 } 3161 }
3117 logicalTop.setValue(Fixed, staticLogicalTop); 3162 logicalTop.setValue(Fixed, staticLogicalTop);
3118 } 3163 }
3119 3164
3120 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const 3165 void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp utedValues) const
3121 { 3166 {
3122 if (isReplaced()) { 3167 if (isReplaced()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3155 * But rather than actually calculating the dimensions of that hypothetical 3200 * But rather than actually calculating the dimensions of that hypothetical
3156 * box, user agents are free to make a guess at its probable position. 3201 * box, user agents are free to make a guess at its probable position.
3157 * 3202 *
3158 * For the purposes of calculating the static position, the containing block 3203 * For the purposes of calculating the static position, the containing block
3159 * of fixed positioned elements is the initial containing block instead of 3204 * of fixed positioned elements is the initial containing block instead of
3160 * the viewport. 3205 * the viewport.
3161 \*-------------------------------------------------------------------------- -*/ 3206 \*-------------------------------------------------------------------------- -*/
3162 3207
3163 // see FIXME 1 3208 // see FIXME 1
3164 // Calculate the static distance if needed. 3209 // Calculate the static distance if needed.
3165 computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, cont ainerBlock); 3210 computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, cont ainerBlock, containerLogicalHeight);
3166 3211
3167 // Calculate constraint equation values for 'height' case. 3212 // Calculate constraint equation values for 'height' case.
3168 LayoutUnit logicalHeight = computedValues.m_extent; 3213 LayoutUnit logicalHeight = computedValues.m_extent;
3169 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight, 3214 computePositionedLogicalHeightUsing(styleToUse->logicalHeight(), containerBl ock, containerLogicalHeight, bordersPlusPadding, logicalHeight,
3170 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter, 3215 logicalTopLength, logicalBottomLength, m arginBefore, marginAfter,
3171 computedValues); 3216 computedValues);
3172 3217
3173 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults). 3218 // Avoid doing any work in the common case (where the values of min-height a nd max-height are their defaults).
3174 // see FIXME 2 3219 // see FIXME 2
3175 3220
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
3561 // are dealt with in computeReplacedHeight(). This means that the steps to produce 3606 // are dealt with in computeReplacedHeight(). This means that the steps to produce
3562 // correct max/min in the non-replaced version, are not necessary. 3607 // correct max/min in the non-replaced version, are not necessary.
3563 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight(); 3608 computedValues.m_extent = computeReplacedLogicalHeight() + borderAndPaddingL ogicalHeight();
3564 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent; 3609 const LayoutUnit availableSpace = containerLogicalHeight - computedValues.m_ extent;
3565 3610
3566 /*-----------------------------------------------------------------------*\ 3611 /*-----------------------------------------------------------------------*\
3567 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top' 3612 * 2. If both 'top' and 'bottom' have the value 'auto', replace 'top'
3568 * with the element's static position. 3613 * with the element's static position.
3569 \*-----------------------------------------------------------------------*/ 3614 \*-----------------------------------------------------------------------*/
3570 // see FIXME 1 3615 // see FIXME 1
3571 computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock); 3616 computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock, containerLogicalHeight);
3572 3617
3573 /*-----------------------------------------------------------------------*\ 3618 /*-----------------------------------------------------------------------*\
3574 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or 3619 * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or
3575 * 'margin-bottom' with '0'. 3620 * 'margin-bottom' with '0'.
3576 \*-----------------------------------------------------------------------*/ 3621 \*-----------------------------------------------------------------------*/
3577 // FIXME: The spec. says that this step should only be taken when bottom is 3622 // FIXME: The spec. says that this step should only be taken when bottom is
3578 // auto, but if only top is auto, this makes step 4 impossible. 3623 // auto, but if only top is auto, this makes step 4 impossible.
3579 if (logicalTop.isAuto() || logicalBottom.isAuto()) { 3624 if (logicalTop.isAuto() || logicalBottom.isAuto()) {
3580 if (marginBefore.isAuto()) 3625 if (marginBefore.isAuto())
3581 marginBefore.setValue(Fixed, 0); 3626 marginBefore.setValue(Fixed, 0);
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
4509 ASSERT(style()->hasBackground() || style()->hasBoxDecorations()); 4554 ASSERT(style()->hasBackground() || style()->hasBoxDecorations());
4510 4555
4511 if (m_rareData && m_rareData->m_previousBorderBoxSize.width() != -1) 4556 if (m_rareData && m_rareData->m_previousBorderBoxSize.width() != -1)
4512 return m_rareData->m_previousBorderBoxSize; 4557 return m_rareData->m_previousBorderBoxSize;
4513 4558
4514 // We didn't save the old border box size because it was the same as the siz e of oldBounds. 4559 // We didn't save the old border box size because it was the same as the siz e of oldBounds.
4515 return previousBoundsSize; 4560 return previousBoundsSize;
4516 } 4561 }
4517 4562
4518 } // namespace blink 4563 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698