Skip to content

Commit

Permalink
Stop using Gecko namespace ids in servo.
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 2532dHCGPXW
  • Loading branch information
bholley committed Apr 6, 2018
1 parent 628aa6a commit 9b5354f
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 88 deletions.
3 changes: 0 additions & 3 deletions components/style/gecko/generated/bindings.rs
Expand Up @@ -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,
Expand Down
115 changes: 104 additions & 11 deletions components/style/gecko/generated/structs.rs
Expand Up @@ -26311,6 +26311,47 @@ pub mod root {
}
#[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,
Expand Down Expand Up @@ -26395,6 +26436,7 @@ pub mod root {
#[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,
Expand Down Expand Up @@ -26427,6 +26469,19 @@ pub mod root {
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 _
Expand Down Expand Up @@ -41719,6 +41774,44 @@ pub mod root {
);
}
#[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>>(),
Expand Down Expand Up @@ -41928,7 +42021,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -43679,7 +43772,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -44126,7 +44219,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -44255,7 +44348,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -46639,7 +46732,7 @@ pub mod root {
);
}
#[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,
Expand All @@ -46658,7 +46751,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -46905,7 +46998,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -46943,7 +47036,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -47518,7 +47611,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -48017,7 +48110,7 @@ pub mod root {
);
}
#[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,
Expand Down Expand Up @@ -48093,7 +48186,7 @@ pub mod root {
);
}
#[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,
Expand Down
4 changes: 2 additions & 2 deletions components/style/gecko/selector_parser.rs
Expand Up @@ -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()
}
}

Expand Down
45 changes: 25 additions & 20 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -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_};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions components/style/servo/selector_parser.rs
Expand Up @@ -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()
}
}

Expand Down
20 changes: 2 additions & 18 deletions components/style/stylesheets/rule_parser.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
};

Expand Down
5 changes: 2 additions & 3 deletions components/style/stylesheets/stylesheet.rs
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 9b5354f

Please sign in to comment.