mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
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:
parent
e2901169c8
commit
b798336f81
1 changed files with 28 additions and 13 deletions
|
@ -13,7 +13,6 @@ use crate::media_queries::{Device, MediaType};
|
|||
use crate::values::computed::CSSPixelLength;
|
||||
use crate::values::computed::Ratio;
|
||||
use crate::values::computed::Resolution;
|
||||
use crate::Atom;
|
||||
use app_units::Au;
|
||||
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)
|
||||
}
|
||||
|
||||
fn eval_moz_os_version(
|
||||
device: &Device,
|
||||
query_value: Option<Atom>,
|
||||
_: Option<RangeOrOperator>,
|
||||
) -> bool {
|
||||
/// Allows front-end CSS to discern platform via media queries.
|
||||
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
|
||||
#[repr(u8)]
|
||||
pub enum Platform {
|
||||
/// 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 {
|
||||
Some(v) => v,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let os_version =
|
||||
unsafe { bindings::Gecko_MediaFeatures_GetOperatingSystemVersion(device.document()) };
|
||||
|
||||
query_value.as_ptr() == os_version
|
||||
unsafe { bindings::Gecko_MediaFeatures_MatchesPlatform(query_value) }
|
||||
}
|
||||
|
||||
fn eval_moz_windows_non_native_menus(
|
||||
|
@ -576,7 +591,7 @@ fn eval_moz_windows_non_native_menus(
|
|||
0 => false,
|
||||
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)
|
||||
},
|
||||
};
|
||||
|
@ -869,9 +884,9 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 58] = [
|
|||
ParsingRequirements::CHROME_AND_UA_ONLY,
|
||||
),
|
||||
feature!(
|
||||
atom!("-moz-os-version"),
|
||||
atom!("-moz-platform"),
|
||||
AllowsRanges::No,
|
||||
Evaluator::Ident(eval_moz_os_version),
|
||||
keyword_evaluator!(eval_moz_platform, Platform),
|
||||
ParsingRequirements::CHROME_AND_UA_ONLY,
|
||||
),
|
||||
feature!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue