diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-04-22 09:06:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 07:06:36 +0000 |
commit | f9e154af5543063e4a168b92948d1009c73f2bf3 (patch) | |
tree | 49b20dd980cb773dd79e2d3a7e247740ec34fb09 /components | |
parent | 67f239d1bab9e866539ea4ef76a1d40bcbeb7d53 (diff) | |
download | servo-f9e154af5543063e4a168b92948d1009c73f2bf3.tar.gz servo-f9e154af5543063e4a168b92948d1009c73f2bf3.zip |
Fix InsertRule to use the right CssRuleTypes (#32125)
`CSSRule::Type()` returns an u16 for CSSOM. `InsertRule()` was
incorrectly using this to create a `CssRuleTypes`.
Instead of `CssRuleTypes::from_bits(rule_type)`, it should be something
like `CssRuleTypes::from_bits(1 << rule_type)`.
However, that would only work when `Type()` provides an actual value,
which per https://drafts.csswg.org/cssom/#dom-cssrule-type only happens
for old rule types. New rule types just return 0.
Therefore, this patch changes the signature of `SpecificCSSRule::ty()`
to return the actual `CssRuleType`, and then `CSSRule::Type()` can zero
it out when necessary.
The fix is only relevant for CSS Nesting, which is currently disabled on
Servo, so no test is necessary.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because the fix is only
relevant for CSS Nesting, which is currently disabled
<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->
<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->
Diffstat (limited to 'components')
-rw-r--r-- | components/script/dom/cssfontfacerule.rs | 7 | ||||
-rw-r--r-- | components/script/dom/cssgroupingrule.rs | 4 | ||||
-rw-r--r-- | components/script/dom/cssimportrule.rs | 7 | ||||
-rw-r--r-- | components/script/dom/csskeyframerule.rs | 6 | ||||
-rw-r--r-- | components/script/dom/csskeyframesrule.rs | 6 | ||||
-rw-r--r-- | components/script/dom/csslayerblockrule.rs | 6 | ||||
-rw-r--r-- | components/script/dom/csslayerstatementrule.rs | 6 | ||||
-rw-r--r-- | components/script/dom/cssmediarule.rs | 7 | ||||
-rw-r--r-- | components/script/dom/cssnamespacerule.rs | 7 | ||||
-rw-r--r-- | components/script/dom/cssrule.rs | 13 | ||||
-rw-r--r-- | components/script/dom/cssstylerule.rs | 7 | ||||
-rw-r--r-- | components/script/dom/csssupportsrule.rs | 7 |
12 files changed, 42 insertions, 41 deletions
diff --git a/components/script/dom/cssfontfacerule.rs b/components/script/dom/cssfontfacerule.rs index 125d7a82fbb..67027da294a 100644 --- a/components/script/dom/cssfontfacerule.rs +++ b/components/script/dom/cssfontfacerule.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::{Locked, ToCssWithGuard}; -use style::stylesheets::FontFaceRule; +use style::stylesheets::{CssRuleType, FontFaceRule}; use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::root::DomRoot; @@ -50,9 +50,8 @@ impl CSSFontFaceRule { } impl SpecificCSSRule for CSSFontFaceRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::FONT_FACE_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::FontFace } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/cssgroupingrule.rs b/components/script/dom/cssgroupingrule.rs index a84208f7c45..eb542c6205c 100644 --- a/components/script/dom/cssgroupingrule.rs +++ b/components/script/dom/cssgroupingrule.rs @@ -8,7 +8,6 @@ use style::shared_lock::{Locked, SharedRwLock}; use style::stylesheets::{CssRuleTypes, CssRules as StyleCssRules}; use crate::dom::bindings::codegen::Bindings::CSSGroupingRuleBinding::CSSGroupingRuleMethods; -use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRule_Binding::CSSRuleMethods; use crate::dom::bindings::error::{ErrorResult, Fallible}; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::DomObject; @@ -69,7 +68,8 @@ impl CSSGroupingRuleMethods for CSSGroupingRule { // https://drafts.csswg.org/cssom/#dom-cssgroupingrule-insertrule fn InsertRule(&self, rule: DOMString, index: u32) -> Fallible<u32> { // TODO: this should accumulate the rule types of all ancestors. - let containing_rule_types = CssRuleTypes::from_bits(self.cssrule.Type().into()); + let rule_type = self.cssrule.as_specific().ty(); + let containing_rule_types = CssRuleTypes::from(rule_type); self.rulelist() .insert_rule(&rule, index, containing_rule_types) } diff --git a/components/script/dom/cssimportrule.rs b/components/script/dom/cssimportrule.rs index 2a9bdf44b9c..d75ec291460 100644 --- a/components/script/dom/cssimportrule.rs +++ b/components/script/dom/cssimportrule.rs @@ -6,7 +6,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::import_rule::ImportLayer; -use style::stylesheets::ImportRule; +use style::stylesheets::{CssRuleType, ImportRule}; use style_traits::ToCss; use crate::dom::bindings::codegen::Bindings::CSSImportRuleBinding::CSSImportRuleMethods; @@ -50,9 +50,8 @@ impl CSSImportRule { } impl SpecificCSSRule for CSSImportRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::IMPORT_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Import } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/csskeyframerule.rs b/components/script/dom/csskeyframerule.rs index 4bbf7b026f0..f53f68956fb 100644 --- a/components/script/dom/csskeyframerule.rs +++ b/components/script/dom/csskeyframerule.rs @@ -6,6 +6,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::keyframes_rule::Keyframe; +use style::stylesheets::CssRuleType; use crate::dom::bindings::codegen::Bindings::CSSKeyframeRuleBinding::CSSKeyframeRuleMethods; use crate::dom::bindings::inheritance::Castable; @@ -73,9 +74,8 @@ impl CSSKeyframeRuleMethods for CSSKeyframeRule { } impl SpecificCSSRule for CSSKeyframeRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::KEYFRAME_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Keyframe } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/csskeyframesrule.rs b/components/script/dom/csskeyframesrule.rs index 62fb03ec925..272e7086a41 100644 --- a/components/script/dom/csskeyframesrule.rs +++ b/components/script/dom/csskeyframesrule.rs @@ -7,6 +7,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::{Locked, ToCssWithGuard}; use style::stylesheets::keyframes_rule::{Keyframe, KeyframeSelector, KeyframesRule}; +use style::stylesheets::CssRuleType; use style::values::KeyframesName; use crate::dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods; @@ -145,9 +146,8 @@ impl CSSKeyframesRuleMethods for CSSKeyframesRule { } impl SpecificCSSRule for CSSKeyframesRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::KEYFRAMES_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Keyframes } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/csslayerblockrule.rs b/components/script/dom/csslayerblockrule.rs index 08779e62f98..21db85c2f6d 100644 --- a/components/script/dom/csslayerblockrule.rs +++ b/components/script/dom/csslayerblockrule.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; -use style::stylesheets::LayerBlockRule; +use style::stylesheets::{CssRuleType, LayerBlockRule}; use style_traits::ToCss; use crate::dom::bindings::codegen::Bindings::CSSLayerBlockRuleBinding::CSSLayerBlockRuleMethods; @@ -56,8 +56,8 @@ impl CSSLayerBlockRule { } impl SpecificCSSRule for CSSLayerBlockRule { - fn ty(&self) -> u16 { - 0 + fn ty(&self) -> CssRuleType { + CssRuleType::LayerBlock } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/csslayerstatementrule.rs b/components/script/dom/csslayerstatementrule.rs index f2dbfeca0fd..9a4aa5a0dc9 100644 --- a/components/script/dom/csslayerstatementrule.rs +++ b/components/script/dom/csslayerstatementrule.rs @@ -6,7 +6,7 @@ use dom_struct::dom_struct; use js::jsval::JSVal; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; -use style::stylesheets::LayerStatementRule; +use style::stylesheets::{CssRuleType, LayerStatementRule}; use style_traits::ToCss; use crate::dom::bindings::codegen::Bindings::CSSLayerStatementRuleBinding::CSSLayerStatementRuleMethods; @@ -55,8 +55,8 @@ impl CSSLayerStatementRule { } impl SpecificCSSRule for CSSLayerStatementRule { - fn ty(&self) -> u16 { - 0 + fn ty(&self) -> CssRuleType { + CssRuleType::LayerStatement } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/cssmediarule.rs b/components/script/dom/cssmediarule.rs index f321cd64bf4..3ecf63b1c22 100644 --- a/components/script/dom/cssmediarule.rs +++ b/components/script/dom/cssmediarule.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; -use style::stylesheets::MediaRule; +use style::stylesheets::{CssRuleType, MediaRule}; use style_traits::ToCss; use crate::dom::bindings::codegen::Bindings::CSSMediaRuleBinding::CSSMediaRuleMethods; @@ -68,9 +68,8 @@ impl CSSMediaRule { } impl SpecificCSSRule for CSSMediaRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::MEDIA_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Media } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/cssnamespacerule.rs b/components/script/dom/cssnamespacerule.rs index 0c51b43f387..30395f0158b 100644 --- a/components/script/dom/cssnamespacerule.rs +++ b/components/script/dom/cssnamespacerule.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; -use style::stylesheets::NamespaceRule; +use style::stylesheets::{CssRuleType, NamespaceRule}; use crate::dom::bindings::codegen::Bindings::CSSNamespaceRuleBinding::CSSNamespaceRuleMethods; use crate::dom::bindings::reflector::reflect_dom_object; @@ -67,9 +67,8 @@ impl CSSNamespaceRuleMethods for CSSNamespaceRule { } impl SpecificCSSRule for CSSNamespaceRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::NAMESPACE_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Namespace } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/cssrule.rs b/components/script/dom/cssrule.rs index c56f299c16f..4c7c0b7bd0a 100644 --- a/components/script/dom/cssrule.rs +++ b/components/script/dom/cssrule.rs @@ -6,7 +6,7 @@ use std::cell::Cell; use dom_struct::dom_struct; use style::shared_lock::SharedRwLock; -use style::stylesheets::CssRule as StyleCssRule; +use style::stylesheets::{CssRule as StyleCssRule, CssRuleType}; use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods; use crate::dom::bindings::inheritance::Castable; @@ -147,7 +147,14 @@ impl CSSRule { impl CSSRuleMethods for CSSRule { // https://drafts.csswg.org/cssom/#dom-cssrule-type fn Type(&self) -> u16 { - self.as_specific().ty() + let rule_type = self.as_specific().ty() as u16; + // Per https://drafts.csswg.org/cssom/#dom-cssrule-type for constants > 15 + // we return 0. + if rule_type > 15 { + 0 + } else { + rule_type + } } // https://drafts.csswg.org/cssom/#dom-cssrule-parentstylesheet @@ -171,7 +178,7 @@ impl CSSRuleMethods for CSSRule { } pub trait SpecificCSSRule { - fn ty(&self) -> u16; + fn ty(&self) -> CssRuleType; fn get_css(&self) -> DOMString; /// Remove parentStylesheet from all transitive children fn deparent_children(&self) { diff --git a/components/script/dom/cssstylerule.rs b/components/script/dom/cssstylerule.rs index fe9fecfb4b1..f2e6c279d0e 100644 --- a/components/script/dom/cssstylerule.rs +++ b/components/script/dom/cssstylerule.rs @@ -10,7 +10,7 @@ use selectors::parser::{ParseRelative, SelectorList}; use servo_arc::Arc; use style::selector_parser::SelectorParser; use style::shared_lock::{Locked, ToCssWithGuard}; -use style::stylesheets::{Origin, StyleRule}; +use style::stylesheets::{CssRuleType, Origin, StyleRule}; use crate::dom::bindings::codegen::Bindings::CSSStyleRuleBinding::CSSStyleRuleMethods; use crate::dom::bindings::inheritance::Castable; @@ -58,9 +58,8 @@ impl CSSStyleRule { } impl SpecificCSSRule for CSSStyleRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::STYLE_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Style } fn get_css(&self) -> DOMString { diff --git a/components/script/dom/csssupportsrule.rs b/components/script/dom/csssupportsrule.rs index 6341bc51a44..18ec34aac0e 100644 --- a/components/script/dom/csssupportsrule.rs +++ b/components/script/dom/csssupportsrule.rs @@ -5,7 +5,7 @@ use dom_struct::dom_struct; use servo_arc::Arc; use style::shared_lock::ToCssWithGuard; -use style::stylesheets::SupportsRule; +use style::stylesheets::{CssRuleType, SupportsRule}; use style_traits::ToCss; use crate::dom::bindings::reflector::reflect_dom_object; @@ -58,9 +58,8 @@ impl CSSSupportsRule { } impl SpecificCSSRule for CSSSupportsRule { - fn ty(&self) -> u16 { - use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; - CSSRuleConstants::SUPPORTS_RULE + fn ty(&self) -> CssRuleType { + CssRuleType::Supports } fn get_css(&self) -> DOMString { |