diff options
author | Till Schneidereit <till@tillschneidereit.net> | 2015-10-06 15:55:28 +0200 |
---|---|---|
committer | Till Schneidereit <till@tillschneidereit.net> | 2015-11-07 18:11:29 +0100 |
commit | 543703e3d8d7dde5efd280fb01e42061287c7002 (patch) | |
tree | 3b36ac6d5b08f842035f7f9b2eed16b94aeb0d28 /components/script/layout_interface.rs | |
parent | 068e6a8e9f926fa6e8649b934ee9ffe2ef7b78de (diff) | |
download | servo-543703e3d8d7dde5efd280fb01e42061287c7002.tar.gz servo-543703e3d8d7dde5efd280fb01e42061287c7002.zip |
Move Stylesheet loading and ownership from the layout task into HTML elements
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Diffstat (limited to 'components/script/layout_interface.rs')
-rw-r--r-- | components/script/layout_interface.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/components/script/layout_interface.rs b/components/script/layout_interface.rs index afc7adedbd3..f6d96f1f09f 100644 --- a/components/script/layout_interface.rs +++ b/components/script/layout_interface.rs @@ -16,32 +16,24 @@ use msg::compositor_msg::Epoch; use msg::compositor_msg::LayerId; use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId}; use msg::constellation_msg::{WindowSizeData}; -use net_traits::PendingAsyncLoad; use net_traits::image_cache_task::ImageCacheTask; use profile_traits::mem::ReportsChan; use script_traits::{ConstellationControlMsg, LayoutControlMsg}; -use script_traits::{OpaqueScriptLayoutChannel, StylesheetLoadResponder, UntrustedNodeAddress}; +use script_traits::{OpaqueScriptLayoutChannel, UntrustedNodeAddress}; use selectors::parser::PseudoElement; use std::any::Any; +use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender, channel}; use string_cache::Atom; use style::animation::PropertyAnimation; -use style::media_queries::MediaQueryList; use style::stylesheets::Stylesheet; -use style::viewport::ViewportRule; use url::Url; pub use dom::node::TrustedNodeAddress; /// Asynchronous messages that script can send to layout. pub enum Msg { /// Adds the given stylesheet to the document. - AddStylesheet(Stylesheet, MediaQueryList), - - /// Adds the given stylesheet to the document. - LoadStylesheet(Url, MediaQueryList, PendingAsyncLoad, Box<StylesheetLoadResponder + Send>), - - /// Adds a @viewport rule (translated from a <META name="viewport"> element) to the document. - AddMetaViewport(ViewportRule), + AddStylesheet(Arc<Stylesheet>), /// Puts a document into quirks mode, causing the quirks mode stylesheet to be loaded. SetQuirksMode, @@ -175,6 +167,10 @@ pub struct ScriptReflow { pub reflow_info: Reflow, /// The document node. pub document: TrustedNodeAddress, + /// The document's list of stylesheets. + pub document_stylesheets: Vec<Arc<Stylesheet>>, + /// Whether the document's stylesheets have changed since the last script reflow. + pub stylesheets_changed: bool, /// The current window size. pub window_size: WindowSizeData, /// The channel that we send a notification to. |