:nth-child and friends, changes in response to SimonSapin's review

This commit is contained in:
Daniel Glazman 2013-11-29 09:58:11 +01:00
parent 991d4d8a3c
commit eb76ea76db

View file

@ -522,7 +522,7 @@ fn url_is_visited(_url: &str) -> bool {
#[inline] #[inline]
fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>( fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: ElementLike>(
element: &T, a: i32, b: i32, isOfType: bool, isFromEnd: bool) -> bool { element: &T, a: i32, b: i32, is_of_type: bool, is_from_end: bool) -> bool {
let mut node = element.clone(); let mut node = element.clone();
// fail if we can't find a parent or if the node is the root element // fail if we can't find a parent or if the node is the root element
// of the document (Cf. Selectors Level 3) // of the document (Cf. Selectors Level 3)
@ -534,7 +534,7 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
}; };
let mut local_name = ""; let mut local_name = "";
if isOfType { if is_of_type {
// FIXME this is wrong // FIXME this is wrong
// TODO when the DOM supports namespaces on elements // TODO when the DOM supports namespaces on elements
do element.with_imm_element_like |element: &E| { do element.with_imm_element_like |element: &E| {
@ -544,7 +544,7 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
let mut index = 1; let mut index = 1;
loop { loop {
if isFromEnd { if is_from_end {
match node.node().next_sibling() { match node.node().next_sibling() {
None => break, None => break,
Some(next_sibling) => node = next_sibling Some(next_sibling) => node = next_sibling
@ -557,7 +557,7 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
} }
if node.is_element() { if node.is_element() {
if isOfType { if is_of_type {
// FIXME this is wrong // FIXME this is wrong
// TODO when the DOM supports namespaces on elements // TODO when the DOM supports namespaces on elements
do node.with_imm_element_like |node: &E| { do node.with_imm_element_like |node: &E| {
@ -576,7 +576,7 @@ fn matches_generic_nth_child<N: TreeNode<T>, T: TreeNodeRefAsElement<N, E>, E: E
return b == index; return b == index;
} }
let n: i32 = (((index as f32) - (b as f32)) / (a as f32)) as i32; let (n, r) = (index - b).div_rem(&a);
n >= 0 && (a * n == index - b) n >= 0 && (a * n == index - b)
} }