Skip to content
Permalink
Browse files

Stop using Gecko namespace ids in servo.

MozReview-Commit-ID: 2532dHCGPXW
  • Loading branch information
bholley committed Apr 6, 2018
1 parent 628aa6a commit 9b5354f9533c1a7392a206a30ba1d5faac6d5616
@@ -1596,9 +1596,6 @@ extern "C" {
extern "C" {
pub fn Gecko_AddPropertyToSet(arg1: nsCSSPropertyIDSetBorrowedMut, arg2: nsCSSPropertyID);
}
extern "C" {
pub fn Gecko_RegisterNamespace(ns: *mut nsAtom) -> i32;
}
extern "C" {
pub fn Gecko_Construct_Default_nsStyleFont(
ptr: *mut nsStyleFont,
}
#[repr(C)]
#[derive(Debug)]
pub struct nsStyleContentAttr {
pub mName: root::RefPtr<root::nsAtom>,
pub mNamespaceURL: root::RefPtr<root::nsAtom>,
}
#[test]
fn bindgen_test_layout_nsStyleContentAttr() {
assert_eq!(
::std::mem::size_of::<nsStyleContentAttr>(),
16usize,
concat!("Size of: ", stringify!(nsStyleContentAttr))
);
assert_eq!(
::std::mem::align_of::<nsStyleContentAttr>(),
8usize,
concat!("Alignment of ", stringify!(nsStyleContentAttr))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<nsStyleContentAttr>())).mName as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(nsStyleContentAttr),
"::",
stringify!(mName)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<nsStyleContentAttr>())).mNamespaceURL as *const _ as usize
},
8usize,
concat!(
"Offset of field: ",
stringify!(nsStyleContentAttr),
"::",
stringify!(mNamespaceURL)
)
);
}
#[repr(C)]
#[derive(Debug)]
pub struct nsStyleContentData {
pub mType: root::nsStyleContentType,
pub mContent: root::nsStyleContentData__bindgen_ty_1,
#[derive(Debug, Copy)]
pub struct nsStyleContentData__bindgen_ty_1 {
pub mString: root::__BindgenUnionField<*mut u16>,
pub mAttr: root::__BindgenUnionField<*mut root::nsStyleContentAttr>,
pub mImage: root::__BindgenUnionField<*mut root::nsStyleImageRequest>,
pub mCounters: root::__BindgenUnionField<*mut root::nsStyleContentData_CounterFunction>,
pub bindgen_union_field: u64,
stringify!(mString)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<nsStyleContentData__bindgen_ty_1>())).mAttr as *const _
as usize
},
0usize,
concat!(
"Offset of field: ",
stringify!(nsStyleContentData__bindgen_ty_1),
"::",
stringify!(mAttr)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<nsStyleContentData__bindgen_ty_1>())).mImage as *const _
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_4() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
concat!(
"Size of template specialization: ",
stringify!(root::RefPtr<root::nsAtom>)
)
);
assert_eq!(
::std::mem::align_of::<root::RefPtr<root::nsAtom>>(),
8usize,
concat!(
"Alignment of template specialization: ",
stringify!(root::RefPtr<root::nsAtom>)
)
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_5() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
concat!(
"Size of template specialization: ",
stringify!(root::RefPtr<root::nsAtom>)
)
);
assert_eq!(
::std::mem::align_of::<root::RefPtr<root::nsAtom>>(),
8usize,
concat!(
"Alignment of template specialization: ",
stringify!(root::RefPtr<root::nsAtom>)
)
);
}
#[test]
fn __bindgen_test_layout_nsTArray_open0_nsStyleContentData_close0_instantiation() {
assert_eq!(
::std::mem::size_of::<root::nsTArray<root::nsStyleContentData>>(),
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_4() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_6() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_5() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_7() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_6() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_8() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_7() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_9() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_8() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_10() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_9() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_11() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_10() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_12() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_11() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_13() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_12() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_14() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_13() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_15() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
);
}
#[test]
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_14() {
fn __bindgen_test_layout_RefPtr_open0_nsAtom_close0_instantiation_16() {
assert_eq!(
::std::mem::size_of::<root::RefPtr<root::nsAtom>>(),
8usize,
@@ -470,11 +470,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
}

fn default_namespace(&self) -> Option<Namespace> {
self.namespaces.default.clone().as_ref().map(|&(ref ns, _)| ns.clone())
self.namespaces.default.as_ref().map(|ns| ns.clone())
}

fn namespace_for_prefix(&self, prefix: &Atom) -> Option<Namespace> {
self.namespaces.prefixes.get(prefix).map(|&(ref ns, _)| ns.clone())
self.namespaces.prefixes.get(prefix).cloned()
}
}

@@ -55,6 +55,7 @@ use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarat
use rule_tree::StrongRuleNode;
use selector_parser::PseudoElement;
use servo_arc::{Arc, RawOffsetArc};
use std::marker::PhantomData;
use std::mem::{forget, uninitialized, transmute, zeroed};
use std::{cmp, ops, ptr};
use values::{self, CustomIdent, Either, KeyframesName, None_};
@@ -5429,6 +5430,7 @@ clip-path
use values::computed::counters::{Content, ContentItem};
use values::generics::CounterStyleOrNone;
use gecko_bindings::structs::nsStyleContentData;
use gecko_bindings::structs::nsStyleContentAttr;
use gecko_bindings::structs::nsStyleContentType;
use gecko_bindings::structs::nsStyleContentType::*;
use gecko_bindings::bindings::Gecko_ClearAndResizeStyleContents;
@@ -5505,14 +5507,19 @@ clip-path
self.gecko.mContents[i].mType = eStyleContentType_Attr;
unsafe {
// NB: we share allocators, so doing this is fine.
*self.gecko.mContents[i].mContent.mString.as_mut() = match attr.namespace {
Some((_, ns)) => {
as_utf16_and_forget(&format!("{}|{}", ns, attr.attribute))
let maybe_ns = attr.namespace.clone();
let attr_struct = Box::new(nsStyleContentAttr {
mName: structs::RefPtr {
mRawPtr: attr.attribute.clone().into_addrefed(),
_phantom_0: PhantomData,
},
None => {
as_utf16_and_forget(&attr.attribute)
}
};
mNamespaceURL: structs::RefPtr {
mRawPtr: maybe_ns.map_or(ptr::null_mut(), |x| (x.1).0.into_addrefed()),
_phantom_0: PhantomData,
},
});
*self.gecko.mContents[i].mContent.mAttr.as_mut() =
Box::into_raw(attr_struct);
}
}
ContentItem::OpenQuote
@@ -5569,7 +5576,7 @@ clip-path
}

