Bug 1067345 - Part 2 - Add HTMLImageElement::SelectSourceForTagWithAttrs to do <picture> source selection without a DOM

This commit is contained in:
John Schoenick
2014-12-10 18:53:00 -05:00
parent 96f84bfdfe
commit 73294b7f47
4 changed files with 145 additions and 4 deletions

View File

@@ -55,6 +55,25 @@ HTMLSourceElement::MatchesCurrentMedia()
return true;
}
/* static */ bool
HTMLSourceElement::WouldMatchMediaForDocument(const nsAString& aMedia,
const nsIDocument *aDocument)
{
if (aMedia.IsEmpty()) {
return true;
}
nsIPresShell* presShell = aDocument->GetShell();
nsPresContext* pctx = presShell ? presShell->GetPresContext() : nullptr;
MOZ_ASSERT(pctx, "Called for document with no prescontext");
nsCSSParser cssParser;
nsRefPtr<nsMediaList> mediaList = new nsMediaList();
cssParser.ParseMediaList(aMedia, nullptr, 0, mediaList, false);
return pctx && mediaList->Matches(pctx, nullptr);
}
nsresult
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)