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::{
14    Cursor, InputEventId, InputEventResult, InputMethodControl, RenderingContext, ScreenGeometry,
15    WebView,
16};
17
18use super::app_state::RunningAppState;
19
20// This should vary by zoom level and maybe actual text size (focused or under cursor)
21pub(crate) const LINE_HEIGHT: f32 = 76.0;
22pub(crate) const LINE_WIDTH: f32 = 76.0;
23
24/// <https://github.com/web-platform-tests/wpt/blob/9320b1f724632c52929a3fdb11bdaf65eafc7611/webdriver/tests/classic/set_window_rect/set.py#L287-L290>
25/// "A window size of 10x10px shouldn't be supported by any browser."
26pub(crate) const MIN_WINDOW_INNER_SIZE: DeviceIntSize = DeviceIntSize::new(100, 100);
27
28pub trait WindowPortsMethods {
29    fn id(&self) -> winit::window::WindowId;
30    fn screen_geometry(&self) -> ScreenGeometry;
31    fn device_hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
32    fn hidpi_scale_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel>;
33    fn get_fullscreen(&self) -> bool;
34    fn handle_winit_event(&self, state: Rc<RunningAppState>, event: winit::event::WindowEvent);
35    fn set_title(&self, _title: &str) {}
36    fn set_title_if_changed(&self, _title: &str) -> bool {
37        false
38    }
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(&self, _input_method: InputMethodControl) {}
57    fn hide_ime(&self) {}
58    fn theme(&self) -> servo::Theme {
59        servo::Theme::Light
60    }
61    fn window_rect(&self) -> DeviceIndependentIntRect;
62    fn maximize(&self, webview: &WebView);
63
64    fn notify_input_event_handled(
65        &self,
66        _webview: &WebView,
67        _id: InputEventId,
68        _result: InputEventResult,
69    ) {
70    }
71}