Changeset 88553 in webkit
- Timestamp:
- Jun 10, 2011 11:17:21 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r88552 r88553 1 2011-06-10 Luke Macpherson <macpherson@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Clean up CSSPrimitiveValue::computeLength* 6 https://bugs.webkit.org/show_bug.cgi?id=61612 7 8 No new tests as no functionality changed. 9 10 * css/CSSGradientValue.cpp: 11 Use new computeLength functions. 12 * css/CSSPrimitiveValue.cpp: 13 (WebCore::CSSPrimitiveValue::computeLengthIntForLength): 14 Reduce to a single function using default parameter values. 15 (WebCore::CSSPrimitiveValue::computeLength): 16 Redefine existing functions with separate names as a single function using templated function specialization. 17 * css/CSSPrimitiveValue.h: 18 Prototypes for computeLengthIntForLength and computeLength. 19 * css/CSSStyleApplyProperty.cpp: 20 Use new computeLength functions. 21 * css/CSSStyleSelector.cpp: 22 Use new computeLength functions. 23 * css/MediaQueryEvaluator.cpp: 24 Use new computeLength functions. 25 * css/SVGCSSStyleSelector.cpp: 26 Use new computeLength functions. 27 1 28 2011-06-10 Simon Fraser <simon.fraser@apple.com> 2 29 -
trunk/Source/WebCore/css/CSSGradientValue.cpp
r87389 r88553 160 160 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100; 161 161 else if (CSSPrimitiveValue::isUnitTypeLength(type)) { 162 float length = stop.m_position->computeLength Float(style, rootStyle, style->effectiveZoom());162 float length = stop.m_position->computeLength<float>(style, rootStyle, style->effectiveZoom()); 163 163 if (!computedGradientLength) { 164 164 FloatSize gradientSize(gradientStart - gradientEnd); … … 392 392 393 393 default: 394 return value->computeLength Float(style, rootStyle, zoomFactor);394 return value->computeLength<float>(style, rootStyle, zoomFactor); 395 395 } 396 396 } … … 645 645 result = *widthOrHeight * radius->getFloatValue() / 100; 646 646 else 647 result = radius->computeLength Float(style, rootStyle, zoomFactor);647 result = radius->computeLength<float>(style, rootStyle, zoomFactor); 648 648 649 649 return result; -
trunk/Source/WebCore/css/CSSPrimitiveValue.cpp
r80463 r88553 250 250 } 251 251 252 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle) 253 { 254 return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle)); 255 } 256 257 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 258 { 259 return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier)); 252 template<> int CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 253 { 254 return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)); 260 255 } 261 256 262 257 // Lengths expect an int that is only 28-bits, so we have to check for a 263 258 // different overflow. 264 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle) 265 { 266 return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle)); 267 } 268 269 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 270 { 271 return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier)); 272 } 273 274 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle) 275 { 276 return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle)); 277 } 278 279 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle, double multiplier) 280 { 281 return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier)); 282 } 283 284 float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, bool computingFontSize) 285 { 286 return static_cast<float>(computeLengthDouble(style, rootStyle, 1.0, computingFontSize)); 287 } 288 289 float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 259 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 260 { 261 return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)); 262 } 263 264 template<> Length CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 265 { 266 return Length(computeLengthIntForLength(style, rootStyle, multiplier, computingFontSize), Fixed); 267 } 268 269 template<> short CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 270 { 271 return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)); 272 } 273 274 template<> float CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 290 275 { 291 276 return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize)); 277 } 278 279 template<> double CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize) 280 { 281 return computeLengthDouble(style, rootStyle, multiplier, computingFontSize); 292 282 } 293 283 -
trunk/Source/WebCore/css/CSSPrimitiveValue.h
r87771 r88553 137 137 * and some tool to calibrate. 138 138 */ 139 int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle); 140 int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier); 141 int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle); 142 int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier); 143 short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle); 144 short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier); 145 float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, bool computingFontSize = false); 146 float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize = false); 147 double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false); 139 template<typename T> T computeLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false); 140 int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false); 148 141 149 142 // use with care!!! … … 221 214 void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value. 222 215 bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const; 216 217 double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize); 223 218 224 219 virtual bool isPrimitiveValue() const { return true; } -
trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp
r88525 r88553 372 372 break; 373 373 case CSSValueInvalid: 374 width = primitiveValue->computeLength Short(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());374 width = primitiveValue->computeLength<short>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()); 375 375 // CSS2 box model does not allow negative lengths for borders. 376 376 if (width < 0) -
trunk/Source/WebCore/css/CSSStyleSelector.cpp
r88526 r88553 3345 3345 } else if (CSSPrimitiveValue::isUnitTypeLength(type)) { 3346 3346 if (toFloat) 3347 l = Length(primitiveValue->computeLength Double(style, rootStyle, multiplier), Fixed);3347 l = Length(primitiveValue->computeLength<double>(style, rootStyle, multiplier), Fixed); 3348 3348 else 3349 3349 l = Length(primitiveValue->computeLengthIntForLength(style, rootStyle, multiplier), Fixed); … … 3741 3741 if (!primitiveValue) 3742 3742 return; 3743 short spacing = primitiveValue->computeLength Short(style(), m_rootElementStyle, zoomFactor);3743 short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor); 3744 3744 m_style->setHorizontalBorderSpacing(spacing); 3745 3745 return; … … 3749 3749 if (!primitiveValue) 3750 3750 return; 3751 short spacing = primitiveValue->computeLength Short(style(), m_rootElementStyle, zoomFactor);3751 short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor); 3752 3752 m_style->setVerticalBorderSpacing(spacing); 3753 3753 return; … … 3818 3818 if (!primitiveValue) 3819 3819 return; 3820 width = primitiveValue->computeLength Int(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);3820 width = primitiveValue->computeLength<int>(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor); 3821 3821 } 3822 3822 switch (id) { … … 3943 3943 type != CSSPrimitiveValue::CSS_REMS)); 3944 3944 if (CSSPrimitiveValue::isUnitTypeLength(type)) 3945 size = primitiveValue->computeLength Float(m_parentStyle, m_rootElementStyle, true);3945 size = primitiveValue->computeLength<float>(m_parentStyle, m_rootElementStyle, 1.0, true); 3946 3946 else if (type == CSSPrimitiveValue::CSS_PERCENTAGE) 3947 3947 size = (primitiveValue->getFloatValue() * oldSize) / 100.0f; … … 4563 4563 radiusWidth = Length(pair->first()->getDoubleValue(), Percent); 4564 4564 else 4565 radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength Int(style(), m_rootElementStyle, zoomFactor))), Fixed);4565 radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed); 4566 4566 if (pair->second()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) 4567 4567 radiusHeight = Length(pair->second()->getDoubleValue(), Percent); 4568 4568 else 4569 radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength Int(style(), m_rootElementStyle, zoomFactor))), Fixed);4569 radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed); 4570 4570 int width = radiusWidth.value(); 4571 4571 int height = radiusHeight.value(); … … 4600 4600 case CSSPropertyOutlineOffset: 4601 4601 HANDLE_INHERIT_AND_INITIAL(outlineOffset, OutlineOffset) 4602 m_style->setOutlineOffset(primitiveValue->computeLength Int(style(), m_rootElementStyle, zoomFactor));4602 m_style->setOutlineOffset(primitiveValue->computeLength<int>(style(), m_rootElementStyle, zoomFactor)); 4603 4603 return; 4604 4604 case CSSPropertyImageRendering: … … 4628 4628 continue; 4629 4629 ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i)); 4630 int x = item->x->computeLength Int(style(), m_rootElementStyle, zoomFactor);4631 int y = item->y->computeLength Int(style(), m_rootElementStyle, zoomFactor);4632 int blur = item->blur ? item->blur->computeLength Int(style(), m_rootElementStyle, zoomFactor) : 0;4633 int spread = item->spread ? item->spread->computeLength Int(style(), m_rootElementStyle, zoomFactor) : 0;4630 int x = item->x->computeLength<int>(style(), m_rootElementStyle, zoomFactor); 4631 int y = item->y->computeLength<int>(style(), m_rootElementStyle, zoomFactor); 4632 int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0; 4633 int spread = item->spread ? item->spread->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0; 4634 4634 ShadowStyle shadowStyle = item->style && item->style->getIdent() == CSSValueInset ? Inset : Normal; 4635 4635 Color color; … … 4761 4761 return; 4762 4762 } 4763 m_style->setColumnGap(primitiveValue->computeLength Float(style(), m_rootElementStyle, zoomFactor));4763 m_style->setColumnGap(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor)); 4764 4764 return; 4765 4765 } … … 4780 4780 return; 4781 4781 } 4782 m_style->setColumnWidth(primitiveValue->computeLength Float(style(), m_rootElementStyle, zoomFactor));4782 m_style->setColumnWidth(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor)); 4783 4783 return; 4784 4784 } … … 5057 5057 else if (primitiveValue->getIdent() == CSSValueThick) 5058 5058 result *= 5; 5059 width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength Float(style(), m_rootElementStyle, zoomFactor);5059 width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength<float>(style(), m_rootElementStyle, zoomFactor); 5060 5060 break; 5061 5061 } 5062 5062 default: 5063 width = primitiveValue->computeLength Float(style(), m_rootElementStyle, zoomFactor);5063 width = primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor); 5064 5064 break; 5065 5065 } … … 5110 5110 else if (type == CSSPrimitiveValue::CSS_NUMBER) { 5111 5111 // For backward compatibility, treat valueless numbers as px. 5112 perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength Float(style(), m_rootElementStyle, zoomFactor);5112 perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(style(), m_rootElementStyle, zoomFactor); 5113 5113 } else 5114 5114 return; -
trunk/Source/WebCore/css/MediaQueryEvaluator.cpp
r72954 r88553 312 312 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); 313 313 RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle(); 314 return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength Int(style, rootStyle), op);314 return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op); 315 315 } 316 316 // ({,min-,max-}device-height) … … 324 324 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); 325 325 RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle(); 326 return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength Int(style, rootStyle), op);326 return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op); 327 327 } 328 328 // ({,min-,max-}device-width) … … 337 337 338 338 if (value) 339 return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength Int(style, rootStyle), op);339 return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op); 340 340 341 341 return view->layoutHeight() != 0; … … 348 348 349 349 if (value) 350 return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength Int(style, rootStyle), op);350 return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op); 351 351 352 352 return view->layoutWidth() != 0; -
trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp
r88266 r88553 573 573 return; 574 574 ShadowValue* item = static_cast<ShadowValue*>(firstValue); 575 int x = item->x->computeLength Int(style(), m_rootElementStyle);576 int y = item->y->computeLength Int(style(), m_rootElementStyle);577 int blur = item->blur ? item->blur->computeLength Int(style(), m_rootElementStyle) : 0;575 int x = item->x->computeLength<int>(style(), m_rootElementStyle); 576 int y = item->y->computeLength<int>(style(), m_rootElementStyle); 577 int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle) : 0; 578 578 Color color; 579 579 if (item->color)
Note: See TracChangeset
for help on using the changeset viewer.