From 89087437192070b6c2408c32ab8e90a276adaa23 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:33:00 -0500 Subject: [PATCH 01/14] Bug 1298588 part 2, servo piece. Pass through an nsPresContext to the PerDocumentStyleData constructor. r=bholley --- components/style/build_gecko.rs | 3 +++ components/style/gecko/data.rs | 4 +++- components/style/gecko_bindings/bindings.rs | 6 +++++- components/style/gecko_bindings/structs_debug.rs | 2 ++ components/style/gecko_bindings/structs_release.rs | 2 ++ ports/geckolib/glue.rs | 6 ++++-- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index 21f8b05dbf6..2eec1be1ce3 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -392,6 +392,7 @@ mod bindings { // for clang. "nsPIDOMWindow", // <- Takes the vtable from a template parameter, and we can't // generate it conditionally. + "RawGeckoPresContext", // Just passing it through. "JS::Rooted", "mozilla::Maybe", "gfxSize", // <- union { struct { T width; T height; }; T components[2] }; @@ -467,6 +468,7 @@ mod bindings { "RawGeckoDocument", "RawGeckoElement", "RawGeckoNode", + "RawGeckoPresContext", "ThreadSafeURIHolder", "ThreadSafePrincipalHolder", "ConsumeStyleBehavior", @@ -560,6 +562,7 @@ mod bindings { "RawGeckoElement", "RawGeckoDocument", "RawServoDeclarationBlockStrong", + "RawGeckoPresContext", ]; let servo_borrow_types = [ "nsCSSValue", diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index f67e3871bbc..c0b9dbff4ce 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -8,6 +8,7 @@ use animation::Animation; use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut}; use dom::OpaqueNode; use euclid::size::TypedSize2D; +use gecko_bindings::bindings::RawGeckoPresContextBorrowed; use gecko_bindings::bindings::RawServoStyleSet; use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use media_queries::{Device, MediaType}; @@ -73,7 +74,8 @@ lazy_static! { impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. - pub fn new() -> Self { + #[allow(unused_variables)] // temporary until we make use of the ctor arg. + pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { // FIXME(bholley): Real window size. let window_size: TypedSize2D = TypedSize2D::new(800.0, 600.0); let device = Device::new(MediaType::Screen, window_size); diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 77a2fb2712d..60880449382 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -6,6 +6,7 @@ type nsAString_internal = nsAString; use gecko_bindings::structs::RawGeckoDocument; use gecko_bindings::structs::RawGeckoElement; use gecko_bindings::structs::RawGeckoNode; +use gecko_bindings::structs::RawGeckoPresContext; use gecko_bindings::structs::ThreadSafeURIHolder; use gecko_bindings::structs::ThreadSafePrincipalHolder; use gecko_bindings::structs::ConsumeStyleBehavior; @@ -206,6 +207,8 @@ pub type RawGeckoDocumentBorrowed<'a> = &'a RawGeckoDocument; pub type RawGeckoDocumentBorrowedOrNull<'a> = Option<&'a RawGeckoDocument>; pub type RawServoDeclarationBlockStrongBorrowed<'a> = &'a RawServoDeclarationBlockStrong; pub type RawServoDeclarationBlockStrongBorrowedOrNull<'a> = Option<&'a RawServoDeclarationBlockStrong>; +pub type RawGeckoPresContextBorrowed<'a> = &'a RawGeckoPresContext; +pub type RawGeckoPresContextBorrowedOrNull<'a> = Option<&'a RawGeckoPresContext>; pub type nsCSSValueBorrowed<'a> = &'a nsCSSValue; pub type nsCSSValueBorrowedOrNull<'a> = Option<&'a nsCSSValue>; pub type nsCSSValueBorrowedMut<'a> = &'a mut nsCSSValue; @@ -1028,7 +1031,8 @@ extern "C" { -> ServoCssRulesStrong; } extern "C" { - pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned; + pub fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextBorrowed) + -> RawServoStyleSetOwned; } extern "C" { pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed, diff --git a/components/style/gecko_bindings/structs_debug.rs b/components/style/gecko_bindings/structs_debug.rs index 4f51b9b523a..25ed0cb366f 100644 --- a/components/style/gecko_bindings/structs_debug.rs +++ b/components/style/gecko_bindings/structs_debug.rs @@ -11613,12 +11613,14 @@ pub mod root { pub type RawGeckoNode = root::nsINode; pub type RawGeckoElement = root::mozilla::dom::Element; pub type RawGeckoDocument = root::nsIDocument; + pub type RawGeckoPresContext = [u64; 156usize]; pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode; pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode; pub type RawGeckoElementBorrowed = *const root::RawGeckoElement; pub type RawGeckoElementBorrowedOrNull = *const root::RawGeckoElement; pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument; pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument; + pub type RawGeckoPresContextBorrowed = *const [u64; 156usize]; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsCSSTokenSerializationType { diff --git a/components/style/gecko_bindings/structs_release.rs b/components/style/gecko_bindings/structs_release.rs index 27501f88a86..99e02860158 100644 --- a/components/style/gecko_bindings/structs_release.rs +++ b/components/style/gecko_bindings/structs_release.rs @@ -11540,12 +11540,14 @@ pub mod root { pub type RawGeckoNode = root::nsINode; pub type RawGeckoElement = root::mozilla::dom::Element; pub type RawGeckoDocument = root::nsIDocument; + pub type RawGeckoPresContext = [u64; 152usize]; pub type RawGeckoNodeBorrowed = *const root::RawGeckoNode; pub type RawGeckoNodeBorrowedOrNull = *const root::RawGeckoNode; pub type RawGeckoElementBorrowed = *const root::RawGeckoElement; pub type RawGeckoElementBorrowedOrNull = *const root::RawGeckoElement; pub type RawGeckoDocumentBorrowed = *const root::RawGeckoDocument; pub type RawGeckoDocumentBorrowedOrNull = *const root::RawGeckoDocument; + pub type RawGeckoPresContextBorrowed = *const [u64; 152usize]; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum nsCSSTokenSerializationType { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 87ef1c87738..c5c0733a5c5 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -36,6 +36,7 @@ use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedVal use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong}; use style::gecko_bindings::bindings::{nsACString, nsAString}; use style::gecko_bindings::bindings::RawGeckoElementBorrowed; +use style::gecko_bindings::bindings::RawGeckoPresContextBorrowed; use style::gecko_bindings::bindings::RawServoImportRuleBorrowed; use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; @@ -601,8 +602,9 @@ pub extern "C" fn Servo_ComputedValues_Release(ptr: ServoComputedValuesBorrowed) } #[no_mangle] -pub extern "C" fn Servo_StyleSet_Init() -> RawServoStyleSetOwned { - let data = Box::new(PerDocumentStyleData::new()); +pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextBorrowed) + -> RawServoStyleSetOwned { + let data = Box::new(PerDocumentStyleData::new(pres_context)); data.into_ffi() } From 34bb2f1e6ce94835cb3de4b73bd8d60667c8a41c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:37:36 -0500 Subject: [PATCH 02/14] Bug 1298588 part 3, servo piece. Add a default ComputedValues member to PerDocumentStyleData. r=bholley --- components/style/gecko/data.rs | 6 +- components/style/gecko_bindings/bindings.rs | 126 ++++++++++++++++++++ components/style/properties/gecko.mako.rs | 23 ++++ 3 files changed, 154 insertions(+), 1 deletion(-) diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index c0b9dbff4ce..f6b52154256 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -14,6 +14,7 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use media_queries::{Device, MediaType}; use num_cpus; use parking_lot::RwLock; +use properties::ComputedValues; use rayon; use std::cmp; use std::collections::HashMap; @@ -56,6 +57,9 @@ pub struct PerDocumentStyleDataImpl { /// The number of threads of the work queue. pub num_threads: usize, + + /// Default computed values for this document. + pub default_computed_values: Arc } /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics @@ -74,7 +78,6 @@ lazy_static! { impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. - #[allow(unused_variables)] // temporary until we make use of the ctor arg. pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { // FIXME(bholley): Real window size. let window_size: TypedSize2D = TypedSize2D::new(800.0, 600.0); @@ -98,6 +101,7 @@ impl PerDocumentStyleData { rayon::ThreadPool::new(configuration).ok() }, num_threads: *NUM_THREADS, + default_computed_values: ComputedValues::default_values(pres_context), })) } diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 60880449382..0f7da774c8e 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -735,6 +735,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleFont(ptr: *mut nsStyleFont, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont, other: *const nsStyleFont); @@ -745,6 +750,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleColor(ptr: *mut nsStyleColor, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor, other: *const nsStyleColor); @@ -755,6 +765,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleList(ptr: *mut nsStyleList, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList, other: *const nsStyleList); @@ -765,6 +780,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleText(ptr: *mut nsStyleText, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText, other: *const nsStyleText); @@ -775,6 +795,12 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleVisibility(ptr: + *mut nsStyleVisibility, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility, other: @@ -787,6 +813,12 @@ extern "C" { pub fn Gecko_Construct_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleUserInterface(ptr: + *mut nsStyleUserInterface, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleUserInterface(ptr: *mut nsStyleUserInterface, @@ -799,6 +831,12 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleTableBorder(ptr: + *mut nsStyleTableBorder, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder, @@ -811,6 +849,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleSVG(ptr: *mut nsStyleSVG, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG, other: *const nsStyleSVG); @@ -821,6 +864,12 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleVariables(ptr: + *mut nsStyleVariables, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables, other: @@ -832,6 +881,12 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleBackground(ptr: + *mut nsStyleBackground, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground, other: @@ -843,6 +898,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition); } +extern "C" { + pub fn Gecko_Construct_Default_nsStylePosition(ptr: *mut nsStylePosition, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition, other: *const nsStylePosition); @@ -853,6 +913,12 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleTextReset(ptr: + *mut nsStyleTextReset, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset, other: @@ -864,6 +930,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleDisplay(ptr: *mut nsStyleDisplay, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay, other: *const nsStyleDisplay); @@ -874,6 +945,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleContent(ptr: *mut nsStyleContent, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent, other: *const nsStyleContent); @@ -884,6 +960,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleUIReset(ptr: *mut nsStyleUIReset, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset, other: *const nsStyleUIReset); @@ -894,6 +975,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleTable(ptr: *mut nsStyleTable, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable, other: *const nsStyleTable); @@ -904,6 +990,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleMargin(ptr: *mut nsStyleMargin, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin, other: *const nsStyleMargin); @@ -914,6 +1005,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding); } +extern "C" { + pub fn Gecko_Construct_Default_nsStylePadding(ptr: *mut nsStylePadding, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding, other: *const nsStylePadding); @@ -924,6 +1020,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleBorder(ptr: *mut nsStyleBorder, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder, other: *const nsStyleBorder); @@ -934,6 +1035,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleOutline(ptr: *mut nsStyleOutline, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline, other: *const nsStyleOutline); @@ -944,6 +1050,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleXUL(ptr: *mut nsStyleXUL, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL, other: *const nsStyleXUL); @@ -954,6 +1065,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, other: *const nsStyleSVGReset); @@ -964,6 +1080,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleColumn(ptr: *mut nsStyleColumn, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn, other: *const nsStyleColumn); @@ -974,6 +1095,11 @@ extern "C" { extern "C" { pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects); } +extern "C" { + pub fn Gecko_Construct_Default_nsStyleEffects(ptr: *mut nsStyleEffects, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Gecko_CopyConstruct_nsStyleEffects(ptr: *mut nsStyleEffects, other: *const nsStyleEffects); diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ab0f6b4d46c..0dffdd16344 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -16,6 +16,7 @@ use gecko_bindings::bindings; % for style_struct in data.style_structs: use gecko_bindings::structs::${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_Construct_${style_struct.gecko_ffi_name}; +use gecko_bindings::bindings::Gecko_Construct_Default_${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name}; % endfor @@ -40,6 +41,7 @@ use gecko_bindings::bindings::Gecko_SetMozBinding; use gecko_bindings::bindings::Gecko_SetNullImageValue; use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom}; +use gecko_bindings::bindings::RawGeckoPresContextBorrowed; use gecko_bindings::structs; use gecko_bindings::structs::nsStyleVariables; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; @@ -125,6 +127,18 @@ impl ComputedValues { } } + pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc { + Arc::new(ComputedValues { + custom_properties: None, + shareable: true, + writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious + root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious? + % for style_struct in data.style_structs: + ${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context), + % endfor + }) + } + pub unsafe fn initialize() { debug_assert!(raw_initial_values().is_null()); set_raw_initial_values(Box::into_raw(Box::new(ComputedValues { @@ -422,6 +436,15 @@ impl ${style_struct.gecko_struct_name} { } result } + #[allow(dead_code, unused_variables)] + pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc { + let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } }); + unsafe { + Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko, + pres_context); + } + result + } pub fn get_gecko(&self) -> &${style_struct.gecko_ffi_name} { &self.gecko } From a5ac55c8ff0c572fc1dcdb9b420720828d0c18d4 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:40:19 -0500 Subject: [PATCH 03/14] Bug 1298588 part 4, servo piece. Recreate the default computed values for a document as needed. r=bholley --- components/style/gecko_bindings/bindings.rs | 6 ++++++ ports/geckolib/glue.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 0f7da774c8e..83350c3d389 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1160,6 +1160,12 @@ extern "C" { pub fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextBorrowed) -> RawServoStyleSetOwned; } +extern "C" { + pub fn Servo_StyleSet_RecomputeDefaultStyles(set: + RawServoStyleSetBorrowed, + pres_context: + RawGeckoPresContextBorrowed); +} extern "C" { pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed, sheet: RawServoStyleSheetBorrowed, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index c5c0733a5c5..9758c696797 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -608,6 +608,14 @@ pub extern "C" fn Servo_StyleSet_Init(pres_context: RawGeckoPresContextBorrowed) data.into_ffi() } +#[no_mangle] +pub extern "C" fn Servo_StyleSet_RecomputeDefaultStyles( + raw_data: RawServoStyleSetBorrowed, + pres_context: RawGeckoPresContextBorrowed) { + let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); + data.default_computed_values = ComputedValues::default_values(pres_context); +} + #[no_mangle] pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () { let _ = data.into_box::(); From 56941d61a78f0978480750698d0ee793da48a698 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:41:47 -0500 Subject: [PATCH 04/14] Bug 1298588 part 5. Store a ComputedValues on SharedStyleContext. r=bholley --- components/layout_thread/lib.rs | 6 ++++++ components/style/context.rs | 5 +++++ ports/geckolib/glue.rs | 1 + 3 files changed, 12 insertions(+) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 78a1295c1b5..4d25350835b 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -118,6 +118,7 @@ use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter}; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; use style::parser::ParserContextExtraData; +use style::properties::ComputedValues; use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW}; use style::stylesheets::{Origin, Stylesheet, UserAgentStylesheets}; use style::stylist::Stylist; @@ -527,6 +528,11 @@ impl LayoutThread { local_context_creation_data: Mutex::new(thread_local_style_context_creation_data), timer: self.timer.clone(), quirks_mode: self.quirks_mode.unwrap(), + // FIXME(bz): This isn't really right, but it's no more wrong + // than what we used to do. See + // https://github.com/servo/servo/issues/14773 for fixing it + // properly. + default_computed_values: Arc::new(ComputedValues::initial_values().clone()), }, image_cache_thread: Mutex::new(self.image_cache_thread.clone()), image_cache_sender: Mutex::new(self.image_cache_sender.clone()), diff --git a/components/style/context.rs b/components/style/context.rs index 57a256d4911..ab5899e142f 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -13,6 +13,7 @@ use error_reporting::ParseErrorReporter; use euclid::Size2D; use matching::StyleSharingCandidateCache; use parking_lot::RwLock; +use properties::ComputedValues; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::sync::mpsc::Sender; @@ -82,6 +83,10 @@ pub struct SharedStyleContext { /// The QuirksMode state which the document needs to be rendered with pub quirks_mode: QuirksMode, + + /// The default computed values to use for elements with no rules + /// applying to them. + pub default_computed_values: Arc, } /// A thread-local style context. diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9758c696797..5e5b1316a9b 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -112,6 +112,7 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle timer: Timer::new(), // FIXME Find the real QuirksMode information for this document quirks_mode: QuirksMode::NoQuirks, + default_computed_values: per_doc_data.default_computed_values.clone(), } } From c313c8d17ee1fa74d12e4a36ac9be708424e3c56 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:44:08 -0500 Subject: [PATCH 05/14] Bug 1298588 part 6, servo piece. Stop using initial_values when doing inheritance in Gecko glue code. r=bholley --- components/style/gecko_bindings/bindings.rs | 3 ++- components/style/properties/gecko.mako.rs | 11 ++--------- ports/geckolib/glue.rs | 9 ++++++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 83350c3d389..a78aec48ff9 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1361,7 +1361,8 @@ extern "C" { -> ServoComputedValuesStrong; } extern "C" { - pub fn Servo_ComputedValues_Inherit(parent_style: + pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed, + parent_style: ServoComputedValuesBorrowedOrNull) -> ServoComputedValuesStrong; } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 0dffdd16344..6fd2d868b26 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -78,7 +78,7 @@ pub struct ComputedValues { } impl ComputedValues { - pub fn inherit_from(parent: &Arc) -> Arc { + pub fn inherit_from(parent: &Arc, default: &Arc) -> Arc { Arc::new(ComputedValues { custom_properties: parent.custom_properties.clone(), shareable: parent.shareable, @@ -88,7 +88,7 @@ impl ComputedValues { % if style_struct.inherited: ${style_struct.ident}: parent.${style_struct.ident}.clone(), % else: - ${style_struct.ident}: Self::initial_values().${style_struct.ident}.clone(), + ${style_struct.ident}: default.${style_struct.ident}.clone(), % endif % endfor }) @@ -113,13 +113,6 @@ impl ComputedValues { } } - pub fn style_for_child_text_node(parent: &Arc) -> Arc { - // Gecko expects text nodes to be styled as if they were elements that - // matched no rules (that is, inherited style structs are inherited and - // non-inherited style structs are set to their initial values). - ComputedValues::inherit_from(parent) - } - pub fn initial_values() -> &'static Self { unsafe { debug_assert!(!raw_initial_values().is_null()); diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 5e5b1316a9b..314d33a5bf4 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -581,13 +581,16 @@ fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom, } #[no_mangle] -pub extern "C" fn Servo_ComputedValues_Inherit(parent_style: ServoComputedValuesBorrowedOrNull) +pub extern "C" fn Servo_ComputedValues_Inherit( + raw_data: RawServoStyleSetBorrowed, + parent_style: ServoComputedValuesBorrowedOrNull) -> ServoComputedValuesStrong { + let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let maybe_arc = ComputedValues::arc_from_borrowed(&parent_style); let style = if let Some(reference) = maybe_arc.as_ref() { - ComputedValues::inherit_from(reference) + ComputedValues::inherit_from(reference, &data.default_computed_values) } else { - Arc::new(ComputedValues::initial_values().clone()) + data.default_computed_values.clone() }; style.into_strong() } From d3e34db50895116ef1f77a32b9dde81dc6a90ee6 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:45:15 -0500 Subject: [PATCH 06/14] Bug 1298588 part 7, servo piece. Stop using initial_values in general in Gecko glue code. r=bholley --- components/style/gecko_bindings/bindings.rs | 1 + ports/geckolib/glue.rs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index a78aec48ff9..0a94d146cd7 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1387,6 +1387,7 @@ extern "C" { } extern "C" { pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, + set: RawServoStyleSetBorrowed, consume: ConsumeStyleBehavior) -> ServoComputedValuesStrong; } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 314d33a5bf4..49625543e73 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -544,6 +544,7 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, { let element = GeckoElement(element); let data = unsafe { element.ensure_data() }.borrow_mut(); + let doc_data = PerDocumentStyleData::from_ffi(raw_data); // FIXME(bholley): Assert against this. if data.get_styles().is_none() { @@ -551,11 +552,10 @@ pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed, return if is_probe { Strong::null() } else { - Arc::new(ComputedValues::initial_values().clone()).into_strong() + doc_data.borrow().default_computed_values.clone().into_strong() }; } - let doc_data = PerDocumentStyleData::from_ffi(raw_data); match get_pseudo_style(element, pseudo_tag, data.styles(), doc_data) { Some(values) => values.into_strong(), None if !is_probe => data.styles().primary.values.clone().into_strong(), @@ -942,6 +942,7 @@ pub extern "C" fn Servo_CheckChangeHint(element: RawGeckoElementBorrowed) -> nsC #[no_mangle] pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, + raw_data: RawServoStyleSetBorrowed, consume: structs::ConsumeStyleBehavior) -> ServoComputedValuesStrong { @@ -949,10 +950,11 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, debug!("Servo_ResolveStyle: {:?}, consume={:?}", element, consume); let mut data = unsafe { element.ensure_data() }.borrow_mut(); + let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); if !data.has_current_styles() { error!("Resolving style on unstyled element with lazy computation forbidden."); - return Arc::new(ComputedValues::initial_values().clone()).into_strong(); + return per_doc_data.default_computed_values.clone().into_strong(); } let values = data.styles().primary.values.clone(); From 09c74190b99ccd20091aaa1c64ef9b199b7e6ecb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:46:41 -0500 Subject: [PATCH 07/14] Bug 1298588 part 8. Pass a SharedStyleContext, not a Stylist, to Legalizer methods. r=bholley --- components/layout/construct.rs | 39 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 660d4f64834..1d9c1212ad6 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -54,7 +54,6 @@ use style::logical_geometry::Direction; use style::properties::{self, ServoComputedValues}; use style::selector_parser::{PseudoElement, RestyleDamage}; use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW}; -use style::stylist::Stylist; use style::values::Either; use table::TableFlow; use table_caption::TableCaptionFlow; @@ -470,7 +469,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> } inline_flow_ref.finish(); - legalizer.add_child(&self.style_context().stylist, flow, inline_flow_ref) + legalizer.add_child(self.style_context(), flow, inline_flow_ref) } fn build_block_flow_using_construction_result_of_child( @@ -503,7 +502,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> legalizer, node); } - legalizer.add_child(&self.style_context().stylist, flow, kid_flow) + legalizer.add_child(self.style_context(), flow, kid_flow) } abs_descendants.push_descendants(kid_abs_descendants); } @@ -537,7 +536,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> node); // Push the flow generated by the {ib} split onto our list of flows. - legalizer.add_child(&self.style_context().stylist, flow, kid_flow) + legalizer.add_child(self.style_context(), flow, kid_flow) } // Add the fragments to the list we're maintaining. @@ -1123,7 +1122,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> caption_side::T::top); if let ConstructionResult::Flow(table_flow, table_abs_descendants) = construction_result { - legalizer.add_child(&self.style_context().stylist, &mut wrapper_flow, table_flow); + legalizer.add_child(self.style_context(), &mut wrapper_flow, table_flow); abs_descendants.push_descendants(table_abs_descendants); } @@ -1889,16 +1888,16 @@ impl Legalizer { /// Makes the `child` flow a new child of `parent`. Anonymous flows are automatically inserted /// to keep the tree legal. - fn add_child(&mut self, stylist: &Stylist, parent: &mut FlowRef, mut child: FlowRef) { + fn add_child(&mut self, context: &SharedStyleContext, parent: &mut FlowRef, mut child: FlowRef) { while !self.stack.is_empty() { - if self.try_to_add_child(stylist, parent, &mut child) { + if self.try_to_add_child(context, parent, &mut child) { return } self.flush_top_of_stack(parent) } - while !self.try_to_add_child(stylist, parent, &mut child) { - self.push_next_anonymous_flow(stylist, parent) + while !self.try_to_add_child(context, parent, &mut child) { + self.push_next_anonymous_flow(context, parent) } } @@ -1915,7 +1914,7 @@ impl Legalizer { /// This method attempts to create anonymous blocks in between `parent` and `child` if and only /// if those blocks will only ever have `child` as their sole child. At present, this is only /// true for anonymous block children of flex flows. - fn try_to_add_child(&mut self, stylist: &Stylist, parent: &mut FlowRef, child: &mut FlowRef) + fn try_to_add_child(&mut self, context: &SharedStyleContext, parent: &mut FlowRef, child: &mut FlowRef) -> bool { let mut parent = self.stack.last_mut().unwrap_or(parent); let (parent_class, child_class) = (parent.class(), child.class()); @@ -1947,7 +1946,7 @@ impl Legalizer { (FlowClass::Flex, FlowClass::Inline) => { flow::mut_base(FlowRef::deref_mut(child)).flags.insert(MARGINS_CANNOT_COLLAPSE); let mut block_wrapper = - Legalizer::create_anonymous_flow(stylist, + Legalizer::create_anonymous_flow(context, parent, &[PseudoElement::ServoAnonymousBlock], SpecificFragmentInfo::Generic, @@ -1999,32 +1998,32 @@ impl Legalizer { /// Adds the anonymous flow that would be necessary to make an illegal child of `parent` legal /// to the stack. - fn push_next_anonymous_flow(&mut self, stylist: &Stylist, parent: &FlowRef) { + fn push_next_anonymous_flow(&mut self, context: &SharedStyleContext, parent: &FlowRef) { let parent_class = self.stack.last().unwrap_or(parent).class(); match parent_class { FlowClass::TableRow => { - self.push_new_anonymous_flow(stylist, + self.push_new_anonymous_flow(context, parent, &[PseudoElement::ServoAnonymousTableCell], SpecificFragmentInfo::TableCell, TableCellFlow::from_fragment) } FlowClass::Table | FlowClass::TableRowGroup => { - self.push_new_anonymous_flow(stylist, + self.push_new_anonymous_flow(context, parent, &[PseudoElement::ServoAnonymousTableRow], SpecificFragmentInfo::TableRow, TableRowFlow::from_fragment) } FlowClass::TableWrapper => { - self.push_new_anonymous_flow(stylist, + self.push_new_anonymous_flow(context, parent, &[PseudoElement::ServoAnonymousTable], SpecificFragmentInfo::Table, TableFlow::from_fragment) } _ => { - self.push_new_anonymous_flow(stylist, + self.push_new_anonymous_flow(context, parent, &[PseudoElement::ServoTableWrapper, PseudoElement::ServoAnonymousTableWrapper], @@ -2036,13 +2035,13 @@ impl Legalizer { /// Creates an anonymous flow and pushes it onto the stack. fn push_new_anonymous_flow(&mut self, - stylist: &Stylist, + context: &SharedStyleContext, reference: &FlowRef, pseudos: &[PseudoElement], specific_fragment_info: SpecificFragmentInfo, constructor: extern "Rust" fn(Fragment) -> F) where F: Flow { - let new_flow = Legalizer::create_anonymous_flow(stylist, + let new_flow = Legalizer::create_anonymous_flow(context, reference, pseudos, specific_fragment_info, @@ -2055,7 +2054,7 @@ impl Legalizer { /// /// This method invokes the supplied constructor function on the given specific fragment info /// in order to actually generate the flow. - fn create_anonymous_flow(stylist: &Stylist, + fn create_anonymous_flow(context: &SharedStyleContext, reference: &FlowRef, pseudos: &[PseudoElement], specific_fragment_info: SpecificFragmentInfo, @@ -2065,7 +2064,7 @@ impl Legalizer { let reference_block = reference.as_block(); let mut new_style = reference_block.fragment.style.clone(); for pseudo in pseudos { - new_style = stylist.style_for_anonymous_box(pseudo, &new_style) + new_style = context.stylist.style_for_anonymous_box(pseudo, &new_style) } let fragment = reference_block.fragment .create_similar_anonymous_fragment(new_style, From 61f6025dc31619151908c5f82c052821802e1095 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:48:23 -0500 Subject: [PATCH 08/14] Bug 1298588 part 9, servo piece. Pass through useful default styles to cascade(). r=bholley --- components/layout/construct.rs | 7 ++++--- components/script_layout_interface/wrapper_traits.rs | 4 +++- components/style/matching.rs | 2 ++ components/style/properties/properties.mako.rs | 3 ++- components/style/stylist.rs | 11 ++++++++--- ports/geckolib/glue.rs | 5 +++-- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 1d9c1212ad6..7c039d38729 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -661,7 +661,8 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> if node_is_input_or_text_area { style = self.style_context() .stylist - .style_for_anonymous_box(&PseudoElement::ServoInputText, &style) + .style_for_anonymous_box(&PseudoElement::ServoInputText, &style, + &self.style_context().default_computed_values) } self.create_fragments_for_node_text_content(&mut initial_fragments, node, &style) @@ -1093,7 +1094,7 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> let wrapper_style = self.style_context() .stylist .style_for_anonymous_box(&PseudoElement::ServoTableWrapper, - &table_style); + &table_style, &self.style_context().default_computed_values); let wrapper_fragment = Fragment::from_opaque_node_and_style(node.opaque(), PseudoElementType::Normal, @@ -2064,7 +2065,7 @@ impl Legalizer { let reference_block = reference.as_block(); let mut new_style = reference_block.fragment.style.clone(); for pseudo in pseudos { - new_style = context.stylist.style_for_anonymous_box(pseudo, &new_style) + new_style = context.stylist.style_for_anonymous_box(pseudo, &new_style, &context.default_computed_values) } let fragment = reference_block.fragment .create_similar_anonymous_fragment(new_style, diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 77414fa48d5..0103b185096 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -391,6 +391,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + context.stylist.precomputed_values_for_pseudo( &style_pseudo, Some(&data.styles().primary.values), + &context.default_computed_values, false); data.styles_mut().pseudos .insert(style_pseudo.clone(), new_style.unwrap()); @@ -407,7 +408,8 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + .lazily_compute_pseudo_element_style( self, &style_pseudo, - &data.styles().primary.values); + &data.styles().primary.values, + &context.default_computed_values); data.styles_mut().pseudos .insert(style_pseudo.clone(), new_style.unwrap()); } diff --git a/components/style/matching.rs b/components/style/matching.rs index af8cd4bf627..f8d019ea775 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -470,6 +470,7 @@ trait PrivateMatchMethods: TElement { cascade(shared_context.viewport_size, rule_node, Some(&***parent_style), + &shared_context.default_computed_values, Some(&mut cascade_info), shared_context.error_reporter.clone(), cascade_flags) @@ -478,6 +479,7 @@ trait PrivateMatchMethods: TElement { cascade(shared_context.viewport_size, rule_node, None, + &shared_context.default_computed_values, Some(&mut cascade_info), shared_context.error_reporter.clone(), cascade_flags) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 647a5e7539d..66a8e158582 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1714,13 +1714,14 @@ bitflags! { pub fn cascade(viewport_size: Size2D, rule_node: &StrongRuleNode, parent_style: Option<<&ComputedValues>, + default_style: &Arc, cascade_info: Option<<&mut CascadeInfo>, error_reporter: StdBox, flags: CascadeFlags) -> ComputedValues { let (is_root_element, inherited_style) = match parent_style { Some(parent_style) => (false, parent_style), - None => (true, ComputedValues::initial_values()), + None => (true, &**default_style), }; // Hold locks until after the apply_declarations() call returns. // Use filter_map because the root node has no style source. diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 1a1dfabaf3d..e0c6bf3f68d 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -274,6 +274,7 @@ impl Stylist { pub fn precomputed_values_for_pseudo(&self, pseudo: &PseudoElement, parent: Option<&Arc>, + default: &Arc, inherit_all: bool) -> Option { debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); @@ -293,6 +294,7 @@ impl Stylist { properties::cascade(self.device.au_viewport_size(), &rule_node, parent.map(|p| &**p), + default, None, Box::new(StdoutErrorReporter), flags); @@ -306,7 +308,8 @@ impl Stylist { #[cfg(feature = "servo")] pub fn style_for_anonymous_box(&self, pseudo: &PseudoElement, - parent_style: &Arc) + parent_style: &Arc, + default_style: &Arc) -> Arc { // For most (but not all) pseudo-elements, we inherit all values from the parent. let inherit_all = match *pseudo { @@ -325,7 +328,7 @@ impl Stylist { unreachable!("That pseudo doesn't represent an anonymous box!") } }; - self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), inherit_all) + self.precomputed_values_for_pseudo(&pseudo, Some(parent_style), default_style, inherit_all) .expect("style_for_anonymous_box(): No precomputed values for that pseudo!") .values } @@ -340,7 +343,8 @@ impl Stylist { pub fn lazily_compute_pseudo_element_style(&self, element: &E, pseudo: &PseudoElement, - parent: &Arc) + parent: &Arc, + default: &Arc) -> Option where E: ElementExt + fmt::Debug + @@ -368,6 +372,7 @@ impl Stylist { properties::cascade(self.device.au_viewport_size(), &rule_node, Some(&**parent), + default, None, Box::new(StdoutErrorReporter), CascadeFlags::empty()); diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 49625543e73..9c947fc73f7 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -531,7 +531,8 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: let maybe_parent = ComputedValues::arc_from_borrowed(&parent_style_or_null); - let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, false) + let new_computed = data.stylist.precomputed_values_for_pseudo(&pseudo, maybe_parent, + &data.default_computed_values, false) .map(|styles| styles.values); new_computed.map_or(Strong::null(), |c| c.into_strong()) } @@ -574,7 +575,7 @@ fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom, PseudoElementCascadeType::Lazy => { let d = doc_data.borrow_mut(); let base = &styles.primary.values; - d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base) + d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base, &d.default_computed_values) .map(|s| s.values.clone()) }, } From c826b18f87124a4f8485f0d8481caee3c5f277b6 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:50:23 -0500 Subject: [PATCH 09/14] Bug 1298588 part 10, servo piece. Pass through useful default styles to apply_declarations(). r=bholley --- components/style/animation.rs | 1 + components/style/gecko_bindings/bindings.rs | 3 ++- components/style/properties/properties.mako.rs | 6 +++--- ports/geckolib/glue.rs | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/style/animation.rs b/components/style/animation.rs index 2dabb608d99..1545cac72f8 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -430,6 +430,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, /* is_root = */ false, iter, previous_style, + &context.default_computed_values, /* cascade_info = */ None, context.error_reporter.clone(), /* Metrics provider */ None, diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 0a94d146cd7..03f51a130ca 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1248,7 +1248,8 @@ extern "C" { -> RawServoDeclarationBlockStrong; } extern "C" { - pub fn Servo_RestyleWithAddedDeclaration(declarations: + pub fn Servo_RestyleWithAddedDeclaration(set: RawServoStyleSetBorrowed, + declarations: RawServoDeclarationBlockBorrowed, previous_style: ServoComputedValuesBorrowed) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 66a8e158582..d5d068060bf 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1746,6 +1746,7 @@ pub fn cascade(viewport_size: Size2D, is_root_element, iter_declarations, inherited_style, + default_style, cascade_info, error_reporter, None, @@ -1758,6 +1759,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, is_root_element: bool, iter_declarations: F, inherited_style: &ComputedValues, + default_style: &Arc, mut cascade_info: Option<<&mut CascadeInfo>, mut error_reporter: StdBox, font_metrics_provider: Option<<&FontMetricsProvider>, @@ -1784,8 +1786,6 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, ::custom_properties::finish_cascade( custom_properties, &inherited_custom_properties); - let initial_values = ComputedValues::initial_values(); - let starting_style = if !flags.contains(INHERIT_ALL) { ComputedValues::new(custom_properties, flags.contains(SHAREABLE), @@ -1795,7 +1795,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, % if style_struct.inherited: inherited_style.clone_${style_struct.name_lower}(), % else: - initial_values.clone_${style_struct.name_lower}(), + default_style.clone_${style_struct.name_lower}(), % endif % endfor ) diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 9c947fc73f7..a0be6d60f80 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -170,7 +170,8 @@ pub extern "C" fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed, } #[no_mangle] -pub extern "C" fn Servo_RestyleWithAddedDeclaration(declarations: RawServoDeclarationBlockBorrowed, +pub extern "C" fn Servo_RestyleWithAddedDeclaration(raw_data: RawServoStyleSetBorrowed, + declarations: RawServoDeclarationBlockBorrowed, previous_style: ServoComputedValuesBorrowed) -> ServoComputedValuesStrong { @@ -183,11 +184,14 @@ pub extern "C" fn Servo_RestyleWithAddedDeclaration(declarations: RawServoDeclar guard.declarations.iter().rev().map(|&(ref decl, _importance)| decl) }; + let data = PerDocumentStyleData::from_ffi(raw_data).borrow(); + // FIXME (bug 1303229): Use the actual viewport size here let computed = apply_declarations(Size2D::new(Au(0), Au(0)), /* is_root_element = */ false, declarations, previous_style, + &data.default_computed_values, None, Box::new(StdoutErrorReporter), None, From 8367c96c1b1f9cbadda04d258438002e807179f7 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:52:44 -0500 Subject: [PATCH 10/14] Bug 1298588 part 11. Pass through useful default styles to CascadePropertyFn. r=bholley --- components/style/properties/helpers.mako.rs | 3 ++- components/style/properties/properties.mako.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 89e9d1d2b2e..f072da97c8f 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -210,6 +210,7 @@ #[allow(unused_variables)] pub fn cascade_property(declaration: &PropertyDeclaration, inherited_style: &ComputedValues, + default_style: &Arc, context: &mut computed::Context, seen: &mut PropertyBitField, cacheable: &mut bool, @@ -260,7 +261,7 @@ DeclaredValue::Initial => { // We assume that it's faster to use copy_*_from rather than // set_*(get_initial_value()); - let initial_struct = ComputedValues::initial_values() + let initial_struct = default_style .get_${data.current_style_struct.name_lower}(); context.mutate_style().mutate_${data.current_style_struct.name_lower}() .copy_${property.ident}_from(initial_struct ${maybe_wm}); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index d5d068060bf..d3a84e857c0 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1668,6 +1668,7 @@ mod lazy_static_module { pub type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration, inherited_style: &ComputedValues, + default_style: &Arc, context: &mut computed::Context, seen: &mut PropertyBitField, cacheable: &mut bool, @@ -1875,6 +1876,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, let discriminant = longhand_id as usize; (CASCADE_PROPERTY[discriminant])(declaration, inherited_style, + default_style, &mut context, &mut seen, &mut cacheable, From 62961370ecdf7c412760452fcc1a894c686ace0c Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:54:03 -0500 Subject: [PATCH 11/14] Bug 1298588 part 12. Compile some bits that call ComputedValues::initial_values only for servo, not stylo. r=bholley Stylist::set_device seems to only be used in servo code, and is the only consumer of ViewportConstraints::maybe_new. --- components/style/stylist.rs | 9 ++++++++- components/style/viewport.rs | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index e0c6bf3f68d..5952e242cf1 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -11,7 +11,9 @@ use data::ComputedStyle; use dom::{PresentationalHintsSynthetizer, TElement}; use error_reporting::StdoutErrorReporter; use keyframes::KeyframesAnimation; -use media_queries::{Device, MediaType}; +use media_queries::Device; +#[cfg(feature = "servo")] +use media_queries::MediaType; use parking_lot::RwLock; use properties::{self, CascadeFlags, ComputedValues, INHERIT_ALL, Importance}; use properties::{PropertyDeclaration, PropertyDeclarationBlock}; @@ -34,6 +36,7 @@ use std::slice; use std::sync::Arc; use style_traits::viewport::ViewportConstraints; use stylesheets::{CssRule, Origin, StyleRule, Stylesheet, UserAgentStylesheets}; +#[cfg(feature = "servo")] use viewport::{self, MaybeNew, ViewportRule}; pub use ::fnv::FnvHashMap; @@ -385,6 +388,10 @@ impl Stylist { /// /// This means that we may need to rebuild style data even if the /// stylesheets haven't changed. + /// + /// Viewport_Constraints::maybe_new is servo-only (see the comment above it + /// explaining why), so we need to be servo-only too, since we call it. + #[cfg(feature = "servo")] pub fn set_device(&mut self, mut device: Device, stylesheets: &[Arc]) { let cascaded_rule = ViewportRule { declarations: viewport::Cascade::from_stylesheets(stylesheets, &device).finish(), diff --git a/components/style/viewport.rs b/components/style/viewport.rs index d8d45016b25..38ff5a6942d 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -9,13 +9,18 @@ #![deny(missing_docs)] +#[cfg(feature = "servo")] use app_units::Au; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important}; use cssparser::ToCss as ParserToCss; +#[cfg(feature = "servo")] use euclid::scale_factor::ScaleFactor; -use euclid::size::{Size2D, TypedSize2D}; +#[cfg(feature = "servo")] +use euclid::size::Size2D; +use euclid::size::TypedSize2D; use media_queries::Device; use parser::{ParserContext, log_css_error}; +#[cfg(feature = "servo")] use properties::ComputedValues; use std::ascii::AsciiExt; use std::borrow::Cow; @@ -25,6 +30,7 @@ use std::str::Chars; use style_traits::{ToCss, ViewportPx}; use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom}; use stylesheets::{Stylesheet, Origin}; +#[cfg(feature = "servo")] use values::computed::{Context, ToComputedValue}; use values::specified::{Length, LengthOrPercentageOrAuto, ViewportPercentageLength}; @@ -605,6 +611,11 @@ pub trait MaybeNew { -> Option; } +/// MaybeNew for ViewportConstraints uses ComputedValues::initial_values which +/// is servo-only (not present in gecko). Once it has been changed to properly +/// use per-document initial computed values, or not use the initial computed +/// values at all, it can go back to being compiled unconditionally. +#[cfg(feature = "servo")] impl MaybeNew for ViewportConstraints { fn maybe_new(initial_viewport: TypedSize2D, rule: &ViewportRule) From 369fdddcd926110334266a6e43a55843d8164aea Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 13:55:05 -0500 Subject: [PATCH 12/14] Bug 1298588 part 13. Make sure Device has a ComputedValues for stylo. r=bholley --- components/style/gecko/data.rs | 9 ++++-- components/style/media_queries.rs | 41 ++++++++++++++++++++++--- components/style/values/computed/mod.rs | 14 --------- ports/geckolib/glue.rs | 1 + tests/unit/style/parsing/image.rs | 10 +++++- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index f6b52154256..dd4ae30a429 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -81,7 +81,12 @@ impl PerDocumentStyleData { pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { // FIXME(bholley): Real window size. let window_size: TypedSize2D = TypedSize2D::new(800.0, 600.0); - let device = Device::new(MediaType::Screen, window_size); + let default_computed_values = ComputedValues::default_values(pres_context); + + // FIXME(bz): We're going to need to either update the computed values + // in the Stylist's Device or give the Stylist a new Device when our + // default_computed_values changes. + let device = Device::new(MediaType::Screen, window_size, &default_computed_values); let (new_anims_sender, new_anims_receiver) = channel(); @@ -101,7 +106,7 @@ impl PerDocumentStyleData { rayon::ThreadPool::new(configuration).ok() }, num_threads: *NUM_THREADS, - default_computed_values: ComputedValues::default_values(pres_context), + default_computed_values: default_computed_values, })) } diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index 5762effb4c2..98c621ad89a 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -10,14 +10,16 @@ use Atom; use app_units::Au; use cssparser::{Delimiter, Parser, Token}; use euclid::size::{Size2D, TypedSize2D}; +use properties::ComputedValues; use serialize_comma_separated_list; use std::ascii::AsciiExt; use std::fmt; +#[cfg(feature = "gecko")] +use std::sync::Arc; use style_traits::{ToCss, ViewportPx}; use values::computed::{self, ToComputedValue}; use values::specified; - #[derive(Debug, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct MediaList { @@ -47,10 +49,18 @@ pub enum Range { } impl Range { - fn to_computed_range(&self, viewport_size: Size2D) -> Range { + fn to_computed_range(&self, viewport_size: Size2D, default_values: &ComputedValues) -> Range { // http://dev.w3.org/csswg/mediaqueries3/#units // em units are relative to the initial font-size. - let context = computed::Context::initial(viewport_size, false); + let context = computed::Context { + is_root_element: false, + viewport_size: viewport_size, + inherited_style: default_values, + // This cloning business is kind of dumb.... It's because Context + // insists on having an actual ComputedValues inside itself. + style: default_values.clone(), + font_metrics_provider: None + }; match *self { Range::Min(ref width) => Range::Min(width.to_computed_value(&context)), @@ -225,9 +235,12 @@ impl MediaType { pub struct Device { pub media_type: MediaType, pub viewport_size: TypedSize2D, + #[cfg(feature = "gecko")] + pub default_values: Arc, } impl Device { + #[cfg(feature = "servo")] pub fn new(media_type: MediaType, viewport_size: TypedSize2D) -> Device { Device { media_type: media_type, @@ -235,6 +248,26 @@ impl Device { } } + #[cfg(feature = "servo")] + pub fn default_values(&self) -> &ComputedValues { + ComputedValues::initial_values() + } + + #[cfg(feature = "gecko")] + pub fn new(media_type: MediaType, viewport_size: TypedSize2D, + default_values: &Arc) -> Device { + Device { + media_type: media_type, + viewport_size: viewport_size, + default_values: default_values.clone(), + } + } + + #[cfg(feature = "gecko")] + pub fn default_values(&self) -> &ComputedValues { + &*self.default_values + } + #[inline] pub fn au_viewport_size(&self) -> Size2D { Size2D::new(Au::from_f32_px(self.viewport_size.width), @@ -337,7 +370,7 @@ impl MediaList { let query_match = media_match && mq.expressions.iter().all(|expression| { match *expression { Expression::Width(ref value) => - value.to_computed_range(viewport_size).evaluate(viewport_size.width), + value.to_computed_range(viewport_size, device.default_values()).evaluate(viewport_size.width), } }); diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 2f8ca20fd42..8c739e4c3d7 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -62,20 +62,6 @@ impl<'a> Context<'a> { pub fn style(&self) -> &ComputedValues { &self.style } /// A mutable reference to the current style. pub fn mutate_style(&mut self) -> &mut ComputedValues { &mut self.style } - - /// Creates a dummy computed context for use in multiple places, like - /// evaluating media queries. - pub fn initial(viewport_size: Size2D, is_root_element: bool) -> Self { - let initial_style = ComputedValues::initial_values(); - // FIXME: Enforce a font metrics provider. - Context { - is_root_element: is_root_element, - viewport_size: viewport_size, - inherited_style: initial_style, - style: initial_style.clone(), - font_metrics_provider: None, - } - } } /// A trait to represent the conversion between computed and specified values. diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index a0be6d60f80..ef6bdb28ff6 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -623,6 +623,7 @@ pub extern "C" fn Servo_StyleSet_RecomputeDefaultStyles( pres_context: RawGeckoPresContextBorrowed) { let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); data.default_computed_values = ComputedValues::default_values(pres_context); + // FIXME(bz): We need to update our Stylist's Device's computed values, but how? } #[no_mangle] diff --git a/tests/unit/style/parsing/image.rs b/tests/unit/style/parsing/image.rs index 96069dd83cc..cb4dfac001e 100644 --- a/tests/unit/style/parsing/image.rs +++ b/tests/unit/style/parsing/image.rs @@ -8,6 +8,7 @@ use euclid::size::Size2D; use media_queries::CSSErrorReporterTest; use std::f32::consts::PI; use style::parser::ParserContext; +use style::properties::ComputedValues; use style::stylesheets::Origin; use style::values::computed; use style::values::computed::{Angle, Context, ToComputedValue}; @@ -43,7 +44,14 @@ fn test_linear_gradient() { // Note that Angle(PI) is correct for top-to-bottom rendering, whereas Angle(0) would render bottom-to-top. // ref: https://developer.mozilla.org/en-US/docs/Web/CSS/angle let container = Size2D::new(Au::default(), Au::default()); - let specified_context = Context::initial(container, true); + let initial_style = ComputedValues::initial_values(); + let specified_context = Context { + is_root_element: true, + viewport_size: container, + inherited_style: initial_style, + style: initial_style.clone(), + font_metrics_provider: None, + }; assert_eq!(specified::AngleOrCorner::None.to_computed_value(&specified_context), computed::AngleOrCorner::Angle(Angle(PI))); } From 8e2acee24e58850ee32d27774cb8e7a21a9a2f02 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 14:00:05 -0500 Subject: [PATCH 13/14] Bug 1298588 part 14. Remove ComputedValues::initial_values for stylo. r=bholley --- components/style/properties/gecko.mako.rs | 37 ----------------------- ports/geckolib/glue.rs | 14 --------- 2 files changed, 51 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 6fd2d868b26..972f3aab42a 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -55,7 +55,6 @@ use properties::longhands; use std::fmt::{self, Debug}; use std::mem::{transmute, zeroed}; use std::ptr; -use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering}; use std::sync::Arc; use std::cmp; @@ -113,13 +112,6 @@ impl ComputedValues { } } - pub fn initial_values() -> &'static Self { - unsafe { - debug_assert!(!raw_initial_values().is_null()); - &*raw_initial_values() - } - } - pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc { Arc::new(ComputedValues { custom_properties: None, @@ -132,25 +124,6 @@ impl ComputedValues { }) } - pub unsafe fn initialize() { - debug_assert!(raw_initial_values().is_null()); - set_raw_initial_values(Box::into_raw(Box::new(ComputedValues { - % for style_struct in data.style_structs: - ${style_struct.ident}: style_structs::${style_struct.name}::initial(), - % endfor - custom_properties: None, - shareable: true, - writing_mode: WritingMode::empty(), - root_font_size: longhands::font_size::get_initial_value(), - }))); - } - - pub unsafe fn shutdown() { - debug_assert!(!raw_initial_values().is_null()); - let _ = Box::from_raw(raw_initial_values()); - set_raw_initial_values(ptr::null_mut()); - } - % for style_struct in data.style_structs: #[inline] pub fn clone_${style_struct.name_lower}(&self) -> Arc { @@ -2662,13 +2635,3 @@ pub unsafe extern "C" fn Servo_GetStyleVariables(_cv: ServoComputedValuesBorrowe &*EMPTY_VARIABLES_STRUCT } -// To avoid UB, we store the initial values as a atomic. It would be nice to -// store them as AtomicPtr, but we can't have static AtomicPtr without const -// fns, which aren't in stable Rust. -static INITIAL_VALUES_STORAGE: AtomicUsize = ATOMIC_USIZE_INIT; -unsafe fn raw_initial_values() -> *mut ComputedValues { - INITIAL_VALUES_STORAGE.load(Ordering::Relaxed) as *mut ComputedValues -} -unsafe fn set_raw_initial_values(v: *mut ComputedValues) { - INITIAL_VALUES_STORAGE.store(v as usize, Ordering::Relaxed); -} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index ef6bdb28ff6..aeb1fe6484e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -82,17 +82,12 @@ pub extern "C" fn Servo_Initialize() -> () { // See https://doc.rust-lang.org/log/env_logger/index.html for instructions. env_logger::init().unwrap(); - // Allocate our default computed values. - unsafe { ComputedValues::initialize(); } - // Pretend that we're a Servo Layout thread, to make some assertions happy. thread_state::initialize(thread_state::LAYOUT); } #[no_mangle] pub extern "C" fn Servo_Shutdown() -> () { - // Destroy our default computed values. - unsafe { ComputedValues::shutdown(); } } fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyleContext { @@ -118,15 +113,6 @@ fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyle fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed, unstyled_children_only: bool) { - // Force the creation of our lazily-constructed initial computed values on - // the main thread, since it's not safe to call elsewhere. - // - // FIXME(bholley): this should move into Servo_Initialize as soon as we get - // rid of the HackilyFindSomeDeviceContext stuff that happens during - // initial_values computation, since that stuff needs to be called further - // along in startup than the sensible place to call Servo_Initialize. - ComputedValues::initial_values(); - // When new content is inserted in a display:none subtree, we will call into // servo to try to style it. Detect that here and bail out. if let Some(parent) = element.parent_element() { From dd80b5c0e7b0ad62b7897ac17782d573a2fa16ea Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 4 Jan 2017 14:01:53 -0500 Subject: [PATCH 14/14] Bug 1298588 part 15, servo piece. Rip out the initial() methods on style structs in stylo. r=bholley --- components/style/gecko_bindings/bindings.rs | 76 +-------------------- components/style/properties/gecko.mako.rs | 9 --- 2 files changed, 3 insertions(+), 82 deletions(-) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 03f51a130ca..1b560cd4518 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -732,9 +732,6 @@ extern "C" { pub fn Gecko_ReleaseCSSValueSharedListArbitraryThread(aPtr: *mut nsCSSValueSharedList); } -extern "C" { - pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleFont(ptr: *mut nsStyleFont, pres_context: @@ -747,9 +744,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleFont(ptr: *mut nsStyleFont); } -extern "C" { - pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleColor(ptr: *mut nsStyleColor, pres_context: @@ -762,9 +756,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleColor(ptr: *mut nsStyleColor); } -extern "C" { - pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleList(ptr: *mut nsStyleList, pres_context: @@ -777,9 +768,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleList(ptr: *mut nsStyleList); } -extern "C" { - pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleText(ptr: *mut nsStyleText, pres_context: @@ -792,9 +780,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleText(ptr: *mut nsStyleText); } -extern "C" { - pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleVisibility(ptr: *mut nsStyleVisibility, @@ -809,10 +794,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleVisibility(ptr: *mut nsStyleVisibility); } -extern "C" { - pub fn Gecko_Construct_nsStyleUserInterface(ptr: - *mut nsStyleUserInterface); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleUserInterface(ptr: *mut nsStyleUserInterface, @@ -828,9 +809,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); } -extern "C" { - pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleTableBorder(ptr: *mut nsStyleTableBorder, @@ -846,9 +824,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); } -extern "C" { - pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleSVG(ptr: *mut nsStyleSVG, pres_context: @@ -861,9 +836,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleSVG(ptr: *mut nsStyleSVG); } -extern "C" { - pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleVariables(ptr: *mut nsStyleVariables, @@ -878,9 +850,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleVariables(ptr: *mut nsStyleVariables); } -extern "C" { - pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleBackground(ptr: *mut nsStyleBackground, @@ -895,9 +864,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleBackground(ptr: *mut nsStyleBackground); } -extern "C" { - pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition); -} extern "C" { pub fn Gecko_Construct_Default_nsStylePosition(ptr: *mut nsStylePosition, pres_context: @@ -910,9 +876,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStylePosition(ptr: *mut nsStylePosition); } -extern "C" { - pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleTextReset(ptr: *mut nsStyleTextReset, @@ -927,9 +890,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleTextReset(ptr: *mut nsStyleTextReset); } -extern "C" { - pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleDisplay(ptr: *mut nsStyleDisplay, pres_context: @@ -942,9 +902,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleDisplay(ptr: *mut nsStyleDisplay); } -extern "C" { - pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleContent(ptr: *mut nsStyleContent, pres_context: @@ -957,9 +914,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleContent(ptr: *mut nsStyleContent); } -extern "C" { - pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleUIReset(ptr: *mut nsStyleUIReset, pres_context: @@ -972,9 +926,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleUIReset(ptr: *mut nsStyleUIReset); } -extern "C" { - pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleTable(ptr: *mut nsStyleTable, pres_context: @@ -987,9 +938,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleTable(ptr: *mut nsStyleTable); } -extern "C" { - pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleMargin(ptr: *mut nsStyleMargin, pres_context: @@ -1002,9 +950,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleMargin(ptr: *mut nsStyleMargin); } -extern "C" { - pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding); -} extern "C" { pub fn Gecko_Construct_Default_nsStylePadding(ptr: *mut nsStylePadding, pres_context: @@ -1017,9 +962,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStylePadding(ptr: *mut nsStylePadding); } -extern "C" { - pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleBorder(ptr: *mut nsStyleBorder, pres_context: @@ -1032,9 +974,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleBorder(ptr: *mut nsStyleBorder); } -extern "C" { - pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleOutline(ptr: *mut nsStyleOutline, pres_context: @@ -1047,9 +986,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleOutline(ptr: *mut nsStyleOutline); } -extern "C" { - pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleXUL(ptr: *mut nsStyleXUL, pres_context: @@ -1062,9 +998,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleXUL(ptr: *mut nsStyleXUL); } -extern "C" { - pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, pres_context: @@ -1077,9 +1010,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); } -extern "C" { - pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleColumn(ptr: *mut nsStyleColumn, pres_context: @@ -1092,9 +1022,6 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleColumn(ptr: *mut nsStyleColumn); } -extern "C" { - pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects); -} extern "C" { pub fn Gecko_Construct_Default_nsStyleEffects(ptr: *mut nsStyleEffects, pres_context: @@ -1107,6 +1034,9 @@ extern "C" { extern "C" { pub fn Gecko_Destroy_nsStyleEffects(ptr: *mut nsStyleEffects); } +extern "C" { + pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); +} extern "C" { pub fn Servo_Element_ClearData(node: RawGeckoElementBorrowed); } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 972f3aab42a..2a6dde3e576 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -15,7 +15,6 @@ use custom_properties::ComputedValuesMap; use gecko_bindings::bindings; % for style_struct in data.style_structs: use gecko_bindings::structs::${style_struct.gecko_ffi_name}; -use gecko_bindings::bindings::Gecko_Construct_${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_Construct_Default_${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_CopyConstruct_${style_struct.gecko_ffi_name}; use gecko_bindings::bindings::Gecko_Destroy_${style_struct.gecko_ffi_name}; @@ -394,14 +393,6 @@ def set_gecko_property(ffi_name, expr): <%def name="impl_style_struct(style_struct)"> impl ${style_struct.gecko_struct_name} { - #[allow(dead_code, unused_variables)] - pub fn initial() -> Arc { - let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } }); - unsafe { - Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko); - } - result - } #[allow(dead_code, unused_variables)] pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc { let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });