Auto merge of #17086 - upsuper:bug1352968, r=heycam

Add CSSOM support of @import rule for stylo

This is the Servo side change of [bug 1352968](https://bugzilla.mozilla.org/show_bug.cgi?id=1352968).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17086)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-29 18:51:45 -05:00 committed by GitHub
commit 085743560c
5 changed files with 66 additions and 30 deletions

View file

@ -1739,10 +1739,6 @@ extern "C" {
quirks_mode: nsCompatibility) quirks_mode: nsCompatibility)
-> RawServoStyleSheetStrong; -> RawServoStyleSheetStrong;
} }
extern "C" {
pub fn Servo_ImportRule_GetSheet(import_rule: RawServoImportRuleBorrowed)
-> RawServoStyleSheetStrong;
}
extern "C" { extern "C" {
pub fn Servo_StyleSheet_ClearAndUpdate(stylesheet: pub fn Servo_StyleSheet_ClearAndUpdate(stylesheet:
RawServoStyleSheetBorrowed, RawServoStyleSheetBorrowed,
@ -1873,6 +1869,20 @@ extern "C" {
pub fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, pub fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed,
result: *mut nsAString); result: *mut nsAString);
} }
extern "C" {
pub fn Servo_CssRules_GetImportRuleAt(rules: ServoCssRulesBorrowed,
index: u32, line: *mut u32,
column: *mut u32)
-> RawServoImportRuleStrong;
}
extern "C" {
pub fn Servo_ImportRule_Debug(rule: RawServoImportRuleBorrowed,
result: *mut nsACString);
}
extern "C" {
pub fn Servo_ImportRule_GetCssText(rule: RawServoImportRuleBorrowed,
result: *mut nsAString);
}
extern "C" { extern "C" {
pub fn Servo_Keyframe_Debug(rule: RawServoKeyframeBorrowed, pub fn Servo_Keyframe_Debug(rule: RawServoKeyframeBorrowed,
result: *mut nsACString); result: *mut nsACString);
@ -2000,6 +2010,14 @@ extern "C" {
pub fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed, pub fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed,
result: *mut nsAString); result: *mut nsAString);
} }
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" { extern "C" {
pub fn Servo_Keyframe_GetKeyText(keyframe: RawServoKeyframeBorrowed, pub fn Servo_Keyframe_GetKeyText(keyframe: RawServoKeyframeBorrowed,
result: *mut nsAString); result: *mut nsAString);

View file

@ -1555,11 +1555,6 @@ pub mod root {
_unused: [u8; 0], _unused: [u8; 0],
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImportRule {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct Rule { pub struct Rule {
pub _base: root::nsIDOMCSSRule, pub _base: root::nsIDOMCSSRule,
@ -3349,6 +3344,11 @@ pub mod root {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct CSSImportRule {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct CSSRuleList { pub struct CSSRuleList {
_unused: [u8; 0], _unused: [u8; 0],
} }
@ -6692,6 +6692,7 @@ pub mod root {
pub mTitle: ::nsstring::nsStringRepr, pub mTitle: ::nsstring::nsStringRepr,
pub mDocument: *mut root::nsIDocument, pub mDocument: *mut root::nsIDocument,
pub mOwningNode: *mut root::nsINode, pub mOwningNode: *mut root::nsINode,
pub mOwnerRule: *mut root::mozilla::dom::CSSImportRule,
pub mMedia: root::RefPtr<root::mozilla::dom::MediaList>, pub mMedia: root::RefPtr<root::mozilla::dom::MediaList>,
pub mNext: root::RefPtr<root::mozilla::StyleSheet>, pub mNext: root::RefPtr<root::mozilla::StyleSheet>,
pub mParsingMode: root::mozilla::css::SheetParsingMode, pub mParsingMode: root::mozilla::css::SheetParsingMode,
@ -6786,7 +6787,7 @@ pub mod root {
} }
#[test] #[test]
fn bindgen_test_layout_StyleSheet() { fn bindgen_test_layout_StyleSheet() {
assert_eq!(::std::mem::size_of::<StyleSheet>() , 152usize , concat assert_eq!(::std::mem::size_of::<StyleSheet>() , 160usize , concat
! ( "Size of: " , stringify ! ( StyleSheet ) )); ! ( "Size of: " , stringify ! ( StyleSheet ) ));
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
! ( "Alignment of " , stringify ! ( StyleSheet ) )); ! ( "Alignment of " , stringify ! ( StyleSheet ) ));

View file

@ -1479,11 +1479,6 @@ pub mod root {
_unused: [u8; 0], _unused: [u8; 0],
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ImportRule {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct Rule { pub struct Rule {
pub _base: root::nsIDOMCSSRule, pub _base: root::nsIDOMCSSRule,
@ -3254,6 +3249,11 @@ pub mod root {
} }
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct CSSImportRule {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct CSSRuleList { pub struct CSSRuleList {
_unused: [u8; 0], _unused: [u8; 0],
} }
@ -6562,6 +6562,7 @@ pub mod root {
pub mTitle: ::nsstring::nsStringRepr, pub mTitle: ::nsstring::nsStringRepr,
pub mDocument: *mut root::nsIDocument, pub mDocument: *mut root::nsIDocument,
pub mOwningNode: *mut root::nsINode, pub mOwningNode: *mut root::nsINode,
pub mOwnerRule: *mut root::mozilla::dom::CSSImportRule,
pub mMedia: root::RefPtr<root::mozilla::dom::MediaList>, pub mMedia: root::RefPtr<root::mozilla::dom::MediaList>,
pub mNext: root::RefPtr<root::mozilla::StyleSheet>, pub mNext: root::RefPtr<root::mozilla::StyleSheet>,
pub mParsingMode: root::mozilla::css::SheetParsingMode, pub mParsingMode: root::mozilla::css::SheetParsingMode,
@ -6656,7 +6657,7 @@ pub mod root {
} }
#[test] #[test]
fn bindgen_test_layout_StyleSheet() { fn bindgen_test_layout_StyleSheet() {
assert_eq!(::std::mem::size_of::<StyleSheet>() , 144usize , concat assert_eq!(::std::mem::size_of::<StyleSheet>() , 152usize , concat
! ( "Size of: " , stringify ! ( StyleSheet ) )); ! ( "Size of: " , stringify ! ( StyleSheet ) ));
assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat assert_eq! (::std::mem::align_of::<StyleSheet>() , 8usize , concat
! ( "Alignment of " , stringify ! ( StyleSheet ) )); ! ( "Alignment of " , stringify ! ( StyleSheet ) ));

View file

@ -633,6 +633,9 @@ pub struct ImportRule {
/// It contains an empty list of rules and namespace set that is updated /// It contains an empty list of rules and namespace set that is updated
/// when it loads. /// when it loads.
pub stylesheet: Arc<Stylesheet>, pub stylesheet: Arc<Stylesheet>,
/// The line and column of the rule's source code.
pub source_location: SourceLocation,
} }
impl Clone for ImportRule { impl Clone for ImportRule {
@ -641,6 +644,7 @@ impl Clone for ImportRule {
ImportRule { ImportRule {
url: self.url.clone(), url: self.url.clone(),
stylesheet: Arc::new(stylesheet.clone()), stylesheet: Arc::new(stylesheet.clone()),
source_location: self.source_location.clone(),
} }
} }
} }
@ -1530,6 +1534,8 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
fn parse_prelude(&mut self, name: &str, input: &mut Parser) fn parse_prelude(&mut self, name: &str, input: &mut Parser)
-> Result<AtRuleType<AtRulePrelude, CssRule>, ()> { -> Result<AtRuleType<AtRulePrelude, CssRule>, ()> {
let location = get_location_with_offset(input.current_source_location(),
self.context.line_number_offset);
match_ignore_ascii_case! { name, match_ignore_ascii_case! { name,
"import" => { "import" => {
if self.state.get() <= State::Imports { if self.state.get() <= State::Imports {
@ -1561,7 +1567,8 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
dirty_on_viewport_size_change: AtomicBool::new(false), dirty_on_viewport_size_change: AtomicBool::new(false),
disabled: AtomicBool::new(false), disabled: AtomicBool::new(false),
quirks_mode: self.context.quirks_mode, quirks_mode: self.context.quirks_mode,
}) }),
source_location: location,
} }
}, &mut |import_rule| { }, &mut |import_rule| {
Arc::new(self.shared_lock.wrap(import_rule)) Arc::new(self.shared_lock.wrap(import_rule))
@ -1576,9 +1583,6 @@ impl<'a> AtRuleParser for TopLevelRuleParser<'a> {
if self.state.get() <= State::Namespaces { if self.state.get() <= State::Namespaces {
self.state.set(State::Namespaces); self.state.set(State::Namespaces);
let location = get_location_with_offset(input.current_source_location(),
self.context.line_number_offset);
let prefix_result = input.try(|input| input.expect_ident()); let prefix_result = input.try(|input| input.expect_ident());
let url = Namespace::from(try!(input.expect_url_or_string())); let url = Namespace::from(try!(input.expect_url_or_string()));

View file

@ -30,6 +30,7 @@ use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoElementBo
use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut}; use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyframeListBorrowedMut};
use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong}; use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong};
use style::gecko_bindings::bindings::{RawServoDocumentRule, RawServoDocumentRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoDocumentRule, RawServoDocumentRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoImportRule, RawServoImportRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframeBorrowed, RawServoKeyframeStrong}; use style::gecko_bindings::bindings::{RawServoKeyframe, RawServoKeyframeBorrowed, RawServoKeyframeStrong};
use style::gecko_bindings::bindings::{RawServoKeyframesRule, RawServoKeyframesRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoKeyframesRule, RawServoKeyframesRuleBorrowed};
use style::gecko_bindings::bindings::{RawServoMediaList, RawServoMediaListBorrowed, RawServoMediaListStrong}; use style::gecko_bindings::bindings::{RawServoMediaList, RawServoMediaListBorrowed, RawServoMediaListStrong};
@ -56,8 +57,8 @@ use style::gecko_bindings::bindings::RawGeckoServoStyleRuleListBorrowedMut;
use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed; use style::gecko_bindings::bindings::RawServoAnimationValueBorrowed;
use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowedMut; use style::gecko_bindings::bindings::RawServoAnimationValueMapBorrowedMut;
use style::gecko_bindings::bindings::RawServoAnimationValueStrong; use style::gecko_bindings::bindings::RawServoAnimationValueStrong;
use style::gecko_bindings::bindings::RawServoImportRuleBorrowed;
use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed; use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed;
use style::gecko_bindings::bindings::RawServoStyleSheet;
use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t;
use style::gecko_bindings::bindings::nsTimingFunctionBorrowed; use style::gecko_bindings::bindings::nsTimingFunctionBorrowed;
@ -988,6 +989,12 @@ impl_basic_rule_funcs! { (Style, StyleRule, RawServoStyleRule),
to_css: Servo_StyleRule_GetCssText, to_css: Servo_StyleRule_GetCssText,
} }
impl_basic_rule_funcs! { (Import, ImportRule, RawServoImportRule),
getter: Servo_CssRules_GetImportRuleAt,
debug: Servo_ImportRule_Debug,
to_css: Servo_ImportRule_GetCssText,
}
impl_basic_rule_funcs_without_getter! { (Keyframe, RawServoKeyframe), impl_basic_rule_funcs_without_getter! { (Keyframe, RawServoKeyframe),
debug: Servo_Keyframe_Debug, debug: Servo_Keyframe_Debug,
to_css: Servo_Keyframe_GetCssText, to_css: Servo_Keyframe_GetCssText,
@ -1077,6 +1084,20 @@ pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowe
}) })
} }
#[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 {
read_locked_arc(rule, |rule: &ImportRule| {
rule.stylesheet.as_borrowed_opt().unwrap() as *const _
})
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_Keyframe_GetKeyText(keyframe: RawServoKeyframeBorrowed, result: *mut nsAString) { pub extern "C" fn Servo_Keyframe_GetKeyText(keyframe: RawServoKeyframeBorrowed, result: *mut nsAString) {
read_locked_arc(keyframe, |keyframe: &Keyframe| { read_locked_arc(keyframe, |keyframe: &Keyframe| {
@ -2294,15 +2315,6 @@ pub extern "C" fn Servo_NoteExplicitHints(element: RawGeckoElementBorrowed,
} }
} }
#[no_mangle]
pub extern "C" fn Servo_ImportRule_GetSheet(import_rule:
RawServoImportRuleBorrowed)
-> RawServoStyleSheetStrong {
read_locked_arc(import_rule, |rule: &ImportRule| {
rule.stylesheet.clone().into_strong()
})
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_TakeChangeHint(element: RawGeckoElementBorrowed) -> nsChangeHint pub extern "C" fn Servo_TakeChangeHint(element: RawGeckoElementBorrowed) -> nsChangeHint
{ {