float ViewportStyleResolver::viewportArgumentValue(CSSPropertyID id) const { float defaultValue = ViewportDescription::ValueAuto; // UserZoom default value is CSSValueZoom, which maps to true, meaning that // yes, it is user scalable. When the value is set to CSSValueFixed, we // return false. if (id == CSSPropertyUserZoom) defaultValue = 1; RefPtr<CSSValue> value = m_propertySet->getPropertyCSSValue(id); if (!value || !value->isPrimitiveValue()) return defaultValue; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); if (primitiveValue->isNumber() || primitiveValue->isPx()) return primitiveValue->getFloatValue(); if (primitiveValue->isFontRelativeLength()) return primitiveValue->getFloatValue() * m_document->renderStyle()->fontDescription().computedSize(); if (primitiveValue->isPercentage()) { float percentValue = primitiveValue->getFloatValue() / 100.0f; switch (id) { case CSSPropertyMaxZoom: case CSSPropertyMinZoom: case CSSPropertyZoom: return percentValue; default: ASSERT_NOT_REACHED(); break; } } switch (primitiveValue->getValueID()) { case CSSValueAuto: return defaultValue; case CSSValueLandscape: return ViewportDescription::ValueLandscape; case CSSValuePortrait: return ViewportDescription::ValuePortrait; case CSSValueZoom: return defaultValue; case CSSValueInternalExtendToZoom: return ViewportDescription::ValueExtendToZoom; case CSSValueFixed: return 0; default: return defaultValue; } }
void CSSToStyleMap::mapNinePieceImageRepeat(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); }
static v8::Handle<v8::Value> setFloatValueCallback(const v8::Arguments& args) { INC_STATS("DOM.CSSPrimitiveValue.setFloatValue"); CSSPrimitiveValue* imp = V8CSSPrimitiveValue::toNative(args.Holder()); ExceptionCode ec = 0; { EXCEPTION_BLOCK(int, unitType, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined))); EXCEPTION_BLOCK(float, floatValue, static_cast<float>(MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)->NumberValue())); imp->setFloatValue(unitType, floatValue, ec); if (UNLIKELY(ec)) goto fail; return v8::Handle<v8::Value>(); } fail: V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
void StyleBuilderFunctions::applyValueCSSPropertyWebkitClipPath(StyleResolverState& state, CSSValue* value) { if (value->isBasicShapeValue()) { state.style()->setClipPath(ShapeClipPathOperation::create(basicShapeForValue(state, *value))); } if (value->isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->getValueID() == CSSValueNone) { state.style()->setClipPath(nullptr); } else if (primitiveValue->isURI()) { String cssURLValue = primitiveValue->getStringValue(); KURL url = state.document().completeURL(cssURLValue); // FIXME: It doesn't work with forward or external SVG references (see https://bugs.webkit.org/show_bug.cgi?id=90405) state.style()->setClipPath(ReferenceClipPathOperation::create(cssURLValue, AtomicString(url.fragmentIdentifier()))); } } }
void CSSToStyleMap::mapAnimationTimingFunction(Animation* animation, CSSValue* value) { if (value->isInitialValue()) { animation->setTimingFunction(Animation::initialAnimationTimingFunction()); return; } if (value->isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); switch (primitiveValue->getValueID()) { case CSSValueLinear: animation->setTimingFunction(LinearTimingFunction::create()); break; case CSSValueEase: animation->setTimingFunction(CubicBezierTimingFunction::create()); break; case CSSValueEaseIn: animation->setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseIn)); break; case CSSValueEaseOut: animation->setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseOut)); break; case CSSValueEaseInOut: animation->setTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::EaseInOut)); break; case CSSValueStepStart: animation->setTimingFunction(StepsTimingFunction::create(1, true)); break; case CSSValueStepEnd: animation->setTimingFunction(StepsTimingFunction::create(1, false)); break; default: break; } return; } if (value->isCubicBezierTimingFunctionValue()) { CSSCubicBezierTimingFunctionValue* cubicTimingFunction = static_cast<CSSCubicBezierTimingFunctionValue*>(value); animation->setTimingFunction(CubicBezierTimingFunction::create(cubicTimingFunction->x1(), cubicTimingFunction->y1(), cubicTimingFunction->x2(), cubicTimingFunction->y2())); } else if (value->isStepsTimingFunctionValue()) { CSSStepsTimingFunctionValue* stepsTimingFunction = static_cast<CSSStepsTimingFunctionValue*>(value); animation->setTimingFunction(StepsTimingFunction::create(stepsTimingFunction->numberOfSteps(), stepsTimingFunction->stepAtStart())); } else if (value->isLinearTimingFunctionValue()) animation->setTimingFunction(LinearTimingFunction::create()); }
static v8::Handle<v8::Value> setStringValueCallback(const v8::Arguments& args) { INC_STATS("DOM.CSSPrimitiveValue.setStringValue"); CSSPrimitiveValue* imp = V8CSSPrimitiveValue::toNative(args.Holder()); ExceptionCode ec = 0; { EXCEPTION_BLOCK(int, stringType, toUInt32(MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined))); STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, stringValue, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)); imp->setStringValue(stringType, stringValue, ec); if (UNLIKELY(ec)) goto fail; return v8::Handle<v8::Value>(); } fail: V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
void StyleBuilderFunctions::applyValueCSSPropertyTransformOrigin(StyleResolverState& state, CSSValue* value) { CSSValueList* list = toCSSValueList(value); ASSERT(list->length() == 3); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(list->item(0)); if (primitiveValue->isValueID()) { switch (primitiveValue->getValueID()) { case CSSValueLeft: state.style()->setTransformOriginX(Length(0, Percent)); break; case CSSValueRight: state.style()->setTransformOriginX(Length(100, Percent)); break; case CSSValueCenter: state.style()->setTransformOriginX(Length(50, Percent)); break; default: ASSERT_NOT_REACHED(); } } else { state.style()->setTransformOriginX(StyleBuilderConverter::convertLength(state, primitiveValue)); } primitiveValue = toCSSPrimitiveValue(list->item(1)); if (primitiveValue->isValueID()) { switch (primitiveValue->getValueID()) { case CSSValueTop: state.style()->setTransformOriginY(Length(0, Percent)); break; case CSSValueBottom: state.style()->setTransformOriginY(Length(100, Percent)); break; case CSSValueCenter: state.style()->setTransformOriginY(Length(50, Percent)); break; default: ASSERT_NOT_REACHED(); } } else { state.style()->setTransformOriginY(StyleBuilderConverter::convertLength(state, primitiveValue)); } primitiveValue = toCSSPrimitiveValue(list->item(2)); state.style()->setTransformOriginZ(StyleBuilderConverter::convertComputedLength<float>(state, primitiveValue)); }
FontDescription::VariantLigatures StyleBuilderConverter::convertFontVariantLigatures(StyleResolverState&, CSSValue* value) { if (value->isValueList()) { FontDescription::VariantLigatures ligatures; CSSValueList* valueList = toCSSValueList(value); for (size_t i = 0; i < valueList->length(); ++i) { CSSValue* item = valueList->item(i); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item); switch (primitiveValue->getValueID()) { case CSSValueNoCommonLigatures: ligatures.common = FontDescription::DisabledLigaturesState; break; case CSSValueCommonLigatures: ligatures.common = FontDescription::EnabledLigaturesState; break; case CSSValueNoDiscretionaryLigatures: ligatures.discretionary = FontDescription::DisabledLigaturesState; break; case CSSValueDiscretionaryLigatures: ligatures.discretionary = FontDescription::EnabledLigaturesState; break; case CSSValueNoHistoricalLigatures: ligatures.historical = FontDescription::DisabledLigaturesState; break; case CSSValueHistoricalLigatures: ligatures.historical = FontDescription::EnabledLigaturesState; break; case CSSValueNoContextual: ligatures.contextual = FontDescription::DisabledLigaturesState; break; case CSSValueContextual: ligatures.contextual = FontDescription::EnabledLigaturesState; break; default: ASSERT_NOT_REACHED(); break; } } return ligatures; } ASSERT_WITH_SECURITY_IMPLICATION(value->isPrimitiveValue()); ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNormal); return FontDescription::VariantLigatures(); }
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())); }
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>(m_document->renderStyle(), m_document->renderStyle()); 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); } }
bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const { if (type() != other.type()) return false; switch (type()) { case UnitType::Unknown: return false; case UnitType::Number: case UnitType::Percentage: case UnitType::Ems: case UnitType::Exs: case UnitType::Rems: case UnitType::Pixels: case UnitType::Centimeters: case UnitType::DotsPerPixel: case UnitType::DotsPerInch: case UnitType::DotsPerCentimeter: case UnitType::Millimeters: case UnitType::Inches: case UnitType::Points: case UnitType::Picas: case UnitType::Degrees: case UnitType::Radians: case UnitType::Gradians: case UnitType::Milliseconds: case UnitType::Seconds: case UnitType::Hertz: case UnitType::Kilohertz: case UnitType::Turns: case UnitType::ViewportWidth: case UnitType::ViewportHeight: case UnitType::ViewportMin: case UnitType::ViewportMax: case UnitType::Fraction: return m_value.num == other.m_value.num; case UnitType::PropertyID: return m_value.propertyID == other.m_value.propertyID; case UnitType::ValueID: return m_value.valueID == other.m_value.valueID; case UnitType::CustomIdentifier: case UnitType::String: case UnitType::URI: return equal(m_value.string, other.m_value.string); case UnitType::RGBColor: return m_value.rgbcolor == other.m_value.rgbcolor; case UnitType::Calc: return m_value.calc && other.m_value.calc && m_value.calc->equals(*other.m_value.calc); case UnitType::Integer: case UnitType::Chs: case UnitType::CalcPercentageWithNumber: case UnitType::CalcPercentageWithLength: case UnitType::QuirkyEms: return false; } return false; }
LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) { if (!value || !value->isPrimitiveValue()) return LengthBox(); // Get our zoom value. CSSToLengthConversionData conversionData = useSVGZoomRules() ? m_resolver->state().cssToLengthConversionData().copyWithAdjustedZoom(1.0f) : m_resolver->state().cssToLengthConversionData(); // Retrieve the primitive value. CSSPrimitiveValue* borderWidths = toCSSPrimitiveValue(value); // Set up a length box to represent our image slices. LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below. Quad* slices = borderWidths->getQuadValue(); if (slices->top()->isNumber()) box.m_top = Length(slices->top()->getIntValue(), Relative); else if (slices->top()->isPercentage()) box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->top()->getValueID() != CSSValueAuto) box.m_top = slices->top()->computeLength<Length>(conversionData); if (slices->right()->isNumber()) box.m_right = Length(slices->right()->getIntValue(), Relative); else if (slices->right()->isPercentage()) box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->right()->getValueID() != CSSValueAuto) box.m_right = slices->right()->computeLength<Length>(conversionData); if (slices->bottom()->isNumber()) box.m_bottom = Length(slices->bottom()->getIntValue(), Relative); else if (slices->bottom()->isPercentage()) box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->bottom()->getValueID() != CSSValueAuto) box.m_bottom = slices->bottom()->computeLength<Length>(conversionData); if (slices->left()->isNumber()) box.m_left = Length(slices->left()->getIntValue(), Relative); else if (slices->left()->isPercentage()) box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->left()->getValueID() != CSSValueAuto) box.m_left = slices->left()->computeLength<Length>(conversionData); return box; }
LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value) { if (!value || !value->isPrimitiveValue()) return LengthBox(); // Get our zoom value. float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom(); // Retrieve the primitive value. CSSPrimitiveValue* borderWidths = static_cast<CSSPrimitiveValue*>(value); // Set up a length box to represent our image slices. LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below. Quad* slices = borderWidths->getQuadValue(); if (slices->top()->isNumber()) box.m_top = Length(slices->top()->getIntValue(), Relative); else if (slices->top()->isPercentage()) box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->top()->getValueID() != CSSValueAuto) box.m_top = slices->top()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->right()->isNumber()) box.m_right = Length(slices->right()->getIntValue(), Relative); else if (slices->right()->isPercentage()) box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->right()->getValueID() != CSSValueAuto) box.m_right = slices->right()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->bottom()->isNumber()) box.m_bottom = Length(slices->bottom()->getIntValue(), Relative); else if (slices->bottom()->isPercentage()) box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->bottom()->getValueID() != CSSValueAuto) box.m_bottom = slices->bottom()->computeLength<Length>(style(), rootElementStyle(), zoom); if (slices->left()->isNumber()) box.m_left = Length(slices->left()->getIntValue(), Relative); else if (slices->left()->isPercentage()) box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if (slices->left()->getValueID() != CSSValueAuto) box.m_left = slices->left()->computeLength<Length>(style(), rootElementStyle(), zoom); return box; }
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); }
static bool computeLength(CSSValue* value, bool strict, const CSSToLengthConversionData& conversionData, int& result) { if (!value->isPrimitiveValue()) return false; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->isNumber()) { result = primitiveValue->getIntValue(); return !strict || !result; } if (primitiveValue->isLength()) { result = primitiveValue->computeLength<int>(conversionData); return true; } return false; }
SVGLengthValue SVGLengthValue::fromCSSPrimitiveValue(const CSSPrimitiveValue& value) { SVGLengthType type; switch (value.primitiveType()) { case CSSPrimitiveValue::CSS_NUMBER: type = LengthTypeNumber; break; case CSSPrimitiveValue::CSS_PERCENTAGE: type = LengthTypePercentage; break; case CSSPrimitiveValue::CSS_EMS: type = LengthTypeEMS; break; case CSSPrimitiveValue::CSS_EXS: type = LengthTypeEXS; break; case CSSPrimitiveValue::CSS_PX: type = LengthTypePX; break; case CSSPrimitiveValue::CSS_CM: type = LengthTypeCM; break; case CSSPrimitiveValue::CSS_MM: type = LengthTypeMM; break; case CSSPrimitiveValue::CSS_IN: type = LengthTypeIN; break; case CSSPrimitiveValue::CSS_PT: type = LengthTypePT; break; case CSSPrimitiveValue::CSS_PC: type = LengthTypePC; break; case CSSPrimitiveValue::CSS_UNKNOWN: default: return { }; }; SVGLengthValue length; length.newValueSpecifiedUnits(type, value.floatValue()); return length; }
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(); }
KCDashArray KSVGPainterFactory::dashArrayFromRenderingStyle(const RenderStyle* style) { KCDashArray array; CSSValueList* dashes = style->svgStyle()->strokeDashArray(); if (dashes) { CSSPrimitiveValue* dash = 0; unsigned long len = dashes->length(); for (unsigned long i = 0; i < len; i++) { dash = static_cast<CSSPrimitiveValue*>(dashes->item(i)); if (!dash) continue; array.append(dash->computeLengthFloat(const_cast<RenderStyle*>(style))); } } return array; }
void StyleBuilder::applyProperty(CSSPropertyID id, StyleResolverState& state, CSSValue* value) { ASSERT_WITH_MESSAGE(!isExpandedShorthand(id), "Shorthand property id = %d wasn't expanded at parsing time", id); bool isInherit = state.parentNode() && value->isInheritedValue(); bool isInitial = value->isInitialValue() || (!state.parentNode() && value->isInheritedValue()); ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInherit -> (state.parentNode() && state.parentStyle()) CSSPrimitiveValue* primitiveValue = value->isPrimitiveValue() ? toCSSPrimitiveValue(value) : 0; if (primitiveValue && primitiveValue->getValueID() == CSSValueCurrentcolor) state.style()->setHasCurrentColor(); if (isInherit && !state.parentStyle()->hasExplicitlyInheritedProperties() && !CSSPropertyMetadata::isInheritedProperty(id)) state.parentStyle()->setHasExplicitlyInheritedProperties(); StyleBuilder::applyProperty(id, state, value, isInitial, isInherit); }
static bool computeLength(CSSValue* value, bool strict, RenderStyle* style, RenderStyle* rootStyle, int& result) { if (!value->isPrimitiveValue()) return false; CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); if (primitiveValue->isNumber()) { result = primitiveValue->getIntValue(); return !strict || !result; } if (primitiveValue->isLength()) { result = primitiveValue->computeLength<int>(style, rootStyle); return true; } return false; }
DashArray dashArrayFromRenderingStyle(const RenderStyle* style, RenderStyle* rootStyle) { DashArray array; CSSValueList* dashes = style->svgStyle()->strokeDashArray(); if (dashes) { CSSPrimitiveValue* dash = 0; unsigned long len = dashes->length(); for (unsigned long i = 0; i < len; i++) { dash = static_cast<CSSPrimitiveValue*>(dashes->itemWithoutBoundsCheck(i)); if (!dash) continue; array.append((float) dash->computeLengthFloat(const_cast<RenderStyle*>(style), rootStyle)); } } return array; }
EGlyphOrientation StyleBuilderConverter::convertGlyphOrientation(StyleResolverState&, CSSValue* value) { if (!value->isPrimitiveValue()) return GO_0DEG; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_DEG) return GO_0DEG; float angle = fabsf(fmodf(primitiveValue->getFloatValue(), 360.0f)); if (angle <= 45.0f || angle > 315.0f) return GO_0DEG; if (angle > 45.0f && angle <= 135.0f) return GO_90DEG; if (angle > 135.0f && angle <= 225.0f) return GO_180DEG; return GO_270DEG; }
float SVGRenderStyle::cssPrimitiveToLength(const RenderObject* item, CSSValue* value, float defaultValue) { CSSPrimitiveValue* primitive = static_cast<CSSPrimitiveValue*>(value); unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) CSSPrimitiveValue::CSS_UNKNOWN); if (!(cssType > CSSPrimitiveValue::CSS_UNKNOWN && cssType <= CSSPrimitiveValue::CSS_PC)) return defaultValue; if (cssType == CSSPrimitiveValue::CSS_PERCENTAGE) { SVGStyledElement* element = static_cast<SVGStyledElement*>(item->node()); SVGElement* viewportElement = (element ? element->viewportElement() : 0); if (viewportElement) { float result = primitive->getFloatValue() / 100.0f; return SVGLength::PercentageOfViewport(result, element, LengthModeOther); } } return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()), item->document()->documentElement()->renderStyle()); }
SVGParsingError SVGLength::setValueAsString(const String& string) { if (string.isEmpty()) { m_value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::UserUnits); return SVGParseStatus::NoError; } CSSParserContext svgParserContext(SVGAttributeMode, nullptr); CSSValue* parsed = CSSParser::parseSingleValue(CSSPropertyX, string, svgParserContext); if (!parsed || !parsed->isPrimitiveValue()) return SVGParseStatus::ExpectedLength; CSSPrimitiveValue* newValue = toCSSPrimitiveValue(parsed); // TODO(fs): Enable calc for SVG lengths if (newValue->isCalculated() || !isSupportedCSSUnitType(newValue->typeWithCalcResolved())) return SVGParseStatus::ExpectedLength; m_value = newValue; return SVGParseStatus::NoError; }
static void addResolutionWarningMessageToConsole(Document& document, const String& serializedExpression, const CSSPrimitiveValue& value) { static NeverDestroyed<String> mediaQueryMessage(ASCIILiteral("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: ")); static NeverDestroyed<String> mediaValueDPI(ASCIILiteral("dpi")); static NeverDestroyed<String> mediaValueDPCM(ASCIILiteral("dpcm")); static NeverDestroyed<String> lengthUnitInch(ASCIILiteral("inch")); static NeverDestroyed<String> lengthUnitCentimeter(ASCIILiteral("centimeter")); String message; if (value.isDotsPerInch()) message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPI).replace("%lengthUnit%", lengthUnitInch); else if (value.isDotsPerCentimeter()) message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter); else ASSERT_NOT_REACHED(); message.append(serializedExpression); document.addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message); }
void CSSToStyleMap::mapAnimationAdditive(Animation* layer, CSSValue* value) { if (value->isInitialValue()) { layer->setAdditive(Animation::initialAnimationAdditive()); return; } if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); switch (primitiveValue->getIdent()) { case CSSValueReplace: layer->setAdditive(AnimationAdditiveReplace); break; case CSSValueAdditive: layer->setAdditive(AnimationAdditiveAdditive); break; } }
void StyleBuilderFunctions::applyValueCSSPropertyTextAlign(StyleResolverState& state, CSSValue* value) { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); // FIXME : Per http://www.w3.org/TR/css3-text/#text-align0 can now take <string> but this is not implemented in the // rendering code. if (primitiveValue->isString()) return; if (primitiveValue->isValueID() && primitiveValue->getValueID() != CSSValueWebkitMatchParent) state.style()->setTextAlign(*primitiveValue); else if (state.parentStyle()->textAlign() == TASTART) state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? LEFT : RIGHT); else if (state.parentStyle()->textAlign() == TAEND) state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? RIGHT : LEFT); else state.style()->setTextAlign(state.parentStyle()->textAlign()); }
virtual void applyValue(CSSStyleSelector* selector, CSSValue* value) const { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); FontDescription fontDescription = selector->fontDescription(); switch (primitiveValue->getIdent()) { case CSSValueInvalid: ASSERT_NOT_REACHED(); break; case CSSValueBolder: fontDescription.setWeight(fontDescription.bolderWeight()); break; case CSSValueLighter: fontDescription.setWeight(fontDescription.lighterWeight()); break; default: fontDescription.setWeight(*primitiveValue); } selector->setFontDescription(fontDescription); }
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())); }
PassRefPtrWillBeRawPtr<AnimatableLength> AnimatableLength::create(CSSValue* value) { ASSERT(canCreateFrom(value)); if (value->isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = WebCore::toCSSPrimitiveValue(value); const CSSCalcValue* calcValue = primitiveValue->cssCalcValue(); if (calcValue) return create(calcValue->expressionNode(), primitiveValue); CSSPrimitiveValue::LengthUnitType unitType; bool isPrimitiveLength = CSSPrimitiveValue::unitTypeToLengthUnitType(primitiveValue->primitiveType(), unitType); ASSERT_UNUSED(isPrimitiveLength, isPrimitiveLength); const double scale = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(primitiveValue->primitiveType()); return create(primitiveValue->getDoubleValue() * scale, unitType, primitiveValue); } if (value->isCalcValue()) return create(toCSSCalcValue(value)->expressionNode()); ASSERT_NOT_REACHED(); return nullptr; }