stylo: Use ComputedValuesInner instead of ComputedValues when we don't need it

This commit is contained in:
Manish Goregaokar 2017-07-17 11:41:52 -07:00 committed by Manish Goregaokar
parent 04b0ae64f2
commit 808b1f509b
38 changed files with 302 additions and 316 deletions

View file

@ -11,7 +11,7 @@ use context::SharedStyleContext;
use dom::OpaqueNode;
use euclid::Point2D;
use font_metrics::FontMetricsProvider;
use properties::{self, CascadeFlags, ComputedValues, Importance};
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner, Importance};
use properties::animated_properties::{AnimatableLonghand, AnimatedProperty, TransitionProperty};
use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection;
use properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
@ -347,8 +347,8 @@ impl PropertyAnimation {
fn from_animatable_longhand(animatable_longhand: &AnimatableLonghand,
timing_function: TimingFunction,
duration: Time,
old_style: &ComputedValues,
new_style: &ComputedValues)
old_style: &ComputedValuesInner,
new_style: &ComputedValuesInner)
-> Option<PropertyAnimation> {
let animated_property = AnimatedProperty::from_animatable_longhand(animatable_longhand,
old_style,
@ -480,10 +480,10 @@ pub fn start_transitions_if_applicable(new_animations_sender: &Sender<Animation>
fn compute_style_for_animation_step(context: &SharedStyleContext,
step: &KeyframesStep,
previous_style: &ComputedValues,
style_from_cascade: &ComputedValues,
previous_style: &ComputedValuesInner,
style_from_cascade: &ComputedValuesInner,
font_metrics_provider: &FontMetricsProvider)
-> ComputedValues {
-> ComputedValuesInner {
match step.value {
KeyframesStepValue::ComputedValues => style_from_cascade.clone(),
KeyframesStepValue::Declarations { block: ref declarations } => {

View file

@ -15,7 +15,7 @@ use data::ElementData;
use element_state::ElementState;
use font_metrics::FontMetricsProvider;
use media_queries::Device;
use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock};
use properties::{AnimationRules, ComputedValues, ComputedValuesInner, PropertyDeclarationBlock};
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValue;
#[cfg(feature = "gecko")] use properties::animated_properties::TransitionProperty;
use rule_tree::CascadeLevel;
@ -436,7 +436,7 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
fn may_generate_pseudo(
&self,
pseudo: &PseudoElement,
_primary_style: &ComputedValues,
_primary_style: &ComputedValuesInner,
) -> bool {
// ::before/::after are always supported for now, though we could try to
// optimize out leaf elements.

View file

@ -16,7 +16,7 @@ use gecko_bindings::structs::nsIDocument;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
use media_queries::{Device, MediaList};
use properties::ComputedValues;
use properties::ComputedValuesInner;
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
use stylearc::Arc;
use stylesheet_set::StylesheetSet;
@ -188,8 +188,8 @@ impl PerDocumentStyleDataImpl {
}
/// Get the default computed values for this document.
pub fn default_computed_values(&self) -> &Arc<ComputedValues> {
self.stylist.device().default_computed_values_arc()
pub fn default_computed_values(&self) -> &ComputedValuesInner {
self.stylist.device().default_computed_values()
}
/// Clear the stylist. This will be a no-op if the stylist is

View file

@ -17,7 +17,7 @@ use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
use media_queries::MediaType;
use parser::ParserContext;
use properties::{ComputedValues, StyleBuilder};
use properties::{ComputedValuesInner, StyleBuilder};
use properties::longhands::font_size;
use selectors::parser::SelectorParseError;
use std::fmt::{self, Write};
@ -26,7 +26,6 @@ use str::starts_with_ignore_ascii_case;
use string_cache::Atom;
use style_traits::{ToCss, ParseError, StyleParseError};
use style_traits::viewport::ViewportConstraints;
use stylearc::Arc;
use values::{CSSFloat, specified};
use values::computed::{self, ToComputedValue};
@ -37,7 +36,7 @@ pub struct Device {
/// stylist, and thus the `Device`, so having a raw pres context pointer
/// here is fine.
pres_context: RawGeckoPresContextOwned,
default_values: Arc<ComputedValues>,
default_values: ComputedValuesInner,
viewport_override: Option<ViewportConstraints>,
/// The font size of the root element
/// This is set when computing the style of the root
@ -62,7 +61,7 @@ impl Device {
assert!(!pres_context.is_null());
Device {
pres_context: pres_context,
default_values: ComputedValues::default_values(unsafe { &*pres_context }),
default_values: ComputedValuesInner::default_values(unsafe { &*pres_context }),
viewport_override: None,
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
used_root_font_size: AtomicBool::new(false),
@ -78,19 +77,7 @@ impl Device {
/// Returns the default computed values as a reference, in order to match
/// Servo.
pub fn default_computed_values(&self) -> &ComputedValues {
&*self.default_values
}
/// Returns the default computed values, but wrapped in an arc for cheap
/// cloning.
pub fn default_computed_values_arc(&self) -> &Arc<ComputedValues> {
&self.default_values
}
/// Returns the default computed values as an `Arc`, in order to avoid
/// clones.
pub fn default_values_arc(&self) -> &Arc<ComputedValues> {
pub fn default_computed_values(&self) -> &ComputedValuesInner {
&self.default_values
}
@ -114,7 +101,7 @@ impl Device {
pub fn reset_computed_values(&mut self) {
// NB: A following stylesheet flush will populate this if appropriate.
self.viewport_override = None;
self.default_values = ComputedValues::default_values(self.pres_context());
self.default_values = ComputedValuesInner::default_values(self.pres_context());
self.used_root_font_size.store(false, Ordering::Relaxed);
}

View file

@ -110,13 +110,13 @@ impl<'a> Iterator for PropertyDeclarationIterator<'a> {
pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> {
iter: Iter<'a, (PropertyDeclaration, Importance)>,
context: &'cx mut Context<'cx_a>,
default_values: &'a Arc<ComputedValues>,
default_values: &'a ComputedValuesInner,
}
impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> {
fn new(declarations: &'a PropertyDeclarationBlock,
context: &'cx mut Context<'cx_a>,
default_values: &'a Arc<ComputedValues>) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
default_values: &'a ComputedValuesInner) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
AnimationValueIterator {
iter: declarations.declarations().iter(),
context: context,
@ -204,7 +204,7 @@ impl PropertyDeclarationBlock {
/// Return an iterator of (AnimatableLonghand, AnimationValue).
pub fn to_animation_value_iter<'a, 'cx, 'cx_a:'cx>(&'a self,
context: &'cx mut Context<'cx_a>,
default_values: &'a Arc<ComputedValues>)
default_values: &'a ComputedValuesInner)
-> AnimationValueIterator<'a, 'cx, 'cx_a> {
AnimationValueIterator::new(self, context, default_values)
}

View file

@ -97,7 +97,7 @@ impl Clone for ComputedValuesInner {
}
}
impl ComputedValues {
impl ComputedValuesInner {
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
writing_mode: WritingMode,
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
@ -108,24 +108,21 @@ impl ComputedValues {
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Self {
ComputedValues {
inner: ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
% endfor
}
ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
% endfor
}
}
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues {
inner: ComputedValuesInner {
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Self {
ComputedValuesInner {
custom_properties: None,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
font_computation_data: FontComputationData::default_values(),
@ -135,8 +132,10 @@ impl ComputedValues {
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(style_structs::${style_struct.name}::default(pres_context)),
% endfor
}
})
}
}
pub fn to_outer(self) -> Arc<ComputedValues> {
Arc::new(ComputedValues {inner: self})
}
}
@ -198,12 +197,12 @@ impl ComputedValuesInner {
}
/// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option<<&Arc<ComputedValues>> {
self.visited_style.as_ref()
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
self.visited_style.as_ref().map(|x| &***x)
}
/// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &Arc<ComputedValues> {
pub fn visited_style(&self) -> &ComputedValuesInner {
self.get_visited_style().unwrap()
}

View file

@ -292,7 +292,7 @@
#[allow(unused_imports)]
use properties::{DeclaredValue, LonghandId, LonghandIdSet};
#[allow(unused_imports)]
use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration};
use properties::{CSSWideKeyword, ComputedValuesInner, PropertyDeclaration};
#[allow(unused_imports)]
use properties::style_structs;
#[allow(unused_imports)]
@ -310,8 +310,8 @@
${caller.body()}
#[allow(unused_variables)]
pub fn cascade_property(declaration: &PropertyDeclaration,
inherited_style: &ComputedValues,
default_style: &ComputedValues,
inherited_style: &ComputedValuesInner,
default_style: &ComputedValuesInner,
context: &mut computed::Context,
cacheable: &mut bool,
cascade_info: &mut Option<<&mut CascadeInfo>) {

View file

@ -29,7 +29,7 @@ use smallvec::SmallVec;
use std::cmp;
#[cfg(feature = "gecko")] use fnv::FnvHashMap;
use style_traits::ParseError;
use super::ComputedValues;
use super::ComputedValuesInner;
#[cfg(any(feature = "gecko", feature = "testing"))]
use values::Auto;
use values::{CSSFloat, CustomIdent, Either};
@ -394,7 +394,7 @@ impl AnimatedProperty {
/// Update `style` with the proper computed style corresponding to this
/// animation at `progress`.
pub fn update(&self, style: &mut ComputedValues, progress: f64) {
pub fn update(&self, style: &mut ComputedValuesInner, progress: f64) {
match *self {
% for prop in data.longhands:
% if prop.animatable:
@ -427,8 +427,8 @@ impl AnimatedProperty {
/// Get an animatable value from a transition-property, an old style, and a
/// new style.
pub fn from_animatable_longhand(property: &AnimatableLonghand,
old_style: &ComputedValues,
new_style: &ComputedValues)
old_style: &ComputedValuesInner,
new_style: &ComputedValuesInner)
-> AnimatedProperty {
match *property {
% for prop in data.longhands:
@ -521,7 +521,7 @@ impl AnimationValue {
/// Construct an AnimationValue from a property declaration
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context,
initial: &ComputedValues) -> Option<Self> {
initial: &ComputedValuesInner) -> Option<Self> {
use properties::LonghandId;
match *decl {
@ -593,7 +593,7 @@ impl AnimationValue {
/// Get an AnimationValue for an AnimatableLonghand from a given computed values.
pub fn from_computed_values(property: &AnimatableLonghand,
computed_values: &ComputedValues)
computed_values: &ComputedValuesInner)
-> Self {
match *property {
% for prop in data.longhands:

View file

@ -181,7 +181,7 @@
% if product == "servo":
fn cascade_property_custom(_declaration: &PropertyDeclaration,
_inherited_style: &ComputedValues,
_inherited_style: &ComputedValuesInner,
context: &mut computed::Context,
_cacheable: &mut bool) {
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);

View file

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

View file

@ -1872,6 +1872,8 @@ pub mod style_structs {
#[cfg(feature = "gecko")]
pub use gecko_properties::ComputedValues;
#[cfg(feature = "gecko")]
pub use gecko_properties::ComputedValuesInner;
#[cfg(feature = "servo")]
@ -1920,7 +1922,7 @@ pub struct ComputedValues {
}
#[cfg(feature = "servo")]
impl ComputedValues {
impl ComputedValuesInner {
/// Construct a `ComputedValues` instance.
pub fn new(
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
@ -1933,18 +1935,16 @@ impl ComputedValues {
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Self {
ComputedValues {
inner: ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.active_style_structs():
${style_struct.ident}: ${style_struct.ident},
% endfor
}
ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.active_style_structs():
${style_struct.ident}: ${style_struct.ident},
% endfor
}
}
@ -1969,6 +1969,11 @@ impl ops::DerefMut for ComputedValues {
#[cfg(feature = "servo")]
impl ComputedValuesInner {
/// Convert to an Arc<ComputedValues>
pub fn to_outer(self) -> Arc<ComputedValues> {
Arc::new(ComputedValues {inner: self})
}
% for style_struct in data.active_style_structs():
/// Clone the ${style_struct.name} struct.
#[inline]
@ -2006,13 +2011,13 @@ impl ComputedValuesInner {
}
/// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option<<&Arc<ComputedValues>> {
self.visited_style.as_ref()
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
self.visited_style.as_ref().map(|x| &***x)
}
/// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &Arc<ComputedValues> {
self.get_visited_style().unwrap()
pub fn visited_style(&self) -> &ComputedValuesInner {
self.get_visited_style().as_ref().map(|x| &**x).unwrap()
}
/// Clone the visited style. Used for inheriting parent styles in
@ -2441,8 +2446,8 @@ pub struct StyleBuilder<'a> {
impl<'a> StyleBuilder<'a> {
/// Trivially construct a `StyleBuilder`.
fn new(
inherited_style: &'a ComputedValues,
reset_style: &'a ComputedValues,
inherited_style: &'a ComputedValuesInner,
reset_style: &'a ComputedValuesInner,
rules: Option<StrongRuleNode>,
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
writing_mode: WritingMode,
@ -2469,15 +2474,15 @@ impl<'a> StyleBuilder<'a> {
/// Creates a StyleBuilder holding only references to the structs of `s`, in
/// order to create a derived style.
pub fn for_derived_style(s: &'a ComputedValues) -> Self {
pub fn for_derived_style(s: &'a ComputedValuesInner) -> Self {
Self::for_inheritance(s, s)
}
/// Inherits style from the parent element, accounting for the default
/// computed values that need to be provided as well.
pub fn for_inheritance(
parent: &'a ComputedValues,
default: &'a ComputedValues
parent: &'a ComputedValuesInner,
default: &'a ComputedValuesInner
) -> Self {
Self::new(
parent,
@ -2521,7 +2526,7 @@ impl<'a> StyleBuilder<'a> {
}
/// Reset the current `${style_struct.name}` style to its default value.
pub fn reset_${style_struct.name_lower}(&mut self, default: &'a ComputedValues) {
pub fn reset_${style_struct.name_lower}(&mut self, default: &'a ComputedValuesInner) {
self.${style_struct.ident} =
StyleStructRef::Borrowed(default.${style_struct.name_lower}_arc());
}
@ -2555,8 +2560,8 @@ impl<'a> StyleBuilder<'a> {
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
pub fn build(self) -> ComputedValues {
ComputedValues::new(self.custom_properties,
pub fn build(self) -> ComputedValuesInner {
ComputedValuesInner::new(self.custom_properties,
self.writing_mode,
self.font_size_keyword,
self.flags,
@ -2586,30 +2591,28 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
mod lazy_static_module {
use logical_geometry::WritingMode;
use stylearc::Arc;
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
use super::{ComputedValuesInner, longhands, style_structs, FontComputationData};
use super::computed_value_flags::ComputedValueFlags;
/// The initial values for all style structs as defined by the specification.
lazy_static! {
pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues {
inner: ComputedValuesInner {
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands:
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
% endfor
% if style_struct.name == "Font":
hash: 0,
% endif
}),
% endfor
custom_properties: None,
writing_mode: WritingMode::empty(),
font_computation_data: FontComputationData::default_values(),
rules: None,
visited_style: None,
flags: ComputedValueFlags::empty(),
}
pub static ref INITIAL_SERVO_VALUES: ComputedValuesInner = ComputedValuesInner {
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands:
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
% endfor
% if style_struct.name == "Font":
hash: 0,
% endif
}),
% endfor
custom_properties: None,
writing_mode: WritingMode::empty(),
font_computation_data: FontComputationData::default_values(),
rules: None,
visited_style: None,
flags: ComputedValueFlags::empty(),
};
}
}
@ -2617,8 +2620,8 @@ mod lazy_static_module {
/// A per-longhand function that performs the CSS cascade for that longhand.
pub type CascadePropertyFn =
extern "Rust" fn(declaration: &PropertyDeclaration,
inherited_style: &ComputedValues,
default_style: &ComputedValues,
inherited_style: &ComputedValuesInner,
default_style: &ComputedValuesInner,
context: &mut computed::Context,
cacheable: &mut bool,
cascade_info: &mut Option<<&mut CascadeInfo>);
@ -2679,14 +2682,14 @@ bitflags! {
pub fn cascade(device: &Device,
rule_node: &StrongRuleNode,
guards: &StylesheetGuards,
parent_style: Option<<&ComputedValues>,
layout_parent_style: Option<<&ComputedValues>,
parent_style: Option<<&ComputedValuesInner>,
layout_parent_style: Option<<&ComputedValuesInner>,
visited_style: Option<Arc<ComputedValues>>,
cascade_info: Option<<&mut CascadeInfo>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode)
-> ComputedValues {
-> ComputedValuesInner {
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
let (inherited_style, layout_parent_style) = match parent_style {
Some(parent_style) => {
@ -2741,14 +2744,14 @@ pub fn cascade(device: &Device,
pub fn apply_declarations<'a, F, I>(device: &Device,
rules: &StrongRuleNode,
iter_declarations: F,
inherited_style: &ComputedValues,
layout_parent_style: &ComputedValues,
inherited_style: &ComputedValuesInner,
layout_parent_style: &ComputedValuesInner,
visited_style: Option<Arc<ComputedValues>>,
mut cascade_info: Option<<&mut CascadeInfo>,
font_metrics_provider: &FontMetricsProvider,
flags: CascadeFlags,
quirks_mode: QuirksMode)
-> ComputedValues
-> ComputedValuesInner
where F: Fn() -> I,
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
{

View file

@ -11,7 +11,7 @@ use euclid::{Size2D, TypedSize2D};
use font_metrics::ServoMetricsProvider;
use media_queries::MediaType;
use parser::ParserContext;
use properties::{ComputedValues, StyleBuilder};
use properties::{ComputedValuesInner, StyleBuilder};
use properties::longhands::font_size;
use selectors::parser::SelectorParseError;
use std::fmt;
@ -62,11 +62,11 @@ impl Device {
}
/// Return the default computed values for this device.
pub fn default_computed_values(&self) -> &ComputedValues {
pub fn default_computed_values(&self) -> &ComputedValuesInner {
// 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.
ComputedValues::initial_values()
ComputedValuesInner::initial_values()
}
/// Get the font size of the root element (for rem)

View file

@ -6,7 +6,7 @@
//! a computed style needs in order for it to adhere to the CSS spec.
use app_units::Au;
use properties::{self, CascadeFlags, ComputedValues};
use properties::{self, CascadeFlags, ComputedValuesInner};
use properties::{IS_ROOT_ELEMENT, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, StyleBuilder};
use properties::longhands::display::computed_value::T as display;
use properties::longhands::float::computed_value::T as float;
@ -54,7 +54,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// Apply the blockification rules based on the table in CSS 2.2 section 9.7.
/// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo
fn blockify_if_necessary(&mut self,
layout_parent_style: &ComputedValues,
layout_parent_style: &ComputedValuesInner,
flags: CascadeFlags) {
let mut blockify = false;
macro_rules! blockify_if {
@ -136,7 +136,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html
/// https://github.com/servo/servo/issues/15754
fn adjust_for_writing_mode(&mut self,
layout_parent_style: &ComputedValues) {
layout_parent_style: &ComputedValuesInner) {
let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode();
let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode();
@ -196,7 +196,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
///
/// See https://github.com/servo/servo/issues/15229
#[cfg(feature = "servo")]
fn adjust_for_alignment(&mut self, layout_parent_style: &ComputedValues) {
fn adjust_for_alignment(&mut self, layout_parent_style: &ComputedValuesInner) {
use computed_values::align_items::T as align_items;
use computed_values::align_self::T as align_self;
@ -315,7 +315,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
}
/// Set the HAS_TEXT_DECORATION_LINES flag based on parent style.
fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValues) {
fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValuesInner) {
use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES;
if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) ||
!self.style.get_text().clone_text_decoration_line().is_empty() {
@ -324,7 +324,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
}
#[cfg(feature = "gecko")]
fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool {
fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValuesInner) -> bool {
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
// Line break suppression should only be propagated to in-flow children.
if self.style.floated() || self.style.out_of_flow_positioned() {
@ -361,8 +361,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// * correct unicode-bidi.
#[cfg(feature = "gecko")]
fn adjust_for_ruby(&mut self,
layout_parent_style: &ComputedValues,
default_computed_values: &'b ComputedValues,
layout_parent_style: &ComputedValuesInner,
default_computed_values: &'b ComputedValuesInner,
flags: CascadeFlags) {
use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
@ -406,8 +406,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// When comparing to Gecko, this is similar to the work done by
/// `nsStyleContext::ApplyStyleFixups`.
pub fn adjust(&mut self,
layout_parent_style: &ComputedValues,
_default_computed_values: &'b ComputedValues,
layout_parent_style: &ComputedValuesInner,
_default_computed_values: &'b ComputedValuesInner,
flags: CascadeFlags) {
#[cfg(feature = "gecko")]
{

View file

@ -11,7 +11,7 @@ use data::{ElementStyles, EagerPseudoStyles};
use dom::TElement;
use log::LogLevel::Trace;
use matching::{CascadeVisitedMode, MatchMethods};
use properties::{AnimationRules, CascadeFlags, ComputedValues};
use properties::{AnimationRules, CascadeFlags, ComputedValues, ComputedValuesInner};
use properties::{IS_ROOT_ELEMENT, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
use properties::{VISITED_DEPENDENT_ONLY, cascade};
use rule_tree::StrongRuleNode;
@ -47,7 +47,7 @@ pub struct PrimaryStyle {
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
where
E: TElement,
F: FnOnce(Option<&ComputedValues>, Option<&ComputedValues>) -> R,
F: FnOnce(Option<&ComputedValuesInner>, Option<&ComputedValuesInner>) -> R,
{
let parent_el = element.inheritance_parent();
let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data());
@ -72,7 +72,7 @@ where
layout_parent_style = Some(layout_parent_data.styles.primary());
}
f(parent_style.map(|s| &**s), layout_parent_style.map(|s| &**s))
f(parent_style.map(|s| &***s), layout_parent_style.map(|s| &***s))
}
impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E>
@ -98,8 +98,8 @@ where
/// Resolve just the style of a given element.
pub fn resolve_primary_style(
&mut self,
parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
parent_style: Option<&ComputedValuesInner>,
layout_parent_style: Option<&ComputedValuesInner>,
) -> PrimaryStyle {
let primary_results =
self.match_primary(VisitedHandlingMode::AllLinksUnvisited);
@ -146,8 +146,8 @@ where
/// Resolve the style of a given element, and all its eager pseudo-elements.
pub fn resolve_style(
&mut self,
parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
parent_style: Option<&ComputedValuesInner>,
layout_parent_style: Option<&ComputedValuesInner>,
) -> ElementStyles {
use properties::longhands::display::computed_value::T as display;
@ -168,7 +168,7 @@ where
if primary_style.style.is_display_contents() {
layout_parent_style
} else {
Some(&*primary_style.style)
Some(&**primary_style.style)
};
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
let pseudo_style = self.resolve_pseudo_style(
@ -215,8 +215,8 @@ where
fn cascade_style_and_visited(
&mut self,
inputs: CascadeInputs,
parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
parent_style: Option<&ComputedValuesInner>,
layout_parent_style: Option<&ComputedValuesInner>,
pseudo: Option<&PseudoElement>,
) -> Arc<ComputedValues> {
let mut style_if_visited = None;
@ -272,7 +272,7 @@ where
if primary_style.style.is_display_contents() {
layout_parent_style
} else {
Some(&*primary_style.style)
Some(&**primary_style.style)
};
for (i, mut inputs) in pseudo_array.unwrap().iter_mut().enumerate() {
@ -302,7 +302,7 @@ where
&mut self,
pseudo: &PseudoElement,
originating_element_style: &PrimaryStyle,
layout_parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValuesInner>,
) -> Option<Arc<ComputedValues>> {
let rules = self.match_pseudo(
&originating_element_style.style,
@ -398,7 +398,7 @@ where
fn match_pseudo(
&mut self,
originating_element_style: &ComputedValues,
originating_element_style: &ComputedValuesInner,
pseudo_element: &PseudoElement,
visited_handling: VisitedHandlingMode,
) -> Option<StrongRuleNode> {
@ -462,8 +462,8 @@ where
&mut self,
rules: Option<&StrongRuleNode>,
style_if_visited: Option<Arc<ComputedValues>>,
mut parent_style: Option<&ComputedValues>,
layout_parent_style: Option<&ComputedValues>,
mut parent_style: Option<&ComputedValuesInner>,
layout_parent_style: Option<&ComputedValuesInner>,
cascade_visited: CascadeVisitedMode,
pseudo: Option<&PseudoElement>,
) -> Arc<ComputedValues> {
@ -475,7 +475,7 @@ where
}
if cascade_visited.visited_dependent_only() {
parent_style = parent_style.map(|s| {
s.get_visited_style().map(|s| &**s).unwrap_or(s)
s.get_visited_style().unwrap_or(s)
});
cascade_flags.insert(VISITED_DEPENDENT_ONLY);
}
@ -486,7 +486,7 @@ where
}
let values =
Arc::new(cascade(
cascade(
self.context.shared.stylist.device(),
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
&self.context.shared.guards,
@ -497,9 +497,9 @@ where
&self.context.thread_local.font_metrics_provider,
cascade_flags,
self.context.shared.quirks_mode
));
);
cascade_info.finish(&self.element.as_node());
values
values.to_outer()
}
}

View file

@ -16,7 +16,7 @@ use gecko_bindings::structs::{nsIAtom, StyleRuleInclusion};
use invalidation::element::invalidation_map::InvalidationMap;
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
use media_queries::Device;
use properties::{self, CascadeFlags, ComputedValues};
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner};
use properties::{AnimationRules, PropertyDeclarationBlock};
#[cfg(feature = "servo")]
use properties::INHERIT_ALL;
@ -599,7 +599,7 @@ impl Stylist {
pub fn precomputed_values_for_pseudo(&self,
guards: &StylesheetGuards,
pseudo: &PseudoElement,
parent: Option<&Arc<ComputedValues>>,
parent: Option<&ComputedValuesInner>,
cascade_flags: CascadeFlags,
font_metrics: &FontMetricsProvider)
-> Arc<ComputedValues> {
@ -629,18 +629,16 @@ impl Stylist {
// descendant of a display: contents element where display: contents is
// the actual used value, and the computed value of it would need
// blockification.
let computed =
properties::cascade(&self.device,
&rule_node,
guards,
parent.map(|p| &**p),
parent.map(|p| &**p),
None,
None,
font_metrics,
cascade_flags,
self.quirks_mode);
Arc::new(computed)
properties::cascade(&self.device,
&rule_node,
guards,
parent,
parent,
None,
None,
font_metrics,
cascade_flags,
self.quirks_mode).to_outer()
}
/// Returns the style for an anonymous box of the given type.
@ -648,7 +646,7 @@ impl Stylist {
pub fn style_for_anonymous(&self,
guards: &StylesheetGuards,
pseudo: &PseudoElement,
parent_style: &Arc<ComputedValues>)
parent_style: &ComputedValuesInner)
-> Arc<ComputedValues> {
use font_metrics::ServoMetricsProvider;
@ -692,7 +690,7 @@ impl Stylist {
element: &E,
pseudo: &PseudoElement,
rule_inclusion: RuleInclusion,
parent_style: &Arc<ComputedValues>,
parent_style: &ComputedValuesInner,
is_probe: bool,
font_metrics: &FontMetricsProvider)
-> Option<Arc<ComputedValues>>
@ -713,7 +711,7 @@ impl Stylist {
pub fn compute_pseudo_element_style_with_inputs(&self,
inputs: &CascadeInputs,
guards: &StylesheetGuards,
parent_style: &Arc<ComputedValues>,
parent_style: &ComputedValuesInner,
font_metrics: &FontMetricsProvider)
-> Option<Arc<ComputedValues>>
{
@ -736,7 +734,7 @@ impl Stylist {
// We want to use the visited bits (if any) from our parent style as
// our parent.
let inherited_style =
parent_style.get_visited_style().unwrap_or(&*parent_style);
parent_style.get_visited_style().unwrap_or(parent_style);
// FIXME(emilio): The lack of layout_parent_style here could be
// worrying, but we're probably dropping the display fixup for
@ -753,9 +751,9 @@ impl Stylist {
None,
font_metrics,
CascadeFlags::empty(),
self.quirks_mode);
self.quirks_mode).to_outer();
Some(Arc::new(computed))
Some(computed)
} else {
None
};
@ -768,19 +766,16 @@ impl Stylist {
// difficult to assert that display: contents nodes never arrive here
// (tl;dr: It doesn't apply for replaced elements and such, but the
// computed value is still "contents").
let computed =
properties::cascade(&self.device,
rules,
guards,
Some(parent_style),
Some(parent_style),
visited_values,
None,
font_metrics,
CascadeFlags::empty(),
self.quirks_mode);
Some(Arc::new(computed))
Some(properties::cascade(&self.device,
rules,
guards,
Some(parent_style),
Some(parent_style),
visited_values,
None,
font_metrics,
CascadeFlags::empty(),
self.quirks_mode).to_outer())
}
/// Computes the cascade inputs for a lazily-cascaded pseudo-element.
@ -1317,7 +1312,7 @@ impl Stylist {
/// Computes styles for a given declaration with parent_style.
pub fn compute_for_declarations(&self,
guards: &StylesheetGuards,
parent_style: &Arc<ComputedValues>,
parent_style: &ComputedValuesInner,
declarations: Arc<Locked<PropertyDeclarationBlock>>)
-> Arc<ComputedValues> {
use font_metrics::get_metrics_provider_for_product;
@ -1333,16 +1328,16 @@ impl Stylist {
// font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations.
// It is unclear if visited styles are meaningful for this case.
let metrics = get_metrics_provider_for_product();
Arc::new(properties::cascade(&self.device,
&rule_node,
guards,
Some(parent_style),
Some(parent_style),
None,
None,
&metrics,
CascadeFlags::empty(),
self.quirks_mode))
properties::cascade(&self.device,
&rule_node,
guards,
Some(parent_style),
Some(parent_style),
None,
None,
&metrics,
CascadeFlags::empty(),
self.quirks_mode).to_outer()
}
/// Accessor for a shared reference to the device.

View file

@ -484,8 +484,8 @@ where
let primary_style =
StyleResolverForElement::new(*ancestor, context, rule_inclusion)
.resolve_primary_style(
style.as_ref().map(|s| &**s),
layout_parent_style.as_ref().map(|s| &**s)
style.as_ref().map(|s| &***s),
layout_parent_style.as_ref().map(|s| &***s)
);
let is_display_contents = primary_style.style.is_display_contents();
@ -501,8 +501,8 @@ where
context.thread_local.bloom_filter.assert_complete(element);
StyleResolverForElement::new(element, context, rule_inclusion)
.resolve_style(
style.as_ref().map(|s| &**s),
layout_parent_style.as_ref().map(|s| &**s)
style.as_ref().map(|s| &***s),
layout_parent_style.as_ref().map(|s| &***s)
)
}

View file

@ -11,7 +11,7 @@ use font_metrics::FontMetricsProvider;
use media_queries::Device;
#[cfg(feature = "gecko")]
use properties;
use properties::{ComputedValues, StyleBuilder};
use properties::{ComputedValuesInner, StyleBuilder};
use std::f32;
use std::f64;
use std::f64::consts::PI;
@ -72,13 +72,13 @@ pub struct Context<'a> {
pub device: &'a Device,
/// The style we're inheriting from.
pub inherited_style: &'a ComputedValues,
pub inherited_style: &'a ComputedValuesInner,
/// The style of the layout parent node. This will almost always be
/// `inherited_style`, except when `display: contents` is at play, in which
/// case it's the style of the last ancestor with a `display` value that
/// isn't `contents`.
pub layout_parent_style: &'a ComputedValues,
pub layout_parent_style: &'a ComputedValuesInner,
/// Values accessed through this need to be in the properties "computed
/// early": color, text-decoration, font-size, display, position, float,
@ -115,7 +115,7 @@ impl<'a> Context<'a> {
/// The current viewport size.
pub fn viewport_size(&self) -> Size2D<Au> { self.device.au_viewport_size() }
/// The style we're inheriting from.
pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style }
pub fn inherited_style(&self) -> &ComputedValuesInner { &self.inherited_style }
/// The current style. Note that only "eager" properties should be accessed
/// from here, see the comment in the member.
pub fn style(&self) -> &StyleBuilder { &self.style }