From e3b4492853aae0d8fa941ffe91739697b913be69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 21 Jan 2021 06:14:16 +0000 Subject: [PATCH] Bug 1686613 - Add a non-native-theme media query. r=heycam Differential Revision: https://phabricator.services.mozilla.com/D102457 --- layout/style/GeckoBindings.h | 1 + layout/style/nsMediaFeatures.cpp | 4 ++++ .../chrome/test_chrome_only_media_queries.html | 1 + servo/components/style/gecko/media_features.rs | 18 +++++++++++++++++- xpcom/ds/StaticAtoms.py | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/layout/style/GeckoBindings.h b/layout/style/GeckoBindings.h index 2e5b939e8210..927e8a49283d 100644 --- a/layout/style/GeckoBindings.h +++ b/layout/style/GeckoBindings.h @@ -613,6 +613,7 @@ bool Gecko_IsMainThread(); mozilla::StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode( const mozilla::dom::Document*); +bool Gecko_MediaFeatures_ShouldAvoidNativeTheme(const mozilla::dom::Document*); uint32_t Gecko_MediaFeatures_GetColorDepth(const mozilla::dom::Document*); uint32_t Gecko_MediaFeatures_GetMonochromeBitsPerPixel( const mozilla::dom::Document*); diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index 6c9c09771b87..cc0366c8cde4 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -96,6 +96,10 @@ bool Gecko_MediaFeatures_IsResourceDocument(const Document* aDocument) { return aDocument->IsResourceDoc(); } +bool Gecko_MediaFeatures_ShouldAvoidNativeTheme(const Document* aDocument) { + return aDocument->ShouldAvoidNativeTheme(); +} + static nsDeviceContext* GetDeviceContextFor(const Document* aDocument) { nsPresContext* pc = aDocument->GetPresContext(); if (!pc) { diff --git a/layout/style/test/chrome/test_chrome_only_media_queries.html b/layout/style/test/chrome/test_chrome_only_media_queries.html index 6523b10a71b1..9c346076ff62 100644 --- a/layout/style/test/chrome/test_chrome_only_media_queries.html +++ b/layout/style/test/chrome/test_chrome_only_media_queries.html @@ -47,6 +47,7 @@ function testToggle(toggle) { const TOGGLES = [ "-moz-is-glyph", "-moz-print-preview", + "-moz-non-native-content-theme", "-moz-scrollbar-start-backward", "-moz-scrollbar-start-forward", "-moz-scrollbar-end-backward", diff --git a/servo/components/style/gecko/media_features.rs b/servo/components/style/gecko/media_features.rs index 589d7dd76aa2..9c17c6a79976 100644 --- a/servo/components/style/gecko/media_features.rs +++ b/servo/components/style/gecko/media_features.rs @@ -543,6 +543,16 @@ fn eval_moz_print_preview( query_value.map_or(is_print_preview, |v| v == is_print_preview) } +fn eval_moz_non_native_content_theme( + device: &Device, + query_value: Option, + _: Option, +) -> bool { + let non_native_theme = + unsafe { bindings::Gecko_MediaFeatures_ShouldAvoidNativeTheme(device.document()) }; + query_value.map_or(non_native_theme, |v| v == non_native_theme) +} + fn eval_moz_is_resource_document( device: &Device, query_value: Option, @@ -610,7 +620,7 @@ macro_rules! system_metric_feature { /// to support new types in these entries and (2) ensuring that either /// nsPresContext::MediaFeatureValuesChanged is called when the value that /// would be returned by the evaluator function could change. -pub static MEDIA_FEATURES: [MediaFeatureDescription; 55] = [ +pub static MEDIA_FEATURES: [MediaFeatureDescription; 56] = [ feature!( atom!("width"), AllowsRanges::Yes, @@ -814,6 +824,12 @@ pub static MEDIA_FEATURES: [MediaFeatureDescription; 55] = [ Evaluator::BoolInteger(eval_moz_print_preview), ParsingRequirements::CHROME_AND_UA_ONLY, ), + feature!( + atom!("-moz-non-native-content-theme"), + AllowsRanges::No, + Evaluator::BoolInteger(eval_moz_non_native_content_theme), + ParsingRequirements::CHROME_AND_UA_ONLY, + ), system_metric_feature!(atom!("-moz-scrollbar-start-backward")), system_metric_feature!(atom!("-moz-scrollbar-start-forward")), system_metric_feature!(atom!("-moz-scrollbar-end-backward")), diff --git a/xpcom/ds/StaticAtoms.py b/xpcom/ds/StaticAtoms.py index 91a30f1f9a6e..0c3ce0f730a7 100644 --- a/xpcom/ds/StaticAtoms.py +++ b/xpcom/ds/StaticAtoms.py @@ -50,6 +50,7 @@ STATIC_ATOMS = [ Atom("_moz_is_glyph", "-moz-is-glyph"), Atom("_moz_original_size", "_moz_original_size"), Atom("_moz_print_preview", "-moz-print-preview"), + Atom("_moz_non_native_content_theme", "-moz-non-native-content-theme"), Atom("menuactive", "_moz-menuactive"), Atom("_poundDefault", "#default"), Atom("_asterisk", "*"),