Bug 1722322 - Implement LargestContentfulPaint r=emilio

Spec: https://w3c.github.io/largest-contentful-paint

Differential Revision: https://phabricator.services.mozilla.com/D151079
This commit is contained in:
Sean Feng
2023-11-02 20:53:36 +00:00
parent 8af9f7d663
commit 2d6e584e05
30 changed files with 1080 additions and 52 deletions

View File

@@ -28,6 +28,7 @@
#include "mozilla/SVGUtils.h"
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/dom/SVGImageElement.h"
#include "mozilla/dom/LargestContentfulPaint.h"
#include "nsIReflowCallback.h"
using namespace mozilla::dom;
@@ -391,6 +392,12 @@ void SVGImageFrame::PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform,
LayoutDeviceSize devPxSize(width, height);
nsRect destRect(nsPoint(), LayoutDevicePixel::ToAppUnits(
devPxSize, appUnitsPerDevPx));
nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest();
if (currentRequest) {
LCPHelpers::FinalizeLCPEntryForImage(
GetContent()->AsElement(),
static_cast<imgRequestProxy*>(currentRequest.get()), destRect);
}
// Note: Can't use DrawSingleUnscaledImage for the TYPE_VECTOR case.
// That method needs our image to have a fixed native width & height,
@@ -467,14 +474,7 @@ bool SVGImageFrame::CreateWebRenderCommands(
// try to setup the image
if (!mImageContainer) {
nsCOMPtr<imgIRequest> currentRequest;
nsCOMPtr<nsIImageLoadingContent> imageLoader =
do_QueryInterface(GetContent());
if (imageLoader) {
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
getter_AddRefs(currentRequest));
}
nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest();
if (currentRequest) {
currentRequest->GetImage(getter_AddRefs(mImageContainer));
}
@@ -633,6 +633,14 @@ bool SVGImageFrame::CreateWebRenderCommands(
mImageContainer, this, destRect, clipRect, aSc, flags, svgContext,
region);
if (nsCOMPtr<imgIRequest> currentRequest = GetCurrentRequest()) {
LCPHelpers::FinalizeLCPEntryForImage(
GetContent()->AsElement(),
static_cast<imgRequestProxy*>(currentRequest.get()),
LayoutDeviceRect::ToAppUnits(destRect, appUnitsPerDevPx) -
toReferenceFrame);
}
RefPtr<image::WebRenderImageProvider> provider;
ImgDrawResult drawResult = mImageContainer->GetImageProvider(
aManager->LayerManager(), decodeSize, svgContext, region, flags,
@@ -783,6 +791,17 @@ bool SVGImageFrame::ReflowFinished() {
void SVGImageFrame::ReflowCallbackCanceled() { mReflowCallbackPosted = false; }
already_AddRefed<imgIRequest> SVGImageFrame::GetCurrentRequest() const {
nsCOMPtr<imgIRequest> request;
nsCOMPtr<nsIImageLoadingContent> imageLoader =
do_QueryInterface(GetContent());
if (imageLoader) {
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
getter_AddRefs(request));
}
return request.forget();
}
bool SVGImageFrame::IgnoreHitTest() const {
switch (Style()->PointerEvents()) {
case StylePointerEvents::None: