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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved.
7 * Copyright (C) 2015 Google Inc. All rights reserved. 7 * Copyright (C) 2015 Google Inc. 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 Lesser General Public 10 * modify it under the terms of the GNU Lesser General Public
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return cssValuePool().createIdentifierValue(CSSValueLuminance); 155 return cssValuePool().createIdentifierValue(CSSValueLuminance);
156 } 156 }
157 157
158 ASSERT_NOT_REACHED(); 158 ASSERT_NOT_REACHED();
159 159
160 return nullptr; 160 return nullptr;
161 } 161 }
162 162
163 static CSSValue* valueForPositionOffset(const ComputedStyle& style, CSSPropertyI D propertyID, const LayoutObject* layoutObject) 163 static CSSValue* valueForPositionOffset(const ComputedStyle& style, CSSPropertyI D propertyID, const LayoutObject* layoutObject)
164 { 164 {
165 Length offset; 165 Length offset, opposite;
166 switch (propertyID) { 166 switch (propertyID) {
167 case CSSPropertyLeft: 167 case CSSPropertyLeft:
168 offset = style.left(); 168 offset = style.left();
169 opposite = style.right();
169 break; 170 break;
170 case CSSPropertyRight: 171 case CSSPropertyRight:
171 offset = style.right(); 172 offset = style.right();
173 opposite = style.left();
172 break; 174 break;
173 case CSSPropertyTop: 175 case CSSPropertyTop:
174 offset = style.top(); 176 offset = style.top();
177 opposite = style.bottom();
175 break; 178 break;
176 case CSSPropertyBottom: 179 case CSSPropertyBottom:
177 offset = style.bottom(); 180 offset = style.bottom();
181 opposite = style.top();
178 break; 182 break;
179 default: 183 default:
180 return nullptr; 184 return nullptr;
181 } 185 }
182 186
183 if (offset.hasPercent() && layoutObject && layoutObject->isBox() && layoutOb ject->isPositioned()) { 187 if (offset.hasPercent() && layoutObject && layoutObject->isBox() && layoutOb ject->isPositioned()) {
184 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || prope rtyID == CSSPropertyRight) ? 188 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || prope rtyID == CSSPropertyRight) ?
185 toLayoutBox(layoutObject)->containingBlockLogicalWidthForContent() : 189 toLayoutBox(layoutObject)->containingBlockLogicalWidthForContent() :
186 toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetCompute dStyle(); 190 toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetCompute dStyle();
187 return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize ), style); 191 return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize ), style);
188 } 192 }
189 if (offset.isAuto()) { 193
190 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. 194 if (offset.isAuto() && layoutObject) {
191 // In other words if left is auto and right is not auto, then left's com puted value is negative right(). 195 // If the property applies to a positioned element and the resolved valu e of the display
192 // So we should get the opposite length unit and see if it is auto. 196 // property is not none, the resolved value is the used value.
197 if (layoutObject->isInFlowPositioned()) {
198 // If e.g. left is auto and right is not auto, then left's computed value is negative right.
199 // So we get the opposite length unit and see if it is auto.
200 if (opposite.isAuto())
201 return cssValuePool().createValue(0, CSSPrimitiveValue::UnitType ::Pixels);
202
203 if (opposite.hasPercent()) {
204 LayoutUnit containingBlockSize =
205 (propertyID == CSSPropertyLeft || propertyID == CSSPropertyR ight) ?
206 toLayoutBox(layoutObject)->containingBlockLogicalWidthForCon tent() :
207 toLayoutBox(layoutObject)->containingBlockLogicalHeightForGe tComputedStyle();
208 return zoomAdjustedPixelValue(-floatValueForLength(opposite, con tainingBlockSize), style);
209 }
210 return zoomAdjustedPixelValue(-opposite.pixels(), style);
211 }
212
213 if (layoutObject->isOutOfFlowPositioned()) {
214 // For fixed and absolute positioned elements, the top, left, bottom , and right
215 // are defined relative to the corresponding sides of the containing block.
216 LayoutBlock* container = layoutObject->containingBlock();
217 const LayoutBox* layoutBox = toLayoutBox(layoutObject);
218
219 // clientOffset is the distance from this object's border edge to th e container's
220 // padding edge. Thus it includes margins which we subtract below.
221 const LayoutSize clientOffset =
222 layoutBox->locationOffset() - LayoutSize(container->clientLeft() , container->clientTop());
223 LayoutUnit position;
224
225 switch (propertyID) {
226 case CSSPropertyLeft:
227 position = clientOffset.width() - layoutBox->marginLeft();
228 break;
229 case CSSPropertyTop:
230 position = clientOffset.height() - layoutBox->marginTop();
231 break;
232 case CSSPropertyRight:
233 position = container->clientWidth() - layoutBox->marginRight() -
234 (layoutBox->offsetWidth() + clientOffset.width());
235 break;
236 case CSSPropertyBottom:
237 position = container->clientHeight() - layoutBox->marginBottom() -
238 (layoutBox->offsetHeight() + clientOffset.height());
239 break;
240 default:
241 ASSERT_NOT_REACHED();
242 }
243 return zoomAdjustedPixelValue(position, style);
244 }
245 }
246
247 if (offset.isAuto())
193 return cssValuePool().createIdentifierValue(CSSValueAuto); 248 return cssValuePool().createIdentifierValue(CSSValueAuto);
194 }
195 249
196 return zoomAdjustedPixelValueForLength(offset, style); 250 return zoomAdjustedPixelValueForLength(offset, style);
197 } 251 }
198 252
199 static CSSBorderImageSliceValue* valueForNinePieceImageSlice(const NinePieceImag e& image) 253 static CSSBorderImageSliceValue* valueForNinePieceImageSlice(const NinePieceImag e& image)
200 { 254 {
201 // Create the slices. 255 // Create the slices.
202 CSSPrimitiveValue* top = nullptr; 256 CSSPrimitiveValue* top = nullptr;
203 CSSPrimitiveValue* right = nullptr; 257 CSSPrimitiveValue* right = nullptr;
204 CSSPrimitiveValue* bottom = nullptr; 258 CSSPrimitiveValue* bottom = nullptr;
(...skipping 2553 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 case CSSPropertyAll: 2812 case CSSPropertyAll:
2759 return nullptr; 2813 return nullptr;
2760 default: 2814 default:
2761 break; 2815 break;
2762 } 2816 }
2763 ASSERT_NOT_REACHED(); 2817 ASSERT_NOT_REACHED();
2764 return nullptr; 2818 return nullptr;
2765 } 2819 }
2766 2820
2767 } // namespace blink 2821 } // namespace blink
OLDNEW
« 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