nsresult HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers) { nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); if (HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { // FIXME: Bug 660963 it would be nice if we could just have // ClearBrokenState update our state and do it fast... ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); // If loading is temporarily disabled, don't even launch MaybeLoadImage. // Otherwise MaybeLoadImage may run later when someone has reenabled // loading. if (LoadingEnabled()) { nsContentUtils::AddScriptRunner( NS_NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); } } return rv; }
nsresult HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers) { nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); if (aParent) { UpdateFormOwner(); } if (HaveSrcsetOrInPicture()) { if (aDocument && !mInDocResponsiveContent) { aDocument->AddResponsiveContent(this); mInDocResponsiveContent = true; } bool forceLoadEvent = HTMLPictureElement::IsPictureEnabled() && aParent && aParent->IsHTMLElement(nsGkAtoms::picture); QueueImageLoadTask(forceLoadEvent); } else if (!InResponsiveMode() && HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { // We skip loading when our attributes were set from parser land, // so trigger a aForce=false load now to check if things changed. // This isn't necessary for responsive mode, since creating the // image load task is asynchronous we don't need to take special // care to avoid doing so when being filled by the parser. // FIXME: Bug 660963 it would be nice if we could just have // ClearBrokenState update our state and do it fast... ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); // We still act synchronously for the non-responsive case (Bug // 1076583), but still need to delay if it is unsafe to run // script. // If loading is temporarily disabled, don't even launch MaybeLoadImage. // Otherwise MaybeLoadImage may run later when someone has reenabled // loading. if (LoadingEnabled()) { nsContentUtils::AddScriptRunner( NS_NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); } } return rv; }
nsresult HTMLImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers) { nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); nsImageLoadingContent::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); if (aParent) { UpdateFormOwner(); } bool haveSrcset = IsSrcsetEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::srcset); if (haveSrcset || HasAttr(kNameSpaceID_None, nsGkAtoms::src)) { // FIXME: Bug 660963 it would be nice if we could just have // ClearBrokenState update our state and do it fast... ClearBrokenState(); RemoveStatesSilently(NS_EVENT_STATE_BROKEN); // We don't handle responsive changes when not bound to a tree, update them // now if necessary if (haveSrcset) { nsAutoString srcset; GetAttr(kNameSpaceID_None, nsGkAtoms::srcset, srcset); UpdateSourceSet(srcset); if (mResponsiveSelector) { nsAutoString src; GetAttr(kNameSpaceID_None, nsGkAtoms::src, src); mResponsiveSelector->SetDefaultSource(src); } } // If loading is temporarily disabled, don't even launch MaybeLoadImage. // Otherwise MaybeLoadImage may run later when someone has reenabled // loading. if (LoadingEnabled()) { nsContentUtils::AddScriptRunner( NS_NewRunnableMethod(this, &HTMLImageElement::MaybeLoadImage)); } } return rv; }
nsresult nsSVGImageElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, PRBool aCompileEventHandlers) { nsresult rv = nsSVGImageElementBase::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href)) { ClearBrokenState(); nsContentUtils::AddScriptRunner( new nsRunnableMethod<nsSVGImageElement>(this, &nsSVGImageElement::MaybeLoadSVGImage)); } return rv; }