servoshell/desktop/
window_trait.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Definition of Window.
6//! Implemented by headless and headed windows.
7
8use std::rc::Rc;
9
10use euclid::{Length, Scale};
11use servo::servo_geometry::{DeviceIndependentIntRect, DeviceIndependentPixel};
12use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel};
13use servo::{Cursor, RenderingContext, ScreenGeometry, WebView};
14
15use super::app_state::RunningAppState;
16
17// This should vary by zoom level and maybe actual text size (focused or under cursor)
18pub(crate) const LINE_HEIGHT: f32 = 76.0;
19pub(crate) const LINE_WIDTH: f32 = 76.0;
20// MouseScrollDelta::PixelDelta is default for MacOS, which is high precision and very slow
21// in winit. Therefore we use a factor of 4.0 to make it more usable.
22// See https://github.com/servo/servo/pull/34063#discussion_r2197729507
23pub(crate) const PIXEL_DELTA_FACTOR: f64 = 4.0;
24
25/// <https://github.com/web-platform-tests/wpt/blob/9320b1f724632c52929a3fdb11bdaf65eafc7611/webdriver/tests/classic/set_window_rect/set.py#L287-L290>
26/// "A window size of 10x10px shouldn't be supported by any browser."
27pub(crate) const MIN_INNER_WIDTH: i32 = 20;
28pub(crate) const MIN_INNER_HEIGHT: i32 = 20;
29
30pub trait WindowPortsMethods {
31    fn id(&self) -> winit::window::WindowId;
32    fn screen_geometry(&self) -> ScreenGeometry;
33    fn device_hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
34    fn hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
35    fn page_height(&self) -> f32;
36    fn get_fullscreen(&self) -> bool;
37    fn handle_winit_event(&self, state: Rc<RunningAppState>, event: winit::event::WindowEvent);
38    fn set_title(&self, _title: &str) {}
39    /// Request a new outer size for the window, including external decorations.
40    /// This should be the same as `window.outerWidth` and `window.outerHeight``
41    fn request_resize(&self, webview: &WebView, outer_size: DeviceIntSize)
42    -> Option<DeviceIntSize>;
43    fn set_position(&self, _point: DeviceIntPoint) {}
44    fn set_fullscreen(&self, _state: bool) {}
45    fn set_cursor(&self, _cursor: Cursor) {}
46    #[cfg(feature = "webxr")]
47    fn new_glwindow(
48        &self,
49        event_loop: &winit::event_loop::ActiveEventLoop,
50    ) -> Rc<dyn servo::webxr::glwindow::GlWindow>;
51    fn winit_window(&self) -> Option<&winit::window::Window>;
52    fn toolbar_height(&self) -> Length<f32, DeviceIndependentPixel>;
53    fn set_toolbar_height(&self, height: Length<f32, DeviceIndependentPixel>);
54    /// This returns [`RenderingContext`] matching the viewport.
55    fn rendering_context(&self) -> Rc<dyn RenderingContext>;
56    fn show_ime(
57        &self,
58        _input_type: servo::InputMethodType,
59        _text: Option<(String, i32)>,
60        _multiline: bool,
61        _position: servo::webrender_api::units::DeviceIntRect,
62    ) {
63    }
64    fn hide_ime(&self) {}
65    fn theme(&self) -> servo::Theme {
66        servo::Theme::Light
67    }
68    fn window_rect(&self) -> DeviceIndependentIntRect;
69    fn maximize(&self, webview: &WebView);
70}