mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Process colorSchemeSimulation in TargetConfigurationActor (#36297)
Implements Steps 1,4&6 of https://github.com/servo/servo/issues/35867: - Adds `pub simulate_color_scheme` to `BrowsingContextActor` using `script_chan`. - Processes `colorSchemeSimulation` flag in `TargetConfigurationActor`’s `updateConfiguration`. - Routes `colorSchemeSimulation` from `RootActor` via `TabDescriptorActor` to `BrowsingContextActor`. Testing: Compiles and lints clean. Fixes: https://github.com/servo/servo/issues/35867 --------- Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This commit is contained in:
parent
9d07416163
commit
fab5e02972
3 changed files with 44 additions and 7 deletions
|
@ -11,8 +11,11 @@ use std::collections::HashMap;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
|
||||||
use base::id::PipelineId;
|
use base::id::PipelineId;
|
||||||
use devtools_traits::DevtoolScriptControlMsg::{self, GetCssDatabase, WantsLiveNotifications};
|
use devtools_traits::DevtoolScriptControlMsg::{
|
||||||
|
self, GetCssDatabase, SimulateColorScheme, WantsLiveNotifications,
|
||||||
|
};
|
||||||
use devtools_traits::{DevtoolsPageInfo, NavigationState};
|
use devtools_traits::{DevtoolsPageInfo, NavigationState};
|
||||||
|
use embedder_traits::Theme;
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
@ -352,4 +355,10 @@ impl BrowsingContextActor {
|
||||||
let _ = stream.write_json_packet(&msg);
|
let _ = stream.write_json_packet(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn simulate_color_scheme(&self, theme: Theme) -> Result<(), ()> {
|
||||||
|
self.script_chan
|
||||||
|
.send(SimulateColorScheme(self.active_pipeline_id.get(), theme))
|
||||||
|
.map_err(|_| ())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,16 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
|
||||||
|
use embedder_traits::Theme;
|
||||||
|
use log::warn;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
|
||||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||||
|
use crate::actors::browsing_context::BrowsingContextActor;
|
||||||
|
use crate::actors::tab::TabDescriptorActor;
|
||||||
use crate::protocol::JsonPacketStream;
|
use crate::protocol::JsonPacketStream;
|
||||||
use crate::{EmptyReplyMsg, StreamId};
|
use crate::{EmptyReplyMsg, RootActor, StreamId};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
@ -44,15 +48,39 @@ impl Actor for TargetConfigurationActor {
|
||||||
/// - `updateConfiguration`: Receives new configuration flags from the devtools host.
|
/// - `updateConfiguration`: Receives new configuration flags from the devtools host.
|
||||||
fn handle_message(
|
fn handle_message(
|
||||||
&self,
|
&self,
|
||||||
_registry: &ActorRegistry,
|
registry: &ActorRegistry,
|
||||||
msg_type: &str,
|
msg_type: &str,
|
||||||
_msg: &Map<String, Value>,
|
msg: &Map<String, Value>,
|
||||||
stream: &mut TcpStream,
|
stream: &mut TcpStream,
|
||||||
_id: StreamId,
|
_id: StreamId,
|
||||||
) -> Result<ActorMessageStatus, ()> {
|
) -> Result<ActorMessageStatus, ()> {
|
||||||
Ok(match msg_type {
|
Ok(match msg_type {
|
||||||
"updateConfiguration" => {
|
"updateConfiguration" => {
|
||||||
// TODO: Actually update configuration
|
let config = match msg.get("configuration").and_then(|v| v.as_object()) {
|
||||||
|
Some(config) => config,
|
||||||
|
None => {
|
||||||
|
let msg = EmptyReplyMsg { from: self.name() };
|
||||||
|
let _ = stream.write_json_packet(&msg);
|
||||||
|
return Ok(ActorMessageStatus::Processed);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if let Some(scheme) = config.get("colorSchemeSimulation").and_then(|v| v.as_str()) {
|
||||||
|
let theme = match scheme {
|
||||||
|
"dark" => Theme::Dark,
|
||||||
|
"light" => Theme::Light,
|
||||||
|
_ => Theme::Light,
|
||||||
|
};
|
||||||
|
let root_actor = registry.find::<RootActor>("root");
|
||||||
|
if let Some(tab_name) = root_actor.active_tab() {
|
||||||
|
let tab_actor = registry.find::<TabDescriptorActor>(&tab_name);
|
||||||
|
let browsing_context_name = tab_actor.browsing_context();
|
||||||
|
let browsing_context_actor =
|
||||||
|
registry.find::<BrowsingContextActor>(&browsing_context_name);
|
||||||
|
browsing_context_actor.simulate_color_scheme(theme)?;
|
||||||
|
} else {
|
||||||
|
warn!("No active tab for updateConfiguration");
|
||||||
|
}
|
||||||
|
}
|
||||||
let msg = EmptyReplyMsg { from: self.name() };
|
let msg = EmptyReplyMsg { from: self.name() };
|
||||||
let _ = stream.write_json_packet(&msg);
|
let _ = stream.write_json_packet(&msg);
|
||||||
ActorMessageStatus::Processed
|
ActorMessageStatus::Processed
|
||||||
|
@ -69,7 +97,7 @@ impl TargetConfigurationActor {
|
||||||
configuration: HashMap::new(),
|
configuration: HashMap::new(),
|
||||||
supported_options: HashMap::from([
|
supported_options: HashMap::from([
|
||||||
("cacheDisabled", false),
|
("cacheDisabled", false),
|
||||||
("colorSchemeSimulation", false),
|
("colorSchemeSimulation", true),
|
||||||
("customFormatters", false),
|
("customFormatters", false),
|
||||||
("customUserAgent", false),
|
("customUserAgent", false),
|
||||||
("javascriptEnabled", false),
|
("javascriptEnabled", false),
|
||||||
|
|
|
@ -293,7 +293,7 @@ pub enum EmbedderMsg {
|
||||||
AllowOpeningWebView(WebViewId, IpcSender<Option<(WebViewId, ViewportDetails)>>),
|
AllowOpeningWebView(WebViewId, IpcSender<Option<(WebViewId, ViewportDetails)>>),
|
||||||
/// A webview was destroyed.
|
/// A webview was destroyed.
|
||||||
WebViewClosed(WebViewId),
|
WebViewClosed(WebViewId),
|
||||||
/// A webview gained focus for keyboard events.
|
/// A webview gained focus for keyboard events
|
||||||
WebViewFocused(WebViewId),
|
WebViewFocused(WebViewId),
|
||||||
/// All webviews lost focus for keyboard events.
|
/// All webviews lost focus for keyboard events.
|
||||||
WebViewBlurred,
|
WebViewBlurred,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue