Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const { ASSERT(id == CSSPropertyMaxHeight || id == CSSPropertyMinHeight || id == CSSPropertyMaxWidth || id == CSSPropertyMinWidth); CSSValue* value = m_propertySet->getPropertyCSSValue(id); if (!value || !value->isPrimitiveValue()) return Length(); // auto CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->getValueID() == CSSValueInternalExtendToZoom) return Length(ExtendToZoom); ComputedStyle* documentStyle = m_document->mutableComputedStyle(); // If we have viewport units the conversion will mark the document style as having viewport units. bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); documentStyle->setHasViewportUnits(false); CSSToLengthConversionData::FontSizes fontSizes(documentStyle, documentStyle); CSSToLengthConversionData::ViewportSize viewportSize(m_document->layoutView()); if (primitiveValue->getValueID() == CSSValueAuto) return Length(Auto); Length result = primitiveValue->convertToLength(CSSToLengthConversionData(documentStyle, fontSizes, viewportSize, 1.0f)); if (documentStyle->hasViewportUnits()) m_document->setHasViewportUnits(); documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); return result; }
void StyleBuilderFunctions::applyValueCSSPropertyVerticalAlign(StyleResolverState& state, CSSValue* value) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->getValueID()) state.style()->setVerticalAlign(*primitiveValue); else state.style()->setVerticalAlignLength(primitiveValue->convertToLength(state.cssToLengthConversionData())); }
float SVGLengthContext::resolveValue(const CSSPrimitiveValue& primitiveValue, SVGLengthMode mode) const { const ComputedStyle* style = computedStyleForLengthResolving(m_context); if (!style) return 0; const ComputedStyle* rootStyle = rootElementStyle(m_context); if (!rootStyle) return 0; CSSToLengthConversionData conversionData = CSSToLengthConversionData( style, rootStyle, m_context->document().layoutViewItem(), 1.0f); Length length = primitiveValue.convertToLength(conversionData); return valueForLength(length, 1.0f, mode); }
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(state.cssToLengthConversionData()); layer->setYPosition(length); if (pair) layer->setBackgroundYOrigin(*(pair->first())); }
void StyleBuilderFunctions::applyValueCSSPropertyTextIndent(StyleResolverState& state, CSSValue* value) { Length lengthOrPercentageValue; TextIndentLine textIndentLineValue = ComputedStyle::initialTextIndentLine(); TextIndentType textIndentTypeValue = ComputedStyle::initialTextIndentType(); for (auto& listValue : toCSSValueList(*value)) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(listValue.get()); if (!primitiveValue->getValueID()) lengthOrPercentageValue = primitiveValue->convertToLength(state.cssToLengthConversionData()); else if (primitiveValue->getValueID() == CSSValueEachLine) textIndentLineValue = TextIndentEachLine; else if (primitiveValue->getValueID() == CSSValueHanging) textIndentTypeValue = TextIndentHanging; else ASSERT_NOT_REACHED(); } state.style()->setTextIndent(lengthOrPercentageValue); state.style()->setTextIndentLine(textIndentLineValue); state.style()->setTextIndentType(textIndentTypeValue); }
static Length convertToFloatLength( const CSSPrimitiveValue& primitiveValue, const CSSToLengthConversionData& conversionData) { return primitiveValue.convertToLength(conversionData); }
FilterOperations FilterOperationResolver::createFilterOperations(StyleResolverState& state, const CSSValue& inValue) { FilterOperations operations; if (inValue.isPrimitiveValue()) { ASSERT(toCSSPrimitiveValue(inValue).getValueID() == CSSValueNone); return operations; } const CSSToLengthConversionData& conversionData = state.cssToLengthConversionData(); for (auto& currValue : toCSSValueList(inValue)) { CSSFunctionValue* filterValue = toCSSFunctionValue(currValue.get()); FilterOperation::OperationType operationType = filterOperationForType(filterValue->functionType()); countFilterUse(operationType, state.document()); ASSERT(filterValue->length() <= 1); if (operationType == FilterOperation::REFERENCE) { CSSSVGDocumentValue* svgDocumentValue = toCSSSVGDocumentValue(filterValue->item(0)); KURL url = state.document().completeURL(svgDocumentValue->url()); RawPtr<ReferenceFilterOperation> operation = ReferenceFilterOperation::create(svgDocumentValue->url(), AtomicString(url.fragmentIdentifier())); if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(), state.document())) { if (!svgDocumentValue->loadRequested()) state.elementStyleResources().addPendingSVGDocument(operation.get(), svgDocumentValue); else if (svgDocumentValue->cachedSVGDocument()) ReferenceFilterBuilder::setDocumentResourceReference(operation.get(), adoptPtr(new DocumentResourceReference(svgDocumentValue->cachedSVGDocument()))); } operations.operations().append(operation); continue; } CSSPrimitiveValue* firstValue = filterValue->length() && filterValue->item(0)->isPrimitiveValue() ? toCSSPrimitiveValue(filterValue->item(0)) : nullptr; switch (filterValue->functionType()) { case CSSValueGrayscale: case CSSValueSepia: case CSSValueSaturate: { double amount = 1; if (filterValue->length() == 1) { amount = firstValue->getDoubleValue(); if (firstValue->isPercentage()) amount /= 100; } operations.operations().append(BasicColorMatrixFilterOperation::create(amount, operationType)); break; } case CSSValueHueRotate: { double angle = 0; if (filterValue->length() == 1) angle = firstValue->computeDegrees(); operations.operations().append(BasicColorMatrixFilterOperation::create(angle, operationType)); break; } case CSSValueInvert: case CSSValueBrightness: case CSSValueContrast: case CSSValueOpacity: { double amount = (filterValue->functionType() == CSSValueBrightness) ? 0 : 1; if (filterValue->length() == 1) { amount = firstValue->getDoubleValue(); if (firstValue->isPercentage()) amount /= 100; } operations.operations().append(BasicComponentTransferFilterOperation::create(amount, operationType)); break; } case CSSValueBlur: { Length stdDeviation = Length(0, Fixed); if (filterValue->length() >= 1) stdDeviation = firstValue->convertToLength(conversionData); operations.operations().append(BlurFilterOperation::create(stdDeviation)); break; } case CSSValueDropShadow: { CSSShadowValue* item = toCSSShadowValue(filterValue->item(0)); IntPoint location(item->x->computeLength<int>(conversionData), item->y->computeLength<int>(conversionData)); int blur = item->blur ? item->blur->computeLength<int>(conversionData) : 0; Color shadowColor = Color::black; if (item->color) shadowColor = state.document().textLinkColors().colorFromCSSValue(*item->color, state.style()->color()); operations.operations().append(DropShadowFilterOperation::create(location, blur, shadowColor)); break; } default: ASSERT_NOT_REACHED(); break; } } return operations; }