static float computeLength(CSSValue* value, RenderStyle& style, RenderView* view) { CSSToLengthConversionData conversionData(&style, &style, view); if (is<CSSPrimitiveValue>(value)) { CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value); if (!primitiveValue.isLength()) return defaultLength(style, view); return primitiveValue.computeLength<float>(conversionData); } if (is<CSSCalcValue>(value)) return downcast<CSSCalcValue>(*value).computeLengthPx(conversionData); return defaultLength(style, view); }
static float computeLength(CSSValue* value, RenderStyle& style, RenderView* view) { CSSToLengthConversionData conversionData(&style, &style, view); if (is<CSSPrimitiveValue>(value)) { CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value); if (!primitiveValue.isLength()) return defaultLength(style, view); return primitiveValue.computeLength<float>(conversionData); } if (is<CSSCalcValue>(value)) { Length length(downcast<CSSCalcValue>(*value).createCalculationValue(conversionData)); return CSSPrimitiveValue::create(length, &style)->computeLength<float>(conversionData); } return defaultLength(style, view); }
// FIXME: Have to pass RenderStyles here for calc/computed values. This shouldn't be neecessary. void FontBuilder::setFontSizeValue(CSSValue* value, RenderStyle* parentStyle, const RenderStyle* rootElementStyle) { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); FontDescriptionChangeScope scope(this); scope.fontDescription().setKeywordSize(0); float parentSize = 0; bool parentIsAbsoluteSize = false; float size = 0; // FIXME: Find out when parentStyle could be 0? if (parentStyle) { parentSize = parentStyle->fontDescription().specifiedSize(); parentIsAbsoluteSize = parentStyle->fontDescription().isAbsoluteSize(); } if (CSSValueID valueID = primitiveValue->getValueID()) { switch (valueID) { case CSSValueXxSmall: case CSSValueXSmall: case CSSValueSmall: case CSSValueMedium: case CSSValueLarge: case CSSValueXLarge: case CSSValueXxLarge: case CSSValueWebkitXxxLarge: size = FontSize::fontSizeForKeyword(m_document, valueID, scope.fontDescription().useFixedDefaultSize()); scope.fontDescription().setKeywordSize(valueID - CSSValueXxSmall + 1); break; case CSSValueLarger: size = largerFontSize(parentSize); break; case CSSValueSmaller: size = smallerFontSize(parentSize); break; default: return; } scope.fontDescription().setIsAbsoluteSize(parentIsAbsoluteSize && (valueID == CSSValueLarger || valueID == CSSValueSmaller)); } else { scope.fontDescription().setIsAbsoluteSize(parentIsAbsoluteSize || !(primitiveValue->isPercentage() || primitiveValue->isFontRelativeLength())); if (primitiveValue->isPercentage()) { size = (primitiveValue->getFloatValue() * parentSize) / 100.0f; } else { // If we have viewport units the conversion will mark the parent style as having viewport units. bool parentHasViewportUnits = parentStyle->hasViewportUnits(); parentStyle->setHasViewportUnits(false); CSSToLengthConversionData conversionData(parentStyle, rootElementStyle, m_document->renderView(), 1.0f, true); if (primitiveValue->isLength()) size = primitiveValue->computeLength<float>(conversionData); else if (primitiveValue->isCalculatedPercentageWithLength()) size = primitiveValue->cssCalcValue()->toCalcValue(conversionData)->evaluate(parentSize); else ASSERT_NOT_REACHED(); m_fontSizehasViewportUnits = parentStyle->hasViewportUnits(); parentStyle->setHasViewportUnits(parentHasViewportUnits); } } if (size < 0) return; // Overly large font sizes will cause crashes on some platforms (such as Windows). // Cap font size here to make sure that doesn't happen. size = std::min(maximumAllowedFontSize, size); scope.fontDescription().setSpecifiedSize(size); }