float StyleBuilderConverter::convertNumberOrPercentage(StyleResolverState& state, CSSValue* value) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); ASSERT(primitiveValue->isNumber() || primitiveValue->isPercentage()); if (primitiveValue->isNumber()) return primitiveValue->getFloatValue(); return primitiveValue->getFloatValue() / 100.0f; }
static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op) { // FIXME: Possible handle other media types than 'screen' and 'print'. float deviceScaleFactor = 0; // This checks the actual media type applied to the document, and we know // this method only got called if this media type matches the one defined // in the query. Thus, if if the document's media type is "print", the // media type of the query will either be "print" or "all". String mediaType = frame->view()->mediaType(); if (equalIgnoringCase(mediaType, "screen")) deviceScaleFactor = frame->page()->deviceScaleFactor(); else if (equalIgnoringCase(mediaType, "print")) { // The resolution of images while printing should not depend on the dpi // of the screen. Until we support proper ways of querying this info // we use 300px which is considered minimum for current printers. deviceScaleFactor = 3.125; // 300dpi / 96dpi; } if (!value) return !!deviceScaleFactor; if (!value->isPrimitiveValue()) return false; CSSPrimitiveValue* resolution = static_cast<CSSPrimitiveValue*>(value); return compareValue(deviceScaleFactor, resolution->isNumber() ? resolution->getFloatValue() : resolution->getFloatValue(CSSPrimitiveValue::CSS_DPPX), op); }
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; } CSSValueID id = primitiveValue.getValueID(); bool isColor = ((id >= CSSValueAqua && id <= CSSValueTransparent) || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) || id == CSSValueGrey); return (id != CSSValueNone) && !isColor; }
void StyleBuilderFunctions::applyValueCSSPropertyZoom(StyleResolverState& state, CSSValue* value) { ASSERT_WITH_SECURITY_IMPLICATION(value->isPrimitiveValue()); CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->getValueID() == CSSValueNormal) { resetEffectiveZoom(state); state.setZoom(ComputedStyle::initialZoom()); } else if (primitiveValue->getValueID() == CSSValueReset) { state.setEffectiveZoom(ComputedStyle::initialZoom()); state.setZoom(ComputedStyle::initialZoom()); } else if (primitiveValue->getValueID() == CSSValueDocument) { float docZoom = state.rootElementStyle() ? state.rootElementStyle()->zoom() : ComputedStyle::initialZoom(); state.setEffectiveZoom(docZoom); state.setZoom(docZoom); } else if (primitiveValue->isPercentage()) { resetEffectiveZoom(state); if (float percent = primitiveValue->getFloatValue()) state.setZoom(percent / 100.0f); } else if (primitiveValue->isNumber()) { resetEffectiveZoom(state); if (float number = primitiveValue->getFloatValue()) state.setZoom(number); } }
float ViewportStyleResolver::getViewportArgumentValue(CSSPropertyID id) const { float defaultValue = ViewportArguments::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->documentElement()->renderStyle()->fontDescription().computedSize(); if (primitiveValue->isPercentage()) { float percentValue = primitiveValue->getFloatValue() / 100.0f; switch (id) { case CSSPropertyMaxHeight: case CSSPropertyMinHeight: ASSERT(m_document->initialViewportSize().height() > 0); return percentValue * m_document->initialViewportSize().height(); case CSSPropertyMaxWidth: case CSSPropertyMinWidth: ASSERT(m_document->initialViewportSize().width() > 0); return percentValue * m_document->initialViewportSize().width(); case CSSPropertyMaxZoom: case CSSPropertyMinZoom: case CSSPropertyZoom: return percentValue; default: ASSERT_NOT_REACHED(); break; } } switch (primitiveValue->getValueID()) { case CSSValueAuto: return defaultValue; case CSSValueLandscape: return ViewportArguments::ValueLandscape; case CSSValuePortrait: return ViewportArguments::ValuePortrait; case CSSValueZoom: return defaultValue; case CSSValueFixed: return 0; default: return defaultValue; } }
static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const CSSToLengthConversionData& conversionData) { if (value.isNumber()) return value.getDoubleValue(); if (value.isPercentage()) return Length(value.getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); if (value.getValueID() != CSSValueAuto) return value.computeLength<Length>(conversionData); return Length(Auto); }
GridPosition StyleBuilderConverter::convertGridPosition(StyleResolverState&, CSSValue* value) { // We accept the specification's grammar: // 'auto' | [ <integer> || <custom-ident> ] | [ span && [ <integer> || <custom-ident> ] ] | <custom-ident> GridPosition position; if (value->isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); // We translate <custom-ident> to <string> during parsing as it // makes handling it more simple. if (primitiveValue->isString()) { position.setNamedGridArea(primitiveValue->getStringValue()); return position; } ASSERT(primitiveValue->getValueID() == CSSValueAuto); return position; } CSSValueList* values = toCSSValueList(value); ASSERT(values->length()); bool isSpanPosition = false; // The specification makes the <integer> optional, in which case it default to '1'. int gridLineNumber = 1; String gridLineName; CSSValueListIterator it = values; CSSPrimitiveValue* currentValue = toCSSPrimitiveValue(it.value()); if (currentValue->getValueID() == CSSValueSpan) { isSpanPosition = true; it.advance(); currentValue = it.hasMore() ? toCSSPrimitiveValue(it.value()) : 0; } if (currentValue && currentValue->isNumber()) { gridLineNumber = currentValue->getIntValue(); it.advance(); currentValue = it.hasMore() ? toCSSPrimitiveValue(it.value()) : 0; } if (currentValue && currentValue->isString()) { gridLineName = currentValue->getStringValue(); it.advance(); } ASSERT(!it.hasMore()); if (isSpanPosition) position.setSpanPosition(gridLineNumber, gridLineName); else position.setExplicitPosition(gridLineNumber, gridLineName); return position; }
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; CSSValue* value = m_propertySet->getPropertyCSSValue(id); if (!value || !value->isPrimitiveValue()) return defaultValue; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->isNumber() || primitiveValue->isPx()) return primitiveValue->getFloatValue(); if (primitiveValue->isFontRelativeLength()) return primitiveValue->getFloatValue() * m_document->computedStyle()->getFontDescription().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 StyleBuilderFunctions::applyValueCSSPropertyWebkitPerspective(StyleResolverState& state, CSSValue* value) { if (!value->isPrimitiveValue()) return; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->isNumber()) { float perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(state.cssToLengthConversionData()); if (perspectiveValue >= 0.0f) state.style()->setPerspective(perspectiveValue); } else { applyValueCSSPropertyPerspective(state, value); } }
static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op) { // According to MQ4, only 'screen', 'print' and 'speech' may match. // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/issues/348 float actualResolution = 0; // This checks the actual media type applied to the document, and we know // this method only got called if this media type matches the one defined // in the query. Thus, if if the document's media type is "print", the // media type of the query will either be "print" or "all". String mediaType = frame->view()->mediaType(); if (equalIgnoringCase(mediaType, "screen")) actualResolution = clampTo<float>(frame->devicePixelRatio()); else if (equalIgnoringCase(mediaType, "print")) { // The resolution of images while printing should not depend on the DPI // of the screen. Until we support proper ways of querying this info // we use 300px which is considered minimum for current printers. actualResolution = 300 / cssPixelsPerInch; } if (!value) return !!actualResolution; if (!value->isPrimitiveValue()) return false; CSSPrimitiveValue* resolution = toCSSPrimitiveValue(value); if (resolution->isNumber()) return compareValue(actualResolution, resolution->getFloatValue(), op); if (!resolution->isResolution()) return false; if (resolution->isDotsPerCentimeter()) { // To match DPCM to DPPX values, we limit to 2 decimal points. // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends // "that the pixel unit refer to the whole number of device pixels that best // approximates the reference pixel". With that in mind, allowing 2 decimal // point precision seems appropriate. return compareValue( floorf(0.5 + 100 * actualResolution) / 100, floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_DPPX)) / 100, op); } return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitiveValue::CSS_DPPX), op); }
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()); return (primitiveValue.getValueID() != CSSValueNone); }
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; }
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; }
void StyleBuilderFunctions::applyValueCSSPropertyLineHeight(StyleResolverState& state, CSSValue* value) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); Length lineHeight; if (primitiveValue->getValueID() == CSSValueNormal) { lineHeight = RenderStyle::initialLineHeight(); } else if (primitiveValue->isLength()) { lineHeight = primitiveValue->computeLength<Length>(state.cssToLengthConversionData()); } else if (primitiveValue->isPercentage()) { lineHeight = Length((state.style()->computedFontSize() * primitiveValue->getIntValue()) / 100.0, Fixed); } else if (primitiveValue->isNumber()) { lineHeight = Length(primitiveValue->getDoubleValue() * 100.0, Percent); } else if (primitiveValue->isCalculated()) { Length length = Length(primitiveValue->cssCalcValue()->toCalcValue(state.cssToLengthConversionData())); lineHeight = Length(valueForLength(length, state.style()->fontSize()), Fixed); } else { return; } state.style()->setLineHeight(lineHeight); }
static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyle, int& result) { if (!value->isPrimitiveValue()) return false; CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); if (primitiveValue->isNumber()) { result = primitiveValue->getIntValue(); return !strict || !result; } if (primitiveValue->isLength()) { // Relative (like EM) and root relative (like REM) units are always resolved against // the initial values for media queries, hence the two initialStyle parameters. // FIXME: We need to plumb viewport unit support down to here. result = primitiveValue->computeLength<int>(CSSToLengthConversionData(initialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */)); return true; } return false; }
static PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSyntax(CSSFilterValue* filterValue, StyleResolverState& state) { CSSValue* shadersValue = filterValue->itemWithoutBoundsCheck(0); ASSERT_WITH_SECURITY_IMPLICATION(shadersValue->isValueList()); CSSValueList* shadersList = toCSSValueList(shadersValue); unsigned shadersListLength = shadersList->length(); ASSERT(shadersListLength); CSSShaderValue* vertexShader = 0; CSSShaderValue* fragmentShader = 0; if (shadersList->itemWithoutBoundsCheck(0)->isShaderValue()) vertexShader = toCSSShaderValue(shadersList->itemWithoutBoundsCheck(0)); CustomFilterProgramType programType = ProgramTypeBlendsElementTexture; CustomFilterProgramMixSettings mixSettings; if (shadersListLength > 1) { CSSValue* fragmentShaderOrMixFunction = shadersList->itemWithoutBoundsCheck(1); if (fragmentShaderOrMixFunction->isMixFunctionValue()) { CSSMixFunctionValue* mixFunction = toCSSMixFunctionValue(fragmentShaderOrMixFunction); CSSValueListIterator iterator(mixFunction); ASSERT(mixFunction->length()); if (iterator.value()->isShaderValue()) fragmentShader = toCSSShaderValue(iterator.value()); iterator.advance(); ASSERT(mixFunction->length() <= 3); while (iterator.hasMore()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator.value()); if (CSSParser::isBlendMode(primitiveValue->getValueID())) mixSettings.blendMode = *primitiveValue; else if (CSSParser::isCompositeOperator(primitiveValue->getValueID())) mixSettings.compositeOperator = *primitiveValue; else ASSERT_NOT_REACHED(); iterator.advance(); } } else { programType = ProgramTypeNoElementTexture; if (fragmentShaderOrMixFunction->isShaderValue()) fragmentShader = toCSSShaderValue(fragmentShaderOrMixFunction); } } if (!vertexShader && !fragmentShader) return 0; unsigned meshRows = 1; unsigned meshColumns = 1; CustomFilterMeshType meshType = MeshTypeAttached; CSSValue* parametersValue = 0; if (filterValue->length() > 1) { CSSValueListIterator iterator(filterValue->itemWithoutBoundsCheck(1)); // The second value might be the mesh box or the list of parameters: // If it starts with a number or any of the mesh-box identifiers it is // the mesh-box list, if not it means it is the parameters list. if (iterator.hasMore() && iterator.isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator.value()); if (primitiveValue->isNumber()) { // If only one integer value is specified, it will set both // the rows and the columns. meshColumns = meshRows = primitiveValue->getIntValue(); iterator.advance(); // Try to match another number for the rows. if (iterator.hasMore() && iterator.isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator.value()); if (primitiveValue->isNumber()) { meshRows = primitiveValue->getIntValue(); iterator.advance(); } } } } if (iterator.hasMore() && iterator.isPrimitiveValue()) { CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator.value()); if (primitiveValue->getValueID() == CSSValueDetached) { meshType = MeshTypeDetached; iterator.advance(); } } if (!iterator.index()) { // If no value was consumed from the mesh value, then it is just a parameter list, meaning that we end up // having just two CSSListValues: list of shaders and list of parameters. ASSERT(filterValue->length() == 2); parametersValue = filterValue->itemWithoutBoundsCheck(1); } } if (filterValue->length() > 2 && !parametersValue) parametersValue = filterValue->itemWithoutBoundsCheck(2); CustomFilterParameterList parameterList; if (parametersValue && !parseCustomFilterParameterList(parametersValue, parameterList, state)) return 0; RefPtr<CustomFilterProgram> program = createCustomFilterProgram(vertexShader, fragmentShader, programType, mixSettings, meshType, state); return CustomFilterOperation::create(program.release(), parameterList, meshRows, meshColumns, meshType); }