mirror of
https://github.com/servo/servo.git
synced 2025-07-17 20:33:40 +01:00
style: Use an Atom to store pseudo-class string arguments.
Differential Revision: https://phabricator.services.mozilla.com/D4740
This commit is contained in:
parent
4ee3b56d54
commit
2af9264cfe
2 changed files with 4 additions and 22 deletions
|
@ -37,7 +37,7 @@ bitflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type used for storing pseudo-class string arguments.
|
/// The type used for storing pseudo-class string arguments.
|
||||||
pub type PseudoClassStringArg = ThinBoxedSlice<u16>;
|
pub type PseudoClassStringArg = Atom;
|
||||||
|
|
||||||
macro_rules! pseudo_class_name {
|
macro_rules! pseudo_class_name {
|
||||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||||
|
@ -72,24 +72,13 @@ impl ToCss for NonTSPseudoClass {
|
||||||
where
|
where
|
||||||
W: fmt::Write,
|
W: fmt::Write,
|
||||||
{
|
{
|
||||||
use cssparser::CssStringWriter;
|
|
||||||
use std::fmt::Write;
|
|
||||||
macro_rules! pseudo_class_serialize {
|
macro_rules! pseudo_class_serialize {
|
||||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||||
string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => {
|
string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*]) => {
|
||||||
match *self {
|
match *self {
|
||||||
$(NonTSPseudoClass::$name => concat!(":", $css),)*
|
$(NonTSPseudoClass::$name => concat!(":", $css),)*
|
||||||
$(NonTSPseudoClass::$s_name(ref s) => {
|
$(NonTSPseudoClass::$s_name(ref s) => {
|
||||||
dest.write_str(concat!(":", $s_css, "("))?;
|
return write!(dest, concat!(":", $s_css, "({})"), s)
|
||||||
{
|
|
||||||
// FIXME(emilio): Avoid the extra allocation!
|
|
||||||
let mut css = CssStringWriter::new(dest);
|
|
||||||
|
|
||||||
// Discount the null char in the end from the
|
|
||||||
// string.
|
|
||||||
css.write_str(&String::from_utf16(&s[..s.len() - 1]).unwrap())?;
|
|
||||||
}
|
|
||||||
return dest.write_str(")")
|
|
||||||
}, )*
|
}, )*
|
||||||
NonTSPseudoClass::MozLocaleDir(ref dir) => {
|
NonTSPseudoClass::MozLocaleDir(ref dir) => {
|
||||||
dest.write_str(":-moz-locale-dir(")?;
|
dest.write_str(":-moz-locale-dir(")?;
|
||||||
|
@ -405,10 +394,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
||||||
match_ignore_ascii_case! { &name,
|
match_ignore_ascii_case! { &name,
|
||||||
$($s_css => {
|
$($s_css => {
|
||||||
let name = parser.expect_ident_or_string()?;
|
let name = parser.expect_ident_or_string()?;
|
||||||
// convert to null terminated utf16 string
|
NonTSPseudoClass::$s_name(Atom::from(name.as_ref()))
|
||||||
// since that's what Gecko deals with
|
|
||||||
let utf16: Vec<u16> = name.encode_utf16().chain(Some(0u16)).collect();
|
|
||||||
NonTSPseudoClass::$s_name(utf16.into_boxed_slice().into())
|
|
||||||
}, )*
|
}, )*
|
||||||
"-moz-locale-dir" => {
|
"-moz-locale-dir" => {
|
||||||
NonTSPseudoClass::MozLocaleDir(Direction::parse(parser)?)
|
NonTSPseudoClass::MozLocaleDir(Direction::parse(parser)?)
|
||||||
|
|
|
@ -1721,10 +1721,6 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
// Gecko supports :lang() from CSS Selectors 3, which only accepts a
|
// Gecko supports :lang() from CSS Selectors 3, which only accepts a
|
||||||
// single language tag, and which performs simple dash-prefix matching
|
// single language tag, and which performs simple dash-prefix matching
|
||||||
// on it.
|
// on it.
|
||||||
debug_assert!(
|
|
||||||
value.len() > 0 && value[value.len() - 1] == 0,
|
|
||||||
"expected value to be null terminated"
|
|
||||||
);
|
|
||||||
let override_lang_ptr = match &override_lang {
|
let override_lang_ptr = match &override_lang {
|
||||||
&Some(Some(ref atom)) => atom.as_ptr(),
|
&Some(Some(ref atom)) => atom.as_ptr(),
|
||||||
_ => ptr::null_mut(),
|
_ => ptr::null_mut(),
|
||||||
|
@ -1734,7 +1730,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
||||||
self.0,
|
self.0,
|
||||||
override_lang_ptr,
|
override_lang_ptr,
|
||||||
override_lang.is_some(),
|
override_lang.is_some(),
|
||||||
value.as_ptr(),
|
value.as_slice().as_ptr(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue