本文整理汇总了C++中ImageResource::addObserver方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageResource::addObserver方法的具体用法?C++ ImageResource::addObserver怎么用?C++ ImageResource::addObserver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageResource
的用法示例。
在下文中一共展示了ImageResource::addObserver方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doUpdateFromElement
void ImageLoader::doUpdateFromElement(BypassMainWorldBehavior bypassBehavior,
UpdateFromElementBehavior updateBehavior,
const KURL& url,
ReferrerPolicy referrerPolicy) {
// FIXME: According to
// http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content.html#the-img-element:the-img-element-55
// When "update image" is called due to environment changes and the load
// fails, onerror should not be called. That is currently not the case.
//
// We don't need to call clearLoader here: Either we were called from the
// task, or our caller updateFromElement cleared the task's loader (and set
// m_pendingTask to null).
m_pendingTask.reset();
// Make sure to only decrement the count when we exit this function
std::unique_ptr<IncrementLoadEventDelayCount> loadDelayCounter;
loadDelayCounter.swap(m_loadDelayCounter);
Document& document = m_element->document();
if (!document.isActive())
return;
AtomicString imageSourceURL = m_element->imageSourceURL();
ImageResource* newImage = nullptr;
if (!url.isNull()) {
// Unlike raw <img>, we block mixed content inside of <picture> or
// <img srcset>.
ResourceLoaderOptions resourceLoaderOptions =
ResourceFetcher::defaultResourceOptions();
ResourceRequest resourceRequest(url);
if (updateBehavior == UpdateForcedReload) {
resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache);
resourceRequest.setLoFiState(WebURLRequest::LoFiOff);
}
if (referrerPolicy != ReferrerPolicyDefault) {
resourceRequest.setHTTPReferrer(SecurityPolicy::generateReferrer(
referrerPolicy, url, document.outgoingReferrer()));
}
if (isHTMLPictureElement(element()->parentNode()) ||
!element()->fastGetAttribute(HTMLNames::srcsetAttr).isNull())
resourceRequest.setRequestContext(WebURLRequest::RequestContextImageSet);
FetchRequest request(resourceRequest, element()->localName(),
resourceLoaderOptions);
configureRequest(request, bypassBehavior, *m_element,
document.clientHintsPreferences());
newImage = ImageResource::fetch(request, document.fetcher());
if (!newImage && !pageIsBeingDismissed(&document)) {
crossSiteOrCSPViolationOccurred(imageSourceURL);
dispatchErrorEvent();
} else {
clearFailedLoadURL();
}
} else {
if (!imageSourceURL.isNull()) {
// Fire an error event if the url string is not empty, but the KURL is.
dispatchErrorEvent();
}
noImageResourceToLoad();
}
ImageResource* oldImage = m_image.get();
if (updateBehavior == UpdateSizeChanged && m_element->layoutObject() &&
m_element->layoutObject()->isImage() && newImage == oldImage) {
toLayoutImage(m_element->layoutObject())->intrinsicSizeChanged();
} else {
if (m_hasPendingLoadEvent) {
loadEventSender().cancelEvent(this);
m_hasPendingLoadEvent = false;
}
// Cancel error events that belong to the previous load, which is now
// cancelled by changing the src attribute. If newImage is null and
// m_hasPendingErrorEvent is true, we know the error event has been just
// posted by this load and we should not cancel the event.
// FIXME: If both previous load and this one got blocked with an error, we
// can receive one error event instead of two.
if (m_hasPendingErrorEvent && newImage) {
errorEventSender().cancelEvent(this);
m_hasPendingErrorEvent = false;
}
m_image = newImage;
m_hasPendingLoadEvent = newImage;
m_imageComplete = !newImage;
updateLayoutObject();
// If newImage exists and is cached, addObserver() will result in the load
// event being queued to fire. Ensure this happens after beforeload is
// dispatched.
if (newImage) {
newImage->addObserver(this);
}
if (oldImage) {
oldImage->removeObserver(this);
}
}
//.........这里部分代码省略.........