Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Window's focus() API to focus opener #109

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,30 @@ action of the user), then return.":
{{DOMException}}.
2. <a>Consume user activation</a> given <a>this</a>'s <a>relevant global object</a>.

## Focusing the opener window ## {#focusing-the-opener-window}

<p>
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.
</p>

<p class="issue">
Merge this into {{Window/focus()}} once it has enough consensus.
</p>

Add a new step to {{Window/focus()}} after step 3, "Run the <a>focusing steps</a> with |current|.":

4. If |current| is a <a>top-level traversable</a>, then:
1. Let |pipWindow| be |current|'s <a>active window</a>'s
<a>documentPictureInPicture API</a>'s <a>last-opened window</a>.
2. If |pipWindow| is not <code>null</code> and |pipWindow|'s <a>relevant global object</a>
has <a>transient activation</a>, then:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to raise an Exception to inform developer focus() requires a user gesture from a PiP window.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that focus() is still technically usable regardless, you just wouldn't get system-level focus in this case. It would essentially mean any time a window that owns a pip window calls window.focus() (or another window calls focus() on it), they'd get a new error despite otherwise having the same functionality as before

1. <a>Consume user activation</a> given |pipWindow|'s <a>relevant global object</a>.
2. Give |current| <a>system focus</a>.
steimelchrome marked this conversation as resolved.
Show resolved Hide resolved

# Examples # {#examples}

<em>This section is non-normative</em>
Expand Down Expand Up @@ -570,6 +594,20 @@ expandButton.addEventListener('click', () => {
pipWindow.document.body.append(expandButton);
</pre>

## 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):

<pre class="lang-javascript">
const returnToTabButton = pipWindow.document.createElement('button');
returnToTabButton.textContent = 'Return to opener tab';
returnToTabButton.addEventListener('click', () => {
window.focus();
});
pipWindow.document.body.append(returnToTabButton);
</pre>

# Acknowledgments # {#acknowledgments}

Many thanks to Frank Liberato, Mark Foltz, Klaus Weidner, François Beaufort,
Expand Down