mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Bring back the Namespace newtype.
This commit is contained in:
parent
fdb2071b2d
commit
cf05cd934d
4 changed files with 84 additions and 21 deletions
|
@ -6,7 +6,7 @@ use element_state::ElementState;
|
|||
use selector_impl::PseudoElementCascadeType;
|
||||
use selector_impl::{attr_exists_selector_is_shareable, attr_equals_selector_is_shareable};
|
||||
use selectors::parser::{ParserContext, SelectorImpl, AttrSelector};
|
||||
use string_cache::{Atom, WeakAtom};
|
||||
use string_cache::{Atom, WeakAtom, Namespace, WeakNamespace};
|
||||
use stylesheets::Stylesheet;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
@ -154,8 +154,8 @@ impl SelectorImpl for GeckoSelectorImpl {
|
|||
type Identifier = Atom;
|
||||
type ClassName = Atom;
|
||||
type LocalName = Atom;
|
||||
type Namespace = Atom;
|
||||
type BorrowedNamespace = WeakAtom;
|
||||
type Namespace = Namespace;
|
||||
type BorrowedNamespace = WeakNamespace;
|
||||
type BorrowedLocalName = WeakAtom;
|
||||
|
||||
type PseudoElement = PseudoElement;
|
||||
|
|
|
@ -30,19 +30,9 @@ use std::slice;
|
|||
|
||||
#[macro_use]
|
||||
pub mod atom_macro;
|
||||
pub mod namespace;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ns {
|
||||
() => { atom!("") }
|
||||
}
|
||||
|
||||
pub type Namespace = Atom;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[inline]
|
||||
pub fn Namespace(atom: Atom) -> Atom {
|
||||
atom
|
||||
}
|
||||
pub use namespace::{Namespace, WeakNamespace};
|
||||
|
||||
/// A strong reference to a Gecko atom.
|
||||
#[derive(PartialEq, Eq)]
|
||||
|
|
73
ports/geckolib/string_cache/namespace.rs
Normal file
73
ports/geckolib/string_cache/namespace.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* 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/. */
|
||||
|
||||
use gecko_bindings::structs::nsIAtom;
|
||||
use selectors::bloom::BloomHash;
|
||||
use std::borrow::Borrow;
|
||||
use std::ops::Deref;
|
||||
use {Atom, WeakAtom};
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! ns {
|
||||
() => { $crate::Namespace(atom!("")) }
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Default, Hash)]
|
||||
pub struct Namespace(pub Atom);
|
||||
pub struct WeakNamespace(WeakAtom);
|
||||
|
||||
impl Deref for Namespace {
|
||||
type Target = WeakNamespace;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &WeakNamespace {
|
||||
let weak: *const WeakAtom = &*self.0;
|
||||
unsafe {
|
||||
&*(weak as *const WeakNamespace)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Borrow<WeakNamespace> for Namespace {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &WeakNamespace {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl WeakNamespace {
|
||||
#[inline]
|
||||
pub unsafe fn new<'a>(atom: *mut nsIAtom) -> &'a Self {
|
||||
&*(atom as *const WeakNamespace)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn clone(&self) -> Namespace {
|
||||
Namespace(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for WeakNamespace {}
|
||||
impl PartialEq for WeakNamespace {
|
||||
#[inline]
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
let weak: *const WeakNamespace = self;
|
||||
let other: *const WeakNamespace = other;
|
||||
weak == other
|
||||
}
|
||||
}
|
||||
|
||||
impl BloomHash for Namespace {
|
||||
#[inline]
|
||||
fn bloom_hash(&self) -> u32 {
|
||||
self.0.get_hash()
|
||||
}
|
||||
}
|
||||
|
||||
impl BloomHash for WeakNamespace {
|
||||
#[inline]
|
||||
fn bloom_hash(&self) -> u32 {
|
||||
self.0.get_hash()
|
||||
}
|
||||
}
|
|
@ -26,7 +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 gecko_string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use glue::GeckoDeclarationBlock;
|
||||
use libc::uintptr_t;
|
||||
use selectors::Element;
|
||||
|
@ -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.as_ptr(),
|
||||
namespace.0.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.as_ptr(),
|
||||
namespace.0.as_ptr(),
|
||||
attr.as_ptr(),
|
||||
val.as_ptr(),
|
||||
/* ignoreCase = */ false)
|
||||
|
@ -506,9 +506,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_namespace(&self) -> &WeakAtom {
|
||||
fn get_namespace(&self) -> &WeakNamespace {
|
||||
unsafe {
|
||||
WeakAtom::new(Gecko_Namespace(self.element))
|
||||
WeakNamespace::new(Gecko_Namespace(self.element))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,7 +577,7 @@ 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.as_ptr(),
|
||||
NamespaceConstraint::Specific(ref ns) => ns.0.as_ptr(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue