mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
servoshell: Move initial_window_size
and screen_size_override
into ServoShellPreferences
from Opts
(#35407)
These settings just configure `servoshell` so should be in `ServoShellPreferences` instead. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
bea7a969f4
commit
118a813dba
5 changed files with 32 additions and 42 deletions
|
@ -9,9 +9,7 @@ use std::default::Default;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
|
use std::sync::{LazyLock, RwLock, RwLockReadGuard};
|
||||||
|
|
||||||
use euclid::Size2D;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use servo_geometry::DeviceIndependentPixel;
|
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
|
||||||
/// Global flags for Servo, currently set on the command line.
|
/// Global flags for Servo, currently set on the command line.
|
||||||
|
@ -59,13 +57,6 @@ pub struct Opts {
|
||||||
/// remote WebDriver commands.
|
/// remote WebDriver commands.
|
||||||
pub webdriver_port: Option<u16>,
|
pub webdriver_port: Option<u16>,
|
||||||
|
|
||||||
/// The initial requested size of the window.
|
|
||||||
pub initial_window_size: Size2D<u32, DeviceIndependentPixel>,
|
|
||||||
|
|
||||||
/// An override for the screen resolution. This is useful for testing behavior on different screen sizes,
|
|
||||||
/// such as the screen of a mobile device.
|
|
||||||
pub screen_size_override: Option<Size2D<u32, DeviceIndependentPixel>>,
|
|
||||||
|
|
||||||
/// Whether we're running in multiprocess mode.
|
/// Whether we're running in multiprocess mode.
|
||||||
pub multiprocess: bool,
|
pub multiprocess: bool,
|
||||||
|
|
||||||
|
@ -213,8 +204,6 @@ impl Default for Opts {
|
||||||
output_file: None,
|
output_file: None,
|
||||||
hard_fail: true,
|
hard_fail: true,
|
||||||
webdriver_port: None,
|
webdriver_port: None,
|
||||||
initial_window_size: Size2D::new(1024, 740),
|
|
||||||
screen_size_override: None,
|
|
||||||
multiprocess: false,
|
multiprocess: false,
|
||||||
background_hang_monitor: false,
|
background_hang_monitor: false,
|
||||||
random_pipeline_closure_probability: None,
|
random_pipeline_closure_probability: None,
|
||||||
|
|
|
@ -103,6 +103,7 @@ impl App {
|
||||||
/// Initialize Application once event loop start running.
|
/// Initialize Application once event loop start running.
|
||||||
pub fn init(&mut self, event_loop: Option<&ActiveEventLoop>) {
|
pub fn init(&mut self, event_loop: Option<&ActiveEventLoop>) {
|
||||||
// Create rendering context
|
// Create rendering context
|
||||||
|
let initial_window_size = self.servoshell_preferences.initial_window_size;
|
||||||
let rendering_context = if self.servoshell_preferences.headless {
|
let rendering_context = if self.servoshell_preferences.headless {
|
||||||
let connection = Connection::new().expect("Failed to create connection");
|
let connection = Connection::new().expect("Failed to create connection");
|
||||||
let adapter = connection
|
let adapter = connection
|
||||||
|
@ -111,7 +112,7 @@ impl App {
|
||||||
SurfmanRenderingContext::create(
|
SurfmanRenderingContext::create(
|
||||||
&connection,
|
&connection,
|
||||||
&adapter,
|
&adapter,
|
||||||
Some(self.opts.initial_window_size.to_untyped().to_i32()),
|
Some(initial_window_size.to_untyped().to_i32()),
|
||||||
)
|
)
|
||||||
.expect("Failed to create WR surfman")
|
.expect("Failed to create WR surfman")
|
||||||
} else {
|
} else {
|
||||||
|
@ -130,19 +131,13 @@ impl App {
|
||||||
|
|
||||||
let headless = self.servoshell_preferences.headless;
|
let headless = self.servoshell_preferences.headless;
|
||||||
let window = if headless {
|
let window = if headless {
|
||||||
headless_window::Window::new(
|
headless_window::Window::new(&self.servoshell_preferences)
|
||||||
self.opts.initial_window_size,
|
|
||||||
self.servoshell_preferences.device_pixel_ratio_override,
|
|
||||||
self.opts.screen_size_override,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
Rc::new(headed_window::Window::new(
|
Rc::new(headed_window::Window::new(
|
||||||
&self.opts,
|
&self.opts,
|
||||||
|
&self.servoshell_preferences,
|
||||||
&rendering_context,
|
&rendering_context,
|
||||||
self.opts.initial_window_size,
|
|
||||||
event_loop.unwrap(),
|
event_loop.unwrap(),
|
||||||
self.servoshell_preferences.no_native_titlebar,
|
|
||||||
self.servoshell_preferences.device_pixel_ratio_override,
|
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ use super::geometry::{winit_position_to_euclid_point, winit_size_to_euclid_size}
|
||||||
use super::keyutils::{keyboard_event_from_winit, CMD_OR_ALT};
|
use super::keyutils::{keyboard_event_from_winit, CMD_OR_ALT};
|
||||||
use super::window_trait::{WindowPortsMethods, LINE_HEIGHT};
|
use super::window_trait::{WindowPortsMethods, LINE_HEIGHT};
|
||||||
use crate::desktop::keyutils::CMD_OR_CONTROL;
|
use crate::desktop::keyutils::CMD_OR_CONTROL;
|
||||||
|
use crate::prefs::ServoShellPreferences;
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
winit_window: winit::window::Window,
|
winit_window: winit::window::Window,
|
||||||
|
@ -65,18 +66,18 @@ pub struct Window {
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
opts: &Opts,
|
opts: &Opts,
|
||||||
|
servoshell_preferences: &ServoShellPreferences,
|
||||||
rendering_context: &SurfmanRenderingContext,
|
rendering_context: &SurfmanRenderingContext,
|
||||||
window_size: Size2D<u32, DeviceIndependentPixel>,
|
|
||||||
event_loop: &ActiveEventLoop,
|
event_loop: &ActiveEventLoop,
|
||||||
no_native_titlebar: bool,
|
|
||||||
device_pixel_ratio_override: Option<f32>,
|
|
||||||
) -> Window {
|
) -> Window {
|
||||||
// If there's no chrome, start off with the window invisible. It will be set to visible in
|
// If there's no chrome, start off with the window invisible. It will be set to visible in
|
||||||
// `load_end()`. This avoids an ugly flash of unstyled content (especially important since
|
// `load_end()`. This avoids an ugly flash of unstyled content (especially important since
|
||||||
// unstyled content is white and chrome often has a transparent background). See issue
|
// unstyled content is white and chrome often has a transparent background). See issue
|
||||||
// #9996.
|
// #9996.
|
||||||
let visible = opts.output_file.is_none() && !no_native_titlebar;
|
let no_native_titlebar = servoshell_preferences.no_native_titlebar;
|
||||||
|
let visible = opts.output_file.is_none() && !servoshell_preferences.no_native_titlebar;
|
||||||
|
|
||||||
|
let window_size = servoshell_preferences.initial_window_size;
|
||||||
let window_attr = winit::window::Window::default_attributes()
|
let window_attr = winit::window::Window::default_attributes()
|
||||||
.with_title("Servo".to_string())
|
.with_title("Servo".to_string())
|
||||||
.with_decorations(!no_native_titlebar)
|
.with_decorations(!no_native_titlebar)
|
||||||
|
@ -100,7 +101,7 @@ impl Window {
|
||||||
.or_else(|| winit_window.available_monitors().nth(0))
|
.or_else(|| winit_window.available_monitors().nth(0))
|
||||||
.expect("No monitor detected");
|
.expect("No monitor detected");
|
||||||
|
|
||||||
let (screen_size, screen_scale) = opts.screen_size_override.map_or_else(
|
let (screen_size, screen_scale) = servoshell_preferences.screen_size_override.map_or_else(
|
||||||
|| (monitor.size(), monitor.scale_factor()),
|
|| (monitor.size(), monitor.scale_factor()),
|
||||||
|size| (PhysicalSize::new(size.width, size.height), 1.0),
|
|size| (PhysicalSize::new(size.width, size.height), 1.0),
|
||||||
);
|
);
|
||||||
|
@ -145,7 +146,7 @@ impl Window {
|
||||||
inner_size: Cell::new(inner_size),
|
inner_size: Cell::new(inner_size),
|
||||||
monitor,
|
monitor,
|
||||||
screen_size,
|
screen_size,
|
||||||
device_pixel_ratio_override,
|
device_pixel_ratio_override: servoshell_preferences.device_pixel_ratio_override,
|
||||||
xr_window_poses: RefCell::new(vec![]),
|
xr_window_poses: RefCell::new(vec![]),
|
||||||
modifiers_state: Cell::new(ModifiersState::empty()),
|
modifiers_state: Cell::new(ModifiersState::empty()),
|
||||||
toolbar_height: Cell::new(Default::default()),
|
toolbar_height: Cell::new(Default::default()),
|
||||||
|
|
|
@ -15,6 +15,7 @@ use servo::webrender_api::units::{DeviceIntSize, DevicePixel};
|
||||||
|
|
||||||
use super::app_state::RunningAppState;
|
use super::app_state::RunningAppState;
|
||||||
use crate::desktop::window_trait::WindowPortsMethods;
|
use crate::desktop::window_trait::WindowPortsMethods;
|
||||||
|
use crate::prefs::ServoShellPreferences;
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
animation_state: Cell<AnimationState>,
|
animation_state: Cell<AnimationState>,
|
||||||
|
@ -27,20 +28,17 @@ pub struct Window {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
#[allow(clippy::new_ret_no_self)]
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub fn new(
|
pub fn new(servoshell_preferences: &ServoShellPreferences) -> Rc<dyn WindowPortsMethods> {
|
||||||
size: Size2D<u32, DeviceIndependentPixel>,
|
let device_pixel_ratio_override = servoshell_preferences.device_pixel_ratio_override;
|
||||||
device_pixel_ratio_override: Option<f32>,
|
|
||||||
screen_size_override: Option<Size2D<u32, DeviceIndependentPixel>>,
|
|
||||||
) -> Rc<dyn WindowPortsMethods> {
|
|
||||||
let device_pixel_ratio_override: Option<Scale<f32, DeviceIndependentPixel, DevicePixel>> =
|
let device_pixel_ratio_override: Option<Scale<f32, DeviceIndependentPixel, DevicePixel>> =
|
||||||
device_pixel_ratio_override.map(Scale::new);
|
device_pixel_ratio_override.map(Scale::new);
|
||||||
let hidpi_factor = device_pixel_ratio_override.unwrap_or_else(Scale::identity);
|
let hidpi_factor = device_pixel_ratio_override.unwrap_or_else(Scale::identity);
|
||||||
|
|
||||||
let size = size.to_i32();
|
let size = servoshell_preferences.initial_window_size.to_i32();
|
||||||
let inner_size = Cell::new((size.to_f32() * hidpi_factor).to_i32());
|
let inner_size = Cell::new((size.to_f32() * hidpi_factor).to_i32());
|
||||||
let window_rect = Box2D::from_origin_and_size(Point2D::zero(), size);
|
let window_rect = Box2D::from_origin_and_size(Point2D::zero(), size);
|
||||||
|
|
||||||
let screen_size = screen_size_override.map_or_else(
|
let screen_size = servoshell_preferences.screen_size_override.map_or_else(
|
||||||
|| window_rect.size(),
|
|| window_rect.size(),
|
||||||
|screen_size_override| screen_size_override.to_i32(),
|
|screen_size_override| screen_size_override.to_i32(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,6 +14,7 @@ use log::{error, warn};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use servo::config::opts::{DebugOptions, Opts, OutputOptions};
|
use servo::config::opts::{DebugOptions, Opts, OutputOptions};
|
||||||
use servo::config::prefs::{PrefValue, Preferences};
|
use servo::config::prefs::{PrefValue, Preferences};
|
||||||
|
use servo::servo_geometry::DeviceIndependentPixel;
|
||||||
use servo::servo_url::ServoUrl;
|
use servo::servo_url::ServoUrl;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -42,20 +43,27 @@ pub(crate) struct ServoShellPreferences {
|
||||||
/// Overrides directives specified via `SERVO_TRACING` if set.
|
/// Overrides directives specified via `SERVO_TRACING` if set.
|
||||||
/// See: <https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html#directives>
|
/// See: <https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/filter/struct.EnvFilter.html#directives>
|
||||||
pub tracing_filter: Option<String>,
|
pub tracing_filter: Option<String>,
|
||||||
|
/// The initial requested size of the window.
|
||||||
|
pub initial_window_size: Size2D<u32, DeviceIndependentPixel>,
|
||||||
|
/// An override for the screen resolution. This is useful for testing behavior on different screen sizes,
|
||||||
|
/// such as the screen of a mobile device.
|
||||||
|
pub screen_size_override: Option<Size2D<u32, DeviceIndependentPixel>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ServoShellPreferences {
|
impl Default for ServoShellPreferences {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
user_agent: None,
|
|
||||||
url: None,
|
|
||||||
device_pixel_ratio_override: None,
|
|
||||||
clean_shutdown: false,
|
clean_shutdown: false,
|
||||||
homepage: "https://servo.org".into(),
|
device_pixel_ratio_override: None,
|
||||||
no_native_titlebar: true,
|
|
||||||
searchpage: "https://duckduckgo.com/html/?q=%s".into(),
|
|
||||||
headless: false,
|
headless: false,
|
||||||
|
homepage: "https://servo.org".into(),
|
||||||
|
initial_window_size: Size2D::new(1024, 740),
|
||||||
|
no_native_titlebar: true,
|
||||||
|
screen_size_override: None,
|
||||||
|
searchpage: "https://duckduckgo.com/html/?q=%s".into(),
|
||||||
tracing_filter: None,
|
tracing_filter: None,
|
||||||
|
url: None,
|
||||||
|
user_agent: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,7 +500,6 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
||||||
.map_or(default_window_size, |screen_size_override| {
|
.map_or(default_window_size, |screen_size_override| {
|
||||||
default_window_size.min(screen_size_override)
|
default_window_size.min(screen_size_override)
|
||||||
});
|
});
|
||||||
|
|
||||||
let initial_window_size = opt_match
|
let initial_window_size = opt_match
|
||||||
.opt_str("window-size")
|
.opt_str("window-size")
|
||||||
.map_or(default_window_size, parse_resolution_string);
|
.map_or(default_window_size, parse_resolution_string);
|
||||||
|
@ -565,6 +572,8 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
||||||
clean_shutdown: opt_match.opt_present("clean-shutdown"),
|
clean_shutdown: opt_match.opt_present("clean-shutdown"),
|
||||||
headless: opt_match.opt_present("z"),
|
headless: opt_match.opt_present("z"),
|
||||||
tracing_filter,
|
tracing_filter,
|
||||||
|
initial_window_size,
|
||||||
|
screen_size_override,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -585,8 +594,6 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
|
||||||
output_file,
|
output_file,
|
||||||
hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"),
|
hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"),
|
||||||
webdriver_port,
|
webdriver_port,
|
||||||
initial_window_size,
|
|
||||||
screen_size_override,
|
|
||||||
multiprocess: opt_match.opt_present("M"),
|
multiprocess: opt_match.opt_present("M"),
|
||||||
background_hang_monitor: opt_match.opt_present("B"),
|
background_hang_monitor: opt_match.opt_present("B"),
|
||||||
sandbox: opt_match.opt_present("S"),
|
sandbox: opt_match.opt_present("S"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue