void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionState) { if (string.isEmpty()) return; if (const CSSValue* value = CSSParser::parseSingleValue(CSSPropertyTransform, string)) { // Check for a "none" transform. In these cases we can use the default // identity matrix. if (value->isIdentifierValue() && (toCSSIdentifierValue(value))->getValueID() == CSSValueNone) return; DEFINE_STATIC_REF(ComputedStyle, initialStyle, createInitialStyle()); TransformOperations operations = TransformBuilder::createTransformOperations( *value, CSSToLengthConversionData(initialStyle, initialStyle, LayoutViewItem(nullptr), 1.0f)); // Convert transform operations to a TransformationMatrix. This can fail // if a param has a percentage ('%') if (operations.dependsOnBoxSize()) exceptionState.throwDOMException(SyntaxError, "The transformation depends on the box " "size, which is not supported."); m_matrix = TransformationMatrix::create(); operations.apply(FloatSize(0, 0), *m_matrix); } else { // There is something there but parsing failed. exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'."); } }
void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionState) { if (string.isEmpty()) return; RefPtr<MutableStylePropertySet> styleDeclaration = MutableStylePropertySet::create(); if (BisonCSSParser::parseValue(styleDeclaration.get(), CSSPropertyWebkitTransform, string, true, HTMLStandardMode, 0)) { // Convert to TransformOperations. This can fail if a property // requires style (i.e., param uses 'ems' or 'exs') RefPtrWillBeRawPtr<CSSValue> value = styleDeclaration->getPropertyCSSValue(CSSPropertyWebkitTransform); // Check for a "none" or empty transform. In these cases we can use the default identity matrix. if (!value || (value->isPrimitiveValue() && (toCSSPrimitiveValue(value.get()))->getValueID() == CSSValueNone)) return; DEFINE_STATIC_REF(RenderStyle, defaultStyle, RenderStyle::createDefaultStyle()); TransformOperations operations; if (!TransformBuilder::createTransformOperations(value.get(), CSSToLengthConversionData(defaultStyle, defaultStyle, 0, 0, 1.0f), operations)) { exceptionState.throwDOMException(SyntaxError, "Failed to interpret '" + string + "' as a transformation operation."); return; } // Convert transform operations to a TransformationMatrix. This can fail // if a param has a percentage ('%') if (operations.dependsOnBoxSize()) exceptionState.throwDOMException(SyntaxError, "The transformation depends on the box size, which is not supported."); TransformationMatrix t; operations.apply(FloatSize(0, 0), t); // set the matrix m_matrix = t; } else { // There is something there but parsing failed. exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'."); } }
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; }
ExceptionOr<void> WebKitCSSMatrix::setMatrixValue(const String& string) { if (string.isEmpty()) return { }; auto styleDeclaration = MutableStyleProperties::create(); if (CSSParser::parseValue(styleDeclaration, CSSPropertyTransform, string, true, HTMLStandardMode) == CSSParser::ParseResult::Error) return Exception { SYNTAX_ERR }; // Convert to TransformOperations. This can fail if a property requires style (i.e., param uses 'ems' or 'exs') auto value = styleDeclaration->getPropertyCSSValue(CSSPropertyTransform); // Check for a "none" or empty transform. In these cases we can use the default identity matrix. if (!value || (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).valueID() == CSSValueNone)) return { }; TransformOperations operations; if (!transformsForValue(*value, CSSToLengthConversionData(), operations)) return Exception { SYNTAX_ERR }; // Convert transform operations to a TransformationMatrix. This can fail if a parameter has a percentage ('%'). TransformationMatrix matrix; for (auto& operation : operations.operations()) { if (operation->apply(matrix, IntSize(0, 0))) return Exception { SYNTAX_ERR }; } m_matrix = matrix; return { }; }
Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const { ASSERT(id == CSSPropertyMaxHeight || id == CSSPropertyMinHeight || id == CSSPropertyMaxWidth || id == CSSPropertyMinWidth); RefPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(id); if (!value || !value->isPrimitiveValue()) return Length(); // auto CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); if (primitiveValue->isLength()) return primitiveValue->computeLength<Length>(CSSToLengthConversionData(m_document->renderStyle(), m_document->renderStyle(), 1.0f)); if (primitiveValue->isViewportPercentageLength()) return primitiveValue->viewportPercentageLength(); if (primitiveValue->isPercentage()) return Length(primitiveValue->getFloatValue(), Percent); switch (primitiveValue->getValueID()) { case CSSValueInternalExtendToZoom: return Length(ExtendToZoom); case CSSValueAuto: return Length(); default: // Unrecognized keyword. ASSERT_NOT_REACHED(); return Length(0, Fixed); } }
Length ViewportStyleResolver::viewportLengthValue(CSSPropertyID id) const { ASSERT(id == CSSPropertyMaxHeight || id == CSSPropertyMinHeight || id == CSSPropertyMaxWidth || id == CSSPropertyMinWidth); RefPtrWillBeRawPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(id); if (!value || !value->isPrimitiveValue()) return Length(); // auto CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); if (primitiveValue->getValueID() == CSSValueInternalExtendToZoom) return Length(ExtendToZoom); RenderStyle* documentStyle = m_document->renderStyle(); // If we have viewport units the conversion will mark the document style as having viewport units. bool documentStyleHasViewportUnits = documentStyle->hasViewportUnits(); documentStyle->setHasViewportUnits(false); FrameView* view = m_document->view(); float width = view ? view->width() : 0; float height = view ? view->height() : 0; Length result = primitiveValue->convertToLength<AnyConversion>(CSSToLengthConversionData(documentStyle, documentStyle, width, height, 1.0f)); if (documentStyle->hasViewportUnits()) m_document->setHasViewportUnits(); documentStyle->setHasViewportUnits(documentStyleHasViewportUnits); return result; }
void CSSMatrix::setMatrixValue(const String& string, ExceptionState& exceptionState) { if (string.isEmpty()) return; // FIXME: crbug.com/154772 - should this continue to use legacy style parsing? if (RefPtrWillBeRawPtr<CSSValue> value = CSSParser::parseSingleValue(CSSPropertyWebkitTransform, string)) { // Check for a "none" transform. In these cases we can use the default identity matrix. if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value.get()))->getValueID() == CSSValueNone) return; // FIXME: This has a null pointer crash if we use ex units (crbug.com/414145) DEFINE_STATIC_REF(RenderStyle, defaultStyle, RenderStyle::createDefaultStyle()); TransformOperations operations; if (!TransformBuilder::createTransformOperations(value.get(), CSSToLengthConversionData(defaultStyle, defaultStyle, 0, 0, 1.0f), operations)) { exceptionState.throwDOMException(SyntaxError, "Failed to interpret '" + string + "' as a transformation operation."); return; } // Convert transform operations to a TransformationMatrix. This can fail // if a param has a percentage ('%') if (operations.dependsOnBoxSize()) exceptionState.throwDOMException(SyntaxError, "The transformation depends on the box size, which is not supported."); TransformationMatrix t; operations.apply(FloatSize(0, 0), t); // set the matrix m_matrix = t; } else { // There is something there but parsing failed. exceptionState.throwDOMException(SyntaxError, "Failed to parse '" + string + "'."); } }
CSSToLengthConversionData StyleResolverState::fontSizeConversionData() const { float em = parentStyle()->specifiedFontSize(); float rem = rootElementStyle() ? rootElementStyle()->specifiedFontSize() : 1; CSSToLengthConversionData::FontSizes fontSizes(em, rem, &parentStyle()->font()); CSSToLengthConversionData::ViewportSize viewportSize(document().layoutViewItem()); return CSSToLengthConversionData(style(), fontSizes, viewportSize, 1); }
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 WebKitCSSMatrix::setMatrixValue(const String& string, ExceptionCode& ec) { if (string.isEmpty()) return; RefPtr<MutableStyleProperties> styleDeclaration = MutableStyleProperties::create(); if (CSSParser::parseValue(styleDeclaration.get(), CSSPropertyWebkitTransform, string, true, CSSStrictMode, 0)) { // Convert to TransformOperations. This can fail if a property // requires style (i.e., param uses 'ems' or 'exs') RefPtr<CSSValue> value = styleDeclaration->getPropertyCSSValue(CSSPropertyWebkitTransform); // Check for a "none" or empty transform. In these cases we can use the default identity matrix. if (!value || (value->isPrimitiveValue() && (toCSSPrimitiveValue(value.get()))->getValueID() == CSSValueNone)) return; TransformOperations operations; if (!transformsForValue(value.get(), CSSToLengthConversionData(), operations)) { ec = SYNTAX_ERR; return; } // Convert transform operations to a TransformationMatrix. This can fail // if a param has a percentage ('%') TransformationMatrix t; for (unsigned i = 0; i < operations.operations().size(); ++i) { if (operations.operations()[i].get()->apply(t, IntSize(0, 0))) { ec = SYNTAX_ERR; return; } } // set the matrix m_matrix = t; } else // There is something there but parsing failed. ec = SYNTAX_ERR; }
static float defaultLength(RenderStyle& style, RenderView* view) { return clampTo<float>(CSSPrimitiveValue::computeNonCalcLengthDouble(CSSToLengthConversionData(&style, &style, view), CSSPrimitiveValue::CSS_VW, 100.0)); }
static float defaultLength(RenderStyle& style, RenderView* view) { return CSSPrimitiveValue::create(100, CSSPrimitiveValue::CSS_VW)->computeLength<float>(CSSToLengthConversionData(&style, &style, view)); }