aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/stylesheet_loader.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-06-28 12:12:14 -0700
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-07-02 15:49:40 +0200
commit12630757762b99c509661ddb524daff0d153c423 (patch)
treeee752c55df7a8918f158486759850926dd31f969 /components/script/stylesheet_loader.rs
parentfd65ac8924dd75b1f80e2cf048f64e11d3387976 (diff)
downloadservo-12630757762b99c509661ddb524daff0d153c423.tar.gz
servo-12630757762b99c509661ddb524daff0d153c423.zip
stylo: Fix StyleSheetInner/Stylesheet mapping
The key of this patch is the split between Stylesheet and StylesheetContents. Gecko will use StylesheetContents, which maps to a ServoStyleSheetInner.
Diffstat (limited to 'components/script/stylesheet_loader.rs')
-rw-r--r--components/script/stylesheet_loader.rs49
1 files changed, 39 insertions, 10 deletions
diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs
index 4d2518a7cca..562e16d05ef 100644
--- a/components/script/stylesheet_loader.rs
+++ b/components/script/stylesheet_loader.rs
@@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+use cssparser::SourceLocation;
use document_loader::LoadType;
use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
@@ -22,14 +23,19 @@ use ipc_channel::router::ROUTER;
use net_traits::{FetchResponseListener, FetchMetadata, FilteredMetadata, Metadata, NetworkError, ReferrerPolicy};
use net_traits::request::{CorsSettings, CredentialsMode, Destination, RequestInit, RequestMode, Type as RequestType};
use network_listener::{NetworkListener, PreInvoke};
+use parking_lot::RwLock;
use servo_url::ServoUrl;
use std::mem;
use std::sync::Mutex;
+use std::sync::atomic::AtomicBool;
use style::media_queries::MediaList;
-use style::shared_lock::Locked as StyleLocked;
+use style::parser::ParserContext;
+use style::shared_lock::{Locked, SharedRwLock};
use style::stylearc::Arc;
-use style::stylesheets::{ImportRule, Stylesheet, Origin};
+use style::stylesheets::{CssRules, ImportRule, Namespaces, Stylesheet, StylesheetContents, Origin};
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
+use style::stylesheets::import_rule::ImportSheet;
+use style::values::specified::url::SpecifiedUrl;
pub trait StylesheetOwner {
/// Returns whether this element was inserted by the parser (i.e., it should
@@ -268,20 +274,43 @@ impl<'a> StylesheetLoader<'a> {
}
impl<'a> StyleStylesheetLoader for StylesheetLoader<'a> {
+ /// Request a stylesheet after parsing a given `@import` rule, and return
+ /// the constructed `@import` rule.
fn request_stylesheet(
&self,
- media: Arc<StyleLocked<MediaList>>,
- make_import: &mut FnMut(Arc<StyleLocked<MediaList>>) -> ImportRule,
- make_arc: &mut FnMut(ImportRule) -> Arc<StyleLocked<ImportRule>>,
- ) -> Arc<StyleLocked<ImportRule>> {
- let import = make_import(media);
- let url = import.url.url().expect("Invalid urls shouldn't enter the loader").clone();
+ url: SpecifiedUrl,
+ source_location: SourceLocation,
+ context: &ParserContext,
+ lock: &SharedRwLock,
+ media: Arc<Locked<MediaList>>,
+ ) -> Arc<Locked<ImportRule>> {
+ let sheet = Arc::new(Stylesheet {
+ contents: StylesheetContents {
+ rules: CssRules::new(Vec::new(), lock),
+ origin: context.stylesheet_origin,
+ url_data: RwLock::new(context.url_data.clone()),
+ dirty_on_viewport_size_change: AtomicBool::new(false),
+ quirks_mode: context.quirks_mode,
+ namespaces: RwLock::new(Namespaces::default()),
+ },
+ media: media,
+ shared_lock: lock.clone(),
+ disabled: AtomicBool::new(false),
+ });
+
+ let stylesheet = ImportSheet(sheet.clone());
+ let import = ImportRule { url, source_location, stylesheet };
+
+ let url = match import.url.url().cloned() {
+ Some(url) => url,
+ None => return Arc::new(lock.wrap(import)),
+ };
// TODO (mrnayak) : Whether we should use the original loader's CORS
// setting? Fix this when spec has more details.
- let source = StylesheetContextSource::Import(import.stylesheet.clone());
+ let source = StylesheetContextSource::Import(sheet.clone());
self.load(source, url, None, "".to_owned());
- make_arc(import)
+ Arc::new(lock.wrap(import))
}
}