mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Remove CascadeInfo.
This commit is contained in:
parent
6e9a96a6f8
commit
2291ce4767
7 changed files with 8 additions and 131 deletions
|
@ -502,7 +502,6 @@ fn compute_style_for_animation_step(context: &SharedStyleContext,
|
|||
Some(previous_style),
|
||||
Some(previous_style),
|
||||
Some(previous_style),
|
||||
/* cascade_info = */ None,
|
||||
/* visited_style = */ None,
|
||||
font_metrics_provider,
|
||||
CascadeFlags::empty(),
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! A structure to collect information about the cascade.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use dom::TNode;
|
||||
use properties::{DeclaredValue, PropertyDeclaration};
|
||||
use style_traits::HasViewportPercentage;
|
||||
|
||||
/// A structure to collect information about the cascade.
|
||||
///
|
||||
/// This is useful to gather information about what an element is affected by,
|
||||
/// and can be used in the future to track optimisations like when a
|
||||
/// non-inherited property is explicitly inherited, in order to cut-off the
|
||||
/// traversal.
|
||||
pub struct CascadeInfo {
|
||||
/// Whether we've seen viewport units so far.
|
||||
pub saw_viewport_units: bool,
|
||||
/// Whether the cascade has been marked as finished. This is a debug-only
|
||||
/// flag to ensure `finish` is called, given it's optional to not pass a
|
||||
/// `CascadeInfo`.
|
||||
#[cfg(debug_assertions)]
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
impl CascadeInfo {
|
||||
/// Construct a new `CascadeInfo`.
|
||||
#[cfg(debug_assertions)]
|
||||
pub fn new() -> Self {
|
||||
CascadeInfo {
|
||||
saw_viewport_units: false,
|
||||
finished: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Construct a new `CascadeInfo`.
|
||||
#[cfg(not(debug_assertions))]
|
||||
pub fn new() -> Self {
|
||||
CascadeInfo {
|
||||
saw_viewport_units: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when a property is cascaded.
|
||||
///
|
||||
/// NOTE: We can add a vast amount of information here.
|
||||
#[inline]
|
||||
pub fn on_cascade_property<T>(&mut self,
|
||||
_property_declaration: &PropertyDeclaration,
|
||||
value: &DeclaredValue<T>)
|
||||
where T: HasViewportPercentage,
|
||||
{
|
||||
// TODO: we can be smarter and keep a property bitfield to keep track of
|
||||
// the last applying rule.
|
||||
if value.has_viewport_percentage() {
|
||||
self.saw_viewport_units = true;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn mark_as_finished_if_appropriate(&mut self) {
|
||||
self.finished = true;
|
||||
}
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn mark_as_finished_if_appropriate(&mut self) {}
|
||||
|
||||
/// Called when the cascade is finished, in order to use the information
|
||||
/// we've collected.
|
||||
///
|
||||
/// Currently used for styling to mark a node as needing restyling when the
|
||||
/// viewport size changes.
|
||||
#[allow(unsafe_code)]
|
||||
pub fn finish<N: TNode>(mut self, node: &N) {
|
||||
self.mark_as_finished_if_appropriate();
|
||||
|
||||
if self.saw_viewport_units {
|
||||
unsafe {
|
||||
node.set_dirty_on_viewport_size_changed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
impl Drop for CascadeInfo {
|
||||
fn drop(&mut self) {
|
||||
debug_assert!(self.finished,
|
||||
"Didn't use the result of CascadeInfo, if you don't need \
|
||||
it, consider passing None");
|
||||
}
|
||||
}
|
|
@ -99,7 +99,6 @@ pub mod applicable_declarations;
|
|||
pub mod bezier;
|
||||
pub mod bloom;
|
||||
pub mod cache;
|
||||
pub mod cascade_info;
|
||||
pub mod context;
|
||||
pub mod counter_style;
|
||||
pub mod custom_properties;
|
||||
|
|
|
@ -275,8 +275,6 @@
|
|||
#[allow(unused_imports)]
|
||||
use values::{Auto, Either, None_, Normal};
|
||||
#[allow(unused_imports)]
|
||||
use cascade_info::CascadeInfo;
|
||||
#[allow(unused_imports)]
|
||||
use error_reporting::ParseErrorReporter;
|
||||
#[allow(unused_imports)]
|
||||
use properties::longhands;
|
||||
|
@ -303,7 +301,6 @@
|
|||
pub fn cascade_property(
|
||||
declaration: &PropertyDeclaration,
|
||||
context: &mut computed::Context,
|
||||
cascade_info: &mut Option<<&mut CascadeInfo>,
|
||||
) {
|
||||
let value = match *declaration {
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => {
|
||||
|
@ -320,9 +317,6 @@
|
|||
};
|
||||
|
||||
% if not property.derived_from:
|
||||
if let Some(ref mut cascade_info) = *cascade_info {
|
||||
cascade_info.on_cascade_property(&declaration, &value);
|
||||
}
|
||||
match value {
|
||||
DeclaredValue::Value(ref specified_value) => {
|
||||
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
|
||||
|
|
|
@ -43,7 +43,6 @@ use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraDat
|
|||
use values::generics::text::LineHeight;
|
||||
use values::computed;
|
||||
use values::computed::NonNegativeAu;
|
||||
use cascade_info::CascadeInfo;
|
||||
use rule_tree::{CascadeLevel, StrongRuleNode};
|
||||
use self::computed_value_flags::ComputedValueFlags;
|
||||
use style_adjuster::StyleAdjuster;
|
||||
|
@ -2953,9 +2952,10 @@ mod lazy_static_module {
|
|||
|
||||
/// A per-longhand function that performs the CSS cascade for that longhand.
|
||||
pub type CascadePropertyFn =
|
||||
extern "Rust" fn(declaration: &PropertyDeclaration,
|
||||
extern "Rust" fn(
|
||||
declaration: &PropertyDeclaration,
|
||||
context: &mut computed::Context,
|
||||
cascade_info: &mut Option<<&mut CascadeInfo>);
|
||||
);
|
||||
|
||||
/// A per-longhand array of functions to perform the CSS cascade on each of
|
||||
/// them, effectively doing virtual dispatch.
|
||||
|
@ -3030,7 +3030,6 @@ pub fn cascade(
|
|||
parent_style_ignoring_first_line: Option<<&ComputedValues>,
|
||||
layout_parent_style: Option<<&ComputedValues>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
cascade_info: Option<<&mut CascadeInfo>,
|
||||
font_metrics_provider: &FontMetricsProvider,
|
||||
flags: CascadeFlags,
|
||||
quirks_mode: QuirksMode
|
||||
|
@ -3089,7 +3088,6 @@ pub fn cascade(
|
|||
parent_style_ignoring_first_line,
|
||||
layout_parent_style,
|
||||
visited_style,
|
||||
cascade_info,
|
||||
font_metrics_provider,
|
||||
flags,
|
||||
quirks_mode,
|
||||
|
@ -3108,7 +3106,6 @@ pub fn apply_declarations<'a, F, I>(
|
|||
parent_style_ignoring_first_line: Option<<&ComputedValues>,
|
||||
layout_parent_style: Option<<&ComputedValues>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
mut cascade_info: Option<<&mut CascadeInfo>,
|
||||
font_metrics_provider: &FontMetricsProvider,
|
||||
flags: CascadeFlags,
|
||||
quirks_mode: QuirksMode,
|
||||
|
@ -3280,9 +3277,7 @@ where
|
|||
% endif
|
||||
|
||||
let discriminant = longhand_id as usize;
|
||||
(CASCADE_PROPERTY[discriminant])(&*declaration,
|
||||
&mut context,
|
||||
&mut cascade_info);
|
||||
(CASCADE_PROPERTY[discriminant])(&*declaration, &mut context);
|
||||
}
|
||||
% if category_to_cascade_now == "early":
|
||||
let writing_mode = get_writing_mode(context.builder.get_inheritedbox());
|
||||
|
@ -3363,9 +3358,7 @@ where
|
|||
if let Some(ref declaration) = font_family {
|
||||
|
||||
let discriminant = LonghandId::FontFamily as usize;
|
||||
(CASCADE_PROPERTY[discriminant])(declaration,
|
||||
&mut context,
|
||||
&mut cascade_info);
|
||||
(CASCADE_PROPERTY[discriminant])(declaration, &mut context);
|
||||
% if product == "gecko":
|
||||
let device = context.builder.device;
|
||||
if let PropertyDeclaration::FontFamily(ref val) = **declaration {
|
||||
|
@ -3383,9 +3376,7 @@ where
|
|||
|
||||
if let Some(ref declaration) = font_size {
|
||||
let discriminant = LonghandId::FontSize as usize;
|
||||
(CASCADE_PROPERTY[discriminant])(declaration,
|
||||
&mut context,
|
||||
&mut cascade_info);
|
||||
(CASCADE_PROPERTY[discriminant])(declaration, &mut context);
|
||||
% if product == "gecko":
|
||||
// Font size must be explicitly inherited to handle lang changes and
|
||||
// scriptlevel changes.
|
||||
|
@ -3397,9 +3388,7 @@ where
|
|||
let size = PropertyDeclaration::CSSWideKeyword(
|
||||
LonghandId::FontSize, CSSWideKeyword::Inherit);
|
||||
|
||||
(CASCADE_PROPERTY[discriminant])(&size,
|
||||
&mut context,
|
||||
&mut cascade_info);
|
||||
(CASCADE_PROPERTY[discriminant])(&size, &mut context);
|
||||
% endif
|
||||
}
|
||||
% endif
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
//! Style resolution for a given element or pseudo-element.
|
||||
|
||||
use applicable_declarations::ApplicableDeclarationList;
|
||||
use cascade_info::CascadeInfo;
|
||||
use context::{CascadeInputs, ElementCascadeInputs, StyleContext};
|
||||
use data::{ElementStyles, EagerPseudoStyles};
|
||||
use dom::TElement;
|
||||
|
@ -481,7 +480,6 @@ where
|
|||
cascade_visited: CascadeVisitedMode,
|
||||
pseudo: Option<&PseudoElement>,
|
||||
) -> Arc<ComputedValues> {
|
||||
let mut cascade_info = CascadeInfo::new();
|
||||
let mut cascade_flags = CascadeFlags::empty();
|
||||
|
||||
if self.element.skip_root_and_item_based_display_fixup() ||
|
||||
|
@ -525,14 +523,11 @@ where
|
|||
parent_style,
|
||||
layout_parent_style,
|
||||
style_if_visited,
|
||||
Some(&mut cascade_info),
|
||||
&self.context.thread_local.font_metrics_provider,
|
||||
cascade_flags,
|
||||
self.context.shared.quirks_mode(),
|
||||
);
|
||||
|
||||
cascade_info.finish(&self.element.as_node());
|
||||
|
||||
values
|
||||
}
|
||||
}
|
||||
|
|
|
@ -721,7 +721,6 @@ impl Stylist {
|
|||
parent,
|
||||
parent,
|
||||
None,
|
||||
None,
|
||||
font_metrics,
|
||||
cascade_flags,
|
||||
self.quirks_mode,
|
||||
|
@ -901,7 +900,6 @@ impl Stylist {
|
|||
Some(inherited_style_ignoring_first_line),
|
||||
Some(layout_parent_style_for_visited),
|
||||
None,
|
||||
None,
|
||||
font_metrics,
|
||||
cascade_flags,
|
||||
self.quirks_mode,
|
||||
|
@ -927,7 +925,6 @@ impl Stylist {
|
|||
Some(parent_style_ignoring_first_line),
|
||||
Some(layout_parent_style),
|
||||
visited_values,
|
||||
None,
|
||||
font_metrics,
|
||||
cascade_flags,
|
||||
self.quirks_mode,
|
||||
|
@ -1543,7 +1540,6 @@ impl Stylist {
|
|||
Some(parent_style),
|
||||
Some(parent_style),
|
||||
None,
|
||||
None,
|
||||
&metrics,
|
||||
CascadeFlags::empty(),
|
||||
self.quirks_mode,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue