diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-01-04 21:01:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 21:01:38 -0800 |
commit | 143dfc879e609603839502d61bc064fba96cc80f (patch) | |
tree | 265320a870027cb37d355aeacebff435db4be8ec | |
parent | 16b0da5004fd730de87883daa35a78b6af01f042 (diff) | |
parent | dd80b5c0e7b0ad62b7897ac17782d573a2fa16ea (diff) | |
download | servo-143dfc879e609603839502d61bc064fba96cc80f.tar.gz servo-143dfc879e609603839502d61bc064fba96cc80f.zip |
Auto merge of #14848 - bzbarsky:initial-styles, r=bholley
Stop using global initial styles for stylo; the initial styles need to be per-document
<!-- 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
- [X] These changes fix https://bugzilla.mozilla.org/show_bug.cgi?id=1298588
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests on the servo side because behavior is unchanged. Gecko-side tests probably exist.
<!-- 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/14848)
<!-- Reviewable:end -->
-rw-r--r-- | components/layout/construct.rs | 44 | ||||
-rw-r--r-- | components/layout_thread/lib.rs | 6 | ||||
-rw-r--r-- | components/script_layout_interface/wrapper_traits.rs | 4 | ||||
-rw-r--r-- | components/style/animation.rs | 1 | ||||
-rw-r--r-- | components/style/build_gecko.rs | 3 | ||||
-rw-r--r-- | components/style/context.rs | 5 | ||||
-rw-r--r-- | components/style/gecko/data.rs | 15 | ||||
-rw-r--r-- | components/style/gecko_bindings/bindings.rs | 125 | ||||
-rw-r--r-- | components/style/gecko_bindings/structs_debug.rs | 2 | ||||
-rw-r--r-- | components/style/gecko_bindings/structs_release.rs | 2 | ||||
-rw-r--r-- | components/style/matching.rs | 2 | ||||
-rw-r--r-- | components/style/media_queries.rs | 41 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 60 | ||||
-rw-r--r-- | components/style/properties/helpers.mako.rs | 3 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 11 | ||||
-rw-r--r-- | components/style/stylist.rs | 20 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 14 | ||||
-rw-r--r-- | components/style/viewport.rs | 13 | ||||
-rw-r--r-- | ports/geckolib/glue.rs | 58 | ||||
-rw-r--r-- | tests/unit/style/parsing/image.rs | 10 |
20 files changed, 287 insertions, 152 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 660d4f64834..7c039d38729 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. @@ -662,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) @@ -1094,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, @@ -1123,7 +1123,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 +1889,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 +1915,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 +1947,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 +1999,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 +2036,13 @@ impl Legalizer { /// Creates an anonymous flow and pushes it onto the stack. fn push_new_anonymous_flow<F>(&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 +2055,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<F>(stylist: &Stylist, + fn create_anonymous_flow<F>(context: &SharedStyleContext, reference: &FlowRef, pseudos: &[PseudoElement], specific_fragment_info: SpecificFragmentInfo, @@ -2065,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 = 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/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/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/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/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/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<ComputedValues>, } /// A thread-local style context. diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index f67e3871bbc..dd4ae30a429 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -8,11 +8,13 @@ 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}; use num_cpus; use parking_lot::RwLock; +use properties::ComputedValues; use rayon; use std::cmp; use std::collections::HashMap; @@ -55,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<ComputedValues> } /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics @@ -73,10 +78,15 @@ lazy_static! { impl PerDocumentStyleData { /// Create a dummy `PerDocumentStyleData`. - pub fn new() -> Self { + pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self { // FIXME(bholley): Real window size. let window_size: TypedSize2D<f32, ViewportPx> = 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(); @@ -96,6 +106,7 @@ impl PerDocumentStyleData { rayon::ThreadPool::new(configuration).ok() }, num_threads: *NUM_THREADS, + default_computed_values: default_computed_values, })) } diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 77a2fb2712d..1b560cd4518 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; @@ -730,7 +733,9 @@ extern "C" { *mut nsCSSValueSharedList); } extern "C" { - pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont); + pub fn Gecko_Construct_Default_nsStyleFont(ptr: *mut nsStyleFont, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont, @@ -740,7 +745,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleFont(ptr: *mut nsStyleFont); } extern "C" { - pub fn Gecko_Construct_nsStyleColor(ptr: *mut nsStyleColor); + pub fn Gecko_Construct_Default_nsStyleColor(ptr: *mut nsStyleColor, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleColor(ptr: *mut nsStyleColor, @@ -750,7 +757,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleColor(ptr: *mut nsStyleColor); } extern "C" { - pub fn Gecko_Construct_nsStyleList(ptr: *mut nsStyleList); + pub fn Gecko_Construct_Default_nsStyleList(ptr: *mut nsStyleList, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleList(ptr: *mut nsStyleList, @@ -760,7 +769,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleList(ptr: *mut nsStyleList); } extern "C" { - pub fn Gecko_Construct_nsStyleText(ptr: *mut nsStyleText); + pub fn Gecko_Construct_Default_nsStyleText(ptr: *mut nsStyleText, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleText(ptr: *mut nsStyleText, @@ -770,7 +781,10 @@ extern "C" { pub fn Gecko_Destroy_nsStyleText(ptr: *mut nsStyleText); } extern "C" { - pub fn Gecko_Construct_nsStyleVisibility(ptr: *mut nsStyleVisibility); + pub fn Gecko_Construct_Default_nsStyleVisibility(ptr: + *mut nsStyleVisibility, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleVisibility(ptr: *mut nsStyleVisibility, @@ -781,8 +795,10 @@ extern "C" { pub fn Gecko_Destroy_nsStyleVisibility(ptr: *mut nsStyleVisibility); } extern "C" { - pub fn Gecko_Construct_nsStyleUserInterface(ptr: - *mut nsStyleUserInterface); + pub fn Gecko_Construct_Default_nsStyleUserInterface(ptr: + *mut nsStyleUserInterface, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleUserInterface(ptr: @@ -794,7 +810,10 @@ extern "C" { pub fn Gecko_Destroy_nsStyleUserInterface(ptr: *mut nsStyleUserInterface); } extern "C" { - pub fn Gecko_Construct_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); + pub fn Gecko_Construct_Default_nsStyleTableBorder(ptr: + *mut nsStyleTableBorder, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleTableBorder(ptr: @@ -806,7 +825,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleTableBorder(ptr: *mut nsStyleTableBorder); } extern "C" { - pub fn Gecko_Construct_nsStyleSVG(ptr: *mut nsStyleSVG); + pub fn Gecko_Construct_Default_nsStyleSVG(ptr: *mut nsStyleSVG, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleSVG(ptr: *mut nsStyleSVG, @@ -816,7 +837,10 @@ extern "C" { pub fn Gecko_Destroy_nsStyleSVG(ptr: *mut nsStyleSVG); } extern "C" { - pub fn Gecko_Construct_nsStyleVariables(ptr: *mut nsStyleVariables); + pub fn Gecko_Construct_Default_nsStyleVariables(ptr: + *mut nsStyleVariables, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleVariables(ptr: *mut nsStyleVariables, @@ -827,7 +851,10 @@ extern "C" { pub fn Gecko_Destroy_nsStyleVariables(ptr: *mut nsStyleVariables); } extern "C" { - pub fn Gecko_Construct_nsStyleBackground(ptr: *mut nsStyleBackground); + pub fn Gecko_Construct_Default_nsStyleBackground(ptr: + *mut nsStyleBackground, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleBackground(ptr: *mut nsStyleBackground, @@ -838,7 +865,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleBackground(ptr: *mut nsStyleBackground); } extern "C" { - pub fn Gecko_Construct_nsStylePosition(ptr: *mut nsStylePosition); + pub fn Gecko_Construct_Default_nsStylePosition(ptr: *mut nsStylePosition, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStylePosition(ptr: *mut nsStylePosition, @@ -848,7 +877,10 @@ extern "C" { pub fn Gecko_Destroy_nsStylePosition(ptr: *mut nsStylePosition); } extern "C" { - pub fn Gecko_Construct_nsStyleTextReset(ptr: *mut nsStyleTextReset); + pub fn Gecko_Construct_Default_nsStyleTextReset(ptr: + *mut nsStyleTextReset, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleTextReset(ptr: *mut nsStyleTextReset, @@ -859,7 +891,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleTextReset(ptr: *mut nsStyleTextReset); } extern "C" { - pub fn Gecko_Construct_nsStyleDisplay(ptr: *mut nsStyleDisplay); + pub fn Gecko_Construct_Default_nsStyleDisplay(ptr: *mut nsStyleDisplay, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleDisplay(ptr: *mut nsStyleDisplay, @@ -869,7 +903,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleDisplay(ptr: *mut nsStyleDisplay); } extern "C" { - pub fn Gecko_Construct_nsStyleContent(ptr: *mut nsStyleContent); + pub fn Gecko_Construct_Default_nsStyleContent(ptr: *mut nsStyleContent, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleContent(ptr: *mut nsStyleContent, @@ -879,7 +915,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleContent(ptr: *mut nsStyleContent); } extern "C" { - pub fn Gecko_Construct_nsStyleUIReset(ptr: *mut nsStyleUIReset); + pub fn Gecko_Construct_Default_nsStyleUIReset(ptr: *mut nsStyleUIReset, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleUIReset(ptr: *mut nsStyleUIReset, @@ -889,7 +927,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleUIReset(ptr: *mut nsStyleUIReset); } extern "C" { - pub fn Gecko_Construct_nsStyleTable(ptr: *mut nsStyleTable); + pub fn Gecko_Construct_Default_nsStyleTable(ptr: *mut nsStyleTable, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleTable(ptr: *mut nsStyleTable, @@ -899,7 +939,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleTable(ptr: *mut nsStyleTable); } extern "C" { - pub fn Gecko_Construct_nsStyleMargin(ptr: *mut nsStyleMargin); + pub fn Gecko_Construct_Default_nsStyleMargin(ptr: *mut nsStyleMargin, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleMargin(ptr: *mut nsStyleMargin, @@ -909,7 +951,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleMargin(ptr: *mut nsStyleMargin); } extern "C" { - pub fn Gecko_Construct_nsStylePadding(ptr: *mut nsStylePadding); + pub fn Gecko_Construct_Default_nsStylePadding(ptr: *mut nsStylePadding, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStylePadding(ptr: *mut nsStylePadding, @@ -919,7 +963,9 @@ extern "C" { pub fn Gecko_Destroy_nsStylePadding(ptr: *mut nsStylePadding); } extern "C" { - pub fn Gecko_Construct_nsStyleBorder(ptr: *mut nsStyleBorder); + pub fn Gecko_Construct_Default_nsStyleBorder(ptr: *mut nsStyleBorder, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleBorder(ptr: *mut nsStyleBorder, @@ -929,7 +975,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleBorder(ptr: *mut nsStyleBorder); } extern "C" { - pub fn Gecko_Construct_nsStyleOutline(ptr: *mut nsStyleOutline); + pub fn Gecko_Construct_Default_nsStyleOutline(ptr: *mut nsStyleOutline, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleOutline(ptr: *mut nsStyleOutline, @@ -939,7 +987,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleOutline(ptr: *mut nsStyleOutline); } extern "C" { - pub fn Gecko_Construct_nsStyleXUL(ptr: *mut nsStyleXUL); + pub fn Gecko_Construct_Default_nsStyleXUL(ptr: *mut nsStyleXUL, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleXUL(ptr: *mut nsStyleXUL, @@ -949,7 +999,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleXUL(ptr: *mut nsStyleXUL); } extern "C" { - pub fn Gecko_Construct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); + pub fn Gecko_Construct_Default_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleSVGReset(ptr: *mut nsStyleSVGReset, @@ -959,7 +1011,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleSVGReset(ptr: *mut nsStyleSVGReset); } extern "C" { - pub fn Gecko_Construct_nsStyleColumn(ptr: *mut nsStyleColumn); + pub fn Gecko_Construct_Default_nsStyleColumn(ptr: *mut nsStyleColumn, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleColumn(ptr: *mut nsStyleColumn, @@ -969,7 +1023,9 @@ extern "C" { pub fn Gecko_Destroy_nsStyleColumn(ptr: *mut nsStyleColumn); } extern "C" { - pub fn Gecko_Construct_nsStyleEffects(ptr: *mut nsStyleEffects); + pub fn Gecko_Construct_Default_nsStyleEffects(ptr: *mut nsStyleEffects, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Gecko_CopyConstruct_nsStyleEffects(ptr: *mut nsStyleEffects, @@ -979,6 +1035,9 @@ 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); } extern "C" { @@ -1028,7 +1087,14 @@ 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_RecomputeDefaultStyles(set: + RawServoStyleSetBorrowed, + pres_context: + RawGeckoPresContextBorrowed); } extern "C" { pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed, @@ -1112,7 +1178,8 @@ extern "C" { -> RawServoDeclarationBlockStrong; } extern "C" { - pub fn Servo_RestyleWithAddedDeclaration(declarations: + pub fn Servo_RestyleWithAddedDeclaration(set: RawServoStyleSetBorrowed, + declarations: RawServoDeclarationBlockBorrowed, previous_style: ServoComputedValuesBorrowed) @@ -1225,7 +1292,8 @@ extern "C" { -> ServoComputedValuesStrong; } extern "C" { - pub fn Servo_ComputedValues_Inherit(parent_style: + pub fn Servo_ComputedValues_Inherit(set: RawServoStyleSetBorrowed, + parent_style: ServoComputedValuesBorrowedOrNull) -> ServoComputedValuesStrong; } @@ -1250,6 +1318,7 @@ extern "C" { } extern "C" { pub fn Servo_ResolveStyle(element: RawGeckoElementBorrowed, + set: RawServoStyleSetBorrowed, consume: ConsumeStyleBehavior) -> ServoComputedValuesStrong; } 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/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/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<T> { } impl Range<specified::Length> { - fn to_computed_range(&self, viewport_size: Size2D<Au>) -> Range<Au> { + fn to_computed_range(&self, viewport_size: Size2D<Au>, default_values: &ComputedValues) -> Range<Au> { // 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<f32, ViewportPx>, + #[cfg(feature = "gecko")] + pub default_values: Arc<ComputedValues>, } impl Device { + #[cfg(feature = "servo")] pub fn new(media_type: MediaType, viewport_size: TypedSize2D<f32, ViewportPx>) -> 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<f32, ViewportPx>, + default_values: &Arc<ComputedValues>) -> 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<Au> { 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/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ab0f6b4d46c..2a6dde3e576 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -15,7 +15,7 @@ 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}; % endfor @@ -40,6 +40,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}; @@ -53,7 +54,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; @@ -76,7 +76,7 @@ pub struct ComputedValues { } impl ComputedValues { - pub fn inherit_from(parent: &Arc<Self>) -> Arc<Self> { + pub fn inherit_from(parent: &Arc<Self>, default: &Arc<Self>) -> Arc<Self> { Arc::new(ComputedValues { custom_properties: parent.custom_properties.clone(), shareable: parent.shareable, @@ -86,7 +86,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 }) @@ -111,37 +111,16 @@ impl ComputedValues { } } - pub fn style_for_child_text_node(parent: &Arc<Self>) -> Arc<Self> { - // 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()); - &*raw_initial_values() - } - } - - 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 + pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> { + Arc::new(ComputedValues { 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()); + 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 + }) } % for style_struct in data.style_structs: @@ -415,10 +394,11 @@ 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<Self> { + pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> { 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); + Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko, + pres_context); } result } @@ -2646,13 +2626,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/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<ComputedValues>, 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 0a5eb2d3087..77175707ef2 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1658,6 +1658,7 @@ mod lazy_static_module { pub type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration, inherited_style: &ComputedValues, + default_style: &Arc<ComputedValues>, context: &mut computed::Context, seen: &mut PropertyBitField, cacheable: &mut bool, @@ -1704,13 +1705,14 @@ bitflags! { pub fn cascade(viewport_size: Size2D<Au>, rule_node: &StrongRuleNode, parent_style: Option<<&ComputedValues>, + default_style: &Arc<ComputedValues>, cascade_info: Option<<&mut CascadeInfo>, error_reporter: StdBox<ParseErrorReporter + Send>, 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. @@ -1735,6 +1737,7 @@ pub fn cascade(viewport_size: Size2D<Au>, is_root_element, iter_declarations, inherited_style, + default_style, cascade_info, error_reporter, None, @@ -1747,6 +1750,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>, is_root_element: bool, iter_declarations: F, inherited_style: &ComputedValues, + default_style: &Arc<ComputedValues>, mut cascade_info: Option<<&mut CascadeInfo>, mut error_reporter: StdBox<ParseErrorReporter + Send>, font_metrics_provider: Option<<&FontMetricsProvider>, @@ -1773,8 +1777,6 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>, ::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), @@ -1784,7 +1786,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>, % 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 ) @@ -1864,6 +1866,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>, let discriminant = longhand_id as usize; (CASCADE_PROPERTY[discriminant])(declaration, inherited_style, + default_style, &mut context, &mut seen, &mut cacheable, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 1a1dfabaf3d..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; @@ -274,6 +277,7 @@ impl Stylist { pub fn precomputed_values_for_pseudo(&self, pseudo: &PseudoElement, parent: Option<&Arc<ComputedValues>>, + default: &Arc<ComputedValues>, inherit_all: bool) -> Option<ComputedStyle> { debug_assert!(SelectorImpl::pseudo_element_cascade_type(pseudo).is_precomputed()); @@ -293,6 +297,7 @@ impl Stylist { properties::cascade(self.device.au_viewport_size(), &rule_node, parent.map(|p| &**p), + default, None, Box::new(StdoutErrorReporter), flags); @@ -306,7 +311,8 @@ impl Stylist { #[cfg(feature = "servo")] pub fn style_for_anonymous_box(&self, pseudo: &PseudoElement, - parent_style: &Arc<ComputedValues>) + parent_style: &Arc<ComputedValues>, + default_style: &Arc<ComputedValues>) -> Arc<ComputedValues> { // For most (but not all) pseudo-elements, we inherit all values from the parent. let inherit_all = match *pseudo { @@ -325,7 +331,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 +346,8 @@ impl Stylist { pub fn lazily_compute_pseudo_element_style<E>(&self, element: &E, pseudo: &PseudoElement, - parent: &Arc<ComputedValues>) + parent: &Arc<ComputedValues>, + default: &Arc<ComputedValues>) -> Option<ComputedStyle> where E: ElementExt + fmt::Debug + @@ -368,6 +375,7 @@ impl Stylist { properties::cascade(self.device.au_viewport_size(), &rule_node, Some(&**parent), + default, None, Box::new(StdoutErrorReporter), CascadeFlags::empty()); @@ -380,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<Stylesheet>]) { let cascaded_rule = ViewportRule { declarations: viewport::Cascade::from_stylesheets(stylesheets, &device).finish(), 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<Au>, 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/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<ViewportConstraints>; } +/// 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<f32, ViewportPx>, rule: &ViewportRule) diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 87ef1c87738..aeb1fe6484e 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; @@ -81,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 { @@ -111,20 +107,12 @@ 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(), } } 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() { @@ -168,7 +156,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 { @@ -181,11 +170,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, @@ -529,7 +521,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()) } @@ -542,6 +535,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() { @@ -549,11 +543,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(), @@ -572,20 +565,23 @@ 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()) }, } } #[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() } @@ -601,12 +597,22 @@ 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() } #[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); + // FIXME(bz): We need to update our Stylist's Device's computed values, but how? +} + +#[no_mangle] pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () { let _ = data.into_box::<PerDocumentStyleData>(); } @@ -928,6 +934,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 { @@ -935,10 +942,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(); 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))); } |