servo: Merge #17210 - Bug 1367615 - Stylo: implement inIDOMUtils.getSelectorCount and inIDO… (from ferjm:bug1367615.inDOMUtils); r=emilio
authorFernando Jiménez Moreno <ferjmoreno@gmail.com>
Wed, 07 Jun 2017 09:54:47 -0700
changeset 410950 47ddea39b2a66e44e11233941e9afc5fd45a7732
parent 410949 4b3ef3cb1b9c494e28728c6574481e2a0a2e2a48
child 410951 24861f3cb85f42d78c64f3f941ba6da02700d6dc
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs17210, 1367615
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #17210 - Bug 1367615 - Stylo: implement inIDOMUtils.getSelectorCount and inIDO… (from ferjm:bug1367615.inDOMUtils); r=emilio …MUtils.getSelectorTextFromIndex https://bugzilla.mozilla.org/show_bug.cgi?id=1367615 Source-Repo: https://github.com/servo/servo Source-Revision: cb281af463e2f6a30f4f65db0dd614b07570c356
servo/components/selectors/parser.rs
servo/components/style/gecko/generated/bindings.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/selectors/parser.rs
+++ b/servo/components/selectors/parser.rs
@@ -162,16 +162,33 @@ impl<Impl: SelectorImpl> SelectorList<Im
         input.parse_comma_separated(|input| parse_selector(parser, input).map(SelectorAndHashes::new))
              .map(SelectorList)
     }
 
     /// Creates a SelectorList from a Vec of selectors. Used in tests.
     pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
         SelectorList(v.into_iter().map(SelectorAndHashes::new).collect())
     }
+
+    pub fn to_css_from_index<W>(&self, from_index: usize, dest: &mut W)
+        -> fmt::Result where W: fmt::Write {
+        let mut iter = self.0.iter().skip(from_index);
+
+        let first = match iter.next() {
+            Some(f) => f,
+            None => return Ok(()),
+        };
+
+        first.selector.to_css(dest)?;
+        for selector_and_hashes in iter {
+            dest.write_str(", ")?;
+            selector_and_hashes.selector.to_css(dest)?;
+        }
+        Ok(())
+    }
 }
 
 /// Copied from Gecko, who copied it from WebKit. Note that increasing the
 /// number of hashes here will adversely affect the cache hit when fast-
 /// rejecting long lists of Rules with inline hashes.
 const NUM_ANCESTOR_HASHES: usize = 4;
 
 /// Ancestor hashes for the bloom filter. We precompute these and store them
@@ -633,25 +650,17 @@ impl<Impl: SelectorImpl> Debug for AttrS
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_css(f) }
 }
 impl<Impl: SelectorImpl> Debug for LocalName<Impl> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_css(f) }
 }
 
 impl<Impl: SelectorImpl> ToCss for SelectorList<Impl> {
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-        let mut iter = self.0.iter();
-        let first = iter.next()
-            .expect("Empty SelectorList, should contain at least one selector");
-        first.selector.to_css(dest)?;
-        for selector_and_hashes in iter {
-            dest.write_str(", ")?;
-            selector_and_hashes.selector.to_css(dest)?;
-        }
-        Ok(())
+        self.to_css_from_index(/* from_index = */ 0, dest)
     }
 }
 
 impl<Impl: SelectorImpl> ToCss for Selector<Impl> {
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
        for item in self.iter_raw_rev() {
            item.to_css(dest)?;
        }
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -2046,16 +2046,26 @@ extern "C" {
                                     declarations:
                                         RawServoDeclarationBlockBorrowed);
 }
 extern "C" {
     pub fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed,
                                            result: *mut nsAString);
 }
 extern "C" {
+    pub fn Servo_StyleRule_GetSelectorTextFromIndex(rule:
+                                                        RawServoStyleRuleBorrowed,
+                                                    index: u32,
+                                                    result: *mut nsAString);
+}
+extern "C" {
+    pub fn Servo_StyleRule_GetSelectorCount(rule: RawServoStyleRuleBorrowed,
+                                            count: *mut u32);
+}
+extern "C" {
     pub fn Servo_ImportRule_GetHref(rule: RawServoImportRuleBorrowed,
                                     result: *mut nsAString);
 }
 extern "C" {
     pub fn Servo_ImportRule_GetSheet(rule: RawServoImportRuleBorrowed)
      -> *const RawServoStyleSheet;
 }
 extern "C" {
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1152,16 +1152,35 @@ pub extern "C" fn Servo_StyleRule_SetSty
 #[no_mangle]
 pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) {
     read_locked_arc(rule, |rule: &StyleRule| {
         rule.selectors.to_css(unsafe { result.as_mut().unwrap() }).unwrap();
     })
 }
 
 #[no_mangle]
+pub extern "C" fn Servo_StyleRule_GetSelectorTextFromIndex(rule: RawServoStyleRuleBorrowed,
+                                                           aSelectorIndex: u32,
+                                                           result: *mut nsAString) {
+    read_locked_arc(rule, |rule: &StyleRule| {
+        rule.selectors.to_css_from_index(
+            aSelectorIndex as usize,
+            unsafe { result.as_mut().unwrap() }
+        ).unwrap();
+    })
+}
+
+#[no_mangle]
+pub extern "C" fn Servo_StyleRule_GetSelectorCount(rule: RawServoStyleRuleBorrowed, count: *mut u32) {
+    read_locked_arc(rule, |rule: &StyleRule| {
+        *unsafe { count.as_mut().unwrap() } = rule.selectors.0.len() as u32;
+    })
+}
+
+#[no_mangle]
 pub extern "C" fn Servo_ImportRule_GetHref(rule: RawServoImportRuleBorrowed, result: *mut nsAString) {
     read_locked_arc(rule, |rule: &ImportRule| {
         write!(unsafe { &mut *result }, "{}", rule.url.as_str()).unwrap();
     })
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_ImportRule_GetSheet(rule: RawServoImportRuleBorrowed) -> *const RawServoStyleSheet {