Skip to content

Commit

Permalink
Bug 1870676 - Move a bunch of code in properties.mako.rs outside of m…
Browse files Browse the repository at this point in the history
…ako. r=firefox-style-system-reviewers,zrhoffman

Most of these bits don't need mako. Move them to properties/mod.rs.

Differential Revision: https://phabricator.services.mozilla.com/D196758
  • Loading branch information
emilio committed Dec 19, 2023
1 parent 3387523 commit 933d556
Show file tree
Hide file tree
Showing 9 changed files with 1,682 additions and 1,654 deletions.
4 changes: 1 addition & 3 deletions servo/components/style/gecko/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,16 +935,14 @@ fn get_animation_rule(
element: &GeckoElement,
cascade_level: CascadeLevel,
) -> Option<Arc<Locked<PropertyDeclarationBlock>>> {
use crate::properties::longhands::ANIMATABLE_PROPERTY_COUNT;

// There's a very rough correlation between the number of effects
// (animations) on an element and the number of properties it is likely to
// animate, so we use that as an initial guess for the size of the
// AnimationValueMap in order to reduce the number of re-allocations needed.
let effect_count = unsafe { Gecko_GetAnimationEffectCount(element.0) };
// Also, we should try to reuse the PDB, to avoid creating extra rule nodes.
let mut animation_values = AnimationValueMap::with_capacity_and_hasher(
effect_count.min(ANIMATABLE_PROPERTY_COUNT),
effect_count.min(crate::properties::property_counts::ANIMATABLE),
Default::default(),
);
if unsafe { Gecko_GetAnimationRule(element.0, cascade_level, &mut animation_values) } {
Expand Down
12 changes: 4 additions & 8 deletions servo/components/style/properties/cascade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ use crate::dom::TElement;
use crate::font_metrics::FontMetricsOrientation;
use crate::logical_geometry::WritingMode;
use crate::properties::{
declaration_block::{DeclarationImportanceIterator, Importance},
generated::{
CSSWideKeyword, ComputedValues, LonghandId, LonghandIdSet, PrioritaryPropertyId,
PropertyDeclaration, PropertyFlags, ShorthandsWithPropertyReferencesCache, StyleBuilder,
CASCADE_PROPERTY, PRIORITARY_PROPERTY_COUNT,
},
property_declaration::PropertyDeclarationId,
property_counts, CSSWideKeyword, ComputedValues, DeclarationImportanceIterator, Importance,
LonghandId, LonghandIdSet, PrioritaryPropertyId, PropertyDeclaration, PropertyDeclarationId,
PropertyFlags, ShorthandsWithPropertyReferencesCache, StyleBuilder, CASCADE_PROPERTY,
};
use crate::rule_cache::{RuleCache, RuleCacheConditions};
use crate::rule_tree::{CascadeLevel, StrongRuleNode};
Expand Down Expand Up @@ -560,7 +556,7 @@ struct Declarations<'a> {
/// A list of all the applicable longhand declarations.
longhand_declarations: SmallVec<[Declaration<'a>; 32]>,
/// The prioritary property position data.
prioritary_positions: [PrioritaryDeclarationPosition; PRIORITARY_PROPERTY_COUNT],
prioritary_positions: [PrioritaryDeclarationPosition; property_counts::PRIORITARY],
}

impl<'a> Declarations<'a> {
Expand Down
70 changes: 70 additions & 0 deletions servo/components/style/properties/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,70 @@
SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_stretch font_weight""".split()

PRIORITARY_PROPERTIES = set(
[
# The writing-mode group has the most priority of all property groups, as
# sizes like font-size can depend on it.
"writing-mode",
"direction",
"text-orientation",
# The fonts and colors group has the second priority, as all other lengths
# and colors depend on them.
#
# There are some interdependencies between these, but we fix them up in
# Cascade::fixup_font_stuff.
# Needed to properly compute the zoomed font-size.
"-x-text-scale",
# Needed to do font-size computation in a language-dependent way.
"-x-lang",
# Needed for ruby to respect language-dependent min-font-size
# preferences properly, see bug 1165538.
"-moz-min-font-size-ratio",
# font-size depends on math-depth's computed value.
"math-depth",
# Needed to compute the first available font and its used size,
# in order to compute font-relative units correctly.
"font-size",
"font-size-adjust",
"font-weight",
"font-stretch",
"font-style",
"font-family",
# color-scheme affects how system colors resolve.
"color-scheme",
# forced-color-adjust affects whether colors are adjusted.
"forced-color-adjust",
# Zoom affects all absolute lengths.
"zoom",
# Line height lengths depend on this.
"line-height",
]
)

VISITED_DEPENDENT_PROPERTIES = set(
[
"column-rule-color",
"text-emphasis-color",
"-webkit-text-fill-color",
"-webkit-text-stroke-color",
"text-decoration-color",
"fill",
"stroke",
"caret-color",
"background-color",
"border-top-color",
"border-right-color",
"border-bottom-color",
"border-left-color",
"border-block-start-color",
"border-inline-end-color",
"border-block-end-color",
"border-inline-start-color",
"outline-color",
"color",
]
)

# Bitfield values for all rule types which can have property declarations.
STYLE_RULE = 1 << 0
PAGE_RULE = 1 << 1
Expand Down Expand Up @@ -281,6 +345,12 @@ def explicitly_enabled_in_chrome(self):
def enabled_in_content(self):
return self.enabled_in == "content"

def is_visited_dependent(self):
return self.name in VISITED_DEPENDENT_PROPERTIES

def is_prioritary(self):
return self.name in PRIORITARY_PROPERTIES

def nscsspropertyid(self):
return "nsCSSPropertyID::eCSSProperty_" + self.ident

Expand Down
20 changes: 8 additions & 12 deletions servo/components/style/properties/declaration_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#![deny(missing_docs)]

use super::generated::{
shorthands, AllShorthand, ComputedValues, LogicalGroupSet, LonghandIdSet,
NonCustomPropertyIdSet, PropertyDeclaration, PropertyId, ShorthandId,
SourcePropertyDeclaration, SourcePropertyDeclarationDrain, SubpropertiesVec,
use super::{
property_counts, AllShorthand, ComputedValues, LogicalGroupSet, LonghandIdSet,
LonghandIdSetIterator, NonCustomPropertyIdSet, PropertyDeclaration, PropertyDeclarationId,
PropertyId, ShorthandId, SourcePropertyDeclaration, SourcePropertyDeclarationDrain,
SubpropertiesVec,
};
use super::property_declaration::PropertyDeclarationId;
use super::LonghandIdSetIterator;
use crate::context::QuirksMode;
use crate::custom_properties;
use crate::error_reporting::{ContextualParseError, ParseErrorReporter};
Expand Down Expand Up @@ -332,11 +331,8 @@ impl<'a, 'cx, 'cx_a: 'cx> Iterator for AnimationValueIterator<'a, 'cx, 'cx_a> {
continue;
}

let animation = AnimationValue::from_declaration(
decl,
&mut self.context,
self.default_values,
);
let animation =
AnimationValue::from_declaration(decl, &mut self.context, self.default_values);

if let Some(anim) = animation {
return Some(anim);
Expand Down Expand Up @@ -584,7 +580,7 @@ impl PropertyDeclarationBlock {
let all_shorthand_len = match drain.all_shorthand {
AllShorthand::NotSet => 0,
AllShorthand::CSSWideKeyword(_) | AllShorthand::WithVariables(_) => {
shorthands::ALL_SHORTHAND_MAX_LEN
property_counts::ALL_SHORTHAND_EXPANDED
},
};
let push_calls_count = drain.declarations.len() + all_shorthand_len;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::ptr;
use std::mem;
use fxhash::FxHashMap;
use super::ComputedValues;
use crate::properties::property_declaration::OwnedPropertyDeclarationId;
use crate::properties::OwnedPropertyDeclarationId;
use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero};
use crate::values::animated::effects::AnimatedFilter;
#[cfg(feature = "gecko")] use crate::values::computed::TransitionProperty;
Expand Down
Loading

0 comments on commit 933d556

Please sign in to comment.