Remove shareable boolean from ComputedValues and simplify code.

This code is all vestigial at this point, presumably after a refactoring.

MozReview-Commit-ID: CV0lKMStq13
This commit is contained in:
Bobby Holley 2017-04-05 18:30:46 -07:00
parent f9de1dedd8
commit 42f5aea76a
4 changed files with 14 additions and 52 deletions

View file

@ -15,7 +15,7 @@ use cascade_info::CascadeInfo;
use context::{SequentialTask, SharedStyleContext, StyleContext}; use context::{SequentialTask, SharedStyleContext, StyleContext};
use data::{ComputedStyle, ElementData, ElementStyles, RestyleData}; use data::{ComputedStyle, ElementData, ElementStyles, RestyleData};
use dom::{AnimationRules, SendElement, TElement, TNode}; use dom::{AnimationRules, SendElement, TElement, TNode};
use properties::{CascadeFlags, ComputedValues, SHAREABLE, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, cascade}; use properties::{CascadeFlags, ComputedValues, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP, cascade};
use properties::longhands::display::computed_value as display; use properties::longhands::display::computed_value as display;
use restyle_hints::{RESTYLE_STYLE_ATTRIBUTE, RESTYLE_CSS_ANIMATIONS, RestyleHint}; use restyle_hints::{RESTYLE_STYLE_ATTRIBUTE, RESTYLE_CSS_ANIMATIONS, RestyleHint};
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode}; use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode};
@ -430,15 +430,6 @@ pub enum StyleSharingResult {
StyleWasShared(usize), StyleWasShared(usize),
} }
/// Callers need to pass several boolean flags to cascade_primary_or_pseudo.
/// We encapsulate them in this struct to avoid mixing them up.
///
/// FIXME(pcwalton): Unify with `CascadeFlags`, perhaps?
struct CascadeBooleans {
shareable: bool,
animate: bool,
}
trait PrivateMatchMethods: TElement { trait PrivateMatchMethods: TElement {
/// Returns the closest parent element that doesn't have a display: contents /// Returns the closest parent element that doesn't have a display: contents
/// style (and thus generates a box). /// style (and thus generates a box).
@ -543,13 +534,9 @@ trait PrivateMatchMethods: TElement {
fn cascade_internal(&self, fn cascade_internal(&self,
context: &StyleContext<Self>, context: &StyleContext<Self>,
primary_style: &ComputedStyle, primary_style: &ComputedStyle,
pseudo_style: &Option<(&PseudoElement, &mut ComputedStyle)>, pseudo_style: &Option<(&PseudoElement, &mut ComputedStyle)>)
booleans: &CascadeBooleans)
-> Arc<ComputedValues> { -> Arc<ComputedValues> {
let mut cascade_flags = CascadeFlags::empty(); let mut cascade_flags = CascadeFlags::empty();
if booleans.shareable {
cascade_flags.insert(SHAREABLE)
}
if self.skip_root_and_item_based_display_fixup() { if self.skip_root_and_item_based_display_fixup() {
cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP)
} }
@ -566,7 +553,7 @@ trait PrivateMatchMethods: TElement {
data: &mut ElementData, data: &mut ElementData,
pseudo: Option<&PseudoElement>, pseudo: Option<&PseudoElement>,
possibly_expired_animations: &mut Vec<PropertyAnimation>, possibly_expired_animations: &mut Vec<PropertyAnimation>,
booleans: CascadeBooleans) { animate: bool) {
// Collect some values. // Collect some values.
let (mut styles, restyle) = data.styles_and_restyle_mut(); let (mut styles, restyle) = data.styles_and_restyle_mut();
let mut primary_style = &mut styles.primary; let mut primary_style = &mut styles.primary;
@ -577,10 +564,10 @@ trait PrivateMatchMethods: TElement {
// Compute the new values. // Compute the new values.
let mut new_values = self.cascade_internal(context, primary_style, let mut new_values = self.cascade_internal(context, primary_style,
&pseudo_style, &booleans); &pseudo_style);
// Handle animations. // Handle animations.
if booleans.animate { if animate {
self.process_animations(context, self.process_animations(context,
&mut old_values, &mut old_values,
&mut new_values, &mut new_values,
@ -1177,18 +1164,14 @@ pub trait MatchMethods : TElement {
/// starting any new transitions or animations. /// starting any new transitions or animations.
fn cascade_element(&self, fn cascade_element(&self,
context: &mut StyleContext<Self>, context: &mut StyleContext<Self>,
mut data: &mut AtomicRefMut<ElementData>, mut data: &mut AtomicRefMut<ElementData>)
primary_is_shareable: bool)
{ {
let mut possibly_expired_animations = vec![]; let mut possibly_expired_animations = vec![];
// Cascade the primary style. // Cascade the primary style.
self.cascade_primary_or_pseudo(context, data, None, self.cascade_primary_or_pseudo(context, data, None,
&mut possibly_expired_animations, &mut possibly_expired_animations,
CascadeBooleans { /* animate = */ true);
shareable: primary_is_shareable,
animate: true,
});
// Check whether the primary style is display:none. // Check whether the primary style is display:none.
let display_none = data.styles().primary.values().get_box().clone_display() == let display_none = data.styles().primary.values().get_box().clone_display() ==
@ -1214,10 +1197,7 @@ pub trait MatchMethods : TElement {
let animate = pseudo.is_before_or_after(); let animate = pseudo.is_before_or_after();
self.cascade_primary_or_pseudo(context, data, Some(&pseudo), self.cascade_primary_or_pseudo(context, data, Some(&pseudo),
&mut possibly_expired_animations, &mut possibly_expired_animations,
CascadeBooleans { animate);
shareable: false,
animate: animate,
});
} }
} }

View file

@ -77,7 +77,6 @@ pub struct ComputedValues {
% endfor % endfor
custom_properties: Option<Arc<ComputedValuesMap>>, custom_properties: Option<Arc<ComputedValuesMap>>,
shareable: bool,
pub writing_mode: WritingMode, pub writing_mode: WritingMode,
pub root_font_size: Au, pub root_font_size: Au,
pub font_size_keyword: Option<longhands::font_size::KeywordSize>, pub font_size_keyword: Option<longhands::font_size::KeywordSize>,
@ -87,7 +86,6 @@ impl ComputedValues {
pub fn inherit_from(parent: &Self, default: &Self) -> Arc<Self> { pub fn inherit_from(parent: &Self, default: &Self) -> Arc<Self> {
Arc::new(ComputedValues { Arc::new(ComputedValues {
custom_properties: parent.custom_properties.clone(), custom_properties: parent.custom_properties.clone(),
shareable: parent.shareable,
writing_mode: parent.writing_mode, writing_mode: parent.writing_mode,
root_font_size: parent.root_font_size, root_font_size: parent.root_font_size,
font_size_keyword: parent.font_size_keyword, font_size_keyword: parent.font_size_keyword,
@ -102,7 +100,6 @@ impl ComputedValues {
} }
pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>, pub fn new(custom_properties: Option<Arc<ComputedValuesMap>>,
shareable: bool,
writing_mode: WritingMode, writing_mode: WritingMode,
root_font_size: Au, root_font_size: Au,
font_size_keyword: Option<longhands::font_size::KeywordSize>, font_size_keyword: Option<longhands::font_size::KeywordSize>,
@ -112,7 +109,6 @@ impl ComputedValues {
) -> Self { ) -> Self {
ComputedValues { ComputedValues {
custom_properties: custom_properties, custom_properties: custom_properties,
shareable: shareable,
writing_mode: writing_mode, writing_mode: writing_mode,
root_font_size: root_font_size, root_font_size: root_font_size,
font_size_keyword: font_size_keyword, font_size_keyword: font_size_keyword,
@ -125,7 +121,6 @@ impl ComputedValues {
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> { pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues { Arc::new(ComputedValues {
custom_properties: None, custom_properties: None,
shareable: true,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious? root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
font_size_keyword: Some(Default::default()), font_size_keyword: Some(Default::default()),

View file

@ -1542,7 +1542,6 @@ pub struct ComputedValues {
${style_struct.ident}: Arc<style_structs::${style_struct.name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool,
/// 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 root element's computed font size. /// The root element's computed font size.
@ -1555,7 +1554,6 @@ pub struct ComputedValues {
impl ComputedValues { impl ComputedValues {
/// Construct a `ComputedValues` instance. /// Construct a `ComputedValues` instance.
pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>, pub fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool,
writing_mode: WritingMode, writing_mode: WritingMode,
root_font_size: Au, root_font_size: Au,
font_size_keyword: Option<longhands::font_size::KeywordSize>, font_size_keyword: Option<longhands::font_size::KeywordSize>,
@ -1565,7 +1563,6 @@ impl ComputedValues {
) -> Self { ) -> Self {
ComputedValues { ComputedValues {
custom_properties: custom_properties, custom_properties: custom_properties,
shareable: shareable,
writing_mode: writing_mode, writing_mode: writing_mode,
root_font_size: root_font_size, root_font_size: root_font_size,
font_size_keyword: font_size_keyword, font_size_keyword: font_size_keyword,
@ -1889,7 +1886,6 @@ mod lazy_static_module {
}), }),
% endfor % endfor
custom_properties: None, custom_properties: None,
shareable: true,
writing_mode: WritingMode::empty(), writing_mode: WritingMode::empty(),
root_font_size: longhands::font_size::get_initial_value(), root_font_size: longhands::font_size::get_initial_value(),
font_size_keyword: Some(Default::default()), font_size_keyword: Some(Default::default()),
@ -1918,15 +1914,12 @@ static CASCADE_PROPERTY: [CascadePropertyFn; ${len(data.longhands)}] = [
bitflags! { bitflags! {
/// A set of flags to tweak the behavior of the `cascade` function. /// A set of flags to tweak the behavior of the `cascade` function.
pub flags CascadeFlags: u8 { pub flags CascadeFlags: u8 {
/// Whether the `ComputedValues` structure to be constructed should be
/// considered shareable.
const SHAREABLE = 0x01,
/// Whether to inherit all styles from the parent. If this flag is not /// Whether to inherit all styles from the parent. If this flag is not
/// present, non-inherited styles are reset to their initial values. /// present, non-inherited styles are reset to their initial values.
const INHERIT_ALL = 0x02, const INHERIT_ALL = 0x01,
/// Whether to skip any root element and flex/grid item display style /// Whether to skip any root element and flex/grid item display style
/// fixup. /// fixup.
const SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP = 0x04, const SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP = 0x02,
} }
} }
@ -2033,7 +2026,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
let starting_style = if !flags.contains(INHERIT_ALL) { let starting_style = if !flags.contains(INHERIT_ALL) {
ComputedValues::new(custom_properties, ComputedValues::new(custom_properties,
flags.contains(SHAREABLE),
WritingMode::empty(), WritingMode::empty(),
inherited_style.root_font_size, inherited_style.root_font_size,
inherited_style.font_size_keyword, inherited_style.font_size_keyword,
@ -2047,7 +2039,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
) )
} else { } else {
ComputedValues::new(custom_properties, ComputedValues::new(custom_properties,
flags.contains(SHAREABLE),
WritingMode::empty(), WritingMode::empty(),
inherited_style.root_font_size, inherited_style.root_font_size,
inherited_style.font_size_keyword, inherited_style.font_size_keyword,

View file

@ -395,9 +395,8 @@ fn resolve_style_internal<E, F>(context: &mut StyleContext<E>,
} }
// Compute our style. // Compute our style.
let match_results = element.match_element(context, &mut data); element.match_element(context, &mut data);
element.cascade_element(context, &mut data, element.cascade_element(context, &mut data);
match_results.primary_is_shareable());
// Conservatively mark us as having dirty descendants, since there might // Conservatively mark us as having dirty descendants, since there might
// be other unstyled siblings we miss when walking straight up the parent // be other unstyled siblings we miss when walking straight up the parent
@ -625,13 +624,10 @@ fn compute_style<E, D>(_traversal: &D,
}; };
// Cascade properties and compute values. // Cascade properties and compute values.
let shareable = match_results.primary_is_shareable(); element.cascade_element(context, &mut data);
unsafe {
element.cascade_element(context, &mut data, shareable);
}
// If the style is shareable, add it to the LRU cache. // If the style is shareable, add it to the LRU cache.
if shareable { if match_results.primary_is_shareable() {
context.thread_local context.thread_local
.style_sharing_candidate_cache .style_sharing_candidate_cache
.insert_if_possible(&element, .insert_if_possible(&element,