-
Notifications
You must be signed in to change notification settings - Fork 43
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
document.fullscreenElement in scroll event after entering fullscreen matters for compat #74
Comments
FWIW, this is what Gecko does, actually. I thought it is hard to distinguish between this behavior and the specced behavior. It seems I was wrong. |
BTW, if the element is already removed from the document, I suppose browser should exit fullscreen anyway... unless they just hide the element. |
@upsuper, would you support changing the spec to be closer to Gecko? It is rather unfortunate to not make the state changes right before the events, but then the resize has already happened so there's no way to have everything happen at the very same time. (Unless, I suppose, every observable side effect of the resize is hidden until the resize event, which seems like a lot of effort to sort through.)
Yeah, I recall you mentioned a change like this in Gecko, and I have a TODO in Blink around this. FWIW, it will be slightly easier to handle this situation at resize time, because at least one doesn't need to consider how things can change between then and when the animation frame task is run (in the current model). |
…th the spec (patchset #3 id:40001 of https://codereview.chromium.org/2573773002/ ) Reason for revert: Delaying fullscreen element stack changes until the animation frame after resize, and thus after resize-triggered scroll events, caused a regression with twitter video embeds that may require spec changes to fix: whatwg/fullscreen#74 BUG=680467 Original issue's description: > Sync requestFullscreen() and exitFullscreen() algorithms with the spec > > The central change is the timing for when the fullscreen element stack > is modified and when the events fire. This makes it possible to make > webkitCurrentFullScreenElement an alias of fullscreenElement, as the old > notion of a single fullscreen element is gone. > > Previously, fullscreen requests did: > 1. In Fullscreen::requestFullscreen(), synchronously modify > m_fullscreenElementStack, visible in document.fullscreenElement, but > not document.webkitCurrentFullScreenElement. Also enqueue events to > fire, without starting the timer to fire them. > 2. As soon as the resize happens, in Fullscreen::didEnterFullscreen(), > set m_currentFullScreenElement, affecting :-webkit-full-screen > document.webkitCurrentFullScreenElement. Start the event timer. > 3. When the timer fires, events are dispatched. If the tree has changed > since the events were enqueued, additional events may be fired. > > And similarly for exit. For errors, requestFullscreen() would itself > start the timer to fire the events. > > Now, fullscreen requests will: > 1. In Fullscreen::requestFullscreen(), append to a list of pending > requests. > 2. When the resize happens, enqueue an animation frame task for each > pending request. > 3. In the animation frame task, apply all changes, decide which events > to fire and then fire them. > > TEST=run-webkit-tests fullscreen/ imported/wpt/fullscreen/ > webkit_unit_tests --gtest_filter=*Fullscreen* > interactive_ui_tests --gtest_filter=SitePerProcessInteractiveBrowserTest.Fullscreen* > BUG=402376,402421 > CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2 > > Committed: https://crrev.com/e1d42d636990425056ede44086ef49a1f8c6a0a5 > Cr-Commit-Position: refs/heads/master@{#439607} [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=402376,402421 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2 Review-Url: https://codereview.chromium.org/2654083006 Cr-Commit-Position: refs/heads/master@{#446643}
I would support that. I think it makes sense to have the document changes its state as soon as possible, hopefully before any script can get a chance to execute, so that we can limit the number of necessary reflow to the minimum. In the HTML spec, scroll and resize are both dispatched before fullscreen steps, which is probably bad based on that... So yes, let's make it change the state immediately, and keep dispatching events (and resolving promise) in the animation frame task. Not sure how spec should say about that, though. |
@annevk, does a change like that make sense to you, at least enough that I should try a PR? |
(I'd probably try to implement and update tests first.) |
So we'd make changes to state just before the "rendering task" and then during the "rendering task" we invoke all the JavaScript callbacks? That sounds reasonable. One problem that seems likely to come up again is that the infrastructure in HTML is on a per-document basis, whereas browsers do rendering on a per event loop basis, no? So shouldn't we adjust that too/first? |
Yeah, that is a problem I've had to grapple with especially when exiting. I can use the phrasing "enqueue animation frame task for document" to make it clear what I intend, and then I can finally define that in HTML. |
…th the spec (patchset #3 id:40001 of https://codereview.chromium.org/2573773002/ ) Reason for revert: Delaying fullscreen element stack changes until the animation frame after resize, and thus after resize-triggered scroll events, caused a regression with twitter video embeds that may require spec changes to fix: whatwg/fullscreen#74 BUG=680467 Original issue's description: > Sync requestFullscreen() and exitFullscreen() algorithms with the spec > > The central change is the timing for when the fullscreen element stack > is modified and when the events fire. This makes it possible to make > webkitCurrentFullScreenElement an alias of fullscreenElement, as the old > notion of a single fullscreen element is gone. > > Previously, fullscreen requests did: > 1. In Fullscreen::requestFullscreen(), synchronously modify > m_fullscreenElementStack, visible in document.fullscreenElement, but > not document.webkitCurrentFullScreenElement. Also enqueue events to > fire, without starting the timer to fire them. > 2. As soon as the resize happens, in Fullscreen::didEnterFullscreen(), > set m_currentFullScreenElement, affecting :-webkit-full-screen > document.webkitCurrentFullScreenElement. Start the event timer. > 3. When the timer fires, events are dispatched. If the tree has changed > since the events were enqueued, additional events may be fired. > > And similarly for exit. For errors, requestFullscreen() would itself > start the timer to fire the events. > > Now, fullscreen requests will: > 1. In Fullscreen::requestFullscreen(), append to a list of pending > requests. > 2. When the resize happens, enqueue an animation frame task for each > pending request. > 3. In the animation frame task, apply all changes, decide which events > to fire and then fire them. > > TEST=run-webkit-tests fullscreen/ imported/wpt/fullscreen/ > webkit_unit_tests --gtest_filter=*Fullscreen* > interactive_ui_tests --gtest_filter=SitePerProcessInteractiveBrowserTest.Fullscreen* > BUG=402376,402421 > CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2 > > Committed: https://crrev.com/e1d42d636990425056ede44086ef49a1f8c6a0a5 > Cr-Commit-Position: refs/heads/master@{#439607} [email protected],[email protected],[email protected],[email protected] BUG=402376,402421 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2 Review-Url: https://codereview.chromium.org/2654083006 Cr-Commit-Position: refs/heads/master@{#446643} (cherry picked from commit 40a515a53aa3510c608fe60c572045850632e720) Review-Url: https://codereview.chromium.org/2667913002 . Cr-Commit-Position: refs/branch-heads/2987@{#216} Cr-Branched-From: ad51088-refs/heads/master@{#444943}
@upsuper, this issue is about the timing of Are there changes you think we should make timing-wise that would amount to not aligning the events with animation frame tasks? I ask because I'm addition to https://crbug.com/680467 there was also a bit of trouble in https://crbug.com/679281 where the interaction with the Screen Orientation API was impacted, and it all boils down to timing. @mounirlamouri FYI |
I think you mean this comment. But it seems to me the previous plan in this issue was to make the document state change immediately and only delay the event dispatch? |
To give more context about that interaction with Screen Orientation API: we implemented a feature in the Blink native controls to lock the orientation when the video goes fullscreen using the web events. @foolip told me that with the new event timing, that feature wouldn't work and we needed to have internal callbacks to keep the feature working. The way it was implemented in Blink is exactly the way a website would implement this feature which makes me think it might break some experiences. For example, there was a Web Fundamentals article advertising deeper interactions between fullscreen and orientation changes: https://developers.google.com/web/fundamentals/media/mobile-web-video-playback |
@upsuper, that was it indeed, "I have a feeling that we may actually want fullscreen events to be dispatched at a very early stage, probably even before resize." The problem has to do with restoring the original scale and scroll position after exiting fullscreen. This isn't something the spec covers, and I'd be surprised if it works exactly the same in all browsers. In any case, if the orientation lock changes are applied in reaction to fullscreenchange events, it means that when exiting fullscreen, the orientation will still be locked for a few more frames. The problem is the same as with this sequence of events, with a few seconds between each step:
After this, will the scale and scroll position be the same as in the beginning? If yes, then it must mean that unlocking the screen orientation is what restores the pre-fullscreen state, i.e. the APIs are entangled in a way that isn't suggested by either spec. Maybe they should be? Or, possibly, some change to the timing would happen to fix this problem. |
This means that changes to document.fullscreenElement and other state will be observable as soon as the resize itself is (e.g. via window.innerWidth) and before resize or scroll events are fired. The fullscreenchange event is still delayed to animation frame timing. This also includes a slight change when /resize/ is true in "exit fullscreen". By changing /doc/ to /topLevelDoc/ in this case, we can make sure that we always fully unfullscreen all documents in this case. This makes a "fully exit fullscreen" corner case unnecessary. Fixes #74.
This means that changes to document.fullscreenElement and other state will be observable as soon as the resize itself is (e.g. via window.innerWidth) and before resize or scroll events are fired. The fullscreenchange event is still delayed to animation frame timing. This also includes a slight change when /resize/ is true in "exit fullscreen". By changing /doc/ to /topLevelDoc/ in this case, we can make sure that we always fully unfullscreen all documents in this case. This makes a "fully exit fullscreen" corner case unnecessary. Fixes #74.
@mounirlamouri, #92 fixes my original problem in this issue but not the Screen Orientation API issues. The earliest possible time that one could fire the events I think is in a microtask following the resize, but I don't think that'd really solve anything. The orientation change itself can involve an animation and is in any event out-of-process in some implementations, so it couldn't be guaranteed to happen before the layout at which the original scale and scroll position should be restored. Maybe a good start would be to write (manual) testharness.js tests for the expected behavior that are as unforgiving timing-wise as possible. Is that something you have the bandwidth for? |
This means that changes to document.fullscreenElement and other state will be observable as soon as the resize itself is (e.g. via window.innerWidth) and before resize or scroll events are fired. The fullscreenchange event is still delayed to animation frame timing. This also includes a slight change when /resize/ is true in "exit fullscreen". By changing /doc/ to /topLevelDoc/ in this case, we can make sure that we always fully unfullscreen all documents in this case. This makes a "fully exit fullscreen" corner case unnecessary. Fixes #74.
This means that changes to document.fullscreenElement and other state will be observable as soon as the resize itself is (e.g. via window.innerWidth) and before resize or scroll events are fired. The fullscreenchange event is still delayed to animation frame timing. This also includes a slight change when /resize/ is true in "exit fullscreen". By changing /doc/ to /topLevelDoc/ in this case, we can make sure that we always fully unfullscreen all documents in this case. This makes a "fully exit fullscreen" corner case unnecessary. Fixes #74.
In https://crbug.com/680467 there is fallout from aligning the timing of
document.fullscreenElement
andfullscreenchange
event with animation frames in https://crbug.com/402376.On https://twitter.com/BCCI, if ones scrolls down a bit and plays a video in fullscreen, the iframe the video is in is removed from the document, leaving things in a broken-looking state. I speculate that this code tries to remove video that have scrolled out of view.
The crucial change is that in the scroll event fired after entering fullscreen, the fullscreen steps have not yet run, so to the page it looks like the page has simply been resized, causing a scroll.
I investigated current behavior:
I can see a few alternatives here, in rough order of preference:
document.pendingFullscreenElement
that could be used by Twitter to avoid this problem.@upsuper @jernoble @aliams
The text was updated successfully, but these errors were encountered: