diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 9c4fbf9ce8c..5f3c3cf9469 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -97,9 +97,9 @@ impl FrameTreeId { } /// NB: Never block on the constellation, because sometimes the constellation blocks on us. -pub struct IOCompositor { +pub struct IOCompositor { /// The application window. - pub window: Rc, + pub window: Rc, /// The port on which we receive messages. port: CompositorReceiver, @@ -356,9 +356,9 @@ pub enum CompositeTarget { PngFile(Rc), } -impl IOCompositor { +impl IOCompositor { pub fn new( - window: Rc, + window: Rc, state: InitialCompositorState, composite_target: CompositeTarget, exit_after_load: bool, diff --git a/components/servo/examples/winit_minimal.rs b/components/servo/examples/winit_minimal.rs index 08f5ad4fac2..da4742ca880 100644 --- a/components/servo/examples/winit_minimal.rs +++ b/components/servo/examples/winit_minimal.rs @@ -44,7 +44,7 @@ enum App { Initial(Waker), Running { window_delegate: Rc, - servo: Servo, + servo: Servo, }, Exiting, } diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 5e26f406ae5..a516f228019 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -176,8 +176,8 @@ mod media_platform { /// application Servo is embedded in. Clients then create an event /// loop to pump messages between the embedding application and /// various browser components. -pub struct Servo { - compositor: IOCompositor, +pub struct Servo { + compositor: IOCompositor, constellation_chan: Sender, embedder_receiver: EmbedderReceiver, messages_for_embedder: Vec<(Option, EmbedderMsg)>, @@ -221,10 +221,7 @@ impl webrender_api::RenderNotifier for RenderNotifier { } } -impl Servo -where - Window: WindowMethods + 'static + ?Sized, -{ +impl Servo { #[cfg_attr( feature = "tracing", tracing::instrument( @@ -233,16 +230,15 @@ where level = "trace", ) )] - #[allow(clippy::new_ret_no_self)] pub fn new( opts: Opts, preferences: Preferences, rendering_context: Rc, mut embedder: Box, - window: Rc, + window: Rc, user_agent: Option, composite_target: CompositeTarget, - ) -> Servo { + ) -> Self { // Global configuration options, parsed from the command line. opts::set_options(opts); let opts = opts::get(); @@ -982,7 +978,7 @@ where log::set_max_level(filter); } - pub fn window(&self) -> &Window { + pub fn window(&self) -> &Rc { &self.compositor.window } diff --git a/ports/servoshell/desktop/app.rs b/ports/servoshell/desktop/app.rs index 39bed45edcc..75449adac2b 100644 --- a/ports/servoshell/desktop/app.rs +++ b/ports/servoshell/desktop/app.rs @@ -13,7 +13,7 @@ use std::{env, fs}; use log::{info, trace}; use raw_window_handle::HasDisplayHandle; use servo::base::id::WebViewId; -use servo::compositing::windowing::EmbedderEvent; +use servo::compositing::windowing::{EmbedderEvent, WindowMethods}; use servo::compositing::CompositeTarget; use servo::config::opts::Opts; use servo::config::prefs::Preferences; @@ -45,7 +45,7 @@ pub struct App { opts: Opts, preferences: Preferences, servo_shell_preferences: ServoShellPreferences, - servo: Option>, + servo: Option, webviews: Option>, event_queue: Vec, suspended: Cell, @@ -194,7 +194,18 @@ impl App { None }; - let window = window.clone(); + // TODO: Remove this once dyn upcasting coercion stabilises + // + struct UpcastedWindow(Rc); + impl WindowMethods for UpcastedWindow { + fn get_coordinates(&self) -> servo::compositing::windowing::EmbedderCoordinates { + self.0.get_coordinates() + } + fn set_animation_state(&self, state: servo::compositing::windowing::AnimationState) { + self.0.set_animation_state(state); + } + } + let window = UpcastedWindow(window.clone()); // Implements embedder methods, used by libservo and constellation. let embedder = Box::new(EmbedderCallbacks::new(self.waker.clone(), xr_discovery)); @@ -208,7 +219,7 @@ impl App { self.preferences.clone(), Rc::new(rendering_context), embedder, - window.clone(), + Rc::new(window), self.servo_shell_preferences.user_agent.clone(), composite_target, ); diff --git a/ports/servoshell/egl/servo_glue.rs b/ports/servoshell/egl/servo_glue.rs index 77c2fda7829..4500efd5e05 100644 --- a/ports/servoshell/egl/servo_glue.rs +++ b/ports/servoshell/egl/servo_glue.rs @@ -80,7 +80,7 @@ pub struct WebView {} pub struct ServoGlue { rendering_context: SurfmanRenderingContext, - servo: Servo, + servo: Servo, batch_mode: bool, need_present: bool, callbacks: Rc, @@ -107,7 +107,7 @@ pub struct ServoGlue { impl ServoGlue { pub(super) fn new( rendering_context: SurfmanRenderingContext, - servo: Servo, + servo: Servo, callbacks: Rc, servoshell_preferences: ServoShellPreferences, ) -> Self {