@@ -9,6 +9,7 @@ use crate::context::QuirksMode;
9
9
use crate :: custom_properties:: CssEnvironment ;
10
10
use crate :: font_metrics:: FontMetrics ;
11
11
use crate :: queries:: feature:: { AllowsRanges , Evaluator , FeatureFlags , QueryFeatureDescription } ;
12
+ use crate :: queries:: values:: PrefersColorScheme ;
12
13
use crate :: logical_geometry:: WritingMode ;
13
14
use crate :: media_queries:: MediaType ;
14
15
use crate :: properties:: style_structs:: Font ;
@@ -86,6 +87,9 @@ pub struct Device {
86
87
/// Whether any styles computed in the document relied on the viewport size.
87
88
#[ ignore_malloc_size_of = "Pure stack type" ]
88
89
used_viewport_units : AtomicBool ,
90
+ /// Whether the user prefers light mode or dark mode
91
+ #[ ignore_malloc_size_of = "Pure stack type" ]
92
+ prefers_color_scheme : PrefersColorScheme ,
89
93
/// The CssEnvironment object responsible of getting CSS environment
90
94
/// variables.
91
95
environment : CssEnvironment ,
@@ -106,6 +110,7 @@ impl Device {
106
110
device_pixel_ratio : Scale < f32 , CSSPixel , DevicePixel > ,
107
111
font_metrics_provider : Box < dyn FontMetricsProvider > ,
108
112
default_computed_values : Arc < ComputedValues > ,
113
+ prefers_color_scheme : PrefersColorScheme ,
109
114
) -> Device {
110
115
Device {
111
116
media_type,
@@ -118,6 +123,7 @@ impl Device {
118
123
used_root_line_height : AtomicBool :: new ( false ) ,
119
124
used_font_metrics : AtomicBool :: new ( false ) ,
120
125
used_viewport_units : AtomicBool :: new ( false ) ,
126
+ prefers_color_scheme,
121
127
environment : CssEnvironment ,
122
128
font_metrics_provider,
123
129
default_computed_values,
@@ -357,8 +363,15 @@ fn eval_device_pixel_ratio(context: &Context) -> f32 {
357
363
eval_resolution ( context) . dppx ( )
358
364
}
359
365
366
+ fn eval_prefers_color_scheme ( context : & Context , query_value : Option < PrefersColorScheme > ) -> bool {
367
+ match query_value {
368
+ Some ( v) => context. device ( ) . prefers_color_scheme == v,
369
+ None => true ,
370
+ }
371
+ }
372
+
360
373
/// A list with all the media features that Servo supports.
361
- pub static MEDIA_FEATURES : [ QueryFeatureDescription ; 5 ] = [
374
+ pub static MEDIA_FEATURES : [ QueryFeatureDescription ; 6 ] = [
362
375
feature ! (
363
376
atom!( "width" ) ,
364
377
AllowsRanges :: Yes ,
@@ -389,4 +402,10 @@ pub static MEDIA_FEATURES: [QueryFeatureDescription; 5] = [
389
402
Evaluator :: Float ( eval_device_pixel_ratio) ,
390
403
FeatureFlags :: empty( ) ,
391
404
) ,
405
+ feature ! (
406
+ atom!( "prefers-color-scheme" ) ,
407
+ AllowsRanges :: No ,
408
+ keyword_evaluator!( eval_prefers_color_scheme, PrefersColorScheme ) ,
409
+ FeatureFlags :: empty( ) ,
410
+ ) ,
392
411
] ;
0 commit comments