Auto merge of #11242 - bholley:gecko_atoms, r=emilio

Add basic support for Gecko atoms

This is a rough initial implementation of gecko atoms. This allows us to get rid of the custom rust-selectors branch we use to build stylo.

The gecko changes are at https://bugzilla.mozilla.org/show_bug.cgi?id=1273771

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11242)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-05-18 11:35:28 -07:00
commit e3be7184fb
26 changed files with 5170 additions and 189 deletions

26
ports/cef/Cargo.lock generated
View file

@ -692,7 +692,7 @@ dependencies = [
"servo-skia 0.20130412.9 (registry+https://github.com/rust-lang/crates.io-index)",
"simd 0.1.0 (git+https://github.com/huonw/simd)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -858,7 +858,7 @@ dependencies = [
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1052,11 +1052,11 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1",
"script_traits 0.0.1",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1738,10 +1738,10 @@ dependencies = [
"regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"tinyfiledialogs 0.1.0 (git+https://github.com/jdm/tinyfiledialogs)",
@ -1782,7 +1782,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.5.9"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1793,7 +1793,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1992,7 +1992,7 @@ dependencies = [
[[package]]
name = "string_cache"
version = "0.2.15"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2022,11 +2022,11 @@ dependencies = [
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2242,7 +2242,7 @@ dependencies = [
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2466,7 +2466,7 @@ dependencies = [
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]

View file

@ -14,9 +14,9 @@ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@ -118,14 +118,6 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "debug_unreachable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "deque"
version = "0.3.1"
@ -324,20 +316,6 @@ dependencies = [
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_generator"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_shared 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_shared"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "plugins"
version = "0.0.1"
@ -407,7 +385,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "selectors"
version = "0.5.9"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -418,7 +396,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -451,18 +429,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "string_cache"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.2.16"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize_plugin 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_generator 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_shared 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "string_cache"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
replace = "string_cache 0.2.16"
[[package]]
name = "style"
version = "0.0.1"
@ -481,11 +461,11 @@ dependencies = [
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -603,7 +583,7 @@ dependencies = [
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View file

@ -20,12 +20,15 @@ heapsize_plugin = "0.1.2"
lazy_static = "0.2"
libc = "0.2"
num_cpus = "0.2.2"
selectors = "0.5"
selectors = "0.6"
smallvec = "0.1"
string_cache = "0.2.12"
string_cache = "0.2.16"
url = "1.0.0"
log = {version = "0.3.5", features = ["release_max_level_info"]}
plugins = {path = "../../components/plugins"}
util = {path = "../../components/util"}
style = {path = "../../components/style", features = ["gecko"]}
env_logger = "0.3"
[replace]
"string_cache:0.2.16" = {path = "string_cache"}

View file

@ -142,6 +142,20 @@ extern "C" {
pub fn Gecko_SetNodeData(node: *mut RawGeckoNode,
data: *mut ServoNodeData);
pub fn Servo_DropNodeData(data: *mut ServoNodeData);
pub fn Gecko_Atomize(aString: *const ::std::os::raw::c_char, aLength: u32)
-> *mut nsIAtom;
pub fn Gecko_AddRefAtom(aAtom: *mut nsIAtom);
pub fn Gecko_ReleaseAtom(aAtom: *mut nsIAtom);
pub fn Gecko_HashAtom(aAtom: *mut nsIAtom) -> u32;
pub fn Gecko_GetAtomAsUTF16(aAtom: *mut nsIAtom, aLength: *mut u32)
-> *const u16;
pub fn Gecko_AtomEqualsUTF8(aAtom: *mut nsIAtom,
aString: *const ::std::os::raw::c_char,
aLength: u32) -> bool;
pub fn Gecko_AtomEqualsUTF8IgnoreCase(aAtom: *mut nsIAtom,
aString:
*const ::std::os::raw::c_char,
aLength: u32) -> bool;
pub fn Gecko_SetListStyleType(style_struct: *mut nsStyleList, type_: u32);
pub fn Gecko_CopyListStyleTypeFrom(dst: *mut nsStyleList,
src: *const nsStyleList);
@ -181,18 +195,15 @@ extern "C" {
-> *mut ServoComputedValues;
pub fn Servo_AddRefComputedValues(arg1: *mut ServoComputedValues);
pub fn Servo_ReleaseComputedValues(arg1: *mut ServoComputedValues);
pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const u8, nslen: u32,
name: *const u8, namelen: u32, length: *mut u32)
-> *const ::std::os::raw::c_char;
pub fn Gecko_GetAtomAsUTF16(atom: *mut nsIAtom, length: *mut u32)
-> *const u16;
pub fn Gecko_LocalName(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Gecko_Namespace(element: *mut RawGeckoElement, length: *mut u32)
-> *const u16;
pub fn Servo_Initialize();
pub fn Servo_RestyleDocument(doc: *mut RawGeckoDocument,
set: *mut RawServoStyleSet);
pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement,
ns: *mut nsIAtom, name: *mut nsIAtom,
length: *mut u32)
-> *const ::std::os::raw::c_char;
pub fn Gecko_LocalName(element: *mut RawGeckoElement) -> *mut nsIAtom;
pub fn Gecko_Namespace(element: *mut RawGeckoElement) -> *mut nsIAtom;
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
other: *const nsStyleFont);

View file

@ -0,0 +1,21 @@
[package]
name = "string_cache"
description = "A crate to allow using Gecko's nsIAtom as a replacement for string_cache."
version = "0.2.16"
authors = ["The Servo Project Developers"]
publish = false
[lib]
name = "string_cache"
path = "lib.rs"
[features]
log-events = []
unstable = []
heap_size = []
[dependencies]
heapsize = "0.3.5"
libc = "0.2"
gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"}
serde = "0.7"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,228 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate gecko_bindings;
extern crate heapsize;
extern crate serde;
use gecko_bindings::bindings::Gecko_AddRefAtom;
use gecko_bindings::bindings::Gecko_AtomEqualsUTF8IgnoreCase;
use gecko_bindings::bindings::Gecko_Atomize;
use gecko_bindings::bindings::Gecko_GetAtomAsUTF16;
use gecko_bindings::bindings::Gecko_HashAtom;
use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::bindings::nsIAtom;
use heapsize::HeapSizeOf;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::mem::transmute;
use std::ops::Deref;
use std::slice;
#[macro_use]
pub mod atom_macro;
#[macro_export]
macro_rules! ns {
() => { $crate::Namespace(atom!("")) };
}
#[derive(PartialEq, Eq)]
pub struct Atom(*mut nsIAtom);
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
pub struct Namespace(pub Atom);
pub struct BorrowedAtom<'a> {
weak_ptr: *mut nsIAtom,
chain: PhantomData<&'a ()>,
}
impl<'a> BorrowedAtom<'a> {
pub unsafe fn new(atom: *mut nsIAtom) -> Self {
BorrowedAtom {
weak_ptr: atom,
chain: PhantomData,
}
}
}
impl<'a> Deref for BorrowedAtom<'a> {
type Target = Atom;
fn deref(&self) -> &Atom {
unsafe {
transmute(self)
}
}
}
impl<'a> PartialEq<Atom> for BorrowedAtom<'a> {
fn eq(&self, other: &Atom) -> bool {
self.weak_ptr == other.as_ptr()
}
}
pub struct BorrowedNamespace<'a> {
weak_ptr: *mut nsIAtom,
chain: PhantomData<&'a ()>,
}
impl<'a> BorrowedNamespace<'a> {
pub unsafe fn new(atom: *mut nsIAtom) -> Self {
BorrowedNamespace {
weak_ptr: atom,
chain: PhantomData,
}
}
}
impl<'a> Deref for BorrowedNamespace<'a> {
type Target = Namespace;
fn deref(&self) -> &Namespace {
unsafe {
transmute(self)
}
}
}
impl<'a> PartialEq<Namespace> for BorrowedNamespace<'a> {
fn eq(&self, other: &Namespace) -> bool {
self.weak_ptr == other.0.as_ptr()
}
}
unsafe impl Send for Atom {}
unsafe impl Sync for Atom {}
impl Atom {
pub fn get_hash(&self) -> u32 {
unsafe {
Gecko_HashAtom(self.0)
}
}
pub fn as_slice(&self) -> &[u16] {
unsafe {
let mut len = 0;
let ptr = Gecko_GetAtomAsUTF16(self.0, &mut len);
slice::from_raw_parts(ptr, len as usize)
}
}
pub fn with_str<F, Output>(&self, cb: F) -> Output
where F: FnOnce(&str) -> Output {
// FIXME(bholley): We should measure whether it makes more sense to
// cache the UTF-8 version in the Gecko atom table somehow.
let owned = String::from_utf16(self.as_slice()).unwrap();
cb(&owned)
}
pub fn eq_str_ignore_ascii_case(&self, s: &str) -> bool {
unsafe {
Gecko_AtomEqualsUTF8IgnoreCase(self.0, s.as_ptr() as *const _, s.len() as u32)
}
}
pub fn to_string(&self) -> String {
String::from_utf16(self.as_slice()).unwrap()
}
pub fn as_ptr(&self) -> *mut nsIAtom {
self.0
}
// Static atoms have a dummy AddRef/Release, so we don't bother calling
// AddRef() here. This would cause memory corruption with non-static atoms
// both because (a) we wouldn't hold the atom alive, and (b) we can't avoid
// calling Release() when the Atom is dropped, since we can't tell the
// difference between static and non-static atoms without bloating the
// size of Atom beyond word-size.
pub unsafe fn from_static(ptr: *mut nsIAtom) -> Atom {
Atom(ptr)
}
}
impl Hash for Atom {
fn hash<H>(&self, state: &mut H)
where H: Hasher
{
state.write_u32(self.get_hash());
}
}
impl Clone for Atom {
#[inline(always)]
fn clone(&self) -> Atom {
unsafe {
Gecko_AddRefAtom(self.0);
}
Atom(self.0)
}
}
impl Drop for Atom {
#[inline]
fn drop(&mut self) {
unsafe {
Gecko_ReleaseAtom(self.0);
}
}
}
impl HeapSizeOf for Atom {
fn heap_size_of_children(&self) -> usize {
0
}
}
impl HeapSizeOf for Namespace {
fn heap_size_of_children(&self) -> usize {
0
}
}
impl Serialize for Atom {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
self.with_str(|s| s.serialize(serializer))
}
}
impl Deserialize for Atom {
fn deserialize<D>(deserializer: &mut D) -> Result<Atom, D::Error> where D: Deserializer {
let string: String = try!(Deserialize::deserialize(deserializer));
Ok(Atom::from(&*string))
}
}
impl fmt::Debug for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "Gecko Atom {:p}", self.0)
}
}
impl<'a> From<&'a str> for Atom {
#[inline]
fn from(string: &str) -> Atom {
assert!(string.len() <= u32::max_value() as usize);
Atom(unsafe {
Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32)
})
}
}
impl<'a> From<Cow<'a, str>> for Atom {
#[inline]
fn from(string: Cow<'a, str>) -> Atom {
Atom::from(&*string)
}
}
impl From<String> for Atom {
#[inline]
fn from(string: String) -> Atom {
Atom::from(&*string)
}
}

View file

@ -0,0 +1,36 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import re
import sys
if len(sys.argv) != 2:
print "usage: ./%s PATH/TO/OBJDIR" % sys.argv[0]
objdir_path = sys.argv[1]
def line_to_atom(line):
result = re.match('^GK_ATOM\((.+),\s*"(.*)"\)', line)
return (result.group(1), result.group(2))
def symbolify(ident):
return "_ZN9nsGkAtoms" + str(len(ident)) + ident + "E"
with open(objdir_path + "/dist/include/nsGkAtomList.h") as f:
lines = [line for line in f.readlines() if line.startswith("GK_ATOM")]
atoms = [line_to_atom(line) for line in lines]
with open("atom_macro.rs", "w") as f:
f.write("use gecko_bindings::bindings::nsIAtom;\n\n")
f.write("use Atom;\n\n")
f.write("pub fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom { unsafe { Atom::from_static(ptr) } }\n\n")
for atom in atoms:
f.write('extern { pub static %s: *mut nsIAtom; }\n' % symbolify(atom[0]))
f.write("#[macro_export]\n")
f.write("macro_rules! atom {\n")
f.writelines(['("%s") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::%s) };\n'
% (atom[1], symbolify(atom[0])) for atom in atoms])
f.write("}\n")

View file

@ -31,7 +31,7 @@ use std::ops::BitOr;
use std::slice;
use std::str::from_utf8_unchecked;
use std::sync::Arc;
use string_cache::{Atom, Namespace};
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace};
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use style::element_state::ElementState;
@ -344,9 +344,8 @@ impl<'le> TElement for GeckoElement<'le> {
fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> {
unsafe {
let mut length: u32 = 0;
let ptr = Gecko_GetAttrAsUTF8(self.element,
namespace.0.as_ptr(), namespace.0.len() as u32,
name.as_ptr(), name.len() as u32, &mut length);
let ptr = Gecko_GetAttrAsUTF8(self.element, namespace.0.as_ptr(), name.as_ptr(),
&mut length);
reinterpret_string(ptr, length)
}
}
@ -408,26 +407,16 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
unimplemented!()
}
fn get_local_name(&self) -> &Atom {
panic!("Requires signature modification - only implemented in stylo branch");
/*
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a> {
unsafe {
let mut length: u32 = 0;
let p = Gecko_LocalName(self.element, &mut length);
Atom::from(String::from_utf16(slice::from_raw_parts(p, length as usize)).unwrap())
BorrowedAtom::new(Gecko_LocalName(self.element))
}
*/
}
fn get_namespace(&self) -> &Namespace {
panic!("Requires signature modification - only implemented in stylo branch");
/*
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a> {
unsafe {
let mut length: u32 = 0;
let p = Gecko_Namespace(self.element, &mut length);
Namespace(Atom::from(String::from_utf16(slice::from_raw_parts(p, length as usize)).unwrap()))
BorrowedNamespace::new(Gecko_Namespace(self.element))
}
*/
}
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {

26
ports/gonk/Cargo.lock generated
View file

@ -704,7 +704,7 @@ dependencies = [
"servo-skia 0.20130412.9 (registry+https://github.com/rust-lang/crates.io-index)",
"simd 0.1.0 (git+https://github.com/huonw/simd)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -850,7 +850,7 @@ dependencies = [
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1044,11 +1044,11 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script 0.0.1",
"script_traits 0.0.1",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1730,10 +1730,10 @@ dependencies = [
"regex 0.1.69 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_traits 0.0.1",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"tinyfiledialogs 0.1.0 (git+https://github.com/jdm/tinyfiledialogs)",
@ -1774,7 +1774,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.5.9"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1785,7 +1785,7 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"quickersort 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -1982,7 +1982,7 @@ dependencies = [
[[package]]
name = "string_cache"
version = "0.2.15"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2012,11 +2012,11 @@ dependencies = [
"num-traits 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
"plugins 0.0.1",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"style_traits 0.0.1",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2232,7 +2232,7 @@ dependencies = [
"serde 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2426,7 +2426,7 @@ dependencies = [
"phf 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)",
"tendril 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
]