Skip to content

Commit 8bf1985

Browse files
committed
Bug 1858562 - Part 3: Platform specific Document Picture-in-Picture adjustments. r=emilio,dom-core,win-reviewers,gstoll,smaug
Differential Revision: https://phabricator.services.mozilla.com/D265291
1 parent a3047a1 commit 8bf1985

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

widget/InitData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ enum class TransparencyMode : uint8_t {
7575
enum class PiPType : uint8_t {
7676
NoPiP,
7777
// https://w3c.github.io/picture-in-picture
78-
MediaPiP
78+
MediaPiP,
79+
// https://wicg.github.io/document-picture-in-picture
80+
DocumentPiP
7981
};
8082

8183
// Basic struct for widget initialization data.

widget/cocoa/nsCocoaWindow.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5261,9 +5261,10 @@ static unsigned int WindowMaskForBorderStyle(BorderStyle aBorderStyle) {
52615261
mWindowAnimationBehavior = behavior;
52625262
}
52635263

5264-
// We don't want alwaysontop / alert windows to pull focus when they're
5265-
// opened, as these tend to be for peripheral indicators and displays.
5266-
if (mAlwaysOnTop || mIsAlert) {
5264+
// We don't want most alwaysontop / alert windows to pull focus when
5265+
// they're opened, as these tend to be for peripheral indicators and
5266+
// displays.
5267+
if ((mAlwaysOnTop && mPiPType != PiPType::DocumentPiP) || mIsAlert) {
52675268
[mWindow orderFront:nil];
52685269
} else {
52695270
[mWindow makeKeyAndOrderFront:nil];

widget/gtk/nsWindow.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6427,7 +6427,8 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
64276427

64286428
// alwaysontop windows are generally used for peripheral indicators,
64296429
// so we don't focus them by default.
6430-
if (mAlwaysOnTop) {
6430+
const bool shouldFocus = !mAlwaysOnTop || mPiPType == PiPType::DocumentPiP;
6431+
if (!shouldFocus) {
64316432
gtk_window_set_focus_on_map(GTK_WINDOW(mShell), FALSE);
64326433
}
64336434

@@ -6451,7 +6452,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
64516452
// make sure this is the focus widget in the container
64526453
gtk_widget_show(container);
64536454

6454-
if (!mAlwaysOnTop) {
6455+
if (shouldFocus) {
64556456
gtk_widget_grab_focus(container);
64566457
}
64576458

@@ -6622,7 +6623,9 @@ nsresult nsWindow::Create(nsIWidget* aParent, const LayoutDeviceIntRect& aRect,
66226623
nullptr);
66236624

66246625
LOG(" nsWindow type %d %s\n", int(mWindowType),
6625-
mPiPType == PiPType::MediaPiP ? "Media PiP window" : "");
6626+
mPiPType == PiPType::MediaPiP
6627+
? "Media PiP window"
6628+
: (mPiPType == PiPType::DocumentPiP ? "Document PiP window" : ""));
66266629
LOG(" mShell %p (window %p) mContainer %p mGdkWindow %p XID 0x%lx\n", mShell,
66276630
GetToplevelGdkWindow(), mContainer, mGdkWindow, GetX11Window());
66286631

widget/headless/HeadlessWidget.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ void HeadlessWidget::Show(bool aState) {
167167
LOG(("HeadlessWidget::Show [%p] state %d\n", (void*)this, aState));
168168

169169
// Top-level window and dialogs are activated/raised when shown.
170-
// NB: alwaysontop windows are generally used for peripheral indicators,
171-
// so we don't focus them by default.
172-
if (aState && !mAlwaysOnTop &&
170+
// NB: alwaysontop windows are generally used for peripheral indicators.
171+
// So we don't focus them by default unless they are a Document
172+
// Picture-in-Picture.
173+
if (aState && (!mAlwaysOnTop || mPiPType == PiPType::DocumentPiP) &&
173174
(mWindowType == WindowType::TopLevel ||
174175
mWindowType == WindowType::Dialog)) {
175176
RaiseWindow();

widget/windows/nsWindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,8 @@ void nsWindow::Show(bool aState) {
17741774
::ShowWindow(mWnd, SW_SHOWMINIMIZED);
17751775
break;
17761776
default:
1777-
if (CanTakeFocus() && !mAlwaysOnTop) {
1777+
if (CanTakeFocus() &&
1778+
(!mAlwaysOnTop || mPiPType == PiPType::DocumentPiP)) {
17781779
::ShowWindow(mWnd, SW_SHOWNORMAL);
17791780
} else {
17801781
::ShowWindow(mWnd, SW_SHOWNOACTIVATE);
@@ -1807,7 +1808,7 @@ void nsWindow::Show(bool aState) {
18071808
if (wasVisible) {
18081809
flags |= SWP_NOZORDER;
18091810
}
1810-
if (mAlwaysOnTop || mIsAlert) {
1811+
if ((mAlwaysOnTop && mPiPType != PiPType::DocumentPiP) || mIsAlert) {
18111812
flags |= SWP_NOACTIVATE;
18121813
}
18131814

xpfe/appshell/nsAppShellService.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ nsresult nsAppShellService::JustCreateTopWindow(
526526
}
527527
#endif
528528

529+
if (widgetInitData.mWindowType == widget::WindowType::TopLevel &&
530+
(aChromeMask & nsIWebBrowserChrome::CHROME_DOCUMENT_PICTURE_IN_PICTURE) ==
531+
nsIWebBrowserChrome::CHROME_DOCUMENT_PICTURE_IN_PICTURE) {
532+
widgetInitData.mPiPType = mozilla::widget::PiPType::DocumentPiP;
533+
}
534+
529535
// alert=yes is expected to be used along with dialogs, not other window
530536
// types.
531537
MOZ_ASSERT_IF(aChromeMask & nsIWebBrowserChrome::CHROME_ALERT,

0 commit comments

Comments
 (0)