Bug 1608905 - Parse the HTMLImageElement.loading attribute. r=smaug

Behind a pref of course. Toggle that pref on on the loading/lazyload test
subdirectory, though there are no tests for the IDL (I guess once the spec PR
lands the existing IDL tests will be updated from the spec).

Differential Revision: https://phabricator.services.mozilla.com/D59764
This commit is contained in:
Emilio Cobos Álvarez
2020-01-13 21:10:43 +00:00
parent 2b012cd24d
commit 86efcb5306
6 changed files with 39 additions and 1 deletions

View File

@@ -193,6 +193,16 @@ void HTMLImageElement::GetDecoding(nsAString& aValue) {
GetEnumAttr(nsGkAtoms::decoding, kDecodingTableDefault->tag, aValue);
}
// https://whatpr.org/html/3752/urls-and-fetching.html#lazy-loading-attributes
static const nsAttrValue::EnumTable kLoadingTable[] = {
{"eager", HTMLImageElement::Loading::Eager},
{"lazy", HTMLImageElement::Loading::Lazy},
{nullptr, 0}};
void HTMLImageElement::GetLoading(nsAString& aValue) const {
GetEnumAttr(nsGkAtoms::loading, kLoadingTable[0].tag, aValue);
}
already_AddRefed<Promise> HTMLImageElement::Decode(ErrorResult& aRv) {
return nsImageLoadingContent::QueueDecodeAsync(aRv);
}
@@ -210,9 +220,15 @@ bool HTMLImageElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
return true;
}
if (aAttribute == nsGkAtoms::decoding) {
return aResult.ParseEnumValue(aValue, kDecodingTable, false,
return aResult.ParseEnumValue(aValue, kDecodingTable,
/* aCaseSensitive = */ false,
kDecodingTableDefault);
}
if (aAttribute == nsGkAtoms::loading) {
return aResult.ParseEnumValue(aValue, kLoadingTable,
/* aCaseSensitive = */ false,
kLoadingTable);
}
if (ParseImageAttribute(aAttribute, aValue, aResult)) {
return true;
}