mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Unify media query and media query list parsing (#36520)
Several places were using identical logic in order to parse a media queries or media query lists. This patch centralizes the logic into 2 new helper methods in MediaList. Testing: not needed (no behavior change) Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
064f82d0a3
commit
cc04caa8ce
4 changed files with 64 additions and 123 deletions
|
@ -4,16 +4,13 @@
|
|||
|
||||
use std::cell::Cell;
|
||||
|
||||
use cssparser::{Parser as CssParser, ParserInput};
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix};
|
||||
use js::rust::HandleObject;
|
||||
use net_traits::ReferrerPolicy;
|
||||
use servo_arc::Arc;
|
||||
use style::media_queries::MediaList;
|
||||
use style::parser::ParserContext as CssParserContext;
|
||||
use style::stylesheets::{AllowImportRules, CssRuleType, Origin, Stylesheet, UrlExtraData};
|
||||
use style_traits::ParsingMode;
|
||||
use style::media_queries::MediaList as StyleMediaList;
|
||||
use style::stylesheets::{AllowImportRules, Origin, Stylesheet, UrlExtraData};
|
||||
|
||||
use crate::dom::attr::Attr;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
|
@ -26,6 +23,7 @@ use crate::dom::cssstylesheet::CSSStyleSheet;
|
|||
use crate::dom::document::Document;
|
||||
use crate::dom::element::{AttributeMutation, Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::medialist::MediaList;
|
||||
use crate::dom::node::{BindContext, ChildrenMutation, Node, NodeTraits, UnbindContext};
|
||||
use crate::dom::stylesheet::StyleSheet as DOMStyleSheet;
|
||||
use crate::dom::virtualmethods::VirtualMethods;
|
||||
|
@ -83,26 +81,9 @@ impl HTMLStyleElement {
|
|||
)
|
||||
}
|
||||
|
||||
fn create_media_list(&self, mq_str: &str) -> MediaList {
|
||||
if mq_str.is_empty() {
|
||||
return MediaList::empty();
|
||||
}
|
||||
|
||||
let window = self.owner_window();
|
||||
let doc = self.owner_document();
|
||||
let url_data = UrlExtraData(window.get_url().get_arc());
|
||||
let context = CssParserContext::new(
|
||||
Origin::Author,
|
||||
&url_data,
|
||||
Some(CssRuleType::Media),
|
||||
ParsingMode::DEFAULT,
|
||||
doc.quirks_mode(),
|
||||
/* namespaces = */ Default::default(),
|
||||
window.css_error_reporter(),
|
||||
None,
|
||||
);
|
||||
let mut input = ParserInput::new(mq_str);
|
||||
MediaList::parse(&context, &mut CssParser::new(&mut input))
|
||||
#[inline]
|
||||
fn create_media_list(&self, mq_str: &str) -> StyleMediaList {
|
||||
MediaList::parse_media_list(mq_str, &self.owner_window())
|
||||
}
|
||||
|
||||
pub(crate) fn parse_own_css(&self) {
|
||||
|
@ -279,7 +260,7 @@ impl VirtualMethods for HTMLStyleElement {
|
|||
let media = stylesheet.media.write_with(&mut guard);
|
||||
match mutation {
|
||||
AttributeMutation::Set(_) => *media = self.create_media_list(&attr.value()),
|
||||
AttributeMutation::Removed => *media = MediaList::empty(),
|
||||
AttributeMutation::Removed => *media = StyleMediaList::empty(),
|
||||
};
|
||||
self.owner_document().invalidate_stylesheets();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue