static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID propertyId, const String& string, CSSParserMode cssParserMode) { ASSERT(!string.isEmpty()); bool acceptsNegativeNumbers = false; // In @viewport, width and height are shorthands, not simple length values. if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) return nullptr; unsigned length = string.length(); double number; CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::CSS_NUMBER; if (string.is8Bit()) { if (!parseSimpleLength(string.characters8(), length, unit, number)) return nullptr; } else { if (!parseSimpleLength(string.characters16(), length, unit, number)) return nullptr; } if (unit == CSSPrimitiveValue::CSS_NUMBER) { bool quirksMode = isQuirksModeBehavior(cssParserMode); if (number && !quirksMode) return nullptr; unit = CSSPrimitiveValue::CSS_PX; } if (number < 0 && !acceptsNegativeNumbers) return nullptr; return cssValuePool().createValue(number, unit); }
static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId, const String& string, CSSParserMode cssParserMode) { ASSERT(!string.isEmpty()); bool acceptsNegativeNumbers = false; // In @viewport, width and height are shorthands, not simple length values. if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) return nullptr; unsigned length = string.length(); double number; CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::UnitType::Number; if (string.is8Bit()) { if (!parseSimpleLength(string.characters8(), length, unit, number)) return nullptr; } else { if (!parseSimpleLength(string.characters16(), length, unit, number)) return nullptr; } if (unit == CSSPrimitiveValue::UnitType::Number) { if (cssParserMode == SVGAttributeMode) unit = CSSPrimitiveValue::UnitType::UserUnits; else if (!number) unit = CSSPrimitiveValue::UnitType::Pixels; else return nullptr; } if (number < 0 && !acceptsNegativeNumbers) return nullptr; return CSSPrimitiveValue::create(number, unit); }
static bool parseTransformTranslateArguments(CharType*& pos, CharType* end, unsigned expectedCount, CSSFunctionValue* transformValue) { while (expectedCount) { size_t delimiter = WTF::find(pos, end - pos, expectedCount == 1 ? ')' : ','); if (delimiter == kNotFound) return false; unsigned argumentLength = static_cast<unsigned>(delimiter); CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::CSS_NUMBER; double number; if (!parseSimpleLength(pos, argumentLength, unit, number)) return false; if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER)) return false; transformValue->append(cssValuePool().createValue(number, CSSPrimitiveValue::CSS_PX)); pos += argumentLength + 1; --expectedCount; } return true; }