style: Generalize moz-os-version into moz-platform

Allow differentiating non-windows platforms on it.

Differential Revision: https://phabricator.services.mozilla.com/D138431
This commit is contained in:
Emilio Cobos Álvarez 2023-06-06 23:51:40 +02:00 committed by Oriol Brufau
parent e2901169c8
commit b798336f81

View file

@ -13,7 +13,6 @@ use crate::media_queries::{Device, MediaType};
use crate::values::computed::CSSPixelLength; use crate::values::computed::CSSPixelLength;
use crate::values::computed::Ratio; use crate::values::computed::Ratio;
use crate::values::computed::Resolution; use crate::values::computed::Resolution;
use crate::Atom;
use app_units::Au; use app_units::Au;
use euclid::default::Size2D; use euclid::default::Size2D;
@ -550,20 +549,36 @@ fn eval_moz_is_resource_document(
query_value.map_or(is_resource_doc, |v| v == is_resource_doc) query_value.map_or(is_resource_doc, |v| v == is_resource_doc)
} }
fn eval_moz_os_version( /// Allows front-end CSS to discern platform via media queries.
device: &Device, #[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
query_value: Option<Atom>, #[repr(u8)]
_: Option<RangeOrOperator>, pub enum Platform {
) -> bool { /// Matches any Android version.
Android,
/// For our purposes here, "linux" is just "gtk" (so unix-but-not-mac).
/// There's no need for our front-end code to differentiate between those
/// platforms and they already use the "linux" string elsewhere (e.g.,
/// toolkit/themes/linux).
Linux,
/// Matches any macOS version.
Macos,
/// Matches any Windows version.
Windows,
/// Matches only Windows 7.
WindowsWin7,
/// Matches only Windows 8.
WindowsWin8,
/// Matches windows 10 and actually matches windows 11 too, as of right now.
WindowsWin10,
}
fn eval_moz_platform(_: &Device, query_value: Option<Platform>) -> bool {
let query_value = match query_value { let query_value = match query_value {
Some(v) => v, Some(v) => v,
None => return false, None => return false,
}; };
let os_version = unsafe { bindings::Gecko_MediaFeatures_MatchesPlatform(query_value) }
unsafe { bindings::Gecko_MediaFeatures_GetOperatingSystemVersion(device.document()) };
query_value.as_ptr() == os_version
} }
fn eval_moz_windows_non_native_menus( fn eval_moz_windows_non_native_menus(
@ -576,7 +591,7 @@ fn eval_moz_windows_non_native_menus(
0 => false, 0 => false,
1 => true, 1 => true,
_ => { _ => {
eval_moz_os_version(device, Some(atom!("windows-win10")), None) && eval_moz_platform(device, Some(Platform::WindowsWin10)) &&
get_lnf_int_as_bool(bindings::LookAndFeel_IntID::WindowsDefaultTheme as i32) get_lnf_int_as_bool(bindings::LookAndFeel_IntID::WindowsDefaultTheme as i32)
}, },
}; };
@ -869,9 +884,9 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [
ParsingRequirements::CHROME_AND_UA_ONLY, ParsingRequirements::CHROME_AND_UA_ONLY,
), ),
feature!( feature!(
atom!("-moz-os-version"), atom!("-moz-platform"),
AllowsRanges::No, AllowsRanges::No,
Evaluator::Ident(eval_moz_os_version), keyword_evaluator!(eval_moz_platform, Platform),
ParsingRequirements::CHROME_AND_UA_ONLY, ParsingRequirements::CHROME_AND_UA_ONLY,
), ),
feature!( feature!(