Add embedder event for preferred color scheme and respond to it in the LayoutThread (#34532)

* respond to winit platform theme changed event and send it to the layout thread

Signed-off-by: Lloyd Massiah <artmis9@protonmail.com>

* refactoring viewport and theme change handling functions based on feedback

Signed-off-by: Lloyd Massiah <artmis9@protonmail.com>

* fixing issues reported by test-tidy

Signed-off-by: Lloyd Massiah <artmis9@protonmail.com>

* update stylo in order to use color_scheme function on Device

Signed-off-by: Lloyd Massiah <artmis9@protonmail.com>

---------

Signed-off-by: Lloyd Massiah <artmis9@protonmail.com>
Co-authored-by: lazypassion <25536767+lazypassion@users.noreply.github.com>
This commit is contained in:
arthmis 2024-12-12 01:17:02 -05:00 committed by GitHub
parent dfcbb18a8b
commit 26f61103d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 144 additions and 43 deletions

View file

@ -143,7 +143,7 @@ use script_traits::{
LoadData, LoadOrigin, LogEntry, MediaSessionActionType, MessagePortMsg, MouseEventType,
PortMessageTask, SWManagerMsg, SWManagerSenders, ScriptMsg as FromScriptMsg,
ScriptToConstellationChan, ServiceWorkerManagerFactory, ServiceWorkerMsg,
StructuredSerializedData, TimerSchedulerMsg, TraversalDirection, UpdatePipelineIdReason,
StructuredSerializedData, Theme, TimerSchedulerMsg, TraversalDirection, UpdatePipelineIdReason,
WebDriverCommandMsg, WindowSizeData, WindowSizeType,
};
use serde::{Deserialize, Serialize};
@ -1503,6 +1503,9 @@ where
FromCompositorMsg::WindowSize(top_level_browsing_context_id, new_size, size_type) => {
self.handle_window_size_msg(top_level_browsing_context_id, new_size, size_type);
},
FromCompositorMsg::ThemeChange(theme) => {
self.handle_theme_change(theme);
},
FromCompositorMsg::TickAnimation(pipeline_id, tick_type) => {
self.handle_tick_animation(pipeline_id, tick_type)
},
@ -5477,6 +5480,23 @@ where
}
}
/// Handle theme change events from the embedder and forward them to the script thread
#[cfg_attr(
feature = "tracing",
tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace")
)]
fn handle_theme_change(&mut self, theme: Theme) {
for pipeline in self.pipelines.values() {
let msg = ConstellationControlMsg::ThemeChange(pipeline.id, theme);
if let Err(err) = pipeline.event_loop.send(msg) {
warn!(
"{}: Failed to send theme change event to pipeline ({:?}).",
pipeline.id, err
);
}
}
}
// Handle switching from fullscreen mode
#[cfg_attr(
feature = "tracing",