aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-05-26 14:05:38 +0200
committerGitHub <noreply@github.com>2025-05-26 12:05:38 +0000
commitd3e57a513c79f61f619f8ff667ae4152714ff2c9 (patch)
tree98f1115a23c8f12311b129645ed588d1c5834d0b /components/script/dom/window.rs
parentc96de69e80362546e8557afbcb1c5eb92a59c0d3 (diff)
downloadservo-d3e57a513c79f61f619f8ff667ae4152714ff2c9.tar.gz
servo-d3e57a513c79f61f619f8ff667ae4152714ff2c9.zip
constellation: Pass system theme to new Pipelines (#37132)
Previously, when the theme was set it was only set on currently active `Window`s. This change makes setting the `Theme` stateful. Now the `Constellation` tracks what theme is applied to a `WebView` and properly passes that value to new `Pipeline`s when they are constructed. In addition, the value is passed to layout when that is constructed as well. Testing: this change adds a unit test. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 24e694b4f06..f75ae4b4cb3 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -80,7 +80,6 @@ use style::dom::OpaqueNode;
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
use style::properties::PropertyId;
use style::properties::style_structs::Font;
-use style::queries::values::PrefersColorScheme;
use style::selector_parser::PseudoElement;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::UrlExtraData;
@@ -269,7 +268,7 @@ pub(crate) struct Window {
/// Platform theme.
#[no_trace]
- theme: Cell<PrefersColorScheme>,
+ theme: Cell<Theme>,
/// Parent id associated with this page, if any.
#[no_trace]
@@ -2739,13 +2738,13 @@ impl Window {
self.viewport_details.get()
}
+ /// Get the theme of this [`Window`].
+ pub(crate) fn theme(&self) -> Theme {
+ self.theme.get()
+ }
+
/// Handle a theme change request, triggering a reflow is any actual change occured.
pub(crate) fn handle_theme_change(&self, new_theme: Theme) {
- let new_theme = match new_theme {
- Theme::Light => PrefersColorScheme::Light,
- Theme::Dark => PrefersColorScheme::Dark,
- };
-
if self.theme.get() == new_theme {
return;
}
@@ -3033,6 +3032,7 @@ impl Window {
player_context: WindowGLContext,
#[cfg(feature = "webgpu")] gpu_id_hub: Arc<IdentityHub>,
inherited_secure_context: Option<bool>,
+ theme: Theme,
) -> DomRoot<Self> {
let error_reporter = CSSErrorReporter {
pipelineid: pipeline_id,
@@ -3118,7 +3118,7 @@ impl Window {
throttled: Cell::new(false),
layout_marker: DomRefCell::new(Rc::new(Cell::new(true))),
current_event: DomRefCell::new(None),
- theme: Cell::new(PrefersColorScheme::Light),
+ theme: Cell::new(theme),
trusted_types: Default::default(),
});