Allow script to scroll overflow: scroll elements

Before the code was only allowing `overflow: hidden` elements to scroll.
This fixes that issue and also clean up the code that deals with
detecting whether the body is a "potentially scrollable" in quirks mode.
This commit is contained in:
Martin Robinson 2023-04-25 09:07:53 +02:00
parent 3ab5e2a188
commit eca0acf459
11 changed files with 60 additions and 173 deletions

View file

@ -1699,24 +1699,23 @@ impl Window {
// TODO Step 4 - determine if a window has a viewport
// Step 5
//TODO remove scrollbar width
let width = self.InnerWidth() as f64;
// Step 6
//TODO remove scrollbar height
let height = self.InnerHeight() as f64;
// Step 5 & 6
// TODO: Remove scrollbar dimensions.
let viewport = self.window_size.get().initial_viewport;
// Step 7 & 8
//TODO use overflow direction
// TODO: Consider `block-end` and `inline-end` overflow direction.
let body = self.Document().GetBody();
let (x, y) = match body {
Some(e) => {
let content_size = e.upcast::<Node>().bounding_content_box_or_zero();
let content_height = content_size.size.height.to_f64_px();
let content_width = content_size.size.width.to_f64_px();
let scroll_area = e.upcast::<Node>().scroll_area();
(
xfinite.min(content_width - width).max(0.0f64),
yfinite.min(content_height - height).max(0.0f64),
xfinite
.min(scroll_area.width() as f64 - viewport.width as f64)
.max(0.0f64),
yfinite
.min(scroll_area.height() as f64 - viewport.height as f64)
.max(0.0f64),
)
},
None => (xfinite.max(0.0f64), yfinite.max(0.0f64)),
@ -1731,14 +1730,13 @@ impl Window {
//TODO Step 11
//let document = self.Document();
// Step 12
let global_scope = self.upcast::<GlobalScope>();
let x = x.to_f32().unwrap_or(0.0f32);
let y = y.to_f32().unwrap_or(0.0f32);
self.update_viewport_for_scroll(x, y);
self.perform_a_scroll(
x,
y,
global_scope.pipeline_id().root_scroll_id(),
self.upcast::<GlobalScope>().pipeline_id().root_scroll_id(),
behavior,
None,
);