mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Move a bit declaration_block and cascade modules
So that they aren't imported via #[path]. This allows cargo to see them even before building. Differential Revision: https://phabricator.services.mozilla.com/D178105
This commit is contained in:
parent
9c58f0c635
commit
ae993e485a
5 changed files with 90 additions and 64 deletions
|
@ -163,14 +163,7 @@ pub use style_traits::owned_str::OwnedStr;
|
|||
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
|
||||
/// The CSS properties supported by the style system.
|
||||
/// Generated from the properties.mako.rs template by build.rs
|
||||
#[macro_use]
|
||||
#[allow(unsafe_code)]
|
||||
#[deny(missing_docs)]
|
||||
pub mod properties {
|
||||
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
|
||||
}
|
||||
pub mod properties;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -181,12 +174,6 @@ pub mod gecko;
|
|||
#[allow(unsafe_code)]
|
||||
pub mod servo;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[allow(unsafe_code, missing_docs)]
|
||||
pub mod gecko_properties {
|
||||
include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs"));
|
||||
}
|
||||
|
||||
macro_rules! reexport_computed_values {
|
||||
( $( { $name: ident } )+ ) => {
|
||||
/// Types for [computed values][computed].
|
||||
|
|
|
@ -6,23 +6,26 @@
|
|||
|
||||
use crate::applicable_declarations::CascadePriority;
|
||||
use crate::color::AbsoluteColor;
|
||||
use crate::computed_value_flags::ComputedValueFlags;
|
||||
use crate::context::QuirksMode;
|
||||
use crate::custom_properties::CustomPropertiesBuilder;
|
||||
use crate::dom::TElement;
|
||||
use crate::logical_geometry::WritingMode;
|
||||
use crate::media_queries::Device;
|
||||
use crate::properties::{
|
||||
CSSWideKeyword, ComputedValueFlags, ComputedValues, DeclarationImportanceIterator, Importance,
|
||||
LonghandId, LonghandIdSet, PropertyDeclaration, PropertyDeclarationId, PropertyFlags,
|
||||
ShorthandsWithPropertyReferencesCache, StyleBuilder, CASCADE_PROPERTY,
|
||||
use crate::properties::declaration_block::{DeclarationImportanceIterator, Importance};
|
||||
use crate::properties::generated::{
|
||||
CSSWideKeyword, ComputedValues, LonghandId, LonghandIdSet, PropertyDeclaration,
|
||||
PropertyDeclarationId, PropertyFlags, ShorthandsWithPropertyReferencesCache, StyleBuilder,
|
||||
CASCADE_PROPERTY,
|
||||
};
|
||||
use crate::rule_cache::{RuleCache, RuleCacheConditions};
|
||||
use crate::rule_tree::{StrongRuleNode, CascadeLevel};
|
||||
use crate::rule_tree::{CascadeLevel, StrongRuleNode};
|
||||
use crate::selector_parser::PseudoElement;
|
||||
use crate::shared_lock::StylesheetGuards;
|
||||
use crate::style_adjuster::StyleAdjuster;
|
||||
use crate::stylesheets::{Origin, layer_rule::LayerOrder};
|
||||
use crate::stylesheets::container_rule::ContainerSizeQuery;
|
||||
use crate::stylesheets::{layer_rule::LayerOrder, Origin};
|
||||
use crate::values::specified::length::FontBaseSize;
|
||||
use crate::values::{computed, specified};
|
||||
use fxhash::FxHashMap;
|
||||
use servo_arc::Arc;
|
||||
|
@ -596,7 +599,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
declaration.value.substitute_variables(
|
||||
declaration.id,
|
||||
self.context.builder.writing_mode,
|
||||
self.context.builder.custom_properties.as_ref(),
|
||||
self.context.builder.custom_properties(),
|
||||
self.context.quirks_mode,
|
||||
self.context.device(),
|
||||
cache,
|
||||
|
@ -961,14 +964,16 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
};
|
||||
|
||||
let font = builder.mutate_font();
|
||||
font.mFont.family.families.prioritize_first_generic_or_prepend(default_font_type);
|
||||
font.mFont
|
||||
.family
|
||||
.families
|
||||
.prioritize_first_generic_or_prepend(default_font_type);
|
||||
}
|
||||
|
||||
/// Some keyword sizes depend on the font family and language.
|
||||
#[cfg(feature = "gecko")]
|
||||
fn recompute_keyword_font_size_if_needed(&mut self) {
|
||||
use crate::values::computed::ToComputedValue;
|
||||
use crate::values::specified;
|
||||
|
||||
if !self.seen.contains(LonghandId::XLang) && !self.seen.contains(LonghandId::FontFamily) {
|
||||
return;
|
||||
|
@ -1080,7 +1085,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
return;
|
||||
}
|
||||
|
||||
const SCALE_FACTOR_WHEN_INCREMENTING_MATH_DEPTH_BY_ONE : f32 = 0.71;
|
||||
const SCALE_FACTOR_WHEN_INCREMENTING_MATH_DEPTH_BY_ONE: f32 = 0.71;
|
||||
|
||||
// Helper function that calculates the scale factor applied to font-size
|
||||
// when math-depth goes from parent_math_depth to computed_math_depth.
|
||||
|
@ -1163,7 +1168,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
|
|||
parent_font.mMathDepth as i32,
|
||||
font.mMathDepth as i32,
|
||||
font_metrics.script_percent_scale_down,
|
||||
font_metrics.script_script_percent_scale_down
|
||||
font_metrics.script_script_percent_scale_down,
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
@ -6,11 +6,16 @@
|
|||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use super::*;
|
||||
use super::generated::{
|
||||
shorthands, AllShorthand, ComputedValues, LogicalGroupSet, LonghandIdSet,
|
||||
NonCustomPropertyIdSet, PropertyDeclaration, PropertyDeclarationId, PropertyId, ShorthandId,
|
||||
SourcePropertyDeclaration, SourcePropertyDeclarationDrain, SubpropertiesVec,
|
||||
};
|
||||
use crate::applicable_declarations::CascadePriority;
|
||||
use crate::context::QuirksMode;
|
||||
use crate::custom_properties::{self, CustomPropertiesBuilder};
|
||||
use crate::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use crate::media_queries::Device;
|
||||
use crate::parser::ParserContext;
|
||||
use crate::properties::animated_properties::{AnimationValue, AnimationValueMap};
|
||||
use crate::rule_tree::CascadeLevel;
|
||||
|
@ -26,6 +31,7 @@ use cssparser::{
|
|||
};
|
||||
use itertools::Itertools;
|
||||
use selectors::SelectorList;
|
||||
use servo_arc::Arc;
|
||||
use smallbitvec::{self, SmallBitVec};
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt::{self, Write};
|
||||
|
|
27
components/style/properties/mod.rs
Normal file
27
components/style/properties/mod.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Supported CSS properties and the cascade.
|
||||
|
||||
pub mod declaration_block;
|
||||
pub mod cascade;
|
||||
|
||||
/// The CSS properties supported by the style system.
|
||||
/// Generated from the properties.mako.rs template by build.rs
|
||||
#[macro_use]
|
||||
#[allow(unsafe_code)]
|
||||
#[deny(missing_docs)]
|
||||
pub mod generated {
|
||||
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[allow(unsafe_code, missing_docs)]
|
||||
pub mod gecko {
|
||||
include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs"));
|
||||
}
|
||||
}
|
||||
|
||||
pub use self::cascade::*;
|
||||
pub use self::declaration_block::*;
|
||||
pub use self::generated::*;
|
|
@ -48,9 +48,7 @@ use crate::rule_tree::StrongRuleNode;
|
|||
use crate::Zero;
|
||||
use crate::str::{CssString, CssStringWriter};
|
||||
use std::cell::Cell;
|
||||
|
||||
pub use self::declaration_block::*;
|
||||
pub use self::cascade::*;
|
||||
use super::declaration_block::AppendableValue;
|
||||
|
||||
<%!
|
||||
from collections import defaultdict
|
||||
|
@ -59,11 +57,6 @@ pub use self::cascade::*;
|
|||
import os.path
|
||||
%>
|
||||
|
||||
#[path="${repr(os.path.join(os.path.dirname(__file__), 'declaration_block.rs'))[1:-1]}"]
|
||||
pub mod declaration_block;
|
||||
#[path="${repr(os.path.join(os.path.dirname(__file__), 'cascade.rs'))[1:-1]}"]
|
||||
pub mod cascade;
|
||||
|
||||
/// Conversion with fewer impls than From/Into
|
||||
pub trait MaybeBoxed<Out> {
|
||||
/// Convert
|
||||
|
@ -428,7 +421,7 @@ impl PropertyDeclaration {
|
|||
|
||||
/// Returns the color value of a given property, for high-contrast-mode
|
||||
/// tweaks.
|
||||
pub(crate) fn color_value(&self) -> Option<<&crate::values::specified::Color> {
|
||||
pub(super) fn color_value(&self) -> Option<<&crate::values::specified::Color> {
|
||||
${static_longhand_id_set("COLOR_PROPERTIES", lambda p: p.predefined_type == "Color")}
|
||||
<%
|
||||
# sanity check
|
||||
|
@ -1009,7 +1002,7 @@ impl LonghandIdSet {
|
|||
/// Only a few properties are allowed to depend on the visited state of
|
||||
/// links. When cascading visited styles, we can save time by only
|
||||
/// processing these properties.
|
||||
fn visited_dependent() -> &'static Self {
|
||||
pub(super) fn visited_dependent() -> &'static Self {
|
||||
${static_longhand_id_set(
|
||||
"VISITED_DEPENDENT",
|
||||
lambda p: is_visited_dependent(p)
|
||||
|
@ -1019,7 +1012,7 @@ impl LonghandIdSet {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn writing_mode_group() -> &'static Self {
|
||||
pub(super) fn writing_mode_group() -> &'static Self {
|
||||
${static_longhand_id_set(
|
||||
"WRITING_MODE_GROUP",
|
||||
lambda p: p.name in CASCADE_GROUPS["writing_mode"]
|
||||
|
@ -1028,7 +1021,7 @@ impl LonghandIdSet {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn fonts_and_color_group() -> &'static Self {
|
||||
pub(super) fn fonts_and_color_group() -> &'static Self {
|
||||
${static_longhand_id_set(
|
||||
"FONTS_AND_COLOR_GROUP",
|
||||
lambda p: p.name in CASCADE_GROUPS["fonts_and_color"]
|
||||
|
@ -1037,13 +1030,13 @@ impl LonghandIdSet {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn late_group_only_inherited() -> &'static Self {
|
||||
pub(super) fn late_group_only_inherited() -> &'static Self {
|
||||
${static_longhand_id_set("LATE_GROUP_ONLY_INHERITED", lambda p: p.style_struct.inherited and in_late_group(p))}
|
||||
&LATE_GROUP_ONLY_INHERITED
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn late_group() -> &'static Self {
|
||||
pub(super) fn late_group() -> &'static Self {
|
||||
${static_longhand_id_set("LATE_GROUP", lambda p: in_late_group(p))}
|
||||
&LATE_GROUP
|
||||
}
|
||||
|
@ -1276,7 +1269,8 @@ impl LonghandId {
|
|||
!LonghandIdSet::reset().contains(self)
|
||||
}
|
||||
|
||||
fn shorthands(&self) -> NonCustomPropertyIterator<ShorthandId> {
|
||||
/// Returns an iterator over all the shorthands that include this longhand.
|
||||
pub fn shorthands(&self) -> NonCustomPropertyIterator<ShorthandId> {
|
||||
// first generate longhand to shorthands lookup map
|
||||
//
|
||||
// NOTE(emilio): This currently doesn't exclude the "all" shorthand. It
|
||||
|
@ -1451,7 +1445,7 @@ impl LonghandId {
|
|||
/// Returns true if the property is one that is ignored when document
|
||||
/// colors are disabled.
|
||||
#[inline]
|
||||
fn ignored_when_document_colors_disabled(self) -> bool {
|
||||
pub fn ignored_when_document_colors_disabled(self) -> bool {
|
||||
LonghandIdSet::ignored_when_colors_disabled().contains(self)
|
||||
}
|
||||
}
|
||||
|
@ -1720,7 +1714,7 @@ pub type ShorthandsWithPropertyReferencesCache =
|
|||
FxHashMap<(ShorthandId, LonghandId), PropertyDeclaration>;
|
||||
|
||||
impl UnparsedValue {
|
||||
fn substitute_variables<'cache>(
|
||||
pub(super) fn substitute_variables<'cache>(
|
||||
&self,
|
||||
longhand_id: LonghandId,
|
||||
writing_mode: WritingMode,
|
||||
|
@ -2242,10 +2236,12 @@ pub struct WideKeywordDeclaration {
|
|||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||
#[derive(Clone, PartialEq, ToCss, ToShmem)]
|
||||
pub struct VariableDeclaration {
|
||||
/// The id of the property this declaration represents.
|
||||
#[css(skip)]
|
||||
id: LonghandId,
|
||||
pub id: LonghandId,
|
||||
/// The unparsed value of the variable.
|
||||
#[cfg_attr(feature = "gecko", ignore_malloc_size_of = "XXX: how to handle this?")]
|
||||
value: Arc<UnparsedValue>,
|
||||
pub value: Arc<UnparsedValue>,
|
||||
}
|
||||
|
||||
/// A custom property declaration value is either an unparsed value or a CSS
|
||||
|
@ -2603,16 +2599,17 @@ const SUB_PROPERTIES_ARRAY_CAP: usize =
|
|||
${max(len(s.sub_properties) for s in data.shorthands_except_all()) \
|
||||
if data.shorthands_except_all() else 0};
|
||||
|
||||
type SubpropertiesVec<T> = ArrayVec<T, SUB_PROPERTIES_ARRAY_CAP>;
|
||||
/// An ArrayVec of subproperties, contains space for the longest shorthand except all.
|
||||
pub type SubpropertiesVec<T> = ArrayVec<T, SUB_PROPERTIES_ARRAY_CAP>;
|
||||
|
||||
/// A stack-allocated vector of `PropertyDeclaration`
|
||||
/// large enough to parse one CSS `key: value` declaration.
|
||||
/// (Shorthands expand to multiple `PropertyDeclaration`s.)
|
||||
pub struct SourcePropertyDeclaration {
|
||||
declarations: SubpropertiesVec<PropertyDeclaration>,
|
||||
|
||||
/// The storage for the actual declarations (except for all).
|
||||
pub declarations: SubpropertiesVec<PropertyDeclaration>,
|
||||
/// Stored separately to keep SubpropertiesVec smaller.
|
||||
all_shorthand: AllShorthand,
|
||||
pub all_shorthand: AllShorthand,
|
||||
}
|
||||
|
||||
// This is huge, but we allocate it on the stack and then never move it,
|
||||
|
@ -2663,20 +2660,26 @@ impl SourcePropertyDeclaration {
|
|||
|
||||
/// Return type of SourcePropertyDeclaration::drain
|
||||
pub struct SourcePropertyDeclarationDrain<'a> {
|
||||
declarations: ArrayVecDrain<'a, PropertyDeclaration, SUB_PROPERTIES_ARRAY_CAP>,
|
||||
all_shorthand: AllShorthand,
|
||||
/// A drain over the non-all declarations.
|
||||
pub declarations: ArrayVecDrain<'a, PropertyDeclaration, SUB_PROPERTIES_ARRAY_CAP>,
|
||||
/// The all shorthand that was set.
|
||||
pub all_shorthand: AllShorthand,
|
||||
}
|
||||
|
||||
enum AllShorthand {
|
||||
/// A parsed all-shorthand value.
|
||||
pub enum AllShorthand {
|
||||
/// Not present.
|
||||
NotSet,
|
||||
/// A CSS-wide keyword.
|
||||
CSSWideKeyword(CSSWideKeyword),
|
||||
/// An all shorthand with var() references that we can't resolve right now.
|
||||
WithVariables(Arc<UnparsedValue>)
|
||||
}
|
||||
|
||||
impl AllShorthand {
|
||||
/// Iterates property declarations from the given all shorthand value.
|
||||
#[inline]
|
||||
fn declarations(&self) -> AllShorthandDeclarationIterator {
|
||||
pub fn declarations(&self) -> AllShorthandDeclarationIterator {
|
||||
AllShorthandDeclarationIterator {
|
||||
all_shorthand: self,
|
||||
longhands: ShorthandId::All.longhands(),
|
||||
|
@ -2684,7 +2687,8 @@ impl AllShorthand {
|
|||
}
|
||||
}
|
||||
|
||||
struct AllShorthandDeclarationIterator<'a> {
|
||||
/// An iterator over the all shorthand's shorthand declarations.
|
||||
pub struct AllShorthandDeclarationIterator<'a> {
|
||||
all_shorthand: &'a AllShorthand,
|
||||
longhands: NonCustomPropertyIterator<LonghandId>,
|
||||
}
|
||||
|
@ -2712,7 +2716,7 @@ impl<'a> Iterator for AllShorthandDeclarationIterator<'a> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use crate::gecko_properties::style_structs;
|
||||
pub use super::gecko::style_structs;
|
||||
|
||||
/// The module where all the style structs are defined.
|
||||
#[cfg(feature = "servo")]
|
||||
|
@ -3026,7 +3030,7 @@ pub mod style_structs {
|
|||
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use crate::gecko_properties::{ComputedValues, ComputedValuesInner};
|
||||
pub use super::gecko::{ComputedValues, ComputedValuesInner};
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
|
||||
|
@ -3710,7 +3714,7 @@ pub struct StyleBuilder<'a> {
|
|||
/// The element's style if visited, only computed if there's a relevant link
|
||||
/// for this element. A element's "relevant link" is the element being
|
||||
/// matched if it is a link or the nearest ancestor link.
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
pub visited_style: Option<Arc<ComputedValues>>,
|
||||
% for style_struct in data.active_style_structs():
|
||||
${style_struct.ident}: StyleStructRef<'a, style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
|
@ -3718,7 +3722,7 @@ pub struct StyleBuilder<'a> {
|
|||
|
||||
impl<'a> StyleBuilder<'a> {
|
||||
/// Trivially construct a `StyleBuilder`.
|
||||
fn new(
|
||||
pub(super) fn new(
|
||||
device: &'a Device,
|
||||
parent_style: Option<<&'a ComputedValues>,
|
||||
parent_style_ignoring_first_line: Option<<&'a ComputedValues>,
|
||||
|
@ -4003,13 +4007,13 @@ impl<'a> StyleBuilder<'a> {
|
|||
}
|
||||
|
||||
/// Clears the "have any reset structs been modified" flag.
|
||||
fn clear_modified_reset(&mut self) {
|
||||
pub fn clear_modified_reset(&mut self) {
|
||||
self.modified_reset = false;
|
||||
}
|
||||
|
||||
/// Returns whether we have mutated any reset structs since the the last
|
||||
/// time `clear_modified_reset` was called.
|
||||
fn modified_reset(&self) -> bool {
|
||||
pub fn modified_reset(&self) -> bool {
|
||||
self.modified_reset
|
||||
}
|
||||
|
||||
|
@ -4049,10 +4053,7 @@ impl<'a> StyleBuilder<'a> {
|
|||
}
|
||||
|
||||
/// Get the custom properties map if necessary.
|
||||
///
|
||||
/// Cloning the Arc here is fine because it only happens in the case where
|
||||
/// we have custom properties, and those are both rare and expensive.
|
||||
fn custom_properties(&self) -> Option<<&Arc<crate::custom_properties::CustomPropertiesMap>> {
|
||||
pub fn custom_properties(&self) -> Option<<&Arc<crate::custom_properties::CustomPropertiesMap>> {
|
||||
self.custom_properties.as_ref()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue