diff --git a/components/script/dom/document_event_handler.rs b/components/script/dom/document_event_handler.rs index 40a1bd52b0e..9cb5f42a01d 100644 --- a/components/script/dom/document_event_handler.rs +++ b/components/script/dom/document_event_handler.rs @@ -28,7 +28,7 @@ use script_bindings::codegen::GenericBindings::NavigatorBinding::NavigatorMethod use script_bindings::codegen::GenericBindings::NodeBinding::NodeMethods; use script_bindings::codegen::GenericBindings::PerformanceBinding::PerformanceMethods; use script_bindings::codegen::GenericBindings::TouchBinding::TouchMethods; -use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods; +use script_bindings::codegen::GenericBindings::WindowBinding::{ScrollBehavior, WindowMethods}; use script_bindings::inheritance::Castable; use script_bindings::num::Finite; use script_bindings::root::{Dom, DomRoot, DomSlice}; @@ -1474,10 +1474,49 @@ impl DocumentEventHandler { } pub(crate) fn run_default_keyboard_event_handler(&self, event: &KeyboardEvent, can_gc: CanGc) { - if event.upcast::().type_() != atom!("keydown") { + const LINE_HEIGHT: f32 = 76.0; + const LINE_WIDTH: f32 = 76.0; + + if event.upcast::().type_() != atom!("keydown") || !event.modifiers().is_empty() { return; } + // 1. Find the element to scroll + ; + + // 2. Determine what key was pressed, and calculate the scroll distance + let (x, y) = match event.key() { + // Key::Named(NamedKey::Home) => { + // // webview.notify_scroll_event(ScrollLocation::Start, origin); + // } + // Key::Named(NamedKey::End) => { + // // webview.notify_scroll_event(ScrollLocation::End, origin); + // } + + Key::Named(NamedKey::PageDown) => { + (0.0, self.window.InnerHeight() as f32 - 2.0 * LINE_HEIGHT) + } + Key::Named(NamedKey::PageUp) => { + (0.0, 2.0 * LINE_HEIGHT - self.window.InnerHeight() as f32) + } + Key::Named(NamedKey::ArrowUp) => { + (0.0, -LINE_HEIGHT) + } + Key::Named(NamedKey::ArrowDown) => { + (0.0, LINE_HEIGHT) + } + Key::Named(NamedKey::ArrowLeft) => { + (-LINE_WIDTH, 0.0) + } + Key::Named(NamedKey::ArrowRight) => { + (LINE_WIDTH, 0.0) + } + _ => return, + }; + + // 3. Do the scroll + self.window.perform_a_scroll(x, y, self.window.pipeline_id().root_scroll_id(), ScrollBehavior::Auto, None); + // keydown dbg!(event.upcast::().type_()); }