Bug 1193349 - Part 1: Force a reload only when a source/img is really inserted into a picture; r=jdm

MozReview-Commit-ID: 4FfTwg1nRFO

--HG--
extra : rebase_source : e6b71dff9e4bee8cc81622b0895fed5aefffd2e6
This commit is contained in:
Edgar Chen 2016-05-04 10:21:45 +08:00
parent 1302887134
commit 914003c3ec
4 changed files with 38 additions and 12 deletions

View File

@ -593,9 +593,10 @@ HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
mInDocResponsiveContent = true;
}
bool forceLoadEvent = HTMLPictureElement::IsPictureEnabled() &&
aParent && aParent->IsHTMLElement(nsGkAtoms::picture);
QueueImageLoadTask(forceLoadEvent);
// Run selection algorithm when an img element is inserted into a document
// in order to react to changes in the environment. See note of
// https://html.spec.whatwg.org/multipage/embedded-content.html#img-environment-changes
QueueImageLoadTask(false);
} else if (!InResponsiveMode() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::src)) {
// We skip loading when our attributes were set from parser land,
@ -1069,6 +1070,10 @@ HTMLImageElement::PictureSourceAdded(nsIContent *aSourceNode)
return;
}
MOZ_ASSERT(aSourceNode == this ||
IsPreviousSibling(aSourceNode, this),
"Should not be getting notifications for non-previous-siblings");
QueueImageLoadTask(true);
}

View File

@ -62,6 +62,35 @@ HTMLPictureElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
}
}
nsresult
HTMLPictureElement::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
{
nsresult rv = nsGenericHTMLElement::InsertChildAt(aKid, aIndex, aNotify);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(aKid, rv);
if (aKid->IsHTMLElement(nsGkAtoms::img)) {
HTMLImageElement* img = HTMLImageElement::FromContent(aKid);
if (img) {
img->PictureSourceAdded(aKid->AsContent());
}
} else if (aKid->IsHTMLElement(nsGkAtoms::source)) {
// Find all img siblings after this <source> to notify them of its insertion
nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
if (nextSibling && nextSibling->GetParentNode() == this) {
do {
HTMLImageElement* img = HTMLImageElement::FromContent(nextSibling);
if (img) {
img->PictureSourceAdded(aKid->AsContent());
}
} while ( (nextSibling = nextSibling->GetNextSibling()) );
}
}
return rv;
}
bool
HTMLPictureElement::IsPictureEnabled()
{

View File

@ -30,6 +30,7 @@ public:
virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult) const override;
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) override;
virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify) override;
static bool IsPictureEnabled();

View File

@ -173,15 +173,6 @@ HTMLSourceElement::BindToTree(nsIDocument *aDocument,
if (aParent && aParent->IsNodeOfType(nsINode::eMEDIA)) {
HTMLMediaElement* media = static_cast<HTMLMediaElement*>(aParent);
media->NotifyAddedSource();
} else if (aParent && aParent->IsHTMLElement(nsGkAtoms::picture)) {
// Find any img siblings after this <source> and notify them
nsCOMPtr<nsIContent> sibling = AsContent();
while ( (sibling = sibling->GetNextSibling()) ) {
if (sibling->IsHTMLElement(nsGkAtoms::img)) {
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
img->PictureSourceAdded(AsContent());
}
}
}
return NS_OK;