mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Use Servo data to back @counter-style rule.
This commit is contained in:
parent
32cd0b4ea0
commit
80ab893e3a
12 changed files with 18158 additions and 18132 deletions
|
@ -9,17 +9,10 @@ use computed_values::{font_stretch, font_style, font_weight};
|
|||
use counter_style::{self, CounterBound};
|
||||
use cssparser::UnicodeRange;
|
||||
use font_face::{Source, FontDisplay, FontWeight};
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs::{self, nsCSSValue};
|
||||
use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
|
||||
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
|
||||
use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
|
||||
use nsstring::nsString;
|
||||
use properties::longhands::font_language_override;
|
||||
use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
|
||||
use std::fmt::{self, Write};
|
||||
use std::str;
|
||||
use str::CssStringWriter;
|
||||
use values::computed::font::FamilyName;
|
||||
use values::generics::font::FontTag;
|
||||
use values::specified::font::{SpecifiedFontVariationSettings, SpecifiedFontFeatureSettings};
|
||||
|
@ -192,101 +185,62 @@ impl<'a> ToNsCssValue for &'a FontDisplay {
|
|||
}
|
||||
}
|
||||
|
||||
/// A @counter-style rule
|
||||
pub type CounterStyleRule = RefPtr<nsCSSCounterStyleRule>;
|
||||
|
||||
impl CounterStyleRule {
|
||||
/// Ask Gecko to deep clone the nsCSSCounterStyleRule, and then construct
|
||||
/// a CounterStyleRule object from it.
|
||||
pub fn deep_clone_from_gecko(&self) -> CounterStyleRule {
|
||||
let result = unsafe {
|
||||
UniqueRefPtr::from_addrefed(
|
||||
bindings::Gecko_CSSCounterStyle_Clone(self.get()))
|
||||
};
|
||||
result.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<counter_style::CounterStyleRuleData> for CounterStyleRule {
|
||||
fn from(data: counter_style::CounterStyleRuleData) -> CounterStyleRule {
|
||||
let mut result = unsafe {
|
||||
UniqueRefPtr::from_addrefed(
|
||||
bindings::Gecko_CSSCounterStyle_Create(data.name().0.as_ptr()))
|
||||
};
|
||||
data.set_descriptors(&mut result.mValues);
|
||||
result.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCssWithGuard for CounterStyleRule {
|
||||
fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
|
||||
let mut css_text = nsString::new();
|
||||
unsafe {
|
||||
bindings::Gecko_CSSCounterStyle_GetCssText(self.get(), &mut *css_text);
|
||||
}
|
||||
write!(dest, "{}", css_text)
|
||||
}
|
||||
}
|
||||
|
||||
/// The type of nsCSSCounterStyleRule::mValues
|
||||
pub type CounterStyleDescriptors = [nsCSSValue; nsCSSCounterDesc::eCSSCounterDesc_COUNT as usize];
|
||||
|
||||
impl ToNsCssValue for counter_style::System {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::System {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
use counter_style::System::*;
|
||||
match self {
|
||||
match *self {
|
||||
Cyclic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_CYCLIC as i32),
|
||||
Numeric => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_NUMERIC as i32),
|
||||
Alphabetic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ALPHABETIC as i32),
|
||||
Symbolic => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_SYMBOLIC as i32),
|
||||
Additive => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ADDITIVE as i32),
|
||||
Fixed { first_symbol_value } => {
|
||||
Fixed { ref first_symbol_value } => {
|
||||
let mut a = nsCSSValue::null();
|
||||
let mut b = nsCSSValue::null();
|
||||
a.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_FIXED as i32);
|
||||
b.set_integer(first_symbol_value.map_or(1, |v| v.value()));
|
||||
nscssvalue.set_pair(&a, &b);
|
||||
}
|
||||
Extends(other) => {
|
||||
Extends(ref other) => {
|
||||
let mut a = nsCSSValue::null();
|
||||
let mut b = nsCSSValue::null();
|
||||
a.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_EXTENDS as i32);
|
||||
b.set_atom_ident(other.0);
|
||||
b.set_atom_ident(other.0.clone());
|
||||
nscssvalue.set_pair(&a, &b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Negative {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Negative {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
if let Some(second) = self.1 {
|
||||
if let Some(ref second) = self.1 {
|
||||
let mut a = nsCSSValue::null();
|
||||
let mut b = nsCSSValue::null();
|
||||
a.set_from(self.0);
|
||||
a.set_from(&self.0);
|
||||
b.set_from(second);
|
||||
nscssvalue.set_pair(&a, &b);
|
||||
} else {
|
||||
nscssvalue.set_from(self.0)
|
||||
nscssvalue.set_from(&self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Symbol {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Symbol {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
match self {
|
||||
counter_style::Symbol::String(s) => nscssvalue.set_string(&s),
|
||||
counter_style::Symbol::Ident(s) => nscssvalue.set_ident_from_atom(&s.0),
|
||||
match *self {
|
||||
counter_style::Symbol::String(ref s) => nscssvalue.set_string(s),
|
||||
counter_style::Symbol::Ident(ref s) => nscssvalue.set_ident_from_atom(&s.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Ranges {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Ranges {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
if self.0.is_empty() {
|
||||
nscssvalue.set_auto();
|
||||
} else {
|
||||
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
|
||||
nscssvalue.set_pair_list(self.0.iter().map(|range| {
|
||||
fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) {
|
||||
if let CounterBound::Integer(finite) = bound {
|
||||
nscssvalue.set_integer(finite.value())
|
||||
|
@ -304,25 +258,25 @@ impl ToNsCssValue for counter_style::Ranges {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Pad {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Pad {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
let mut min_length = nsCSSValue::null();
|
||||
let mut pad_with = nsCSSValue::null();
|
||||
min_length.set_integer(self.0.value());
|
||||
pad_with.set_from(self.1);
|
||||
pad_with.set_from(&self.1);
|
||||
nscssvalue.set_pair(&min_length, &pad_with);
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Fallback {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Fallback {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_atom_ident(self.0 .0)
|
||||
nscssvalue.set_atom_ident(self.0 .0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::Symbols {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::Symbols {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_list(self.0.into_iter().map(|item| {
|
||||
nscssvalue.set_list(self.0.iter().map(|item| {
|
||||
let mut value = nsCSSValue::null();
|
||||
value.set_from(item);
|
||||
value
|
||||
|
@ -330,27 +284,27 @@ impl ToNsCssValue for counter_style::Symbols {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::AdditiveSymbols {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::AdditiveSymbols {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_pair_list(self.0.into_iter().map(|tuple| {
|
||||
nscssvalue.set_pair_list(self.0.iter().map(|tuple| {
|
||||
let mut weight = nsCSSValue::null();
|
||||
let mut symbol = nsCSSValue::null();
|
||||
weight.set_integer(tuple.weight.value());
|
||||
symbol.set_from(tuple.symbol);
|
||||
symbol.set_from(&tuple.symbol);
|
||||
(weight, symbol)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for counter_style::SpeakAs {
|
||||
impl<'a> ToNsCssValue for &'a counter_style::SpeakAs {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
use counter_style::SpeakAs::*;
|
||||
match self {
|
||||
match *self {
|
||||
Auto => nscssvalue.set_auto(),
|
||||
Bullets => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_BULLETS as i32),
|
||||
Numbers => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_NUMBERS as i32),
|
||||
Words => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_WORDS as i32),
|
||||
Other(other) => nscssvalue.set_atom_ident(other.0),
|
||||
Other(ref other) => nscssvalue.set_atom_ident(other.0.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue