mirror of
https://github.com/servo/servo.git
synced 2025-09-27 07:10:19 +01:00
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:
parent
99fbd36b5d
commit
ac8895c3ae
19 changed files with 540 additions and 185 deletions
|
@ -11,14 +11,12 @@ use std::rc::Rc;
|
|||
|
||||
use crossbeam_channel::Receiver;
|
||||
use embedder_traits::webdriver::WebDriverSenders;
|
||||
use euclid::Vector2D;
|
||||
use keyboard_types::{Key, Modifiers, NamedKey, ShortcutMatcher};
|
||||
use keyboard_types::ShortcutMatcher;
|
||||
use log::{error, info};
|
||||
use servo::base::generic_channel::GenericSender;
|
||||
use servo::base::id::WebViewId;
|
||||
use servo::config::pref;
|
||||
use servo::ipc_channel::ipc::IpcSender;
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
||||
use servo::{
|
||||
AllowOrDenyRequest, AuthenticationRequest, FilterPattern, FormControl, GamepadHapticEffectType,
|
||||
|
@ -32,7 +30,7 @@ use super::app::PumpResult;
|
|||
use super::dialog::Dialog;
|
||||
use super::gamepad::GamepadSupport;
|
||||
use super::keyutils::CMD_OR_CONTROL;
|
||||
use super::window_trait::{LINE_HEIGHT, LINE_WIDTH, WindowPortsMethods};
|
||||
use super::window_trait::WindowPortsMethods;
|
||||
use crate::output_image::save_output_image_if_necessary;
|
||||
use crate::prefs::ServoShellPreferences;
|
||||
|
||||
|
@ -414,7 +412,6 @@ impl RunningAppState {
|
|||
|
||||
/// Handle servoshell key bindings that may have been prevented by the page in the focused webview.
|
||||
fn handle_overridable_key_bindings(&self, webview: ::servo::WebView, event: KeyboardEvent) {
|
||||
let origin = webview.rect().min.ceil().to_i32();
|
||||
ShortcutMatcher::from_event(event.event)
|
||||
.shortcut(CMD_OR_CONTROL, '=', || {
|
||||
webview.set_zoom(1.1);
|
||||
|
@ -427,42 +424,6 @@ impl RunningAppState {
|
|||
})
|
||||
.shortcut(CMD_OR_CONTROL, '0', || {
|
||||
webview.reset_zoom();
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::PageDown), || {
|
||||
let scroll_location = ScrollLocation::Delta(Vector2D::new(
|
||||
0.0,
|
||||
self.inner().window.page_height() - 2.0 * LINE_HEIGHT,
|
||||
));
|
||||
webview.notify_scroll_event(scroll_location, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::PageUp), || {
|
||||
let scroll_location = ScrollLocation::Delta(Vector2D::new(
|
||||
0.0,
|
||||
-self.inner().window.page_height() + 2.0 * LINE_HEIGHT,
|
||||
));
|
||||
webview.notify_scroll_event(scroll_location, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::Home), || {
|
||||
webview.notify_scroll_event(ScrollLocation::Start, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::End), || {
|
||||
webview.notify_scroll_event(ScrollLocation::End, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::ArrowUp), || {
|
||||
let location = ScrollLocation::Delta(Vector2D::new(0.0, -LINE_HEIGHT));
|
||||
webview.notify_scroll_event(location, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::ArrowDown), || {
|
||||
let location = ScrollLocation::Delta(Vector2D::new(0.0, LINE_HEIGHT));
|
||||
webview.notify_scroll_event(location, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::ArrowLeft), || {
|
||||
let location = ScrollLocation::Delta(Vector2D::new(-LINE_WIDTH, 0.0));
|
||||
webview.notify_scroll_event(location, origin);
|
||||
})
|
||||
.shortcut(Modifiers::empty(), Key::Named(NamedKey::ArrowRight), || {
|
||||
let location = ScrollLocation::Delta(Vector2D::new(LINE_WIDTH, 0.0));
|
||||
webview.notify_scroll_event(location, origin);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -532,12 +532,6 @@ impl WindowPortsMethods for Window {
|
|||
.unwrap_or_else(|| self.device_hidpi_scale_factor())
|
||||
}
|
||||
|
||||
fn page_height(&self) -> f32 {
|
||||
let dpr = self.hidpi_scale_factor();
|
||||
let size = self.winit_window.inner_size();
|
||||
size.height as f32 * dpr.get()
|
||||
}
|
||||
|
||||
fn set_title(&self, title: &str) {
|
||||
self.winit_window.set_title(title);
|
||||
}
|
||||
|
|
|
@ -118,12 +118,6 @@ impl WindowPortsMethods for Window {
|
|||
.unwrap_or_else(|| self.device_hidpi_scale_factor())
|
||||
}
|
||||
|
||||
fn page_height(&self) -> f32 {
|
||||
let height = self.inner_size.get().height;
|
||||
let dpr = self.hidpi_scale_factor();
|
||||
height as f32 * dpr.get()
|
||||
}
|
||||
|
||||
fn set_fullscreen(&self, state: bool) {
|
||||
self.fullscreen.set(state);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use super::app_state::RunningAppState;
|
|||
// This should vary by zoom level and maybe actual text size (focused or under cursor)
|
||||
pub(crate) const LINE_HEIGHT: f32 = 76.0;
|
||||
pub(crate) const LINE_WIDTH: f32 = 76.0;
|
||||
|
||||
// MouseScrollDelta::PixelDelta is default for MacOS, which is high precision and very slow
|
||||
// in winit. Therefore we use a factor of 4.0 to make it more usable.
|
||||
// See https://github.com/servo/servo/pull/34063#discussion_r2197729507
|
||||
|
@ -31,7 +32,6 @@ pub trait WindowPortsMethods {
|
|||
fn screen_geometry(&self) -> ScreenGeometry;
|
||||
fn device_hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
|
||||
fn hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
|
||||
fn page_height(&self) -> f32;
|
||||
fn get_fullscreen(&self) -> bool;
|
||||
fn handle_winit_event(&self, state: Rc<RunningAppState>, event: winit::event::WindowEvent);
|
||||
fn set_title(&self, _title: &str) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue