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

Side by Side Diff: third_party/WebKit/Source/core/css/ComputedStyleCSSValueMapping.cpp

Issue 1826423003: fix 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 PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(const ComputedSty le& style, CSSPropertyID propertyID, const LayoutObject* layoutObject) 163 static PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(const ComputedSty le& style, CSSPropertyID 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 }
193
189 if (offset.isAuto()) { 194 if (offset.isAuto()) {
190 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. 195 if (style.display() != NONE) {
mstensho (USE GERRIT) 2016/03/29 13:13:26 Can just check if you have a layoutObject instead
191 // In other words if left is auto and right is not auto, then left's com puted value is negative right(). 196 // If the property applies to a positioned element and the resolved value of the display
192 // So we should get the opposite length unit and see if it is auto. 197 // property is not none, the resolved value is the used value.
198 if (layoutObject->isInFlowPositioned()) {
199 // If e.g. left is auto and right is not auto, then left's compu ted value is negative right().
mstensho (USE GERRIT) 2016/03/29 13:13:26 Should remove "()" from "right()".
200 // So we get the opposite length unit and see if it is auto.
201 if (opposite.isAuto()) {
202 return cssValuePool().createValue(0, CSSPrimitiveValue::Unit Type::Pixels);
203 }
mstensho (USE GERRIT) 2016/03/29 13:13:26 No need for curly braces here.
204 opposite *= -1.f;
mstensho (USE GERRIT) 2016/03/29 13:13:26 Why not "opposite = -opposite"? Oh, right, Length
205 if (opposite.hasPercent()) {
206 LayoutUnit containingBlockSize =
207 (propertyID == CSSPropertyLeft || propertyID == CSSPrope rtyRight) ?
208 toLayoutBox(layoutObject)->containingBlockLogicalWidthFo rContent() :
209 toLayoutBox(layoutObject)->containingBlockLogicalHeightF orGetComputedStyle();
210 return zoomAdjustedPixelValue(valueForLength(opposite, conta iningBlockSize), style);
211 }
212 return zoomAdjustedPixelValueForLength(opposite, style);
mstensho (USE GERRIT) 2016/03/29 13:13:26 Note: We don't take care of over-constrained situa
213 }
214
215 if (layoutObject->isOutOfFlowPositioned()) {
216 // For fixed and absolute positioned elements, the top, left, bo ttom, and right
217 // are defined relative to the corresponding sides of the contai ning block.
218 LayoutBlock* container = layoutObject->containingBlock();
219
220 const LayoutBox* layoutBox = toLayoutBox(layoutObject);
221 // locationOffset is the distance from this object's border edge to
222 // the container's border edge (which is not always the parent).
223 // Thus it includes any logical top/left along with this box's
224 // margins.
225 const LayoutSize locationOffset = layoutBox->locationOffset();
226 LayoutUnit left = locationOffset.width() - container->borderLeft () - layoutBox->marginLeft();
mstensho (USE GERRIT) 2016/03/29 13:13:26 We subtract layoutBox->marginLeft() here, which is
227 LayoutUnit top = locationOffset.height() - container->borderTop( ) - layoutBox->marginTop();
228 LayoutUnit position;
229
230 switch (propertyID) {
231 case CSSPropertyLeft:
232 position = left;
233 break;
234 case CSSPropertyTop:
235 position = top;
236 break;
237 // clientWidth and clientHeight exclude the border width
238 case CSSPropertyRight:
239 position = container->clientWidth() - layoutBox->offsetWidth () - left;
240 position -= (layoutBox->marginRight() + layoutBox->marginLef t());
241 break;
242 case CSSPropertyBottom:
243 position = container->clientHeight() - layoutBox->offsetHeig ht() - top;
244 position -= (layoutBox->marginBottom() + layoutBox->marginTo p());
245 break;
246 default:
247 return nullptr;
mstensho (USE GERRIT) 2016/03/29 13:13:26 You have handled all the possible cases, so better
248 }
249 return zoomAdjustedPixelValue(position, style);
250 }
251 }
193 return cssValuePool().createIdentifierValue(CSSValueAuto); 252 return cssValuePool().createIdentifierValue(CSSValueAuto);
194 } 253 }
195 254
196 return zoomAdjustedPixelValueForLength(offset, style); 255 return zoomAdjustedPixelValueForLength(offset, style);
197 } 256 }
198 257
199 static PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> valueForNinePieceImageSl ice(const NinePieceImage& image) 258 static PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> valueForNinePieceImageSl ice(const NinePieceImage& image)
200 { 259 {
201 // Create the slices. 260 // Create the slices.
202 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr; 261 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr;
(...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 case CSSPropertyAll: 2813 case CSSPropertyAll:
2755 return nullptr; 2814 return nullptr;
2756 default: 2815 default:
2757 break; 2816 break;
2758 } 2817 }
2759 ASSERT_NOT_REACHED(); 2818 ASSERT_NOT_REACHED();
2760 return nullptr; 2819 return nullptr;
2761 } 2820 }
2762 2821
2763 } // namespace blink 2822 } // 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