Implement EnterPictureInPictureEvent support.
<rdar://problem/56267916>
Created attachment 381379 [details] Patch With this patch, the enterpictureinpicture event is fired after the transition is completed and the picture-in-picture window size information is available. But, the leavepictureinpicture event is fired before the transition is completed.
Created attachment 381391 [details] Update the patch to fix build errors on iOS, GTK and WPE
Created attachment 381394 [details] Try to fix build failures on GTK and WPE.
Created attachment 381706 [details] Patch Update the patch to fix API test failures
Comment on attachment 381706 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381706&action=review > Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:153 > + EnterPictureInPictureEvent::Init init; > + init.bubbles = true; > + init.pictureInPictureWindow = PictureInPictureWindow::create(m_videoElement.document(), windowSize.width(), windowSize.height()); Nit: I think "initializer" would be slightly better variable name. > Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:168 > + auto leavePictureInPictureEvent = Event::create(eventNames().leavepictureinpictureEvent, Event::CanBubble::Yes, Event::IsCancelable::No); > + m_videoElement.scheduleEvent(WTFMove(leavePictureInPictureEvent)); Nit: this could be one line. > Source/WebCore/html/HTMLVideoElement.cpp:537 > + if (m_waitingForPictureInPictureWindowFrame) { > + m_waitingForPictureInPictureWindowFrame = false; > + if (m_pictureInPictureObserver) > + m_pictureInPictureObserver->didEnterPictureInPicture(IntSize(frame.size())); > + } else { > + if (m_pictureInPictureObserver) > + m_pictureInPictureObserver->pictureInPictureWindowResized(IntSize(frame.size())); > + } Nit: WebKit style guidelines prefer early return when possible, and I think that would make the slightly easier to read: if (toPresentationMode(fullscreenMode()) != VideoPresentationMode::PictureInPicture) return; if (m_waitingForPictureInPictureWindowFrame) { m_waitingForPictureInPictureWindowFrame = false; if (m_pictureInPictureObserver) m_pictureInPictureObserver->didEnterPictureInPicture(IntSize(frame.size())); return; } if (m_pictureInPictureObserver) m_pictureInPictureObserver->pictureInPictureWindowResized(IntSize(frame.size()));
Comment on attachment 381706 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381706&action=review >> Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:153 >> + init.pictureInPictureWindow = PictureInPictureWindow::create(m_videoElement.document(), windowSize.width(), windowSize.height()); > > Nit: I think "initializer" would be slightly better variable name. Agree. >> Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:168 >> + m_videoElement.scheduleEvent(WTFMove(leavePictureInPictureEvent)); > > Nit: this could be one line. Right, and the same for the enterPictureInPictureEvent. >> Source/WebCore/html/HTMLVideoElement.cpp:537 >> + } > > Nit: WebKit style guidelines prefer early return when possible, and I think that would make the slightly easier to read: > > if (toPresentationMode(fullscreenMode()) != VideoPresentationMode::PictureInPicture) > return; > > if (m_waitingForPictureInPictureWindowFrame) { > m_waitingForPictureInPictureWindowFrame = false; > if (m_pictureInPictureObserver) > m_pictureInPictureObserver->didEnterPictureInPicture(IntSize(frame.size())); > > return; > } > > if (m_pictureInPictureObserver) > m_pictureInPictureObserver->pictureInPictureWindowResized(IntSize(frame.size())); Agree.
Created attachment 381746 [details] Patch Patch for landing
Comment on attachment 381746 [details] Patch Clearing flags on attachment: 381746 Committed r251530: <https://trac.webkit.org/changeset/251530>