Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp |
| diff --git a/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp b/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp |
| index c2262b9e55127ffd155c225031147f7ce0ffcf65..df6ad886fd4758ab49a46054737acc8ea2386ff2 100644 |
| --- a/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp |
| +++ b/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp |
| @@ -162,19 +162,23 @@ static PassRefPtrWillBeRawPtr<CSSValue> valueForFillSourceType(EMaskSourceType t |
| static PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(const ComputedStyle& style, CSSPropertyID propertyID, const LayoutObject* layoutObject) |
| { |
| - Length offset; |
| + Length offset, opposite; |
| switch (propertyID) { |
| case CSSPropertyLeft: |
| offset = style.left(); |
| + opposite = style.right(); |
| break; |
| case CSSPropertyRight: |
| offset = style.right(); |
| + opposite = style.left(); |
| break; |
| case CSSPropertyTop: |
| offset = style.top(); |
| + opposite = style.bottom(); |
| break; |
| case CSSPropertyBottom: |
| offset = style.bottom(); |
| + opposite = style.top(); |
| break; |
| default: |
| return nullptr; |
| @@ -186,13 +190,63 @@ static PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(const ComputedSty |
| toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetComputedStyle(); |
| return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize), style); |
| } |
| - if (offset.isAuto()) { |
| - // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. |
| - // In other words if left is auto and right is not auto, then left's computed value is negative right(). |
| - // So we should get the opposite length unit and see if it is auto. |
| - return cssValuePool().createIdentifierValue(CSSValueAuto); |
| + |
| + if (offset.isAuto() && layoutObject) { |
| + // If the property applies to a positioned element and the resolved value of the display |
| + // property is not none, the resolved value is the used value. |
| + if (layoutObject->isInFlowPositioned()) { |
| + // If e.g. left is auto and right is not auto, then left's computed value is negative right. |
| + // So we get the opposite length unit and see if it is auto. |
| + if (opposite.isAuto()) |
| + return cssValuePool().createValue(0, CSSPrimitiveValue::UnitType::Pixels); |
| + |
| + if (opposite.hasPercent()) { |
| + LayoutUnit containingBlockSize = |
| + (propertyID == CSSPropertyLeft || propertyID == CSSPropertyRight) ? |
| + toLayoutBox(layoutObject)->containingBlockLogicalWidthForContent() : |
| + toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetComputedStyle(); |
| + return zoomAdjustedPixelValue(-floatValueForLength(opposite, containingBlockSize), style); |
| + } |
| + return zoomAdjustedPixelValue(-opposite.pixels(), style); |
| + } |
| + |
| + if (layoutObject->isOutOfFlowPositioned()) { |
| + // For fixed and absolute positioned elements, the top, left, bottom, and right |
| + // are defined relative to the corresponding sides of the containing block. |
| + LayoutBlock* container = layoutObject->containingBlock(); |
| + const LayoutBox* layoutBox = toLayoutBox(layoutObject); |
| + |
| + // clientOffset is the distance from this object's border edge to the container's |
| + // padding edge. Thus it includes margins which we subtract below. |
| + const LayoutSize clientOffset = |
| + layoutBox->locationOffset() - LayoutSize(container->clientLeft(), container->clientTop()); |
| + LayoutUnit position; |
| + |
| + switch (propertyID) { |
| + case CSSPropertyLeft: |
| + position = clientOffset.width() - layoutBox->marginLeft(); |
| + break; |
| + case CSSPropertyTop: |
| + position = clientOffset.height() - layoutBox->marginTop(); |
| + break; |
| + case CSSPropertyRight: |
| + position = container->clientWidth() - layoutBox->marginRight() - |
| + (layoutBox->offsetWidth() + clientOffset.width()); |
| + break; |
| + case CSSPropertyBottom: |
| + position = container->clientHeight() - layoutBox->marginBottom() - |
| + (layoutBox->offsetHeight() + clientOffset.height()); |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| + return zoomAdjustedPixelValue(position, style); |
| + } |
| } |
| + if (offset.isAuto()) |
| + return cssValuePool().createIdentifierValue(CSSValueAuto); |
|
mstensho (USE GERRIT)
2016/04/04 22:19:20
Sorry! Didn't realize that this one was there to h
|
| + |
| return zoomAdjustedPixelValueForLength(offset, style); |
| } |