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

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

Issue 2286543002: Add Length::isPercent and use it in tables. (Closed)
Patch Set: rebase Created 4 years, 3 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 opposite = style.bottom(); 184 opposite = style.bottom();
185 break; 185 break;
186 case CSSPropertyBottom: 186 case CSSPropertyBottom:
187 offset = style.bottom(); 187 offset = style.bottom();
188 opposite = style.top(); 188 opposite = style.top();
189 break; 189 break;
190 default: 190 default:
191 return nullptr; 191 return nullptr;
192 } 192 }
193 193
194 if (offset.hasPercent() && layoutObject && layoutObject->isBox() && layoutOb ject->isPositioned()) { 194 if (offset.isPercentOrCalc() && layoutObject && layoutObject->isBox() && lay outObject->isPositioned()) {
195 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || prope rtyID == CSSPropertyRight) ? 195 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || prope rtyID == CSSPropertyRight) ?
196 toLayoutBox(layoutObject)->containingBlockLogicalWidthForContent() : 196 toLayoutBox(layoutObject)->containingBlockLogicalWidthForContent() :
197 toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetCompute dStyle(); 197 toLayoutBox(layoutObject)->containingBlockLogicalHeightForGetCompute dStyle();
198 return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize ), style); 198 return zoomAdjustedPixelValue(valueForLength(offset, containingBlockSize ), style);
199 } 199 }
200 200
201 if (offset.isAuto() && layoutObject) { 201 if (offset.isAuto() && layoutObject) {
202 // If the property applies to a positioned element and the resolved valu e of the display 202 // If the property applies to a positioned element and the resolved valu e of the display
203 // property is not none, the resolved value is the used value. 203 // property is not none, the resolved value is the used value.
204 if (layoutObject->isInFlowPositioned()) { 204 if (layoutObject->isInFlowPositioned()) {
205 // If e.g. left is auto and right is not auto, then left's computed value is negative right. 205 // If e.g. left is auto and right is not auto, then left's computed value is negative right.
206 // So we get the opposite length unit and see if it is auto. 206 // So we get the opposite length unit and see if it is auto.
207 if (opposite.isAuto()) 207 if (opposite.isAuto())
208 return CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType: :Pixels); 208 return CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType: :Pixels);
209 209
210 if (opposite.hasPercent() || opposite.isCalculated()) { 210 if (opposite.isPercentOrCalc() || opposite.isCalculated()) {
211 if (layoutObject->isBox()) { 211 if (layoutObject->isBox()) {
212 LayoutUnit containingBlockSize = 212 LayoutUnit containingBlockSize =
213 (propertyID == CSSPropertyLeft || propertyID == CSSPrope rtyRight) ? 213 (propertyID == CSSPropertyLeft || propertyID == CSSPrope rtyRight) ?
214 toLayoutBox(layoutObject)->containingBlockLogicalWidthFo rContent() : 214 toLayoutBox(layoutObject)->containingBlockLogicalWidthFo rContent() :
215 toLayoutBox(layoutObject)->containingBlockLogicalHeightF orGetComputedStyle(); 215 toLayoutBox(layoutObject)->containingBlockLogicalHeightF orGetComputedStyle();
216 return zoomAdjustedPixelValue(-floatValueForLength(opposite, containingBlockSize), style); 216 return zoomAdjustedPixelValue(-floatValueForLength(opposite, containingBlockSize), style);
217 } 217 }
218 // FIXME: fall back to auto for position:relative, display:inli ne 218 // FIXME: fall back to auto for position:relative, display:inli ne
219 return CSSPrimitiveValue::createIdentifier(CSSValueAuto); 219 return CSSPrimitiveValue::createIdentifier(CSSValueAuto);
220 } 220 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 static CSSBorderImageSliceValue* valueForNinePieceImageSlice(const NinePieceImag e& image) 267 static CSSBorderImageSliceValue* valueForNinePieceImageSlice(const NinePieceImag e& image)
268 { 268 {
269 // Create the slices. 269 // Create the slices.
270 CSSPrimitiveValue* top = nullptr; 270 CSSPrimitiveValue* top = nullptr;
271 CSSPrimitiveValue* right = nullptr; 271 CSSPrimitiveValue* right = nullptr;
272 CSSPrimitiveValue* bottom = nullptr; 272 CSSPrimitiveValue* bottom = nullptr;
273 CSSPrimitiveValue* left = nullptr; 273 CSSPrimitiveValue* left = nullptr;
274 274
275 // TODO(alancutter): Make this code aware of calc lengths. 275 // TODO(alancutter): Make this code aware of calc lengths.
276 if (image.imageSlices().top().hasPercent()) 276 if (image.imageSlices().top().isPercentOrCalc())
277 top = CSSPrimitiveValue::create(image.imageSlices().top().value(), CSSPr imitiveValue::UnitType::Percentage); 277 top = CSSPrimitiveValue::create(image.imageSlices().top().value(), CSSPr imitiveValue::UnitType::Percentage);
278 else 278 else
279 top = CSSPrimitiveValue::create(image.imageSlices().top().value(), CSSPr imitiveValue::UnitType::Number); 279 top = CSSPrimitiveValue::create(image.imageSlices().top().value(), CSSPr imitiveValue::UnitType::Number);
280 280
281 if (image.imageSlices().right() == image.imageSlices().top() && image.imageS lices().bottom() == image.imageSlices().top() 281 if (image.imageSlices().right() == image.imageSlices().top() && image.imageS lices().bottom() == image.imageSlices().top()
282 && image.imageSlices().left() == image.imageSlices().top()) { 282 && image.imageSlices().left() == image.imageSlices().top()) {
283 right = top; 283 right = top;
284 bottom = top; 284 bottom = top;
285 left = top; 285 left = top;
286 } else { 286 } else {
287 if (image.imageSlices().right().hasPercent()) 287 if (image.imageSlices().right().isPercentOrCalc())
288 right = CSSPrimitiveValue::create(image.imageSlices().right().value( ), CSSPrimitiveValue::UnitType::Percentage); 288 right = CSSPrimitiveValue::create(image.imageSlices().right().value( ), CSSPrimitiveValue::UnitType::Percentage);
289 else 289 else
290 right = CSSPrimitiveValue::create(image.imageSlices().right().value( ), CSSPrimitiveValue::UnitType::Number); 290 right = CSSPrimitiveValue::create(image.imageSlices().right().value( ), CSSPrimitiveValue::UnitType::Number);
291 291
292 if (image.imageSlices().bottom() == image.imageSlices().top() && image.i mageSlices().right() == image.imageSlices().left()) { 292 if (image.imageSlices().bottom() == image.imageSlices().top() && image.i mageSlices().right() == image.imageSlices().left()) {
293 bottom = top; 293 bottom = top;
294 left = right; 294 left = right;
295 } else { 295 } else {
296 if (image.imageSlices().bottom().hasPercent()) 296 if (image.imageSlices().bottom().isPercentOrCalc())
297 bottom = CSSPrimitiveValue::create(image.imageSlices().bottom(). value(), CSSPrimitiveValue::UnitType::Percentage); 297 bottom = CSSPrimitiveValue::create(image.imageSlices().bottom(). value(), CSSPrimitiveValue::UnitType::Percentage);
298 else 298 else
299 bottom = CSSPrimitiveValue::create(image.imageSlices().bottom(). value(), CSSPrimitiveValue::UnitType::Number); 299 bottom = CSSPrimitiveValue::create(image.imageSlices().bottom(). value(), CSSPrimitiveValue::UnitType::Number);
300 300
301 if (image.imageSlices().left() == image.imageSlices().right()) { 301 if (image.imageSlices().left() == image.imageSlices().right()) {
302 left = right; 302 left = right;
303 } else { 303 } else {
304 if (image.imageSlices().left().hasPercent()) 304 if (image.imageSlices().left().isPercentOrCalc())
305 left = CSSPrimitiveValue::create(image.imageSlices().left(). value(), CSSPrimitiveValue::UnitType::Percentage); 305 left = CSSPrimitiveValue::create(image.imageSlices().left(). value(), CSSPrimitiveValue::UnitType::Percentage);
306 else 306 else
307 left = CSSPrimitiveValue::create(image.imageSlices().left(). value(), CSSPrimitiveValue::UnitType::Number); 307 left = CSSPrimitiveValue::create(image.imageSlices().left(). value(), CSSPrimitiveValue::UnitType::Number);
308 } 308 }
309 } 309 }
310 } 310 }
311 311
312 return CSSBorderImageSliceValue::create(CSSQuadValue::create(top, right, bot tom, left, CSSQuadValue::SerializeAsQuad), image.fill()); 312 return CSSBorderImageSliceValue::create(CSSQuadValue::create(top, right, bot tom, left, CSSQuadValue::SerializeAsQuad), image.fill());
313 } 313 }
314 314
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 return createBorderImageValue(imageValue, imageSlices, borderSlices, outset, repeat); 410 return createBorderImageValue(imageValue, imageSlices, borderSlices, outset, repeat);
411 } 411 }
412 412
413 static CSSValue* valueForReflection(const StyleReflection* reflection, const Com putedStyle& style) 413 static CSSValue* valueForReflection(const StyleReflection* reflection, const Com putedStyle& style)
414 { 414 {
415 if (!reflection) 415 if (!reflection)
416 return CSSPrimitiveValue::createIdentifier(CSSValueNone); 416 return CSSPrimitiveValue::createIdentifier(CSSValueNone);
417 417
418 CSSPrimitiveValue* offset = nullptr; 418 CSSPrimitiveValue* offset = nullptr;
419 // TODO(alancutter): Make this work correctly for calc lengths. 419 // TODO(alancutter): Make this work correctly for calc lengths.
420 if (reflection->offset().hasPercent()) 420 if (reflection->offset().isPercentOrCalc())
421 offset = CSSPrimitiveValue::create(reflection->offset().percent(), CSSPr imitiveValue::UnitType::Percentage); 421 offset = CSSPrimitiveValue::create(reflection->offset().percent(), CSSPr imitiveValue::UnitType::Percentage);
422 else 422 else
423 offset = zoomAdjustedPixelValue(reflection->offset().value(), style); 423 offset = zoomAdjustedPixelValue(reflection->offset().value(), style);
424 424
425 CSSPrimitiveValue* direction = nullptr; 425 CSSPrimitiveValue* direction = nullptr;
426 switch (reflection->direction()) { 426 switch (reflection->direction()) {
427 case ReflectionBelow: 427 case ReflectionBelow:
428 direction = CSSPrimitiveValue::createIdentifier(CSSValueBelow); 428 direction = CSSPrimitiveValue::createIdentifier(CSSValueBelow);
429 break; 429 break;
430 case ReflectionAbove: 430 case ReflectionAbove:
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 Length marginTop = style.marginTop(); 2075 Length marginTop = style.marginTop();
2076 if (marginTop.isFixed() || !layoutObject || !layoutObject->isBox()) 2076 if (marginTop.isFixed() || !layoutObject || !layoutObject->isBox())
2077 return zoomAdjustedPixelValueForLength(marginTop, style); 2077 return zoomAdjustedPixelValueForLength(marginTop, style);
2078 return zoomAdjustedPixelValue(toLayoutBox(layoutObject)->marginTop(), st yle); 2078 return zoomAdjustedPixelValue(toLayoutBox(layoutObject)->marginTop(), st yle);
2079 } 2079 }
2080 case CSSPropertyMarginRight: { 2080 case CSSPropertyMarginRight: {
2081 Length marginRight = style.marginRight(); 2081 Length marginRight = style.marginRight();
2082 if (marginRight.isFixed() || !layoutObject || !layoutObject->isBox()) 2082 if (marginRight.isFixed() || !layoutObject || !layoutObject->isBox())
2083 return zoomAdjustedPixelValueForLength(marginRight, style); 2083 return zoomAdjustedPixelValueForLength(marginRight, style);
2084 float value; 2084 float value;
2085 if (marginRight.hasPercent()) { 2085 if (marginRight.isPercentOrCalc()) {
2086 // LayoutBox gives a marginRight() that is the distance between the right-edge of the child box 2086 // LayoutBox gives a marginRight() that is the distance between the right-edge of the child box
2087 // and the right-edge of the containing box, when display == BLOCK. Let's calculate the absolute 2087 // and the right-edge of the containing box, when display == BLOCK. Let's calculate the absolute
2088 // value of the specified margin-right % instead of relying on Layou tBox's marginRight() value. 2088 // value of the specified margin-right % instead of relying on Layou tBox's marginRight() value.
2089 value = minimumValueForLength(marginRight, toLayoutBox(layoutObject) ->containingBlockLogicalWidthForContent()).toFloat(); 2089 value = minimumValueForLength(marginRight, toLayoutBox(layoutObject) ->containingBlockLogicalWidthForContent()).toFloat();
2090 } else { 2090 } else {
2091 value = toLayoutBox(layoutObject)->marginRight().toFloat(); 2091 value = toLayoutBox(layoutObject)->marginRight().toFloat();
2092 } 2092 }
2093 return zoomAdjustedPixelValue(value, style); 2093 return zoomAdjustedPixelValue(value, style);
2094 } 2094 }
2095 case CSSPropertyMarginBottom: { 2095 case CSSPropertyMarginBottom: {
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
3007 case CSSPropertyAll: 3007 case CSSPropertyAll:
3008 return nullptr; 3008 return nullptr;
3009 default: 3009 default:
3010 break; 3010 break;
3011 } 3011 }
3012 ASSERT_NOT_REACHED(); 3012 ASSERT_NOT_REACHED();
3013 return nullptr; 3013 return nullptr;
3014 } 3014 }
3015 3015
3016 } // namespace blink 3016 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698