Skip to content

Commit

Permalink
Auto merge of #14848 - bzbarsky:initial-styles, r=bholley
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Jan 5, 2017
2 parents 16b0da5 + dd80b5c commit 143dfc8
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 152 deletions.
44 changes: 22 additions & 22 deletions components/layout/construct.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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());
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions components/layout_thread/lib.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
Expand Down
4 changes: 3 additions & 1 deletion components/script_layout_interface/wrapper_traits.rs
Expand Up @@ -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());
Expand All @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions components/style/animation.rs
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions components/style/build_gecko.rs
Expand Up @@ -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] };
Expand Down Expand Up @@ -467,6 +468,7 @@ mod bindings {
"RawGeckoDocument",
"RawGeckoElement",
"RawGeckoNode",
"RawGeckoPresContext",
"ThreadSafeURIHolder",
"ThreadSafePrincipalHolder",
"ConsumeStyleBehavior",
Expand Down Expand Up @@ -560,6 +562,7 @@ mod bindings {
"RawGeckoElement",
"RawGeckoDocument",
"RawServoDeclarationBlockStrong",
"RawGeckoPresContext",
];
let servo_borrow_types = [
"nsCSSValue",
Expand Down
5 changes: 5 additions & 0 deletions components/style/context.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions components/style/gecko/data.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -96,6 +106,7 @@ impl PerDocumentStyleData {
rayon::ThreadPool::new(configuration).ok()
},
num_threads: *NUM_THREADS,
default_computed_values: default_computed_values,
}))
}

Expand Down

0 comments on commit 143dfc8

Please sign in to comment.