mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
style: [css-nesting] Update cssparser to allow parsing qualified rules along with declaration
No implementation just yet (the default QualifiedRuleParser implementation just rejects stuff), but this is plumbing that I'd rather get reviewed separately. Differential Revision: https://phabricator.services.mozilla.com/D176686
This commit is contained in:
parent
93e0711194
commit
6f090b8a85
8 changed files with 76 additions and 25 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -1170,8 +1170,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cssparser"
|
name = "cssparser"
|
||||||
version = "0.30.0"
|
version = "0.31.0"
|
||||||
source = "git+https://github.com/servo/rust-cssparser?rev=45bc47e2bcb846f1efb5aea156be5fe7d18624bf#45bc47e2bcb846f1efb5aea156be5fe7d18624bf"
|
source = "git+https://github.com/servo/rust-cssparser?rev=3e1bd05139cb7174ace395d498ca7128feb8f69d#3e1bd05139cb7174ace395d498ca7128feb8f69d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cssparser-macros",
|
"cssparser-macros",
|
||||||
"dtoa-short",
|
"dtoa-short",
|
||||||
|
@ -1187,7 +1187,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cssparser-macros"
|
name = "cssparser-macros"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/servo/rust-cssparser?rev=45bc47e2bcb846f1efb5aea156be5fe7d18624bf#45bc47e2bcb846f1efb5aea156be5fe7d18624bf"
|
source = "git+https://github.com/servo/rust-cssparser?rev=3e1bd05139cb7174ace395d498ca7128feb8f69d#3e1bd05139cb7174ace395d498ca7128feb8f69d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.103",
|
"syn 1.0.103",
|
||||||
|
|
|
@ -27,7 +27,7 @@ compositing_traits = { path = "components/shared/compositing" }
|
||||||
content-security-policy = { version = "0.5", features = ["serde"] }
|
content-security-policy = { version = "0.5", features = ["serde"] }
|
||||||
cookie = "0.12"
|
cookie = "0.12"
|
||||||
crossbeam-channel = "0.5"
|
crossbeam-channel = "0.5"
|
||||||
cssparser = { version = "0.30", git = "https://github.com/servo/rust-cssparser", rev = "45bc47e2bcb846f1efb5aea156be5fe7d18624bf" }
|
cssparser = { version = "0.31", git = "https://github.com/servo/rust-cssparser", rev = "3e1bd05139cb7174ace395d498ca7128feb8f69d" }
|
||||||
darling = { version = "0.14", default-features = false }
|
darling = { version = "0.14", default-features = false }
|
||||||
data-url = "0.1.0"
|
data-url = "0.1.0"
|
||||||
devtools_traits = { path = "components/shared/devtools" }
|
devtools_traits = { path = "components/shared/devtools" }
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::str::CssStringWriter;
|
||||||
use crate::values::specified::Integer;
|
use crate::values::specified::Integer;
|
||||||
use crate::values::CustomIdent;
|
use crate::values::CustomIdent;
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
|
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, QualifiedRuleParser};
|
||||||
use cssparser::{CowRcStr, Parser, SourceLocation, Token};
|
use cssparser::{CowRcStr, Parser, SourceLocation, Token};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
|
@ -153,6 +153,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for CounterStyleRuleParser<'a, 'b> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for CounterStyleRuleParser<'a, 'b> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = ();
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! checker {
|
macro_rules! checker {
|
||||||
($self:ident._($value:ident)) => {};
|
($self:ident._($value:ident)) => {};
|
||||||
($self:ident. $checker:ident($value:ident)) => {
|
($self:ident. $checker:ident($value:ident)) => {
|
||||||
|
|
|
@ -16,18 +16,20 @@ use crate::values::computed::font::{FamilyName, FontStretch};
|
||||||
use crate::values::generics::font::FontStyle as GenericFontStyle;
|
use crate::values::generics::font::FontStyle as GenericFontStyle;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use crate::values::specified::font::MetricsOverride;
|
use crate::values::specified::font::MetricsOverride;
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
use crate::values::specified::font::{FontFeatureSettings, FontVariationSettings};
|
|
||||||
use crate::values::specified::font::SpecifiedFontStyle;
|
use crate::values::specified::font::SpecifiedFontStyle;
|
||||||
use crate::values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
|
use crate::values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
use crate::values::specified::font::{FontFeatureSettings, FontVariationSettings};
|
||||||
use crate::values::specified::url::SpecifiedUrl;
|
use crate::values::specified::url::SpecifiedUrl;
|
||||||
use crate::values::specified::Angle;
|
use crate::values::specified::Angle;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use crate::values::specified::NonNegativePercentage;
|
use crate::values::specified::NonNegativePercentage;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
use cssparser::{
|
||||||
use cssparser::{CowRcStr, SourceLocation};
|
AtRuleParser, CowRcStr, DeclarationListParser, DeclarationParser, Parser, QualifiedRuleParser,
|
||||||
|
SourceLocation,
|
||||||
|
};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ParseError};
|
use style_traits::{CssWriter, ParseError};
|
||||||
|
@ -558,6 +560,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for FontFaceRuleParser<'a, 'b> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for FontFaceRuleParser<'a, 'b> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = ();
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
fn font_tech_enabled() -> bool {
|
fn font_tech_enabled() -> bool {
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
return static_prefs::pref!("layout.css.font-tech.enabled");
|
return static_prefs::pref!("layout.css.font-tech.enabled");
|
||||||
|
|
|
@ -18,10 +18,12 @@ use crate::selector_map::PrecomputedHashSet;
|
||||||
use crate::selector_parser::SelectorImpl;
|
use crate::selector_parser::SelectorImpl;
|
||||||
use crate::shared_lock::Locked;
|
use crate::shared_lock::Locked;
|
||||||
use crate::str::{CssString, CssStringWriter};
|
use crate::str::{CssString, CssStringWriter};
|
||||||
use crate::stylesheets::{CssRuleType, Origin, UrlExtraData, layer_rule::LayerOrder};
|
use crate::stylesheets::{layer_rule::LayerOrder, CssRuleType, Origin, UrlExtraData};
|
||||||
use crate::values::computed::Context;
|
use crate::values::computed::Context;
|
||||||
use cssparser::{parse_important, CowRcStr, DeclarationListParser, ParserInput};
|
use cssparser::{
|
||||||
use cssparser::{AtRuleParser, DeclarationParser, Delimiter, ParseErrorKind, Parser};
|
parse_important, AtRuleParser, CowRcStr, DeclarationListParser, DeclarationParser, Delimiter,
|
||||||
|
ParseErrorKind, Parser, ParserInput, QualifiedRuleParser,
|
||||||
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use selectors::SelectorList;
|
use selectors::SelectorList;
|
||||||
use smallbitvec::{self, SmallBitVec};
|
use smallbitvec::{self, SmallBitVec};
|
||||||
|
@ -930,7 +932,13 @@ impl PropertyDeclarationBlock {
|
||||||
|
|
||||||
for declaration in self.normal_declaration_iter() {
|
for declaration in self.normal_declaration_iter() {
|
||||||
if let PropertyDeclaration::Custom(ref declaration) = *declaration {
|
if let PropertyDeclaration::Custom(ref declaration) = *declaration {
|
||||||
builder.cascade(declaration, CascadePriority::new(CascadeLevel::same_tree_author_normal(), LayerOrder::root()));
|
builder.cascade(
|
||||||
|
declaration,
|
||||||
|
CascadePriority::new(
|
||||||
|
CascadeLevel::same_tree_author_normal(),
|
||||||
|
LayerOrder::root(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,12 +1102,11 @@ impl PropertyDeclarationBlock {
|
||||||
// 3.4.7:
|
// 3.4.7:
|
||||||
// Let value be the result of invoking serialize a CSS value
|
// Let value be the result of invoking serialize a CSS value
|
||||||
// of current longhands.
|
// of current longhands.
|
||||||
let appendable_value = match shorthand
|
let appendable_value =
|
||||||
.get_shorthand_appendable_value(¤t_longhands)
|
match shorthand.get_shorthand_appendable_value(¤t_longhands) {
|
||||||
{
|
None => continue,
|
||||||
None => continue,
|
Some(appendable_value) => appendable_value,
|
||||||
Some(appendable_value) => appendable_value,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
// We avoid re-serializing if we're already an
|
// We avoid re-serializing if we're already an
|
||||||
// AppendableValue::Css.
|
// AppendableValue::Css.
|
||||||
|
@ -1122,7 +1129,9 @@ impl PropertyDeclarationBlock {
|
||||||
AppendableValue::Css({
|
AppendableValue::Css({
|
||||||
// Safety: serialization only generates valid utf-8.
|
// Safety: serialization only generates valid utf-8.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
unsafe { v.as_str_unchecked() }
|
unsafe {
|
||||||
|
v.as_str_unchecked()
|
||||||
|
}
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
&v
|
&v
|
||||||
})
|
})
|
||||||
|
@ -1353,6 +1362,13 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for PropertyDeclarationParser<'a, 'b> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Default methods reject all rules.
|
||||||
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for PropertyDeclarationParser<'a, 'b> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = Importance;
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
/// Based on NonMozillaVendorIdentifier from Gecko's CSS parser.
|
/// Based on NonMozillaVendorIdentifier from Gecko's CSS parser.
|
||||||
fn is_non_mozilla_vendor_identifier(name: &str) -> bool {
|
fn is_non_mozilla_vendor_identifier(name: &str) -> bool {
|
||||||
(name.starts_with("-") && !name.starts_with("-moz-")) || name.starts_with("_")
|
(name.starts_with("-") && !name.starts_with("-moz-")) || name.starts_with("_")
|
||||||
|
|
|
@ -18,9 +18,10 @@ use crate::stylesheets::CssRuleType;
|
||||||
use crate::values::computed::font::FamilyName;
|
use crate::values::computed::font::FamilyName;
|
||||||
use crate::values::serialize_atom_identifier;
|
use crate::values::serialize_atom_identifier;
|
||||||
use crate::Atom;
|
use crate::Atom;
|
||||||
use cssparser::{AtRuleParser, BasicParseErrorKind, CowRcStr};
|
use cssparser::{
|
||||||
use cssparser::{DeclarationListParser, DeclarationParser, Parser};
|
AtRuleParser, BasicParseErrorKind, CowRcStr, DeclarationListParser, DeclarationParser, Parser,
|
||||||
use cssparser::{ParserState, QualifiedRuleParser, RuleListParser, SourceLocation, Token};
|
ParserState, QualifiedRuleParser, RuleListParser, SourceLocation, Token,
|
||||||
|
};
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||||
|
|
||||||
|
@ -193,6 +194,12 @@ impl<'a, 'b, 'i, T> AtRuleParser<'i> for FFVDeclarationsParser<'a, 'b, T> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, 'i, T> QualifiedRuleParser<'i> for FFVDeclarationsParser<'a, 'b, T> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = ();
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T>
|
impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T>
|
||||||
where
|
where
|
||||||
T: Parse,
|
T: Parse,
|
||||||
|
|
|
@ -636,6 +636,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = ();
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
||||||
type Declaration = ();
|
type Declaration = ();
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
|
|
@ -24,8 +24,10 @@ use crate::values::generics::NonNegative;
|
||||||
use crate::values::specified::{self, NoCalcLength};
|
use crate::values::specified::{self, NoCalcLength};
|
||||||
use crate::values::specified::{NonNegativeLengthPercentageOrAuto, ViewportPercentageLength};
|
use crate::values::specified::{NonNegativeLengthPercentageOrAuto, ViewportPercentageLength};
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::CowRcStr;
|
use cssparser::{
|
||||||
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
parse_important, AtRuleParser, CowRcStr, DeclarationListParser, DeclarationParser, Parser,
|
||||||
|
QualifiedRuleParser,
|
||||||
|
};
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -237,6 +239,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for ViewportRuleParser<'a, 'b> {
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for ViewportRuleParser<'a, 'b> {
|
||||||
|
type Prelude = ();
|
||||||
|
type QualifiedRule = Vec<ViewportDescriptorDeclaration>;
|
||||||
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
|
impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
|
||||||
type Declaration = Vec<ViewportDescriptorDeclaration>;
|
type Declaration = Vec<ViewportDescriptorDeclaration>;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue