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..50c8af3a7fc523d37ad9feeb22d4f3afdedbb014 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,10 +190,60 @@ static PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(const ComputedSty |
| toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetComputedStyle(); |
| return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize), style); |
| } |
| + |
| if (offset.isAuto()) { |
|
mstensho (USE GERRIT)
2016/04/04 09:13:26
"if (offset.isAuto() && layoutObject)", to reduce
Mr. Kevin
2016/04/04 17:35:22
It falls through at the end to handle 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. |
| + if (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() : |
|
mstensho (USE GERRIT)
2016/04/04 09:13:26
Using logical width and height to resolve physical
Mr. Kevin
2016/04/04 17:35:22
Acknowledged.
|
| + 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); |
| + } |
| + } |
| return cssValuePool().createIdentifierValue(CSSValueAuto); |
| } |