diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index 2f1ac7b76ba..7e61f4e1232 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -702,25 +702,25 @@ pub static MEDIA_FEATURES: [QueryFeatureDescription; 67] = [ atom!("width"), AllowsRanges::Yes, Evaluator::Length(eval_width), - FeatureFlags::empty(), + FeatureFlags::VIEWPORT_DEPENDENT, ), feature!( atom!("height"), AllowsRanges::Yes, Evaluator::Length(eval_height), - FeatureFlags::empty(), + FeatureFlags::VIEWPORT_DEPENDENT, ), feature!( atom!("aspect-ratio"), AllowsRanges::Yes, Evaluator::NumberRatio(eval_aspect_ratio), - FeatureFlags::empty(), + FeatureFlags::VIEWPORT_DEPENDENT, ), feature!( atom!("orientation"), AllowsRanges::No, keyword_evaluator!(eval_orientation, Orientation), - FeatureFlags::empty(), + FeatureFlags::VIEWPORT_DEPENDENT, ), feature!( atom!("device-width"), diff --git a/components/style/media_queries/media_list.rs b/components/style/media_queries/media_list.rs index 3348a3537a6..dc9a131d247 100644 --- a/components/style/media_queries/media_list.rs +++ b/components/style/media_queries/media_list.rs @@ -102,6 +102,11 @@ impl MediaList { self.media_queries.is_empty() } + /// Whether this `MediaList` depends on the viewport size. + pub fn is_viewport_dependent(&self) -> bool { + self.media_queries.iter().any(|q| q.is_viewport_dependent()) + } + /// Append a new media query item to the media list. /// /// diff --git a/components/style/media_queries/media_query.rs b/components/style/media_queries/media_query.rs index 24312561a1f..c1ec2fd2a6e 100644 --- a/components/style/media_queries/media_query.rs +++ b/components/style/media_queries/media_query.rs @@ -7,7 +7,7 @@ //! https://drafts.csswg.org/mediaqueries/#typedef-media-query use crate::parser::ParserContext; -use crate::queries::{FeatureType, QueryCondition}; +use crate::queries::{FeatureFlags, FeatureType, QueryCondition}; use crate::str::string_as_ascii_lowercase; use crate::values::CustomIdent; use crate::Atom; @@ -117,6 +117,13 @@ impl MediaQuery { } } + /// Returns whether this media query depends on the viewport. + pub fn is_viewport_dependent(&self) -> bool { + self.condition.as_ref().map_or(false, |c| { + return c.cumulative_flags().contains(FeatureFlags::VIEWPORT_DEPENDENT) + }) + } + /// Parse a media query given css input. /// /// Returns an error if any of the expressions is unknown. diff --git a/components/style/queries/feature.rs b/components/style/queries/feature.rs index 3658cb34998..0a85d7a245f 100644 --- a/components/style/queries/feature.rs +++ b/components/style/queries/feature.rs @@ -118,6 +118,8 @@ bitflags! { const CONTAINER_REQUIRES_WIDTH_AXIS = 1 << 4; /// The feature requires containment in the physical height axis. const CONTAINER_REQUIRES_HEIGHT_AXIS = 1 << 5; + /// The feature evaluation depends on the viewport size. + const VIEWPORT_DEPENDENT = 1 << 6; } }