From dbbbebd66436f83d55465fd304195f77af259858 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 2 Mar 2016 20:34:23 -0800 Subject: [PATCH] Parse ServoBindings.h as C++. This allows us to remove the bool-as-int contortions we were doing before. --- ports/geckolib/bindings.rs | 25 ++++++++++++++----------- ports/geckolib/glue.rs | 4 ++-- ports/geckolib/tools/regen_bindings.sh | 2 +- ports/geckolib/wrapper.rs | 14 +++++++------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index d441f44c8e5..ba761f17d78 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -28,15 +28,18 @@ pub type intptr_t = int64_t; pub type uintptr_t = uint64_t; pub type intmax_t = ::libc::c_long; pub type uintmax_t = ::libc::c_ulong; -pub enum RawGeckoNode { } -pub enum RawGeckoElement { } -pub enum RawGeckoDocument { } +pub enum nsINode { } +pub type RawGeckoNode = nsINode; +pub enum Element { } +pub type RawGeckoElement = Element; +pub enum nsIDocument { } +pub type RawGeckoDocument = nsIDocument; pub enum ServoNodeData { } pub enum RawServoStyleSheet { } pub enum RawServoStyleSet { } extern "C" { pub fn Gecko_ChildrenCount(node: *mut RawGeckoNode) -> uint32_t; - pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> i32; + pub fn Gecko_NodeIsElement(node: *mut RawGeckoNode) -> bool; pub fn Gecko_GetParentNode(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetFirstChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; pub fn Gecko_GetLastChild(node: *mut RawGeckoNode) -> *mut RawGeckoNode; @@ -56,12 +59,12 @@ extern "C" { -> *mut RawGeckoElement; pub fn Gecko_ElementState(element: *mut RawGeckoElement) -> uint8_t; pub fn Gecko_IsHTMLElementInHTMLDocument(element: *mut RawGeckoElement) - -> i32; - pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> i32; - pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) -> i32; - pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) -> i32; + -> bool; + pub fn Gecko_IsLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsTextNode(node: *mut RawGeckoNode) -> bool; + pub fn Gecko_IsVisitedLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsUnvisitedLink(element: *mut RawGeckoElement) -> bool; + pub fn Gecko_IsRootElement(element: *mut RawGeckoElement) -> bool; pub fn Gecko_GetNodeData(node: *mut RawGeckoNode) -> *mut ServoNodeData; pub fn Gecko_SetNodeData(node: *mut RawGeckoNode, data: *mut ServoNodeData); @@ -76,7 +79,7 @@ extern "C" { set: *mut RawServoStyleSet); pub fn Servo_RemoveStyleSheet(sheet: *mut RawServoStyleSheet, set: *mut RawServoStyleSet); - pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> i32; + pub fn Servo_StyleSheetHasRules(sheet: *mut RawServoStyleSheet) -> bool; pub fn Servo_InitStyleSet() -> *mut RawServoStyleSet; pub fn Servo_DropStyleSet(set: *mut RawServoStyleSet); pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9185d701c18..510e39cc041 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -127,8 +127,8 @@ pub extern "C" fn Servo_RemoveStyleSheet(raw_sheet: *mut RawServoStyleSheet, } #[no_mangle] -pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> ::libc::c_int { - with_arc_stylesheet(raw_sheet, |sheet| if sheet.rules.is_empty() { 0 } else { 1 }) +pub extern "C" fn Servo_StyleSheetHasRules(raw_sheet: *mut RawServoStyleSheet) -> bool { + with_arc_stylesheet(raw_sheet, |sheet| !sheet.rules.is_empty()) } diff --git a/ports/geckolib/tools/regen_bindings.sh b/ports/geckolib/tools/regen_bindings.sh index 4795910c70d..157877b0c72 100755 --- a/ports/geckolib/tools/regen_bindings.sh +++ b/ports/geckolib/tools/regen_bindings.sh @@ -30,4 +30,4 @@ fi # library in DYLD_LIBRARY_PATH. # # /Applications/Xcode.app/Contents/Developer/usr/bin/lldb -- -./rust-bindgen/target/debug/bindgen -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h +./rust-bindgen/target/debug/bindgen -x c++ -std=gnu++0x -I$DIST_INCLUDE -o ../bindings.rs $DIST_INCLUDE/mozilla/ServoBindings.h diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index a05e08d5227..272b89f64d6 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -103,13 +103,13 @@ impl<'ln> TNode<'ln> for GeckoNode<'ln> { fn is_text_node(&self) -> bool { unsafe { - Gecko_IsTextNode(self.node) != 0 + Gecko_IsTextNode(self.node) } } fn is_element(&self) -> bool { unsafe { - Gecko_NodeIsElement(self.node) != 0 + Gecko_NodeIsElement(self.node) } } @@ -392,7 +392,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn is_root(&self) -> bool { unsafe { - Gecko_IsRootElement(self.element) != 0 + Gecko_IsRootElement(self.element) } } @@ -425,9 +425,9 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn match_non_ts_pseudo_class(&self, pseudo_class: NonTSPseudoClass) -> bool { match pseudo_class { // https://github.com/servo/servo/issues/8718 - NonTSPseudoClass::AnyLink => unsafe { Gecko_IsLink(self.element) != 0 }, - NonTSPseudoClass::Link => unsafe { Gecko_IsUnvisitedLink(self.element) != 0 }, - NonTSPseudoClass::Visited => unsafe { Gecko_IsVisitedLink(self.element) != 0 }, + NonTSPseudoClass::AnyLink => unsafe { Gecko_IsLink(self.element) }, + NonTSPseudoClass::Link => unsafe { Gecko_IsUnvisitedLink(self.element) }, + NonTSPseudoClass::Visited => unsafe { Gecko_IsVisitedLink(self.element) }, NonTSPseudoClass::Active | NonTSPseudoClass::Focus | NonTSPseudoClass::Hover | @@ -480,7 +480,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> { fn is_html_element_in_html_document(&self) -> bool { unsafe { - Gecko_IsHTMLElementInHTMLDocument(self.element) != 0 + Gecko_IsHTMLElementInHTMLDocument(self.element) } } }