mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00: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
|
@ -31,7 +31,10 @@ use bluetooth_traits::BluetoothRequest;
|
|||
use canvas_traits::webgl::WebGLPipeline;
|
||||
use crossbeam_channel::{RecvTimeoutError, Sender};
|
||||
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
|
||||
use embedder_traits::CompositorEventVariant;
|
||||
use embedder_traits::{
|
||||
ClipboardEventType, CompositorEventVariant, GamepadEvent, MediaSessionActionType, MouseButton,
|
||||
MouseEventType, Theme, TouchEventType, TouchId, WheelDelta,
|
||||
};
|
||||
use euclid::default::Point2D;
|
||||
use euclid::{Rect, Scale, Size2D, UnknownUnit, Vector2D};
|
||||
use http::{HeaderMap, Method};
|
||||
|
@ -65,7 +68,6 @@ use webrender_traits::{
|
|||
pub use crate::script_msg::{
|
||||
DOMMessage, EventResult, IFrameSizeMsg, Job, JobError, JobResult, JobResultValue, JobType,
|
||||
LayoutMsg, LogEntry, SWManagerMsg, SWManagerSenders, ScopeThings, ScriptMsg, ServiceWorkerMsg,
|
||||
TraversalDirection,
|
||||
};
|
||||
use crate::serializable::{BlobData, BlobImpl};
|
||||
use crate::transferable::MessagePortImpl;
|
||||
|
@ -470,96 +472,6 @@ pub enum AnimationState {
|
|||
NoAnimationCallbacksPresent,
|
||||
}
|
||||
|
||||
/// The type of input represented by a multi-touch event.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub enum TouchEventType {
|
||||
/// A new touch point came in contact with the screen.
|
||||
Down,
|
||||
/// An existing touch point changed location.
|
||||
Move,
|
||||
/// A touch point was removed from the screen.
|
||||
Up,
|
||||
/// The system stopped tracking a touch point.
|
||||
Cancel,
|
||||
}
|
||||
|
||||
/// An opaque identifier for a touch point.
|
||||
///
|
||||
/// <http://w3c.github.io/touch-events/#widl-Touch-identifier>
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct TouchId(pub i32);
|
||||
|
||||
/// The mouse button involved in the event.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
pub enum MouseButton {
|
||||
/// The left mouse button.
|
||||
Left = 1,
|
||||
/// The right mouse button.
|
||||
Right = 2,
|
||||
/// The middle mouse button.
|
||||
Middle = 4,
|
||||
}
|
||||
|
||||
/// The types of mouse events
|
||||
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
|
||||
pub enum MouseEventType {
|
||||
/// Mouse button clicked
|
||||
Click,
|
||||
/// Mouse button down
|
||||
MouseDown,
|
||||
/// Mouse button up
|
||||
MouseUp,
|
||||
}
|
||||
|
||||
/// Mode to measure WheelDelta floats in
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub enum WheelMode {
|
||||
/// Delta values are specified in pixels
|
||||
DeltaPixel = 0x00,
|
||||
/// Delta values are specified in lines
|
||||
DeltaLine = 0x01,
|
||||
/// Delta values are specified in pages
|
||||
DeltaPage = 0x02,
|
||||
}
|
||||
|
||||
/// The Wheel event deltas in every direction
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
||||
pub struct WheelDelta {
|
||||
/// Delta in the left/right direction
|
||||
pub x: f64,
|
||||
/// Delta in the up/down direction
|
||||
pub y: f64,
|
||||
/// Delta in the direction going into/out of the screen
|
||||
pub z: f64,
|
||||
/// Mode to measure the floats in
|
||||
pub mode: WheelMode,
|
||||
}
|
||||
|
||||
/// The types of clipboard events
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum ClipboardEventType {
|
||||
/// Contents of the system clipboard are changed
|
||||
Change,
|
||||
/// Copy
|
||||
Copy,
|
||||
/// Cut
|
||||
Cut,
|
||||
/// Paste
|
||||
Paste(String),
|
||||
}
|
||||
|
||||
impl ClipboardEventType {
|
||||
/// Convert to event name
|
||||
pub fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
ClipboardEventType::Change => "clipboardchange",
|
||||
ClipboardEventType::Copy => "copy",
|
||||
ClipboardEventType::Cut => "cut",
|
||||
ClipboardEventType::Paste(..) => "paste",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Events from the compositor that the script thread needs to know about
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum CompositorEvent {
|
||||
|
@ -784,15 +696,6 @@ pub enum WindowSizeType {
|
|||
Resize,
|
||||
}
|
||||
|
||||
/// The type of platform theme.
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum Theme {
|
||||
/// Light theme.
|
||||
Light,
|
||||
/// Dark theme.
|
||||
Dark,
|
||||
}
|
||||
|
||||
/// Messages to the constellation originating from the WebDriver server.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverCommandMsg {
|
||||
|
@ -1044,103 +947,3 @@ impl Clone for BroadcastMsg {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of MediaSession action.
|
||||
/// <https://w3c.github.io/mediasession/#enumdef-mediasessionaction>
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]
|
||||
pub enum MediaSessionActionType {
|
||||
/// The action intent is to resume playback.
|
||||
Play,
|
||||
/// The action intent is to pause the currently active playback.
|
||||
Pause,
|
||||
/// The action intent is to move the playback time backward by a short period (i.e. a few
|
||||
/// seconds).
|
||||
SeekBackward,
|
||||
/// The action intent is to move the playback time forward by a short period (i.e. a few
|
||||
/// seconds).
|
||||
SeekForward,
|
||||
/// The action intent is to either start the current playback from the beginning if the
|
||||
/// playback has a notion, of beginning, or move to the previous item in the playlist if the
|
||||
/// playback has a notion of playlist.
|
||||
PreviousTrack,
|
||||
/// The action is to move to the playback to the next item in the playlist if the playback has
|
||||
/// a notion of playlist.
|
||||
NextTrack,
|
||||
/// The action intent is to skip the advertisement that is currently playing.
|
||||
SkipAd,
|
||||
/// The action intent is to stop the playback and clear the state if appropriate.
|
||||
Stop,
|
||||
/// The action intent is to move the playback time to a specific time.
|
||||
SeekTo,
|
||||
}
|
||||
|
||||
impl From<i32> for MediaSessionActionType {
|
||||
fn from(value: i32) -> MediaSessionActionType {
|
||||
match value {
|
||||
1 => MediaSessionActionType::Play,
|
||||
2 => MediaSessionActionType::Pause,
|
||||
3 => MediaSessionActionType::SeekBackward,
|
||||
4 => MediaSessionActionType::SeekForward,
|
||||
5 => MediaSessionActionType::PreviousTrack,
|
||||
6 => MediaSessionActionType::NextTrack,
|
||||
7 => MediaSessionActionType::SkipAd,
|
||||
8 => MediaSessionActionType::Stop,
|
||||
9 => MediaSessionActionType::SeekTo,
|
||||
_ => panic!("Unknown MediaSessionActionType"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
|
||||
)]
|
||||
/// Index of gamepad in list of system's connected gamepads
|
||||
pub struct GamepadIndex(pub usize);
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
/// The minimum and maximum values that can be reported for axis or button input from this gamepad
|
||||
pub struct GamepadInputBounds {
|
||||
/// Minimum and maximum axis values
|
||||
pub axis_bounds: (f64, f64),
|
||||
/// Minimum and maximum button values
|
||||
pub button_bounds: (f64, f64),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
/// The haptic effects supported by this gamepad
|
||||
pub struct GamepadSupportedHapticEffects {
|
||||
/// Gamepad support for dual rumble effects
|
||||
pub supports_dual_rumble: bool,
|
||||
/// Gamepad support for trigger rumble effects
|
||||
pub supports_trigger_rumble: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
/// The type of Gamepad event
|
||||
pub enum GamepadEvent {
|
||||
/// A new gamepad has been connected
|
||||
/// <https://www.w3.org/TR/gamepad/#event-gamepadconnected>
|
||||
Connected(
|
||||
GamepadIndex,
|
||||
String,
|
||||
GamepadInputBounds,
|
||||
GamepadSupportedHapticEffects,
|
||||
),
|
||||
/// An existing gamepad has been disconnected
|
||||
/// <https://www.w3.org/TR/gamepad/#event-gamepaddisconnected>
|
||||
Disconnected(GamepadIndex),
|
||||
/// An existing gamepad has been updated
|
||||
/// <https://www.w3.org/TR/gamepad/#receiving-inputs>
|
||||
Updated(GamepadIndex, GamepadUpdateType),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
/// The type of Gamepad input being updated
|
||||
pub enum GamepadUpdateType {
|
||||
/// Axis index and input value
|
||||
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-axis>
|
||||
Axis(usize, f64),
|
||||
/// Button index and input value
|
||||
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-button>
|
||||
Button(usize, f64),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue