diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index deda7d481c7..d187aa1a37f 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -40,7 +40,7 @@ use script::layout_interface::{ContentBoxesQuery, ContentBoxQuery, ExitNowMsg, G use script::layout_interface::{HitTestResponse, LayoutChan, LayoutRPC, LoadStylesheetMsg}; use script::layout_interface::{MouseOverResponse, Msg, NoQuery, PrepareToExitMsg}; use script::layout_interface::{ReapLayoutDataMsg, Reflow, ReflowForDisplay, ReflowMsg}; -use script::layout_interface::{ScriptLayoutChan, TrustedNodeAddress}; +use script::layout_interface::{ScriptLayoutChan, SetQuirksModeMsg, TrustedNodeAddress}; use script_traits::{SendEventMsg, ReflowEvent, ReflowCompleteMsg, OpaqueScriptLayoutChannel}; use script_traits::{ScriptControlChan, UntrustedNodeAddress}; use servo_msg::compositor_msg::Scrollable; @@ -390,6 +390,7 @@ impl LayoutTask { match request { AddStylesheetMsg(sheet) => self.handle_add_stylesheet(sheet, possibly_locked_rw_data), LoadStylesheetMsg(url) => self.handle_load_stylesheet(url, possibly_locked_rw_data), + SetQuirksModeMsg => self.handle_set_quirks_mode(possibly_locked_rw_data), GetRPCMsg(response_chan) => { response_chan.send(box LayoutRPCImpl(self.rw_data.clone()) as Box); @@ -500,6 +501,15 @@ impl LayoutTask { LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data); } + /// Sets quirks mode for the document, causing the quirks mode stylesheet to be loaded. + fn handle_set_quirks_mode<'a>(&'a self, + possibly_locked_rw_data: + &mut Option>) { + let mut rw_data = self.lock_rw_data(possibly_locked_rw_data); + rw_data.stylist.add_quirks_mode_stylesheet(); + LayoutTask::return_rw_data(possibly_locked_rw_data, rw_data); + } + /// Retrieves the flow tree root from the root node. fn try_get_layout_root(&self, node: LayoutNode) -> Option { let mut layout_data_ref = node.mutate_layout_data(); diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index c4dc787ac26..4fdb8a9befd 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -61,6 +61,7 @@ use servo_util::namespace; use servo_util::str::{DOMString, split_html_space_chars}; use html5ever::tree_builder::{QuirksMode, NoQuirks, LimitedQuirks, Quirks}; +use layout_interface::{LayoutChan, SetQuirksModeMsg}; use string_cache::{Atom, QualName}; use url::Url; @@ -217,6 +218,15 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { fn set_quirks_mode(self, mode: QuirksMode) { self.quirks_mode.set(mode); + + match mode { + Quirks => { + let window = self.window.root(); + let LayoutChan(ref layout_chan) = window.page().layout_chan; + layout_chan.send(SetQuirksModeMsg); + } + NoQuirks | LimitedQuirks => {} + } } fn set_last_modified(self, value: DOMString) { diff --git a/components/script/layout_interface.rs b/components/script/layout_interface.rs index c3afb15c057..0f3f4fbacbf 100644 --- a/components/script/layout_interface.rs +++ b/components/script/layout_interface.rs @@ -29,6 +29,9 @@ pub enum Msg { /// Adds the given stylesheet to the document. LoadStylesheetMsg(Url), + /// Puts a document into quirks mode, causing the quirks mode stylesheet to be loaded. + SetQuirksModeMsg, + /// Requests a reflow. ReflowMsg(Box), diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 6d868028894..1e1acaf918a 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -292,7 +292,6 @@ impl Stylist { after_map: PerPseudoElementSelectorMap::new(), rules_source_order: 0u, }; - // FIXME: Add quirks-mode.css in quirks mode. // FIXME: Add iso-8859-9.css when the document’s encoding is ISO-8859-8. // FIXME: presentational-hints.css should be at author origin with zero specificity. // (Does it make a difference?) @@ -388,6 +387,15 @@ impl Stylist { self.is_dirty |= is_dirty; } + pub fn add_quirks_mode_stylesheet(&mut self) { + self.add_stylesheet(Stylesheet::from_bytes( + read_resource_file(["quirks-mode.css"]).unwrap().as_slice(), + Url::parse("chrome:///quirks-mode.css").unwrap(), + None, + None, + UserAgentOrigin)) + } + pub fn add_stylesheet(&mut self, stylesheet: Stylesheet) { self.stylesheets.push(stylesheet); self.is_dirty = true;