mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
style: Cleanup most of the Inner mess.
MozReview-Commit-ID: Ieg2GJT0yUl
This commit is contained in:
parent
b113d54987
commit
655c842d2e
13 changed files with 289 additions and 221 deletions
|
@ -416,7 +416,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
|
||||||
&style_pseudo,
|
&style_pseudo,
|
||||||
Some(data.styles.primary()),
|
Some(data.styles.primary()),
|
||||||
CascadeFlags::empty(),
|
CascadeFlags::empty(),
|
||||||
&ServoMetricsProvider, (), ())
|
&ServoMetricsProvider)
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
PseudoElementCascadeType::Lazy => {
|
PseudoElementCascadeType::Lazy => {
|
||||||
|
@ -428,7 +428,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
|
||||||
RuleInclusion::All,
|
RuleInclusion::All,
|
||||||
data.styles.primary(),
|
data.styles.primary(),
|
||||||
/* is_probe = */ false,
|
/* is_probe = */ false,
|
||||||
&ServoMetricsProvider, (), ())
|
&ServoMetricsProvider)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use context::SharedStyleContext;
|
||||||
use dom::OpaqueNode;
|
use dom::OpaqueNode;
|
||||||
use euclid::Point2D;
|
use euclid::Point2D;
|
||||||
use font_metrics::FontMetricsProvider;
|
use font_metrics::FontMetricsProvider;
|
||||||
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner, Importance};
|
use properties::{self, CascadeFlags, ComputedValues, Importance};
|
||||||
use properties::animated_properties::{AnimatableLonghand, AnimatedProperty, TransitionProperty};
|
use properties::animated_properties::{AnimatableLonghand, AnimatedProperty, TransitionProperty};
|
||||||
use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection;
|
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;
|
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,
|
fn from_animatable_longhand(animatable_longhand: &AnimatableLonghand,
|
||||||
timing_function: TimingFunction,
|
timing_function: TimingFunction,
|
||||||
duration: Time,
|
duration: Time,
|
||||||
old_style: &ComputedValuesInner,
|
old_style: &ComputedValues,
|
||||||
new_style: &ComputedValuesInner)
|
new_style: &ComputedValues)
|
||||||
-> Option<PropertyAnimation> {
|
-> Option<PropertyAnimation> {
|
||||||
let animated_property = AnimatedProperty::from_animatable_longhand(animatable_longhand,
|
let animated_property = AnimatedProperty::from_animatable_longhand(animatable_longhand,
|
||||||
old_style,
|
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,
|
fn compute_style_for_animation_step(context: &SharedStyleContext,
|
||||||
step: &KeyframesStep,
|
step: &KeyframesStep,
|
||||||
previous_style: &ComputedValuesInner,
|
previous_style: &ComputedValues,
|
||||||
style_from_cascade: &ComputedValuesInner,
|
style_from_cascade: &Arc<ComputedValues>,
|
||||||
font_metrics_provider: &FontMetricsProvider)
|
font_metrics_provider: &FontMetricsProvider)
|
||||||
-> ComputedValuesInner {
|
-> Arc<ComputedValues> {
|
||||||
match step.value {
|
match step.value {
|
||||||
KeyframesStepValue::ComputedValues => style_from_cascade.clone(),
|
KeyframesStepValue::ComputedValues => style_from_cascade.clone(),
|
||||||
KeyframesStepValue::Declarations { block: ref declarations } => {
|
KeyframesStepValue::Declarations { block: ref declarations } => {
|
||||||
|
@ -502,10 +502,11 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
|
||||||
// as existing browsers don't appear to animate visited styles.
|
// as existing browsers don't appear to animate visited styles.
|
||||||
let computed =
|
let computed =
|
||||||
properties::apply_declarations(context.stylist.device(),
|
properties::apply_declarations(context.stylist.device(),
|
||||||
|
/* pseudo = */ None,
|
||||||
previous_style.rules(),
|
previous_style.rules(),
|
||||||
iter,
|
iter,
|
||||||
previous_style,
|
Some(previous_style),
|
||||||
previous_style,
|
Some(previous_style),
|
||||||
/* cascade_info = */ None,
|
/* cascade_info = */ None,
|
||||||
/* visited_style = */ None,
|
/* visited_style = */ None,
|
||||||
font_metrics_provider,
|
font_metrics_provider,
|
||||||
|
|
|
@ -72,13 +72,46 @@ pub mod style_structs {
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// FIXME(emilio): This is completely duplicated with the other properties code.
|
||||||
pub type ComputedValuesInner = ::gecko_bindings::structs::ServoComputedValues;
|
pub type ComputedValuesInner = ::gecko_bindings::structs::ServoComputedValues;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct ComputedValues(::gecko_bindings::structs::mozilla::ServoStyleContext);
|
pub struct ComputedValues(::gecko_bindings::structs::mozilla::ServoStyleContext);
|
||||||
|
|
||||||
|
impl ComputedValues {
|
||||||
|
pub fn new(
|
||||||
|
device: &Device,
|
||||||
|
parent: Option<<&ComputedValues>,
|
||||||
|
pseudo: Option<<&PseudoElement>,
|
||||||
|
custom_properties: Option<Arc<CustomPropertiesMap>>,
|
||||||
|
writing_mode: WritingMode,
|
||||||
|
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||||
|
flags: ComputedValueFlags,
|
||||||
|
rules: Option<StrongRuleNode>,
|
||||||
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
% for style_struct in data.style_structs:
|
||||||
|
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||||
|
% endfor
|
||||||
|
) -> Arc<Self> {
|
||||||
|
ComputedValuesInner::new(
|
||||||
|
custom_properties,
|
||||||
|
writing_mode,
|
||||||
|
font_size_keyword,
|
||||||
|
flags,
|
||||||
|
rules,
|
||||||
|
visited_style,
|
||||||
|
% for style_struct in data.style_structs:
|
||||||
|
${style_struct.ident},
|
||||||
|
% endfor
|
||||||
|
).to_outer(
|
||||||
|
device,
|
||||||
|
parent,
|
||||||
|
pseudo.map(|p| p.pseudo_info())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Drop for ComputedValues {
|
impl Drop for ComputedValues {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -154,6 +187,7 @@ impl ComputedValuesInner {
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo,
|
pub fn to_outer(self, device: &Device, parent: ParentStyleContextInfo,
|
||||||
info: Option<PseudoInfo>) -> Arc<ComputedValues> {
|
info: Option<PseudoInfo>) -> Arc<ComputedValues> {
|
||||||
let (tag, ty) = if let Some(info) = info {
|
let (tag, ty) = if let Some(info) = info {
|
||||||
|
|
|
@ -292,7 +292,7 @@
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use properties::{DeclaredValue, LonghandId, LonghandIdSet};
|
use properties::{DeclaredValue, LonghandId, LonghandIdSet};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use properties::{CSSWideKeyword, ComputedValuesInner, PropertyDeclaration};
|
use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration};
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use properties::style_structs;
|
use properties::style_structs;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
|
@ -310,8 +310,8 @@
|
||||||
${caller.body()}
|
${caller.body()}
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub fn cascade_property(declaration: &PropertyDeclaration,
|
pub fn cascade_property(declaration: &PropertyDeclaration,
|
||||||
inherited_style: &ComputedValuesInner,
|
inherited_style: &ComputedValues,
|
||||||
default_style: &ComputedValuesInner,
|
default_style: &ComputedValues,
|
||||||
context: &mut computed::Context,
|
context: &mut computed::Context,
|
||||||
cacheable: &mut bool,
|
cacheable: &mut bool,
|
||||||
cascade_info: &mut Option<<&mut CascadeInfo>) {
|
cascade_info: &mut Option<<&mut CascadeInfo>) {
|
||||||
|
|
|
@ -181,7 +181,7 @@
|
||||||
|
|
||||||
% if product == "servo":
|
% if product == "servo":
|
||||||
fn cascade_property_custom(_declaration: &PropertyDeclaration,
|
fn cascade_property_custom(_declaration: &PropertyDeclaration,
|
||||||
_inherited_style: &ComputedValuesInner,
|
_inherited_style: &ComputedValues,
|
||||||
context: &mut computed::Context,
|
context: &mut computed::Context,
|
||||||
_cacheable: &mut bool) {
|
_cacheable: &mut bool) {
|
||||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
|
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
|
||||||
|
|
|
@ -249,7 +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: &ComputedValuesInner,
|
_inherited_style: &ComputedValues,
|
||||||
context: &mut computed::Context,
|
context: &mut computed::Context,
|
||||||
_cacheable: &mut bool) {
|
_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);
|
||||||
|
|
|
@ -32,6 +32,7 @@ use media_queries::Device;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use properties::animated_properties::AnimatableLonghand;
|
use properties::animated_properties::AnimatableLonghand;
|
||||||
#[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont;
|
#[cfg(feature = "gecko")] use properties::longhands::system_font::SystemFont;
|
||||||
|
use selector_parser::PseudoElement;
|
||||||
use selectors::parser::SelectorParseError;
|
use selectors::parser::SelectorParseError;
|
||||||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||||
use shared_lock::StylesheetGuards;
|
use shared_lock::StylesheetGuards;
|
||||||
|
@ -107,19 +108,20 @@ pub struct FontComputationData {
|
||||||
///
|
///
|
||||||
/// When this is Some, we compute font sizes by computing the keyword against
|
/// When this is Some, we compute font sizes by computing the keyword against
|
||||||
/// the generic font, and then multiplying it by the ratio.
|
/// the generic font, and then multiplying it by the ratio.
|
||||||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>
|
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl FontComputationData {
|
impl FontComputationData {
|
||||||
/// Assigns values for variables in struct FontComputationData
|
/// Assigns values for variables in struct FontComputationData
|
||||||
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self {
|
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self {
|
||||||
FontComputationData {
|
FontComputationData {
|
||||||
font_size_keyword: font_size_keyword
|
font_size_keyword: font_size_keyword
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Assigns default values for variables in struct FontComputationData
|
|
||||||
pub fn default_values() -> Self {
|
/// Assigns default values for variables in struct FontComputationData
|
||||||
|
pub fn default_values() -> Self {
|
||||||
FontComputationData{
|
FontComputationData{
|
||||||
font_size_keyword: Some((Default::default(), 1.))
|
font_size_keyword: Some((Default::default(), 1.))
|
||||||
}
|
}
|
||||||
|
@ -1873,14 +1875,6 @@ pub mod style_structs {
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo};
|
pub use gecko_properties::{ComputedValues, ComputedValuesInner, ParentStyleContextInfo, PseudoInfo};
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
/// Servo doesn't have style contexts so this is extraneous info
|
|
||||||
pub type PseudoInfo = ();
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
/// Servo doesn't have style contexts so this is extraneous info
|
|
||||||
pub type ParentStyleContextInfo = ();
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
|
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
|
||||||
/// Actual data of ComputedValues, to match up with Gecko
|
/// Actual data of ComputedValues, to match up with Gecko
|
||||||
|
@ -1891,6 +1885,7 @@ pub struct ComputedValuesInner {
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
/// The writing mode of this computed values struct.
|
/// The writing mode of this computed values struct.
|
||||||
pub writing_mode: WritingMode,
|
pub writing_mode: WritingMode,
|
||||||
|
|
||||||
/// The keyword behind the current font-size property, if any
|
/// The keyword behind the current font-size property, if any
|
||||||
pub font_computation_data: FontComputationData,
|
pub font_computation_data: FontComputationData,
|
||||||
|
|
||||||
|
@ -1923,12 +1918,51 @@ pub struct ComputedValues {
|
||||||
/// whereas ComputedValuesInner is the core set of computed values.
|
/// whereas ComputedValuesInner is the core set of computed values.
|
||||||
///
|
///
|
||||||
/// We maintain this distinction in servo to reduce the amount of special casing.
|
/// We maintain this distinction in servo to reduce the amount of special casing.
|
||||||
pub inner: ComputedValuesInner,
|
inner: ComputedValuesInner,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ComputedValues {
|
||||||
|
/// Create a new refcounted `ComputedValues`
|
||||||
|
pub fn new(
|
||||||
|
_: &Device,
|
||||||
|
_: Option<<&ComputedValues>,
|
||||||
|
_: Option<<&PseudoElement>,
|
||||||
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
|
writing_mode: WritingMode,
|
||||||
|
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||||
|
flags: ComputedValueFlags,
|
||||||
|
rules: Option<StrongRuleNode>,
|
||||||
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
|
% for style_struct in data.active_style_structs():
|
||||||
|
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||||
|
% endfor
|
||||||
|
) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
inner: ComputedValuesInner::new(
|
||||||
|
custom_properties,
|
||||||
|
writing_mode,
|
||||||
|
font_size_keyword,
|
||||||
|
flags,
|
||||||
|
rules,
|
||||||
|
visited_style,
|
||||||
|
% for style_struct in data.active_style_structs():
|
||||||
|
${style_struct.ident},
|
||||||
|
% endfor
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the initial computed values.
|
||||||
|
pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES }
|
||||||
|
|
||||||
|
/// Servo doesn't track the pseudo-element, so no need to do anything fancy
|
||||||
|
/// here.
|
||||||
|
fn pseudo(&self) -> Option<<&PseudoElement> { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
impl ComputedValuesInner {
|
impl ComputedValuesInner {
|
||||||
/// Construct a `ComputedValues` instance.
|
/// Construct a `ComputedValuesInner` instance.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
|
@ -1952,9 +1986,6 @@ impl ComputedValuesInner {
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the initial computed values.
|
|
||||||
pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
|
@ -1974,12 +2005,6 @@ impl ops::DerefMut for ComputedValues {
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
impl ComputedValuesInner {
|
impl ComputedValuesInner {
|
||||||
/// Convert to an Arc<ComputedValues>
|
|
||||||
pub fn to_outer(self, _: &Device, _: ParentStyleContextInfo,
|
|
||||||
_: Option<PseudoInfo>) -> Arc<ComputedValues> {
|
|
||||||
Arc::new(ComputedValues {inner: self})
|
|
||||||
}
|
|
||||||
|
|
||||||
% for style_struct in data.active_style_structs():
|
% for style_struct in data.active_style_structs():
|
||||||
/// Clone the ${style_struct.name} struct.
|
/// Clone the ${style_struct.name} struct.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2428,6 +2453,9 @@ 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,
|
||||||
|
parent_style: Option<<&'a ComputedValues>,
|
||||||
|
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>,
|
||||||
|
@ -2452,8 +2480,11 @@ pub struct StyleBuilder<'a> {
|
||||||
impl<'a> StyleBuilder<'a> {
|
impl<'a> StyleBuilder<'a> {
|
||||||
/// Trivially construct a `StyleBuilder`.
|
/// Trivially construct a `StyleBuilder`.
|
||||||
fn new(
|
fn new(
|
||||||
inherited_style: &'a ComputedValuesInner,
|
device: &'a Device,
|
||||||
reset_style: &'a ComputedValuesInner,
|
parent_style: Option<<&'a ComputedValues>,
|
||||||
|
reset_style: &'a ComputedValues,
|
||||||
|
pseudo: Option<<&'a PseudoElement>,
|
||||||
|
cascade_flags: CascadeFlags,
|
||||||
rules: Option<StrongRuleNode>,
|
rules: Option<StrongRuleNode>,
|
||||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||||
writing_mode: WritingMode,
|
writing_mode: WritingMode,
|
||||||
|
@ -2461,7 +2492,17 @@ impl<'a> StyleBuilder<'a> {
|
||||||
flags: ComputedValueFlags,
|
flags: ComputedValueFlags,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let inherited_style = parent_style.unwrap_or(reset_style);
|
||||||
|
let reset_style = if cascade_flags.contains(INHERIT_ALL) {
|
||||||
|
inherited_style
|
||||||
|
} else {
|
||||||
|
reset_style
|
||||||
|
};
|
||||||
|
|
||||||
StyleBuilder {
|
StyleBuilder {
|
||||||
|
device,
|
||||||
|
parent_style,
|
||||||
|
pseudo,
|
||||||
rules,
|
rules,
|
||||||
custom_properties,
|
custom_properties,
|
||||||
writing_mode,
|
writing_mode,
|
||||||
|
@ -2480,19 +2521,27 @@ impl<'a> StyleBuilder<'a> {
|
||||||
|
|
||||||
/// Creates a StyleBuilder holding only references to the structs of `s`, in
|
/// Creates a StyleBuilder holding only references to the structs of `s`, in
|
||||||
/// order to create a derived style.
|
/// order to create a derived style.
|
||||||
pub fn for_derived_style(s: &'a ComputedValuesInner) -> Self {
|
pub fn for_derived_style(device: &'a Device, s: &'a ComputedValues) -> Self {
|
||||||
Self::for_inheritance(s, s)
|
Self::for_inheritance(device, s, s, s.pseudo())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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(
|
||||||
parent: &'a ComputedValuesInner,
|
device: &'a Device,
|
||||||
default: &'a ComputedValuesInner
|
parent: &'a ComputedValues,
|
||||||
|
reset: &'a ComputedValues,
|
||||||
|
pseudo: Option<<&'a PseudoElement>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
// FIXME(emilio): This Some(parent) here is inconsistent with what we
|
||||||
|
// usually do if `parent` is the default computed values, but that's
|
||||||
|
// fine, and we want to eventually get rid of it.
|
||||||
Self::new(
|
Self::new(
|
||||||
parent,
|
device,
|
||||||
default,
|
Some(parent),
|
||||||
|
reset,
|
||||||
|
pseudo,
|
||||||
|
CascadeFlags::empty(),
|
||||||
/* rules = */ None,
|
/* rules = */ None,
|
||||||
parent.custom_properties(),
|
parent.custom_properties(),
|
||||||
parent.writing_mode,
|
parent.writing_mode,
|
||||||
|
@ -2566,16 +2615,20 @@ impl<'a> StyleBuilder<'a> {
|
||||||
|
|
||||||
|
|
||||||
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
|
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
|
||||||
pub fn build(self) -> ComputedValuesInner {
|
pub fn build(self) -> Arc<ComputedValues> {
|
||||||
ComputedValuesInner::new(self.custom_properties,
|
ComputedValues::new(
|
||||||
self.writing_mode,
|
self.device,
|
||||||
self.font_size_keyword,
|
self.parent_style,
|
||||||
self.flags,
|
self.pseudo,
|
||||||
self.rules,
|
self.custom_properties,
|
||||||
self.visited_style,
|
self.writing_mode,
|
||||||
% for style_struct in data.active_style_structs():
|
self.font_size_keyword,
|
||||||
self.${style_struct.ident}.build(),
|
self.flags,
|
||||||
% endfor
|
self.rules,
|
||||||
|
self.visited_style,
|
||||||
|
% for style_struct in data.active_style_structs():
|
||||||
|
self.${style_struct.ident}.build(),
|
||||||
|
% endfor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2597,28 +2650,30 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
|
||||||
mod lazy_static_module {
|
mod lazy_static_module {
|
||||||
use logical_geometry::WritingMode;
|
use logical_geometry::WritingMode;
|
||||||
use stylearc::Arc;
|
use stylearc::Arc;
|
||||||
use super::{ComputedValuesInner, longhands, style_structs, FontComputationData};
|
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
|
||||||
use super::computed_value_flags::ComputedValueFlags;
|
use super::computed_value_flags::ComputedValueFlags;
|
||||||
|
|
||||||
/// The initial values for all style structs as defined by the specification.
|
/// The initial values for all style structs as defined by the specification.
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref INITIAL_SERVO_VALUES: ComputedValuesInner = ComputedValuesInner {
|
pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues {
|
||||||
% for style_struct in data.active_style_structs():
|
inner: ComputedValuesInner {
|
||||||
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
|
% for style_struct in data.active_style_structs():
|
||||||
% for longhand in style_struct.longhands:
|
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
|
||||||
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
|
% for longhand in style_struct.longhands:
|
||||||
% endfor
|
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
|
||||||
% if style_struct.name == "Font":
|
% endfor
|
||||||
hash: 0,
|
% if style_struct.name == "Font":
|
||||||
% endif
|
hash: 0,
|
||||||
}),
|
% endif
|
||||||
% endfor
|
}),
|
||||||
custom_properties: None,
|
% endfor
|
||||||
writing_mode: WritingMode::empty(),
|
custom_properties: None,
|
||||||
font_computation_data: FontComputationData::default_values(),
|
writing_mode: WritingMode::empty(),
|
||||||
rules: None,
|
font_computation_data: FontComputationData::default_values(),
|
||||||
visited_style: None,
|
rules: None,
|
||||||
flags: ComputedValueFlags::empty(),
|
visited_style: None,
|
||||||
|
flags: ComputedValueFlags::empty(),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2626,8 +2681,8 @@ 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: &ComputedValuesInner,
|
inherited_style: &ComputedValues,
|
||||||
default_style: &ComputedValuesInner,
|
default_style: &ComputedValues,
|
||||||
context: &mut computed::Context,
|
context: &mut computed::Context,
|
||||||
cacheable: &mut bool,
|
cacheable: &mut bool,
|
||||||
cascade_info: &mut Option<<&mut CascadeInfo>);
|
cascade_info: &mut Option<<&mut CascadeInfo>);
|
||||||
|
@ -2688,29 +2743,19 @@ bitflags! {
|
||||||
/// Returns the computed values.
|
/// Returns the computed values.
|
||||||
/// * `flags`: Various flags.
|
/// * `flags`: Various flags.
|
||||||
///
|
///
|
||||||
pub fn cascade(device: &Device,
|
pub fn cascade(
|
||||||
rule_node: &StrongRuleNode,
|
device: &Device,
|
||||||
guards: &StylesheetGuards,
|
pseudo: Option<<&PseudoElement>,
|
||||||
parent_style: Option<<&ComputedValuesInner>,
|
rule_node: &StrongRuleNode,
|
||||||
layout_parent_style: Option<<&ComputedValuesInner>,
|
guards: &StylesheetGuards,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
parent_style: Option<<&ComputedValues>,
|
||||||
cascade_info: Option<<&mut CascadeInfo>,
|
layout_parent_style: Option<<&ComputedValues>,
|
||||||
font_metrics_provider: &FontMetricsProvider,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
flags: CascadeFlags,
|
cascade_info: Option<<&mut CascadeInfo>,
|
||||||
quirks_mode: QuirksMode)
|
font_metrics_provider: &FontMetricsProvider,
|
||||||
-> ComputedValuesInner {
|
flags: CascadeFlags,
|
||||||
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
|
quirks_mode: QuirksMode
|
||||||
let (inherited_style, layout_parent_style) = match parent_style {
|
) -> Arc<ComputedValues> {
|
||||||
Some(parent_style) => {
|
|
||||||
(parent_style,
|
|
||||||
layout_parent_style.unwrap_or(parent_style))
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
(device.default_computed_values(),
|
|
||||||
device.default_computed_values())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let iter_declarations = || {
|
let iter_declarations = || {
|
||||||
rule_node.self_and_ancestors().flat_map(|node| {
|
rule_node.self_and_ancestors().flat_map(|node| {
|
||||||
let cascade_level = node.cascade_level();
|
let cascade_level = node.cascade_level();
|
||||||
|
@ -2735,35 +2780,53 @@ pub fn cascade(device: &Device,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
apply_declarations(device,
|
apply_declarations(
|
||||||
rule_node,
|
device,
|
||||||
iter_declarations,
|
pseudo,
|
||||||
inherited_style,
|
rule_node,
|
||||||
layout_parent_style,
|
iter_declarations,
|
||||||
visited_style,
|
parent_style,
|
||||||
cascade_info,
|
layout_parent_style,
|
||||||
font_metrics_provider,
|
visited_style,
|
||||||
flags,
|
cascade_info,
|
||||||
quirks_mode)
|
font_metrics_provider,
|
||||||
|
flags,
|
||||||
|
quirks_mode,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NOTE: This function expects the declaration with more priority to appear
|
/// NOTE: This function expects the declaration with more priority to appear
|
||||||
/// first.
|
/// first.
|
||||||
#[allow(unused_mut)] // conditionally compiled code for "position"
|
#[allow(unused_mut)] // conditionally compiled code for "position"
|
||||||
pub fn apply_declarations<'a, F, I>(device: &Device,
|
pub fn apply_declarations<'a, F, I>(
|
||||||
rules: &StrongRuleNode,
|
device: &Device,
|
||||||
iter_declarations: F,
|
pseudo: Option<<&PseudoElement>,
|
||||||
inherited_style: &ComputedValuesInner,
|
rules: &StrongRuleNode,
|
||||||
layout_parent_style: &ComputedValuesInner,
|
iter_declarations: F,
|
||||||
visited_style: Option<Arc<ComputedValues>>,
|
parent_style: Option<<&ComputedValues>,
|
||||||
mut cascade_info: Option<<&mut CascadeInfo>,
|
layout_parent_style: Option<<&ComputedValues>,
|
||||||
font_metrics_provider: &FontMetricsProvider,
|
visited_style: Option<Arc<ComputedValues>>,
|
||||||
flags: CascadeFlags,
|
mut cascade_info: Option<<&mut CascadeInfo>,
|
||||||
quirks_mode: QuirksMode)
|
font_metrics_provider: &FontMetricsProvider,
|
||||||
-> ComputedValuesInner
|
flags: CascadeFlags,
|
||||||
where F: Fn() -> I,
|
quirks_mode: QuirksMode,
|
||||||
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
|
) -> Arc<ComputedValues>
|
||||||
|
where
|
||||||
|
F: Fn() -> I,
|
||||||
|
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
|
||||||
{
|
{
|
||||||
|
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
|
||||||
|
let (inherited_style, layout_parent_style) = match parent_style {
|
||||||
|
Some(parent_style) => {
|
||||||
|
(parent_style,
|
||||||
|
layout_parent_style.unwrap_or(parent_style))
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
(device.default_computed_values(),
|
||||||
|
device.default_computed_values())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let default_style = device.default_computed_values();
|
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;
|
||||||
|
@ -2780,23 +2843,19 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
::custom_properties::finish_cascade(
|
::custom_properties::finish_cascade(
|
||||||
custom_properties, &inherited_custom_properties);
|
custom_properties, &inherited_custom_properties);
|
||||||
|
|
||||||
let reset_style = if flags.contains(INHERIT_ALL) {
|
|
||||||
inherited_style
|
|
||||||
} else {
|
|
||||||
default_style
|
|
||||||
};
|
|
||||||
|
|
||||||
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,
|
device: device,
|
||||||
inherited_style: inherited_style,
|
inherited_style: inherited_style,
|
||||||
layout_parent_style: layout_parent_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(
|
style: StyleBuilder::new(
|
||||||
inherited_style,
|
device,
|
||||||
reset_style,
|
parent_style,
|
||||||
|
device.default_computed_values(),
|
||||||
|
pseudo,
|
||||||
|
flags,
|
||||||
Some(rules.clone()),
|
Some(rules.clone()),
|
||||||
custom_properties,
|
custom_properties,
|
||||||
WritingMode::empty(),
|
WritingMode::empty(),
|
||||||
|
@ -3038,8 +3097,11 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
|
|
||||||
{
|
{
|
||||||
StyleAdjuster::new(&mut style)
|
StyleAdjuster::new(&mut style)
|
||||||
.adjust(context.layout_parent_style,
|
.adjust(
|
||||||
context.device.default_computed_values(), flags);
|
layout_parent_style,
|
||||||
|
context.device.default_computed_values(),
|
||||||
|
flags
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
|
|
|
@ -11,7 +11,7 @@ use euclid::{Size2D, TypedSize2D};
|
||||||
use font_metrics::ServoMetricsProvider;
|
use font_metrics::ServoMetricsProvider;
|
||||||
use media_queries::MediaType;
|
use media_queries::MediaType;
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use properties::{ComputedValuesInner, StyleBuilder};
|
use properties::{ComputedValues, StyleBuilder};
|
||||||
use properties::longhands::font_size;
|
use properties::longhands::font_size;
|
||||||
use selectors::parser::SelectorParseError;
|
use selectors::parser::SelectorParseError;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -62,11 +62,11 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the default computed values for this device.
|
/// Return the default computed values for this device.
|
||||||
pub fn default_computed_values(&self) -> &ComputedValuesInner {
|
pub fn default_computed_values(&self) -> &ComputedValues{
|
||||||
// FIXME(bz): This isn't really right, but it's no more wrong
|
// FIXME(bz): This isn't really right, but it's no more wrong
|
||||||
// than what we used to do. See
|
// than what we used to do. See
|
||||||
// https://github.com/servo/servo/issues/14773 for fixing it properly.
|
// https://github.com/servo/servo/issues/14773 for fixing it properly.
|
||||||
ComputedValuesInner::initial_values()
|
ComputedValues::initial_values()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the font size of the root element (for rem)
|
/// Get the font size of the root element (for rem)
|
||||||
|
@ -231,8 +231,7 @@ impl Range<specified::Length> {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: device,
|
device: device,
|
||||||
inherited_style: default_values,
|
inherited_style: default_values,
|
||||||
layout_parent_style: default_values,
|
style: StyleBuilder::for_derived_style(device, default_values),
|
||||||
style: StyleBuilder::for_derived_style(default_values),
|
|
||||||
// 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.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use data::{ElementStyles, EagerPseudoStyles};
|
||||||
use dom::TElement;
|
use dom::TElement;
|
||||||
use log::LogLevel::Trace;
|
use log::LogLevel::Trace;
|
||||||
use matching::{CascadeVisitedMode, MatchMethods};
|
use matching::{CascadeVisitedMode, MatchMethods};
|
||||||
use properties::{AnimationRules, CascadeFlags, ComputedValues, ComputedValuesInner};
|
use properties::{AnimationRules, CascadeFlags, ComputedValues};
|
||||||
use properties::{IS_ROOT_ELEMENT, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
|
use properties::{IS_ROOT_ELEMENT, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
|
||||||
use properties::{VISITED_DEPENDENT_ONLY, cascade};
|
use properties::{VISITED_DEPENDENT_ONLY, cascade};
|
||||||
use rule_tree::StrongRuleNode;
|
use rule_tree::StrongRuleNode;
|
||||||
|
@ -47,7 +47,7 @@ pub struct PrimaryStyle {
|
||||||
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
|
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
F: FnOnce(Option<&ComputedValues>, Option<&ComputedValuesInner>) -> R,
|
F: FnOnce(Option<&ComputedValues>, Option<&ComputedValues>) -> R,
|
||||||
{
|
{
|
||||||
let parent_el = element.inheritance_parent();
|
let parent_el = element.inheritance_parent();
|
||||||
let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data());
|
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());
|
layout_parent_style = Some(layout_parent_data.styles.primary());
|
||||||
}
|
}
|
||||||
|
|
||||||
f(parent_style.map(|x| &**x), layout_parent_style.map(|s| &***s))
|
f(parent_style.map(|x| &**x), layout_parent_style.map(|s| &**s))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E>
|
impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E>
|
||||||
|
@ -99,7 +99,7 @@ where
|
||||||
pub fn resolve_primary_style(
|
pub fn resolve_primary_style(
|
||||||
&mut self,
|
&mut self,
|
||||||
parent_style: Option<&ComputedValues>,
|
parent_style: Option<&ComputedValues>,
|
||||||
layout_parent_style: Option<&ComputedValuesInner>,
|
layout_parent_style: Option<&ComputedValues>,
|
||||||
) -> PrimaryStyle {
|
) -> PrimaryStyle {
|
||||||
let primary_results =
|
let primary_results =
|
||||||
self.match_primary(VisitedHandlingMode::AllLinksUnvisited);
|
self.match_primary(VisitedHandlingMode::AllLinksUnvisited);
|
||||||
|
@ -147,7 +147,7 @@ where
|
||||||
pub fn resolve_style(
|
pub fn resolve_style(
|
||||||
&mut self,
|
&mut self,
|
||||||
parent_style: Option<&ComputedValues>,
|
parent_style: Option<&ComputedValues>,
|
||||||
layout_parent_style: Option<&ComputedValuesInner>,
|
layout_parent_style: Option<&ComputedValues>,
|
||||||
) -> ElementStyles {
|
) -> ElementStyles {
|
||||||
use properties::longhands::display::computed_value::T as display;
|
use properties::longhands::display::computed_value::T as display;
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ where
|
||||||
if primary_style.style.is_display_contents() {
|
if primary_style.style.is_display_contents() {
|
||||||
layout_parent_style
|
layout_parent_style
|
||||||
} else {
|
} else {
|
||||||
Some(&**primary_style.style)
|
Some(&*primary_style.style)
|
||||||
};
|
};
|
||||||
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
|
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
|
||||||
let pseudo_style = self.resolve_pseudo_style(
|
let pseudo_style = self.resolve_pseudo_style(
|
||||||
|
@ -216,7 +216,7 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
inputs: CascadeInputs,
|
inputs: CascadeInputs,
|
||||||
parent_style: Option<&ComputedValues>,
|
parent_style: Option<&ComputedValues>,
|
||||||
layout_parent_style: Option<&ComputedValuesInner>,
|
layout_parent_style: Option<&ComputedValues>,
|
||||||
pseudo: Option<&PseudoElement>,
|
pseudo: Option<&PseudoElement>,
|
||||||
) -> Arc<ComputedValues> {
|
) -> Arc<ComputedValues> {
|
||||||
let mut style_if_visited = None;
|
let mut style_if_visited = None;
|
||||||
|
@ -272,7 +272,7 @@ where
|
||||||
if primary_style.style.is_display_contents() {
|
if primary_style.style.is_display_contents() {
|
||||||
layout_parent_style
|
layout_parent_style
|
||||||
} else {
|
} else {
|
||||||
Some(&**primary_style.style)
|
Some(&*primary_style.style)
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, mut inputs) in pseudo_array.unwrap().iter_mut().enumerate() {
|
for (i, mut inputs) in pseudo_array.unwrap().iter_mut().enumerate() {
|
||||||
|
@ -302,7 +302,7 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
originating_element_style: &PrimaryStyle,
|
originating_element_style: &PrimaryStyle,
|
||||||
layout_parent_style: Option<&ComputedValuesInner>,
|
layout_parent_style: Option<&ComputedValues>,
|
||||||
) -> Option<Arc<ComputedValues>> {
|
) -> Option<Arc<ComputedValues>> {
|
||||||
let rules = self.match_pseudo(
|
let rules = self.match_pseudo(
|
||||||
&originating_element_style.style,
|
&originating_element_style.style,
|
||||||
|
@ -398,7 +398,7 @@ where
|
||||||
|
|
||||||
fn match_pseudo(
|
fn match_pseudo(
|
||||||
&mut self,
|
&mut self,
|
||||||
originating_element_style: &ComputedValuesInner,
|
originating_element_style: &ComputedValues,
|
||||||
pseudo_element: &PseudoElement,
|
pseudo_element: &PseudoElement,
|
||||||
visited_handling: VisitedHandlingMode,
|
visited_handling: VisitedHandlingMode,
|
||||||
) -> Option<StrongRuleNode> {
|
) -> Option<StrongRuleNode> {
|
||||||
|
@ -463,7 +463,7 @@ where
|
||||||
rules: Option<&StrongRuleNode>,
|
rules: Option<&StrongRuleNode>,
|
||||||
style_if_visited: Option<Arc<ComputedValues>>,
|
style_if_visited: Option<Arc<ComputedValues>>,
|
||||||
mut parent_style: Option<&ComputedValues>,
|
mut parent_style: Option<&ComputedValues>,
|
||||||
layout_parent_style: Option<&ComputedValuesInner>,
|
layout_parent_style: Option<&ComputedValues>,
|
||||||
cascade_visited: CascadeVisitedMode,
|
cascade_visited: CascadeVisitedMode,
|
||||||
pseudo: Option<&PseudoElement>,
|
pseudo: Option<&PseudoElement>,
|
||||||
) -> Arc<ComputedValues> {
|
) -> Arc<ComputedValues> {
|
||||||
|
@ -485,17 +485,14 @@ where
|
||||||
cascade_flags.insert(IS_ROOT_ELEMENT);
|
cascade_flags.insert(IS_ROOT_ELEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
let implemented_pseudo = self.element.implemented_pseudo_element();
|
||||||
let parent_style_context = parent_style;
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
let parent_style_context = ();
|
|
||||||
|
|
||||||
let values =
|
let values =
|
||||||
cascade(
|
cascade(
|
||||||
self.context.shared.stylist.device(),
|
self.context.shared.stylist.device(),
|
||||||
|
pseudo.or(implemented_pseudo.as_ref()),
|
||||||
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
|
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
|
||||||
&self.context.shared.guards,
|
&self.context.shared.guards,
|
||||||
parent_style.map(|x| &**x),
|
parent_style,
|
||||||
layout_parent_style,
|
layout_parent_style,
|
||||||
style_if_visited,
|
style_if_visited,
|
||||||
Some(&mut cascade_info),
|
Some(&mut cascade_info),
|
||||||
|
@ -506,17 +503,6 @@ where
|
||||||
|
|
||||||
cascade_info.finish(&self.element.as_node());
|
cascade_info.finish(&self.element.as_node());
|
||||||
|
|
||||||
// In case of NAC like ::placeholder we style it via
|
values
|
||||||
// cascade_primary without a PseudoElement, but
|
|
||||||
// the element itself is a pseudo, so try to use that
|
|
||||||
// when `pseudo` is unset
|
|
||||||
let pseudo_info = if let Some(pseudo) = pseudo {
|
|
||||||
Some(pseudo.pseudo_info())
|
|
||||||
} else {
|
|
||||||
self.element.implemented_pseudo_element().map(|x| x.pseudo_info())
|
|
||||||
};
|
|
||||||
values.to_outer(self.context.shared.stylist.device(),
|
|
||||||
parent_style_context,
|
|
||||||
pseudo_info)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,13 +702,11 @@ impl MaybeNew for ViewportConstraints {
|
||||||
|
|
||||||
let default_values = device.default_computed_values();
|
let default_values = device.default_computed_values();
|
||||||
|
|
||||||
// TODO(emilio): Stop cloning `ComputedValues` around!
|
|
||||||
let context = Context {
|
let context = Context {
|
||||||
is_root_element: false,
|
is_root_element: false,
|
||||||
device: device,
|
device: device,
|
||||||
inherited_style: default_values,
|
inherited_style: default_values,
|
||||||
layout_parent_style: default_values,
|
style: StyleBuilder::for_derived_style(device, default_values),
|
||||||
style: StyleBuilder::for_derived_style(default_values),
|
|
||||||
font_metrics_provider: &provider,
|
font_metrics_provider: &provider,
|
||||||
cached_system_font: None,
|
cached_system_font: None,
|
||||||
in_media_query: false,
|
in_media_query: false,
|
||||||
|
|
|
@ -16,8 +16,8 @@ use gecko_bindings::structs::{nsIAtom, StyleRuleInclusion};
|
||||||
use invalidation::element::invalidation_map::InvalidationMap;
|
use invalidation::element::invalidation_map::InvalidationMap;
|
||||||
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
|
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
use properties::{self, CascadeFlags, ComputedValues, ComputedValuesInner};
|
use properties::{self, CascadeFlags, ComputedValues};
|
||||||
use properties::{AnimationRules, PropertyDeclarationBlock, PseudoInfo, ParentStyleContextInfo};
|
use properties::{AnimationRules, PropertyDeclarationBlock};
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
use properties::INHERIT_ALL;
|
use properties::INHERIT_ALL;
|
||||||
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
|
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
|
||||||
|
@ -599,11 +599,9 @@ impl Stylist {
|
||||||
pub fn precomputed_values_for_pseudo(&self,
|
pub fn precomputed_values_for_pseudo(&self,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
parent: Option<&ComputedValuesInner>,
|
parent: Option<&ComputedValues>,
|
||||||
cascade_flags: CascadeFlags,
|
cascade_flags: CascadeFlags,
|
||||||
font_metrics: &FontMetricsProvider,
|
font_metrics: &FontMetricsProvider)
|
||||||
pseudo_info: PseudoInfo,
|
|
||||||
parent_style_context: ParentStyleContextInfo)
|
|
||||||
-> Arc<ComputedValues> {
|
-> Arc<ComputedValues> {
|
||||||
debug_assert!(pseudo.is_precomputed());
|
debug_assert!(pseudo.is_precomputed());
|
||||||
|
|
||||||
|
@ -632,6 +630,7 @@ impl Stylist {
|
||||||
// the actual used value, and the computed value of it would need
|
// the actual used value, and the computed value of it would need
|
||||||
// blockification.
|
// blockification.
|
||||||
properties::cascade(&self.device,
|
properties::cascade(&self.device,
|
||||||
|
Some(pseudo),
|
||||||
&rule_node,
|
&rule_node,
|
||||||
guards,
|
guards,
|
||||||
parent,
|
parent,
|
||||||
|
@ -640,8 +639,7 @@ impl Stylist {
|
||||||
None,
|
None,
|
||||||
font_metrics,
|
font_metrics,
|
||||||
cascade_flags,
|
cascade_flags,
|
||||||
self.quirks_mode).to_outer(self.device(), parent_style_context,
|
self.quirks_mode)
|
||||||
Some(pseudo_info))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the style for an anonymous box of the given type.
|
/// Returns the style for an anonymous box of the given type.
|
||||||
|
@ -649,7 +647,7 @@ impl Stylist {
|
||||||
pub fn style_for_anonymous(&self,
|
pub fn style_for_anonymous(&self,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
parent_style: &ComputedValuesInner)
|
parent_style: &ComputedValues)
|
||||||
-> Arc<ComputedValues> {
|
-> Arc<ComputedValues> {
|
||||||
use font_metrics::ServoMetricsProvider;
|
use font_metrics::ServoMetricsProvider;
|
||||||
|
|
||||||
|
@ -678,7 +676,7 @@ impl Stylist {
|
||||||
cascade_flags.insert(INHERIT_ALL);
|
cascade_flags.insert(INHERIT_ALL);
|
||||||
}
|
}
|
||||||
self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags,
|
self.precomputed_values_for_pseudo(guards, &pseudo, Some(parent_style), cascade_flags,
|
||||||
&ServoMetricsProvider, (), ())
|
&ServoMetricsProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes a pseudo-element style lazily during layout.
|
/// Computes a pseudo-element style lazily during layout.
|
||||||
|
@ -693,22 +691,19 @@ impl Stylist {
|
||||||
element: &E,
|
element: &E,
|
||||||
pseudo: &PseudoElement,
|
pseudo: &PseudoElement,
|
||||||
rule_inclusion: RuleInclusion,
|
rule_inclusion: RuleInclusion,
|
||||||
parent_style: &ComputedValuesInner,
|
parent_style: &ComputedValues,
|
||||||
is_probe: bool,
|
is_probe: bool,
|
||||||
font_metrics: &FontMetricsProvider,
|
font_metrics: &FontMetricsProvider)
|
||||||
pseudo_info: PseudoInfo,
|
|
||||||
parent_style_context: ParentStyleContextInfo)
|
|
||||||
-> Option<Arc<ComputedValues>>
|
-> Option<Arc<ComputedValues>>
|
||||||
where E: TElement,
|
where E: TElement,
|
||||||
{
|
{
|
||||||
let cascade_inputs =
|
let cascade_inputs =
|
||||||
self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion);
|
self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion);
|
||||||
self.compute_pseudo_element_style_with_inputs(&cascade_inputs,
|
self.compute_pseudo_element_style_with_inputs(&cascade_inputs,
|
||||||
|
pseudo,
|
||||||
guards,
|
guards,
|
||||||
parent_style,
|
parent_style,
|
||||||
font_metrics,
|
font_metrics)
|
||||||
pseudo_info,
|
|
||||||
parent_style_context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes a pseudo-element style lazily using the given CascadeInputs.
|
/// Computes a pseudo-element style lazily using the given CascadeInputs.
|
||||||
|
@ -717,11 +712,10 @@ impl Stylist {
|
||||||
/// their style with a new parent style.
|
/// their style with a new parent style.
|
||||||
pub fn compute_pseudo_element_style_with_inputs(&self,
|
pub fn compute_pseudo_element_style_with_inputs(&self,
|
||||||
inputs: &CascadeInputs,
|
inputs: &CascadeInputs,
|
||||||
|
pseudo: &PseudoElement,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
parent_style: &ComputedValuesInner,
|
parent_style: &ComputedValues,
|
||||||
font_metrics: &FontMetricsProvider,
|
font_metrics: &FontMetricsProvider)
|
||||||
pseudo_info: PseudoInfo,
|
|
||||||
parent_style_context: ParentStyleContextInfo)
|
|
||||||
-> Option<Arc<ComputedValues>>
|
-> Option<Arc<ComputedValues>>
|
||||||
{
|
{
|
||||||
// We may have only visited rules in cases when we are actually
|
// We may have only visited rules in cases when we are actually
|
||||||
|
@ -743,7 +737,7 @@ impl Stylist {
|
||||||
// We want to use the visited bits (if any) from our parent style as
|
// We want to use the visited bits (if any) from our parent style as
|
||||||
// our parent.
|
// our parent.
|
||||||
let inherited_style =
|
let inherited_style =
|
||||||
parent_style.get_visited_style().map(|x| &**x).unwrap_or(parent_style);
|
parent_style.get_visited_style().unwrap_or(parent_style);
|
||||||
|
|
||||||
// FIXME(emilio): The lack of layout_parent_style here could be
|
// FIXME(emilio): The lack of layout_parent_style here could be
|
||||||
// worrying, but we're probably dropping the display fixup for
|
// worrying, but we're probably dropping the display fixup for
|
||||||
|
@ -752,6 +746,7 @@ impl Stylist {
|
||||||
// (Though the flags don't indicate so!)
|
// (Though the flags don't indicate so!)
|
||||||
let computed =
|
let computed =
|
||||||
properties::cascade(&self.device,
|
properties::cascade(&self.device,
|
||||||
|
Some(pseudo),
|
||||||
rule_node,
|
rule_node,
|
||||||
guards,
|
guards,
|
||||||
Some(inherited_style),
|
Some(inherited_style),
|
||||||
|
@ -760,8 +755,7 @@ impl Stylist {
|
||||||
None,
|
None,
|
||||||
font_metrics,
|
font_metrics,
|
||||||
CascadeFlags::empty(),
|
CascadeFlags::empty(),
|
||||||
self.quirks_mode).to_outer(self.device(), parent_style_context,
|
self.quirks_mode);
|
||||||
Some(pseudo_info.clone()));
|
|
||||||
|
|
||||||
Some(computed)
|
Some(computed)
|
||||||
} else {
|
} else {
|
||||||
|
@ -777,17 +771,16 @@ impl Stylist {
|
||||||
// (tl;dr: It doesn't apply for replaced elements and such, but the
|
// (tl;dr: It doesn't apply for replaced elements and such, but the
|
||||||
// computed value is still "contents").
|
// computed value is still "contents").
|
||||||
Some(properties::cascade(&self.device,
|
Some(properties::cascade(&self.device,
|
||||||
rules,
|
Some(pseudo),
|
||||||
guards,
|
rules,
|
||||||
Some(parent_style),
|
guards,
|
||||||
Some(parent_style),
|
Some(parent_style),
|
||||||
visited_values,
|
Some(parent_style),
|
||||||
None,
|
visited_values,
|
||||||
font_metrics,
|
None,
|
||||||
CascadeFlags::empty(),
|
font_metrics,
|
||||||
self.quirks_mode).to_outer(self.device(),
|
CascadeFlags::empty(),
|
||||||
parent_style_context,
|
self.quirks_mode))
|
||||||
Some(pseudo_info)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the cascade inputs for a lazily-cascaded pseudo-element.
|
/// Computes the cascade inputs for a lazily-cascaded pseudo-element.
|
||||||
|
@ -1324,9 +1317,8 @@ impl Stylist {
|
||||||
/// Computes styles for a given declaration with parent_style.
|
/// Computes styles for a given declaration with parent_style.
|
||||||
pub fn compute_for_declarations(&self,
|
pub fn compute_for_declarations(&self,
|
||||||
guards: &StylesheetGuards,
|
guards: &StylesheetGuards,
|
||||||
parent_style: &ComputedValuesInner,
|
parent_style: &ComputedValues,
|
||||||
declarations: Arc<Locked<PropertyDeclarationBlock>>,
|
declarations: Arc<Locked<PropertyDeclarationBlock>>)
|
||||||
parent_style_context: ParentStyleContextInfo)
|
|
||||||
-> Arc<ComputedValues> {
|
-> Arc<ComputedValues> {
|
||||||
use font_metrics::get_metrics_provider_for_product;
|
use font_metrics::get_metrics_provider_for_product;
|
||||||
|
|
||||||
|
@ -1341,7 +1333,9 @@ impl Stylist {
|
||||||
// font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations.
|
// font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations.
|
||||||
// It is unclear if visited styles are meaningful for this case.
|
// It is unclear if visited styles are meaningful for this case.
|
||||||
let metrics = get_metrics_provider_for_product();
|
let metrics = get_metrics_provider_for_product();
|
||||||
|
// FIXME(emilio): the pseudo bit looks quite dubious!
|
||||||
properties::cascade(&self.device,
|
properties::cascade(&self.device,
|
||||||
|
/* pseudo = */ None,
|
||||||
&rule_node,
|
&rule_node,
|
||||||
guards,
|
guards,
|
||||||
Some(parent_style),
|
Some(parent_style),
|
||||||
|
@ -1350,7 +1344,7 @@ impl Stylist {
|
||||||
None,
|
None,
|
||||||
&metrics,
|
&metrics,
|
||||||
CascadeFlags::empty(),
|
CascadeFlags::empty(),
|
||||||
self.quirks_mode).to_outer(self.device(), parent_style_context, None)
|
self.quirks_mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accessor for a shared reference to the device.
|
/// Accessor for a shared reference to the device.
|
||||||
|
|
|
@ -486,7 +486,7 @@ where
|
||||||
StyleResolverForElement::new(*ancestor, context, rule_inclusion)
|
StyleResolverForElement::new(*ancestor, context, rule_inclusion)
|
||||||
.resolve_primary_style(
|
.resolve_primary_style(
|
||||||
style.as_ref().map(|s| &**s),
|
style.as_ref().map(|s| &**s),
|
||||||
layout_parent_style.as_ref().map(|s| &***s)
|
layout_parent_style.as_ref().map(|s| &**s)
|
||||||
);
|
);
|
||||||
|
|
||||||
let is_display_contents = primary_style.style.is_display_contents();
|
let is_display_contents = primary_style.style.is_display_contents();
|
||||||
|
@ -503,7 +503,7 @@ where
|
||||||
StyleResolverForElement::new(element, context, rule_inclusion)
|
StyleResolverForElement::new(element, context, rule_inclusion)
|
||||||
.resolve_style(
|
.resolve_style(
|
||||||
style.as_ref().map(|s| &**s),
|
style.as_ref().map(|s| &**s),
|
||||||
layout_parent_style.as_ref().map(|s| &***s)
|
layout_parent_style.as_ref().map(|s| &**s)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use font_metrics::FontMetricsProvider;
|
||||||
use media_queries::Device;
|
use media_queries::Device;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use properties;
|
use properties;
|
||||||
use properties::{ComputedValuesInner, StyleBuilder};
|
use properties::{ComputedValues, StyleBuilder};
|
||||||
use std::f32;
|
use std::f32;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::f64::consts::PI;
|
use std::f64::consts::PI;
|
||||||
|
@ -72,13 +72,7 @@ pub struct Context<'a> {
|
||||||
pub device: &'a Device,
|
pub device: &'a Device,
|
||||||
|
|
||||||
/// The style we're inheriting from.
|
/// The style we're inheriting from.
|
||||||
pub inherited_style: &'a ComputedValuesInner,
|
pub inherited_style: &'a ComputedValues,
|
||||||
|
|
||||||
/// 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 ComputedValuesInner,
|
|
||||||
|
|
||||||
/// 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,
|
||||||
|
@ -115,7 +109,7 @@ impl<'a> Context<'a> {
|
||||||
/// 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.device.au_viewport_size() }
|
||||||
/// The style we're inheriting from.
|
/// The style we're inheriting from.
|
||||||
pub fn inherited_style(&self) -> &ComputedValuesInner { &self.inherited_style }
|
pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style }
|
||||||
/// The current style. Note that only "eager" properties should be accessed
|
/// The current style. Note that only "eager" properties should be accessed
|
||||||
/// from here, see the comment in the member.
|
/// from here, see the comment in the member.
|
||||||
pub fn style(&self) -> &StyleBuilder { &self.style }
|
pub fn style(&self) -> &StyleBuilder { &self.style }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue