From 53cf12d6d808c80c4ce240cbbf8d29344c8ce644 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 12 Jul 2018 18:56:16 +0200 Subject: Bug 1346501. Don't mark every image as visible when a frame is created for it --- dom/base/nsImageLoadingContent.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'dom/base/nsImageLoadingContent.cpp') diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index d25dd6319..b76bc533f 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -491,8 +491,8 @@ nsImageLoadingContent::FrameCreated(nsIFrame* aFrame) mFrameCreateCalled = true; - TrackImage(mCurrentRequest); - TrackImage(mPendingRequest); + TrackImage(mCurrentRequest, aFrame); + TrackImage(mPendingRequest, aFrame); // We need to make sure that our image request is registered, if it should // be registered. @@ -1486,7 +1486,8 @@ nsImageLoadingContent::OnVisibilityChange(Visibility aNewVisibility, } void -nsImageLoadingContent::TrackImage(imgIRequest* aImage) +nsImageLoadingContent::TrackImage(imgIRequest* aImage, + nsIFrame* aFrame /*= nullptr */) { if (!aImage) return; @@ -1499,13 +1500,21 @@ nsImageLoadingContent::TrackImage(imgIRequest* aImage) return; } - // We only want to track this request if we're visible. Ordinarily we check - // the visible count, but that requires a frame; in cases where - // GetOurPrimaryFrame() cannot obtain a frame (e.g. ), we assume - // we're visible if FrameCreated() was called. - nsIFrame* frame = GetOurPrimaryFrame(); - if ((frame && frame->GetVisibility() == Visibility::APPROXIMATELY_NONVISIBLE) || - (!frame && !mFrameCreateCalled)) { + if (!aFrame) { + aFrame = GetOurPrimaryFrame(); + } + + /* This line is deceptively simple. It hides a lot of subtlety. Before we + * create an nsImageFrame we call nsImageFrame::ShouldCreateImageFrameFor + * to determine if we should create an nsImageFrame or create a frame based + * on the display of the element (ie inline, block, etc). Inline, block, etc + * frames don't register for visibility tracking so they will return UNTRACKED + * from GetVisibility(). So this line is choosing to mark such images as + * visible. Once the image loads we will get an nsImageFrame and the proper + * visibility. This is a pitfall of tracking the visibility on the frames + * instead of the content node. + */ + if (!aFrame || aFrame->GetVisibility() == Visibility::APPROXIMATELY_NONVISIBLE) { return; } -- cgit v1.2.3 From 3945eb4c1d15a3232bb340b7348006a220398ebd Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 12 Jul 2018 18:57:25 +0200 Subject: Bug 1346501. Remove mFrameCreateCalled from nsImageLoadingContent, it is now unused --- dom/base/nsImageLoadingContent.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'dom/base/nsImageLoadingContent.cpp') diff --git a/dom/base/nsImageLoadingContent.cpp b/dom/base/nsImageLoadingContent.cpp index b76bc533f..0c6c37b44 100644 --- a/dom/base/nsImageLoadingContent.cpp +++ b/dom/base/nsImageLoadingContent.cpp @@ -94,8 +94,7 @@ nsImageLoadingContent::nsImageLoadingContent() mNewRequestsWillNeedAnimationReset(false), mStateChangerDepth(0), mCurrentRequestRegistered(false), - mPendingRequestRegistered(false), - mFrameCreateCalled(false) + mPendingRequestRegistered(false) { if (!nsContentUtils::GetImgLoaderForChannel(nullptr, nullptr)) { mLoadingEnabled = false; @@ -489,8 +488,6 @@ nsImageLoadingContent::FrameCreated(nsIFrame* aFrame) { NS_ASSERTION(aFrame, "aFrame is null"); - mFrameCreateCalled = true; - TrackImage(mCurrentRequest, aFrame); TrackImage(mPendingRequest, aFrame); @@ -513,8 +510,6 @@ nsImageLoadingContent::FrameDestroyed(nsIFrame* aFrame) { NS_ASSERTION(aFrame, "aFrame is null"); - mFrameCreateCalled = false; - // We need to make sure that our image request is deregistered. nsPresContext* presContext = GetFramePresContext(); if (mCurrentRequest) { -- cgit v1.2.3