script: Fire scroll event on visual viewport scroll#42771
Conversation
| /// Whenever a visual viewport gets scrolled (whether in response to user interaction or by an | ||
| /// API), the user agent must run these steps: | ||
| /// <https://drafts.csswg.org/cssom-view/#scrolling-events> | ||
| // TODO: the scroll event handling should be updated and this function should follow as well |
There was a problem hiding this comment.
| /// Whenever a visual viewport gets scrolled (whether in response to user interaction or by an | |
| /// API), the user agent must run these steps: | |
| /// <https://drafts.csswg.org/cssom-view/#scrolling-events> | |
| // TODO: the scroll event handling should be updated and this function should follow as well | |
| /// From <https://drafts.csswg.org/cssom-view/#scrolling-events>: | |
| /// > Whenever a visual viewport gets scrolled (whether in response to user interaction or by an | |
| /// > API), the user agent must run these steps: | |
| // TODO: the scroll event handling should be updated and this function should follow as well |
What do you mean by the last TODO? I'm not sure I completely follow it. Updated in what way?
There was a problem hiding this comment.
It is to note that the Document::pending_scroll_event_targets is changed and thus the algorithm need some modification too. Should have move the TODO to the Document::pending_scroll_event_targets instead. It is not necessary to change it now since scrollend is not implemented i guess.
There was a problem hiding this comment.
But changed in what way? And what modifications?
There was a problem hiding this comment.
But changed in what way? And what modifications?
Initially, the document have two pending list of event targets.
From: https://www.w3.org/TR/cssom-view-1/#scrolling-events, which is not updated yet.
Each Document has an associated list of pending scroll event targets, initially empty.
Each Document has an associated list of pending scrollend event targets, initially empty.
But now it is merged, I remember it is because essentially all browser are doing the same.
From: https://drafts.csswg.org/cssom-view/#scrolling-events
Each Document has an associated list of pending scroll events, which stores pairs of (EventTarget, DOMString), initially empty.
Should have added that.
There was a problem hiding this comment.
Just updated the comments. Please check whether it is clear. Thanks! @mrobinson
| // > If target is a Document, fire an event named scroll that bubbles at target. | ||
| target.fire_bubbling_event(Atom::from("scroll"), can_gc); | ||
| } else if target.downcast::<Element>().is_some() { | ||
| } else { |
There was a problem hiding this comment.
What sort of non-Elements is it important to send scroll events to?
There was a problem hiding this comment.
Initially the scroll only applies to Element and Document since the VisualViewport is not implemented, but now, since it is implemented we should fire to the VisualViewport as well.
It is to bring the algorithm closer to the spec as well, since the spec doesn't limit what kind of target we are firing on to.
99ca390 to
0cca5a9
Compare
254e83f to
c9f3256
Compare
|
@stevennovaryo is that something we could use to implement #42150 ? |
It is more about JS |
c9f3256 to
43e5401
Compare
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
43e5401 to
d6c3caa
Compare
|
Rebased, can we have another look for the PR? @mrobinson Thanks! |
mrobinson
left a comment
There was a problem hiding this comment.
Looks good with some tiny nits:
| /// > Whenever a visual viewport gets scrolled (whether in response to user interaction or by an | ||
| /// > API), the user agent must run these steps: | ||
| pub(crate) fn handle_visual_viewport_scroll_event(&self, visual_viewport: &VisualViewport) { | ||
| // Step 3. |
There was a problem hiding this comment.
Please include the text of steps 1 and 2 here with a TODO comment. There are other examples of this, in this file.
There was a problem hiding this comment.
Sure! It is definitely better to be comprehensive, I have added the steps 1 and 2, they are basically the variable that's been passed into the function.
| let eval_visual_viewport = |attr: &str| match evaluate_javascript( | ||
| &servo_test, | ||
| webview.clone(), | ||
| format!("window.visualViewport.{}", attr), | ||
| ) { | ||
| Ok(JSValue::Number(num)) => Some(num), | ||
| _ => None, | ||
| }; |
There was a problem hiding this comment.
| let eval_visual_viewport = |attr: &str| match evaluate_javascript( | |
| &servo_test, | |
| webview.clone(), | |
| format!("window.visualViewport.{}", attr), | |
| ) { | |
| Ok(JSValue::Number(num)) => Some(num), | |
| _ => None, | |
| }; | |
| let eval_visual_viewport = |attribute: &str| match evaluate_javascript( | |
| &servo_test, | |
| webview.clone(), | |
| format!("window.visualViewport.{}", attribute) | |
| ) | |
| Ok(JSValue::Number(number)) => Some(number), | |
| _ => None, | |
| }; |
| // TODO(31665): Instead of having separate list for `scroll` and `scrollend` event, the updated spec | ||
| // make it store both the event target and the event type. Need to update this along with | ||
| // the implementation of `scrollend`. |
There was a problem hiding this comment.
This is a tiny nit, but we typically don't indent TODO comments like this. Please format them like this:
| // TODO(31665): Instead of having separate list for `scroll` and `scrollend` event, the updated spec | |
| // make it store both the event target and the event type. Need to update this along with | |
| // the implementation of `scrollend`. | |
| // TODO(#31665): Instead of having separate list for `scroll` and `scrollend` event, the updated spec | |
| // make it store both the event target and the event type. Need to update this along with the | |
| // implementation of `scrollend`. |
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
On visual viewport scroll, fire the scroll event to the `VisualViewport` instances. Incidentaly, fix a bug where the pinch zoom update should be propagated to the script. Testing: New unit test and manual WPT. --------- Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
On visual viewport scroll, fire the scroll event to the
VisualViewportinstances. Incidentaly, fix a bug where the pinch zoom update should be propagated to the script.Testing: New unit test and manual WPT.