pub fn clone_content(&self) -> longhands::content::computed_value::T {
use Atom;
use {Atom, Namespace};
use gecko::conversions::string_from_chars_pointer;
use gecko_bindings::structs::nsStyleContentType::*;
use values::computed::counters::{Content, ContentItem};
@@ -5600,19 +5607,17 @@ clip-path
ContentItem::String(string.into_boxed_str())
},
eStyleContentType_Attr => {
let gecko_chars = unsafe { gecko_content.mContent.mString.as_ref() };
let string = unsafe { string_from_chars_pointer(*gecko_chars) };
let (namespace, attribute) =
match string.find('|') {
None => (None, string),
Some(index) => {
let (_, val) = string.split_at(index);
// FIXME: We should give NamespaceId as well to make Attr
// struct. However, there is no field for it in Gecko.
debug_assert!(false, "Attr with namespace does not support yet");
(None, val.to_string())
}
let (namespace, attribute) = unsafe {
let s = &**gecko_content.mContent.mAttr.as_ref();
let ns = if s.mNamespaceURL.mRawPtr.is_null() {
None
} else {
// FIXME(bholley): We don't have any way to get the prefix here. :-(
let prefix = atom!("");
Some((prefix, Namespace(Atom::from_raw(s.mNamespaceURL.mRawPtr))))
};
(ns, Atom::from_raw(s.mName.mRawPtr))
};
ContentItem::Attr(Attr { namespace, attribute })
},
eStyleContentType_Counter | eStyleContentType_Counters => {
@@ -591,11 +591,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
}

fn default_namespace(&self) -> Option<Namespace> {
self.namespaces.default.as_ref().map(|&(ref ns, _)| ns.clone())
self.namespaces.default.as_ref().map(|ns| ns.clone())
}

fn namespace_for_prefix(&self, prefix: &Prefix) -> Option<Namespace> {
self.namespaces.prefixes.get(prefix).map(|&(ref ns, _)| ns.clone())
self.namespaces.prefixes.get(prefix).cloned()
}
}

@@ -137,20 +137,6 @@ pub enum AtRuleNonBlockPrelude {
Namespace(Option<Prefix>, Namespace, SourceLocation),
}


#[cfg(feature = "gecko")]
fn register_namespace(ns: &Namespace) -> i32 {
use gecko_bindings::bindings;
let id = unsafe { bindings::Gecko_RegisterNamespace(ns.0.as_ptr()) };
debug_assert!(id >= 0);
id
}

#[cfg(feature = "servo")]
fn register_namespace(_: &Namespace) {
// servo doesn't use namespace ids
}

impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a, R> {
type PreludeNoBlock = AtRuleNonBlockPrelude;
type PreludeBlock = AtRuleBlockPrelude;
@@ -242,15 +228,13 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
CssRule::Import(import_rule)
}
AtRuleNonBlockPrelude::Namespace(prefix, url, location) => {
let id = register_namespace(&url);

let opt_prefix = if let Some(prefix) = prefix {
self.namespaces
.prefixes
.insert(prefix.clone(), (url.clone(), id));
.insert(prefix.clone(), url.clone());
Some(prefix)
} else {
self.namespaces.default = Some((url.clone(), id));
self.namespaces.default = Some(url.clone());
None
};

@@ -23,7 +23,6 @@ use stylesheets::{CssRule, CssRules, Origin, UrlExtraData};
use stylesheets::loader::StylesheetLoader;
use stylesheets::rule_parser::{State, TopLevelRuleParser};
use stylesheets::rules_iterator::{EffectiveRules, EffectiveRulesIterator, NestedRuleIterationCondition, RulesIterator};
use values::specified::NamespaceId;

/// This structure holds the user-agent and user stylesheets.
pub struct UserAgentStylesheets {
@@ -41,8 +40,8 @@ pub struct UserAgentStylesheets {
#[derive(Clone, Debug, Default, MallocSizeOf)]
#[allow(missing_docs)]
pub struct Namespaces {
pub default: Option<(Namespace, NamespaceId)>,
pub prefixes: FnvHashMap<Prefix, (Namespace, NamespaceId)>,
pub default: Option<Namespace>,
pub prefixes: FnvHashMap<Prefix, Namespace>,
}

/// The contents of a given stylesheet. This effectively maps to a

0 comments on commit 9b5354f

Please sign in to comment.
You can’t perform that action at this time.