Skip to content

Commit

Permalink
Handle properly alternate stylesheet
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesvdv committed Jan 10, 2017
1 parent 50bba77 commit 19e31d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 13 additions & 11 deletions components/script/dom/htmllinkelement.rs
Expand Up @@ -99,6 +99,17 @@ impl HTMLLinkElement {
})
})
}

pub fn is_alternate(&self) -> bool {
let rel = get_attr(self.upcast(), &local_name!("rel"));
match rel {
Some(ref value) => {
value.split(HTML_SPACE_CHARACTERS)
.any(|s| s.eq_ignore_ascii_case("alternate"))
},
None => false,
}
}
}

fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
Expand All @@ -112,17 +123,8 @@ fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
fn string_is_stylesheet(value: &Option<String>) -> bool {
match *value {
Some(ref value) => {
let mut found_stylesheet = false;
for s in value.split(HTML_SPACE_CHARACTERS).into_iter() {
if s.eq_ignore_ascii_case("alternate") {
return false;
}

if s.eq_ignore_ascii_case("stylesheet") {
found_stylesheet = true;
}
}
found_stylesheet
value.split(HTML_SPACE_CHARACTERS)
.any(|s| s.eq_ignore_ascii_case("stylesheet"))
},
None => false,
}
Expand Down
3 changes: 3 additions & 0 deletions components/script/stylesheet_loader.rs
Expand Up @@ -138,6 +138,9 @@ impl FetchResponseListener for StylesheetContext {
Some(&loader),
win.css_error_reporter(),
ParserContextExtraData::default()));
if elem.downcast::<HTMLLinkElement>().unwrap().is_alternate() {
sheet.set_disabled(true);
}
elem.downcast::<HTMLLinkElement>()
.unwrap()
.set_stylesheet(sheet.clone());
Expand Down

0 comments on commit 19e31d5

Please sign in to comment.