From 1a3b32a2482a7f09dba4c7076d7800b1cc0e004f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 17 Feb 2023 21:15:06 +0000 Subject: [PATCH] style: Expose scrollbar-inline-size as a chrome-only environment variable After the previous patches this is rather straight-forward. Reviewed in: https://phabricator.services.mozilla.com/D168148 --- components/style/custom_properties.rs | 10 +++++++++- components/style/gecko/media_queries.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 9538cce4ab3..25066c50c44 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -85,6 +85,10 @@ fn get_content_preferred_color_scheme(_device: &Device) -> VariableValue { VariableValue::ident("light") } +fn get_scrollbar_inline_size(device: &Device) -> VariableValue { + VariableValue::pixels(device.scrollbar_inline_size().px()) +} + static ENVIRONMENT_VARIABLES: [EnvironmentVariable; 4] = [ make_variable!(atom!("safe-area-inset-top"), get_safearea_inset_top), make_variable!(atom!("safe-area-inset-bottom"), get_safearea_inset_bottom), @@ -120,7 +124,7 @@ macro_rules! lnf_int_variable { }}; } -static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 6] = [ +static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 7] = [ lnf_int_variable!( atom!("-moz-gtk-csd-titlebar-radius"), TitlebarRadius, @@ -146,6 +150,10 @@ static CHROME_ENVIRONMENT_VARIABLES: [EnvironmentVariable; 6] = [ atom!("-moz-content-preferred-color-scheme"), get_content_preferred_color_scheme ), + make_variable!( + atom!("scrollbar-inline-size"), + get_scrollbar_inline_size + ), ]; impl CssEnvironment { diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index d098849be7d..397996f7041 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -199,6 +199,18 @@ impl Device { unsafe { bindings::Gecko_GetBaseSize(self.document(), language.as_ptr(), generic) } } + /// Gets the size of the scrollbar in CSS pixels. + pub fn scrollbar_inline_size(&self) -> Length { + let pc = match self.pres_context() { + Some(pc) => pc, + // XXX: we could have a more reasonable default perhaps. + None => return Length::new(0.0), + }; + Length::new(unsafe { + bindings::Gecko_GetScrollbarInlineSize(pc) + }) + } + /// Queries font metrics pub fn query_font_metrics( &self,