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

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: Incorporated review comments 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
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()) {
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() &&
190 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. 195 if (layoutObject) {
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.
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
204 if (opposite.hasPercent()) {
205 LayoutUnit containingBlockSize =
206 (propertyID == CSSPropertyLeft || propertyID == CSSPrope rtyRight) ?
207 toLayoutBox(layoutObject)->containingBlockLogicalWidthFo rContent() :
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.
208 toLayoutBox(layoutObject)->containingBlockLogicalHeightF orGetComputedStyle();
209 return zoomAdjustedPixelValue(-floatValueForLength(opposite, containingBlockSize), style);
210 }
211 return zoomAdjustedPixelValue(-opposite.pixels(), style);
212 }
213
214 if (layoutObject->isOutOfFlowPositioned()) {
215 // For fixed and absolute positioned elements, the top, left, bo ttom, and right
216 // are defined relative to the corresponding sides of the contai ning block.
217 LayoutBlock* container = layoutObject->containingBlock();
218 const LayoutBox* layoutBox = toLayoutBox(layoutObject);
219
220 // clientOffset is the distance from this object's border edge t o the container's
221 // padding edge. Thus it includes margins which we subtract belo w.
222 const LayoutSize clientOffset =
223 layoutBox->locationOffset() - LayoutSize(container->clientLe ft(), container->clientTop());
224 LayoutUnit position;
225
226 switch (propertyID) {
227 case CSSPropertyLeft:
228 position = clientOffset.width() - layoutBox->marginLeft();
229 break;
230 case CSSPropertyTop:
231 position = clientOffset.height() - layoutBox->marginTop();
232 break;
233 case CSSPropertyRight:
234 position = container->clientWidth() - layoutBox->marginRight () -
235 (layoutBox->offsetWidth() + clientOffset.width());
236 break;
237 case CSSPropertyBottom:
238 position = container->clientHeight() - layoutBox->marginBott om() -
239 (layoutBox->offsetHeight() + clientOffset.height());
240 break;
241 default:
242 ASSERT_NOT_REACHED();
243 }
244 return zoomAdjustedPixelValue(position, style);
245 }
246 }
193 return cssValuePool().createIdentifierValue(CSSValueAuto); 247 return cssValuePool().createIdentifierValue(CSSValueAuto);
194 } 248 }
195 249
196 return zoomAdjustedPixelValueForLength(offset, style); 250 return zoomAdjustedPixelValueForLength(offset, style);
197 } 251 }
198 252
199 static PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> valueForNinePieceImageSl ice(const NinePieceImage& image) 253 static PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> valueForNinePieceImageSl ice(const NinePieceImage& image)
200 { 254 {
201 // Create the slices. 255 // Create the slices.
202 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr; 256 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr;
(...skipping 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 case CSSPropertyAll: 2808 case CSSPropertyAll:
2755 return nullptr; 2809 return nullptr;
2756 default: 2810 default:
2757 break; 2811 break;
2758 } 2812 }
2759 ASSERT_NOT_REACHED(); 2813 ASSERT_NOT_REACHED();
2760 return nullptr; 2814 return nullptr;
2761 } 2815 }
2762 2816
2763 } // namespace blink 2817 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698