diff --git a/spec.bs b/spec.bs index 905b3eb..0981109 100644 --- a/spec.bs +++ b/spec.bs @@ -422,6 +422,37 @@ action of the user), then return.": {{DOMException}}. 2. Consume user activation given this's relevant global object. +## Focusing the opener window ## {#focusing-the-opener-window} + +

+It can often be useful for the picture-in-picture window to be able to re-focus +its opener tab, e.g. when the smaller form-factor of the window doesn't fit the +experience the user needs. We modify the {{Window/focus()}} API to allow it to +take system-level focus when a picture-in-picture window is focusing its +opener. +

+ +

+Merge this into {{Window/focus()}} once it has enough consensus. +

+ +Add a new step to {{Window/focus()}} after step 3, "Run the focusing steps with |current|.": + +4. If |current| is a top-level traversable, then: + 1. Let |pipWindow| be |current|'s active window's + documentPictureInPicture API's last-opened window. + 2. If |pipWindow| is not null and |pipWindow|'s relevant global object + has transient activation, then: + 1. Consume user activation given |pipWindow|'s relevant global object. + 2. Give |current| system focus. + +

+Giving system focus to the opener does not necessarily need to close the +document picture-in-picture window. If the website wants to close the document +picture-in-picture window after focusing, they can always do so using +{{Window/close()}} on the document picture-in-picture window itself. +

+ # Examples # {#examples} This section is non-normative @@ -570,6 +601,20 @@ expandButton.addEventListener('click', () => { pipWindow.document.body.append(expandButton); +## Return to the opener tab ## {#example-return-to-tab} + +The {{Window/focus()}} API can be used to focus the opener tab from a +picture-in-picture window (requiring a user gesture): + +
+const returnToTabButton = pipWindow.document.createElement('button');
+returnToTabButton.textContent = 'Return to opener tab';
+returnToTabButton.addEventListener('click', () => {
+  window.focus();
+});
+pipWindow.document.body.append(returnToTabButton);
+
+ # Acknowledgments # {#acknowledgments} Many thanks to Frank Liberato, Mark Foltz, Klaus Weidner, François Beaufort,