Update to selectors 0.8.2

This commit is contained in:
Simon Sapin 2016-07-15 10:24:10 +02:00
parent f419db834c
commit fdb2071b2d
28 changed files with 455 additions and 286 deletions

28
ports/cef/Cargo.lock generated
View file

@ -695,7 +695,7 @@ dependencies = [
"servo-fontconfig 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"simd 0.1.0 (git+https://github.com/huonw/simd)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (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)",
@ -851,7 +851,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (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.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (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)",
]
@ -1041,10 +1041,10 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1758,10 +1758,10 @@ dependencies = [
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"script_layout_interface 0.0.1",
"script_traits 0.0.1",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (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)",
@ -1795,8 +1795,8 @@ dependencies = [
"profile_traits 0.0.1",
"range 0.0.1",
"script_traits 0.0.1",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"util 0.0.1",
@ -1833,7 +1833,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.7.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1844,7 +1844,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.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -2058,7 +2058,7 @@ dependencies = [
[[package]]
name = "string_cache"
version = "0.2.21"
version = "0.2.22"
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)",
@ -2093,11 +2093,11 @@ dependencies = [
"plugins 0.0.1",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_macros 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (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.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2560,7 +2560,7 @@ dependencies = [
"phf 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_codegen 0.7.16 (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.21 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (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

@ -6,12 +6,12 @@ dependencies = [
"env_logger 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"gecko_string_cache 0.2.20",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1",
"style_traits 0.0.1",
"url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -56,6 +56,14 @@ dependencies = [
"matches 0.1.2 (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"
@ -154,6 +162,18 @@ dependencies = [
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "gecko_string_cache"
version = "0.2.20"
dependencies = [
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getopts"
version = "0.2.14"
@ -263,6 +283,20 @@ dependencies = [
"unreachable 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "phf_generator"
version = "0.7.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"phf_shared 0.7.16 (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.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quickersort"
version = "2.0.1"
@ -304,7 +338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "selectors"
version = "0.7.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -313,7 +347,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.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -328,21 +362,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "string_cache"
version = "0.2.20"
version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"debug_unreachable 0.1.1 (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.16 (registry+https://github.com/rust-lang/crates.io-index)",
"phf_shared 0.7.16 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "string_cache"
version = "0.2.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
replace = "string_cache 0.2.20"
[[package]]
name = "style"
version = "0.0.1"
@ -355,6 +384,7 @@ dependencies = [
"euclid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"gecko_bindings 0.0.1",
"gecko_string_cache 0.2.20",
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
@ -364,9 +394,8 @@ dependencies = [
"ordered-float 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"string_cache 0.2.20 (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.1 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -14,16 +14,13 @@ app_units = "0.2.5"
env_logger = "0.3"
euclid = "0.7.1"
gecko_bindings = {version = "0.0.1", path = "gecko_bindings"}
gecko_string_cache = {path = "string_cache"}
lazy_static = "0.2"
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
num_cpus = "0.2.2"
selectors = "0.7"
string_cache = {version = "0.2.20", features = ["unstable"]}
selectors = "0.8"
style = {path = "../../components/style", features = ["gecko"]}
style_traits = {path = "../../components/style_traits"}
url = "1.0.0"
util = {path = "../../components/util"}
[replace]
"string_cache:0.2.20" = {path = "string_cache"}

View file

@ -6,15 +6,12 @@ extern crate app_units;
extern crate env_logger;
extern crate euclid;
extern crate gecko_bindings;
#[macro_use]
extern crate lazy_static;
#[macro_use] extern crate gecko_string_cache;
#[macro_use] extern crate lazy_static;
extern crate libc;
#[macro_use]
extern crate log;
#[macro_use] extern crate log;
extern crate num_cpus;
extern crate selectors;
#[macro_use(atom, ns)]
extern crate string_cache;
extern crate style;
extern crate style_traits;
extern crate url;

View file

@ -4,11 +4,12 @@
use gecko_bindings::bindings;
use gecko_bindings::structs::ServoElementSnapshot;
use gecko_bindings::structs::ServoElementSnapshotFlags as Flags;
use gecko_string_cache::Atom;
use selectors::parser::AttrSelector;
use snapshot_helpers;
use string_cache::Atom;
use style::element_state::ElementState;
use style::restyle_hints::ElementSnapshot;
use style::selector_impl::TheSelectorImpl;
use wrapper::AttrSelectorHelpers;
// NB: This is sound, in some sense, because during computation of restyle hints
@ -34,9 +35,9 @@ impl GeckoElementSnapshot {
}
impl ::selectors::MatchAttr for GeckoElementSnapshot {
type AttrString = Atom;
type Impl = TheSelectorImpl;
fn match_attr_has(&self, attr: &AttrSelector) -> bool {
fn match_attr_has(&self, attr: &AttrSelector<TheSelectorImpl>) -> bool {
unsafe {
bindings::Gecko_SnapshotHasAttr(self.0,
attr.ns_or_null(),
@ -44,7 +45,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
}
}
fn match_attr_equals(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_equals(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrEquals(self.0,
attr.ns_or_null(),
@ -54,7 +55,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
}
}
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrEquals(self.0,
attr.ns_or_null(),
@ -63,7 +64,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
/* ignoreCase = */ true)
}
}
fn match_attr_includes(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_includes(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrIncludes(self.0,
attr.ns_or_null(),
@ -71,7 +72,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr())
}
}
fn match_attr_dash(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_dash(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrDashEquals(self.0,
attr.ns_or_null(),
@ -79,7 +80,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr())
}
}
fn match_attr_prefix(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_prefix(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrHasPrefix(self.0,
attr.ns_or_null(),
@ -87,7 +88,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr())
}
}
fn match_attr_substring(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_substring(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrHasSubstring(self.0,
attr.ns_or_null(),
@ -95,7 +96,7 @@ impl ::selectors::MatchAttr for GeckoElementSnapshot {
value.as_ptr())
}
}
fn match_attr_suffix(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_suffix(&self, attr: &AttrSelector<TheSelectorImpl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_SnapshotAttrHasSuffix(self.0,
attr.ns_or_null(),

View file

@ -5,8 +5,8 @@
//! Element an snapshot common logic.
use gecko_bindings::structs::nsIAtom;
use gecko_string_cache::Atom;
use std::{ptr, slice};
use string_cache::Atom;
pub type ClassOrClassList<T> = unsafe extern fn (T, *mut *mut nsIAtom, *mut *mut *mut nsIAtom) -> u32;

View file

@ -1,5 +1,5 @@
[package]
name = "string_cache"
name = "gecko_string_cache"
description = "A crate to allow using Gecko's nsIAtom as a replacement for string_cache."
version = "0.2.20"
authors = ["The Servo Project Developers"]
@ -7,17 +7,12 @@ license = "MPL-2.0"
publish = false
[lib]
name = "string_cache"
path = "lib.rs"
[features]
log-events = []
unstable = []
heap_size = []
[dependencies]
cfg-if = "0.1.0"
gecko_bindings = {version = "0.0.1", path = "../gecko_bindings"}
heapsize = "0.3.5"
libc = "0.2"
selectors = "0.8"
serde = "0.7.15"

View file

@ -1,8 +1,17 @@
use gecko_bindings::structs::nsIAtom;
use Atom;
use WeakAtom;
pub fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom { unsafe { Atom::from_static(ptr) } }
// 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 fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom {
Atom(ptr as *mut WeakAtom)
}
cfg_if! {
if #[cfg(not(target_env = "msvc"))] {

View file

@ -2,10 +2,11 @@
* 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/. */
#[macro_use]
#[macro_use] #[no_link]
extern crate cfg_if;
extern crate gecko_bindings;
extern crate heapsize;
extern crate selectors;
extern crate serde;
use gecko_bindings::bindings::Gecko_AddRefAtom;
@ -15,13 +16,15 @@ use gecko_bindings::bindings::Gecko_GetAtomAsUTF16;
use gecko_bindings::bindings::Gecko_ReleaseAtom;
use gecko_bindings::structs::nsIAtom;
use heapsize::HeapSizeOf;
use selectors::bloom::BloomHash;
use selectors::parser::FromCowStr;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::borrow::Cow;
use std::char;
use std::borrow::{Cow, Borrow};
use std::char::{self, DecodeUtf16};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::mem::transmute;
use std::iter::Cloned;
use std::mem;
use std::ops::Deref;
use std::slice;
@ -30,90 +33,88 @@ pub mod atom_macro;
#[macro_export]
macro_rules! ns {
() => { $crate::Namespace(atom!("")) };
() => { atom!("") }
}
pub type Namespace = Atom;
#[allow(non_snake_case)]
#[inline]
pub fn Namespace(atom: Atom) -> Atom {
atom
}
/// A strong reference to a Gecko atom.
#[derive(PartialEq, Eq)]
pub struct Atom(*mut nsIAtom);
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
pub struct Namespace(pub Atom);
pub struct Atom(*mut WeakAtom);
pub struct BorrowedAtom<'a> {
weak_ptr: *mut nsIAtom,
chain: PhantomData<&'a ()>,
}
/// An atom *without* a strong reference.
///
/// Only usable as `&'a WeakAtom`,
/// where `'a` is the lifetime of something that holds a strong reference to that atom.
pub struct WeakAtom(nsIAtom);
impl<'a> BorrowedAtom<'a> {
pub unsafe fn new(atom: *mut nsIAtom) -> Self {
BorrowedAtom {
weak_ptr: atom,
chain: PhantomData,
}
}
}
pub type BorrowedAtom<'a> = &'a WeakAtom;
impl<'a> Deref for BorrowedAtom<'a> {
type Target = Atom;
fn deref(&self) -> &Atom {
impl Deref for Atom {
type Target = WeakAtom;
#[inline]
fn deref(&self) -> &WeakAtom {
unsafe {
transmute(self)
&*self.0
}
}
}
impl<'a> PartialEq<Atom> for BorrowedAtom<'a> {
fn eq(&self, other: &Atom) -> bool {
self.weak_ptr == other.as_ptr()
impl Borrow<WeakAtom> for Atom {
#[inline]
fn borrow(&self) -> &WeakAtom {
self
}
}
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()
impl Eq for WeakAtom {}
impl PartialEq for WeakAtom {
#[inline]
fn eq(&self, other: &Self) -> bool {
let weak: *const WeakAtom = self;
let other: *const WeakAtom = other;
weak == other
}
}
unsafe impl Send for Atom {}
unsafe impl Sync for Atom {}
unsafe impl Sync for WeakAtom {}
impl WeakAtom {
#[inline]
pub unsafe fn new<'a>(atom: *mut nsIAtom) -> &'a mut Self {
&mut *(atom as *mut WeakAtom)
}
#[inline]
pub fn clone(&self) -> Atom {
Atom::from(self.as_ptr())
}
impl Atom {
pub fn get_hash(&self) -> u32 {
unsafe {
(*self.0).mHash
}
self.0.mHash
}
pub fn as_slice(&self) -> &[u16] {
unsafe {
let mut len = 0;
let ptr = Gecko_GetAtomAsUTF16(self.0, &mut len);
let ptr = Gecko_GetAtomAsUTF16(self.as_ptr(), &mut len);
slice::from_raw_parts(ptr, len as usize)
}
}
pub fn chars(&self) -> DecodeUtf16<Cloned<slice::Iter<u16>>> {
char::decode_utf16(self.as_slice().iter().cloned())
}
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
@ -124,7 +125,7 @@ impl Atom {
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)
Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
}
}
@ -132,29 +133,43 @@ impl Atom {
String::from_utf16(self.as_slice()).unwrap()
}
#[inline]
pub fn as_ptr(&self) -> *mut nsIAtom {
self.0
let const_ptr: *const nsIAtom = &self.0;
const_ptr as *mut nsIAtom
}
}
impl Atom {
pub unsafe fn with<F>(ptr: *mut nsIAtom, callback: &mut F) where F: FnMut(&Atom) {
callback(transmute(&ptr))
}
let atom = Atom(WeakAtom::new(ptr));
callback(&atom);
mem::forget(atom);
}
}
// 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 BloomHash for Atom {
#[inline]
fn bloom_hash(&self) -> u32 {
self.get_hash()
}
}
impl BloomHash for WeakAtom {
#[inline]
fn bloom_hash(&self) -> u32 {
self.get_hash()
}
}
impl Hash for Atom {
fn hash<H>(&self, state: &mut H)
where H: Hasher
{
fn hash<H>(&self, state: &mut H) where H: Hasher {
state.write_u32(self.get_hash());
}
}
impl Hash for WeakAtom {
fn hash<H>(&self, state: &mut H) where H: Hasher {
state.write_u32(self.get_hash());
}
}
@ -162,10 +177,7 @@ impl Hash for Atom {
impl Clone for Atom {
#[inline(always)]
fn clone(&self) -> Atom {
unsafe {
Gecko_AddRefAtom(self.0);
}
Atom(self.0)
Atom::from(self.as_ptr())
}
}
@ -173,18 +185,19 @@ impl Drop for Atom {
#[inline]
fn drop(&mut self) {
unsafe {
Gecko_ReleaseAtom(self.0);
Gecko_ReleaseAtom(self.as_ptr());
}
}
}
impl HeapSizeOf for Atom {
fn heap_size_of_children(&self) -> usize {
0
impl Default for Atom {
#[inline]
fn default() -> Self {
atom!("")
}
}
impl HeapSizeOf for Namespace {
impl HeapSizeOf for Atom {
fn heap_size_of_children(&self) -> usize {
0
}
@ -222,9 +235,11 @@ 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)
})
unsafe {
Atom(WeakAtom::new(
Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32)
))
}
}
}
@ -235,6 +250,13 @@ impl<'a> From<Cow<'a, str>> for Atom {
}
}
impl FromCowStr for Atom {
#[inline]
fn from_cow_str(string: Cow<str>) -> Atom {
Atom::from(&*string)
}
}
impl From<String> for Atom {
#[inline]
fn from(string: String) -> Atom {
@ -243,10 +265,11 @@ impl From<String> for Atom {
}
impl From<*mut nsIAtom> for Atom {
#[inline]
fn from(ptr: *mut nsIAtom) -> Atom {
unsafe {
Gecko_AddRefAtom(ptr);
Atom(ptr)
Atom(WeakAtom::new(ptr))
}
}
}

View file

@ -26,6 +26,7 @@ use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsEle
use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode};
use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO};
use gecko_bindings::structs::{nsIAtom, nsChangeHint, nsStyleContext};
use gecko_string_cache::{Atom, Namespace, WeakAtom};
use glue::GeckoDeclarationBlock;
use libc::uintptr_t;
use selectors::Element;
@ -37,7 +38,6 @@ use std::marker::PhantomData;
use std::ops::BitOr;
use std::ptr;
use std::sync::Arc;
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace};
use style::data::PrivateStyleData;
use style::dom::{OpaqueNode, PresentationalHintsSynthetizer};
use style::dom::{TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
@ -433,7 +433,7 @@ impl<'le> TElement for GeckoElement<'le> {
fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool {
unsafe {
bindings::Gecko_HasAttr(self.element,
namespace.0.as_ptr(),
namespace.as_ptr(),
attr.as_ptr())
}
}
@ -442,7 +442,7 @@ impl<'le> TElement for GeckoElement<'le> {
fn attr_equals(&self, namespace: &Namespace, attr: &Atom, val: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrEquals(self.element,
namespace.0.as_ptr(),
namespace.as_ptr(),
attr.as_ptr(),
val.as_ptr(),
/* ignoreCase = */ false)
@ -459,8 +459,6 @@ impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> {
}
impl<'le> ::selectors::Element for GeckoElement<'le> {
type Impl = GeckoSelectorImpl;
fn parent_element(&self) -> Option<Self> {
unsafe {
Gecko_GetParentElement(self.element).as_ref().map(|el| GeckoElement::from_ref(el))
@ -502,15 +500,15 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
false
}
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a> {
fn get_local_name(&self) -> &WeakAtom {
unsafe {
BorrowedAtom::new(Gecko_LocalName(self.element))
WeakAtom::new(Gecko_LocalName(self.element))
}
}
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a> {
fn get_namespace(&self) -> &WeakAtom {
unsafe {
BorrowedNamespace::new(Gecko_Namespace(self.element))
WeakAtom::new(Gecko_Namespace(self.element))
}
}
@ -575,11 +573,11 @@ pub trait AttrSelectorHelpers {
fn select_name(&self, is_html_element_in_html_document: bool) -> *mut nsIAtom;
}
impl AttrSelectorHelpers for AttrSelector {
impl AttrSelectorHelpers for AttrSelector<GeckoSelectorImpl> {
fn ns_or_null(&self) -> *mut nsIAtom {
match self.namespace {
NamespaceConstraint::Any => ptr::null_mut(),
NamespaceConstraint::Specific(ref ns) => ns.0.as_ptr(),
NamespaceConstraint::Specific(ref ns) => ns.as_ptr(),
}
}
@ -593,15 +591,16 @@ impl AttrSelectorHelpers for AttrSelector {
}
impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
type AttrString = Atom;
fn match_attr_has(&self, attr: &AttrSelector) -> bool {
type Impl = GeckoSelectorImpl;
fn match_attr_has(&self, attr: &AttrSelector<Self::Impl>) -> bool {
unsafe {
bindings::Gecko_HasAttr(self.element,
attr.ns_or_null(),
attr.select_name(self.is_html_element_in_html_document()))
}
}
fn match_attr_equals(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_equals(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrEquals(self.element,
attr.ns_or_null(),
@ -610,7 +609,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
/* ignoreCase = */ false)
}
}
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrEquals(self.element,
attr.ns_or_null(),
@ -619,7 +618,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
/* ignoreCase = */ false)
}
}
fn match_attr_includes(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_includes(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrIncludes(self.element,
attr.ns_or_null(),
@ -627,7 +626,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
value.as_ptr())
}
}
fn match_attr_dash(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_dash(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrDashEquals(self.element,
attr.ns_or_null(),
@ -635,7 +634,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
value.as_ptr())
}
}
fn match_attr_prefix(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_prefix(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrHasPrefix(self.element,
attr.ns_or_null(),
@ -643,7 +642,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
value.as_ptr())
}
}
fn match_attr_substring(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_substring(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrHasSubstring(self.element,
attr.ns_or_null(),
@ -651,7 +650,7 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
value.as_ptr())
}
}
fn match_attr_suffix(&self, attr: &AttrSelector, value: &Self::AttrString) -> bool {
fn match_attr_suffix(&self, attr: &AttrSelector<Self::Impl>, value: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrHasSuffix(self.element,
attr.ns_or_null(),