mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Port element traits to use atoms instead of strings.
This commit is contained in:
parent
3670ee6f1f
commit
33dcb08f02
5 changed files with 15 additions and 15 deletions
|
@ -12,6 +12,7 @@ use util::{LayoutDataAccess, LayoutDataWrapper};
|
||||||
use wrapper::{LayoutElement, LayoutNode, PostorderNodeMutTraversal, ThreadSafeLayoutNode};
|
use wrapper::{LayoutElement, LayoutNode, PostorderNodeMutTraversal, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
use gfx::font_context::FontContext;
|
use gfx::font_context::FontContext;
|
||||||
|
use servo_util::atom::Atom;
|
||||||
use servo_util::cache::{Cache, LRUCache, SimpleHashCache};
|
use servo_util::cache::{Cache, LRUCache, SimpleHashCache};
|
||||||
use servo_util::namespace::Null;
|
use servo_util::namespace::Null;
|
||||||
use servo_util::smallvec::{SmallVec, SmallVec16};
|
use servo_util::smallvec::{SmallVec, SmallVec16};
|
||||||
|
@ -162,10 +163,7 @@ pub struct StyleSharingCandidateCache {
|
||||||
pub struct StyleSharingCandidate {
|
pub struct StyleSharingCandidate {
|
||||||
pub style: Arc<ComputedValues>,
|
pub style: Arc<ComputedValues>,
|
||||||
pub parent_style: Arc<ComputedValues>,
|
pub parent_style: Arc<ComputedValues>,
|
||||||
|
pub local_name: Atom,
|
||||||
// TODO(pcwalton): Intern.
|
|
||||||
pub local_name: DOMString,
|
|
||||||
|
|
||||||
pub class: Option<DOMString>,
|
pub class: Option<DOMString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,14 +222,14 @@ impl StyleSharingCandidate {
|
||||||
Some(StyleSharingCandidate {
|
Some(StyleSharingCandidate {
|
||||||
style: style.take_unwrap(),
|
style: style.take_unwrap(),
|
||||||
parent_style: parent_style.take_unwrap(),
|
parent_style: parent_style.take_unwrap(),
|
||||||
local_name: element.get_local_name().to_str(),
|
local_name: element.get_local_name().clone(),
|
||||||
class: element.get_attr(&Null, "class")
|
class: element.get_attr(&Null, "class")
|
||||||
.map(|string| string.to_str()),
|
.map(|string| string.to_str()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_share_style_with(&self, element: &LayoutElement) -> bool {
|
fn can_share_style_with(&self, element: &LayoutElement) -> bool {
|
||||||
if element.get_local_name() != self.local_name.as_slice() {
|
if *element.get_local_name() != self.local_name {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
match (&self.class, element.get_attr(&Null, "class")) {
|
match (&self.class, element.get_attr(&Null, "class")) {
|
||||||
|
|
|
@ -47,6 +47,7 @@ use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, Node, NodeTypeId}
|
||||||
use script::dom::node::{LayoutNodeHelpers, RawLayoutNodeHelpers, TextNodeTypeId};
|
use script::dom::node::{LayoutNodeHelpers, RawLayoutNodeHelpers, TextNodeTypeId};
|
||||||
use script::dom::text::Text;
|
use script::dom::text::Text;
|
||||||
use servo_msg::constellation_msg::{PipelineId, SubpageId};
|
use servo_msg::constellation_msg::{PipelineId, SubpageId};
|
||||||
|
use servo_util::atom::Atom;
|
||||||
use servo_util::namespace::Namespace;
|
use servo_util::namespace::Namespace;
|
||||||
use servo_util::namespace;
|
use servo_util::namespace;
|
||||||
use servo_util::str::is_whitespace;
|
use servo_util::str::is_whitespace;
|
||||||
|
@ -359,8 +360,8 @@ impl<'le> LayoutElement<'le> {
|
||||||
|
|
||||||
impl<'le> TElement for LayoutElement<'le> {
|
impl<'le> TElement for LayoutElement<'le> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_local_name<'a>(&'a self) -> &'a str {
|
fn get_local_name<'a>(&'a self) -> &'a Atom {
|
||||||
self.element.local_name.as_slice()
|
&self.element.local_name
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -201,7 +201,7 @@ impl LayoutElementHelpers for JS<Element> {
|
||||||
|
|
||||||
pub trait ElementHelpers {
|
pub trait ElementHelpers {
|
||||||
fn html_element_in_html_document(&self) -> bool;
|
fn html_element_in_html_document(&self) -> bool;
|
||||||
fn get_local_name<'a>(&'a self) -> &'a str;
|
fn get_local_name<'a>(&'a self) -> &'a Atom;
|
||||||
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +212,8 @@ impl<'a> ElementHelpers for JSRef<'a, Element> {
|
||||||
is_html && node.owner_doc().root().is_html_document
|
is_html && node.owner_doc().root().is_html_document
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_local_name<'a>(&'a self) -> &'a str {
|
fn get_local_name<'a>(&'a self) -> &'a Atom {
|
||||||
self.deref().local_name.as_slice()
|
&self.deref().local_name
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_namespace<'a>(&'a self) -> &'a Namespace {
|
fn get_namespace<'a>(&'a self) -> &'a Namespace {
|
||||||
|
@ -912,7 +912,7 @@ impl<'a> style::TElement for JSRef<'a, Element> {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_local_name<'a>(&'a self) -> &'a str {
|
fn get_local_name<'a>(&'a self) -> &'a Atom {
|
||||||
(self as &ElementHelpers).get_local_name()
|
(self as &ElementHelpers).get_local_name()
|
||||||
}
|
}
|
||||||
fn get_namespace<'a>(&'a self) -> &'a Namespace {
|
fn get_namespace<'a>(&'a self) -> &'a Namespace {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! style.
|
//! style.
|
||||||
|
|
||||||
use selectors::AttrSelector;
|
use selectors::AttrSelector;
|
||||||
|
use servo_util::atom::Atom;
|
||||||
use servo_util::namespace::Namespace;
|
use servo_util::namespace::Namespace;
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ pub trait TNode<E:TElement> : Clone {
|
||||||
pub trait TElement {
|
pub trait TElement {
|
||||||
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str>;
|
fn get_attr(&self, namespace: &Namespace, attr: &str) -> Option<&'static str>;
|
||||||
fn get_link(&self) -> Option<&'static str>;
|
fn get_link(&self) -> Option<&'static str>;
|
||||||
fn get_local_name<'a>(&'a self) -> &'a str;
|
fn get_local_name<'a>(&'a self) -> &'a Atom;
|
||||||
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
fn get_namespace<'a>(&'a self) -> &'a Namespace;
|
||||||
fn get_hover_state(&self) -> bool;
|
fn get_hover_state(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl SelectorMap {
|
||||||
// TODO(pradeep): Case-sensitivity depends on the document type.
|
// TODO(pradeep): Case-sensitivity depends on the document type.
|
||||||
SelectorMap::get_matching_rules_from_hash_ignoring_case(node,
|
SelectorMap::get_matching_rules_from_hash_ignoring_case(node,
|
||||||
&self.element_hash,
|
&self.element_hash,
|
||||||
element.get_local_name(),
|
element.get_local_name().as_slice(),
|
||||||
matching_rules_list,
|
matching_rules_list,
|
||||||
shareable);
|
shareable);
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ fn matches_simple_selector<E:TElement,
|
||||||
// TODO: intern element names
|
// TODO: intern element names
|
||||||
LocalNameSelector(ref name) => {
|
LocalNameSelector(ref name) => {
|
||||||
let element = element.as_element();
|
let element = element.as_element();
|
||||||
element.get_local_name().eq_ignore_ascii_case(name.as_slice())
|
element.get_local_name().as_slice().eq_ignore_ascii_case(name.as_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
NamespaceSelector(ref namespace) => {
|
NamespaceSelector(ref namespace) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue