mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
stylo: Implement GetSpecificity for ServoStyleRule
This commit is contained in:
parent
87140641a4
commit
2cc940384d
3 changed files with 39 additions and 26 deletions
|
@ -201,23 +201,6 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
|
||||||
pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
|
pub fn from_vec(v: Vec<Selector<Impl>>) -> Self {
|
||||||
SelectorList(v.into_iter().map(SelectorAndHashes::new).collect())
|
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
|
/// Copied from Gecko, who copied it from WebKit. Note that increasing the
|
||||||
|
@ -714,7 +697,15 @@ impl<Impl: SelectorImpl> Debug for LocalName<Impl> {
|
||||||
|
|
||||||
impl<Impl: SelectorImpl> ToCss for SelectorList<Impl> {
|
impl<Impl: SelectorImpl> ToCss for SelectorList<Impl> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
self.to_css_from_index(/* from_index = */ 0, dest)
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2112,11 +2112,17 @@ extern "C" {
|
||||||
result: *mut nsAString);
|
result: *mut nsAString);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleRule_GetSelectorTextFromIndex(rule:
|
pub fn Servo_StyleRule_GetSelectorTextAtIndex(rule:
|
||||||
RawServoStyleRuleBorrowed,
|
RawServoStyleRuleBorrowed,
|
||||||
index: u32,
|
index: u32,
|
||||||
result: *mut nsAString);
|
result: *mut nsAString);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_StyleRule_GetSpecificityAtIndex(rule:
|
||||||
|
RawServoStyleRuleBorrowed,
|
||||||
|
index: u32,
|
||||||
|
specificity: *mut u64);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleRule_GetSelectorCount(rule: RawServoStyleRuleBorrowed,
|
pub fn Servo_StyleRule_GetSelectorCount(rule: RawServoStyleRuleBorrowed,
|
||||||
count: *mut u32);
|
count: *mut u32);
|
||||||
|
|
|
@ -1187,14 +1187,15 @@ pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowe
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleRule_GetSelectorTextFromIndex(rule: RawServoStyleRuleBorrowed,
|
pub extern "C" fn Servo_StyleRule_GetSelectorTextAtIndex(rule: RawServoStyleRuleBorrowed,
|
||||||
aSelectorIndex: u32,
|
index: u32,
|
||||||
result: *mut nsAString) {
|
result: *mut nsAString) {
|
||||||
read_locked_arc(rule, |rule: &StyleRule| {
|
read_locked_arc(rule, |rule: &StyleRule| {
|
||||||
rule.selectors.to_css_from_index(
|
let index = index as usize;
|
||||||
aSelectorIndex as usize,
|
if index >= rule.selectors.0.len() {
|
||||||
unsafe { result.as_mut().unwrap() }
|
return;
|
||||||
).unwrap();
|
}
|
||||||
|
rule.selectors.0[index].selector.to_css(unsafe { result.as_mut().unwrap() }).unwrap();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1205,6 +1206,21 @@ pub extern "C" fn Servo_StyleRule_GetSelectorCount(rule: RawServoStyleRuleBorrow
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_StyleRule_GetSpecificityAtIndex(rule: RawServoStyleRuleBorrowed,
|
||||||
|
index: u32,
|
||||||
|
specificity: *mut u64) {
|
||||||
|
read_locked_arc(rule, |rule: &StyleRule| {
|
||||||
|
let mut specificity = unsafe { specificity.as_mut().unwrap() };
|
||||||
|
let index = index as usize;
|
||||||
|
if index >= rule.selectors.0.len() {
|
||||||
|
*specificity = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*specificity = rule.selectors.0[index].selector.specificity() as u64;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ImportRule_GetHref(rule: RawServoImportRuleBorrowed, result: *mut nsAString) {
|
pub extern "C" fn Servo_ImportRule_GetHref(rule: RawServoImportRuleBorrowed, result: *mut nsAString) {
|
||||||
read_locked_arc(rule, |rule: &ImportRule| {
|
read_locked_arc(rule, |rule: &ImportRule| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue