mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
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:
commit
e3be7184fb
26 changed files with 5170 additions and 189 deletions
|
@ -133,11 +133,11 @@ struct FontCache {
|
|||
fn populate_generic_fonts() -> HashMap<FontFamily, LowercaseString> {
|
||||
let mut generic_fonts = HashMap::with_capacity(5);
|
||||
|
||||
append_map(&mut generic_fonts, FontFamily::Serif, "Times New Roman");
|
||||
append_map(&mut generic_fonts, FontFamily::SansSerif, SANS_SERIF_FONT_FAMILY);
|
||||
append_map(&mut generic_fonts, FontFamily::Cursive, "Apple Chancery");
|
||||
append_map(&mut generic_fonts, FontFamily::Fantasy, "Papyrus");
|
||||
append_map(&mut generic_fonts, FontFamily::Monospace, "Menlo");
|
||||
append_map(&mut generic_fonts, FontFamily::Generic(atom!("serif")), "Times New Roman");
|
||||
append_map(&mut generic_fonts, FontFamily::Generic(atom!("sans-serif")), SANS_SERIF_FONT_FAMILY);
|
||||
append_map(&mut generic_fonts, FontFamily::Generic(atom!("cursive")), "Apple Chancery");
|
||||
append_map(&mut generic_fonts, FontFamily::Generic(atom!("fantasy")), "Papyrus");
|
||||
append_map(&mut generic_fonts, FontFamily::Generic(atom!("monospace")), "Menlo");
|
||||
|
||||
fn append_map(generic_fonts: &mut HashMap<FontFamily, LowercaseString>,
|
||||
font_family: FontFamily,
|
||||
|
|
|
@ -72,6 +72,7 @@ extern crate simd;
|
|||
|
||||
extern crate skia;
|
||||
extern crate smallvec;
|
||||
#[macro_use]
|
||||
extern crate string_cache;
|
||||
extern crate style;
|
||||
extern crate style_traits;
|
||||
|
|
|
@ -32,7 +32,7 @@ range = {path = "../range"}
|
|||
rustc-serialize = "0.3"
|
||||
script = {path = "../script"}
|
||||
script_traits = {path = "../script_traits"}
|
||||
selectors = {version = "0.5.1", features = ["heap_size"]}
|
||||
selectors = {version = "0.6", features = ["heap_size"]}
|
||||
serde_json = "0.7"
|
||||
serde_macros = "0.7"
|
||||
smallvec = "0.1"
|
||||
|
|
|
@ -62,7 +62,7 @@ use std::cell::{Ref, RefCell, RefMut};
|
|||
use std::marker::PhantomData;
|
||||
use std::mem::{transmute, transmute_copy};
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace};
|
||||
use style::computed_values::content::ContentItem;
|
||||
use style::computed_values::{content, display};
|
||||
use style::dom::{PresentationalHintsSynthetizer, TDocument, TElement, TNode, UnsafeNode};
|
||||
|
@ -519,13 +519,13 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
self.element.local_name()
|
||||
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a> {
|
||||
BorrowedAtom(self.element.local_name())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_namespace(&self) -> &Namespace {
|
||||
self.element.namespace()
|
||||
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a> {
|
||||
BorrowedNamespace(self.element.namespace())
|
||||
}
|
||||
|
||||
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
|
||||
|
@ -737,8 +737,8 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + Sized + PartialEq {
|
|||
#[inline]
|
||||
fn get_details_summary_pseudo(&self) -> Option<Self> {
|
||||
if self.is_element() &&
|
||||
self.as_element().get_local_name() == &atom!("details") &&
|
||||
self.as_element().get_namespace() == &ns!(html) {
|
||||
self.as_element().get_local_name() == atom!("details") &&
|
||||
self.as_element().get_namespace() == ns!(html) {
|
||||
Some(self.with_pseudo(PseudoElementType::DetailsSummary(None)))
|
||||
} else {
|
||||
None
|
||||
|
@ -748,8 +748,8 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + Sized + PartialEq {
|
|||
#[inline]
|
||||
fn get_details_content_pseudo(&self) -> Option<Self> {
|
||||
if self.is_element() &&
|
||||
self.as_element().get_local_name() == &atom!("details") &&
|
||||
self.as_element().get_namespace() == &ns!(html) {
|
||||
self.as_element().get_local_name() == atom!("details") &&
|
||||
self.as_element().get_namespace() == ns!(html) {
|
||||
let display = if self.as_element().get_attr(&ns!(), &atom!("open")).is_some() {
|
||||
None // Specified by the stylesheet
|
||||
} else {
|
||||
|
@ -958,10 +958,10 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized +
|
|||
fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str>;
|
||||
|
||||
#[inline]
|
||||
fn get_local_name(&self) -> &Atom;
|
||||
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a>;
|
||||
|
||||
#[inline]
|
||||
fn get_namespace(&self) -> &Namespace;
|
||||
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a>;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
@ -1222,8 +1222,8 @@ impl<ConcreteNode> Iterator for ThreadSafeLayoutNodeChildrenIterator<ConcreteNod
|
|||
loop {
|
||||
let next_node = if let Some(ref node) = current_node {
|
||||
if node.is_element() &&
|
||||
node.as_element().get_local_name() == &atom!("summary") &&
|
||||
node.as_element().get_namespace() == &ns!(html) {
|
||||
node.as_element().get_local_name() == atom!("summary") &&
|
||||
node.as_element().get_namespace() == ns!(html) {
|
||||
self.current_node = None;
|
||||
return Some(node.clone());
|
||||
}
|
||||
|
@ -1240,8 +1240,8 @@ impl<ConcreteNode> Iterator for ThreadSafeLayoutNodeChildrenIterator<ConcreteNod
|
|||
let node = self.current_node.clone();
|
||||
let node = node.and_then(|node| {
|
||||
if node.is_element() &&
|
||||
node.as_element().get_local_name() == &atom!("summary") &&
|
||||
node.as_element().get_namespace() == &ns!(html) {
|
||||
node.as_element().get_local_name() == atom!("summary") &&
|
||||
node.as_element().get_namespace() == ns!(html) {
|
||||
unsafe { node.dangerous_next_sibling() }
|
||||
} else {
|
||||
Some(node)
|
||||
|
@ -1301,13 +1301,13 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
self.element.local_name()
|
||||
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a> {
|
||||
BorrowedAtom(self.element.local_name())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_namespace(&self) -> &Namespace {
|
||||
self.element.namespace()
|
||||
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a> {
|
||||
BorrowedNamespace(self.element.namespace())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1374,12 +1374,12 @@ impl <'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
fn get_local_name<'a>(&'a self) -> BorrowedAtom<'a> {
|
||||
ThreadSafeLayoutElement::get_local_name(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_namespace(&self) -> &Namespace {
|
||||
fn get_namespace<'a>(&'a self) -> BorrowedNamespace<'a> {
|
||||
ThreadSafeLayoutElement::get_namespace(self)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ ref_slice = "1.0"
|
|||
regex = "0.1.43"
|
||||
rustc-serialize = "0.3"
|
||||
script_traits = {path = "../script_traits"}
|
||||
selectors = {version = "0.5", features = ["heap_size"]}
|
||||
selectors = {version = "0.6", features = ["heap_size"]}
|
||||
serde = "0.7"
|
||||
smallvec = "0.1"
|
||||
string_cache = {version = "0.2.12", features = ["heap_size", "unstable"]}
|
||||
|
|
|
@ -83,7 +83,7 @@ use std::default::Default;
|
|||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use string_cache::{Atom, Namespace, QualName};
|
||||
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace, QualName};
|
||||
use style::element_state::*;
|
||||
use style::properties::DeclaredValue;
|
||||
use style::properties::longhands::{self, background_image, border_spacing, font_family, overflow_x, font_size};
|
||||
|
@ -2131,12 +2131,12 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
self.local_name()
|
||||
fn get_local_name(&self) -> BorrowedAtom {
|
||||
BorrowedAtom(self.local_name())
|
||||
}
|
||||
|
||||
fn get_namespace(&self) -> &Namespace {
|
||||
self.namespace()
|
||||
fn get_namespace(&self) -> BorrowedNamespace {
|
||||
BorrowedNamespace(self.namespace())
|
||||
}
|
||||
|
||||
fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool {
|
||||
|
|
30
components/servo/Cargo.lock
generated
30
components/servo/Cargo.lock
generated
|
@ -771,7 +771,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)",
|
||||
|
@ -946,7 +946,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)",
|
||||
]
|
||||
|
@ -1140,11 +1140,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)",
|
||||
|
@ -1880,10 +1880,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)",
|
||||
|
@ -1935,7 +1935,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)",
|
||||
|
@ -1946,7 +1946,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]]
|
||||
|
@ -2108,7 +2108,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)",
|
||||
|
@ -2138,11 +2138,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)",
|
||||
|
@ -2158,8 +2158,8 @@ dependencies = [
|
|||
"cssparser 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.6.6 (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.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.6.0 (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",
|
||||
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -2374,7 +2374,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)",
|
||||
]
|
||||
|
||||
|
@ -2605,7 +2605,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)",
|
||||
]
|
||||
|
|
|
@ -28,7 +28,7 @@ matches = "0.1"
|
|||
num-traits = "0.1.32"
|
||||
plugins = {path = "../plugins"}
|
||||
rustc-serialize = "0.3"
|
||||
selectors = {version = "0.5", features = ["heap_size", "unstable"]}
|
||||
selectors = {version = "0.6", features = ["heap_size", "unstable"]}
|
||||
serde = {version = "0.7", features = ["nightly"]}
|
||||
serde_macros = "0.7"
|
||||
smallvec = "0.1"
|
||||
|
|
|
@ -7,12 +7,11 @@ use cssparser::{self, Color, RGBA};
|
|||
use euclid::num::Zero;
|
||||
use num_traits::ToPrimitive;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use url::Url;
|
||||
use util::str::{DOMString, LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS};
|
||||
use util::str::{read_exponent, read_fraction, read_numbers, split_html_space_chars, str_join};
|
||||
use util::str::{read_exponent, read_fraction, read_numbers, split_html_space_chars};
|
||||
use values::specified::{Length};
|
||||
|
||||
// Duplicated from script::dom::values.
|
||||
|
@ -125,7 +124,9 @@ impl AttrValue {
|
|||
AttrValue::TokenList(tokens, atoms)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
||||
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
|
||||
use util::str::str_join;
|
||||
// TODO(ajeffrey): effecient conversion of Vec<Atom> to DOMString
|
||||
let tokens = DOMString::from(str_join(&atoms, "\x20"));
|
||||
AttrValue::TokenList(tokens, atoms)
|
||||
|
@ -293,7 +294,8 @@ impl AttrValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl Deref for AttrValue {
|
||||
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
||||
impl ::std::ops::Deref for AttrValue {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &str {
|
||||
|
|
|
@ -616,8 +616,8 @@ pub trait MatchMethods : TNode {
|
|||
fn insert_into_bloom_filter(&self, bf: &mut BloomFilter) {
|
||||
// Only elements are interesting.
|
||||
if let Some(element) = self.as_element() {
|
||||
bf.insert(element.get_local_name());
|
||||
bf.insert(element.get_namespace());
|
||||
bf.insert(&*element.get_local_name());
|
||||
bf.insert(&*element.get_namespace());
|
||||
element.get_id().map(|id| bf.insert(&id));
|
||||
|
||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||
|
@ -630,8 +630,8 @@ pub trait MatchMethods : TNode {
|
|||
fn remove_from_bloom_filter(&self, bf: &mut BloomFilter) {
|
||||
// Only elements are interesting.
|
||||
if let Some(element) = self.as_element() {
|
||||
bf.remove(element.get_local_name());
|
||||
bf.remove(element.get_namespace());
|
||||
bf.remove(&*element.get_local_name());
|
||||
bf.remove(&*element.get_namespace());
|
||||
element.get_id().map(|id| bf.remove(&id));
|
||||
|
||||
// TODO: case-sensitivity depends on the document type and quirks mode
|
||||
|
|
|
@ -13,12 +13,6 @@
|
|||
use values::computed::ComputedValueAsSpecified;
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
|
||||
const SERIF: &'static str = "serif";
|
||||
const SANS_SERIF: &'static str = "sans-serif";
|
||||
const CURSIVE: &'static str = "cursive";
|
||||
const FANTASY: &'static str = "fantasy";
|
||||
const MONOSPACE: &'static str = "monospace";
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
pub mod computed_value {
|
||||
use cssparser::ToCss;
|
||||
|
@ -28,45 +22,44 @@
|
|||
#[derive(Debug, PartialEq, Eq, Clone, Hash, HeapSizeOf, Deserialize, Serialize)]
|
||||
pub enum FontFamily {
|
||||
FamilyName(Atom),
|
||||
// Generic,
|
||||
Serif,
|
||||
SansSerif,
|
||||
Cursive,
|
||||
Fantasy,
|
||||
Monospace,
|
||||
Generic(Atom),
|
||||
}
|
||||
impl FontFamily {
|
||||
|
||||
#[inline]
|
||||
pub fn name(&self) -> &str {
|
||||
pub fn atom(&self) -> &Atom {
|
||||
match *self {
|
||||
FontFamily::FamilyName(ref name) => &*name,
|
||||
FontFamily::Serif => super::SERIF,
|
||||
FontFamily::SansSerif => super::SANS_SERIF,
|
||||
FontFamily::Cursive => super::CURSIVE,
|
||||
FontFamily::Fantasy => super::FANTASY,
|
||||
FontFamily::Monospace => super::MONOSPACE
|
||||
FontFamily::FamilyName(ref name) => name,
|
||||
FontFamily::Generic(ref name) => name,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
||||
pub fn name(&self) -> &str {
|
||||
self.atom()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
||||
pub fn from_atom(input: Atom) -> FontFamily {
|
||||
let option = match_ignore_ascii_case! { &input,
|
||||
super::SERIF => Some(FontFamily::Serif),
|
||||
super::SANS_SERIF => Some(FontFamily::SansSerif),
|
||||
super::CURSIVE => Some(FontFamily::Cursive),
|
||||
super::FANTASY => Some(FontFamily::Fantasy),
|
||||
super::MONOSPACE => Some(FontFamily::Monospace),
|
||||
&atom!("serif") => Some(atom!("serif")),
|
||||
&atom!("sans-serif") => Some(atom!("sans-serif")),
|
||||
&atom!("cursive") => Some(atom!("cursive")),
|
||||
&atom!("fantasy") => Some(atom!("fantasy")),
|
||||
&atom!("monospace") => Some(atom!("monospace")),
|
||||
_ => None
|
||||
};
|
||||
|
||||
match option {
|
||||
Some(family) => family,
|
||||
Some(family) => FontFamily::Generic(family),
|
||||
None => FontFamily::FamilyName(input)
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ToCss for FontFamily {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
dest.write_str(self.name())
|
||||
self.atom().with_str(|s| dest.write_str(s))
|
||||
}
|
||||
}
|
||||
impl ToCss for T {
|
||||
|
@ -86,7 +79,7 @@
|
|||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(vec![FontFamily::Serif])
|
||||
computed_value::T(vec![FontFamily::Generic(atom!("serif"))])
|
||||
}
|
||||
/// <family-name>#
|
||||
/// <family-name> = <string> | [ <ident>+ ]
|
||||
|
@ -100,14 +93,18 @@
|
|||
}
|
||||
let first_ident = try!(input.expect_ident());
|
||||
|
||||
match_ignore_ascii_case! { first_ident,
|
||||
SERIF => return Ok(FontFamily::Serif),
|
||||
SANS_SERIF => return Ok(FontFamily::SansSerif),
|
||||
CURSIVE => return Ok(FontFamily::Cursive),
|
||||
FANTASY => return Ok(FontFamily::Fantasy),
|
||||
MONOSPACE => return Ok(FontFamily::Monospace),
|
||||
// FIXME(bholley): The fast thing to do here would be to look up the
|
||||
// string (as lowercase) in the static atoms table. We don't have an
|
||||
// API to do that yet though, so we do the simple thing for now.
|
||||
match &first_ident[..] {
|
||||
s if atom!("serif").eq_str_ignore_ascii_case(s) => return Ok(FontFamily::Generic(atom!("serif"))),
|
||||
s if atom!("sans-serif").eq_str_ignore_ascii_case(s) => return Ok(FontFamily::Generic(atom!("sans-serif"))),
|
||||
s if atom!("cursive").eq_str_ignore_ascii_case(s) => return Ok(FontFamily::Generic(atom!("cursive"))),
|
||||
s if atom!("fantasy").eq_str_ignore_ascii_case(s) => return Ok(FontFamily::Generic(atom!("fantasy"))),
|
||||
s if atom!("monospace").eq_str_ignore_ascii_case(s) => return Ok(FontFamily::Generic(atom!("monospace"))),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut value = first_ident.into_owned();
|
||||
while let Ok(ident) = input.try(|input| input.expect_ident()) {
|
||||
value.push_str(" ");
|
||||
|
|
|
@ -478,7 +478,7 @@ impl PartialEq<str> for PropertyDeclarationName {
|
|||
match *self {
|
||||
PropertyDeclarationName::Longhand(n) => n == other,
|
||||
PropertyDeclarationName::Custom(ref n) => {
|
||||
::custom_properties::parse_name(other) == Ok(&**n)
|
||||
n.with_str(|s| ::custom_properties::parse_name(other) == Ok(s))
|
||||
}
|
||||
PropertyDeclarationName::Internal => false,
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ impl fmt::Display for PropertyDeclarationName {
|
|||
PropertyDeclarationName::Longhand(n) => f.write_str(n),
|
||||
PropertyDeclarationName::Custom(ref n) => {
|
||||
try!(f.write_str("--"));
|
||||
f.write_str(n)
|
||||
n.with_str(|s| f.write_str(s))
|
||||
}
|
||||
PropertyDeclarationName::Internal => Ok(()),
|
||||
}
|
||||
|
@ -575,7 +575,7 @@ impl PropertyDeclaration {
|
|||
% endif
|
||||
% endfor
|
||||
PropertyDeclaration::Custom(ref declaration_name, _) => {
|
||||
::custom_properties::parse_name(name) == Ok(&**declaration_name)
|
||||
declaration_name.with_str(|s| ::custom_properties::parse_name(name) == Ok(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ use element_state::*;
|
|||
use selector_impl::SelectorImplExt;
|
||||
use selectors::Element;
|
||||
use selectors::matching::matches_compound_selector;
|
||||
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, NamespaceConstraint, SelectorImpl, SimpleSelector};
|
||||
use selectors::parser::{AttrSelector, Combinator, CompoundSelector, SelectorImpl, SimpleSelector};
|
||||
use std::clone::Clone;
|
||||
use std::sync::Arc;
|
||||
use string_cache::{Atom, Namespace};
|
||||
use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace};
|
||||
|
||||
/// When the ElementState of an element (like IN_HOVER_STATE) changes, certain
|
||||
/// pseudo-classes (like :hover) may require us to restyle that element, its
|
||||
|
@ -133,10 +133,10 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
fn is_html_element_in_html_document(&self) -> bool {
|
||||
self.element.is_html_element_in_html_document()
|
||||
}
|
||||
fn get_local_name(&self) -> &Atom {
|
||||
fn get_local_name(&self) -> BorrowedAtom {
|
||||
self.element.get_local_name()
|
||||
}
|
||||
fn get_namespace(&self) -> &Namespace {
|
||||
fn get_namespace(&self) -> BorrowedNamespace {
|
||||
self.element.get_namespace()
|
||||
}
|
||||
fn get_id(&self) -> Option<Atom> {
|
||||
|
@ -152,8 +152,15 @@ impl<'a, E> Element for ElementWrapper<'a, E>
|
|||
None => self.element.has_class(name),
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
fn match_attr<F>(&self, _: &AttrSelector, _: F) -> bool
|
||||
where F: Fn(&str) -> bool {
|
||||
panic!("Gecko can't borrow atoms as UTF-8.");
|
||||
}
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
fn match_attr<F>(&self, attr: &AttrSelector, test: F) -> bool
|
||||
where F: Fn(&str) -> bool {
|
||||
use selectors::parser::NamespaceConstraint;
|
||||
match self.snapshot.attrs {
|
||||
Some(_) => {
|
||||
let html = self.is_html_element_in_html_document();
|
||||
|
|
|
@ -80,7 +80,7 @@ pub fn breakpoint() {
|
|||
|
||||
// Workaround for lack of `ptr_eq` on Arcs...
|
||||
#[inline]
|
||||
pub fn arc_ptr_eq<T: 'static + Send + Sync>(a: &Arc<T>, b: &Arc<T>) -> bool {
|
||||
pub fn arc_ptr_eq<T: 'static>(a: &Arc<T>, b: &Arc<T>) -> bool {
|
||||
let a: &T = &**a;
|
||||
let b: &T = &**b;
|
||||
(a as *const T) == (b as *const T)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue