Revert "HTML - picture - does not react to resize/viewport changes"

This reverts commit 60da986bb3828ae8941b2e040cc56a7b35861400.
This commit is contained in:
Pale Moon
2018-03-26 15:42:21 +02:00
committed by Roy Tam
parent dc5fe1974d
commit 2d74614076
10 changed files with 37 additions and 187 deletions
+17 -56
View File
@@ -589,9 +589,6 @@ HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
bool addedToPicture = aParent && aParent->IsHTML(nsGkAtoms::picture) &&
HTMLPictureElement::IsPictureEnabled();
if (addedToPicture) {
if (aDocument) {
aDocument->AddResponsiveContent(this);
}
QueueImageLoadTask();
} else if (!InResponsiveMode() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
@@ -633,18 +630,12 @@ HTMLImageElement::UnbindFromTree(bool aDeep, bool aNullParent)
}
}
if (GetParent() &&
if (aNullParent && GetParent() &&
GetParent()->IsHTML(nsGkAtoms::picture) &&
HTMLPictureElement::IsPictureEnabled()) {
nsIDocument* doc = GetOurOwnerDoc();
if (doc) {
doc->RemoveResponsiveContent(this);
}
// Being removed from picture re-triggers selection, even if we
// weren't using a <source> peer
if (aNullParent) {
QueueImageLoadTask();
}
QueueImageLoadTask();
}
nsImageLoadingContent::UnbindFromTree(aDeep, aNullParent);
@@ -1069,19 +1060,7 @@ HTMLImageElement::UpdateResponsiveSource()
// that and keep it if it's still usable.
mResponsiveSelector->SelectImage(true);
if (mResponsiveSelector->NumCandidates()) {
bool isUsableCandidate = true;
// an otherwise-usable source element may still have a media query that may not
// match any more.
if (candidateSource->IsElement() &&
candidateSource->AsElement()->IsHTML(nsGkAtoms::source) &&
!SourceElementMatches(candidateSource->AsContent())) {
isUsableCandidate = false;
}
if (isUsableCandidate) {
break;
}
break;
}
// no longer valid
@@ -1120,31 +1099,6 @@ HTMLImageElement::SupportedPictureSourceType(const nsAString& aType)
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
}
bool
HTMLImageElement::SourceElementMatches(nsIContent* aSourceNode)
{
MOZ_ASSERT(aSourceNode->IsHTML(nsGkAtoms::source));
DebugOnly<Element *> parent(nsINode::GetParentElement());
MOZ_ASSERT(parent && parent->IsHTML(nsGkAtoms::picture));
MOZ_ASSERT(IsPreviousSibling(aSourceNode, this));
MOZ_ASSERT(HTMLPictureElement::IsPictureEnabled());
// Check media and type
HTMLSourceElement *src = static_cast<HTMLSourceElement*>(aSourceNode);
if (!src->MatchesCurrentMedia()) {
return false;
}
nsAutoString type;
if (aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
!SupportedPictureSourceType(type)) {
return false;
}
return true;
}
bool
HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode,
const nsAString *aSrcset,
@@ -1158,7 +1112,20 @@ HTMLImageElement::TryCreateResponsiveSelector(nsIContent *aSourceNode,
// Skip if this is not a <source> with matching media query
bool isSourceTag = aSourceNode->IsHTML(nsGkAtoms::source);
if (isSourceTag) {
if (!SourceElementMatches(aSourceNode)) {
DebugOnly<Element *> parent(nsINode::GetParentElement());
MOZ_ASSERT(parent && parent->IsHTML(nsGkAtoms::picture));
MOZ_ASSERT(IsPreviousSibling(aSourceNode, this));
MOZ_ASSERT(pictureEnabled);
// Check media and type
HTMLSourceElement *src = static_cast<HTMLSourceElement*>(aSourceNode);
if (!src->MatchesCurrentMedia()) {
return false;
}
nsAutoString type;
if (aSourceNode->GetAttr(kNameSpaceID_None, nsGkAtoms::type, type) &&
!SupportedPictureSourceType(type)) {
return false;
}
} else if (aSourceNode->IsHTML(nsGkAtoms::img)) {
@@ -1279,12 +1246,6 @@ HTMLImageElement::DestroyContent()
mResponsiveSelector = nullptr;
}
void
HTMLImageElement::MediaFeatureValuesChanged()
{
QueueImageLoadTask();
}
} // namespace dom
} // namespace mozilla