mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
implement conversion method from Gecko CounterStylePtr to CounterStyleOrNone
This commit is contained in:
parent
16704bbaaa
commit
3e40d670dd
2 changed files with 43 additions and 0 deletions
|
@ -446,4 +446,34 @@ impl CounterStyleOrNone {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert Gecko CounterStylePtr to CounterStyleOrNone.
|
||||||
|
pub fn from_gecko_value(gecko_value: &CounterStylePtr) -> Self {
|
||||||
|
use counter_style::{Symbol, Symbols};
|
||||||
|
use gecko_bindings::bindings::Gecko_CounterStyle_GetName;
|
||||||
|
use gecko_bindings::bindings::Gecko_CounterStyle_GetSymbols;
|
||||||
|
use gecko_bindings::bindings::Gecko_CounterStyle_GetSystem;
|
||||||
|
use gecko_bindings::bindings::Gecko_CounterStyle_IsName;
|
||||||
|
use gecko_bindings::bindings::Gecko_CounterStyle_IsNone;
|
||||||
|
use values::CustomIdent;
|
||||||
|
use values::generics::SymbolsType;
|
||||||
|
|
||||||
|
if unsafe { Gecko_CounterStyle_IsNone(gecko_value) } {
|
||||||
|
CounterStyleOrNone::None
|
||||||
|
} else if unsafe { Gecko_CounterStyle_IsName(gecko_value) } {
|
||||||
|
ns_auto_string!(name);
|
||||||
|
unsafe { Gecko_CounterStyle_GetName(gecko_value, &mut *name) };
|
||||||
|
CounterStyleOrNone::Name(CustomIdent((&*name).into()))
|
||||||
|
} else {
|
||||||
|
let system = unsafe { Gecko_CounterStyle_GetSystem(gecko_value) };
|
||||||
|
let symbol_type = SymbolsType::from_gecko_keyword(system as u32);
|
||||||
|
let symbols = unsafe {
|
||||||
|
let ref gecko_symbols = *Gecko_CounterStyle_GetSymbols(gecko_value);
|
||||||
|
gecko_symbols.iter().map(|gecko_symbol| {
|
||||||
|
Symbol::String(gecko_symbol.to_string())
|
||||||
|
}).collect()
|
||||||
|
};
|
||||||
|
CounterStyleOrNone::Symbols(symbol_type, Symbols(symbols))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,19 @@ impl SymbolsType {
|
||||||
SymbolsType::Fixed => structs::NS_STYLE_COUNTER_SYSTEM_FIXED as u8,
|
SymbolsType::Fixed => structs::NS_STYLE_COUNTER_SYSTEM_FIXED as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert Gecko value to symbol type.
|
||||||
|
pub fn from_gecko_keyword(gecko_value: u32) -> SymbolsType {
|
||||||
|
use gecko_bindings::structs;
|
||||||
|
match gecko_value {
|
||||||
|
structs::NS_STYLE_COUNTER_SYSTEM_CYCLIC => SymbolsType::Cyclic,
|
||||||
|
structs::NS_STYLE_COUNTER_SYSTEM_NUMERIC => SymbolsType::Numeric,
|
||||||
|
structs::NS_STYLE_COUNTER_SYSTEM_ALPHABETIC => SymbolsType::Alphabetic,
|
||||||
|
structs::NS_STYLE_COUNTER_SYSTEM_SYMBOLIC => SymbolsType::Symbolic,
|
||||||
|
structs::NS_STYLE_COUNTER_SYSTEM_FIXED => SymbolsType::Fixed,
|
||||||
|
x => panic!("Unexpected value for symbol type {}", x)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-counter-styles/#typedef-counter-style
|
/// https://drafts.csswg.org/css-counter-styles/#typedef-counter-style
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue