From c37a345dc9f4dda6ea29c42f96f6c7201c42cbac Mon Sep 17 00:00:00 2001 From: chansuke Date: Tue, 18 Sep 2018 23:24:15 +0900 Subject: Format script component --- components/script/stylesheet_loader.rs | 139 ++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 55 deletions(-) (limited to 'components/script/stylesheet_loader.rs') diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index 156d2577656..8ae75a6e35b 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -59,7 +59,7 @@ pub trait StylesheetOwner { pub enum StylesheetContextSource { // NB: `media` is just an option so we avoid cloning it. - LinkElement { media: Option, }, + LinkElement { media: Option }, Import(Arc), } @@ -87,23 +87,19 @@ impl FetchResponseListener for StylesheetContext { fn process_request_eof(&mut self) {} - fn process_response(&mut self, - metadata: Result) { + fn process_response(&mut self, metadata: Result) { if let Ok(FetchMetadata::Filtered { ref filtered, .. }) = metadata { match *filtered { - FilteredMetadata::Opaque | - FilteredMetadata::OpaqueRedirect => { + FilteredMetadata::Opaque | FilteredMetadata::OpaqueRedirect => { self.origin_clean = false; }, _ => {}, } } - self.metadata = metadata.ok().map(|m| { - match m { - FetchMetadata::Unfiltered(m) => m, - FetchMetadata::Filtered { unsafe_, .. } => unsafe_ - } + self.metadata = metadata.ok().map(|m| match m { + FetchMetadata::Unfiltered(m) => m, + FetchMetadata::Filtered { unsafe_, .. } => unsafe_, }); } @@ -121,10 +117,18 @@ impl FetchResponseListener for StylesheetContext { Some(meta) => meta, None => return, }; - let is_css = metadata.content_type.map_or(false, |Serde(ContentType(Mime(top, sub, _)))| - top == TopLevel::Text && sub == SubLevel::Css); - - let data = if is_css { mem::replace(&mut self.data, vec![]) } else { vec![] }; + let is_css = + metadata + .content_type + .map_or(false, |Serde(ContentType(Mime(top, sub, _)))| { + top == TopLevel::Text && sub == SubLevel::Css + }); + + let data = if is_css { + mem::replace(&mut self.data, vec![]) + } else { + vec![] + }; // TODO: Get the actual value. http://dev.w3.org/csswg/css-syntax/#environment-encoding let environment_encoding = UTF_8; @@ -139,20 +143,23 @@ impl FetchResponseListener for StylesheetContext { let link = elem.downcast::().unwrap(); // We must first check whether the generations of the context and the element match up, // else we risk applying the wrong stylesheet when responses come out-of-order. - let is_stylesheet_load_applicable = - self.request_generation_id.map_or(true, |gen| gen == link.get_request_generation_id()); + let is_stylesheet_load_applicable = self + .request_generation_id + .map_or(true, |gen| gen == link.get_request_generation_id()); if is_stylesheet_load_applicable { let shared_lock = document.style_shared_lock().clone(); - let sheet = - Arc::new(Stylesheet::from_bytes(&data, final_url, - protocol_encoding_label, - Some(environment_encoding), - Origin::Author, - media.take().unwrap(), - shared_lock, - Some(&loader), - win.css_error_reporter(), - document.quirks_mode())); + let sheet = Arc::new(Stylesheet::from_bytes( + &data, + final_url, + protocol_encoding_label, + Some(environment_encoding), + Origin::Author, + media.take().unwrap(), + shared_lock, + Some(&loader), + win.css_error_reporter(), + document.quirks_mode(), + )); if link.is_alternate() { sheet.set_disabled(true); @@ -160,16 +167,18 @@ impl FetchResponseListener for StylesheetContext { link.set_stylesheet(sheet); } - } + }, StylesheetContextSource::Import(ref stylesheet) => { - Stylesheet::update_from_bytes(&stylesheet, - &data, - protocol_encoding_label, - Some(environment_encoding), - final_url, - Some(&loader), - win.css_error_reporter()); - } + Stylesheet::update_from_bytes( + &stylesheet, + &data, + protocol_encoding_label, + Some(environment_encoding), + final_url, + Some(&loader), + win.css_error_reporter(), + ); + }, } document.invalidate_stylesheets(); @@ -179,7 +188,9 @@ impl FetchResponseListener for StylesheetContext { successful = metadata.status.map_or(false, |(code, _)| code == 200); } - let owner = elem.upcast::().as_stylesheet_owner() + let owner = elem + .upcast::() + .as_stylesheet_owner() .expect("Stylesheet not loaded by