mod from_script_message;
mod structured_data;
use std::collections::VecDeque;
use std::fmt;
use std::time::Duration;
use embedder_traits::user_contents::{
UserContentManagerId, UserScript, UserScriptId, UserStyleSheet, UserStyleSheetId,
};
use embedder_traits::{
EmbedderControlId, EmbedderControlResponse, InputEventAndId, JavaScriptEvaluationId,
MediaSessionActionType, NewWebViewDetails, PaintHitTestResult, Theme, TraversalId, UrlRequest,
ViewportDetails, WebDriverCommandMsg,
};
pub use from_script_message::*;
use malloc_size_of_derive::MallocSizeOf;
use paint_api::PinchZoomInfos;
use profile_traits::mem::MemoryReportResult;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
use servo_base::cross_process_instant::CrossProcessInstant;
use servo_base::generic_channel::GenericCallback;
use servo_base::id::{MessagePortId, PipelineId, ScriptEventLoopId, WebViewId};
use servo_config::prefs::PrefValue;
use servo_url::{ImmutableOrigin, ServoUrl};
pub use structured_data::*;
use strum::IntoStaticStr;
use webrender_api::units::LayoutVector2D;
use webrender_api::{ExternalScrollId, ImageKey};
#[derive(IntoStaticStr)]
pub enum EmbedderToConstellationMessage {
Exit,
AllowNavigationResponse(PipelineId, bool),
LoadUrl(WebViewId, UrlRequest),
TraverseHistory(WebViewId, TraversalDirection, TraversalId),
ChangeViewportDetails(WebViewId, ViewportDetails, WindowSizeType),
ThemeChange(WebViewId, Theme),
TickAnimation(Vec<WebViewId>),
NoLongerWaitingOnAsynchronousImageUpdates(Vec<PipelineId>),
WebDriverCommand(WebDriverCommandMsg),
Reload(WebViewId),
LogEntry(Option<ScriptEventLoopId>, Option<String>, LogEntry),
NewWebView(ServoUrl, NewWebViewDetails),
CloseWebView(WebViewId),
SendError(Option<WebViewId>, String),
FocusWebView(WebViewId),
BlurWebView,
ForwardInputEvent(WebViewId, InputEventAndId, Option<PaintHitTestResult>),
RefreshCursor(PipelineId),
ToggleProfiler(Duration, Duration),
ExitFullScreen(WebViewId),
MediaSessionAction(MediaSessionActionType),
SetWebViewThrottled(WebViewId, bool),
SetScrollStates(PipelineId, ScrollStateUpdate),
PaintMetric(PipelineId, PaintMetricEvent),
EvaluateJavaScript(WebViewId, JavaScriptEvaluationId, String),
CreateMemoryReport(GenericCallback<MemoryReportResult>),
SendImageKeysForPipeline(PipelineId, Vec<ImageKey>),
PreferencesUpdated(Vec<(&'static str, PrefValue)>),
RequestScreenshotReadiness(WebViewId),
EmbedderControlResponse(EmbedderControlId, EmbedderControlResponse),
UserContentManagerAction(UserContentManagerId, UserContentManagerAction),
UpdatePinchZoomInfos(PipelineId, PinchZoomInfos),
SetAccessibilityActive(WebViewId, bool),
}
pub enum UserContentManagerAction {
AddUserScript(UserScript),
DestroyUserContentManager,
RemoveUserScript(UserScriptId),
AddUserStyleSheet(UserStyleSheet),
RemoveUserStyleSheet(UserStyleSheetId),
}
pub enum PaintMetricEvent {
FirstPaint(CrossProcessInstant, bool ),
FirstContentfulPaint(CrossProcessInstant, bool ),
LargestContentfulPaint(CrossProcessInstant, usize , Option<ServoUrl>),
}
impl fmt::Debug for EmbedderToConstellationMessage {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
let variant_string: &'static str = self.into();
write!(formatter, "ConstellationMsg::{variant_string}")
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum LogEntry {
Panic(String, String),
Error(String),
Warn(String),
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub enum WindowSizeType {
Initial,
Resize,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum TraversalDirection {
Forward(usize),
Back(usize),
}
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct PortMessageTask {
pub origin: ImmutableOrigin,
pub data: StructuredSerializedData,
}
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
pub struct PortTransferInfo {
pub port_message_queue: VecDeque<PortMessageTask>,
pub disentangled: bool,
}
#[derive(Debug, Deserialize, Serialize)]
#[expect(clippy::large_enum_variant)]
pub enum MessagePortMsg {
CompleteTransfer(FxHashMap<MessagePortId, PortTransferInfo>),
CompletePendingTransfer(MessagePortId, PortTransferInfo),
CompleteDisentanglement(MessagePortId),
NewTask(MessagePortId, PortMessageTask),
}
#[derive(Debug, Deserialize, Serialize)]
pub struct ScrollStateUpdate {
pub scrolled_node: ExternalScrollId,
pub offsets: FxHashMap<ExternalScrollId, LayoutVector2D>,
}