mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
libservo: Stop using script_traits
in the embedding layer (#35185)
Many types used directly in the `libservo` API are in the `script_traits` crate, which was created to break circular dependencies. Move all API exposed types to `embedder_traits` which now contains types exposed via the `libservo` embedding API. Also expose these at the root of the `libservo` `servo` crate so that the API won't break when they move around in the future. The idea with `embedder_traits` in the future is that it contains types that are available throughout servo because they are used in the embedding API and thus should have minimal dependencies on other Servo crates (a bit like `base`). Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
78b90030bd
commit
a1cf0cbf86
39 changed files with 330 additions and 334 deletions
|
@ -13,15 +13,14 @@ use std::{env, fs};
|
|||
use log::{info, trace};
|
||||
use raw_window_handle::HasDisplayHandle;
|
||||
use servo::base::id::WebViewId;
|
||||
use servo::compositing::windowing::{EmbedderEvent, WindowMethods};
|
||||
use servo::compositing::windowing::{AnimationState, EmbedderEvent, WindowMethods};
|
||||
use servo::compositing::CompositeTarget;
|
||||
use servo::config::opts::Opts;
|
||||
use servo::config::prefs::Preferences;
|
||||
use servo::embedder_traits::EventLoopWaker;
|
||||
use servo::servo_config::pref;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::Servo;
|
||||
use servo::{EventLoopWaker, Servo};
|
||||
use surfman::Connection;
|
||||
use webxr::glwindow::GlWindowDiscovery;
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -201,7 +200,7 @@ impl App {
|
|||
fn get_coordinates(&self) -> servo::compositing::windowing::EmbedderCoordinates {
|
||||
self.0.get_coordinates()
|
||||
}
|
||||
fn set_animation_state(&self, state: servo::compositing::windowing::AnimationState) {
|
||||
fn set_animation_state(&self, state: AnimationState) {
|
||||
self.0.set_animation_state(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
use net::protocols::ProtocolRegistry;
|
||||
use servo::compositing::windowing::EmbedderMethods;
|
||||
use servo::embedder_traits::{EmbedderProxy, EventLoopWaker};
|
||||
use servo::servo_config::pref;
|
||||
use servo::{EmbedderProxy, EventLoopWaker};
|
||||
use webxr::glwindow::GlWindowDiscovery;
|
||||
#[cfg(target_os = "windows")]
|
||||
use webxr::openxr::OpenXrDiscovery;
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::{Arc, Condvar, Mutex};
|
|||
use std::time;
|
||||
|
||||
use log::warn;
|
||||
use servo::embedder_traits::EventLoopWaker;
|
||||
use servo::EventLoopWaker;
|
||||
use winit::error::EventLoopError;
|
||||
use winit::event_loop::EventLoop as WinitEventLoop;
|
||||
#[cfg(target_os = "macos")]
|
||||
|
|
|
@ -15,14 +15,15 @@ use servo::compositing::windowing::{
|
|||
AnimationState, EmbedderCoordinates, EmbedderEvent, MouseWindowEvent, WindowMethods,
|
||||
};
|
||||
use servo::config::opts::Opts;
|
||||
use servo::embedder_traits::Cursor;
|
||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
use servo::script_traits::{TouchEventType, WheelDelta, WheelMode};
|
||||
use servo::servo_config::pref;
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::{
|
||||
Cursor, Key, KeyState, KeyboardEvent, MouseButton as ServoMouseButton, Theme, TouchEventType,
|
||||
TouchId, WheelDelta, WheelMode,
|
||||
};
|
||||
use surfman::{Context, Device, SurfaceType};
|
||||
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
|
||||
use winit::event::{ElementState, KeyEvent, MouseButton, MouseScrollDelta, TouchPhase};
|
||||
|
@ -40,7 +41,7 @@ pub struct Window {
|
|||
screen_size: Size2D<u32, DeviceIndependentPixel>,
|
||||
inner_size: Cell<PhysicalSize<u32>>,
|
||||
toolbar_height: Cell<Length<f32, DeviceIndependentPixel>>,
|
||||
mouse_down_button: Cell<Option<winit::event::MouseButton>>,
|
||||
mouse_down_button: Cell<Option<MouseButton>>,
|
||||
mouse_down_point: Cell<Point2D<i32, DevicePixel>>,
|
||||
monitor: winit::monitor::MonitorHandle,
|
||||
event_queue: RefCell<Vec<EmbedderEvent>>,
|
||||
|
@ -228,18 +229,16 @@ impl Window {
|
|||
/// Helper function to handle a click
|
||||
fn handle_mouse(
|
||||
&self,
|
||||
button: winit::event::MouseButton,
|
||||
action: winit::event::ElementState,
|
||||
button: MouseButton,
|
||||
action: ElementState,
|
||||
coords: Point2D<i32, DevicePixel>,
|
||||
) {
|
||||
use servo::script_traits::MouseButton;
|
||||
|
||||
let max_pixel_dist = 10.0 * self.hidpi_factor().get();
|
||||
let mouse_button = match &button {
|
||||
winit::event::MouseButton::Left => MouseButton::Left,
|
||||
winit::event::MouseButton::Right => MouseButton::Right,
|
||||
winit::event::MouseButton::Middle => MouseButton::Middle,
|
||||
_ => MouseButton::Left,
|
||||
MouseButton::Left => ServoMouseButton::Left,
|
||||
MouseButton::Right => ServoMouseButton::Right,
|
||||
MouseButton::Middle => ServoMouseButton::Middle,
|
||||
_ => ServoMouseButton::Left,
|
||||
};
|
||||
let event = match action {
|
||||
ElementState::Pressed => {
|
||||
|
@ -455,8 +454,6 @@ impl WindowPortsMethods for Window {
|
|||
self.event_queue.borrow_mut().push(scroll_event);
|
||||
},
|
||||
winit::event::WindowEvent::Touch(touch) => {
|
||||
use servo::script_traits::TouchId;
|
||||
|
||||
let phase = winit_phase_to_touch_event_type(touch.phase);
|
||||
let id = TouchId(touch.id as i32);
|
||||
let position = touch.location;
|
||||
|
@ -484,8 +481,8 @@ impl WindowPortsMethods for Window {
|
|||
},
|
||||
winit::event::WindowEvent::ThemeChanged(theme) => {
|
||||
let theme = match theme {
|
||||
winit::window::Theme::Light => servo::script_traits::Theme::Light,
|
||||
winit::window::Theme::Dark => servo::script_traits::Theme::Dark,
|
||||
winit::window::Theme::Light => Theme::Light,
|
||||
winit::window::Theme::Dark => Theme::Dark,
|
||||
};
|
||||
self.event_queue
|
||||
.borrow_mut()
|
||||
|
|
|
@ -21,12 +21,11 @@ use glow::NativeFramebuffer;
|
|||
use log::{trace, warn};
|
||||
use servo::base::id::WebViewId;
|
||||
use servo::compositing::windowing::EmbedderEvent;
|
||||
use servo::script_traits::TraversalDirection;
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_api::units::DevicePixel;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::TopLevelBrowsingContextId;
|
||||
use servo::{TopLevelBrowsingContextId, TraversalDirection};
|
||||
use winit::event::{ElementState, MouseButton, WindowEvent};
|
||||
use winit::event_loop::ActiveEventLoop;
|
||||
use winit::window::Window;
|
||||
|
|
|
@ -22,7 +22,7 @@ macro_rules! trace_winit_event {
|
|||
};
|
||||
}
|
||||
|
||||
/// Log an event from servo ([servo::embedder_traits::EmbedderMsg]) at trace level.
|
||||
/// Log an event from servo ([servo::EmbedderMsg]) at trace level.
|
||||
/// - To disable tracing: RUST_LOG='servoshell<servo@=off'
|
||||
/// - To enable tracing: RUST_LOG='servoshell<servo@'
|
||||
/// - Recommended filters when tracing is enabled:
|
||||
|
@ -139,7 +139,7 @@ mod from_servo {
|
|||
};
|
||||
}
|
||||
|
||||
impl LogTarget for servo::embedder_traits::EmbedderMsg {
|
||||
impl LogTarget for servo::EmbedderMsg {
|
||||
fn log_target(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Status(..) => target!("Status"),
|
||||
|
|
|
@ -20,19 +20,17 @@ use log::{debug, error, info, trace, warn};
|
|||
use servo::base::id::TopLevelBrowsingContextId as WebViewId;
|
||||
use servo::compositing::windowing::{EmbedderEvent, WebRenderDebugOption};
|
||||
use servo::config::opts::Opts;
|
||||
use servo::embedder_traits::{
|
||||
CompositorEventVariant, ContextMenuResult, DualRumbleEffectParams, EmbedderMsg, FilterPattern,
|
||||
GamepadHapticEffectType, PermissionPrompt, PermissionRequest, PromptCredentialsInput,
|
||||
PromptDefinition, PromptOrigin, PromptResult,
|
||||
};
|
||||
use servo::ipc_channel::ipc::IpcSender;
|
||||
use servo::script_traits::{
|
||||
ClipboardEventType, GamepadEvent, GamepadIndex, GamepadInputBounds,
|
||||
GamepadSupportedHapticEffects, GamepadUpdateType, TouchEventType, TraversalDirection,
|
||||
};
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_api::units::DeviceRect;
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::{
|
||||
ClipboardEventType, CompositorEventVariant, ContextMenuResult, DualRumbleEffectParams,
|
||||
EmbedderMsg, FilterPattern, GamepadEvent, GamepadHapticEffectType, GamepadIndex,
|
||||
GamepadInputBounds, GamepadSupportedHapticEffects, GamepadUpdateType, PermissionPrompt,
|
||||
PermissionRequest, PromptCredentialsInput, PromptDefinition, PromptOrigin, PromptResult,
|
||||
TouchEventType, TraversalDirection,
|
||||
};
|
||||
use tinyfiledialogs::{self, MessageBoxIcon, OkCancel, YesNo};
|
||||
|
||||
use super::keyutils::{CMD_OR_ALT, CMD_OR_CONTROL};
|
||||
|
|
|
@ -9,9 +9,9 @@ use std::rc::Rc;
|
|||
|
||||
use euclid::{Length, Scale};
|
||||
use servo::compositing::windowing::{EmbedderEvent, WindowMethods};
|
||||
use servo::embedder_traits::Cursor;
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize, DevicePixel};
|
||||
use servo::Cursor;
|
||||
|
||||
// This should vary by zoom level and maybe actual text size (focused or under cursor)
|
||||
pub const LINE_HEIGHT: f32 = 38.0;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
use std::path::PathBuf;
|
||||
|
||||
use servo::embedder_traits::resources::{Resource, ResourceReaderMethods};
|
||||
use servo::resources::{Resource, ResourceReaderMethods};
|
||||
|
||||
pub(crate) struct ResourceReaderInstance;
|
||||
|
||||
|
|
|
@ -10,16 +10,15 @@ use std::rc::Rc;
|
|||
use servo::base::id::WebViewId;
|
||||
use servo::compositing::windowing::EmbedderEvent;
|
||||
use servo::compositing::CompositeTarget;
|
||||
use servo::embedder_traits::resources;
|
||||
/// The EventLoopWaker::wake function will be called from any thread.
|
||||
/// It will be called to notify embedder that some events are available,
|
||||
/// and that perform_updates need to be called
|
||||
pub use servo::embedder_traits::EventLoopWaker;
|
||||
pub use servo::embedder_traits::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use servo::servo_url::ServoUrl;
|
||||
pub use servo::webrender_api::units::DeviceIntRect;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::{self, Servo};
|
||||
/// The EventLoopWaker::wake function will be called from any thread.
|
||||
/// It will be called to notify embedder that some events are available,
|
||||
/// and that perform_updates need to be called
|
||||
pub use servo::EventLoopWaker;
|
||||
use servo::{self, resources, Servo};
|
||||
pub use servo::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use surfman::{Connection, SurfaceType};
|
||||
|
||||
use crate::egl::android::resources::ResourceReaderInstance;
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use servo::embedder_traits::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use servo::webrender_api::units::DeviceIntRect;
|
||||
use servo::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
|
||||
/// Callbacks. Implemented by embedder. Called by Servo.
|
||||
pub trait HostTrait {
|
||||
|
|
|
@ -21,9 +21,8 @@ use napi_ohos::{Env, JsObject, JsString, NapiRaw};
|
|||
use ohos_ime::{AttachOptions, Ime, ImeProxy, RawTextEditorProxy};
|
||||
use ohos_ime_sys::types::InputMethod_EnterKeyType;
|
||||
use servo::compositing::windowing::EmbedderEvent;
|
||||
use servo::embedder_traits;
|
||||
use servo::embedder_traits::{InputMethodType, PromptResult};
|
||||
use servo::style::Zero;
|
||||
use servo::{InputMethodType, MediaSessionPlaybackState, PromptResult};
|
||||
use simpleservo::EventLoopWaker;
|
||||
use xcomponent_sys::{
|
||||
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
|
||||
|
@ -740,7 +739,7 @@ impl HostTrait for HostCallbacks {
|
|||
/// and shows the soft keyboard with default settings.
|
||||
fn on_ime_show(
|
||||
&self,
|
||||
input_type: embedder_traits::InputMethodType,
|
||||
input_type: InputMethodType,
|
||||
_text: Option<(String, i32)>,
|
||||
multiline: bool,
|
||||
_bounds: servo::webrender_api::units::DeviceIntRect,
|
||||
|
@ -790,10 +789,7 @@ impl HostTrait for HostCallbacks {
|
|||
warn!("on_media_session_metadata not implemented");
|
||||
}
|
||||
|
||||
fn on_media_session_playback_state_change(
|
||||
&self,
|
||||
state: servo::embedder_traits::MediaSessionPlaybackState,
|
||||
) {
|
||||
fn on_media_session_playback_state_change(&self, state: MediaSessionPlaybackState) {
|
||||
warn!("on_media_session_playback_state_change not implemented");
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use servo::embedder_traits::resources::{Resource, ResourceReaderMethods};
|
||||
use servo::resources::{Resource, ResourceReaderMethods};
|
||||
|
||||
pub(crate) struct ResourceReaderInstance {
|
||||
resource_dir: PathBuf,
|
||||
|
|
|
@ -11,15 +11,14 @@ use log::{debug, error, info};
|
|||
use servo::base::id::WebViewId;
|
||||
use servo::compositing::windowing::EmbedderEvent;
|
||||
use servo::compositing::CompositeTarget;
|
||||
use servo::embedder_traits::resources;
|
||||
/// The EventLoopWaker::wake function will be called from any thread.
|
||||
/// It will be called to notify embedder that some events are available,
|
||||
/// and that perform_updates need to be called
|
||||
pub use servo::embedder_traits::EventLoopWaker;
|
||||
use servo::euclid::Size2D;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::{self, Servo};
|
||||
/// The EventLoopWaker::wake function will be called from any thread.
|
||||
/// It will be called to notify embedder that some events are available,
|
||||
/// and that perform_updates need to be called
|
||||
pub use servo::EventLoopWaker;
|
||||
use servo::{self, resources, Servo};
|
||||
use surfman::{Connection, SurfaceType};
|
||||
use xcomponent_sys::{OH_NativeXComponent, OH_NativeXComponent_GetXComponentSize};
|
||||
|
||||
|
|
|
@ -15,20 +15,17 @@ use servo::compositing::windowing::{
|
|||
AnimationState, EmbedderCoordinates, EmbedderEvent, EmbedderMethods, MouseWindowEvent,
|
||||
WindowMethods,
|
||||
};
|
||||
use servo::embedder_traits::{
|
||||
ContextMenuResult, EmbedderMsg, EmbedderProxy, EventLoopWaker, MediaSessionEvent,
|
||||
PermissionPrompt, PermissionRequest, PromptDefinition, PromptOrigin, PromptResult,
|
||||
};
|
||||
use servo::euclid::{Box2D, Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
use servo::script_traits::{
|
||||
MediaSessionActionType, MouseButton, TouchEventType, TouchId, TraversalDirection,
|
||||
};
|
||||
use servo::servo_geometry::DeviceIndependentPixel;
|
||||
use servo::webrender_api::units::DevicePixel;
|
||||
use servo::webrender_api::ScrollLocation;
|
||||
use servo::webrender_traits::SurfmanRenderingContext;
|
||||
use servo::{Servo, TopLevelBrowsingContextId};
|
||||
use servo::{
|
||||
ContextMenuResult, EmbedderMsg, EmbedderProxy, EventLoopWaker, Key, KeyState, KeyboardEvent,
|
||||
MediaSessionActionType, MediaSessionEvent, MouseButton, PermissionPrompt, PermissionRequest,
|
||||
PromptDefinition, PromptOrigin, PromptResult, Servo, TopLevelBrowsingContextId, TouchEventType,
|
||||
TouchId, TraversalDirection,
|
||||
};
|
||||
|
||||
use crate::egl::host_trait::HostTrait;
|
||||
use crate::prefs::ServoShellPreferences;
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::sync::Mutex;
|
|||
use std::{env, fs};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use servo::embedder_traits::resources::{self, Resource};
|
||||
use servo::resources::{self, Resource};
|
||||
|
||||
static CMD_RESOURCE_DIR: Mutex<Option<PathBuf>> = Mutex::new(None);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue