1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = [
"PictureInPicture",
"PictureInPictureParent",
"PictureInPictureToggleParent",
"PictureInPictureLauncherParent",
];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const PLAYER_URI = "chrome://global/content/pictureinpicture/player.xhtml";
var PLAYER_FEATURES =
"chrome,titlebar=yes,alwaysontop,lockaspectratio,resizable";
/* Don't use dialog on Gtk as it adds extra border and titlebar to PIP window */
if (!AppConstants.MOZ_WIDGET_GTK) {
PLAYER_FEATURES += ",dialog";
}
const WINDOW_TYPE = "Toolkit:PictureInPicture";
const PIP_ENABLED_PREF = "media.videocontrols.picture-in-picture.enabled";
const MULTI_PIP_ENABLED_PREF =
"media.videocontrols.picture-in-picture.allow-multiple";
const TOGGLE_ENABLED_PREF =
"media.videocontrols.picture-in-picture.video-toggle.enabled";
/**
* If closing the Picture-in-Picture player window occurred for a reason that
* we can easily detect (user clicked on the close button, originating tab unloaded,
* user clicked on the unpip button), that will be stashed in gCloseReasons so that
* we can note it in Telemetry when the window finally unloads.
*/
let gCloseReasons = new WeakMap();
/**
* Tracks the number of currently open player windows for Telemetry tracking
*/
let gCurrentPlayerCount = 0;
/**
* To differentiate windows in the Telemetry Event Log, each Picture-in-Picture
* player window is given a unique ID.
*/
let gNextWindowID = 0;
class PictureInPictureLauncherParent extends JSWindowActorParent {
receiveMessage(aMessage) {
switch (aMessage.name) {
case "PictureInPicture:Request": {
let videoData = aMessage.data;
PictureInPicture.handlePictureInPictureRequest(this.manager, videoData);
break;
}
}
}
}
class PictureInPictureToggleParent extends JSWindowActorParent {
receiveMessage(aMessage) {
let browsingContext = aMessage.target.browsingContext;
let browser = browsingContext.top.embedderElement;
switch (aMessage.name) {
case "PictureInPicture:OpenToggleContextMenu": {
let win = browser.ownerGlobal;
PictureInPicture.openToggleContextMenu(win, aMessage.data);
break;
}
}
}
}
/**
* This module is responsible for creating a Picture in Picture window to host
* a clone of a video element running in web content.
*/
class PictureInPictureParent extends JSWindowActorParent {
receiveMessage(aMessage) {
switch (aMessage.name) {
case "PictureInPicture:Resize": {
let videoData = aMessage.data;
PictureInPicture.resizePictureInPictureWindow(videoData, this);
break;
}
case "PictureInPicture:Close": {
/**
* Content has requested that its Picture in Picture window go away.
*/
let reason = aMessage.data.reason;
if (PictureInPicture.isMultiPipEnabled) {
PictureInPicture.closeSinglePipWindow({ reason, actorRef: this });
} else {
PictureInPicture.closeAllPipWindows({ reason });
}
break;
}
case "PictureInPicture:Playing": {
let player = PictureInPicture.getWeakPipPlayer(this);
if (player) {
player.setIsPlayingState(true);
}
break;
}
case "PictureInPicture:Paused": {
let player = PictureInPicture.getWeakPipPlayer(this);
if (player) {
player.setIsPlayingState(false);
}
break;
}
case "PictureInPicture:Muting": {
let player = PictureInPicture.getWeakPipPlayer(this);
if (player) {
player.setIsMutedState(true);
}
break;
}
case "PictureInPicture:Unmuting": {
let player = PictureInPicture.getWeakPipPlayer(this);
if (player) {
player.setIsMutedState(false);
}
break;
}
}
}
}
/**
* This module is responsible for creating a Picture in Picture window to host
* a clone of a video element running in web content.
*/
var PictureInPicture = {
// Maps PictureInPictureParent actors to their corresponding PiP player windows
weakPipToWin: new WeakMap(),
// Maps PiP player windows to their originating content's browser
weakWinToBrowser: new WeakMap(),
/**
* Returns the player window if one exists and if it hasn't yet been closed.
*
* @param pipActorRef (PictureInPictureParent)
* Reference to the calling PictureInPictureParent actor
*
* @return {DOM Window} the player window if it exists and is not in the
* process of being closed. Returns null otherwise.
*/
getWeakPipPlayer(pipActorRef) {
let playerWin = this.weakPipToWin.get(pipActorRef);
if (!playerWin || playerWin.closed) {
return null;
}
return playerWin;
},
/**
* Called when the browser UI handles the View:PictureInPicture command via
* the keyboard.
*/
onCommand(event) {
if (!Services.prefs.getBoolPref(PIP_ENABLED_PREF, false)) {
return;
}
let win = event.target.ownerGlobal;
let browser = win.gBrowser.selectedBrowser;
let actor = browser.browsingContext.currentWindowGlobal.getActor(
"PictureInPictureLauncher"
);
actor.sendAsyncMessage("PictureInPicture:KeyToggle");
},
async focusTabAndClosePip(window, pipActor) {
let browser = this.weakWinToBrowser.get(window);
if (!browser) {
return;
}
let gBrowser = browser.ownerGlobal.gBrowser;
let tab = gBrowser.getTabForBrowser(browser);
gBrowser.selectedTab = tab;
await this.closeSinglePipWindow({ reason: "unpip", actorRef: pipActor });
},
/**
* Remove attribute which enables pip icon in tab
*
* @param window {Window}
* A PictureInPicture player's window, used to resolve the player's
* associated originating content browser
*/
clearPipTabIcon(window) {
const browser = this.weakWinToBrowser.get(window);
if (!browser) {
return;
}
// see if no other pip windows are open for this content browser
for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
if (
win !== window &&
this.weakWinToBrowser.has(win) &&
this.weakWinToBrowser.get(win) === browser
) {
return;
}
}
let gBrowser = browser.ownerGlobal.gBrowser;
let tab = gBrowser.getTabForBrowser(browser);
if (tab) {
tab.removeAttribute("pictureinpicture");
}
},
/**
* Closes and waits for passed PiP player window to finish closing.
*
* @param pipWin {Window}
* Player window to close
*/
async closePipWindow(pipWin) {
if (pipWin.closed) {
return;
}
let closedPromise = new Promise(resolve => {
pipWin.addEventListener("unload", resolve, { once: true });
});
pipWin.close();
await closedPromise;
},
/**
* Closes a single PiP window. Used exclusively in conjunction with support
* for multiple PiP windows
*
* @param {Object} closeData
* Additional data required to complete a close operation on a PiP window
* @param {PictureInPictureParent} closeData.actorRef
* The PictureInPictureParent actor associated with the PiP window being closed
* @param {string} closeData.reason
* The reason for closing this PiP window
*/
async closeSinglePipWindow(closeData) {
const { reason, actorRef } = closeData;
const win = this.getWeakPipPlayer(actorRef);
if (!win) {
return;
}
await this.closePipWindow(win);
gCloseReasons.set(win, reason);
},
/**
* Find and close any pre-existing Picture in Picture windows. Used exclusively
* when multiple PiP window support is turned off. All windows can be closed because it
* is assumed that only 1 window is open when it is called.
*
* @param {Object} closeData
* Additional data required to complete a close operation on a PiP window
* @param {string} closeData.reason
* The reason why this PiP is being closed
*/
async closeAllPipWindows(closeData) {
const { reason } = closeData;
// This uses an enumerator, but there really should only be one of
// these things.
for (let win of Services.wm.getEnumerator(WINDOW_TYPE)) {
if (win.closed) {
continue;
}
let closedPromise = new Promise(resolve => {
win.addEventListener("unload", resolve, { once: true });
});
gCloseReasons.set(win, reason);
win.close();
await closedPromise;
}
},
/**
* A request has come up from content to open a Picture in Picture
* window.
*
* @param wgp (WindowGlobalParent)
* The WindowGlobalParent that is requesting the Picture in Picture
* window.
*
* @param videoData (object)
* An object containing the following properties:
*
* videoHeight (int):
* The preferred height of the video.
*
* videoWidth (int):
* The preferred width of the video.
*
* @returns Promise
* Resolves once the Picture in Picture window has been created, and
* the player component inside it has finished loading.
*/
async handlePictureInPictureRequest(wgp, videoData) {
if (!this.isMultiPipEnabled) {
// If there's a pre-existing PiP window, close it first if multiple
// pips are disabled
await this.closeAllPipWindows({ reason: "new-pip" });
gCurrentPlayerCount = 1;
} else {
// track specific number of open pip players if multi pip is
// enabled
gCurrentPlayerCount += 1;
}
Services.telemetry.scalarSetMaximum(
"pictureinpicture.most_concurrent_players",
gCurrentPlayerCount
);
let browser = wgp.browsingContext.top.embedderElement;
let parentWin = browser.ownerGlobal;
let win = await this.openPipWindow(parentWin, videoData);
win.setIsPlayingState(videoData.playing);
win.setIsMutedState(videoData.isMuted);
// set attribute which shows pip icon in tab
let tab = parentWin.gBrowser.getTabForBrowser(browser);
tab.setAttribute("pictureinpicture", true);
win.setupPlayer(gNextWindowID.toString(), wgp, videoData.videoRef);
gNextWindowID++;
this.weakWinToBrowser.set(win, browser);
Services.prefs.setBoolPref(
"media.videocontrols.picture-in-picture.video-toggle.has-used",
true
);
},
/**
* unload event has been called in player.js, cleanup our preserved
* browser object.
*/
unload(window) {
TelemetryStopwatch.finish(
"FX_PICTURE_IN_PICTURE_WINDOW_OPEN_DURATION",
window
);
let reason = gCloseReasons.get(window) || "other";
Services.telemetry.keyedScalarAdd(
"pictureinpicture.closed_method",
reason,
1
);
gCurrentPlayerCount -= 1;
// Saves the location of the Picture in Picture window
this.savePosition(window);
this.clearPipTabIcon(window);
},
/**
* Open a Picture in Picture window on the same screen as parentWin,
* sized based on the information in videoData.
*
* @param parentWin (chrome window)
* The window hosting the browser that requested the Picture in
* Picture window.
*
* @param videoData (object)
* An object containing the following properties:
*
* videoHeight (int):
* The preferred height of the video.
*
* videoWidth (int):
* The preferred width of the video.
*
* @param actorReference (PictureInPictureParent)
* Reference to the calling PictureInPictureParent
*
* @returns Promise
* Resolves once the window has opened and loaded the player component.
*/
async openPipWindow(parentWin, videoData) {
let { top, left, width, height } = this.fitToScreen(parentWin, videoData);
let features =
`${PLAYER_FEATURES},top=${top},left=${left},` +
`outerWidth=${width},outerHeight=${height}`;
let pipWindow = Services.ww.openWindow(
parentWin,
PLAYER_URI,
null,
features,
null
);
TelemetryStopwatch.start(
"FX_PICTURE_IN_PICTURE_WINDOW_OPEN_DURATION",
pipWindow,
{
inSeconds: true,
}
);
return new Promise(resolve => {
pipWindow.addEventListener(
"load",
() => {
resolve(pipWindow);
},
{ once: true }
);
});
},
/**
* This function tries to restore the last known Picture-in-Picture location
* and size. If those values are unknown or offscreen, then a default
* location and size is used.
*
* @param requestingWin (chrome window|player window)
* The window hosting the browser that requested the Picture in
* Picture window. If this is an existing player window then the returned
* player size and position will be determined based on the existing
* player window's size and position.
*
* @param videoData (object)
* An object containing the following properties:
*
* videoHeight (int):
* The preferred height of the video.
*
* videoWidth (int):
* The preferred width of the video.
*
* @returns (object)
* The size and position for the player window.
*
* top (int):
* The top position for the player window.
*
* left (int):
* The left position for the player window.
*
* width (int):
* The width of the player window.
*
* height (int):
* The height of the player window.
*/
fitToScreen(requestingWin, videoData) {
let { videoHeight, videoWidth } = videoData;
const isPlayer = requestingWin.document.location.href == PLAYER_URI;
let top, left, width, height;
if (isPlayer) {
// requestingWin is a PiP player, conserve its dimensions in this case
left = requestingWin.screenX;
top = requestingWin.screenY;
width = requestingWin.innerWidth;
height = requestingWin.innerHeight;
} else {
// requestingWin is a content window, load last PiP's dimensions
({ top, left, width, height } = this.loadPosition());
}
// Check that previous location and size were loaded
if (!isNaN(top) && !isNaN(left) && !isNaN(width) && !isNaN(height)) {
// Center position of PiP window
let centerX = left + width / 2;
let centerY = top + height / 2;
// Get the screen of the last PiP using the center of the PiP
// window to check.
// PiP screen will be the default screen if the center was
// not on a screen.
let PiPScreen = this.getWorkingScreen(centerX, centerY);
// We have the screen, now we will get the dimensions of the screen
let [
PiPScreenLeft,
PiPScreenTop,
PiPScreenWidth,
PiPScreenHeight,
] = this.getAvailScreenSize(PiPScreen);
// Check that the center of the last PiP location is within the screen limits
// If it's not, then we will use the default size and position
if (
PiPScreenLeft <= centerX &&
centerX <= PiPScreenLeft + PiPScreenWidth &&
PiPScreenTop <= centerY &&
centerY <= PiPScreenTop + PiPScreenHeight
) {
let oldWidth = width;
// The new PiP window will keep the height of the old
// PiP window and adjust the width to the correct ratio
width = Math.round((height * videoWidth) / videoHeight);
// Minimum window size on Windows is 136
if (AppConstants.platform == "win") {
width = 136 > width ? 136 : width;
}
// WIGGLE_ROOM allows the PiP window to be within 5 pixels of the right
// side of the screen to stay snapped to the right side
const WIGGLE_ROOM = 5;
// If the PiP window was right next to the right side of the screen
// then move the PiP window to the right the same distance that
// the width changes from previous width to current width
let rightScreen = PiPScreenLeft + PiPScreenWidth;
let distFromRight = rightScreen - (left + width);
if (
0 < distFromRight &&
distFromRight <= WIGGLE_ROOM + (oldWidth - width)
) {
left += distFromRight;
}
// Checks if some of the PiP window is off screen and
// if so it will adjust to move everything on screen
if (left < PiPScreenLeft) {
// off the left of the screen
// slide right
left += PiPScreenLeft - left;
}
if (top < PiPScreenTop) {
// off the top of the screen
// slide down
top += PiPScreenTop - top;
}
if (left + width > PiPScreenLeft + PiPScreenWidth) {
// off the right of the screen
// slide left
left += PiPScreenLeft + PiPScreenWidth - left - width;
}
if (top + height > PiPScreenTop + PiPScreenHeight) {
// off the bottom of the screen
// slide up
top += PiPScreenTop + PiPScreenHeight - top - height;
}
return { top, left, width, height };
}
}
// We don't have the size or position of the last PiP window, so fall
// back to calculating the default location.
let screen = this.getWorkingScreen(
requestingWin.screenX,
requestingWin.screenY,
requestingWin.innerWidth,
requestingWin.innerHeight
);
let [
screenLeft,
screenTop,
screenWidth,
screenHeight,
] = this.getAvailScreenSize(screen);
// The Picture in Picture window will be a maximum of a quarter of
// the screen height, and a third of the screen width.
const MAX_HEIGHT = screenHeight / 4;
const MAX_WIDTH = screenWidth / 3;
width = videoWidth;
height = videoHeight;
let aspectRatio = videoWidth / videoHeight;
if (videoHeight > MAX_HEIGHT || videoWidth > MAX_WIDTH) {
// We're bigger than the max.
// Take the largest dimension and clamp it to the associated max.
// Recalculate the other dimension to maintain aspect ratio.
if (videoWidth >= videoHeight) {
// We're clamping the width, so the height must be adjusted to match
// the original aspect ratio. Since aspect ratio is width over height,
// that means we need to _divide_ the MAX_WIDTH by the aspect ratio to
// calculate the appropriate height.
width = MAX_WIDTH;
height = Math.round(MAX_WIDTH / aspectRatio);
} else {
// We're clamping the height, so the width must be adjusted to match
// the original aspect ratio. Since aspect ratio is width over height,
// this means we need to _multiply_ the MAX_HEIGHT by the aspect ratio
// to calculate the appropriate width.
height = MAX_HEIGHT;
width = Math.round(MAX_HEIGHT * aspectRatio);
}
}
// Now that we have the dimensions of the video, we need to figure out how
// to position it in the bottom right corner. Since we know the width of the
// available rect, we need to subtract the dimensions of the window we're
// opening to get the top left coordinates that openWindow expects.
//
// In event that the user has multiple displays connected, we have to
// calculate the top-left coordinate of the new window in absolute
// coordinates that span the entire display space, since this is what the
// openWindow expects for its top and left feature values.
//
// The screenWidth and screenHeight values only tell us the available
// dimensions on the screen that the parent window is on. We add these to
// the screenLeft and screenTop values, which tell us where this screen is
// located relative to the "origin" in absolute coordinates.
let isRTL = Services.locale.isAppLocaleRTL;
left = isRTL ? screenLeft : screenLeft + screenWidth - width;
top = screenTop + screenHeight - height;
return { top, left, width, height };
},
resizePictureInPictureWindow(videoData, actorRef) {
let win = this.getWeakPipPlayer(actorRef);
if (!win) {
return;
}
let { top, left, width, height } = this.fitToScreen(win, videoData);
win.resizeTo(width, height);
win.moveTo(left, top);
},
openToggleContextMenu(window, data) {
let document = window.document;
let popup = document.getElementById("pictureInPictureToggleContextMenu");
// We synthesize a new MouseEvent to propagate the inputSource to the
// subsequently triggered popupshowing event.
let newEvent = document.createEvent("MouseEvent");
newEvent.initNSMouseEvent(
"contextmenu",
true,
true,
null,
0,
data.screenX,
data.screenY,
0,
0,
false,
false,
false,
false,
0,
null,
0,
data.mozInputSource
);
popup.openPopupAtScreen(newEvent.screenX, newEvent.screenY, true, newEvent);
},
hideToggle() {
Services.prefs.setBoolPref(TOGGLE_ENABLED_PREF, false);
},
/**
* This function takes a screen and will return the left, top, width and
* height of the screen
* @param screen
* The screen we need to get the sizec and coordinates of
*
* @returns array
* Size and location of screen
*
* screenLeft.value (int):
* The left position for the screen.
*
* screenTop.value (int):
* The top position for the screen.
*
* screenWidth.value (int):
* The width of the screen.
*
* screenHeight.value (int):
* The height of the screen.
*/
getAvailScreenSize(screen) {
let screenLeft = {},
screenTop = {},
screenWidth = {},
screenHeight = {};
screen.GetAvailRectDisplayPix(
screenLeft,
screenTop,
screenWidth,
screenHeight
);
let fullLeft = {},
fullTop = {},
fullWidth = {},
fullHeight = {};
screen.GetRectDisplayPix(fullLeft, fullTop, fullWidth, fullHeight);
// We have to divide these dimensions by the CSS scale factor for the
// display in order for the video to be positioned correctly on displays
// that are not at a 1.0 scaling.
let scaleFactor = screen.contentsScaleFactor / screen.defaultCSSScaleFactor;
screenWidth.value *= scaleFactor;
screenHeight.value *= scaleFactor;
screenLeft.value =
(screenLeft.value - fullLeft.value) * scaleFactor + fullLeft.value;
screenTop.value =
(screenTop.value - fullTop.value) * scaleFactor + fullTop.value;
return [
screenLeft.value,
screenTop.value,
screenWidth.value,
screenHeight.value,
];
},
/**
* This function takes in a left and top value and returns the screen they
* are located on.
* If the left and top are not on any screen, it will return the
* default screen
* @param left
* left or x coordinate
* @param top
* top or y coordinate
*
* @returns screen
* the screen the left and top are on otherwise, default screen
*/
getWorkingScreen(left, top, width = 1, height = 1) {
// Get the screen manager
let screenManager = Cc["@mozilla.org/gfx/screenmanager;1"].getService(
Ci.nsIScreenManager
);
// use screenForRect to get screen
// this returns the default screen if left and top are not
// on any screen
let screen = screenManager.screenForRect(left, top, width, height);
return screen;
},
/**
* Saves position and size of Picture-in-Picture window
* @param win The Picture-in-Picture window
*/
savePosition(win) {
let xulStore = Services.xulStore;
let left = win.screenX;
let top = win.screenY;
let width = win.innerWidth;
let height = win.innerHeight;
xulStore.setValue(PLAYER_URI, "picture-in-picture", "left", left);
xulStore.setValue(PLAYER_URI, "picture-in-picture", "top", top);
xulStore.setValue(PLAYER_URI, "picture-in-picture", "width", width);
xulStore.setValue(PLAYER_URI, "picture-in-picture", "height", height);
},
/**
* Load last Picture in Picture location and size
* @returns object
* The size and position of the last Picture in Picture window.
*
* top (int):
* The top position for the last player window.
* Otherwise NaN
*
* left (int):
* The left position for the last player window.
* Otherwise NaN
*
* width (int):
* The width of the player last window.
* Otherwise NaN
*
* height (int):
* The height of the player last window.
* Otherwise NaN
*/
loadPosition() {
let xulStore = Services.xulStore;
let left = parseInt(
xulStore.getValue(PLAYER_URI, "picture-in-picture", "left")
);
let top = parseInt(
xulStore.getValue(PLAYER_URI, "picture-in-picture", "top")
);
let width = parseInt(
xulStore.getValue(PLAYER_URI, "picture-in-picture", "width")
);
let height = parseInt(
xulStore.getValue(PLAYER_URI, "picture-in-picture", "height")
);
return { top, left, width, height };
},
};
XPCOMUtils.defineLazyPreferenceGetter(
PictureInPicture,
"isMultiPipEnabled",
MULTI_PIP_ENABLED_PREF,
false
);
|