From 7e5a33759c92ff57136129491ac77ff6284c25bf Mon Sep 17 00:00:00 2001 From: ILyoan Date: Thu, 30 May 2013 11:19:49 +0900 Subject: [PATCH 1/2] Add support class selection --- netsurfcss.rc | 21 +++++++++++++++++---- test.rs | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/netsurfcss.rc b/netsurfcss.rc index c51560e..d08de01 100644 --- a/netsurfcss.rc +++ b/netsurfcss.rc @@ -916,10 +916,22 @@ pub mod select { write_ll_qname(&mut hlqname, qname); CSS_OK }, - node_classes: |_node: *c_void, classes: *mut **lwc_string, n_classes: *mut uint32_t| -> css_error { - // FIXME - *classes = null(); - *n_classes = 0; + node_classes: |node: *c_void, classes: *mut **lwc_string, n_classes: *mut uint32_t| -> css_error { + let hlnode: N = VoidPtrLike::from_void_ptr(node); + + let (a, b) = match handler.node_classes(&hlnode) { + Some(classes) => { + let class = classes.map(|e| e.raw_reffed()); + let len = classes.len(); + let size = (len * sys::size_of::()) as libc::size_t; + let mem = libc::malloc(size); + libc::memcpy(mem, vec::raw::to_ptr(class) as *libc::c_void, size); + (mem as **lwc_string, len as u32) + }, + None => (null(), 0) + }; + *classes = a; + *n_classes = b; CSS_OK }, node_id: |node: *c_void, id: *mut *lwc_string| -> css_error { @@ -995,6 +1007,7 @@ pub mod select { pub trait CssSelectHandler { fn node_name(&self, node: &N) -> CssQName; + fn node_classes(&self, node: &N) -> Option<~[LwcString]>; fn node_id(&self, node: &N) -> Option; fn named_parent_node(&self, node: &N, qname: &CssQName) -> Option; fn parent_node(&self, node: &N) -> Option; diff --git a/test.rs b/test.rs index 10605f5..7bbeec1 100644 --- a/test.rs +++ b/test.rs @@ -126,6 +126,8 @@ mod example1 { } } + fn node_classes(&self, _node: &MyDomNode) -> Option<~[LwcString]> { None } + fn node_id(&self, _node: &MyDomNode) -> Option { None } fn named_parent_node(&self, _node: &MyDomNode, _qname: &CssQName) -> Option { From 30ea2a96064f7340ba27284c914765e70659badb Mon Sep 17 00:00:00 2001 From: ILyoan Date: Fri, 31 May 2013 17:14:37 +0900 Subject: [PATCH 2/2] Add support class selection (2) --- netsurfcss.rc | 18 +++++++++++------- test.rs | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/netsurfcss.rc b/netsurfcss.rc index d08de01..76ad7b5 100644 --- a/netsurfcss.rc +++ b/netsurfcss.rc @@ -771,13 +771,9 @@ pub mod select { pub extern fn node_has_name(_pw: *c_void, _node: *c_void, _qname: *css_qname, _match_: *bool) -> css_error { unimpl("node_has_name") } - pub extern fn node_has_class(_pw: *c_void, _node: *c_void, _name: *lwc_string, match_: *mut bool) -> css_error { - // TODO - unsafe { - unimpl_warn("node_has_class"); - *match_ = false; - CSS_OK - } + pub extern fn node_has_class(pw: *c_void, node: *c_void, name: *lwc_string, match_: *mut bool) -> css_error { + enter("node_has_class"); + (ph(pw).node_has_class)(node, name, match_) } pub extern fn node_has_id(pw: *c_void, node: *c_void, name: *lwc_string, match_: *mut bool) -> css_error { enter("node_has_id"); @@ -897,6 +893,7 @@ pub mod select { node_id: &'self fn(node: *c_void, id: *mut *lwc_string) -> css_error, named_parent_node: &'self fn(node: *c_void, qname: *css_qname, parent: *mut *c_void) -> css_error, parent_node: &'self fn(node: *c_void, parent: *mut *c_void) -> css_error, + node_has_class: &'self fn(node: *c_void, name: *lwc_string, match_: *mut bool) -> css_error, node_has_id: &'self fn(node: *c_void, name: *lwc_string, match_: *mut bool) -> css_error, named_ancestor_node: &'self fn(node: *c_void, qname: *css_qname, @@ -960,6 +957,12 @@ pub mod select { }; CSS_OK }, + node_has_class: |node: *c_void, name: *lwc_string, match_: *mut bool| -> css_error { + let hlnode: N = VoidPtrLike::from_void_ptr(node); + let hlname = from_lwc_string(name); + *match_ = handler.node_has_class(&hlnode, hlname); + CSS_OK + }, node_has_id: |node: *c_void, name: *lwc_string, match_: *mut bool| -> css_error { let hlnode: N = VoidPtrLike::from_void_ptr(node); let hlname = from_lwc_string(name); @@ -1011,6 +1014,7 @@ pub mod select { fn node_id(&self, node: &N) -> Option; fn named_parent_node(&self, node: &N, qname: &CssQName) -> Option; fn parent_node(&self, node: &N) -> Option; + fn node_has_class(&self, node: &N, name: LwcString) -> bool; fn node_has_id(&self, node: &N, name: LwcString) -> bool; fn named_ancestor_node(&self, node: &N, qname: &CssQName) -> Option; fn node_is_root(&self, node: &N) -> bool; diff --git a/test.rs b/test.rs index 7bbeec1..8565daa 100644 --- a/test.rs +++ b/test.rs @@ -137,6 +137,8 @@ mod example1 { fn parent_node(&self, _node: &MyDomNode) -> Option { None } + + fn node_has_class(&self, _node: &MyDomNode, _name: LwcString) -> bool { false } fn node_has_id(&self, _node: &MyDomNode, _name: LwcString) -> bool { false }