Skip to content

Commit

Permalink
style: Implement ServoStyleRule::SetSelectorText.
Browse files Browse the repository at this point in the history
Bug: 37468
Reviewed-by: xidorn
  • Loading branch information
krk authored and Moggers committed Jun 13, 2018
1 parent b61b797 commit 2c14584
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ports/geckolib/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cssparser::{ParseErrorKind, Parser, ParserInput, SourceLocation};
use cssparser::ToCss as ParserToCss;
use env_logger::Builder;
use malloc_size_of::MallocSizeOfOps;
use selectors::NthIndexCache;
use selectors::{NthIndexCache, SelectorList};
use selectors::matching::{MatchingContext, MatchingMode, matches_selector};
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use smallvec::SmallVec;
Expand Down Expand Up @@ -1902,6 +1902,37 @@ pub extern "C" fn Servo_StyleRule_SelectorMatchesElement(
})
}

#[no_mangle]
pub unsafe extern "C" fn Servo_StyleRule_SetSelectorText(
sheet: RawServoStyleSheetContentsBorrowed,
rule: RawServoStyleRuleBorrowed,
text: *const nsAString,
) -> bool {
let value_str = (*text).to_string();

write_locked_arc(rule, |rule: &mut StyleRule| {
use style::selector_parser::SelectorParser;

let contents = StylesheetContents::as_arc(&sheet);
let namespaces = contents.namespaces.read();
let url_data = contents.url_data.read();
let parser = SelectorParser {
stylesheet_origin: contents.origin,
namespaces: &namespaces,
url_data: Some(&url_data),
};

let mut parser_input = ParserInput::new(&value_str);
match SelectorList::parse(&parser, &mut Parser::new(&mut parser_input)) {
Ok(selectors) => {
rule.selectors = selectors;
true
}
Err(_) => false,
}
})
}

#[no_mangle]
pub unsafe extern "C" fn Servo_SelectorList_Closest(
element: RawGeckoElementBorrowed,
Expand Down

0 comments on commit 2c14584

Please sign in to comment.