mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #14430 - julienw:access-quirks-mode-from-layout, r=emilio
Expose Quirks Mode information in the layout data and code <!-- Please describe your changes on the following line: --> This patch exposes the Quirks (NoQuirks/LimitedQuirks/Quirks) state to the layout subsystem. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). Prelimary work for issue #11704. <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ (Waiting for guidance of where/which tests I could do here) <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14430) <!-- Reviewable:end -->
This commit is contained in:
commit
164426a7f9
9 changed files with 58 additions and 25 deletions
|
@ -110,7 +110,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
|||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use std::thread;
|
||||
use style::animation::Animation;
|
||||
use style::context::{ReflowGoal, SharedStyleContext, ThreadLocalStyleContextCreationInfo};
|
||||
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, ThreadLocalStyleContextCreationInfo};
|
||||
use style::data::StoredRestyleHint;
|
||||
use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
|
||||
use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter};
|
||||
|
@ -233,6 +233,9 @@ pub struct LayoutThread {
|
|||
// Number of layout threads. This is copied from `servo_config::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 {
|
||||
|
@ -485,6 +488,7 @@ impl LayoutThread {
|
|||
Timer::new()
|
||||
},
|
||||
layout_threads: layout_threads,
|
||||
quirks_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -522,6 +526,7 @@ impl LayoutThread {
|
|||
error_reporter: self.error_reporter.clone(),
|
||||
local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
|
||||
timer: self.timer.clone(),
|
||||
quirks_mode: self.quirks_mode.unwrap(),
|
||||
},
|
||||
image_cache_thread: Mutex::new(self.image_cache_thread.clone()),
|
||||
image_cache_sender: Mutex::new(self.image_cache_sender.clone()),
|
||||
|
@ -977,6 +982,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 &&
|
||||
|
|
|
@ -48,7 +48,6 @@ use euclid::length::Length as EuclidLength;
|
|||
use euclid::rect::Rect;
|
||||
use euclid::size::Size2D;
|
||||
use html5ever::tokenizer::buffer_queue::BufferQueue;
|
||||
use html5ever::tree_builder::QuirksMode;
|
||||
use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
|
||||
use hyper::header::Headers;
|
||||
use hyper::method::Method;
|
||||
|
@ -92,6 +91,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize};
|
|||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::time::{SystemTime, Instant};
|
||||
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
|
||||
use style::context::QuirksMode;
|
||||
use style::element_state::*;
|
||||
use style::font_face::FontFaceRule;
|
||||
use style::keyframes::Keyframe;
|
||||
|
|
|
@ -91,7 +91,6 @@ use encoding::EncodingRef;
|
|||
use encoding::all::UTF_8;
|
||||
use euclid::point::Point2D;
|
||||
use gfx_traits::ScrollRootId;
|
||||
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks, QuirksMode};
|
||||
use html5ever_atoms::{LocalName, QualName};
|
||||
use hyper::header::{Header, SetCookie};
|
||||
use hyper_serde::Serde;
|
||||
|
@ -129,7 +128,7 @@ use std::rc::Rc;
|
|||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use style::attr::AttrValue;
|
||||
use style::context::ReflowGoal;
|
||||
use style::context::{QuirksMode, ReflowGoal};
|
||||
use style::restyle_hints::RestyleHint;
|
||||
use style::selector_parser::{RestyleDamage, Snapshot};
|
||||
use style::str::{split_html_space_chars, str_join};
|
||||
|
@ -490,7 +489,7 @@ impl Document {
|
|||
pub fn set_quirks_mode(&self, mode: QuirksMode) {
|
||||
self.quirks_mode.set(mode);
|
||||
|
||||
if mode == Quirks {
|
||||
if mode == QuirksMode::Quirks {
|
||||
self.window.layout_chan().send(Msg::SetQuirksMode).unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -1777,6 +1776,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)]
|
||||
|
@ -1803,6 +1803,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
|
||||
|
@ -1860,7 +1865,7 @@ impl Document {
|
|||
last_modified: last_modified,
|
||||
url: DOMRefCell::new(url),
|
||||
// https://dom.spec.whatwg.org/#concept-document-quirks
|
||||
quirks_mode: Cell::new(NoQuirks),
|
||||
quirks_mode: Cell::new(QuirksMode::NoQuirks),
|
||||
// https://dom.spec.whatwg.org/#concept-document-encoding
|
||||
encoding: Cell::new(UTF_8),
|
||||
is_html_document: is_html_document == IsHTMLDocument::HTMLDocument,
|
||||
|
@ -2303,8 +2308,8 @@ impl DocumentMethods for Document {
|
|||
// https://dom.spec.whatwg.org/#dom-document-compatmode
|
||||
fn CompatMode(&self) -> DOMString {
|
||||
DOMString::from(match self.quirks_mode.get() {
|
||||
LimitedQuirks | NoQuirks => "CSS1Compat",
|
||||
Quirks => "BackCompat",
|
||||
QuirksMode::LimitedQuirks | QuirksMode::NoQuirks => "CSS1Compat",
|
||||
QuirksMode::Quirks => "BackCompat",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,6 @@ use html5ever::serialize;
|
|||
use html5ever::serialize::SerializeOpts;
|
||||
use html5ever::serialize::TraversalScope;
|
||||
use html5ever::serialize::TraversalScope::{ChildrenOnly, IncludeNode};
|
||||
use html5ever::tree_builder::{LimitedQuirks, NoQuirks, Quirks};
|
||||
use html5ever_atoms::{Prefix, LocalName, Namespace, QualName};
|
||||
use js::jsapi::{HandleValue, JSAutoCompartment};
|
||||
use parking_lot::RwLock;
|
||||
|
@ -98,7 +97,7 @@ use std::rc::Rc;
|
|||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
|
||||
use style::context::ReflowGoal;
|
||||
use style::context::{QuirksMode, ReflowGoal};
|
||||
use style::element_state::*;
|
||||
use style::matching::{common_style_affecting_attributes, rare_style_affecting_attributes};
|
||||
use style::parser::ParserContextExtraData;
|
||||
|
@ -1084,8 +1083,8 @@ impl Element {
|
|||
let quirks_mode = document_from_node(self).quirks_mode();
|
||||
let is_equal = |lhs: &Atom, rhs: &Atom| {
|
||||
match quirks_mode {
|
||||
NoQuirks | LimitedQuirks => lhs == rhs,
|
||||
Quirks => lhs.eq_ignore_ascii_case(&rhs),
|
||||
QuirksMode::NoQuirks | QuirksMode::LimitedQuirks => lhs == rhs,
|
||||
QuirksMode::Quirks => lhs.eq_ignore_ascii_case(&rhs),
|
||||
}
|
||||
};
|
||||
self.get_attribute(&ns!(), &local_name!("class"))
|
||||
|
@ -1265,7 +1264,7 @@ impl Element {
|
|||
|
||||
// Step 7
|
||||
if *self.root_element() == *self {
|
||||
if doc.quirks_mode() != Quirks {
|
||||
if doc.quirks_mode() != QuirksMode::Quirks {
|
||||
win.scroll(x, y, behavior);
|
||||
}
|
||||
|
||||
|
@ -1274,7 +1273,7 @@ impl Element {
|
|||
|
||||
// Step 9
|
||||
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
|
||||
doc.quirks_mode() == Quirks &&
|
||||
doc.quirks_mode() == QuirksMode::Quirks &&
|
||||
!self.potentially_scrollable() {
|
||||
win.scroll(x, y, behavior);
|
||||
return;
|
||||
|
@ -1645,7 +1644,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 5
|
||||
if *self.root_element() == *self {
|
||||
if doc.quirks_mode() == Quirks {
|
||||
if doc.quirks_mode() == QuirksMode::Quirks {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
|
@ -1655,7 +1654,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 7
|
||||
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
|
||||
doc.quirks_mode() == Quirks &&
|
||||
doc.quirks_mode() == QuirksMode::Quirks &&
|
||||
!self.potentially_scrollable() {
|
||||
return win.ScrollY() as f64;
|
||||
}
|
||||
|
@ -1696,7 +1695,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 7
|
||||
if *self.root_element() == *self {
|
||||
if doc.quirks_mode() != Quirks {
|
||||
if doc.quirks_mode() != QuirksMode::Quirks {
|
||||
win.scroll(win.ScrollX() as f64, y, behavior);
|
||||
}
|
||||
|
||||
|
@ -1705,7 +1704,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 9
|
||||
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
|
||||
doc.quirks_mode() == Quirks &&
|
||||
doc.quirks_mode() == QuirksMode::Quirks &&
|
||||
!self.potentially_scrollable() {
|
||||
win.scroll(win.ScrollX() as f64, y, behavior);
|
||||
return;
|
||||
|
@ -1737,7 +1736,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 5
|
||||
if *self.root_element() == *self {
|
||||
if doc.quirks_mode() != Quirks {
|
||||
if doc.quirks_mode() != QuirksMode::Quirks {
|
||||
// Step 6
|
||||
return win.ScrollX() as f64;
|
||||
}
|
||||
|
@ -1747,7 +1746,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 7
|
||||
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
|
||||
doc.quirks_mode() == Quirks &&
|
||||
doc.quirks_mode() == QuirksMode::Quirks &&
|
||||
!self.potentially_scrollable() {
|
||||
return win.ScrollX() as f64;
|
||||
}
|
||||
|
@ -1788,7 +1787,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 7
|
||||
if *self.root_element() == *self {
|
||||
if doc.quirks_mode() == Quirks {
|
||||
if doc.quirks_mode() == QuirksMode::Quirks {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1798,7 +1797,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// Step 9
|
||||
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
|
||||
doc.quirks_mode() == Quirks &&
|
||||
doc.quirks_mode() == QuirksMode::Quirks &&
|
||||
!self.potentially_scrollable() {
|
||||
win.scroll(x, win.ScrollY() as f64, behavior);
|
||||
return;
|
||||
|
|
|
@ -57,7 +57,6 @@ use euclid::point::Point2D;
|
|||
use euclid::rect::Rect;
|
||||
use euclid::size::Size2D;
|
||||
use heapsize::{HeapSizeOf, heap_size_of};
|
||||
use html5ever::tree_builder::QuirksMode;
|
||||
use html5ever_atoms::{Prefix, Namespace, QualName};
|
||||
use js::jsapi::{JSContext, JSObject, JSRuntime};
|
||||
use libc::{self, c_void, uintptr_t};
|
||||
|
@ -78,6 +77,7 @@ use std::iter;
|
|||
use std::mem;
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
use style::context::QuirksMode;
|
||||
use style::dom::OpaqueNode;
|
||||
use style::selector_parser::{SelectorImpl, SelectorParser};
|
||||
use style::stylesheets::Stylesheet;
|
||||
|
|
|
@ -34,6 +34,7 @@ use js::jsapi::JSTracer;
|
|||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::io::{self, Write};
|
||||
use style::context::QuirksMode as ServoQuirksMode;
|
||||
|
||||
#[derive(HeapSizeOf, JSTraceable)]
|
||||
#[must_root]
|
||||
|
@ -187,6 +188,11 @@ impl<'a> TreeSink for Sink {
|
|||
}
|
||||
|
||||
fn set_quirks_mode(&mut self, mode: QuirksMode) {
|
||||
let mode = match mode {
|
||||
QuirksMode::Quirks => ServoQuirksMode::Quirks,
|
||||
QuirksMode::LimitedQuirks => ServoQuirksMode::LimitedQuirks,
|
||||
QuirksMode::NoQuirks => ServoQuirksMode::NoQuirks,
|
||||
};
|
||||
self.document.set_quirks_mode(mode);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ use std::sync::atomic::Ordering;
|
|||
use style::atomic_refcell::AtomicRefCell;
|
||||
use style::attr::AttrValue;
|
||||
use style::computed_values::display;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::context::{QuirksMode, SharedStyleContext};
|
||||
use style::data::ElementData;
|
||||
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TElement, TNode};
|
||||
use style::dom::UnsafeNode;
|
||||
|
@ -321,6 +321,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,
|
||||
|
|
|
@ -31,6 +31,14 @@ impl ThreadLocalStyleContextCreationInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum QuirksMode {
|
||||
Quirks,
|
||||
LimitedQuirks,
|
||||
NoQuirks,
|
||||
}
|
||||
|
||||
pub struct SharedStyleContext {
|
||||
/// The current viewport size.
|
||||
pub viewport_size: Size2D<Au>,
|
||||
|
@ -63,6 +71,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 ThreadLocalStyleContext {
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::ptr;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use style::arc_ptr_eq;
|
||||
use style::atomic_refcell::AtomicRefMut;
|
||||
use style::context::{ThreadLocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext, StyleContext};
|
||||
use style::context::{ThreadLocalStyleContextCreationInfo, QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
||||
use style::data::{ElementData, RestyleData};
|
||||
use style::dom::{ShowSubtreeData, TElement, TNode};
|
||||
use style::error_reporting::StdoutErrorReporter;
|
||||
|
@ -114,6 +114,8 @@ fn create_shared_context(mut per_doc_data: &mut AtomicRefMut<PerDocumentStyleDat
|
|||
error_reporter: Box::new(StdoutErrorReporter),
|
||||
local_context_creation_data: Mutex::new(local_context_data),
|
||||
timer: Timer::new(),
|
||||
// FIXME Find the real QuirksMode information for this document
|
||||
quirks_mode: QuirksMode::NoQuirks,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue