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 -->
This commit is contained in:
bors-servo 2017-01-04 21:01:38 -08:00 committed by GitHub
commit 143dfc879e
20 changed files with 287 additions and 152 deletions

View file

@ -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,

View file

@ -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()),

View file

@ -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());
}

View file

@ -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,

View file

@ -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",

View file

@ -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.

View file

@ -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,
}))
}

View file

@ -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,
@ -978,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);
}
@ -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;
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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)

View file

@ -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),
}
});

View file

@ -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);
}

View file

@ -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});

View file

@ -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,

View file

@ -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(),

View file

@ -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.

View file

@ -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)