mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Inherit used color-scheme from embedder <browser> elements
This allows popups and sidebars to use the chrome preferred color-scheme. This moves the responsibility of setting the content-preferred color scheme to the appropriate browsers to the front-end (via tabs.css). We still return the PreferredColorSchemeForContent() when there's no pres context (e.g., for display:none in-process iframes). We could potentially move a bunch of the pres-context data to the document instead, but that should be acceptable IMO as for general web content there's no behavior change in any case. Differential Revision: https://phabricator.services.mozilla.com/D142578
This commit is contained in:
parent
80d2c8f22b
commit
90a65bcf01
1 changed files with 21 additions and 1 deletions
|
@ -64,6 +64,20 @@ fn get_safearea_inset_right(device: &Device) -> VariableValue {
|
||||||
VariableValue::pixels(device.safe_area_insets().right)
|
VariableValue::pixels(device.safe_area_insets().right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_content_preferred_color_scheme(device: &Device) -> VariableValue {
|
||||||
|
use crate::gecko::media_features::PrefersColorScheme;
|
||||||
|
let prefers_color_scheme = unsafe {
|
||||||
|
crate::gecko_bindings::bindings::Gecko_MediaFeatures_PrefersColorScheme(
|
||||||
|
device.document(),
|
||||||
|
/* use_content = */ true,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
VariableValue::ident(match prefers_color_scheme {
|
||||||
|
PrefersColorScheme::Light => "light",
|
||||||
|
PrefersColorScheme::Dark => "dark",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
static ENVIRONMENT_VARIABLES: [EnvironmentVariable; 4] = [
|
static ENVIRONMENT_VARIABLES: [EnvironmentVariable; 4] = [
|
||||||
make_variable!(atom!("safe-area-inset-top"), get_safearea_inset_top),
|
make_variable!(atom!("safe-area-inset-top"), get_safearea_inset_top),
|
||||||
make_variable!(atom!("safe-area-inset-bottom"), get_safearea_inset_bottom),
|
make_variable!(atom!("safe-area-inset-bottom"), get_safearea_inset_bottom),
|
||||||
|
@ -99,7 +113,7 @@ macro_rules! lnf_int_variable {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 5] = [
|
static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 6] = [
|
||||||
lnf_int_variable!(
|
lnf_int_variable!(
|
||||||
atom!("-moz-gtk-csd-titlebar-radius"),
|
atom!("-moz-gtk-csd-titlebar-radius"),
|
||||||
TitlebarRadius,
|
TitlebarRadius,
|
||||||
|
@ -121,6 +135,7 @@ static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 5] = [
|
||||||
GTKCSDMaximizeButtonPosition,
|
GTKCSDMaximizeButtonPosition,
|
||||||
integer
|
integer
|
||||||
),
|
),
|
||||||
|
make_variable!(atom!("-moz-content-preferred-color-scheme"), get_content_preferred_color_scheme),
|
||||||
];
|
];
|
||||||
|
|
||||||
impl CssEnvironment {
|
impl CssEnvironment {
|
||||||
|
@ -328,6 +343,11 @@ impl VariableValue {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create VariableValue from an int.
|
||||||
|
fn ident(ident: &'static str) -> Self {
|
||||||
|
Self::from_token(Token::Ident(ident.into()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Create VariableValue from a float amount of CSS pixels.
|
/// Create VariableValue from a float amount of CSS pixels.
|
||||||
fn pixels(number: f32) -> Self {
|
fn pixels(number: f32) -> Self {
|
||||||
// FIXME (https://github.com/servo/rust-cssparser/issues/266):
|
// FIXME (https://github.com/servo/rust-cssparser/issues/266):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue