Parse -moz-alt-content as a whole content value (fixes #15726)

This commit is contained in:
Anthony Ramine 2017-05-19 02:23:48 +02:00
parent 8cd4330b2a
commit 499e81410f
4 changed files with 37 additions and 31 deletions

View file

@ -148,7 +148,7 @@ impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T {
let style = self.as_element().unwrap().resolved_style();
return match style.as_ref().get_counters().content {
content::T::Content(ref value) if !value.is_empty() => {
content::T::Items(ref value) if !value.is_empty() => {
TextContent::GeneratedContent((*value).clone())
}
_ => TextContent::GeneratedContent(vec![]),

View file

@ -4238,8 +4238,8 @@ clip-path
}
match v {
T::none |
T::normal => {
T::None |
T::Normal => {
// Ensure destructors run, otherwise we could leak.
if !self.gecko.mContents.is_empty() {
unsafe {
@ -4247,7 +4247,14 @@ clip-path
}
}
},
T::Content(items) => {
T::MozAltContent => {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko, 1);
*self.gecko.mContents[0].mContent.mString.as_mut() = ptr::null_mut();
}
self.gecko.mContents[0].mType = eStyleContentType_AltContent;
},
T::Items(items) => {
unsafe {
Gecko_ClearAndResizeStyleContents(&mut self.gecko,
items.len() as u32);
@ -4289,8 +4296,6 @@ clip-path
=> self.gecko.mContents[i].mType = eStyleContentType_NoOpenQuote,
ContentItem::NoCloseQuote
=> self.gecko.mContents[i].mType = eStyleContentType_NoCloseQuote,
ContentItem::MozAltContent
=> self.gecko.mContents[i].mType = eStyleContentType_AltContent,
ContentItem::Counter(name, style) => {
unsafe {
bindings::Gecko_SetContentDataArray(&mut self.gecko.mContents[i],

View file

@ -55,8 +55,6 @@
NoCloseQuote,
% if product == "gecko":
/// `-moz-alt-content`
MozAltContent,
/// `attr([namespace? `|`]? ident)`
Attr(Option<String>, String),
/// `url(url)`
@ -92,7 +90,6 @@
ContentItem::NoCloseQuote => dest.write_str("no-close-quote"),
% if product == "gecko":
ContentItem::MozAltContent => dest.write_str("-moz-alt-content"),
ContentItem::Attr(ref ns, ref attr) => {
dest.write_str("attr(")?;
if let Some(ref ns) = *ns {
@ -108,21 +105,25 @@
}
}
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
normal,
none,
Content(Vec<ContentItem>),
Normal,
None,
#[cfg(feature = "gecko")]
MozAltContent,
Items(Vec<ContentItem>),
}
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
T::normal => dest.write_str("normal"),
T::none => dest.write_str("none"),
T::Content(ref content) => {
T::Normal => dest.write_str("normal"),
T::None => dest.write_str("none"),
% if product == "gecko":
T::MozAltContent => dest.write_str("-moz-alt-content"),
% endif
T::Items(ref content) => {
let mut iter = content.iter();
try!(iter.next().unwrap().to_css(dest));
for c in iter {
@ -137,7 +138,7 @@
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::normal
computed_value::T::Normal
}
#[cfg(feature = "servo")]
@ -162,11 +163,17 @@
pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
return Ok(SpecifiedValue::normal)
return Ok(SpecifiedValue::Normal)
}
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
return Ok(SpecifiedValue::none)
return Ok(SpecifiedValue::None)
}
% if product == "gecko":
if input.try(|input| input.expect_ident_matching("-moz-alt-content")).is_ok() {
return Ok(SpecifiedValue::MozAltContent)
}
% endif
let mut content = vec![];
loop {
% if product == "gecko":
@ -233,10 +240,6 @@
"no-open-quote" => content.push(ContentItem::NoOpenQuote),
"no-close-quote" => content.push(ContentItem::NoCloseQuote),
% if product == "gecko":
"-moz-alt-content" => content.push(ContentItem::MozAltContent),
% endif
_ => return Err(())
}
}
@ -244,11 +247,10 @@
_ => return Err(())
}
}
if !content.is_empty() {
Ok(SpecifiedValue::Content(content))
} else {
Err(())
if content.is_empty() {
return Err(());
}
Ok(SpecifiedValue::Items(content))
}
</%helpers:longhand>

View file

@ -1820,9 +1820,8 @@ impl ComputedValues {
pub fn ineffective_content_property(&self) -> bool {
use properties::longhands::content::computed_value::T;
match self.get_counters().content {
T::normal |
T::none => true,
T::Content(ref items) => items.is_empty(),
T::Normal | T::None => true,
T::Items(ref items) => items.is_empty(),
}
}