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

Unified Diff: third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp

Issue 1890743002: Reland of ix getComputedStyle positioned element values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/HTMLDialogElement/fixpos-dialog-layout-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 76fa72d1299b1fcd8ba7724319d84bc86e884f33..9ec10b7bc0ac7b305243d9a57c8ee468a912d753 100644
--- a/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp
+++ b/third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp
@@ -162,19 +162,23 @@
static 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,12 +190,62 @@
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.
+
+ 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);
- }
return zoomAdjustedPixelValueForLength(offset, style);
}
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/HTMLDialogElement/fixpos-dialog-layout-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698