Stop using Gecko namespace ids in servo.

MozReview-Commit-ID: 2532dHCGPXW
This commit is contained in:
Bobby Holley 2018-04-03 10:50:06 -07:00
parent 628aa6a630
commit 9b5354f953
10 changed files with 157 additions and 88 deletions

View file

@ -6,9 +6,9 @@
//!
//! TODO(emilio): Enhance docs.
use Prefix;
use {Atom, Namespace, Prefix};
use context::QuirksMode;
use cssparser::{Parser, Token, serialize_identifier};
use cssparser::{Parser, Token};
use num_traits::One;
use parser::{ParserContext, Parse};
use std::f32;
@ -685,24 +685,15 @@ impl AllowQuirks {
}
}
#[cfg(feature = "gecko")]
/// A namespace ID
pub type NamespaceId = i32;
#[cfg(feature = "servo")]
/// A namespace ID (used by gecko only)
pub type NamespaceId = ();
/// An attr(...) rule
///
/// `[namespace? `|`]? ident`
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
pub struct Attr {
/// Optional namespace prefix, with the actual namespace id.
pub namespace: Option<(Prefix, NamespaceId)>,
/// Optional namespace prefix and URL.
pub namespace: Option<(Prefix, Namespace)>,
/// Attribute name
pub attribute: String,
pub attribute: Atom,
}
impl Parse for Attr {
@ -712,9 +703,9 @@ impl Parse for Attr {
}
}
/// Get the Namespace id from the namespace map.
fn get_id_for_namespace(prefix: &Prefix, context: &ParserContext) -> Option<NamespaceId> {
Some(context.namespaces.as_ref()?.prefixes.get(prefix)?.1)
/// Get the Namespace for a given prefix from the namespace map.
fn get_namespace_for_prefix(prefix: &Prefix, context: &ParserContext) -> Option<Namespace> {
context.namespaces.as_ref()?.prefixes.get(prefix).map(|x| x.clone())
}
impl Attr {
@ -737,21 +728,21 @@ impl Attr {
ref t => return Err(location.new_unexpected_token_error(t.clone())),
};
let ns_with_id = if let Some(ns) = first {
let ns = Prefix::from(ns.as_ref());
let id = match get_id_for_namespace(&ns, context) {
Some(id) => id,
let prefix_and_ns = if let Some(ns) = first {
let prefix = Prefix::from(ns.as_ref());
let ns = match get_namespace_for_prefix(&prefix, context) {
Some(ns) => ns,
None => return Err(location.new_custom_error(
StyleParseErrorKind::UnspecifiedError
)),
};
Some((ns, id))
Some((prefix, ns))
} else {
None
};
return Ok(Attr {
namespace: ns_with_id,
attribute: second_token.as_ref().to_owned(),
namespace: prefix_and_ns,
attribute: Atom::from(second_token.as_ref()),
})
}
// In the case of attr(foobar ) we don't want to error out
@ -764,7 +755,7 @@ impl Attr {
if let Some(first) = first {
Ok(Attr {
namespace: None,
attribute: first.as_ref().to_owned(),
attribute: Atom::from(first.as_ref()),
})
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
@ -778,11 +769,11 @@ impl ToCss for Attr {
W: Write,
{
dest.write_str("attr(")?;
if let Some((ref prefix, _id)) = self.namespace {
if let Some((ref prefix, ref _url)) = self.namespace {
serialize_atom_identifier(prefix, dest)?;
dest.write_str("|")?;
}
serialize_identifier(&self.attribute, dest)?;
serialize_atom_identifier(&self.attribute, dest)?;
dest.write_str(")")
}
}