| Index: Source/core/rendering/RenderBox.cpp | 
| diff --git a/Source/core/rendering/RenderBox.cpp b/Source/core/rendering/RenderBox.cpp | 
| index 7e63fe333b7890e7e5c48a84f0ad34a67eb493fb..a9836c79a1e1e0e6b0fc801d72ed7547e61b086e 100644 | 
| --- a/Source/core/rendering/RenderBox.cpp | 
| +++ b/Source/core/rendering/RenderBox.cpp | 
| @@ -2617,6 +2617,9 @@ LayoutUnit RenderBox::containingBlockLogicalWidthForPositioned(const RenderBoxMo | 
| } | 
| } | 
|  | 
| +    if (hasOverrideContainingBlockLogicalWidth()) | 
| +        return overrideContainingBlockContentLogicalWidth(); | 
| + | 
| if (containingBlock->isBox()) | 
| return toRenderBox(containingBlock)->clientLogicalWidth(); | 
|  | 
| @@ -2657,6 +2660,9 @@ LayoutUnit RenderBox::containingBlockLogicalHeightForPositioned(const RenderBoxM | 
| } | 
| } | 
|  | 
| +    if (hasOverrideContainingBlockLogicalHeight()) | 
| +        return overrideContainingBlockContentLogicalHeight(); | 
| + | 
| if (containingBlock->isBox()) { | 
| const RenderBlock* cb = containingBlock->isRenderBlock() ? | 
| toRenderBlock(containingBlock) : containingBlock->containingBlock(); | 
| @@ -2683,14 +2689,37 @@ LayoutUnit RenderBox::containingBlockLogicalHeightForPositioned(const RenderBoxM | 
| return heightResult; | 
| } | 
|  | 
| +static LayoutUnit computeInlineStaticPositionForGridChild(Length& logicalLeft, Length& logicalRight, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth) | 
| +{ | 
| +    ASSERT(containerBlock->isRenderGrid()); | 
| +    LayoutUnit staticPosition = 0; | 
| + | 
| +    if (containerBlock->style()->direction() == LTR) { | 
| +        if (!logicalLeft.isAuto()) | 
| +            staticPosition += valueForLength(logicalLeft, containerLogicalWidth); | 
| +        else if (!logicalRight.isAuto()) | 
| +            staticPosition -= valueForLength(logicalRight, containerLogicalWidth); | 
| +    } else { | 
| +        if (!logicalRight.isAuto()) | 
| +            staticPosition += valueForLength(logicalRight, containerLogicalWidth); | 
| +        else if (!logicalLeft.isAuto()) | 
| +            staticPosition -= valueForLength(logicalLeft, containerLogicalWidth); | 
| +    } | 
| +    return staticPosition; | 
| +} | 
| + | 
| static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRight, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalWidth) | 
| { | 
| -    if (!logicalLeft.isAuto() || !logicalRight.isAuto()) | 
| +    if ((!logicalLeft.isAuto() || !logicalRight.isAuto()) && (!containerBlock->isRenderGrid() || (containerBlock->isRenderGrid() && child->style()->gridColumnStart().isAuto()))) | 
| return; | 
|  | 
| +    LayoutUnit staticPosition = 0; | 
| +    if (containerBlock->isRenderGrid()) | 
| +        staticPosition = computeInlineStaticPositionForGridChild(logicalLeft, logicalRight, child, containerBlock, containerLogicalWidth); | 
| + | 
| // FIXME: The static distance computation has not been patched for mixed writing modes yet. | 
| if (child->parent()->style()->direction() == LTR) { | 
| -        LayoutUnit staticPosition = child->layer()->staticInlinePosition() - containerBlock->borderLogicalLeft(); | 
| +        staticPosition += child->layer()->staticInlinePosition() - containerBlock->borderLogicalLeft(); | 
| for (RenderObject* curr = child->parent(); curr && curr != containerBlock; curr = curr->container()) { | 
| if (curr->isBox()) { | 
| staticPosition += toRenderBox(curr)->logicalLeft(); | 
| @@ -2708,7 +2737,7 @@ static void computeInlineStaticDistance(Length& logicalLeft, Length& logicalRigh | 
| logicalLeft.setValue(Fixed, staticPosition); | 
| } else { | 
| RenderBox* enclosingBox = child->parent()->enclosingBox(); | 
| -        LayoutUnit staticPosition = child->layer()->staticInlinePosition() + containerLogicalWidth + containerBlock->borderLogicalLeft(); | 
| +        staticPosition += child->layer()->staticInlinePosition() + containerLogicalWidth + containerBlock->borderLogicalLeft(); | 
| for (RenderObject* curr = child->parent(); curr; curr = curr->container()) { | 
| if (curr->isBox()) { | 
| if (curr != containerBlock) { | 
| @@ -3051,13 +3080,29 @@ void RenderBox::computePositionedLogicalWidthUsing(Length logicalWidth, const Re | 
| computeLogicalLeftPositionedOffset(computedValues.m_position, this, computedValues.m_extent, containerBlock, containerLogicalWidth); | 
| } | 
|  | 
| -static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom, const RenderBox* child, const RenderBoxModelObject* containerBlock) | 
| +static LayoutUnit computeBlockStaticPositionForGridItem(Length& logicalTop, Length& logicalBottom, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight) | 
| { | 
| -    if (!logicalTop.isAuto() || !logicalBottom.isAuto()) | 
| +    ASSERT(containerBlock->isRenderGrid()); | 
| + | 
| +    LayoutUnit staticPosition = 0; | 
| +    if (!logicalTop.isAuto()) | 
| +        staticPosition += valueForLength(logicalTop, containerLogicalHeight); | 
| +    else if (!logicalBottom.isAuto()) | 
| +        staticPosition -= valueForLength(logicalBottom, containerLogicalHeight); | 
| +    return staticPosition; | 
| +} | 
| + | 
| +static void computeBlockStaticDistance(Length& logicalTop, Length& logicalBottom, const RenderBox* child, const RenderBoxModelObject* containerBlock, LayoutUnit containerLogicalHeight) | 
| +{ | 
| +    if ((!logicalTop.isAuto() || !logicalBottom.isAuto()) && (!containerBlock->isRenderGrid() || (containerBlock->isRenderGrid() && child->style()->gridRowStart().isAuto()))) | 
| return; | 
|  | 
| +    LayoutUnit staticLogicalTop = 0; | 
| +    if (containerBlock->isRenderGrid()) | 
| +        staticLogicalTop = computeBlockStaticPositionForGridItem(logicalTop, logicalBottom, child, containerBlock, containerLogicalHeight); | 
| + | 
| // FIXME: The static distance computation has not been patched for mixed writing modes. | 
| -    LayoutUnit staticLogicalTop = child->layer()->staticBlockPosition() - containerBlock->borderBefore(); | 
| +    staticLogicalTop += child->layer()->staticBlockPosition() - containerBlock->borderBefore(); | 
| for (RenderObject* curr = child->parent(); curr && curr != containerBlock; curr = curr->container()) { | 
| if (curr->isBox() && !curr->isTableRow()) | 
| staticLogicalTop += toRenderBox(curr)->logicalTop(); | 
| @@ -3110,7 +3155,7 @@ void RenderBox::computePositionedLogicalHeight(LogicalExtentComputedValues& comp | 
|  | 
| // see FIXME 1 | 
| // Calculate the static distance if needed. | 
| -    computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, containerBlock); | 
| +    computeBlockStaticDistance(logicalTopLength, logicalBottomLength, this, containerBlock, containerLogicalHeight); | 
|  | 
| // Calculate constraint equation values for 'height' case. | 
| LayoutUnit logicalHeight = computedValues.m_extent; | 
| @@ -3516,7 +3561,7 @@ void RenderBox::computePositionedLogicalHeightReplaced(LogicalExtentComputedValu | 
| *    with the element's static position. | 
| \*-----------------------------------------------------------------------*/ | 
| // see FIXME 1 | 
| -    computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock); | 
| +    computeBlockStaticDistance(logicalTop, logicalBottom, this, containerBlock, containerLogicalHeight); | 
|  | 
| /*-----------------------------------------------------------------------*\ | 
| * 3. If 'bottom' is 'auto', replace any 'auto' on 'margin-top' or | 
|  |