Auto merge of #17788 - emilio:clean-cascade, r=heycam

style: Cleanup the cascade a good bit.

Was about the time.

<!-- 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/17788)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-07-20 02:36:15 -07:00 committed by GitHub
commit f594ae58a6
20 changed files with 286 additions and 248 deletions

View file

@ -138,7 +138,7 @@ impl Angle {
impl nsStyleImage { impl nsStyleImage {
/// Set a given Servo `Image` value into this `nsStyleImage`. /// Set a given Servo `Image` value into this `nsStyleImage`.
pub fn set(&mut self, image: Image, cacheable: &mut bool) { pub fn set(&mut self, image: Image) {
match image { match image {
GenericImage::Gradient(gradient) => { GenericImage::Gradient(gradient) => {
self.set_gradient(gradient) self.set_gradient(gradient)
@ -146,14 +146,6 @@ impl nsStyleImage {
GenericImage::Url(ref url) => { GenericImage::Url(ref url) => {
unsafe { unsafe {
Gecko_SetLayerImageImageValue(self, url.image_value.clone().unwrap().get()); Gecko_SetLayerImageImageValue(self, url.image_value.clone().unwrap().get());
// We unfortunately must make any url() value uncacheable, since
// the applicable declarations cache is not per document, but
// global, and the imgRequestProxy objects we store in the style
// structs don't like to be tracked by more than one document.
//
// FIXME(emilio): With the scoped TLS thing this is no longer
// true, remove this line in a follow-up!
*cacheable = false;
} }
}, },
GenericImage::Rect(ref image_rect) => { GenericImage::Rect(ref image_rect) => {
@ -161,15 +153,6 @@ impl nsStyleImage {
Gecko_SetLayerImageImageValue(self, image_rect.url.image_value.clone().unwrap().get()); Gecko_SetLayerImageImageValue(self, image_rect.url.image_value.clone().unwrap().get());
Gecko_InitializeImageCropRect(self); Gecko_InitializeImageCropRect(self);
// We unfortunately must make any url() value uncacheable, since
// the applicable declarations cache is not per document, but
// global, and the imgRequestProxy objects we store in the style
// structs don't like to be tracked by more than one document.
//
// FIXME(emilio): With the scoped TLS thing this is no longer
// true, remove this line in a follow-up!
*cacheable = false;
// Set CropRect // Set CropRect
let ref mut rect = *self.mCropRect.mPtr; let ref mut rect = *self.mCropRect.mPtr;
image_rect.top.to_gecko_style_coord(&mut rect.data_at_mut(0)); image_rect.top.to_gecko_style_coord(&mut rect.data_at_mut(0));

View file

@ -624,9 +624,7 @@ impl Expression {
// em units are relative to the initial font-size. // em units are relative to the initial font-size.
let context = computed::Context { let context = computed::Context {
is_root_element: false, is_root_element: false,
device: device, builder: StyleBuilder::for_derived_style(device, default_values, None, None),
inherited_style: default_values,
style: StyleBuilder::for_derived_style(device, default_values, None),
font_metrics_provider: &provider, font_metrics_provider: &provider,
cached_system_font: None, cached_system_font: None,
in_media_query: true, in_media_query: true,

View file

@ -1189,7 +1189,7 @@ fn static_assert() {
} }
if let Either::Second(image) = image { if let Either::Second(image) = image {
self.gecko.mBorderImageSource.set(image, &mut false) self.gecko.mBorderImageSource.set(image);
} }
} }
@ -3423,7 +3423,7 @@ fn static_assert() {
} }
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn set_${shorthand}_image<I>(&mut self, images: I, cacheable: &mut bool) pub fn set_${shorthand}_image<I>(&mut self, images: I)
where I: IntoIterator<Item = longhands::${shorthand}_image::computed_value::single_value::T>, where I: IntoIterator<Item = longhands::${shorthand}_image::computed_value::single_value::T>,
I::IntoIter: ExactSizeIterator I::IntoIter: ExactSizeIterator
{ {
@ -3446,7 +3446,7 @@ fn static_assert() {
for (image, geckoimage) in images.zip(self.gecko.${image_layers_field} for (image, geckoimage) in images.zip(self.gecko.${image_layers_field}
.mLayers.iter_mut()) { .mLayers.iter_mut()) {
if let Either::Second(image) = image { if let Either::Second(image) = image {
geckoimage.mImage.set(image, cacheable) geckoimage.mImage.set(image)
} }
} }
} }

View file

@ -263,6 +263,7 @@
fn to_computed_value(&self, context: &Context) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
computed_value::T(self.compute_iter(context).collect()) computed_value::T(self.compute_iter(context).collect())
} }
#[inline] #[inline]
fn from_computed_value(computed: &computed_value::T) -> Self { fn from_computed_value(computed: &computed_value::T) -> Self {
SpecifiedValue(computed.0.iter() SpecifiedValue(computed.0.iter()
@ -316,12 +317,11 @@
use Atom; use Atom;
${caller.body()} ${caller.body()}
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn cascade_property(declaration: &PropertyDeclaration, pub fn cascade_property(
inherited_style: &ComputedValues, declaration: &PropertyDeclaration,
default_style: &ComputedValues, context: &mut computed::Context,
context: &mut computed::Context, cascade_info: &mut Option<<&mut CascadeInfo>,
cacheable: &mut bool, ) {
cascade_info: &mut Option<<&mut CascadeInfo>) {
let value = match *declaration { let value = match *declaration {
PropertyDeclaration::${property.camel_case}(ref value) => { PropertyDeclaration::${property.camel_case}(ref value) => {
DeclaredValue::Value(value) DeclaredValue::Value(value)
@ -338,18 +338,8 @@
% if not property.derived_from: % if not property.derived_from:
if let Some(ref mut cascade_info) = *cascade_info { if let Some(ref mut cascade_info) = *cascade_info {
cascade_info.on_cascade_property(&declaration, cascade_info.on_cascade_property(&declaration, &value);
&value);
} }
% if property.logical:
let wm = context.style.writing_mode;
% endif
<%
maybe_wm = ", wm" if property.logical else ""
maybe_cacheable = ", cacheable" if property.has_uncacheable_values == "True" else ""
props_need_device = "content list_style_type".split() if product == "gecko" else []
maybe_device = ", context.device" if property.ident in props_need_device else ""
%>
match value { match value {
DeclaredValue::Value(ref specified_value) => { DeclaredValue::Value(ref specified_value) => {
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko": % if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
@ -358,30 +348,33 @@
} }
% endif % endif
% if property.is_vector: % if property.is_vector:
// In the case of a vector property we want to pass down // In the case of a vector property we want to pass
// an iterator so that this can be computed without allocation // down an iterator so that this can be computed
// without allocation
// //
// However, computing requires a context, but the style struct // However, computing requires a context, but the
// being mutated is on the context. We temporarily remove it, // style struct being mutated is on the context. We
// mutate it, and then put it back. Vector longhands cannot // temporarily remove it, mutate it, and then put it
// touch their own style struct whilst computing, else this will panic. // back. Vector longhands cannot touch their own
let mut s = context.mutate_style().take_${data.current_style_struct.name_lower}(); // style struct whilst computing, else this will
// panic.
let mut s =
context.builder.take_${data.current_style_struct.name_lower}();
{ {
let iter = specified_value.compute_iter(context); let iter = specified_value.compute_iter(context);
s.set_${property.ident}(iter ${maybe_cacheable}); s.set_${property.ident}(iter);
} }
context.mutate_style().put_${data.current_style_struct.name_lower}(s); context.builder.put_${data.current_style_struct.name_lower}(s);
% else: % else:
let computed = specified_value.to_computed_value(context); let computed = specified_value.to_computed_value(context);
% if property.ident == "font_size": % if property.ident == "font_size":
longhands::font_size::cascade_specified_font_size(context, longhands::font_size::cascade_specified_font_size(
specified_value, context,
computed, &specified_value,
inherited_style.get_font()); computed,
);
% else: % else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}() context.builder.set_${property.ident}(computed)
.set_${property.ident}(computed ${maybe_device}
${maybe_cacheable} ${maybe_wm});
% endif % endif
% endif % endif
} }
@ -394,41 +387,24 @@
% if property.ident == "font_size": % if property.ident == "font_size":
longhands::font_size::cascade_initial_font_size(context); longhands::font_size::cascade_initial_font_size(context);
% else: % else:
// We assume that it's faster to use copy_*_from rather than context.builder.reset_${property.ident}();
// set_*(get_initial_value());
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});
% endif % endif
}, },
% if data.current_style_struct.inherited: % if data.current_style_struct.inherited:
CSSWideKeyword::Unset | CSSWideKeyword::Unset |
% endif % endif
CSSWideKeyword::Inherit => { CSSWideKeyword::Inherit => {
// This is a bit slow, but this is rare so it shouldn't
// matter.
//
// FIXME: is it still?
*cacheable = false;
let inherited_struct =
inherited_style.get_${data.current_style_struct.name_lower}();
% if property.ident == "font_size": % if property.ident == "font_size":
longhands::font_size::cascade_inherit_font_size(context, inherited_struct); longhands::font_size::cascade_inherit_font_size(context);
% else: % else:
context.mutate_style().mutate_${data.current_style_struct.name_lower}() context.builder.inherit_${property.ident}();
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
% endif % endif
} }
} }
} }
% if property.custom_cascade: % if property.custom_cascade:
cascade_property_custom(declaration, cascade_property_custom(declaration, context);
inherited_style,
context,
cacheable);
% endif % endif
% else: % else:
// Do not allow stylesheets to set derived properties. // Do not allow stylesheets to set derived properties.
@ -1108,7 +1084,7 @@
% else: % else:
if let ${length_type}::ExtremumLength(..) = computed { if let ${length_type}::ExtremumLength(..) = computed {
<% is_height = "true" if "height" in name else "false" %> <% is_height = "true" if "height" in name else "false" %>
if ${is_height} != context.style().writing_mode.is_vertical() { if ${is_height} != context.builder.writing_mode.is_vertical() {
return get_initial_value() return get_initial_value()
} }
} }

View file

@ -455,12 +455,7 @@ impl AnimatedProperty {
let value: longhands::${prop.ident}::computed_value::T = let value: longhands::${prop.ident}::computed_value::T =
ToAnimatedValue::from_animated_value(value); ToAnimatedValue::from_animated_value(value);
% endif % endif
<% method = "style.mutate_" + prop.style_struct.ident.strip("_") + "().set_" + prop.ident %> style.mutate_${prop.style_struct.name_lower}().set_${prop.ident}(value);
% if prop.has_uncacheable_values is "True":
${method}(value, &mut false);
% else:
${method}(value);
% endif
} }
% endif % endif
% endfor % endfor
@ -562,9 +557,12 @@ impl AnimationValue {
} }
} }
/// Construct an AnimationValue from a property declaration /// Construct an AnimationValue from a property declaration.
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context, pub fn from_declaration(
initial: &ComputedValues) -> Option<Self> { decl: &PropertyDeclaration,
context: &mut Context,
initial: &ComputedValues
) -> Option<Self> {
use properties::LonghandId; use properties::LonghandId;
match *decl { match *decl {
@ -606,7 +604,7 @@ impl AnimationValue {
CSSWideKeyword::Unset | CSSWideKeyword::Unset |
% endif % endif
CSSWideKeyword::Inherit => { CSSWideKeyword::Inherit => {
let inherit_struct = context.inherited_style let inherit_struct = context.inherited_style()
.get_${prop.style_struct.name_lower}(); .get_${prop.style_struct.name_lower}();
inherit_struct.clone_${prop.ident}() inherit_struct.clone_${prop.ident}()
}, },

View file

@ -181,9 +181,7 @@
% if product == "servo": % if product == "servo":
fn cascade_property_custom(_declaration: &PropertyDeclaration, fn cascade_property_custom(_declaration: &PropertyDeclaration,
_inherited_style: &ComputedValues, context: &mut computed::Context) {
context: &mut computed::Context,
_cacheable: &mut bool) {
longhands::_servo_display_for_hypothetical_box::derive_from_display(context); longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
longhands::_servo_text_decorations_in_effect::derive_from_display(context); longhands::_servo_text_decorations_in_effect::derive_from_display(context);
longhands::_servo_under_display_none::derive_from_display(context); longhands::_servo_under_display_none::derive_from_display(context);
@ -302,7 +300,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
#[inline] #[inline]
pub fn derive_from_display(context: &mut Context) { pub fn derive_from_display(context: &mut Context) {
let d = context.style().get_box().clone_display(); let d = context.style().get_box().clone_display();
context.mutate_style().mutate_box().set__servo_display_for_hypothetical_box(d); context.builder.set__servo_display_for_hypothetical_box(d);
} }
</%helpers:longhand> </%helpers:longhand>

View file

@ -21,7 +21,7 @@
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
self.0.to_computed_value(context) self.0.to_computed_value(context)
.to_rgba(context.inherited_style.get_color().clone_color()) .to_rgba(context.inherited_style().get_color().clone_color())
} }
#[inline] #[inline]
@ -109,7 +109,7 @@
fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue { fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
unsafe { unsafe {
Gecko_GetLookAndFeelSystemColor(*self as i32, Gecko_GetLookAndFeelSystemColor(*self as i32,
cx.device.pres_context()) cx.device().pres_context())
} }
} }

View file

@ -562,7 +562,6 @@ ${helpers.single_keyword_system("font-variant-caps",
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size"> allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
use app_units::Au; use app_units::Au;
use properties::longhands::system_font::SystemFont; use properties::longhands::system_font::SystemFont;
use properties::style_structs::Font;
use std::fmt; use std::fmt;
use style_traits::{HasViewportPercentage, ToCss}; use style_traits::{HasViewportPercentage, ToCss};
use values::FONT_MEDIUM_PX; use values::FONT_MEDIUM_PX;
@ -906,11 +905,10 @@ ${helpers.single_keyword_system("font-variant-caps",
#[allow(unused_mut)] #[allow(unused_mut)]
pub fn cascade_specified_font_size(context: &mut Context, pub fn cascade_specified_font_size(context: &mut Context,
specified_value: &SpecifiedValue, specified_value: &SpecifiedValue,
mut computed: Au, mut computed: Au) {
parent: &Font) {
if let SpecifiedValue::Keyword(kw, fraction) = *specified_value { if let SpecifiedValue::Keyword(kw, fraction) = *specified_value {
context.mutate_style().font_size_keyword = Some((kw, fraction)); context.builder.font_size_keyword = Some((kw, fraction));
} else if let Some(ratio) = specified_value.as_font_ratio() { } else if let Some(ratio) = specified_value.as_font_ratio() {
// In case a font-size-relative value was applied to a keyword // In case a font-size-relative value was applied to a keyword
// value, we must preserve this fact in case the generic font family // value, we must preserve this fact in case the generic font family
@ -918,13 +916,13 @@ ${helpers.single_keyword_system("font-variant-caps",
// recomputed from the base size for the keyword and the relative size. // recomputed from the base size for the keyword and the relative size.
// //
// See bug 1355707 // See bug 1355707
if let Some((kw, fraction)) = context.inherited_style().font_computation_data.font_size_keyword { if let Some((kw, fraction)) = context.builder.inherited_style().font_computation_data.font_size_keyword {
context.mutate_style().font_size_keyword = Some((kw, fraction * ratio)); context.builder.font_size_keyword = Some((kw, fraction * ratio));
} else { } else {
context.mutate_style().font_size_keyword = None; context.builder.font_size_keyword = None;
} }
} else { } else {
context.mutate_style().font_size_keyword = None; context.builder.font_size_keyword = None;
} }
// we could use clone_language and clone_font_family() here but that's // we could use clone_language and clone_font_family() here but that's
@ -933,61 +931,76 @@ ${helpers.single_keyword_system("font-variant-caps",
use gecko_bindings::structs::nsIAtom; use gecko_bindings::structs::nsIAtom;
// if the language or generic changed, we need to recalculate // if the language or generic changed, we need to recalculate
// the font size from the stored font-size origin information. // the font size from the stored font-size origin information.
if context.style().get_font().gecko().mLanguage.raw::<nsIAtom>() != if context.builder.get_font().gecko().mLanguage.raw::<nsIAtom>() !=
context.inherited_style().get_font().gecko().mLanguage.raw::<nsIAtom>() || context.builder.inherited_style().get_font().gecko().mLanguage.raw::<nsIAtom>() ||
context.style().get_font().gecko().mGenericID != context.builder.get_font().gecko().mGenericID !=
context.inherited_style().get_font().gecko().mGenericID { context.builder.inherited_style().get_font().gecko().mGenericID {
if let Some((kw, ratio)) = context.style().font_size_keyword { if let Some((kw, ratio)) = context.builder.font_size_keyword {
computed = kw.to_computed_value(context).scale_by(ratio); computed = kw.to_computed_value(context).scale_by(ratio);
} }
} }
% endif % endif
let device = context.builder.device;
let mut font = context.builder.take_font();
let parent_unconstrained = { let parent_unconstrained = {
let (style, device) = context.mutate_style_with_device(); let parent_style = context.builder.inherited_style();
let parent_font = parent_style.get_font();
style.mutate_font().apply_font_size(computed, parent, device) font.apply_font_size(computed, parent_font, device)
}; };
context.builder.put_font(font);
if let Some(parent) = parent_unconstrained { if let Some(parent) = parent_unconstrained {
let new_unconstrained = specified_value let new_unconstrained =
.to_computed_value_against(context, FontBaseSize::Custom(parent)); specified_value
context.mutate_style() .to_computed_value_against(context, FontBaseSize::Custom(parent));
context.builder
.mutate_font() .mutate_font()
.apply_unconstrained_font_size(new_unconstrained); .apply_unconstrained_font_size(new_unconstrained);
} }
} }
pub fn cascade_inherit_font_size(context: &mut Context, parent: &Font) { /// FIXME(emilio): This is very complex. Also, it should move to
// If inheriting, we must recompute font-size in case of language changes /// StyleBuilder.
// using the font_size_keyword. We also need to do this to handle pub fn cascade_inherit_font_size(context: &mut Context) {
// mathml scriptlevel changes // If inheriting, we must recompute font-size in case of language
let kw_inherited_size = context.style().font_size_keyword.map(|(kw, ratio)| { // changes using the font_size_keyword. We also need to do this to
// handle mathml scriptlevel changes
let kw_inherited_size = context.builder.font_size_keyword.map(|(kw, ratio)| {
SpecifiedValue::Keyword(kw, ratio).to_computed_value(context) SpecifiedValue::Keyword(kw, ratio).to_computed_value(context)
}); });
let parent_kw = context.inherited_style.font_computation_data.font_size_keyword; let parent_kw;
let (style, device) = context.mutate_style_with_device(); let device = context.builder.device;
let used_kw = style.mutate_font() let mut font = context.builder.take_font();
.inherit_font_size_from(parent, kw_inherited_size, device); let used_kw = {
if used_kw { let parent_style = context.builder.inherited_style();
style.font_size_keyword = parent_kw; let parent_font = parent_style.get_font();
} else { parent_kw = parent_style.font_computation_data.font_size_keyword;
style.font_size_keyword = None;
} font.inherit_font_size_from(parent_font, kw_inherited_size, device)
};
context.builder.put_font(font);
context.builder.font_size_keyword =
if used_kw { parent_kw } else { None };
} }
/// Cascade the initial value for the `font-size` property.
///
/// FIXME(emilio): This is the only function that is outside of the
/// `StyleBuilder`, and should really move inside!
///
/// Can we move the font stuff there?
pub fn cascade_initial_font_size(context: &mut Context) { pub fn cascade_initial_font_size(context: &mut Context) {
// font-size's default ("medium") does not always // font-size's default ("medium") does not always
// compute to the same value and depends on the font // compute to the same value and depends on the font
let computed = longhands::font_size::get_initial_specified_value() let computed = longhands::font_size::get_initial_specified_value()
.to_computed_value(context); .to_computed_value(context);
let (style, _device) = context.mutate_style_with_device(); context.builder.mutate_font().set_font_size(computed);
style.mutate_font().set_font_size(computed);
% if product == "gecko": % if product == "gecko":
style.mutate_font().fixup_font_min_size(_device); let device = context.builder.device;
context.builder.mutate_font().fixup_font_min_size(device);
% endif % endif
style.font_size_keyword = Some((Default::default(), 1.)); context.builder.font_size_keyword = Some((Default::default(), 1.));
} }
</%helpers:longhand> </%helpers:longhand>
@ -2414,8 +2427,8 @@ ${helpers.single_keyword("-moz-math-variant",
bindings::Gecko_nsFont_InitSystem( bindings::Gecko_nsFont_InitSystem(
&mut system, &mut system,
id as i32, id as i32,
cx.style.get_font().gecko(), cx.style().get_font().gecko(),
cx.device.pres_context() cx.device().pres_context()
) )
} }
let family = system.fontlist.mFontlist.iter().map(|font| { let family = system.fontlist.mFontlist.iter().map(|font| {

View file

@ -285,8 +285,8 @@ ${helpers.single_keyword("image-rendering",
use super::display::computed_value::T as Display; use super::display::computed_value::T as Display;
if context.style().get_box().clone_display() == Display::none { if context.style().get_box().clone_display() == Display::none {
context.mutate_style().mutate_inheritedbox() context.builder
.set__servo_under_display_none(SpecifiedValue(true)); .set__servo_under_display_none(SpecifiedValue(true));
} }
} }
</%helpers:longhand> </%helpers:longhand>

View file

@ -350,13 +350,13 @@ ${helpers.predefined_type("word-spacing",
#[inline] #[inline]
pub fn derive_from_text_decoration(context: &mut Context) { pub fn derive_from_text_decoration(context: &mut Context) {
let derived = derive(context); let derived = derive(context);
context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived); context.builder.set__servo_text_decorations_in_effect(derived);
} }
#[inline] #[inline]
pub fn derive_from_display(context: &mut Context) { pub fn derive_from_display(context: &mut Context) {
let derived = derive(context); let derived = derive(context);
context.mutate_style().mutate_inheritedtext().set__servo_text_decorations_in_effect(derived); context.builder.set__servo_text_decorations_in_effect(derived);
} }
</%helpers:longhand> </%helpers:longhand>

View file

@ -249,9 +249,7 @@ ${helpers.single_keyword("unicode-bidi",
% if product == "servo": % if product == "servo":
fn cascade_property_custom(_declaration: &PropertyDeclaration, fn cascade_property_custom(_declaration: &PropertyDeclaration,
_inherited_style: &ComputedValues, context: &mut computed::Context) {
context: &mut computed::Context,
_cacheable: &mut bool) {
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context); longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context);
} }
% endif % endif

View file

@ -2453,12 +2453,31 @@ impl<'a, T: 'a> ops::Deref for StyleStructRef<'a, T> {
/// actually cloning them, until we either build the style, or mutate the /// actually cloning them, until we either build the style, or mutate the
/// inherited value. /// inherited value.
pub struct StyleBuilder<'a> { pub struct StyleBuilder<'a> {
device: &'a Device, /// The device we're using to compute style.
///
/// This provides access to viewport unit ratios, etc.
pub device: &'a Device,
/// The style we're inheriting from.
///
/// This is effectively
/// `parent_style.unwrap_or(device.default_computed_values())`.
inherited_style: &'a ComputedValues,
/// The style we're getting reset structs from.
reset_style: &'a ComputedValues,
/// The style we're inheriting from explicitly, or none if we're the root of
/// a subtree.
parent_style: Option<<&'a ComputedValues>, parent_style: Option<<&'a ComputedValues>,
/// The pseudo-element this style will represent.
pseudo: Option<<&'a PseudoElement>, pseudo: Option<<&'a PseudoElement>,
/// The rule node representing the ordered list of rules matched for this /// The rule node representing the ordered list of rules matched for this
/// node. /// node.
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>, custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
/// The writing mode flags. /// The writing mode flags.
/// ///
@ -2482,7 +2501,6 @@ impl<'a> StyleBuilder<'a> {
fn new( fn new(
device: &'a Device, device: &'a Device,
parent_style: Option<<&'a ComputedValues>, parent_style: Option<<&'a ComputedValues>,
reset_style: &'a ComputedValues,
pseudo: Option<<&'a PseudoElement>, pseudo: Option<<&'a PseudoElement>,
cascade_flags: CascadeFlags, cascade_flags: CascadeFlags,
rules: Option<StrongRuleNode>, rules: Option<StrongRuleNode>,
@ -2492,6 +2510,7 @@ impl<'a> StyleBuilder<'a> {
flags: ComputedValueFlags, flags: ComputedValueFlags,
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
) -> Self { ) -> Self {
let reset_style = device.default_computed_values();
let inherited_style = parent_style.unwrap_or(reset_style); let inherited_style = parent_style.unwrap_or(reset_style);
let reset_style = if cascade_flags.contains(INHERIT_ALL) { let reset_style = if cascade_flags.contains(INHERIT_ALL) {
inherited_style inherited_style
@ -2502,6 +2521,8 @@ impl<'a> StyleBuilder<'a> {
StyleBuilder { StyleBuilder {
device, device,
parent_style, parent_style,
inherited_style,
reset_style,
pseudo, pseudo,
rules, rules,
custom_properties, custom_properties,
@ -2523,18 +2544,87 @@ impl<'a> StyleBuilder<'a> {
/// order to create a derived style. /// order to create a derived style.
pub fn for_derived_style( pub fn for_derived_style(
device: &'a Device, device: &'a Device,
s: &'a ComputedValues, style_to_derive_from: &'a ComputedValues,
parent_style: Option<<&'a ComputedValues>,
pseudo: Option<<&'a PseudoElement>, pseudo: Option<<&'a PseudoElement>,
) -> Self { ) -> Self {
Self::for_inheritance(device, s, s, pseudo) let reset_style = device.default_computed_values();
let inherited_style = parent_style.unwrap_or(reset_style);
StyleBuilder {
device,
parent_style,
inherited_style,
reset_style,
pseudo,
rules: None, // FIXME(emilio): Dubious...
custom_properties: style_to_derive_from.custom_properties(),
writing_mode: style_to_derive_from.writing_mode,
font_size_keyword: style_to_derive_from.font_computation_data.font_size_keyword,
flags: style_to_derive_from.flags,
visited_style: style_to_derive_from.clone_visited_style(),
% for style_struct in data.active_style_structs():
${style_struct.ident}: StyleStructRef::Borrowed(
style_to_derive_from.${style_struct.name_lower}_arc()
),
% endfor
}
} }
% for property in data.longhands:
% if property.ident != "font_size":
/// Inherit `${property.ident}` from our parent style.
#[allow(non_snake_case)]
pub fn inherit_${property.ident}(&mut self) {
let inherited_struct =
self.inherited_style.get_${property.style_struct.name_lower}();
self.${property.style_struct.ident}.mutate()
.copy_${property.ident}_from(
inherited_struct,
% if property.logical:
self.writing_mode,
% endif
);
}
/// Reset `${property.ident}` to the initial value.
#[allow(non_snake_case)]
pub fn reset_${property.ident}(&mut self) {
let reset_struct = self.reset_style.get_${property.style_struct.name_lower}();
self.${property.style_struct.ident}.mutate()
.copy_${property.ident}_from(
reset_struct,
% if property.logical:
self.writing_mode,
% endif
);
}
% if not property.is_vector:
/// Set the `${property.ident}` to the computed value `value`.
#[allow(non_snake_case)]
pub fn set_${property.ident}(
&mut self,
value: longhands::${property.ident}::computed_value::T
) {
self.${property.style_struct.ident}.mutate()
.set_${property.ident}(
value,
% if property.logical:
self.writing_mode,
% elif product == "gecko" and property.ident in ["content", "list_style_type"]:
self.device,
% endif
);
}
% endif
% endif
% endfor
/// Inherits style from the parent element, accounting for the default /// Inherits style from the parent element, accounting for the default
/// computed values that need to be provided as well. /// computed values that need to be provided as well.
pub fn for_inheritance( pub fn for_inheritance(
device: &'a Device, device: &'a Device,
parent: &'a ComputedValues, parent: &'a ComputedValues,
reset: &'a ComputedValues,
pseudo: Option<<&'a PseudoElement>, pseudo: Option<<&'a PseudoElement>,
) -> Self { ) -> Self {
// FIXME(emilio): This Some(parent) here is inconsistent with what we // FIXME(emilio): This Some(parent) here is inconsistent with what we
@ -2543,7 +2633,6 @@ impl<'a> StyleBuilder<'a> {
Self::new( Self::new(
device, device,
Some(parent), Some(parent),
reset,
pseudo, pseudo,
CascadeFlags::empty(), CascadeFlags::empty(),
/* rules = */ None, /* rules = */ None,
@ -2555,6 +2644,15 @@ impl<'a> StyleBuilder<'a> {
) )
} }
/// Returns the style we're inheriting from.
pub fn inherited_style(&self) -> &'a ComputedValues {
self.inherited_style
}
/// Returns the style we're getting reset properties from.
pub fn default_style(&self) -> &'a ComputedValues {
self.reset_style
}
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
/// Gets an immutable view of the current `${style_struct.name}` style. /// Gets an immutable view of the current `${style_struct.name}` style.
@ -2585,9 +2683,9 @@ impl<'a> StyleBuilder<'a> {
} }
/// Reset the current `${style_struct.name}` style to its default value. /// Reset the current `${style_struct.name}` style to its default value.
pub fn reset_${style_struct.name_lower}(&mut self, default: &'a ComputedValuesInner) { pub fn reset_${style_struct.name_lower}_struct(&mut self) {
self.${style_struct.ident} = self.${style_struct.ident} =
StyleStructRef::Borrowed(default.${style_struct.name_lower}_arc()); StyleStructRef::Borrowed(self.reset_style.${style_struct.name_lower}_arc());
} }
% endfor % endfor
@ -2685,10 +2783,7 @@ mod lazy_static_module {
/// A per-longhand function that performs the CSS cascade for that longhand. /// A per-longhand function that performs the CSS cascade for that longhand.
pub type CascadePropertyFn = pub type CascadePropertyFn =
extern "Rust" fn(declaration: &PropertyDeclaration, extern "Rust" fn(declaration: &PropertyDeclaration,
inherited_style: &ComputedValues,
default_style: &ComputedValues,
context: &mut computed::Context, context: &mut computed::Context,
cacheable: &mut bool,
cascade_info: &mut Option<<&mut CascadeInfo>); cascade_info: &mut Option<<&mut CascadeInfo>);
/// A per-longhand array of functions to perform the CSS cascade on each of /// A per-longhand array of functions to perform the CSS cascade on each of
@ -2831,7 +2926,6 @@ where
} }
}; };
let default_style = device.default_computed_values();
let inherited_custom_properties = inherited_style.custom_properties(); let inherited_custom_properties = inherited_style.custom_properties();
let mut custom_properties = None; let mut custom_properties = None;
let mut seen_custom = HashSet::new(); let mut seen_custom = HashSet::new();
@ -2849,15 +2943,12 @@ where
let mut context = computed::Context { let mut context = computed::Context {
is_root_element: flags.contains(IS_ROOT_ELEMENT), is_root_element: flags.contains(IS_ROOT_ELEMENT),
device: device,
inherited_style: inherited_style,
// We'd really like to own the rules here to avoid refcount traffic, but // We'd really like to own the rules here to avoid refcount traffic, but
// animation's usage of `apply_declarations` make this tricky. See bug // animation's usage of `apply_declarations` make this tricky. See bug
// 1375525. // 1375525.
style: StyleBuilder::new( builder: StyleBuilder::new(
device, device,
parent_style, parent_style,
device.default_computed_values(),
pseudo, pseudo,
flags, flags,
Some(rules.clone()), Some(rules.clone()),
@ -2883,10 +2974,6 @@ where
// Set computed values, overwriting earlier declarations for the same // Set computed values, overwriting earlier declarations for the same
// property. // property.
//
// NB: The cacheable boolean is not used right now, but will be once we
// start caching computed values in the rule nodes.
let mut cacheable = true;
let mut seen = LonghandIdSet::new(); let mut seen = LonghandIdSet::new();
// Declaration blocks are stored in increasing precedence order, we want // Declaration blocks are stored in increasing precedence order, we want
@ -2909,7 +2996,7 @@ where
PropertyDeclaration::WithVariables(id, ref unparsed) => { PropertyDeclaration::WithVariables(id, ref unparsed) => {
Cow::Owned(unparsed.substitute_variables( Cow::Owned(unparsed.substitute_variables(
id, id,
&context.style.custom_properties, &context.builder.custom_properties,
context.quirks_mode context.quirks_mode
)) ))
} }
@ -2983,15 +3070,12 @@ where
let discriminant = longhand_id as usize; let discriminant = longhand_id as usize;
(CASCADE_PROPERTY[discriminant])(&*declaration, (CASCADE_PROPERTY[discriminant])(&*declaration,
inherited_style,
default_style,
&mut context, &mut context,
&mut cacheable,
&mut cascade_info); &mut cascade_info);
} }
% if category_to_cascade_now == "early": % if category_to_cascade_now == "early":
let writing_mode = get_writing_mode(context.style.get_inheritedbox()); let writing_mode = get_writing_mode(context.builder.get_inheritedbox());
context.style.writing_mode = writing_mode; context.builder.writing_mode = writing_mode;
let mut _skip_font_family = false; let mut _skip_font_family = false;
@ -3027,13 +3111,14 @@ where
// which Gecko just does regular cascading with. Do the same. // which Gecko just does regular cascading with. Do the same.
// This can only happen in the case where the language changed but the family did not // This can only happen in the case where the language changed but the family did not
if generic != structs::kGenericFont_NONE { if generic != structs::kGenericFont_NONE {
let gecko_font = context.style.mutate_font().gecko_mut(); let pres_context = context.builder.device.pres_context();
let gecko_font = context.builder.mutate_font().gecko_mut();
gecko_font.mGenericID = generic; gecko_font.mGenericID = generic;
unsafe { unsafe {
bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric( bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric(
gecko_font, gecko_font,
context.device.pres_context(), pres_context,
generic generic,
); );
} }
} }
@ -3056,13 +3141,11 @@ where
let discriminant = LonghandId::FontFamily as usize; let discriminant = LonghandId::FontFamily as usize;
(CASCADE_PROPERTY[discriminant])(declaration, (CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
default_style,
&mut context, &mut context,
&mut cacheable,
&mut cascade_info); &mut cascade_info);
% if product == "gecko": % if product == "gecko":
context.style.mutate_font().fixup_none_generic(context.device); let device = context.builder.device;
context.builder.mutate_font().fixup_none_generic(device);
% endif % endif
} }
} }
@ -3070,10 +3153,7 @@ where
if let Some(ref declaration) = font_size { if let Some(ref declaration) = font_size {
let discriminant = LonghandId::FontSize as usize; let discriminant = LonghandId::FontSize as usize;
(CASCADE_PROPERTY[discriminant])(declaration, (CASCADE_PROPERTY[discriminant])(declaration,
inherited_style,
default_style,
&mut context, &mut context,
&mut cacheable,
&mut cascade_info); &mut cascade_info);
% if product == "gecko": % if product == "gecko":
// Font size must be explicitly inherited to handle lang changes and // Font size must be explicitly inherited to handle lang changes and
@ -3087,33 +3167,26 @@ where
LonghandId::FontSize, CSSWideKeyword::Inherit); LonghandId::FontSize, CSSWideKeyword::Inherit);
(CASCADE_PROPERTY[discriminant])(&size, (CASCADE_PROPERTY[discriminant])(&size,
inherited_style,
default_style,
&mut context, &mut context,
&mut cacheable,
&mut cascade_info); &mut cascade_info);
% endif % endif
} }
% endif % endif
% endfor % endfor
let mut style = context.style; let mut builder = context.builder;
{ {
StyleAdjuster::new(&mut style) StyleAdjuster::new(&mut builder)
.adjust( .adjust(layout_parent_style, flags);
layout_parent_style,
context.device.default_computed_values(),
flags
);
} }
% if product == "gecko": % if product == "gecko":
if let Some(ref mut bg) = style.get_background_if_mutated() { if let Some(ref mut bg) = builder.get_background_if_mutated() {
bg.fill_arrays(); bg.fill_arrays();
} }
if let Some(ref mut svg) = style.get_svg_if_mutated() { if let Some(ref mut svg) = builder.get_svg_if_mutated() {
svg.fill_arrays(); svg.fill_arrays();
} }
% endif % endif
@ -3123,11 +3196,11 @@ where
seen.contains(LonghandId::FontWeight) || seen.contains(LonghandId::FontWeight) ||
seen.contains(LonghandId::FontStretch) || seen.contains(LonghandId::FontStretch) ||
seen.contains(LonghandId::FontFamily) { seen.contains(LonghandId::FontFamily) {
style.mutate_font().compute_font_hash(); builder.mutate_font().compute_font_hash();
} }
% endif % endif
style.build() builder.build()
} }
/// See StyleAdjuster::adjust_for_border_width. /// See StyleAdjuster::adjust_for_border_width.
@ -3136,7 +3209,7 @@ pub fn adjust_border_width(style: &mut StyleBuilder) {
// Like calling to_computed_value, which wouldn't type check. // Like calling to_computed_value, which wouldn't type check.
if style.get_border().clone_border_${side}_style().none_or_hidden() && if style.get_border().clone_border_${side}_style().none_or_hidden() &&
style.get_border().border_${side}_has_nonzero_width() { style.get_border().border_${side}_has_nonzero_width() {
style.mutate_border().set_border_${side}_width(Au(0)); style.set_border_${side}_width(Au(0));
} }
% endfor % endfor
} }

View file

@ -229,9 +229,7 @@ impl Range<specified::Length> {
// em units are relative to the initial font-size. // em units are relative to the initial font-size.
let context = computed::Context { let context = computed::Context {
is_root_element: false, is_root_element: false,
device: device, builder: StyleBuilder::for_derived_style(device, default_values, None, None),
inherited_style: default_values,
style: StyleBuilder::for_derived_style(device, default_values, None),
// Servo doesn't support font metrics // Servo doesn't support font metrics
// A real provider will be needed here once we do; since // A real provider will be needed here once we do; since
// ch units can exist in media queries. // ch units can exist in media queries.

View file

@ -387,7 +387,6 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn adjust_for_ruby(&mut self, fn adjust_for_ruby(&mut self,
layout_parent_style: &ComputedValues, layout_parent_style: &ComputedValues,
default_computed_values: &'b ComputedValues,
flags: CascadeFlags) { flags: CascadeFlags) {
use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
@ -408,8 +407,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
// how border and padding should be handled for ruby level container, // how border and padding should be handled for ruby level container,
// and suppressing them here make it easier for layout to handle. // and suppressing them here make it easier for layout to handle.
if self_display.is_ruby_level_container() { if self_display.is_ruby_level_container() {
self.style.reset_border(default_computed_values); self.style.reset_border_struct();
self.style.reset_padding(default_computed_values); self.style.reset_padding_struct();
} }
// Force bidi isolation on all internal ruby boxes and ruby container // Force bidi isolation on all internal ruby boxes and ruby container
// per spec https://drafts.csswg.org/css-ruby-1/#bidi // per spec https://drafts.csswg.org/css-ruby-1/#bidi
@ -432,7 +431,6 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// `nsStyleContext::ApplyStyleFixups`. /// `nsStyleContext::ApplyStyleFixups`.
pub fn adjust(&mut self, pub fn adjust(&mut self,
layout_parent_style: &ComputedValues, layout_parent_style: &ComputedValues,
_default_computed_values: &'b ComputedValues,
flags: CascadeFlags) { flags: CascadeFlags) {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
@ -459,8 +457,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
self.adjust_for_text_decoration_lines(layout_parent_style); self.adjust_for_text_decoration_lines(layout_parent_style);
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
self.adjust_for_ruby(layout_parent_style, self.adjust_for_ruby(layout_parent_style, flags);
_default_computed_values, flags);
} }
} }
} }

View file

@ -704,9 +704,7 @@ impl MaybeNew for ViewportConstraints {
let context = Context { let context = Context {
is_root_element: false, is_root_element: false,
device: device, builder: StyleBuilder::for_derived_style(device, default_values, None, None),
inherited_style: default_values,
style: StyleBuilder::for_derived_style(device, default_values, None),
font_metrics_provider: &provider, font_metrics_provider: &provider,
cached_system_font: None, cached_system_font: None,
in_media_query: false, in_media_query: false,

View file

@ -68,16 +68,10 @@ pub struct Context<'a> {
/// Whether the current element is the root element. /// Whether the current element is the root element.
pub is_root_element: bool, pub is_root_element: bool,
/// The Device holds the viewport and other external state.
pub device: &'a Device,
/// The style we're inheriting from.
pub inherited_style: &'a ComputedValues,
/// Values accessed through this need to be in the properties "computed /// Values accessed through this need to be in the properties "computed
/// early": color, text-decoration, font-size, display, position, float, /// early": color, text-decoration, font-size, display, position, float,
/// border-*-style, outline-style, font-family, writing-mode... /// border-*-style, outline-style, font-family, writing-mode...
pub style: StyleBuilder<'a>, pub builder: StyleBuilder<'a>,
/// A cached computed system font value, for use by gecko. /// A cached computed system font value, for use by gecko.
/// ///
@ -105,18 +99,34 @@ pub struct Context<'a> {
impl<'a> Context<'a> { impl<'a> Context<'a> {
/// Whether the current element is the root element. /// Whether the current element is the root element.
pub fn is_root_element(&self) -> bool { self.is_root_element } pub fn is_root_element(&self) -> bool {
self.is_root_element
}
/// The current device.
pub fn device(&self) -> &Device {
self.builder.device
}
/// The current viewport size. /// The current viewport size.
pub fn viewport_size(&self) -> Size2D<Au> { self.device.au_viewport_size() } pub fn viewport_size(&self) -> Size2D<Au> {
self.builder.device.au_viewport_size()
}
/// The style we're inheriting from. /// The style we're inheriting from.
pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style } pub fn inherited_style(&self) -> &ComputedValues {
/// The current style. Note that only "eager" properties should be accessed self.builder.inherited_style()
/// from here, see the comment in the member. }
pub fn style(&self) -> &StyleBuilder { &self.style }
/// A mutable reference to the current style. /// The default computed style we're getting our reset style from.
pub fn mutate_style(&mut self) -> &mut StyleBuilder<'a> { &mut self.style } pub fn default_style(&self) -> &ComputedValues {
/// Get a mutable reference to the current style as well as the device self.builder.default_style()
pub fn mutate_style_with_device(&mut self) -> (&mut StyleBuilder<'a>, &Device) { (&mut self.style, &self.device) } }
/// The current style.
pub fn style(&self) -> &StyleBuilder {
&self.builder
}
} }
/// An iterator over a slice of computed values /// An iterator over a slice of computed values
@ -395,7 +405,7 @@ impl ToComputedValue for specified::JustifyItems {
// If the inherited value of `justify-items` includes the `legacy` keyword, `auto` computes // If the inherited value of `justify-items` includes the `legacy` keyword, `auto` computes
// to the inherited value. // to the inherited value.
if self.0 == align::ALIGN_AUTO { if self.0 == align::ALIGN_AUTO {
let inherited = context.inherited_style.get_position().clone_justify_items(); let inherited = context.inherited_style().get_position().clone_justify_items();
if inherited.0.contains(align::ALIGN_LEGACY) { if inherited.0.contains(align::ALIGN_LEGACY) {
return inherited return inherited
} }

View file

@ -254,7 +254,7 @@ impl ToComputedValue for Color {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
Color::Special(special) => { Color::Special(special) => {
use self::gecko::SpecialColorKeyword as Keyword; use self::gecko::SpecialColorKeyword as Keyword;
let pres_context = _context.device.pres_context(); let pres_context = _context.device().pres_context();
convert_nscolor_to_computedcolor(match special { convert_nscolor_to_computedcolor(match special {
Keyword::MozDefaultColor => pres_context.mDefaultColor, Keyword::MozDefaultColor => pres_context.mDefaultColor,
Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor, Keyword::MozDefaultBackgroundColor => pres_context.mBackgroundColor,
@ -268,7 +268,7 @@ impl ToComputedValue for Color {
use dom::TElement; use dom::TElement;
use gecko::wrapper::GeckoElement; use gecko::wrapper::GeckoElement;
use gecko_bindings::bindings::Gecko_GetBody; use gecko_bindings::bindings::Gecko_GetBody;
let pres_context = _context.device.pres_context(); let pres_context = _context.device().pres_context();
let body = unsafe { let body = unsafe {
Gecko_GetBody(pres_context) Gecko_GetBody(pres_context)
}; };
@ -316,7 +316,7 @@ impl ToComputedValue for RGBAColor {
fn to_computed_value(&self, context: &Context) -> RGBA { fn to_computed_value(&self, context: &Context) -> RGBA {
self.0.to_computed_value(context) self.0.to_computed_value(context)
.to_rgba(context.style.get_color().clone_color()) .to_rgba(context.style().get_color().clone_color())
} }
fn from_computed_value(computed: &RGBA) -> Self { fn from_computed_value(computed: &RGBA) -> Self {

View file

@ -107,7 +107,7 @@ impl FontRelativeLength {
reference_font_size, reference_font_size,
context.style().writing_mode, context.style().writing_mode,
context.in_media_query, context.in_media_query,
context.device) context.device())
} }
let reference_font_size = base_size.resolve(context); let reference_font_size = base_size.resolve(context);
@ -158,7 +158,7 @@ impl FontRelativeLength {
if context.is_root_element { if context.is_root_element {
reference_font_size.scale_by(length) reference_font_size.scale_by(length)
} else { } else {
context.device.root_font_size().scale_by(length) context.device().root_font_size().scale_by(length)
} }
} }
} }
@ -362,7 +362,7 @@ impl PhysicalLength {
const MM_PER_INCH: f32 = 25.4; const MM_PER_INCH: f32 = 25.4;
let physical_inch = unsafe { let physical_inch = unsafe {
bindings::Gecko_GetAppUnitsPerPhysicalInch(context.device.pres_context()) bindings::Gecko_GetAppUnitsPerPhysicalInch(context.device().pres_context())
}; };
let inch = self.0 / MM_PER_INCH; let inch = self.0 / MM_PER_INCH;

View file

@ -1689,7 +1689,6 @@ fn get_pseudo_style(
StyleBuilder::for_inheritance( StyleBuilder::for_inheritance(
doc_data.stylist.device(), doc_data.stylist.device(),
styles.primary(), styles.primary(),
doc_data.default_computed_values(),
Some(pseudo), Some(pseudo),
).build() ).build()
})) }))
@ -1712,7 +1711,6 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
let mut style = StyleBuilder::for_inheritance( let mut style = StyleBuilder::for_inheritance(
data.stylist.device(), data.stylist.device(),
reference, reference,
data.default_computed_values(),
Some(&pseudo) Some(&pseudo)
); );
@ -1727,6 +1725,7 @@ pub extern "C" fn Servo_ComputedValues_Inherit(
StyleBuilder::for_derived_style( StyleBuilder::for_derived_style(
data.stylist.device(), data.stylist.device(),
data.default_computed_values(), data.default_computed_values(),
/* parent_style = */ None,
Some(&pseudo), Some(&pseudo),
).build() ).build()
}; };
@ -2886,20 +2885,21 @@ fn simulate_compute_values_failure(_: &PropertyValuePair) -> bool {
false false
} }
fn create_context<'a>(per_doc_data: &'a PerDocumentStyleDataImpl, fn create_context<'a>(
font_metrics_provider: &'a FontMetricsProvider, per_doc_data: &'a PerDocumentStyleDataImpl,
style: &'a ComputedValues, font_metrics_provider: &'a FontMetricsProvider,
parent_style: Option<&'a ComputedValues>, style: &'a ComputedValues,
pseudo: Option<&'a PseudoElement>) parent_style: Option<&'a ComputedValues>,
-> Context<'a> { pseudo: Option<&'a PseudoElement>,
let default_values = per_doc_data.default_computed_values(); ) -> Context<'a> {
let inherited_style = parent_style.unwrap_or(default_values);
Context { Context {
is_root_element: false, is_root_element: false,
device: per_doc_data.stylist.device(), builder: StyleBuilder::for_derived_style(
inherited_style: inherited_style, per_doc_data.stylist.device(),
style: StyleBuilder::for_derived_style(per_doc_data.stylist.device(), style, pseudo), style,
parent_style,
pseudo,
),
font_metrics_provider: font_metrics_provider, font_metrics_provider: font_metrics_provider,
cached_system_font: None, cached_system_font: None,
in_media_query: false, in_media_query: false,

View file

@ -54,9 +54,7 @@ fn assert_computed_serialization<C, F, T>(f: F, input: &'static str, output: &st
let context = Context { let context = Context {
is_root_element: true, is_root_element: true,
device: &device, builder: StyleBuilder::for_derived_style(&device, initial_style, None, None),
inherited_style: initial_style,
style: StyleBuilder::for_derived_style(&device, initial_style, None),
cached_system_font: None, cached_system_font: None,
font_metrics_provider: &ServoMetricsProvider, font_metrics_provider: &ServoMetricsProvider,
in_media_query: false, in_media_query: false,