mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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:
parent
dfcbb18a8b
commit
26f61103d6
13 changed files with 144 additions and 43 deletions
|
@ -57,7 +57,7 @@ use script_layout_interface::{
|
|||
use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||
use script_traits::{
|
||||
ConstellationControlMsg, DocumentState, HistoryEntryReplacement, LoadData, ScriptMsg,
|
||||
ScriptToConstellationChan, ScrollState, StructuredSerializedData, TimerSchedulerMsg,
|
||||
ScriptToConstellationChan, ScrollState, StructuredSerializedData, Theme, TimerSchedulerMsg,
|
||||
WindowSizeData, WindowSizeType,
|
||||
};
|
||||
use selectors::attr::CaseSensitivity;
|
||||
|
@ -180,6 +180,7 @@ pub enum ReflowReason {
|
|||
UpdateTheRendering,
|
||||
Viewport,
|
||||
WorkletLoaded,
|
||||
ThemeChange,
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -223,6 +224,10 @@ pub struct Window {
|
|||
#[no_trace]
|
||||
unhandled_resize_event: DomRefCell<Option<(WindowSizeData, WindowSizeType)>>,
|
||||
|
||||
/// Platform theme.
|
||||
#[no_trace]
|
||||
theme: Cell<Theme>,
|
||||
|
||||
/// Parent id associated with this page, if any.
|
||||
#[no_trace]
|
||||
parent_info: Option<PipelineId>,
|
||||
|
@ -1887,6 +1892,11 @@ impl Window {
|
|||
.or_else(|| document.GetDocumentElement())
|
||||
.map(|root| root.upcast::<Node>().to_trusted_node_address());
|
||||
|
||||
let theme = match self.theme.get() {
|
||||
Theme::Light => style::queries::values::PrefersColorScheme::Light,
|
||||
Theme::Dark => style::queries::values::PrefersColorScheme::Dark,
|
||||
};
|
||||
|
||||
// Send new document and relevant styles to layout.
|
||||
let reflow = ScriptReflow {
|
||||
reflow_info: Reflow {
|
||||
|
@ -1903,6 +1913,7 @@ impl Window {
|
|||
pending_restyles,
|
||||
animation_timeline_value: document.current_animation_timeline_value(),
|
||||
animations: document.animations().sets.clone(),
|
||||
theme,
|
||||
};
|
||||
|
||||
self.layout.borrow_mut().reflow(reflow);
|
||||
|
@ -2353,6 +2364,10 @@ impl Window {
|
|||
self.window_size.get()
|
||||
}
|
||||
|
||||
pub fn set_theme(&self, theme: Theme) {
|
||||
self.theme.set(theme);
|
||||
}
|
||||
|
||||
pub fn get_url(&self) -> ServoUrl {
|
||||
self.Document().url()
|
||||
}
|
||||
|
@ -2728,6 +2743,7 @@ impl Window {
|
|||
throttled: Cell::new(false),
|
||||
layout_marker: DomRefCell::new(Rc::new(Cell::new(true))),
|
||||
current_event: DomRefCell::new(None),
|
||||
theme: Cell::new(Theme::Light),
|
||||
});
|
||||
|
||||
unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue