mirror of
https://github.com/servo/servo.git
synced 2025-06-18 21:34:30 +00:00
stylo: Honor CallerType for media query parsing.
So that matchMedia can parse internal stuff in Chrome code. Bug: 1410074 Reviewed-by: xidorn MozReview-Commit-ID: 6M4HHqVJ1dp
This commit is contained in:
parent
5da0a8d872
commit
21b314e633
2 changed files with 37 additions and 10 deletions
|
@ -14,6 +14,7 @@ use gecko_bindings::structs::mozilla::css::ErrorReporter;
|
||||||
use gecko_bindings::structs::mozilla::css::ImageValue;
|
use gecko_bindings::structs::mozilla::css::ImageValue;
|
||||||
use gecko_bindings::structs::mozilla::css::URLValue;
|
use gecko_bindings::structs::mozilla::css::URLValue;
|
||||||
use gecko_bindings::structs::mozilla::css::URLValueData;
|
use gecko_bindings::structs::mozilla::css::URLValueData;
|
||||||
|
use gecko_bindings::structs::mozilla::dom::CallerType;
|
||||||
use gecko_bindings::structs::mozilla::AnonymousCounterStyle;
|
use gecko_bindings::structs::mozilla::AnonymousCounterStyle;
|
||||||
use gecko_bindings::structs::mozilla::AtomArray;
|
use gecko_bindings::structs::mozilla::AtomArray;
|
||||||
use gecko_bindings::structs::mozilla::MallocSizeOf;
|
use gecko_bindings::structs::mozilla::MallocSizeOf;
|
||||||
|
@ -2868,7 +2869,8 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed,
|
pub fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed,
|
||||||
text: *const nsACString);
|
text: *const nsACString,
|
||||||
|
aCallerType: CallerType);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_MediaList_GetLength(list: RawServoMediaListBorrowed) -> u32;
|
pub fn Servo_MediaList_GetLength(list: RawServoMediaListBorrowed) -> u32;
|
||||||
|
|
|
@ -78,7 +78,7 @@ use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
|
||||||
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
|
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
|
||||||
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
|
use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut;
|
||||||
use style::gecko_bindings::structs;
|
use style::gecko_bindings::structs;
|
||||||
use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation};
|
use style::gecko_bindings::structs::{CallerType, CSSPseudoElementType, CompositeOperation};
|
||||||
use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets};
|
use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets};
|
||||||
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong, RustString};
|
use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong, RustString};
|
||||||
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID};
|
use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID};
|
||||||
|
@ -2793,16 +2793,41 @@ pub extern "C" fn Servo_MediaList_GetText(list: RawServoMediaListBorrowed, resul
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_MediaList_SetText(list: RawServoMediaListBorrowed, text: *const nsACString) {
|
pub unsafe extern "C" fn Servo_MediaList_SetText(
|
||||||
let text = unsafe { text.as_ref().unwrap().as_str_unchecked() };
|
list: RawServoMediaListBorrowed,
|
||||||
|
text: *const nsACString,
|
||||||
|
caller_type: CallerType,
|
||||||
|
) {
|
||||||
|
let text = (*text).as_str_unchecked();
|
||||||
|
|
||||||
let mut input = ParserInput::new(&text);
|
let mut input = ParserInput::new(&text);
|
||||||
let mut parser = Parser::new(&mut input);
|
let mut parser = Parser::new(&mut input);
|
||||||
let url_data = unsafe { dummy_url_data() };
|
let url_data = dummy_url_data();
|
||||||
let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media),
|
|
||||||
|
// TODO(emilio): If the need for `CallerType` appears in more places,
|
||||||
|
// consider adding an explicit member in `ParserContext` instead of doing
|
||||||
|
// this (or adding a dummy "chrome://" url data).
|
||||||
|
//
|
||||||
|
// For media query parsing it's effectively the same, so for now...
|
||||||
|
let origin = match caller_type {
|
||||||
|
CallerType::System => Origin::UserAgent,
|
||||||
|
CallerType::NonSystem => Origin::Author,
|
||||||
|
};
|
||||||
|
|
||||||
|
let context = ParserContext::new(
|
||||||
|
origin,
|
||||||
|
url_data,
|
||||||
|
Some(CssRuleType::Media),
|
||||||
PARSING_MODE_DEFAULT,
|
PARSING_MODE_DEFAULT,
|
||||||
QuirksMode::NoQuirks);
|
QuirksMode::NoQuirks,
|
||||||
|
);
|
||||||
|
|
||||||
write_locked_arc(list, |list: &mut MediaList| {
|
write_locked_arc(list, |list: &mut MediaList| {
|
||||||
*list = parse_media_query_list(&context, &mut parser, &NullReporter);
|
*list = parse_media_query_list(
|
||||||
|
&context,
|
||||||
|
&mut parser,
|
||||||
|
&NullReporter,
|
||||||
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue