Source/core/css/resolver/FontBuilder.cpp
// FIXME: Have to pass RenderStyles here for calc/computed values. This shouldn't be neecessary.
Have to pass RenderStyles here for calc/computed values. This shouldn't be neecessary.
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;
    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 {
            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;
    size = std::min(maximumAllowedFontSize, size);
    scope.fontDescription().setSpecifiedSize(size);
}
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 ; 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 { 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 ; size = std :: min ( maximumAllowedFontSize , size ) ; scope . fontDescription ( ) . setSpecifiedSize ( size ) ; }
FIXME: Have to pass RenderStyles here for calc/computed values.
FIXME : Have to pass RenderStyles here for calc / computed values .
// FIXME: Find out when parentStyle could be 0? // If we have viewport units the conversion will mark the parent style as having viewport units. // Overly large font sizes will cause crashes on some platforms (such as Windows). // Cap font size here to make sure that doesn't happen.