Make stylo use counter-style for list-style-type and counter functions.

This commit is contained in:
Xidorn Quan 2017-05-16 09:47:28 +10:00
parent 3e00a91e20
commit ff1ac8346f
5 changed files with 200 additions and 69 deletions

View file

@ -2987,29 +2987,12 @@ fn static_assert() {
}
pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T) {
use properties::longhands::list_style_type::computed_value::T as Keyword;
<%
keyword = data.longhands_by_name["list-style-type"].keyword
# The first four are @counter-styles
# The rest have special fallback behavior
special = """upper-roman lower-roman upper-alpha lower-alpha
japanese-informal japanese-formal korean-hangul-formal korean-hanja-informal
korean-hanja-formal simp-chinese-informal simp-chinese-formal
trad-chinese-informal trad-chinese-formal""".split()
%>
let result = match v {
% for value in keyword.values_for('gecko'):
% if value in special:
// Special keywords are implemented as @counter-styles
// and need to be manually set as strings
Keyword::${to_rust_ident(value)} => structs::${keyword.gecko_constant("none")},
% else:
Keyword::${to_rust_ident(value)} =>
structs::${keyword.gecko_constant(value)},
% endif
% endfor
use values::generics::CounterStyleOrNone;
let name = match v.0 {
CounterStyleOrNone::None_ => atom!("none"),
CounterStyleOrNone::Name(name) => name.0,
};
unsafe { Gecko_SetListStyleType(&mut self.gecko, result as u32); }
unsafe { Gecko_SetListStyleType(&mut self.gecko, name.as_ptr()); }
}
@ -4072,7 +4055,8 @@ clip-path
pub fn set_content(&mut self, v: longhands::content::computed_value::T) {
use properties::longhands::content::computed_value::T;
use properties::longhands::content::computed_value::ContentItem;
use style_traits::ToCss;
use values::generics::CounterStyleOrNone;
use gecko_bindings::structs::nsCSSValue;
use gecko_bindings::structs::nsStyleContentType::*;
use gecko_bindings::bindings::Gecko_ClearAndResizeStyleContents;
@ -4086,6 +4070,13 @@ clip-path
ptr
}
fn set_counter_style(style: CounterStyleOrNone, dest: &mut nsCSSValue) {
dest.set_atom_ident(match style {
CounterStyleOrNone::None_ => atom!("none"),
CounterStyleOrNone::Name(name) => name.0,
});
}
match v {
T::none |
T::normal => {
@ -4147,8 +4138,7 @@ clip-path
}
let mut array = unsafe { &mut **self.gecko.mContents[i].mContent.mCounters.as_mut() };
array[0].set_string(&name);
// When we support <custom-ident> values for list-style-type this will need to be updated
array[1].set_atom_ident(style.to_css_string().into());
set_counter_style(style, &mut array[1]);
}
ContentItem::Counters(name, sep, style) => {
unsafe {
@ -4158,8 +4148,7 @@ clip-path
let mut array = unsafe { &mut **self.gecko.mContents[i].mContent.mCounters.as_mut() };
array[0].set_string(&name);
array[1].set_string(&sep);
// When we support <custom-ident> values for list-style-type this will need to be updated
array[2].set_atom_ident(style.to_css_string().into());
set_counter_style(style, &mut array[2]);
}
ContentItem::Url(ref url) => {
unsafe {