Bug 1307357 part 7 - Implement ServoStyleRule::List. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Mon, 07 Nov 2016 17:11:34 +1100
changeset 434696 2b15164603c755fc58722a263eb5aaf82bc360e4
parent 434695 1dbd39a91066b49c83ca037af35ff6064c2c3e99
child 536083 166277b9f78f9cffd1a1ef56b15dcce72c044e68
push id34791
push userxquan@mozilla.com
push dateMon, 07 Nov 2016 06:12:19 +0000
reviewersheycam
bugs1307357
milestone52.0a1
Bug 1307357 part 7 - Implement ServoStyleRule::List. r?heycam MozReview-Commit-ID: 1XRoc43RJKP
layout/style/ServoBindingList.h
layout/style/ServoStyleRule.cpp
servo/ports/geckolib/glue.rs
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -47,16 +47,18 @@ SERVO_BINDING_FUNC(Servo_StyleSet_Prepen
                    RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSet_RemoveStyleSheet, void,
                    RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet)
 SERVO_BINDING_FUNC(Servo_StyleSet_InsertStyleSheetBefore, void,
                    RawServoStyleSetBorrowed set, RawServoStyleSheetBorrowed sheet,
                    RawServoStyleSheetBorrowed reference)
 
 // CSS Rules
+SERVO_BINDING_FUNC(Servo_StyleRule_Debug, void,
+                   RawServoStyleRuleBorrowed rule, nsACString* result)
 SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong,
                    RawServoStyleRuleBorrowed rule)
 SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void,
                    RawServoStyleRuleBorrowed rule,
                    RawServoDeclarationBlockBorrowed declarations)
 SERVO_BINDING_FUNC(Servo_StyleRule_GetCssText, void,
                    RawServoStyleRuleBorrowed rule, nsAString* result)
 SERVO_BINDING_FUNC(Servo_StyleRule_GetSelectorText, void,
--- a/layout/style/ServoStyleRule.cpp
+++ b/layout/style/ServoStyleRule.cpp
@@ -153,17 +153,22 @@ ServoStyleRule::SizeOfIncludingThis(Mall
   // TODO Implement this!
   return aMallocSizeOf(this);
 }
 
 #ifdef DEBUG
 void
 ServoStyleRule::List(FILE* out, int32_t aIndent) const
 {
-  // TODO Implement this!
+  nsAutoCString str;
+  for (int32_t i = 0; i < aIndent; i++) {
+    str.AppendLiteral("  ");
+  }
+  Servo_StyleRule_Debug(mRawRule, &str);
+  fprintf_stderr(out, "%s\n", str.get());
 }
 #endif
 
 /* CSSRule implementation */
 
 NS_IMETHODIMP
 ServoStyleRule::GetType(uint16_t* aType)
 {
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -4,16 +4,17 @@
 
 use app_units::Au;
 use cssparser::{Parser, ToCss};
 use env_logger;
 use euclid::Size2D;
 use parking_lot::RwLock;
 use std::fmt::Write;
 use std::mem::transmute;
+use std::ops::Deref;
 use std::sync::{Arc, Mutex};
 use style::arc_ptr_eq;
 use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext};
 use style::dom::{NodeInfo, StylingMode, TElement, TNode};
 use style::error_reporting::StdoutErrorReporter;
 use style::gecko::data::{NUM_THREADS, PerDocumentStyleData};
 use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement};
 use style::gecko::snapshot::GeckoElementSnapshot;
@@ -281,16 +282,23 @@ pub extern "C" fn Servo_StyleRule_AddRef
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () {
     unsafe { RwLock::<StyleRule>::release(rule) };
 }
 
 #[no_mangle]
+pub extern "C" fn Servo_StyleRule_Debug(rule: RawServoStyleRuleBorrowed, result: *mut nsACString) -> () {
+    let rule = RwLock::<StyleRule>::as_arc(&rule);
+    let result = unsafe { result.as_mut().unwrap() };
+    write!(result, "{:?}", rule.read().deref()).unwrap();
+}
+
+#[no_mangle]
 pub extern "C" fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) -> RawServoDeclarationBlockStrong {
     let rule = RwLock::<StyleRule>::as_arc(&rule);
     rule.read().block.clone().into_strong()
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleRule_SetStyle(rule: RawServoStyleRuleBorrowed,
                                            declarations: RawServoDeclarationBlockBorrowed) -> () {