mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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>
This commit is contained in:
parent
c96de69e80
commit
d3e57a513c
19 changed files with 201 additions and 74 deletions
|
@ -223,6 +223,7 @@ impl HTMLIFrameElement {
|
|||
old_pipeline_id,
|
||||
sandbox: sandboxed,
|
||||
viewport_details,
|
||||
theme: window.theme(),
|
||||
};
|
||||
window
|
||||
.as_global_scope()
|
||||
|
@ -238,6 +239,7 @@ impl HTMLIFrameElement {
|
|||
opener: None,
|
||||
load_data,
|
||||
viewport_details,
|
||||
theme: window.theme(),
|
||||
};
|
||||
|
||||
self.pipeline_id.set(Some(new_pipeline_id));
|
||||
|
@ -250,6 +252,7 @@ impl HTMLIFrameElement {
|
|||
old_pipeline_id,
|
||||
sandbox: sandboxed,
|
||||
viewport_details,
|
||||
theme: window.theme(),
|
||||
};
|
||||
window
|
||||
.as_global_scope()
|
||||
|
|
|
@ -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(),
|
||||
});
|
||||
|
||||
|
|
|
@ -329,6 +329,9 @@ impl WindowProxy {
|
|||
opener: Some(self.browsing_context_id),
|
||||
load_data,
|
||||
viewport_details: window.viewport_details(),
|
||||
// Use the current `WebView`'s theme initially, but the embedder may
|
||||
// change this later.
|
||||
theme: window.theme(),
|
||||
};
|
||||
ScriptThread::process_attach_layout(new_layout_info, document.origin().clone());
|
||||
// TODO: if noopener is false, copy the sessionStorage storage area of the creator origin.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue