Repository navigation
Implement HTML video and audio element lazy-loading via the loading attribute - #76200
Conversation
|
EWS run on previous version of this PR (hash 27fea9c) Details |
27fea9c to
e9d17f3
Compare
|
EWS run on previous version of this PR (hash e9d17f3) Details |
e9d17f3 to
cd036b9
Compare
|
EWS run on previous version of this PR (hash cd036b9) Details |
cd036b9 to
d78478b
Compare
|
EWS run on previous version of this PR (hash d78478b) Details |
d78478b to
6aa27ab
Compare
|
EWS run on previous version of this PR (hash 6aa27ab) Details |
6aa27ab to
215a802
Compare
|
EWS run on previous version of this PR (hash 215a802) Details |
annevk
left a comment
There was a problem hiding this comment.
Generally looks good to me, but I did spot a couple of things that are worth a revision. (And thanks for sorting out the contribution of this on your end!)
|
|
||
| static bool shouldLazyLoadImageForElement(const Element& element, const Document& document) | ||
| { | ||
| if (!LazyLoading::isLazyLoadable(element)) |
There was a problem hiding this comment.
So this only handles frames? That seems a bit weird for the generic function.
There was a problem hiding this comment.
@annevk thanks for the review! This isn't frame specific. It’s step 1 of the will lazy load element steps (“if scripting is disabled for element, then return false”). Both the img and iframe paths already had this same check, so LazyLoading::isLazyLoadable is consolidating them into one generic function. Let me know if that answers your question, I wasn't 100% sure what you meant by "frames".
There was a problem hiding this comment.
Well the thing is that LazyLoading::isLazyLoadable only handles iframe and generally elements with loading=lazy (is that too generic?). And then in this static we handle various settings checks. Why not handle the settings checks in isLazyLoadable too?
There was a problem hiding this comment.
Ahhh I see what you mean. I agree that we can move the settings checks into LazyLoading.cpp. I've put them into isLazyLoadingEnabled, which is called by isLazyLoadable. I noticed that HTMLImageElement was calling isLazyLoadable to implement auto-sizes as defined by the spec. To account for this, I added isInLazyState to LazyLoading.cpp and replaced those instances of isLazyLoadable.
215a802 to
c0028fc
Compare
|
EWS run on previous version of this PR (hash c0028fc) Details |
c0028fc to
8334a4e
Compare
|
EWS run on previous version of this PR (hash 8334a4e) Details |
8334a4e to
eaea668
Compare
|
EWS run on previous version of this PR (hash eaea668) Details |
eaea668 to
0be9b49
Compare
|
EWS run on current version of this PR (hash 0be9b49) Details |
|
Safe-Merge-Queue: Build #109434. |
…ttribute https://bugs.webkit.org/show_bug.cgi?id=303995 Reviewed by Anne van Kesteren. This patch implements a loading attribute for video and audio elements, enabling lazy loading of media sources and video poster images, and deferring autoplay. This was added to the HTML spec here: whatwg/html#11980 Synced test from upstream wpt: - Commit: web-platform-tests/wpt@7d9d48d - Test: imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-source-inserted-load-event.html * LayoutTests/TestExpectations: * LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-embedded-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/windows-1251_include=loading-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252_include=loading-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-autoplay-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-autoplay-when-visible-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-disconnected-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-not-rendered-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-source-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-to-eager-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-load-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-load-preload-auto-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-load-preload-metadata-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-autoplay-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-eager-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-autoplay-when-visible-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-disconnected-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-in-scroller-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-in-viewport-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-load-when-visible-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-not-rendered-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-poster-when-visible-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-resume-on-loading-attribute-change-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-source-inserted-load-event-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-source-inserted-load-event.html: Added. * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-source-poster-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-lazy-to-eager-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video-loading-poster-deferred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/w3c-import.log: * LayoutTests/imported/w3c/web-platform-tests/media/A4.webm: Added. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-in-viewport-expected.txt: Removed. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-lazy-window-onload-expected.txt: Removed. * LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio-loading-load-preload-metadata-deferred-expected.txt: Removed. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Document.h: * Source/WebCore/html/HTMLIFrameElement.cpp: (WebCore::HTMLIFrameElement::attributeChanged): (WebCore::isFrameLazyLoadable): (WebCore::HTMLIFrameElement::shouldLoadFrameLazily): * Source/WebCore/html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): (WebCore::HTMLImageElement::selectImageSource): (WebCore::HTMLImageElement::attributeChanged): (WebCore::HTMLImageElement::didAttachRenderers): (WebCore::HTMLImageElement::allowsAutoSizes const): (WebCore::HTMLImageElement::hasLazyLoadableAttributeValue): Deleted. (WebCore::HTMLImageElement::isLazyLoadable const): Deleted. * Source/WebCore/html/HTMLImageElement.h: * Source/WebCore/html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::didMoveToNewDocument): (WebCore::HTMLMediaElement::attributeChanged): (WebCore::HTMLMediaElement::shouldLazyLoadMediaResource const): (WebCore::HTMLMediaElement::deferMediaResourceLoadIfNeeded): (WebCore::HTMLMediaElement::clearLazyLoadState): (WebCore::HTMLMediaElement::resumeDeferredMediaResourceLoad): (WebCore::HTMLMediaElement::runLazyLoadResumptionSteps): (WebCore::HTMLMediaElement::lazyLoadIntersectionCallbackInvoked): (WebCore::HTMLMediaElement::prepareForLoad): (WebCore::HTMLMediaElement::selectMediaResource): (WebCore::HTMLMediaElement::queueSelectMediaResourceTask): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::sourceWasAdded): * Source/WebCore/html/HTMLMediaElement.h: (WebCore::HTMLMediaElement::isIntersectingViewport const): (WebCore::HTMLMediaElement::tracksViewportIntersection const): (WebCore::HTMLMediaElement::viewportIntersectionChanged): (WebCore::HTMLMediaElement::isMediaResourceLoadDeferred const): (WebCore::HTMLMediaElement::shouldObserveViewportIntersection const): * Source/WebCore/html/HTMLMediaElement.idl: * Source/WebCore/html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::rendererIsNeeded): (WebCore::HTMLVideoElement::didAttachRenderers): (WebCore::HTMLVideoElement::computeAcceleratedRenderingStateAndUpdateMediaPlayer): (WebCore::HTMLVideoElement::attributeChanged): (WebCore::HTMLVideoElement::webkitEnterFullscreen): (WebCore::HTMLVideoElement::didMoveToNewDocument): (WebCore::HTMLVideoElement::viewportIntersectionChanged): (WebCore::HTMLVideoElement::runLazyLoadResumptionSteps): (WebCore::HTMLVideoElement::loadDeferredPosterImage): (WebCore::HTMLVideoElement::resumePosterLoadIfAlreadyVisible): (WebCore::HTMLVideoElement::~HTMLVideoElement): Deleted. (WebCore::HTMLVideoElement::lazyLoadIntersectionCallbackInvoked): Deleted. * Source/WebCore/html/HTMLVideoElement.h: * Source/WebCore/html/LazyLoadElementObserver.cpp: (WebCore::LazyLoadElementObserver::unobserve): (WebCore::LazyLoadElementObserver::unobserveIfLazyLoadOnly): (WebCore::LazyLoadElementObserver::isObserved const): Deleted. * Source/WebCore/html/LazyLoadElementObserver.h: * Source/WebCore/html/LazyLoading.cpp: Added. (WebCore::LazyLoading::hasLazyAttributeValue): (WebCore::LazyLoading::isInLazyState): (WebCore::LazyLoading::isLazyLoadingEnabled): (WebCore::LazyLoading::isLazyLoadable): * Source/WebCore/html/LazyLoading.h: Copied from Source/WebCore/html/LazyLoadElementObserver.h. * Source/WebCore/html/parser/HTMLPreloadScanner.cpp: (WebCore::TokenPreloadScanner::StartTagScanner::createPreloadRequest): (WebCore::TokenPreloadScanner::StartTagScanner::isLazyloadingImage const): (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): * Source/WebCore/loader/ImageLoader.cpp: (WebCore::ImageLoader::updateFromElement): (WebCore::ImageLoader::notifyFinished): (WebCore::ImageLoader::updatedHasPendingEvent): (WebCore::ImageLoader::decode): (WebCore::ImageLoader::resetLazyImageLoading): * Source/WebCore/rendering/RenderImage.cpp: (WebCore::RenderImage::layout): Canonical link: https://commits.webkit.org/325572@main
0be9b49 to
a93ac1a
Compare
|
Committed 325572@main (a93ac1a): https://commits.webkit.org/325572@main Reviewed commits have been landed. Closing PR #76200 and removing active labels. |
🧪 webkitpy
a93ac1a
0be9b49
🛠 playstation