diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index d67b1c8d23e..9e8cc9bc165 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -418,7 +418,7 @@ impl LayoutThread { let font_cache_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_font_cache_receiver); - let stylist = Stylist::new(device); + let stylist = Stylist::new(device, QuirksMode::NoQuirks); let outstanding_web_fonts_counter = Arc::new(AtomicUsize::new(0)); let ua_stylesheets = &*UA_STYLESHEETS; let guard = ua_stylesheets.shared_lock.read(); diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 8376587d5ac..8c6ca283aa9 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -689,6 +689,7 @@ mod bindings { "nsCursorImage", "nsFont", "nsIAtom", + "nsCompatibility", "nsMediaFeature", "nsRestyleHint", "nsStyleBackground", diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index d8397ddeb93..bf71114da37 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -9,6 +9,7 @@ use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use dom::OpaqueNode; use gecko_bindings::bindings::RawServoStyleSet; use gecko_bindings::structs::RawGeckoPresContextOwned; +use gecko_bindings::structs::nsIDocument; use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use media_queries::Device; use parking_lot::RwLock; @@ -56,11 +57,14 @@ impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. pub fn new(pres_context: RawGeckoPresContextOwned) -> Self { let device = Device::new(pres_context); + let quirks_mode = unsafe { + (*(*device.pres_context).mDocument.raw::()).mCompatMode + }; let (new_anims_sender, new_anims_receiver) = channel(); PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl { - stylist: Stylist::new(device), + stylist: Stylist::new(device, quirks_mode.into()), stylesheets: StylesheetSet::new(), new_animations_sender: new_anims_sender, new_animations_receiver: new_anims_receiver, diff --git a/components/style/gecko/generated/bindings.rs b/components/style/gecko/generated/bindings.rs index c365ff677a1..410c35b9b06 100644 --- a/components/style/gecko/generated/bindings.rs +++ b/components/style/gecko/generated/bindings.rs @@ -53,6 +53,7 @@ use gecko_bindings::structs::nsChangeHint; use gecko_bindings::structs::nsCursorImage; use gecko_bindings::structs::nsFont; use gecko_bindings::structs::nsIAtom; +use gecko_bindings::structs::nsCompatibility; use gecko_bindings::structs::nsMediaFeature; use gecko_bindings::structs::nsRestyleHint; use gecko_bindings::structs::nsStyleBackground; @@ -1949,7 +1950,8 @@ extern "C" { } extern "C" { pub fn Servo_ParseStyleAttribute(data: *const nsACString, - extra_data: *mut RawGeckoURLExtraData) + extra_data: *mut RawGeckoURLExtraData, + quirks_mode: nsCompatibility) -> RawServoDeclarationBlockStrong; } extern "C" { diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 150074770b8..7c2f47b4273 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -336,8 +336,9 @@ impl<'le> fmt::Debug for GeckoElement<'le> { impl<'le> GeckoElement<'le> { /// Parse the style attribute of an element. pub fn parse_style_attribute(value: &str, - url_data: &UrlExtraData) -> PropertyDeclarationBlock { - parse_style_attribute(value, url_data, &RustLogReporter, QuirksMode::NoQuirks) + url_data: &UrlExtraData, + quirks_mode: QuirksMode) -> PropertyDeclarationBlock { + parse_style_attribute(value, url_data, &RustLogReporter, quirks_mode) } fn flags(&self) -> u32 { diff --git a/components/style/gecko_bindings/sugar/mod.rs b/components/style/gecko_bindings/sugar/mod.rs index 1c004c8fcc1..f241c94810b 100644 --- a/components/style/gecko_bindings/sugar/mod.rs +++ b/components/style/gecko_bindings/sugar/mod.rs @@ -5,6 +5,7 @@ //! Rust sugar and convenience methods for Gecko types. mod ns_com_ptr; +mod ns_compatibility; mod ns_css_shadow_array; pub mod ns_css_value; mod ns_style_auto_array; diff --git a/components/style/gecko_bindings/sugar/ns_compatibility.rs b/components/style/gecko_bindings/sugar/ns_compatibility.rs new file mode 100644 index 00000000000..3fe63391d36 --- /dev/null +++ b/components/style/gecko_bindings/sugar/ns_compatibility.rs @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//! Little helper for `nsCompatibility`. + +use context::QuirksMode; +use gecko_bindings::structs::nsCompatibility; + +impl From for QuirksMode { + fn from(mode: nsCompatibility) -> QuirksMode { + match mode { + nsCompatibility::eCompatibility_FullStandards => QuirksMode::NoQuirks, + nsCompatibility::eCompatibility_AlmostStandards => QuirksMode::LimitedQuirks, + nsCompatibility::eCompatibility_NavQuirks => QuirksMode::Quirks, + } + } +} diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 2cec8f59778..b929777bd2f 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -189,16 +189,17 @@ impl<'a> ExtraStyleData<'a> { } impl Stylist { - /// Construct a new `Stylist`, using a given `Device`. If more members are - /// added here, think about whether they should be reset in clear(). + /// Construct a new `Stylist`, using given `Device` and `QuirksMode`. + /// If more members are added here, think about whether they should + /// be reset in clear(). #[inline] - pub fn new(device: Device) -> Self { + pub fn new(device: Device, quirks_mode: QuirksMode) -> Self { let mut stylist = Stylist { viewport_constraints: None, device: Arc::new(device), is_device_dirty: true, is_cleared: true, - quirks_mode: QuirksMode::NoQuirks, + quirks_mode: quirks_mode, element_map: PerPseudoElementSelectorMap::new(), pseudos_map: Default::default(), @@ -778,6 +779,11 @@ impl Stylist { self.viewport_constraints.as_ref() } + /// Returns the Quirks Mode of the document. + pub fn quirks_mode(&self) -> QuirksMode { + self.quirks_mode + } + /// Sets the quirks mode of the document. pub fn set_quirks_mode(&mut self, quirks_mode: QuirksMode) { // FIXME(emilio): We don't seem to change the quirks mode dynamically diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 0b209849aae..ebe498946c9 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -65,6 +65,7 @@ use style::gecko_bindings::structs::RawGeckoPresContextOwned; use style::gecko_bindings::structs::ServoElementSnapshotTable; use style::gecko_bindings::structs::URLExtraData; use style::gecko_bindings::structs::nsCSSValueSharedList; +use style::gecko_bindings::structs::nsCompatibility; use style::gecko_bindings::structs::nsresult; use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasFFI, HasArcFFI, HasBoxFFI}; use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong}; @@ -162,8 +163,7 @@ fn create_shared_context<'a>(global_style_data: &GlobalStyleData, guards: StylesheetGuards::same(guard), error_reporter: &DEFAULT_ERROR_REPORTER, timer: Timer::new(), - // FIXME Find the real QuirksMode information for this document - quirks_mode: QuirksMode::NoQuirks, + quirks_mode: per_doc_data.stylist.quirks_mode(), traversal_flags: traversal_flags, snapshot_map: snapshot_map, } @@ -1192,13 +1192,14 @@ pub extern "C" fn Servo_ParseEasing(easing: *const nsAString, #[no_mangle] pub extern "C" fn Servo_ParseStyleAttribute(data: *const nsACString, - raw_extra_data: *mut URLExtraData) + raw_extra_data: *mut URLExtraData, + quirks_mode: nsCompatibility) -> RawServoDeclarationBlockStrong { let global_style_data = &*GLOBAL_STYLE_DATA; let value = unsafe { data.as_ref().unwrap().as_str_unchecked() }; let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) }; Arc::new(global_style_data.shared_lock.wrap( - GeckoElement::parse_style_attribute(value, url_data))).into_strong() + GeckoElement::parse_style_attribute(value, url_data, quirks_mode.into()))).into_strong() } #[no_mangle] @@ -2071,7 +2072,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(keyframes: RawGeckoKeyframeLis font_metrics_provider: &metrics, cached_system_font: None, in_media_query: false, - quirks_mode: QuirksMode::NoQuirks, + quirks_mode: data.stylist.quirks_mode(), }; for (index, keyframe) in keyframes.iter().enumerate() {