static bool parseDescriptors(const CharType* attribute, Vector<DescriptorToken>& descriptors, DescriptorParsingResult& result) { for (Vector<DescriptorToken>::iterator it = descriptors.begin(); it != descriptors.end(); ++it) { if (it->length == 0) continue; CharType c = attribute[it->lastIndex()]; bool isValid = false; if (RuntimeEnabledFeatures::pictureSizesEnabled() && c == 'w') { if (result.hasDensity() || result.hasWidth()) return false; int resourceWidth = it->toInt(attribute, isValid); if (!isValid || resourceWidth <= 0) return false; result.setResourceWidth(resourceWidth); } else if (RuntimeEnabledFeatures::pictureSizesEnabled() && c == 'h') { // This is here only for future compat purposes. // The value of the 'h' descriptor is not used. if (result.hasDensity() || result.hasHeight()) return false; int resourceHeight = it->toInt(attribute, isValid); if (!isValid || resourceHeight <= 0) return false; result.setResourceHeight(resourceHeight); } else if (c == 'x') { if (result.hasDensity() || result.hasHeight() || result.hasWidth()) return false; float density = it->toFloat(attribute, isValid); if (!isValid || density < 0) return false; result.setDensity(density); } } return true; }
static bool parseDescriptors(const CharType* attribute, Vector<DescriptorToken>& descriptors, DescriptorParsingResult& result, Document* document) { for (DescriptorToken& descriptor : descriptors) { if (descriptor.length == 0) continue; CharType c = attribute[descriptor.lastIndex()]; bool isValid = false; if (c == 'w') { if (result.hasDensity() || result.hasWidth()) { srcsetError(document, "it has multiple 'w' descriptors or a mix of 'x' and 'w' descriptors."); return false; } int resourceWidth = descriptor.toInt(attribute, isValid); if (!isValid || resourceWidth <= 0) { srcsetError(document, "its 'w' descriptor is invalid."); return false; } result.setResourceWidth(resourceWidth); } else if (c == 'h') { // This is here only for future compat purposes. // The value of the 'h' descriptor is not used. if (result.hasDensity() || result.hasHeight()) { srcsetError(document, "it has multiple 'h' descriptors or a mix of 'x' and 'h' descriptors."); return false; } int resourceHeight = descriptor.toInt(attribute, isValid); if (!isValid || resourceHeight <= 0) { srcsetError(document, "its 'h' descriptor is invalid."); return false; } result.setResourceHeight(resourceHeight); } else if (c == 'x') { if (result.hasDensity() || result.hasHeight() || result.hasWidth()) { srcsetError(document, "it has multiple 'x' descriptors or a mix of 'x' and 'w'/'h' descriptors."); return false; } float density = descriptor.toFloat(attribute, isValid); if (!isValid || density < 0) { srcsetError(document, "its 'x' descriptor is invalid."); return false; } result.setDensity(density); } else { srcsetError(document, "it has an unknown descriptor."); return false; } } bool res = !result.hasHeight() || result.hasWidth(); if (!res) srcsetError(document, "it has an 'h' descriptor and no 'w' descriptor."); return res; }
static bool parseDescriptors(Vector<StringView>& descriptors, DescriptorParsingResult& result) { for (auto& descriptor : descriptors) { if (descriptor.isEmpty()) continue; unsigned descriptorCharPosition = descriptor.length() - 1; UChar descriptorChar = descriptor[descriptorCharPosition]; descriptor = descriptor.substring(0, descriptorCharPosition); bool isValid = false; if (descriptorChar == 'x') { if (result.hasDensity() || result.hasHeight() || result.hasWidth()) return false; float density = descriptor.toFloat(isValid); if (!isValid || density < 0) return false; result.setDensity(density); } else if (descriptorChar == 'w') { #if ENABLE(PICTURE_SIZES) if (result.hasDensity() || result.hasWidth()) return false; int resourceWidth = descriptor.toInt(isValid); if (!isValid || resourceWidth <= 0) return false; result.setResourceWidth(resourceWidth); #else return false; #endif } else if (descriptorChar == 'h') { #if ENABLE(PICTURE_SIZES) // This is here only for future compat purposes. // The value of the 'h' descriptor is not used. if (result.hasDensity() || result.hasHeight()) return false; int resourceHeight = descriptor.toInt(isValid); if (!isValid || resourceHeight <= 0) return false; result.setResourceHeight(resourceHeight); #else return false; #endif } } return true; }