From 1c9cffdd709d1adf399e74ea215a94a12610537e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 2 Mar 2018 11:18:49 -0500 Subject: [PATCH] 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 --- servo/components/layout/generated_content.rs | 12 ++--- .../components/style/properties/gecko.mako.rs | 44 ++++++++++++----- .../style/values/computed/counters.rs | 48 +++---------------- .../style/values/specified/counters.rs | 8 ++-- 4 files changed, 49 insertions(+), 63 deletions(-) diff --git a/servo/components/layout/generated_content.rs b/servo/components/layout/generated_content.rs index bef641ed782a..b71729adca7d 100644 --- a/servo/components/layout/generated_content.rs +++ b/servo/components/layout/generated_content.rs @@ -188,9 +188,9 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> { counter_style)) => { let temporary_counter = Counter::new(); let counter = self.traversal - .counters - .get(&**counter_name) - .unwrap_or(&temporary_counter); + .counters + .get(&*counter_name.0) + .unwrap_or(&temporary_counter); new_info = counter.render(self.traversal.layout_context, fragment.node, fragment.pseudo.clone(), @@ -203,9 +203,9 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> { counter_style)) => { let temporary_counter = Counter::new(); let counter = self.traversal - .counters - .get(&**counter_name) - .unwrap_or(&temporary_counter); + .counters + .get(&*counter_name.0) + .unwrap_or(&temporary_counter); new_info = counter.render(self.traversal.layout_context, fragment.node, fragment.pseudo, diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 5aa7b3d6fa33..0baeecf8e34c 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -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, - content_type: nsStyleContentType, - name: &str, sep: &str, - style: CounterStyleOrNone, device: &Device) { + fn set_counter_function( + data: &mut nsStyleContentData, + content_type: nsStyleContentType, + 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 => { diff --git a/servo/components/style/values/computed/counters.rs b/servo/components/style/values/computed/counters.rs index a1b1b78740d0..0e3510b8265d 100644 --- a/servo/components/style/values/computed/counters.rs +++ b/servo/components/style/values/computed/counters.rs @@ -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(&self, dest: &mut CssWriter) -> 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), - } - } -} diff --git a/servo/components/style/values/specified/counters.rs b/servo/components/style/values/specified/counters.rs index 4819009a8bc8..9460f3965cf6 100644 --- a/servo/components/style/values/specified/counters.rs +++ b/servo/components/style/values/specified/counters.rs @@ -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), /// `counter(name, style)`. - Counter(Box, CounterStyleType), + #[css(comma, function)] + Counter(CustomIdent, CounterStyleType), /// `counters(name, separator, style)`. - Counters(Box, Box, CounterStyleType), + #[css(comma, function)] + Counters(CustomIdent, Box, CounterStyleType), /// `open-quote`. OpenQuote, /// `close-quote`.