Bug 1763644 - Add basic @container rule parsing and boilerplate. r=firefox-style-system-reviewers,layout-reviewers,boris

For now parse a MediaFeatureCondition. That needs being made more
specific, but that is probably worth its own patch.

Differential Revision: https://phabricator.services.mozilla.com/D143192
This commit is contained in:
Emilio Cobos Álvarez 2022-04-08 04:15:40 +00:00
parent 3e31b63b4f
commit 37716ddbc3
72 changed files with 527 additions and 386 deletions

View file

@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface
*/
// https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface
[Exposed=Window, Pref="layout.css.container-queries.enabled"]
interface CSSContainerRule : CSSConditionRule {
};

View file

@ -475,6 +475,7 @@ WEBIDL_FILES = [
"CSS.webidl",
"CSSAnimation.webidl",
"CSSConditionRule.webidl",
"CSSContainerRule.webidl",
"CSSCounterStyleRule.webidl",
"CSSFontFaceRule.webidl",
"CSSFontFeatureValuesRule.webidl",

View file

@ -86,6 +86,7 @@ void ServoStyleRuleMap::RuleRemoved(StyleSheet& aStyleSheet,
case StyleCssRuleType::Media:
case StyleCssRuleType::Supports:
case StyleCssRuleType::LayerBlock:
case StyleCssRuleType::Container:
case StyleCssRuleType::Document: {
// See the comment in StyleSheetRemoved.
mTable.Clear();
@ -122,6 +123,7 @@ void ServoStyleRuleMap::FillTableFromRule(css::Rule& aRule) {
case StyleCssRuleType::LayerBlock:
case StyleCssRuleType::Media:
case StyleCssRuleType::Supports:
case StyleCssRuleType::Container:
case StyleCssRuleType::Document: {
auto& rule = static_cast<css::GroupRule&>(aRule);
if (ServoCSSRuleList* ruleList = rule.GetCssRules()) {

View file

@ -0,0 +1,83 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/CSSContainerRule.h"
#include "mozilla/css/GroupRule.h"
#include "mozilla/dom/CSSContainerRuleBinding.h"
#include "mozilla/ServoBindings.h"
using namespace mozilla::css;
namespace mozilla::dom {
CSSContainerRule::CSSContainerRule(RefPtr<RawServoContainerRule> aRawRule,
StyleSheet* aSheet, css::Rule* aParentRule,
uint32_t aLine, uint32_t aColumn)
: css::ConditionRule(Servo_ContainerRule_GetRules(aRawRule).Consume(),
aSheet, aParentRule, aLine, aColumn),
mRawRule(std::move(aRawRule)) {}
CSSContainerRule::~CSSContainerRule() = default;
NS_IMPL_ADDREF_INHERITED(CSSContainerRule, ConditionRule)
NS_IMPL_RELEASE_INHERITED(CSSContainerRule, ConditionRule)
// QueryInterface implementation for ContainerRule
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSContainerRule)
NS_INTERFACE_MAP_END_INHERITING(ConditionRule)
#ifdef DEBUG
/* virtual */
void CSSContainerRule::List(FILE* out, int32_t aIndent) const {
nsAutoCString str;
for (int32_t i = 0; i < aIndent; i++) {
str.AppendLiteral(" ");
}
Servo_ContainerRule_Debug(mRawRule, &str);
fprintf_stderr(out, "%s\n", str.get());
}
#endif
StyleCssRuleType CSSContainerRule::Type() const {
return StyleCssRuleType::Container;
}
void CSSContainerRule::GetConditionText(nsACString& aConditionText) {
Servo_ContainerRule_GetConditionText(mRawRule, &aConditionText);
}
void CSSContainerRule::SetConditionText(const nsACString& aConditionText, ErrorResult&) {
// FIXME: This shouldn't be here, CSSConditionRule.conditionText should be
// readonly as per:
// https://github.com/w3c/csswg-drafts/issues/6819#issuecomment-1016695585
}
/* virtual */
void CSSContainerRule::GetCssText(nsACString& aCssText) const {
Servo_ContainerRule_GetCssText(mRawRule, &aCssText);
}
void CSSContainerRule::SetRawAfterClone(RefPtr<RawServoContainerRule> aRaw) {
mRawRule = std::move(aRaw);
css::ConditionRule::SetRawAfterClone(
Servo_ContainerRule_GetRules(mRawRule).Consume());
}
/* virtual */
size_t CSSContainerRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
// TODO Implement this!
return aMallocSizeOf(this);
}
/* virtual */
JSObject* CSSContainerRule::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return CSSContainerRule_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace mozilla::dom

View file

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_CSSContainerRule_h
#define mozilla_dom_CSSContainerRule_h
#include "mozilla/css/GroupRule.h"
#include "mozilla/ServoBindingTypes.h"
namespace mozilla::dom {
class CSSContainerRule final : public css::ConditionRule {
public:
CSSContainerRule(RefPtr<RawServoContainerRule> aRawRule, StyleSheet* aSheet,
css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);
NS_DECL_ISUPPORTS_INHERITED
#ifdef DEBUG
void List(FILE* out = stdout, int32_t aIndent = 0) const final;
#endif
RawServoContainerRule* Raw() const { return mRawRule; }
void SetRawAfterClone(RefPtr<RawServoContainerRule>);
// WebIDL interface
StyleCssRuleType Type() const override;
// WebIDL interface
void GetCssText(nsACString& aCssText) const final;
void GetConditionText(nsACString& aConditionText) final;
void SetConditionText(const nsACString& aConditionText, ErrorResult&) final;
size_t SizeOfIncludingThis(MallocSizeOf) const override;
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
private:
virtual ~CSSContainerRule();
RefPtr<RawServoContainerRule> mRawRule;
};
} // namespace mozilla::dom
#endif // mozilla_dom_CSSContainerRule_h

View file

@ -10,8 +10,7 @@
#include "mozilla/css/GroupRule.h"
#include "mozilla/ServoBindingTypes.h"
namespace mozilla {
namespace dom {
namespace mozilla::dom {
class CSSMediaRule final : public css::ConditionRule {
public:
@ -51,7 +50,6 @@ class CSSMediaRule final : public css::ConditionRule {
RefPtr<dom::MediaList> mMediaList;
};
} // namespace dom
} // namespace mozilla
} // namespace mozilla::dom
#endif // mozilla_dom_CSSMediaRule_h

View file

@ -104,7 +104,8 @@ void Rule::AssertParentRuleType() {
type == StyleCssRuleType::Document ||
type == StyleCssRuleType::Supports ||
type == StyleCssRuleType::Keyframes ||
type == StyleCssRuleType::LayerBlock);
type == StyleCssRuleType::LayerBlock ||
type == StyleCssRuleType::Container);
}
}
#endif

View file

@ -39,6 +39,7 @@ SERVO_ARC_TYPE(NamespaceRule, RawServoNamespaceRule)
SERVO_ARC_TYPE(PageRule, RawServoPageRule)
SERVO_ARC_TYPE(SupportsRule, RawServoSupportsRule)
SERVO_ARC_TYPE(DocumentRule, RawServoMozDocumentRule)
SERVO_ARC_TYPE(ContainerRule, RawServoContainerRule)
SERVO_ARC_TYPE(FontFeatureValuesRule, RawServoFontFeatureValuesRule)
SERVO_ARC_TYPE(FontFaceRule, RawServoFontFaceRule)
SERVO_ARC_TYPE(CounterStyleRule, RawServoCounterStyleRule)

View file

@ -67,6 +67,7 @@ BASIC_RULE_FUNCS(FontFeatureValues)
BASIC_RULE_FUNCS(FontFace)
BASIC_RULE_FUNCS(CounterStyle)
BASIC_RULE_FUNCS(ScrollTimeline)
GROUP_RULE_FUNCS(Container)
#undef GROUP_RULE_FUNCS
#undef BASIC_RULE_FUNCS

View file

@ -15,6 +15,7 @@
#include "mozilla/dom/CSSLayerBlockRule.h"
#include "mozilla/dom/CSSLayerStatementRule.h"
#include "mozilla/dom/CSSKeyframesRule.h"
#include "mozilla/dom/CSSContainerRule.h"
#include "mozilla/dom/CSSMediaRule.h"
#include "mozilla/dom/CSSMozDocumentRule.h"
#include "mozilla/dom/CSSNamespaceRule.h"
@ -93,6 +94,7 @@ css::Rule* ServoCSSRuleList::GetRule(uint32_t aIndex) {
CASE_RULE(LayerBlock, LayerBlock)
CASE_RULE(LayerStatement, LayerStatement)
CASE_RULE(ScrollTimeline, ScrollTimeline)
CASE_RULE(Container, Container)
#undef CASE_RULE
case StyleCssRuleType::Viewport:
MOZ_ASSERT_UNREACHABLE("viewport is not implemented in Gecko");
@ -247,6 +249,7 @@ void ServoCSSRuleList::SetRawAfterClone(RefPtr<ServoCssRules> aNewRules) {
CASE_FOR(LayerBlock, LayerBlock)
CASE_FOR(LayerStatement, LayerStatement)
CASE_FOR(ScrollTimeline, ScrollTimeline)
CASE_FOR(Container, Container)
case StyleCssRuleType::Keyframe:
MOZ_ASSERT_UNREACHABLE("keyframe rule cannot be here");
break;

View file

@ -56,6 +56,7 @@ template struct StyleStrong<RawServoFontFeatureValuesRule>;
template struct StyleStrong<RawServoFontFaceRule>;
template struct StyleStrong<RawServoCounterStyleRule>;
template struct StyleStrong<RawServoScrollTimelineRule>;
template struct StyleStrong<RawServoContainerRule>;
template <typename T>
inline void StyleOwnedSlice<T>::Clear() {

View file

@ -30,6 +30,7 @@
#include "mozilla/dom/CSSFontFaceRule.h"
#include "mozilla/dom/CSSFontFeatureValuesRule.h"
#include "mozilla/dom/CSSImportRule.h"
#include "mozilla/dom/CSSContainerRule.h"
#include "mozilla/dom/CSSLayerBlockRule.h"
#include "mozilla/dom/CSSLayerStatementRule.h"
#include "mozilla/dom/CSSMediaRule.h"
@ -949,6 +950,7 @@ void ServoStyleSet::RuleChangedInternal(StyleSheet& aSheet, css::Rule& aRule,
CASE_FOR(LayerBlock, LayerBlock)
CASE_FOR(LayerStatement, LayerStatement)
CASE_FOR(ScrollTimeline, ScrollTimeline)
CASE_FOR(Container, Container)
// @namespace can only be inserted / removed when there are only other
// @namespace and @import rules, and can't be mutated.
case StyleCssRuleType::Namespace:

View file

@ -121,6 +121,7 @@ EXPORTS.mozilla += [
EXPORTS.mozilla.dom += [
"CSS.h",
"CSSContainerRule.h",
"CSSCounterStyleRule.h",
"CSSFontFaceRule.h",
"CSSFontFeatureValuesRule.h",
@ -166,6 +167,7 @@ UNIFIED_SOURCES += [
"ComputedStyle.cpp",
"CounterStyleManager.cpp",
"CSS.cpp",
"CSSContainerRule.cpp",
"CSSCounterStyleRule.cpp",
"CSSFontFaceRule.cpp",
"CSSFontFeatureValuesRule.cpp",

View file

@ -15,7 +15,7 @@ use crate::gecko_bindings::structs::{
RawServoKeyframesRule, RawServoLayerBlockRule, RawServoLayerStatementRule, RawServoMediaList,
RawServoMediaRule, RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule,
RawServoScrollTimelineRule, RawServoStyleRule, RawServoStyleSheetContents,
RawServoSupportsRule, ServoCssRules,
RawServoSupportsRule, RawServoContainerRule, ServoCssRules,
};
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
use crate::media_queries::MediaList;
@ -26,7 +26,7 @@ use crate::stylesheets::keyframes_rule::Keyframe;
use crate::stylesheets::{
CounterStyleRule, CssRules, DocumentRule, FontFaceRule, FontFeatureValuesRule, ImportRule,
KeyframesRule, LayerBlockRule, LayerStatementRule, MediaRule, NamespaceRule, PageRule,
ScrollTimelineRule, StyleRule, StylesheetContents, SupportsRule,
ScrollTimelineRule, StyleRule, StylesheetContents, SupportsRule, ContainerRule,
};
use servo_arc::{Arc, ArcBorrow};
use std::{mem, ptr};
@ -98,6 +98,9 @@ impl_arc_ffi!(Locked<ScrollTimelineRule> => RawServoScrollTimelineRule
impl_arc_ffi!(Locked<SupportsRule> => RawServoSupportsRule
[Servo_SupportsRule_AddRef, Servo_SupportsRule_Release]);
impl_arc_ffi!(Locked<ContainerRule> => RawServoContainerRule
[Servo_ContainerRule_AddRef, Servo_ContainerRule_Release]);
impl_arc_ffi!(Locked<DocumentRule> => RawServoMozDocumentRule
[Servo_DocumentRule_AddRef, Servo_DocumentRule_Release]);

View file

@ -556,6 +556,7 @@ impl StylesheetInvalidationSet {
FontFace(..) |
Keyframes(..) |
ScrollTimeline(..) |
Container(..) |
Style(..) => {
if is_generic_change {
// TODO(emilio): We need to do this for selector / keyframe
@ -610,7 +611,7 @@ impl StylesheetInvalidationSet {
}
},
Document(..) | Namespace(..) | Import(..) | Media(..) | Supports(..) |
LayerStatement(..) | LayerBlock(..) => {
Container(..) | LayerStatement(..) | LayerBlock(..) => {
// Do nothing, relevant nested rules are visited as part of the
// iteration.
},

View file

@ -0,0 +1,79 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! A [`@container`][container] rule.
//!
//! [container]: https://drafts.csswg.org/css-contain-3/#container-rule
use crate::media_queries::MediaCondition;
use crate::shared_lock::{
DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard,
};
use crate::values::specified::ContainerName;
use crate::str::CssStringWriter;
use crate::stylesheets::CssRules;
use cssparser::SourceLocation;
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use servo_arc::Arc;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
/// A container rule.
#[derive(Debug, ToShmem)]
pub struct ContainerRule {
/// The container name.
pub name: ContainerName,
/// The container query.
pub condition: ContainerCondition,
/// The nested rules inside the block.
pub rules: Arc<Locked<CssRules>>,
/// The source position where this rule was found.
pub source_location: SourceLocation,
}
impl ContainerRule {
/// Measure heap usage.
#[cfg(feature = "gecko")]
pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
// Measurement of other fields may be added later.
self.rules.unconditional_shallow_size_of(ops)
+ self.rules.read_with(guard).size_of(guard, ops)
}
}
impl DeepCloneWithLock for ContainerRule {
fn deep_clone_with_lock(
&self,
lock: &SharedRwLock,
guard: &SharedRwLockReadGuard,
params: &DeepCloneParams,
) -> Self {
let rules = self.rules.read_with(guard);
Self {
name: self.name.clone(),
condition: self.condition.clone(),
rules: Arc::new(lock.wrap(rules.deep_clone_with_lock(lock, guard, params))),
source_location: self.source_location.clone(),
}
}
}
impl ToCssWithGuard for ContainerRule {
fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
dest.write_str("@container ")?;
{
let mut writer = CssWriter::new(dest);
if !self.name.is_none() {
self.name.to_css(&mut writer)?;
writer.write_char(' ')?;
}
self.condition.to_css(&mut writer)?;
}
self.rules.read_with(guard).to_css_block(guard, dest)
}
}
/// TODO: Factor out the media query code to work with containers.
pub type ContainerCondition = MediaCondition;

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! A [`@layer`][layer] urle.
//! A [`@layer`][layer] rule.
//!
//! [layer]: https://drafts.csswg.org/css-cascade-5/#layering

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! An [`@media`][media] urle.
//! An [`@media`][media] rule.
//!
//! [media]: https://drafts.csswg.org/css-conditional/#at-ruledef-media
@ -18,7 +18,7 @@ use servo_arc::Arc;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
/// An [`@media`][media] urle.
/// An [`@media`][media] rule.
///
/// [media]: https://drafts.csswg.org/css-conditional/#at-ruledef-media
#[derive(Debug, ToShmem)]

View file

@ -12,6 +12,7 @@ pub mod font_feature_values_rule;
pub mod import_rule;
pub mod keyframes_rule;
pub mod layer_rule;
pub mod container_rule;
mod loader;
mod media_rule;
mod namespace_rule;
@ -53,6 +54,7 @@ pub use self::import_rule::ImportRule;
pub use self::keyframes_rule::KeyframesRule;
pub use self::layer_rule::{LayerBlockRule, LayerStatementRule};
pub use self::loader::StylesheetLoader;
pub use self::container_rule::ContainerRule;
pub use self::media_rule::MediaRule;
pub use self::namespace_rule::NamespaceRule;
pub use self::origin::{Origin, OriginSet, OriginSetIterator, PerOrigin, PerOriginIter};
@ -253,6 +255,7 @@ pub enum CssRule {
Import(Arc<Locked<ImportRule>>),
Style(Arc<Locked<StyleRule>>),
Media(Arc<Locked<MediaRule>>),
Container(Arc<Locked<ContainerRule>>),
FontFace(Arc<Locked<FontFaceRule>>),
FontFeatureValues(Arc<Locked<FontFeatureValuesRule>>),
CounterStyle(Arc<Locked<CounterStyleRule>>),
@ -287,6 +290,10 @@ impl CssRule {
lock.unconditional_shallow_size_of(ops) + lock.read_with(guard).size_of(guard, ops)
},
CssRule::Container(ref lock) => {
lock.unconditional_shallow_size_of(ops) + lock.read_with(guard).size_of(guard, ops)
},
CssRule::FontFace(_) => 0,
CssRule::FontFeatureValues(_) => 0,
CssRule::CounterStyle(_) => 0,
@ -344,6 +351,7 @@ pub enum CssRuleType {
LayerBlock = 16,
LayerStatement = 17,
ScrollTimeline = 18,
Container = 19,
}
#[allow(missing_docs)]
@ -373,6 +381,7 @@ impl CssRule {
CssRule::LayerBlock(_) => CssRuleType::LayerBlock,
CssRule::LayerStatement(_) => CssRuleType::LayerStatement,
CssRule::ScrollTimeline(_) => CssRuleType::ScrollTimeline,
CssRule::Container(_) => CssRuleType::Container,
}
}
@ -460,6 +469,12 @@ impl DeepCloneWithLock for CssRule {
lock.wrap(rule.deep_clone_with_lock(lock, guard, params)),
))
},
CssRule::Container(ref arc) => {
let rule = arc.read_with(guard);
CssRule::Container(Arc::new(
lock.wrap(rule.deep_clone_with_lock(lock, guard, params)),
))
},
CssRule::Media(ref arc) => {
let rule = arc.read_with(guard);
CssRule::Media(Arc::new(
@ -545,6 +560,7 @@ impl ToCssWithGuard for CssRule {
CssRule::LayerBlock(ref lock) => lock.read_with(guard).to_css(guard, dest),
CssRule::LayerStatement(ref lock) => lock.read_with(guard).to_css(guard, dest),
CssRule::ScrollTimeline(ref lock) => lock.read_with(guard).to_css(guard, dest),
CssRule::Container(ref lock) => lock.read_with(guard).to_css(guard, dest),
}
}
}

View file

@ -13,6 +13,7 @@ use crate::properties::parse_property_declaration_list;
use crate::selector_parser::{SelectorImpl, SelectorParser};
use crate::shared_lock::{Locked, SharedRwLock};
use crate::str::starts_with_ignore_ascii_case;
use crate::stylesheets::container_rule::{ContainerRule, ContainerCondition};
use crate::stylesheets::document_rule::DocumentCondition;
use crate::stylesheets::font_feature_values_rule::parse_family_name_list;
use crate::stylesheets::import_rule::ImportLayer;
@ -28,6 +29,7 @@ use crate::stylesheets::{
};
use crate::values::computed::font::FamilyName;
use crate::values::{CssUrl, CustomIdent, KeyframesName, TimelineName};
use crate::values::specified::ContainerName;
use crate::{Namespace, Prefix};
use cssparser::{
AtRuleParser, BasicParseError, BasicParseErrorKind, CowRcStr, Parser, ParserState,
@ -162,6 +164,8 @@ pub enum AtRulePrelude {
CounterStyle(CustomIdent),
/// A @media rule prelude, with its media queries.
Media(Arc<Locked<MediaList>>),
/// A @container rule prelude.
Container(ContainerName, ContainerCondition),
/// An @supports rule, with its conditional
Supports(SupportsCondition),
/// A @viewport rule prelude.
@ -428,6 +432,15 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
"font-face" => {
AtRulePrelude::FontFace
},
"container" if static_prefs::pref!("layout.css.container-queries.enabled") => {
// FIXME: This is a bit ambiguous:
// https://github.com/w3c/csswg-drafts/issues/7203
let name = input.try_parse(|input| {
ContainerName::parse(self.context, input)
}).ok().unwrap_or_else(ContainerName::none);
let condition = ContainerCondition::parse(self.context, input)?;
AtRulePrelude::Container(name, condition)
},
"layer" if static_prefs::pref!("layout.css.cascade-layers.enabled") => {
let names = input.try_parse(|input| {
input.parse_comma_separated(|input| {
@ -607,6 +620,16 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
},
))))
},
AtRulePrelude::Container(name, condition) => {
Ok(CssRule::Container(Arc::new(self.shared_lock.wrap(
ContainerRule {
name,
condition,
rules: self.parse_nested_rules(input, CssRuleType::Container),
source_location: start.source_location(),
},
))))
},
AtRulePrelude::Layer(names) => {
let name = match names.len() {
0 | 1 => names.into_iter().next(),

View file

@ -88,6 +88,10 @@ where
}
Some(doc_rule.rules.read_with(guard).0.iter())
},
CssRule::Container(ref lock) => {
let container_rule = lock.read_with(guard);
Some(container_rule.rules.read_with(guard).0.iter())
},
CssRule::Media(ref lock) => {
let media_rule = lock.read_with(guard);
if !C::process_media(guard, device, quirks_mode, media_rule) {

View file

@ -359,6 +359,7 @@ impl SanitizationKind {
CssRule::Media(..) |
CssRule::Supports(..) |
CssRule::Import(..) |
CssRule::Container(..) |
// TODO(emilio): Perhaps Layer should not be always sanitized? But
// we sanitize @media and co, so this seems safer for now.
CssRule::LayerStatement(..) |

View file

@ -2828,6 +2828,7 @@ impl CascadeData {
CssRule::Style(..) |
CssRule::Namespace(..) |
CssRule::FontFace(..) |
CssRule::Container(..) |
CssRule::CounterStyle(..) |
CssRule::Supports(..) |
CssRule::Keyframes(..) |

View file

@ -91,7 +91,7 @@ use style::gecko_bindings::structs::{
RawServoLayerStatementRule, RawServoMediaList, RawServoMediaRule, RawServoMozDocumentRule,
RawServoNamespaceRule, RawServoPageRule, RawServoScrollTimelineRule,
RawServoSharedMemoryBuilder, RawServoStyleSet, RawServoStyleSheetContents,
RawServoSupportsRule, ServoCssRules,
RawServoSupportsRule, RawServoContainerRule, ServoCssRules,
};
use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasFFI};
use style::gecko_bindings::sugar::ownership::{
@ -127,7 +127,7 @@ use style::stylesheets::{
DocumentRule, FontFaceRule, FontFeatureValuesRule, ImportRule, KeyframesRule, LayerBlockRule,
LayerStatementRule, MediaRule, NamespaceRule, Origin, OriginSet, PageRule, SanitizationData,
SanitizationKind, ScrollTimelineRule, StyleRule, StylesheetContents,
StylesheetLoader as StyleStylesheetLoader, SupportsRule, UrlExtraData,
StylesheetLoader as StyleStylesheetLoader, SupportsRule, UrlExtraData, ContainerRule,
};
use style::stylist::{add_size_of_ua_cache, AuthorStylesEnabled, RuleInclusion, Stylist};
use style::thread_state;
@ -2334,6 +2334,14 @@ impl_group_rule_funcs! { (Supports, SupportsRule, RawServoSupportsRule),
changed: Servo_StyleSet_SupportsRuleChanged,
}
impl_group_rule_funcs! { (Container, ContainerRule, RawServoContainerRule),
get_rules: Servo_ContainerRule_GetRules,
getter: Servo_CssRules_GetContainerRuleAt,
debug: Servo_ContainerRule_Debug,
to_css: Servo_ContainerRule_GetCssText,
changed: Servo_StyleSet_ContainerRuleChanged,
}
impl_group_rule_funcs! { (LayerBlock, LayerBlockRule, RawServoLayerBlockRule),
get_rules: Servo_LayerBlockRule_GetRules,
getter: Servo_CssRules_GetLayerBlockRuleAt,
@ -2951,6 +2959,16 @@ pub extern "C" fn Servo_SupportsRule_GetConditionText(
})
}
#[no_mangle]
pub extern "C" fn Servo_ContainerRule_GetConditionText(
rule: &RawServoContainerRule,
result: &mut nsACString,
) {
read_locked_arc(rule, |rule: &ContainerRule| {
rule.condition.to_css(&mut CssWriter::new(result)).unwrap();
})
}
#[no_mangle]
pub extern "C" fn Servo_MozDocumentRule_GetConditionText(
rule: &RawServoMozDocumentRule,

View file

@ -1,6 +1,3 @@
[aspect-ratio-feature-evaluation.html]
[@container queries with aspect-ratio and size containment]
expected: FAIL
[@container query with aspect-ratio change after resize]
expected: FAIL

View file

@ -1,34 +1,4 @@
[at-container-parsing.html]
[(width)]
expected: FAIL
[(min-width: 0px)]
expected: FAIL
[(max-width: 0px)]
expected: FAIL
[(height)]
expected: FAIL
[(min-height: 0px)]
expected: FAIL
[(max-height: 0px)]
expected: FAIL
[(aspect-ratio)]
expected: FAIL
[(min-aspect-ratio: 1/2)]
expected: FAIL
[(max-aspect-ratio: 1/2)]
expected: FAIL
[(orientation: portrait)]
expected: FAIL
[(inline-size)]
expected: FAIL
@ -47,24 +17,9 @@
[(max-block-size: 0px)]
expected: FAIL
[(width: 100px)]
expected: FAIL
[((width: 100px))]
expected: FAIL
[(not (width: 100px))]
expected: FAIL
[((width: 100px) and (height: 100px))]
expected: FAIL
[((width: 50px) or (height: 100px))]
expected: FAIL
[(width < 100px)]
expected: FAIL
[(100px < width)]
expected: FAIL
@ -101,42 +56,9 @@
[(grid)]
expected: FAIL
[Container selector: foo]
expected: FAIL
[Container selector: foo]
expected: FAIL
[Container selector: foo ]
expected: FAIL
[(((width: 40px) or (width: 50px)) and (height: 100px))]
expected: FAIL
[((width: 100px) and ((height: 40px) or (height: 50px)))]
expected: FAIL
[(((width: 40x) and (height: 50px)) or (height: 100px))]
expected: FAIL
[((width: 50px) or ((width: 40px) and (height: 50px)))]
expected: FAIL
[((width: 100px) and (not (height: 100px)))]
expected: FAIL
[(width <= 100px)]
expected: FAIL
[(width = 100px)]
expected: FAIL
[(width > 100px)]
expected: FAIL
[(width >= 100px)]
expected: FAIL
[(100px <= width)]
expected: FAIL
@ -187,3 +109,36 @@
[(100px : width : 200px)]
expected: FAIL
[screen and (width: 100px)]
expected: FAIL
[screen or (width: 100px)]
expected: FAIL
[not screen and (width: 100px)]
expected: FAIL
[not screen or (width: 100px)]
expected: FAIL
[(width: 100px) and (height: 100px)]
expected: FAIL
[(width: 100px) or (height: 100px)]
expected: FAIL
[not (width: 100px)]
expected: FAIL
[foo (width: 100px)]
expected: FAIL
[Container selector: foo foo]
expected: FAIL
[Container selector: none]
expected: FAIL
[Container selector: None]
expected: FAIL

View file

@ -8,11 +8,5 @@
[Serialization of nested @container rule]
expected: FAIL
[Serialization of boolean condition syntax]
expected: FAIL
[Serialization of colon condition syntax]
expected: FAIL
[Serialization of range condition syntax]
expected: FAIL

View file

@ -1,2 +0,0 @@
[canvas-as-container-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[canvas-as-container-004.html]
expected: FAIL

View file

@ -1,3 +1,3 @@
[canvas-as-container-005.html]
[Focusable after container size change]
[Initially display:none, not focusable]
expected: FAIL

View file

@ -1,3 +1,3 @@
[canvas-as-container-006.html]
[Focusable after container size change]
[Initially display:none, not focusable]
expected: FAIL

View file

@ -1,2 +0,0 @@
[change-display-in-container.html]
expected: FAIL

View file

@ -1,3 +0,0 @@
[conditional-container-status.html]
[Conditionally applying container-type:initial]
expected: FAIL

View file

@ -2,9 +2,6 @@
[Match container in outer tree]
expected: FAIL
[Match container in same tree, not walking flat tree ancestors]
expected: FAIL
[Match container in ::slotted selector's originating element tree]
expected: FAIL

View file

@ -5,12 +5,6 @@
[@property is defined regardless of evaluation]
expected: FAIL
[@layer order respected regardless of evaluation]
expected: FAIL
[@font-face is defined regardless of evaluation]
expected: FAIL
[@media works inside @container]
expected: FAIL

View file

@ -1,27 +1,21 @@
[container-nested.html]
[Implicit]
expected: FAIL
[Outer named, inner named]
expected: FAIL
[Outer named, inner named (reverse)]
expected: FAIL
[Outer named, inner implicit]
expected: FAIL
[Inner named, outer implicit]
expected: FAIL
[Inner named, outer implicit (reverse)]
expected: FAIL
[Three levels]
expected: FAIL
[Named inner invalidation]
expected: FAIL
[Implicit outer invalidation]
expected: FAIL
[Implicit, outer failing]
expected: FAIL
[Implicit, inner failing]
expected: FAIL
[Failing outer name]
expected: FAIL
[Failing inner name]
expected: FAIL
[Three levels, middle fail]
expected: FAIL

View file

@ -1,43 +1,4 @@
[container-selection.html]
[(width: 16px) for .size > .inline > span]
expected: FAIL
[(height: 16px) for .inline > .size > span]
expected: FAIL
[(width: 16px) for .inline > .size > span]
expected: FAIL
[(height: 32px) for .size > .inline > span]
expected: FAIL
[a (width: 32px) for .a-size > .b-size > span]
expected: FAIL
[b (width: 16px) for .a-size > .b-size > span]
expected: FAIL
[a (width: 16px) for .a-size > .a-size > span]
expected: FAIL
[a (width: 32px) for .a-size > .a > span]
expected: FAIL
[a (width: 32px) for .ab-size > .size > span]
expected: FAIL
[b (width: 32px) for .ab-size > .size > span]
expected: FAIL
[a (width: 8px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[b (width: 16px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[a (height: 32px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[a (inline-size: 8px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
@ -46,3 +7,12 @@
[a (block-size: 32px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[(height: 16px) for .size > .inline > span]
expected: FAIL
[c (width) for .a-size > .b-size > span]
expected: FAIL
[c (width) for .ab-size > .size > span]
expected: FAIL

View file

@ -1,2 +0,0 @@
[counters-in-container-dynamic.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[counters-in-container.html]
expected: FAIL

View file

@ -1,2 +1,3 @@
[deep-nested-inline-size-containers.html]
expected: ERROR
[Test that all container widths match]
expected: FAIL

View file

@ -4,3 +4,6 @@
[getComputedStyle when intermediate container becomes display:contents]
expected: FAIL
[getComputedStyle when container is display:contents]
expected: FAIL

View file

@ -37,3 +37,18 @@
[getComputedStyle when in display:none with layout dirty outer element]
expected: FAIL
[getComputedStyle when container is display:none]
expected: FAIL
[getComputedStyle when inner container is display:none]
expected: FAIL
[getComputedStyle when intermediate ancestor is display:none]
expected: FAIL
[getComputedStyle when outer container is display:none]
expected: FAIL
[getComputedStyle on ::before when container is display:none]
expected: FAIL

View file

@ -1,2 +0,0 @@
[fieldset-legend-change.html]
expected: FAIL

View file

@ -1,12 +1,12 @@
[font-relative-units-dynamic.html]
[em relative after change]
[em relative before change]
expected: FAIL
[rem relative after change]
[rem relative before change]
expected: FAIL
[ex relative after change]
[ex relative before change]
expected: FAIL
[ch relative after change]
[ch relative before change]
expected: FAIL

View file

@ -1,12 +0,0 @@
[font-relative-units.html]
[em relative inline-size]
expected: FAIL
[rem relative inline-size]
expected: FAIL
[ex relative inline-size]
expected: FAIL
[ch relative inline-size]
expected: FAIL

View file

@ -1,3 +0,0 @@
[fragmented-container-001.html]
[Children of fragmented inline-size container should match inline-size of first fragment]
expected: FAIL

View file

@ -1,30 +1,6 @@
[idlharness.html]
[CSSContainerRule interface object length]
expected: FAIL
[CSSContainerRule interface: existence and properties of interface object]
expected: FAIL
[CSSContainerRule interface: existence and properties of interface prototype object]
expected: FAIL
[Stringification of sheet.cssRules[0\].cssRules[0\]]
expected: FAIL
[CSSContainerRule must be primary interface of sheet.cssRules[0\].cssRules[0\]]
expected: FAIL
[CSSContainerRule must be primary interface of sheet.cssRules[0\]]
expected: FAIL
[CSSContainerRule interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[Stringification of sheet.cssRules[0\]]
expected: FAIL
[CSSContainerRule interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[CSSContainerRule interface object name]
expected: FAIL

View file

@ -1,3 +1,6 @@
[ineligible-containment.html]
[Changing containment eligibility invalidates style]
expected: FAIL
[Container ineligible for containment]
expected: FAIL

View file

@ -1,3 +0,0 @@
[inline-size-and-min-width.html]
[min-width of inline-size container affects container size]
expected: FAIL

View file

@ -1,3 +0,0 @@
[multicol-container-001.html]
[Children of multicol inline-size container should match inline-size of the container]
expected: FAIL

View file

@ -1,2 +0,0 @@
[multicol-inside-container.html]
expected: FAIL

View file

@ -0,0 +1,6 @@
[never-match-container.html]
[Size @container query against inline box never matches]
expected: FAIL
[Size @container query against svg element never matches]
expected: FAIL

View file

@ -1,3 +1,3 @@
[orthogonal-wm-container-query.html]
[Orthogonal width]
[Initial non-orthogonal width]
expected: FAIL

View file

@ -5,11 +5,5 @@
[#container width 400px after padding is applied.]
expected: FAIL
[#container width 400px after padding is applied. #second is removed from the rendering]
expected: FAIL
[#container height measured with 499px width. Both container children visible]
expected: FAIL
[#container width 399x after padding is applied. #second is removed from the rendering]
expected: FAIL

View file

@ -1,24 +1,3 @@
[pseudo-elements-003.html]
[Originating element container for ::before]
expected: FAIL
[Originating element container for ::after]
expected: FAIL
[Originating element container for ::marker]
expected: FAIL
[Originating element container for ::first-line]
expected: FAIL
[Originating element container for ::first-letter]
expected: FAIL
[Originating element container for outer ::first-line]
expected: FAIL
[Originating element container for outer ::first-letter]
expected: FAIL
[Originating element container for ::backdrop]
expected: FAIL

View file

@ -1,12 +0,0 @@
[query-content-box.html]
[Size queries with content-box sizing]
expected: FAIL
[Size queries with border-box sizing]
expected: FAIL
[Size queries with content-box sizing and overflow:scroll]
expected: FAIL
[Size queries with border-box sizing and overflow:scroll]
expected: FAIL

View file

@ -1,37 +1,4 @@
[query-evaluation.html]
[(width)]
expected: FAIL
[((width))]
expected: FAIL
[((((width))))]
expected: FAIL
[(not (height))]
expected: FAIL
[((width) and (width))]
expected: FAIL
[((width) and (width) and (width))]
expected: FAIL
[((width) or (width))]
expected: FAIL
[((width) or (width) or (width))]
expected: FAIL
[((height) or (width) or (width))]
expected: FAIL
[((width) or (height) or (width))]
expected: FAIL
[((width) or (width) or (height))]
expected: FAIL
[((unknown) or (width) or (width))]
expected: FAIL
@ -44,12 +11,6 @@
[((unknown) or (height) or (width))]
expected: FAIL
[(not ((width) and (height)))]
expected: FAIL
[((height) or (not ((height) and (width))))]
expected: FAIL
[style((width: 1px))]
expected: FAIL
@ -94,3 +55,39 @@
[style((height: 2px) or (not ((height: 2px) and (width: 1px))))]
expected: FAIL
[(height)]
expected: FAIL
[((height))]
expected: FAIL
[((((height))))]
expected: FAIL
[(not (width))]
expected: FAIL
[((height) and (height))]
expected: FAIL
[((height) and (width) and (width))]
expected: FAIL
[((width) and (height) and (width))]
expected: FAIL
[((width) and (width) and (height))]
expected: FAIL
[((height) or (height))]
expected: FAIL
[(not ((width) and (width)))]
expected: FAIL
[((width) and (not ((height) or (width))))]
expected: FAIL
[((height) or ((height) and (width)))]
expected: FAIL

View file

@ -1,6 +1,3 @@
[reattach-container-with-dirty-child.html]
[Initially wider than 200px]
expected: FAIL
[Container query changed and inner.style applied]
expected: FAIL

View file

@ -1,2 +0,0 @@
[resize-while-content-visibility-hidden.html]
expected: FAIL

View file

@ -1,3 +1,6 @@
[size-container-no-principal-box.html]
[Check that container queries is supported]
[(min-width: 0) does not match a container without a principal box (display:none)]
expected: FAIL
[(min-width: 0) does not match a container without a principal box (display:contents)]
expected: FAIL

View file

@ -1,22 +1,4 @@
[size-feature-evaluation.html]
[(width >= 100px) (.horizontal)]
expected: FAIL
[(min-width: 100px) (.horizontal)]
expected: FAIL
[(max-width: 100px) (.horizontal)]
expected: FAIL
[(height >= 200px) (.horizontal)]
expected: FAIL
[(min-height: 200px) (.horizontal)]
expected: FAIL
[(max-height: 200px) (.horizontal)]
expected: FAIL
[(inline-size >= 100px) (.horizontal)]
expected: FAIL
@ -35,30 +17,6 @@
[(max-block-size: 200px) (.horizontal)]
expected: FAIL
[(orientation: portrait) (.horizontal)]
expected: FAIL
[(aspect-ratio: 1/2) (.horizontal)]
expected: FAIL
[(width >= 100px) (.vertical)]
expected: FAIL
[(min-width: 100px) (.vertical)]
expected: FAIL
[(max-width: 100px) (.vertical)]
expected: FAIL
[(height >= 200px) (.vertical)]
expected: FAIL
[(min-height: 200px) (.vertical)]
expected: FAIL
[(max-height: 200px) (.vertical)]
expected: FAIL
[(block-size >= 100px) (.vertical)]
expected: FAIL
@ -77,8 +35,50 @@
[(max-inline-size: 200px) (.vertical)]
expected: FAIL
[(orientation: portrait) (.vertical)]
[(width < 100px) (.horizontal)]
expected: FAIL
[(aspect-ratio: 1/2) (.vertical)]
[(min-width: 101px) (.horizontal)]
expected: FAIL
[(max-width: 99px) (.horizontal)]
expected: FAIL
[(height < 200px) (.horizontal)]
expected: FAIL
[(min-height: 201px) (.horizontal)]
expected: FAIL
[(max-height: 199px) (.horizontal)]
expected: FAIL
[(orientation: landscape) (.horizontal)]
expected: FAIL
[(aspect-ratio: 2/1) (.horizontal)]
expected: FAIL
[(width < 100px) (.vertical)]
expected: FAIL
[(min-width: 101px) (.vertical)]
expected: FAIL
[(max-width: 99px) (.vertical)]
expected: FAIL
[(height < 200px) (.vertical)]
expected: FAIL
[(min-height: 201px) (.vertical)]
expected: FAIL
[(max-height: 199px) (.vertical)]
expected: FAIL
[(orientation: landscape) (.vertical)]
expected: FAIL
[(aspect-ratio: 2/1) (.vertical)]
expected: FAIL

View file

@ -1,3 +0,0 @@
[style-change-in-container.html]
[Basic test for container query evaluation stability]
expected: FAIL

View file

@ -0,0 +1,2 @@
[svg-foreignobject-no-size-container.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[svg-g-no-size-container.html]
expected: FAIL

View file

@ -1,6 +0,0 @@
[svg-root-size-container.html]
[SVG text querying SVG root size container]
expected: FAIL
[div in foreignObject querying SVG root size container]
expected: FAIL

View file

@ -1,3 +1,2 @@
[top-layer-dialog-backdrop.html]
prefs: [dom.dialog_element.enabled:true]
expected: FAIL

View file

@ -1,3 +1,3 @@
[top-layer-dialog-container.html]
[#dialog sized by viewport]
[#dialog initially sized by #containing-block]
expected: FAIL

View file

@ -5,5 +5,5 @@
[Modal dialog still has parent as query container while in top layer]
expected: FAIL
[Container changes width while dialog is in top layer]
[#container initially wider than 200px]
expected: FAIL

View file

@ -1,3 +1,6 @@
[top-layer-nested-dialog.html]
[@container queries start matching]
[Dialogs initially not matching for container queries]
expected: FAIL
[Dialogs still not matching after showModal]
expected: FAIL

View file

@ -1,3 +0,0 @@
[transition-style-change-event.html]
[Container Queries - Style Change Event for transitions]
expected: FAIL

View file

@ -1,6 +1,24 @@
[unsupported-axis.html]
[(width > 0px)]
expected: FAIL
[(inline-size > 0px)]
expected: FAIL
[(height > 0px)]
expected: FAIL
[((height > 0px) or (width > 0px))]
expected: FAIL
[((width > 0px) or (height > 0px))]
expected: FAIL
[((orientation: landscape) or (width > 0px))]
expected: FAIL
[((width > 0px) or (orientation: landscape))]
expected: FAIL
[((height > 0px) or (orientation: landscape))]
expected: FAIL
[((height > 0px) or (orientation: landscape)), with contain:size]
expected: FAIL

View file

@ -0,0 +1,2 @@
[whitespace-update-after-removal.html]
expected: FAIL