Skip to content

Commit

Permalink
Emit resize event from PiP window
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=241569

Patch by Youssef Soliman <youssefdevelops@gmail.com> on 2022-06-13
Reviewed by Jer Noble.

When the a PiP window is resized, a resize event should be emitted from
the window object, not just the <video> element.

* Source/WebCore/Modules/pictureinpicture/HTMLVideoElementPictureInPicture.cpp:
(WebCore::HTMLVideoElementPictureInPicture::pictureInPictureWindowResized):
* Source/WebCore/Modules/pictureinpicture/PictureInPictureWindow.cpp:
(WebCore::PictureInPictureWindow::create):
(WebCore::PictureInPictureWindow::PictureInPictureWindow):
(WebCore::PictureInPictureWindow::setSize):
* Source/WebCore/Modules/pictureinpicture/PictureInPictureWindow.h:
* Source/WebCore/Modules/pictureinpicture/PictureInPictureWindow.idl:

Canonical link: https://commits.webkit.org/251512@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295507 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
youssefsoli authored and webkit-commit-queue committed Jun 14, 2022
1 parent 6610eda commit 5fea9c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
Expand Up @@ -189,13 +189,7 @@ void HTMLVideoElementPictureInPicture::didExitPictureInPicture()

void HTMLVideoElementPictureInPicture::pictureInPictureWindowResized(const IntSize& windowSize)
{
if (m_pictureInPictureWindow->width() == windowSize.width() && m_pictureInPictureWindow->height() == windowSize.height())
return;

m_pictureInPictureWindow->setSize(windowSize);
auto resizeEvent = Event::create(eventNames().resizeEvent, Event::CanBubble::Yes, Event::IsCancelable::No);
resizeEvent->setTarget(m_pictureInPictureWindow);
m_videoElement.scheduleEvent(WTFMove(resizeEvent));
}

#if !RELEASE_LOG_DISABLED
Expand Down
15 changes: 11 additions & 4 deletions Source/WebCore/Modules/pictureinpicture/PictureInPictureWindow.cpp
Expand Up @@ -29,27 +29,34 @@

#if ENABLE(PICTURE_IN_PICTURE_API)

#include "EventNames.h"
#include <wtf/IsoMallocInlines.h>

namespace WebCore {

WTF_MAKE_ISO_ALLOCATED_IMPL(PictureInPictureWindow);

Ref<PictureInPictureWindow> PictureInPictureWindow::create(ScriptExecutionContext& scriptExecutionContext)
Ref<PictureInPictureWindow> PictureInPictureWindow::create(Document& document)
{
return adoptRef(*new PictureInPictureWindow(scriptExecutionContext));
auto window = adoptRef(*new PictureInPictureWindow(document));
window->suspendIfNeeded();
return window;
}

PictureInPictureWindow::PictureInPictureWindow(ScriptExecutionContext& scriptExecutionContext)
: m_scriptExecutionContext(scriptExecutionContext)
PictureInPictureWindow::PictureInPictureWindow(Document& document)
: ActiveDOMObject(document)
{
}

PictureInPictureWindow::~PictureInPictureWindow() = default;

void PictureInPictureWindow::setSize(const IntSize& size)
{
if (width() == size.width() && height() == size.height())
return;

m_size = size;
queueTaskToDispatchEvent(*this, TaskSource::MediaElement, Event::create(eventNames().resizeEvent, Event::CanBubble::No, Event::IsCancelable::No));
}

void PictureInPictureWindow::close()
Expand Down
16 changes: 10 additions & 6 deletions Source/WebCore/Modules/pictureinpicture/PictureInPictureWindow.h
Expand Up @@ -28,18 +28,20 @@

#if ENABLE(PICTURE_IN_PICTURE_API)

#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "IntSize.h"
#include <wtf/RefCounted.h>

namespace WebCore {

class PictureInPictureWindow final
: public RefCounted<PictureInPictureWindow>
, public EventTargetWithInlineData {
: public ActiveDOMObject
, public EventTargetWithInlineData
, public RefCounted<PictureInPictureWindow> {
WTF_MAKE_ISO_ALLOCATED(PictureInPictureWindow);
public:
static Ref<PictureInPictureWindow> create(ScriptExecutionContext&);
static Ref<PictureInPictureWindow> create(Document&);
virtual ~PictureInPictureWindow();

int width() const { return m_size.width(); }
Expand All @@ -51,15 +53,17 @@ class PictureInPictureWindow final
using RefCounted<PictureInPictureWindow>::deref;

private:
PictureInPictureWindow(ScriptExecutionContext&);
PictureInPictureWindow(Document&);

// ActiveDOMObject
const char* activeDOMObjectName() const final { return "PictureInPictureWindow"; }

// EventTarget
void refEventTarget() final { ref(); }
void derefEventTarget() final { deref(); }
EventTargetInterface eventTargetInterface() const override { return PictureInPictureWindowEventTargetInterfaceType; };
ScriptExecutionContext* scriptExecutionContext() const override { return &m_scriptExecutionContext; };
ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); };

ScriptExecutionContext& m_scriptExecutionContext;
IntSize m_size;
};

Expand Down
Expand Up @@ -25,6 +25,7 @@
*/

[
ActiveDOMObject,
Conditional=PICTURE_IN_PICTURE_API,
EnabledBySetting=PictureInPictureAPIEnabled,
Exposed=Window
Expand Down

0 comments on commit 5fea9c9

Please sign in to comment.