Update rust-selectors

Update for https://github.com/servo/rust-selectors/pull/37
This commit is contained in:
Simon Sapin 2015-07-17 18:18:39 +02:00
parent 0d7744b198
commit 055a1c5cee
18 changed files with 171 additions and 159 deletions

View file

@ -17,7 +17,7 @@ use wrapper::{LayoutElement, LayoutNode};
use script::dom::characterdata::CharacterDataTypeId;
use script::dom::node::NodeTypeId;
use script::layout_interface::Animation;
use selectors::{Node, Element};
use selectors::{Element};
use selectors::bloom::BloomFilter;
use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes};
use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
@ -222,18 +222,14 @@ impl StyleSharingCandidate {
/// Attempts to create a style sharing candidate from this node. Returns
/// the style sharing candidate or `None` if this node is ineligible for
/// style sharing.
fn new(node: &LayoutNode) -> Option<StyleSharingCandidate> {
let parent_node = match node.parent_node() {
fn new(element: &LayoutElement) -> Option<StyleSharingCandidate> {
let parent_element = match element.parent_element() {
None => return None,
Some(parent_node) => parent_node,
};
let element = match parent_node.as_element() {
Some(element) => element,
None => return None
Some(parent_element) => parent_element,
};
let style = unsafe {
match *node.borrow_layout_data_unchecked() {
match *element.as_node().borrow_layout_data_unchecked() {
None => return None,
Some(ref layout_data_ref) => {
match layout_data_ref.shared_data.style {
@ -244,7 +240,7 @@ impl StyleSharingCandidate {
}
};
let parent_style = unsafe {
match *parent_node.borrow_layout_data_unchecked() {
match *parent_element.as_node().borrow_layout_data_unchecked() {
None => return None,
Some(ref parent_layout_data_ref) => {
match parent_layout_data_ref.shared_data.style {
@ -357,8 +353,8 @@ impl StyleSharingCandidateCache {
self.cache.iter()
}
pub fn insert_if_possible(&mut self, node: &LayoutNode) {
match StyleSharingCandidate::new(node) {
pub fn insert_if_possible(&mut self, element: &LayoutElement) {
match StyleSharingCandidate::new(element) {
None => {}
Some(candidate) => self.cache.insert(candidate, ())
}
@ -395,7 +391,7 @@ pub trait MatchMethods {
fn match_node(&self,
stylist: &Stylist,
parent_bf: &Option<Box<BloomFilter>>,
parent_bf: Option<&BloomFilter>,
applicable_declarations: &mut ApplicableDeclarations,
shareable: &mut bool);
@ -540,7 +536,7 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
impl<'ln> MatchMethods for LayoutNode<'ln> {
fn match_node(&self,
stylist: &Stylist,
parent_bf: &Option<Box<BloomFilter>>,
parent_bf: Option<&BloomFilter>,
applicable_declarations: &mut ApplicableDeclarations,
shareable: &mut bool) {
let element = self.as_element().unwrap();

View file

@ -16,7 +16,6 @@ use wrapper::{layout_node_to_unsafe_layout_node, LayoutNode};
use wrapper::{ThreadSafeLayoutNode, UnsafeLayoutNode};
use selectors::bloom::BloomFilter;
use selectors::Node;
use util::opts;
use util::tid::tid;
@ -162,10 +161,7 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
let parent_opt = node.layout_parent_node(self.layout_context.shared);
// Get the style bloom filter.
let bf = take_task_local_bloom_filter(parent_opt, self.layout_context);
// Just needs to be wrapped in an option for `match_node`.
let some_bf = Some(bf);
let mut bf = take_task_local_bloom_filter(parent_opt, self.layout_context);
let nonincremental_layout = opts::get().nonincremental_layout;
if nonincremental_layout || node.is_dirty() {
@ -192,7 +188,7 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
// Perform the CSS selector matching.
let stylist = unsafe { &*self.layout_context.shared.stylist };
node.match_node(stylist,
&some_bf,
Some(&*bf),
&mut applicable_declarations,
&mut shareable);
} else if node.has_changed() {
@ -211,7 +207,9 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
// Add ourselves to the LRU cache.
if shareable {
style_sharing_candidate_cache.insert_if_possible(&node);
if let Some(element) = node.as_element() {
style_sharing_candidate_cache.insert_if_possible(&element);
}
}
}
StyleSharingResult::StyleWasShared(index, damage) => {
@ -221,8 +219,6 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
}
}
let mut bf = some_bf.unwrap();
let unsafe_layout_node = layout_node_to_unsafe_layout_node(&node);
// Before running the children, we need to insert our nodes into the bloom

View file

@ -67,7 +67,6 @@ use std::sync::mpsc::Sender;
use string_cache::{Atom, Namespace};
use style::computed_values::content::ContentItem;
use style::computed_values::{content, display, white_space};
use selectors::Node as SelectorsNode;
use selectors::matching::DeclarationBlock;
use selectors::parser::{NamespaceConstraint, AttrSelector};
use style::legacy::UnsignedIntegerAttribute;
@ -144,12 +143,6 @@ impl<'ln> LayoutNode<'ln> {
LayoutTreeIterator::new(self)
}
fn last_child(self) -> Option<LayoutNode<'ln>> {
unsafe {
self.get_jsmanaged().last_child_ref().map(|node| self.new_with_this_lifetime(&node))
}
}
/// Returns an iterator over this node's children.
pub fn children(self) -> LayoutNodeChildrenIterator<'ln> {
LayoutNodeChildrenIterator {
@ -209,10 +202,10 @@ impl<'ln> LayoutNode<'ln> {
pub fn debug_id(self) -> usize {
self.opaque().to_untrusted_node_address().0 as usize
}
}
impl<'ln> ::selectors::Node for LayoutNode<'ln> {
type Element = LayoutElement<'ln>;
pub fn as_element(&self) -> Option<LayoutElement<'ln>> {
as_element(self.node)
}
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
unsafe {
@ -243,34 +236,6 @@ impl<'ln> ::selectors::Node for LayoutNode<'ln> {
self.node.next_sibling_ref().map(|node| self.new_with_this_lifetime(&node))
}
}
/// If this is an element, accesses the element data.
#[inline]
fn as_element(&self) -> Option<Self::Element> {
ElementCast::to_layout_js(&self.node).map(|element| {
LayoutElement {
element: element,
chain: self.chain,
}
})
}
fn is_document(&self) -> bool {
match self.type_id() {
NodeTypeId::Document(..) => true,
_ => false
}
}
fn is_element_or_non_empty_text(&self) -> bool {
if let Some(text) = TextCast::to_layout_js(&self.node) {
unsafe {
!CharacterDataCast::from_layout_js(&text).data_for_layout().is_empty()
}
} else {
ElementCast::to_layout_js(&self.node).is_some()
}
}
}
impl<'ln> LayoutNode<'ln> {
@ -387,18 +352,78 @@ impl<'le> LayoutElement<'le> {
&*self.element.style_attribute()
}
}
}
impl<'le> ::selectors::Element for LayoutElement<'le> {
type Node = LayoutNode<'le>;
#[inline]
fn as_node(&self) -> LayoutNode<'le> {
pub fn as_node(&self) -> LayoutNode<'le> {
LayoutNode {
node: NodeCast::from_layout_js(&self.element),
chain: PhantomData,
}
}
}
fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
ElementCast::to_layout_js(&node).map(|element| {
LayoutElement {
element: element,
chain: PhantomData,
}
})
}
impl<'le> ::selectors::Element for LayoutElement<'le> {
fn parent_element(&self) -> Option<LayoutElement<'le>> {
unsafe {
NodeCast::from_layout_js(&self.element).parent_node_ref().and_then(as_element)
}
}
fn first_child_element(&self) -> Option<LayoutElement<'le>> {
self.as_node().children().filter_map(|n| n.as_element()).next()
}
fn last_child_element(&self) -> Option<LayoutElement<'le>> {
self.as_node().rev_children().filter_map(|n| n.as_element()).next()
}
fn prev_sibling_element(&self) -> Option<LayoutElement<'le>> {
let mut node = self.as_node();
while let Some(sibling) = node.prev_sibling() {
if let Some(element) = sibling.as_element() {
return Some(element)
}
node = sibling;
}
None
}
fn next_sibling_element(&self) -> Option<LayoutElement<'le>> {
let mut node = self.as_node();
while let Some(sibling) = node.next_sibling() {
if let Some(element) = sibling.as_element() {
return Some(element)
}
node = sibling;
}
None
}
fn is_root(&self) -> bool {
match self.as_node().parent_node() {
None => false,
Some(node) => node.type_id() == NodeTypeId::Document,
}
}
fn is_empty(&self) -> bool {
self.as_node().children().all(|node| match node.type_id() {
NodeTypeId::Element(..) => false,
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => unsafe {
CharacterDataCast::to_layout_js(&node.node).unwrap().data_for_layout().is_empty()
},
_ => true
})
}
#[inline]
fn get_local_name<'a>(&'a self) -> &'a Atom {