зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #20171 - Make ContentItem use a CustomIdent for counter names (from servo:content-item-counters); r=emilio
See https://github.com/w3c/csswg-drafts/pull/2377. Source-Repo: https://github.com/servo/servo Source-Revision: 476a0764f5398675481cbaaa040ecc061ae6e579 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : c3dbd3ab4fa0904e06e2ca01318b2e08c979b3a7
This commit is contained in:
Родитель
cb1016c774
Коммит
1c9cffdd70
|
@ -189,7 +189,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
|
|||
let temporary_counter = Counter::new();
|
||||
let counter = self.traversal
|
||||
.counters
|
||||
.get(&**counter_name)
|
||||
.get(&*counter_name.0)
|
||||
.unwrap_or(&temporary_counter);
|
||||
new_info = counter.render(self.traversal.layout_context,
|
||||
fragment.node,
|
||||
|
@ -204,7 +204,7 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
|
|||
let temporary_counter = Counter::new();
|
||||
let counter = self.traversal
|
||||
.counters
|
||||
.get(&**counter_name)
|
||||
.get(&*counter_name.0)
|
||||
.unwrap_or(&temporary_counter);
|
||||
new_info = counter.render(self.traversal.layout_context,
|
||||
fragment.node,
|
||||
|
|
|
@ -5428,6 +5428,7 @@ clip-path
|
|||
}
|
||||
|
||||
pub fn set_content(&mut self, v: longhands::content::computed_value::T, device: &Device) {
|
||||
use values::CustomIdent;
|
||||
use values::computed::counters::{Content, ContentItem};
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use gecko_bindings::structs::nsStyleContentData;
|
||||
|
@ -5445,16 +5446,20 @@ clip-path
|
|||
ptr
|
||||
}
|
||||
|
||||
fn set_counter_function(data: &mut nsStyleContentData,
|
||||
fn set_counter_function(
|
||||
data: &mut nsStyleContentData,
|
||||
content_type: nsStyleContentType,
|
||||
name: &str, sep: &str,
|
||||
style: CounterStyleOrNone, device: &Device) {
|
||||
name: &CustomIdent,
|
||||
sep: &str,
|
||||
style: CounterStyleOrNone,
|
||||
device: &Device,
|
||||
) {
|
||||
debug_assert!(content_type == eStyleContentType_Counter ||
|
||||
content_type == eStyleContentType_Counters);
|
||||
let counter_func = unsafe {
|
||||
bindings::Gecko_SetCounterFunction(data, content_type).as_mut().unwrap()
|
||||
};
|
||||
counter_func.mIdent.assign_utf8(name);
|
||||
counter_func.mIdent.assign(name.0.as_slice());
|
||||
if content_type == eStyleContentType_Counters {
|
||||
counter_func.mSeparator.assign_utf8(sep);
|
||||
}
|
||||
|
@ -5522,12 +5527,24 @@ clip-path
|
|||
ContentItem::NoCloseQuote
|
||||
=> self.gecko.mContents[i].mType = eStyleContentType_NoCloseQuote,
|
||||
ContentItem::Counter(ref name, ref style) => {
|
||||
set_counter_function(&mut self.gecko.mContents[i],
|
||||
eStyleContentType_Counter, &name, "", style.clone(), device);
|
||||
set_counter_function(
|
||||
&mut self.gecko.mContents[i],
|
||||
eStyleContentType_Counter,
|
||||
&name,
|
||||
"",
|
||||
style.clone(),
|
||||
device,
|
||||
);
|
||||
}
|
||||
ContentItem::Counters(ref name, ref sep, ref style) => {
|
||||
set_counter_function(&mut self.gecko.mContents[i],
|
||||
eStyleContentType_Counters, &name, &sep, style.clone(), device);
|
||||
set_counter_function(
|
||||
&mut self.gecko.mContents[i],
|
||||
eStyleContentType_Counters,
|
||||
&name,
|
||||
&sep,
|
||||
style.clone(),
|
||||
device,
|
||||
);
|
||||
}
|
||||
ContentItem::Url(ref url) => {
|
||||
unsafe {
|
||||
|
@ -5553,10 +5570,11 @@ clip-path
|
|||
}
|
||||
|
||||
pub fn clone_content(&self) -> longhands::content::computed_value::T {
|
||||
use Atom;
|
||||
use gecko::conversions::string_from_chars_pointer;
|
||||
use gecko_bindings::structs::nsStyleContentType::*;
|
||||
use values::computed::counters::{Content, ContentItem};
|
||||
use values::Either;
|
||||
use values::{CustomIdent, Either};
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
use values::specified::Attr;
|
||||
|
@ -5601,7 +5619,7 @@ clip-path
|
|||
eStyleContentType_Counter | eStyleContentType_Counters => {
|
||||
let gecko_function =
|
||||
unsafe { &**gecko_content.mContent.mCounters.as_ref() };
|
||||
let ident = gecko_function.mIdent.to_string();
|
||||
let ident = CustomIdent(Atom::from(&*gecko_function.mIdent));
|
||||
let style =
|
||||
CounterStyleOrNone::from_gecko_value(&gecko_function.mCounterStyle);
|
||||
let style = match style {
|
||||
|
@ -5610,10 +5628,10 @@ clip-path
|
|||
unreachable!("counter function shouldn't have single string type"),
|
||||
};
|
||||
if gecko_content.mType == eStyleContentType_Counter {
|
||||
ContentItem::Counter(ident.into_boxed_str(), style)
|
||||
ContentItem::Counter(ident, style)
|
||||
} else {
|
||||
let separator = gecko_function.mSeparator.to_string();
|
||||
ContentItem::Counters(ident.into_boxed_str(), separator.into_boxed_str(), style)
|
||||
ContentItem::Counters(ident, separator.into_boxed_str(), style)
|
||||
}
|
||||
},
|
||||
eStyleContentType_Image => {
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#[cfg(feature = "servo")]
|
||||
use computed_values::list_style_type::T as ListStyleType;
|
||||
use cssparser::{self, Parser, Token};
|
||||
use cssparser::{Parser, Token};
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use values::CustomIdent;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::generics::CounterStyleOrNone;
|
||||
use values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||
|
@ -93,7 +93,8 @@ impl Parse for Content {
|
|||
Ok(Token::Function(ref name)) => {
|
||||
let result = match_ignore_ascii_case! { &name,
|
||||
"counter" => Some(input.parse_nested_block(|input| {
|
||||
let name = input.expect_ident()?.as_ref().to_owned().into_boxed_str();
|
||||
let location = input.current_source_location();
|
||||
let name = CustomIdent::from_ident(location, input.expect_ident()?, &[])?;
|
||||
#[cfg(feature = "servo")]
|
||||
let style = Content::parse_counter_style(input);
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -101,7 +102,8 @@ impl Parse for Content {
|
|||
Ok(ContentItem::Counter(name, style))
|
||||
})),
|
||||
"counters" => Some(input.parse_nested_block(|input| {
|
||||
let name = input.expect_ident()?.as_ref().to_owned().into_boxed_str();
|
||||
let location = input.current_source_location();
|
||||
let name = CustomIdent::from_ident(location, input.expect_ident()?, &[])?;
|
||||
input.expect_comma()?;
|
||||
let separator = input.expect_string()?.as_ref().to_owned().into_boxed_str();
|
||||
#[cfg(feature = "servo")]
|
||||
|
@ -145,39 +147,3 @@ impl Parse for Content {
|
|||
Ok(Content::Items(content.into_boxed_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for ContentItem {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where W: Write,
|
||||
{
|
||||
match *self {
|
||||
ContentItem::String(ref s) => s.to_css(dest),
|
||||
ContentItem::Counter(ref s, ref counter_style) => {
|
||||
dest.write_str("counter(")?;
|
||||
cssparser::serialize_identifier(&**s, dest)?;
|
||||
dest.write_str(", ")?;
|
||||
counter_style.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
ContentItem::Counters(ref s, ref separator, ref counter_style) => {
|
||||
dest.write_str("counters(")?;
|
||||
cssparser::serialize_identifier(&**s, dest)?;
|
||||
dest.write_str(", ")?;
|
||||
separator.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
counter_style.to_css(dest)?;
|
||||
dest.write_str(")")
|
||||
}
|
||||
ContentItem::OpenQuote => dest.write_str("open-quote"),
|
||||
ContentItem::CloseQuote => dest.write_str("close-quote"),
|
||||
ContentItem::NoOpenQuote => dest.write_str("no-open-quote"),
|
||||
ContentItem::NoCloseQuote => dest.write_str("no-close-quote"),
|
||||
#[cfg(feature = "gecko")]
|
||||
ContentItem::Attr(ref attr) => {
|
||||
attr.to_css(dest)
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
ContentItem::Url(ref url) => url.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,14 +97,16 @@ pub enum Content {
|
|||
}
|
||||
|
||||
/// Items for the `content` property.
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum ContentItem {
|
||||
/// Literal string content.
|
||||
String(Box<str>),
|
||||
/// `counter(name, style)`.
|
||||
Counter(Box<str>, CounterStyleType),
|
||||
#[css(comma, function)]
|
||||
Counter(CustomIdent, CounterStyleType),
|
||||
/// `counters(name, separator, style)`.
|
||||
Counters(Box<str>, Box<str>, CounterStyleType),
|
||||
#[css(comma, function)]
|
||||
Counters(CustomIdent, Box<str>, CounterStyleType),
|
||||
/// `open-quote`.
|
||||
OpenQuote,
|
||||
/// `close-quote`.
|
||||
|
|
Загрузка…
Ссылка в новой задаче