virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); Pair* pair = primitiveValue->getPairValue(); if (!pair || !pair->first() || !pair->second()) return; Length radiusWidth; Length radiusHeight; if (pair->first()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) radiusWidth = Length(pair->first()->getDoubleValue(), Percent); else radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength<int>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()))), Fixed); if (pair->second()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE) radiusHeight = Length(pair->second()->getDoubleValue(), Percent); else radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength<int>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom()))), Fixed); int width = radiusWidth.value(); int height = radiusHeight.value(); if (width < 0 || height < 0) return; if (!width) radiusHeight = radiusWidth; // Null out the other value. else if (!height) radiusWidth = radiusHeight; // Null out the other value. LengthSize size(radiusWidth, radiusHeight); setValue(selector->style(), size); }
void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) { if (value->isInitialValue()) { layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); return; } if (!is<CSSPrimitiveValue>(*value)) return; CSSPrimitiveValue* primitiveValue = downcast<CSSPrimitiveValue>(value); Pair* pair = primitiveValue->getPairValue(); if (pair) { ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY || propertyID == CSSPropertyWebkitMaskPositionY); primitiveValue = pair->second(); } Length length; if (primitiveValue->isLength()) length = primitiveValue->computeLength<Length>(m_resolver->state().cssToLengthConversionData()); else if (primitiveValue->isPercentage()) length = Length(primitiveValue->getDoubleValue(), Percent); else if (primitiveValue->isCalculatedPercentageWithLength()) length = Length(primitiveValue->cssCalcValue()->createCalculationValue(m_resolver->state().cssToLengthConversionData())); else return; layer->setYPosition(length); if (pair) layer->setBackgroundYOrigin(*(pair->first())); }
void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) { if (value->isInitialValue()) { layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); return; } if (!value->isPrimitiveValue()) return; float zoomFactor = style()->effectiveZoom(); CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); Pair* pair = primitiveValue->getPairValue(); if (pair) { ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY || propertyID == CSSPropertyWebkitMaskPositionY); primitiveValue = pair->second(); } Length length; if (primitiveValue->isLength()) length = primitiveValue->computeLength<Length>(style(), rootElementStyle(), zoomFactor); else if (primitiveValue->isPercentage()) length = Length(primitiveValue->getDoubleValue(), Percent); else if (primitiveValue->isCalculatedPercentageWithLength()) length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), rootElementStyle(), zoomFactor)); else if (primitiveValue->isViewportPercentageLength()) length = primitiveValue->viewportPercentageLength(); else return; layer->setYPosition(length); if (pair) layer->setBackgroundYOrigin(*(pair->first())); }
LengthPoint StyleBuilderConverter::convertLengthPoint(StyleResolverState& state, CSSValue* value) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Pair* pair = primitiveValue->getPairValue(); Length x = pair->first()->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()); Length y = pair->second()->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()); return LengthPoint(x, y); }
static inline bool convertToLengthSize(const CSSPrimitiveValue& primitiveValue, CSSToLengthConversionData conversionData, LengthSize& size) { if (auto* pair = primitiveValue.getPairValue()) { size.setWidth(pair->first()->convertToLength<AnyConversion>(conversionData)); size.setHeight(pair->second()->convertToLength<AnyConversion>(conversionData)); } else size.setWidth(primitiveValue.convertToLength<AnyConversion>(conversionData)); return !size.width().isUndefined() && !size.height().isUndefined(); }
LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, CSSValue* value) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Pair* pair = primitiveValue->getPairValue(); Length radiusWidth = pair->first()->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()); Length radiusHeight = pair->second()->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()); float width = radiusWidth.value(); float height = radiusHeight.value(); ASSERT(width >= 0 && height >= 0); if (width <= 0 || height <= 0) return LengthSize(Length(0, Fixed), Length(0, Fixed)); return LengthSize(radiusWidth, radiusHeight); }
bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSPrimitiveValue& primitiveValue) { // FIXME: consider other types. if (primitiveValue.isNumber() || primitiveValue.isPercentage() || primitiveValue.isAngle() || primitiveValue.isRGBColor() || primitiveValue.isURI()) return false; if (primitiveValue.isLength()) return primitiveValue.isFontRelativeLength() || primitiveValue.isViewportPercentageLength(); if (primitiveValue.isCalculated()) { CSSLengthArray lengthArray(CSSPrimitiveValue::LengthUnitTypeCount); primitiveValue.accumulateLengthArray(lengthArray); return lengthArray[CSSPrimitiveValue::UnitTypeFontSize] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin] != 0 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax] != 0; } if (Pair* pair = primitiveValue.getPairValue()) { return interpolationRequiresStyleResolve(*pair->first()) || interpolationRequiresStyleResolve(*pair->second()); } if (Rect* rect = primitiveValue.getRectValue()) { return interpolationRequiresStyleResolve(*rect->top()) || interpolationRequiresStyleResolve(*rect->right()) || interpolationRequiresStyleResolve(*rect->bottom()) || interpolationRequiresStyleResolve(*rect->left()); } if (Quad* quad = primitiveValue.getQuadValue()) { return interpolationRequiresStyleResolve(*quad->top()) || interpolationRequiresStyleResolve(*quad->right()) || interpolationRequiresStyleResolve(*quad->bottom()) || interpolationRequiresStyleResolve(*quad->left()); } if (primitiveValue.isShape()) return interpolationRequiresStyleResolve(*primitiveValue.getShapeValue()); CSSValueID id = primitiveValue.getValueID(); bool isColor = ((id >= CSSValueAqua && id <= CSSValueTransparent) || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) || id == CSSValueGrey); return (id != CSSValueNone) && !isColor; }
void CSSToStyleMap::mapNinePieceImageRepeat(StyleResolverState&, CSSValue* value, NinePieceImage& image) { if (!value || !value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Pair* pair = primitiveValue->getPairValue(); if (!pair || !pair->first() || !pair->second()) return; CSSValueID firstIdentifier = pair->first()->getValueID(); CSSValueID secondIdentifier = pair->second()->getValueID(); ENinePieceImageRule horizontalRule; switch (firstIdentifier) { case CSSValueStretch: horizontalRule = StretchImageRule; break; case CSSValueRound: horizontalRule = RoundImageRule; break; case CSSValueSpace: horizontalRule = SpaceImageRule; break; default: // CSSValueRepeat horizontalRule = RepeatImageRule; break; } image.setHorizontalRule(horizontalRule); ENinePieceImageRule verticalRule; switch (secondIdentifier) { case CSSValueStretch: verticalRule = StretchImageRule; break; case CSSValueRound: verticalRule = RoundImageRule; break; case CSSValueSpace: verticalRule = SpaceImageRule; break; default: // CSSValueRepeat verticalRule = RepeatImageRule; break; } image.setVerticalRule(verticalRule); }
void CSSToStyleMap::mapFillSize(CSSPropertyID, FillLayer* layer, CSSValue* value) { if (!value->isPrimitiveValue()) { layer->setSizeType(SizeNone); return; } CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); if (primitiveValue->getValueID() == CSSValueContain) layer->setSizeType(Contain); else if (primitiveValue->getValueID() == CSSValueCover) layer->setSizeType(Cover); else layer->setSizeType(SizeLength); LengthSize b = FillLayer::initialFillSizeLength(layer->type()); if (value->isInitialValue() || primitiveValue->getValueID() == CSSValueContain || primitiveValue->getValueID() == CSSValueCover) { layer->setSizeLength(b); return; } float zoomFactor = style()->effectiveZoom(); Length firstLength; Length secondLength; if (Pair* pair = primitiveValue->getPairValue()) { CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(pair->first()); CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(pair->second()); firstLength = first->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor); secondLength = second->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor); } else { firstLength = primitiveValue->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor); secondLength = Length(); } if (firstLength.isUndefined() || secondLength.isUndefined()) return; b.setWidth(firstLength); b.setHeight(secondLength); layer->setSizeLength(b); }
void CSSToStyleMap::mapFillSize(StyleResolverState& state, FillLayer* layer, CSSValue* value) { if (value->isInitialValue()) { layer->setSizeType(FillLayer::initialFillSizeType(layer->type())); layer->setSizeLength(FillLayer::initialFillSizeLength(layer->type())); return; } if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->getValueID() == CSSValueContain) layer->setSizeType(Contain); else if (primitiveValue->getValueID() == CSSValueCover) layer->setSizeType(Cover); else layer->setSizeType(SizeLength); LengthSize b = FillLayer::initialFillSizeLength(layer->type()); if (primitiveValue->getValueID() == CSSValueContain || primitiveValue->getValueID() == CSSValueCover) { layer->setSizeLength(b); return; } Length firstLength; Length secondLength; if (Pair* pair = primitiveValue->getPairValue()) { firstLength = pair->first()->convertToLength<AnyConversion>(state.cssToLengthConversionData()); secondLength = pair->second()->convertToLength<AnyConversion>(state.cssToLengthConversionData()); } else { firstLength = primitiveValue->convertToLength<AnyConversion>(state.cssToLengthConversionData()); secondLength = Length(); } b.setWidth(firstLength); b.setHeight(secondLength); layer->setSizeLength(b); }
void CSSToStyleMap::mapFillYPosition(StyleResolverState& state, FillLayer* layer, CSSValue* value) { if (value->isInitialValue()) { layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); return; } if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Pair* pair = primitiveValue->getPairValue(); if (pair) primitiveValue = pair->second(); Length length = primitiveValue->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()); layer->setYPosition(length); if (pair) layer->setBackgroundYOrigin(*(pair->first())); }
void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value) const { if (value->isInitialValue()) { layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); return; } if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Pair* pair = primitiveValue->getPairValue(); if (pair) { ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY || propertyID == CSSPropertyWebkitMaskPositionY); primitiveValue = pair->second(); } Length length = primitiveValue->convertToLength<FixedConversion | PercentConversion>(cssToLengthConversionData()); layer->setYPosition(length); if (pair) layer->setBackgroundYOrigin(*(pair->first())); }