diff options
author | Paul Rouget <me@paulrouget.com> | 2018-04-11 16:04:07 +0800 |
---|---|---|
committer | Paul Rouget <me@paulrouget.com> | 2018-04-27 15:34:52 +0800 |
commit | 9fb5795f3720bc090b221ed0850fb95b24704cb7 (patch) | |
tree | 02ae3fa1c77a85930dec490d57e1c907b287a562 /components/layout_thread/lib.rs | |
parent | 21517504cb95c969e8eb9f5e97273b98f9237a7d (diff) | |
download | servo-9fb5795f3720bc090b221ed0850fb95b24704cb7.tar.gz servo-9fb5795f3720bc090b221ed0850fb95b24704cb7.zip |
delegate resource reading to embedder
Diffstat (limited to 'components/layout_thread/lib.rs')
-rw-r--r-- | components/layout_thread/lib.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index cdfa0f092c2..88c00faae84 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -9,6 +9,7 @@ extern crate app_units; extern crate atomic_refcell; +extern crate embedder_traits; extern crate euclid; extern crate fnv; extern crate gfx; @@ -55,6 +56,7 @@ mod dom_wrapper; use app_units::Au; use dom_wrapper::{ServoLayoutElement, ServoLayoutDocument, ServoLayoutNode}; use dom_wrapper::drop_style_and_layout_data; +use embedder_traits::resources::{self, Resource}; use euclid::{Point2D, Rect, Size2D, TypedScale, TypedSize2D}; use fnv::FnvHashMap; use gfx::display_list::{OpaqueNode, WebRenderImageInfo}; @@ -110,7 +112,6 @@ use servo_arc::Arc as ServoArc; use servo_atoms::Atom; use servo_config::opts; use servo_config::prefs::PREFS; -use servo_config::resource_files::read_resource_file; use servo_geometry::MaxRect; use servo_url::ServoUrl; use std::borrow::ToOwned; @@ -1740,11 +1741,11 @@ fn get_root_flow_background_color(flow: &mut Flow) -> webrender_api::ColorF { fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { fn parse_ua_stylesheet( shared_lock: &SharedRwLock, - filename: &'static str, + filename: &str, + content: &[u8], ) -> Result<DocumentStyleSheet, &'static str> { - let res = read_resource_file(filename).map_err(|_| filename)?; Ok(DocumentStyleSheet(ServoArc::new(Stylesheet::from_bytes( - &res, + content, ServoUrl::parse(&format!("chrome://resources/{:?}", filename)).unwrap(), None, None, @@ -1758,12 +1759,17 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { } let shared_lock = SharedRwLock::new(); - let mut user_or_user_agent_stylesheets = vec!(); // FIXME: presentational-hints.css should be at author origin with zero specificity. // (Does it make a difference?) - for &filename in &["user-agent.css", "servo.css", "presentational-hints.css"] { - user_or_user_agent_stylesheets.push(parse_ua_stylesheet(&shared_lock, filename)?); - } + let mut user_or_user_agent_stylesheets = vec![ + parse_ua_stylesheet(&shared_lock, "user-agent.css", + &resources::read_bytes(Resource::UserAgentCSS))?, + parse_ua_stylesheet(&shared_lock, "servo.css", + &resources::read_bytes(Resource::ServoCSS))?, + parse_ua_stylesheet(&shared_lock, "presentational-hints.css", + &resources::read_bytes(Resource::PresentationalHintsCSS))?, + ]; + for &(ref contents, ref url) in &opts::get().user_stylesheets { user_or_user_agent_stylesheets.push( DocumentStyleSheet(ServoArc::new(Stylesheet::from_bytes( @@ -1781,7 +1787,8 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> { ); } - let quirks_mode_stylesheet = parse_ua_stylesheet(&shared_lock, "quirks-mode.css")?; + let quirks_mode_stylesheet = parse_ua_stylesheet(&shared_lock, "quirks-mode.css", + &resources::read_bytes(Resource::QuirksModeCSS))?; Ok(UserAgentStylesheets { shared_lock: shared_lock, |