script: Move keyboard scrolling to script (#39371)

Instead of having every single embedder implement keyboard scrolling,
handle it in script in the default key event handler. This allows
properly targeting the scroll events to their scroll containers as well
as appropriately sizing "page up" and "page down" scroll deltas.

This change means that when you use the keyboard to scroll, the focused
or most recently clicked `<iframe>` or overflow scroll container is
scrolled, rather than the main frame.

In addition, when a particular scroll frame is larger than its content
in the axis of the scroll, the scrolling operation is chained to
the parent (as in other browsers). One exception is for `<iframe>`s,
which will be implemented in a followup change.

Testing: automated tests runnable locally with `mach test-wpt --product
servodriver`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
shuppy 2025-09-24 04:35:08 +08:00 committed by GitHub
parent 99fbd36b5d
commit ac8895c3ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 540 additions and 185 deletions

View file

@ -50,10 +50,11 @@ use style::data::ElementData;
use style::dom::OpaqueNode;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::media_queries::Device;
use style::properties::PropertyId;
use style::properties::style_structs::Font;
use style::properties::{ComputedValues, PropertyId};
use style::selector_parser::{PseudoElement, RestyleDamage, Snapshot};
use style::stylesheets::{Stylesheet, UrlExtraData};
use style::values::computed::Overflow;
use style_traits::CSSPixel;
use webrender_api::units::{DeviceIntSize, LayoutPoint, LayoutVector2D};
use webrender_api::{ExternalScrollId, ImageKey};
@ -308,7 +309,7 @@ pub trait Layout {
fn query_scroll_container(
&self,
node: TrustedNodeAddress,
query_type: ScrollContainerQueryType,
flags: ScrollContainerQueryFlags,
) -> Option<ScrollContainerResponse>;
fn query_resolved_style(
&self,
@ -366,16 +367,44 @@ pub struct OffsetParentResponse {
pub rect: Rect<Au>,
}
#[derive(PartialEq)]
pub enum ScrollContainerQueryType {
ForScrollParent,
ForScrollIntoView,
bitflags! {
#[derive(PartialEq)]
pub struct ScrollContainerQueryFlags: u8 {
/// Whether or not this query is for the purposes of a `scrollParent` layout query.
const ForScrollParent = 1 << 0;
/// Whether or not to consider the original element's scroll box for the return value.
const Inclusive = 1 << 1;
}
}
#[derive(Clone, Copy, Debug)]
pub struct AxesOverflow {
pub x: Overflow,
pub y: Overflow,
}
impl Default for AxesOverflow {
fn default() -> Self {
Self {
x: Overflow::Visible,
y: Overflow::Visible,
}
}
}
impl From<&ComputedValues> for AxesOverflow {
fn from(style: &ComputedValues) -> Self {
Self {
x: style.clone_overflow_x(),
y: style.clone_overflow_y(),
}
}
}
#[derive(Clone)]
pub enum ScrollContainerResponse {
Viewport,
Element(UntrustedNodeAddress),
Element(UntrustedNodeAddress, AxesOverflow),
}
#[derive(Debug, PartialEq)]