Skip to content

Commit

Permalink
Expose Quirks Mode information in the layout context
Browse files Browse the repository at this point in the history
  • Loading branch information
julienw committed Dec 2, 2016
1 parent a913815 commit ab73ef6
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/layout_thread/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
heapsize = "0.3.0"
heapsize_derive = "0.1"
html5ever = {version = "0.10.2", features = ["heap_size", "unstable"]}
ipc-channel = "0.5"
layout = {path = "../layout"}
layout_traits = {path = "../layout_traits"}
Expand Down
8 changes: 8 additions & 0 deletions components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern crate gfx;
extern crate gfx_traits;
extern crate heapsize;
#[macro_use] extern crate heapsize_derive;
extern crate html5ever;
extern crate ipc_channel;
#[macro_use]
extern crate layout;
Expand Down Expand Up @@ -58,6 +59,7 @@ use gfx::font_cache_thread::FontCacheThread;
use gfx::font_context;
use gfx_traits::{Epoch, FragmentType, ScrollRootId};
use heapsize::HeapSizeOf;
use html5ever::tree_builder::QuirksMode;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout::animation;
Expand Down Expand Up @@ -228,6 +230,9 @@ pub struct LayoutThread {
// Number of layout threads. This is copied from `util::opts`, but we'd
// rather limit the dependency on that module here.
layout_threads: usize,

/// Which quirks mode are we rendering the document in?
quirks_mode: Option<QuirksMode>
}

impl LayoutThreadFactory for LayoutThread {
Expand Down Expand Up @@ -481,6 +486,7 @@ impl LayoutThread {
Timer::new()
},
layout_threads: layout_threads,
quirks_mode: None,
}
}

Expand Down Expand Up @@ -517,6 +523,7 @@ impl LayoutThread {
error_reporter: self.error_reporter.clone(),
local_context_creation_data: Mutex::new(local_style_context_creation_data),
timer: self.timer.clone(),
quirks_mode: self.quirks_mode.unwrap_or(QuirksMode::NoQuirks),
},
image_cache_thread: Mutex::new(self.image_cache_thread.clone()),
image_cache_sender: Mutex::new(self.image_cache_sender.clone()),
Expand Down Expand Up @@ -971,6 +978,7 @@ impl LayoutThread {
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
let document = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap();
self.quirks_mode = Some(document.quirks_mode());

// FIXME(pcwalton): Combine `ReflowGoal` and `ReflowQueryType`. Then remove this assert.
debug_assert!((data.reflow_info.goal == ReflowGoal::ForDisplay &&
Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,7 @@ pub trait LayoutDocumentHelpers {
unsafe fn drain_pending_restyles(&self) -> Vec<(LayoutJS<Element>, PendingRestyle)>;
unsafe fn needs_paint_from_layout(&self);
unsafe fn will_paint(&self);
unsafe fn quirks_mode(&self) -> QuirksMode;
}

#[allow(unsafe_code)]
Expand All @@ -1768,6 +1769,11 @@ impl LayoutDocumentHelpers for LayoutJS<Document> {
unsafe fn will_paint(&self) {
(*self.unsafe_get()).needs_paint.set(false)
}

#[inline]
unsafe fn quirks_mode(&self) -> QuirksMode {
(*self.unsafe_get()).quirks_mode()
}
}

/// https://url.spec.whatwg.org/#network-scheme
Expand Down
5 changes: 5 additions & 0 deletions components/script/layout_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use dom::node::{CAN_BE_FRAGMENTED, DIRTY_ON_VIEWPORT_SIZE_CHANGE, HAS_DIRTY_DESC
use dom::node::{LayoutNodeHelpers, Node};
use dom::text::Text;
use gfx_traits::ByteIndex;
use html5ever::tree_builder::QuirksMode;
use html5ever_atoms::{LocalName, Namespace};
use msg::constellation_msg::PipelineId;
use parking_lot::RwLock;
Expand Down Expand Up @@ -374,6 +375,10 @@ impl<'ld> ServoLayoutDocument<'ld> {
unsafe { self.document.will_paint(); }
}

pub fn quirks_mode(&self) -> QuirksMode {
unsafe { self.document.quirks_mode() }
}

pub fn from_layout_js(doc: LayoutJS<Document>) -> ServoLayoutDocument<'ld> {
ServoLayoutDocument {
document: doc,
Expand Down
1 change: 1 addition & 0 deletions components/style/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ euclid = "0.10.1"
fnv = "1.0"
heapsize = "0.3.0"
heapsize_derive = {version = "0.1", optional = true}
html5ever = {version = "0.10.2", features = ["heap_size", "unstable"]}
html5ever-atoms = {version = "0.1", optional = true}
lazy_static = "0.2"
log = "0.3.5"
Expand Down
4 changes: 4 additions & 0 deletions components/style/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use app_units::Au;
use dom::OpaqueNode;
use error_reporting::ParseErrorReporter;
use euclid::Size2D;
use html5ever::tree_builder::QuirksMode;
use matching::StyleSharingCandidateCache;
use parking_lot::RwLock;
use std::cell::RefCell;
Expand Down Expand Up @@ -71,6 +72,9 @@ pub struct SharedStyleContext {
/// The current timer for transitions and animations. This is needed to test
/// them.
pub timer: Timer,

/// The QuirksMode state which the document needs to be rendered with
pub quirks_mode: QuirksMode,
}

pub struct LocalStyleContext {
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern crate fnv;
#[cfg(feature = "gecko")] #[macro_use] pub mod gecko_string_cache;
extern crate heapsize;
#[cfg(feature = "servo")] #[macro_use] extern crate heapsize_derive;
extern crate html5ever;
#[cfg(feature = "servo")] #[macro_use] extern crate html5ever_atoms;
#[allow(unused_extern_crates)]
#[macro_use]
Expand Down

0 comments on commit ab73ef6

Please sign in to comment.