mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #17688 - emilio:split-style-resolution, r=heycam,BorisChiou
style: Split style resolution and dynamic change computation. This is the Servo side of Mozilla bug 1379505.
This commit is contained in:
commit
16d6dc133b
20 changed files with 5498 additions and 6388 deletions
|
@ -37,7 +37,7 @@ use style::selector_parser::PseudoElement;
|
|||
use style_traits::ToCss;
|
||||
use style_traits::cursor::Cursor;
|
||||
use webrender_traits::ClipId;
|
||||
use wrapper::{LayoutNodeHelpers, LayoutNodeLayoutData};
|
||||
use wrapper::LayoutNodeLayoutData;
|
||||
|
||||
/// Mutable data belonging to the LayoutThread.
|
||||
///
|
||||
|
@ -680,7 +680,9 @@ pub fn process_resolved_style_request<'a, N>(context: &LayoutContext,
|
|||
layout_root: &mut Flow) -> String
|
||||
where N: LayoutNode,
|
||||
{
|
||||
use style::stylist::RuleInclusion;
|
||||
use style::traversal::resolve_style;
|
||||
|
||||
let element = node.as_element().unwrap();
|
||||
|
||||
// We call process_resolved_style_request after performing a whole-document
|
||||
|
@ -689,30 +691,43 @@ pub fn process_resolved_style_request<'a, N>(context: &LayoutContext,
|
|||
return process_resolved_style_request_internal(node, pseudo, property, layout_root);
|
||||
}
|
||||
|
||||
// However, the element may be in a display:none subtree. The style system
|
||||
// has a mechanism to give us that within a defined scope (after which point
|
||||
// it's cleared to maintained style system invariants).
|
||||
// In a display: none subtree. No pseudo-element exists.
|
||||
if pseudo.is_some() {
|
||||
return String::new();
|
||||
}
|
||||
|
||||
let mut tlc = ThreadLocalStyleContext::new(&context.style_context);
|
||||
let mut context = StyleContext {
|
||||
shared: &context.style_context,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
let mut result = None;
|
||||
let ensure = |el: N::ConcreteElement| el.as_node().initialize_data();
|
||||
let clear = |el: N::ConcreteElement| el.as_node().clear_data();
|
||||
resolve_style(&mut context, element, &ensure, &clear, |_: &_| {
|
||||
let s = process_resolved_style_request_internal(node, pseudo, property, layout_root);
|
||||
result = Some(s);
|
||||
});
|
||||
result.unwrap()
|
||||
|
||||
let styles = resolve_style(&mut context, element, RuleInclusion::All);
|
||||
let style = styles.primary();
|
||||
let longhand_id = match *property {
|
||||
PropertyId::Longhand(id) => id,
|
||||
// Firefox returns blank strings for the computed value of shorthands,
|
||||
// so this should be web-compatible.
|
||||
PropertyId::Shorthand(_) => return String::new(),
|
||||
PropertyId::Custom(ref name) => {
|
||||
return style.computed_value_to_string(PropertyDeclarationId::Custom(name))
|
||||
}
|
||||
};
|
||||
|
||||
// No need to care about used values here, since we're on a display: none
|
||||
// subtree, use the resolved value.
|
||||
style.computed_value_to_string(PropertyDeclarationId::Longhand(longhand_id))
|
||||
}
|
||||
|
||||
/// The primary resolution logic, which assumes that the element is styled.
|
||||
fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
||||
pseudo: &Option<PseudoElement>,
|
||||
property: &PropertyId,
|
||||
layout_root: &mut Flow) -> String
|
||||
where N: LayoutNode,
|
||||
fn process_resolved_style_request_internal<'a, N>(
|
||||
requested_node: N,
|
||||
pseudo: &Option<PseudoElement>,
|
||||
property: &PropertyId,
|
||||
layout_root: &mut Flow,
|
||||
) -> String
|
||||
where
|
||||
N: LayoutNode,
|
||||
{
|
||||
let layout_el = requested_node.to_threadsafe().as_element().unwrap();
|
||||
let layout_el = match *pseudo {
|
||||
|
@ -721,6 +736,8 @@ fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
|||
Some(PseudoElement::DetailsSummary) |
|
||||
Some(PseudoElement::DetailsContent) |
|
||||
Some(PseudoElement::Selection) => None,
|
||||
// FIXME(emilio): What about the other pseudos? Probably they shouldn't
|
||||
// just return the element's style!
|
||||
_ => Some(layout_el)
|
||||
};
|
||||
|
||||
|
@ -735,7 +752,6 @@ fn process_resolved_style_request_internal<'a, N>(requested_node: N,
|
|||
};
|
||||
|
||||
let style = &*layout_el.resolved_style();
|
||||
|
||||
let longhand_id = match *property {
|
||||
PropertyId::Longhand(id) => id,
|
||||
|
||||
|
|
|
@ -5,21 +5,6 @@
|
|||
use attr::CaseSensitivity;
|
||||
use bloom::BloomFilter;
|
||||
|
||||
bitflags! {
|
||||
/// Set of flags that determine the different kind of elements affected by
|
||||
/// the selector matching process.
|
||||
///
|
||||
/// This is used to implement efficient sharing.
|
||||
#[derive(Default)]
|
||||
pub flags StyleRelations: usize {
|
||||
/// Whether this element is affected by presentational hints. This is
|
||||
/// computed externally (that is, in Servo).
|
||||
const AFFECTED_BY_PRESENTATIONAL_HINTS = 1 << 0,
|
||||
/// Whether this element has pseudo-element styles. Computed externally.
|
||||
const AFFECTED_BY_PSEUDO_ELEMENTS = 1 << 1,
|
||||
}
|
||||
}
|
||||
|
||||
/// What kind of selector matching mode we should use.
|
||||
///
|
||||
/// There are two modes of selector matching. The difference is only noticeable
|
||||
|
@ -89,9 +74,6 @@ impl QuirksMode {
|
|||
/// transient data that applies to only a single selector.
|
||||
#[derive(Clone)]
|
||||
pub struct MatchingContext<'a> {
|
||||
/// Output that records certains relations between elements noticed during
|
||||
/// matching (and also extended after matching).
|
||||
pub relations: StyleRelations,
|
||||
/// Input with the matching mode we should use when matching selectors.
|
||||
pub matching_mode: MatchingMode,
|
||||
/// Input with the bloom filter used to fast-reject selectors.
|
||||
|
@ -116,7 +98,6 @@ impl<'a> MatchingContext<'a> {
|
|||
-> Self
|
||||
{
|
||||
Self {
|
||||
relations: StyleRelations::empty(),
|
||||
matching_mode: matching_mode,
|
||||
bloom_filter: bloom_filter,
|
||||
visited_handling: VisitedHandlingMode::AllLinksUnvisited,
|
||||
|
@ -134,7 +115,6 @@ impl<'a> MatchingContext<'a> {
|
|||
-> Self
|
||||
{
|
||||
Self {
|
||||
relations: StyleRelations::empty(),
|
||||
matching_mode: matching_mode,
|
||||
bloom_filter: bloom_filter,
|
||||
visited_handling: visited_handling,
|
||||
|
|
|
@ -714,8 +714,6 @@ fn matches_simple_selector<E, F>(
|
|||
matches_last_child(element, flags_setter)
|
||||
}
|
||||
Component::Root => {
|
||||
// We never share styles with an element with no parent, so no point
|
||||
// in creating a new StyleRelation.
|
||||
element.is_root()
|
||||
}
|
||||
Component::Empty => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#[cfg(feature = "servo")] use animation::Animation;
|
||||
use animation::PropertyAnimation;
|
||||
use app_units::Au;
|
||||
use arrayvec::ArrayVec;
|
||||
use bloom::StyleBloom;
|
||||
use cache::LRUCache;
|
||||
use data::{EagerPseudoStyles, ElementData};
|
||||
|
@ -19,8 +18,8 @@ use font_metrics::FontMetricsProvider;
|
|||
#[cfg(feature = "servo")] use parking_lot::RwLock;
|
||||
use properties::ComputedValues;
|
||||
use rule_tree::StrongRuleNode;
|
||||
use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, SnapshotMap};
|
||||
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode};
|
||||
use selector_parser::{EAGER_PSEUDO_COUNT, SnapshotMap};
|
||||
use selectors::matching::ElementSelectorFlags;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use sharing::{ValidationData, StyleSharingCandidateCache};
|
||||
use std::fmt;
|
||||
|
@ -162,36 +161,17 @@ impl<'a> SharedStyleContext<'a> {
|
|||
/// within the `CurrentElementInfo`. At the end of the cascade, they are folded
|
||||
/// down into the main `ComputedValues` to reduce memory usage per element while
|
||||
/// still remaining accessible.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct CascadeInputs {
|
||||
/// The rule node representing the ordered list of rules matched for this
|
||||
/// node.
|
||||
rules: Option<StrongRuleNode>,
|
||||
pub rules: Option<StrongRuleNode>,
|
||||
|
||||
/// The rule node representing the ordered list of rules matched for this
|
||||
/// node 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_rules: Option<StrongRuleNode>,
|
||||
|
||||
/// The element's computed values 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.
|
||||
///
|
||||
/// We also store a reference to this inside the regular ComputedValues to
|
||||
/// avoid refactoring all APIs to become aware of multiple ComputedValues
|
||||
/// objects.
|
||||
visited_values: Option<Arc<ComputedValues>>,
|
||||
}
|
||||
|
||||
impl Default for CascadeInputs {
|
||||
fn default() -> Self {
|
||||
CascadeInputs {
|
||||
rules: None,
|
||||
visited_rules: None,
|
||||
visited_values: None,
|
||||
}
|
||||
}
|
||||
pub visited_rules: Option<StrongRuleNode>,
|
||||
}
|
||||
|
||||
impl CascadeInputs {
|
||||
|
@ -200,125 +180,8 @@ impl CascadeInputs {
|
|||
CascadeInputs {
|
||||
rules: style.rules.clone(),
|
||||
visited_rules: style.get_visited_style().and_then(|v| v.rules.clone()),
|
||||
// Values will be re-cascaded if necessary, so this can be None.
|
||||
visited_values: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether there are any rules. Rules will be present after unvisited
|
||||
/// matching or pulled from a previous cascade if no matching is expected.
|
||||
pub fn has_rules(&self) -> bool {
|
||||
self.rules.is_some()
|
||||
}
|
||||
|
||||
/// Gets a mutable reference to the rule node, if any.
|
||||
pub fn get_rules_mut(&mut self) -> Option<&mut StrongRuleNode> {
|
||||
self.rules.as_mut()
|
||||
}
|
||||
|
||||
/// Gets a reference to the rule node, if any.
|
||||
pub fn get_rules(&self) -> Option<&StrongRuleNode> {
|
||||
self.rules.as_ref()
|
||||
}
|
||||
|
||||
/// Gets a reference to the rule node. Panic if the element does not have
|
||||
/// rule node.
|
||||
pub fn rules(&self) -> &StrongRuleNode {
|
||||
self.rules.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Sets the rule node depending on visited mode.
|
||||
/// Returns whether the rules changed.
|
||||
pub fn set_rules(&mut self,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
rules: StrongRuleNode)
|
||||
-> bool {
|
||||
match visited_handling {
|
||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited => {
|
||||
unreachable!("We should never try to selector match with \
|
||||
AllLinksVisitedAndUnvisited");
|
||||
},
|
||||
VisitedHandlingMode::AllLinksUnvisited => self.set_unvisited_rules(rules),
|
||||
VisitedHandlingMode::RelevantLinkVisited => self.set_visited_rules(rules),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the unvisited rule node, and returns whether it changed.
|
||||
fn set_unvisited_rules(&mut self, rules: StrongRuleNode) -> bool {
|
||||
if let Some(ref old_rules) = self.rules {
|
||||
if *old_rules == rules {
|
||||
return false
|
||||
}
|
||||
}
|
||||
self.rules = Some(rules);
|
||||
true
|
||||
}
|
||||
|
||||
/// Whether there are any visited rules. Visited rules will be present
|
||||
/// after visited matching or pulled from a previous cascade (assuming there
|
||||
/// was a relevant link at the time) if no matching is expected.
|
||||
pub fn has_visited_rules(&self) -> bool {
|
||||
self.visited_rules.is_some()
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited rule node, if any.
|
||||
pub fn get_visited_rules(&self) -> Option<&StrongRuleNode> {
|
||||
self.visited_rules.as_ref()
|
||||
}
|
||||
|
||||
/// Gets a mutable reference to the visited rule node, if any.
|
||||
pub fn get_visited_rules_mut(&mut self) -> Option<&mut StrongRuleNode> {
|
||||
self.visited_rules.as_mut()
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited rule node. Panic if the element does not
|
||||
/// have visited rule node.
|
||||
pub fn visited_rules(&self) -> &StrongRuleNode {
|
||||
self.visited_rules.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Sets the visited rule node, and returns whether it changed.
|
||||
fn set_visited_rules(&mut self, rules: StrongRuleNode) -> bool {
|
||||
if let Some(ref old_rules) = self.visited_rules {
|
||||
if *old_rules == rules {
|
||||
return false
|
||||
}
|
||||
}
|
||||
self.visited_rules = Some(rules);
|
||||
true
|
||||
}
|
||||
|
||||
/// Takes the visited rule node.
|
||||
pub fn take_visited_rules(&mut self) -> Option<StrongRuleNode> {
|
||||
self.visited_rules.take()
|
||||
}
|
||||
|
||||
/// Whether there are any visited values.
|
||||
pub fn has_visited_values(&self) -> bool {
|
||||
self.visited_values.is_some()
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited computed values. Panic if the element
|
||||
/// does not have visited computed values.
|
||||
pub fn visited_values(&self) -> &Arc<ComputedValues> {
|
||||
self.visited_values.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Sets the visited computed values.
|
||||
pub fn set_visited_values(&mut self, values: Arc<ComputedValues>) {
|
||||
self.visited_values = Some(values);
|
||||
}
|
||||
|
||||
/// Take the visited computed values.
|
||||
pub fn take_visited_values(&mut self) -> Option<Arc<ComputedValues>> {
|
||||
self.visited_values.take()
|
||||
}
|
||||
|
||||
/// Clone the visited computed values Arc. Used to store a reference to the
|
||||
/// visited values inside the regular values.
|
||||
pub fn clone_visited_values(&self) -> Option<Arc<ComputedValues>> {
|
||||
self.visited_values.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// We manually implement Debug for CascadeInputs so that we can avoid the
|
||||
|
@ -363,160 +226,9 @@ impl EagerPseudoCascadeInputs {
|
|||
}))
|
||||
}
|
||||
|
||||
/// Returns whether there are any pseudo inputs.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_none()
|
||||
}
|
||||
|
||||
/// Returns a reference to the inputs for a given eager pseudo, if they exist.
|
||||
pub fn get(&self, pseudo: &PseudoElement) -> Option<&CascadeInputs> {
|
||||
debug_assert!(pseudo.is_eager());
|
||||
self.0.as_ref().and_then(|p| p[pseudo.eager_index()].as_ref())
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the inputs for a given eager pseudo, if they exist.
|
||||
pub fn get_mut(&mut self, pseudo: &PseudoElement) -> Option<&mut CascadeInputs> {
|
||||
debug_assert!(pseudo.is_eager());
|
||||
self.0.as_mut().and_then(|p| p[pseudo.eager_index()].as_mut())
|
||||
}
|
||||
|
||||
/// Returns true if the EagerPseudoCascadeInputs has a inputs for |pseudo|.
|
||||
pub fn has(&self, pseudo: &PseudoElement) -> bool {
|
||||
self.get(pseudo).is_some()
|
||||
}
|
||||
|
||||
/// Inserts a pseudo-element. The pseudo-element must not already exist.
|
||||
pub fn insert(&mut self, pseudo: &PseudoElement, inputs: CascadeInputs) {
|
||||
debug_assert!(!self.has(pseudo));
|
||||
if self.0.is_none() {
|
||||
self.0 = Some(Default::default());
|
||||
}
|
||||
self.0.as_mut().unwrap()[pseudo.eager_index()] = Some(inputs);
|
||||
}
|
||||
|
||||
/// Removes a pseudo-element inputs if they exist, and returns it.
|
||||
pub fn take(&mut self, pseudo: &PseudoElement) -> Option<CascadeInputs> {
|
||||
let result = match self.0.as_mut() {
|
||||
None => return None,
|
||||
Some(arr) => arr[pseudo.eager_index()].take(),
|
||||
};
|
||||
let empty = self.0.as_ref().unwrap().iter().all(|x| x.is_none());
|
||||
if empty {
|
||||
self.0 = None;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Returns a list of the pseudo-elements.
|
||||
pub fn keys(&self) -> ArrayVec<[PseudoElement; EAGER_PSEUDO_COUNT]> {
|
||||
let mut v = ArrayVec::new();
|
||||
if let Some(ref arr) = self.0 {
|
||||
for i in 0..EAGER_PSEUDO_COUNT {
|
||||
if arr[i].is_some() {
|
||||
v.push(PseudoElement::from_eager_index(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// Adds the unvisited rule node for a given pseudo-element, which may or
|
||||
/// may not exist.
|
||||
///
|
||||
/// Returns true if the pseudo-element is new.
|
||||
fn add_unvisited_rules(&mut self,
|
||||
pseudo: &PseudoElement,
|
||||
rules: StrongRuleNode)
|
||||
-> bool {
|
||||
if let Some(mut inputs) = self.get_mut(pseudo) {
|
||||
inputs.set_unvisited_rules(rules);
|
||||
return false
|
||||
}
|
||||
let mut inputs = CascadeInputs::default();
|
||||
inputs.set_unvisited_rules(rules);
|
||||
self.insert(pseudo, inputs);
|
||||
true
|
||||
}
|
||||
|
||||
/// Remove the unvisited rule node for a given pseudo-element, which may or
|
||||
/// may not exist. Since removing the rule node implies we don't need any
|
||||
/// other data for the pseudo, take the entire pseudo if found.
|
||||
///
|
||||
/// Returns true if the pseudo-element was removed.
|
||||
fn remove_unvisited_rules(&mut self, pseudo: &PseudoElement) -> bool {
|
||||
self.take(pseudo).is_some()
|
||||
}
|
||||
|
||||
/// Adds the visited rule node for a given pseudo-element. It is assumed to
|
||||
/// already exist because unvisited inputs should have been added first.
|
||||
///
|
||||
/// Returns true if the pseudo-element is new. (Always false, but returns a
|
||||
/// bool for parity with `add_unvisited_rules`.)
|
||||
fn add_visited_rules(&mut self,
|
||||
pseudo: &PseudoElement,
|
||||
rules: StrongRuleNode)
|
||||
-> bool {
|
||||
debug_assert!(self.has(pseudo));
|
||||
let mut inputs = self.get_mut(pseudo).unwrap();
|
||||
inputs.set_visited_rules(rules);
|
||||
false
|
||||
}
|
||||
|
||||
/// Remove the visited rule node for a given pseudo-element, which may or
|
||||
/// may not exist.
|
||||
///
|
||||
/// Returns true if the psuedo-element was removed. (Always false, but
|
||||
/// returns a bool for parity with `remove_unvisited_rules`.)
|
||||
fn remove_visited_rules(&mut self, pseudo: &PseudoElement) -> bool {
|
||||
if let Some(mut inputs) = self.get_mut(pseudo) {
|
||||
inputs.take_visited_rules();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Adds a rule node for a given pseudo-element, which may or may not exist.
|
||||
/// The type of rule node depends on the visited mode.
|
||||
///
|
||||
/// Returns true if the pseudo-element is new.
|
||||
pub fn add_rules(&mut self,
|
||||
pseudo: &PseudoElement,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
rules: StrongRuleNode)
|
||||
-> bool {
|
||||
match visited_handling {
|
||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited => {
|
||||
unreachable!("We should never try to selector match with \
|
||||
AllLinksVisitedAndUnvisited");
|
||||
},
|
||||
VisitedHandlingMode::AllLinksUnvisited => {
|
||||
self.add_unvisited_rules(&pseudo, rules)
|
||||
},
|
||||
VisitedHandlingMode::RelevantLinkVisited => {
|
||||
self.add_visited_rules(&pseudo, rules)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes a rule node for a given pseudo-element, which may or may not
|
||||
/// exist. The type of rule node depends on the visited mode.
|
||||
///
|
||||
/// Returns true if the psuedo-element was removed.
|
||||
pub fn remove_rules(&mut self,
|
||||
pseudo: &PseudoElement,
|
||||
visited_handling: VisitedHandlingMode)
|
||||
-> bool {
|
||||
match visited_handling {
|
||||
VisitedHandlingMode::AllLinksVisitedAndUnvisited => {
|
||||
unreachable!("We should never try to selector match with \
|
||||
AllLinksVisitedAndUnvisited");
|
||||
},
|
||||
VisitedHandlingMode::AllLinksUnvisited => {
|
||||
self.remove_unvisited_rules(&pseudo)
|
||||
},
|
||||
VisitedHandlingMode::RelevantLinkVisited => {
|
||||
self.remove_visited_rules(&pseudo)
|
||||
},
|
||||
}
|
||||
/// Returns the list of rules, if they exist.
|
||||
pub fn into_array(self) -> Option<[Option<CascadeInputs>; EAGER_PSEUDO_COUNT]> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -530,56 +242,20 @@ impl EagerPseudoCascadeInputs {
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct ElementCascadeInputs {
|
||||
/// The element's cascade inputs.
|
||||
pub primary: Option<CascadeInputs>,
|
||||
pub primary: CascadeInputs,
|
||||
/// A list of the inputs for the element's eagerly-cascaded pseudo-elements.
|
||||
pub pseudos: EagerPseudoCascadeInputs,
|
||||
}
|
||||
|
||||
impl Default for ElementCascadeInputs {
|
||||
/// Construct an empty `ElementCascadeInputs`.
|
||||
fn default() -> Self {
|
||||
ElementCascadeInputs {
|
||||
primary: None,
|
||||
pseudos: EagerPseudoCascadeInputs(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ElementCascadeInputs {
|
||||
/// Construct inputs from previous cascade results, if any.
|
||||
pub fn new_from_element_data(data: &ElementData) -> Self {
|
||||
if !data.has_styles() {
|
||||
return ElementCascadeInputs::default()
|
||||
}
|
||||
debug_assert!(data.has_styles());
|
||||
ElementCascadeInputs {
|
||||
primary: Some(CascadeInputs::new_from_style(data.styles.primary())),
|
||||
primary: CascadeInputs::new_from_style(data.styles.primary()),
|
||||
pseudos: EagerPseudoCascadeInputs::new_from_style(&data.styles.pseudos),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns whether we have primary inputs.
|
||||
pub fn has_primary(&self) -> bool {
|
||||
self.primary.is_some()
|
||||
}
|
||||
|
||||
/// Gets the primary inputs. Panic if unavailable.
|
||||
pub fn primary(&self) -> &CascadeInputs {
|
||||
self.primary.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Gets the mutable primary inputs. Panic if unavailable.
|
||||
pub fn primary_mut(&mut self) -> &mut CascadeInputs {
|
||||
self.primary.as_mut().unwrap()
|
||||
}
|
||||
|
||||
/// Ensure primary inputs exist and create them if they do not.
|
||||
/// Returns a mutable reference to the primary inputs.
|
||||
pub fn ensure_primary(&mut self) -> &mut CascadeInputs {
|
||||
if self.primary.is_none() {
|
||||
self.primary = Some(CascadeInputs::default());
|
||||
}
|
||||
self.primary.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about the current element being processed. We group this
|
||||
|
@ -598,11 +274,6 @@ pub struct CurrentElementInfo {
|
|||
/// A Vec of possibly expired animations. Used only by Servo.
|
||||
#[allow(dead_code)]
|
||||
pub possibly_expired_animations: Vec<PropertyAnimation>,
|
||||
/// Temporary storage for various intermediate inputs that are eventually
|
||||
/// used by by the cascade. At the end of the cascade, they are folded down
|
||||
/// into the main `ComputedValues` to reduce memory usage per element while
|
||||
/// still remaining accessible.
|
||||
pub cascade_inputs: ElementCascadeInputs,
|
||||
}
|
||||
|
||||
/// Statistics gathered during the traversal. We gather statistics on each
|
||||
|
@ -906,7 +577,6 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
|||
is_initial_style: !data.has_styles(),
|
||||
validation_data: ValidationData::default(),
|
||||
possibly_expired_animations: Vec::new(),
|
||||
cascade_inputs: ElementCascadeInputs::default(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -951,24 +621,6 @@ pub struct StyleContext<'a, E: TElement + 'a> {
|
|||
pub thread_local: &'a mut ThreadLocalStyleContext<E>,
|
||||
}
|
||||
|
||||
impl<'a, E: TElement + 'a> StyleContext<'a, E> {
|
||||
/// Returns a reference to the cascade inputs. Panics if there is no
|
||||
/// `CurrentElementInfo`.
|
||||
pub fn cascade_inputs(&self) -> &ElementCascadeInputs {
|
||||
&self.thread_local.current_element_info
|
||||
.as_ref().unwrap()
|
||||
.cascade_inputs
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the cascade inputs. Panics if there is
|
||||
/// no `CurrentElementInfo`.
|
||||
pub fn cascade_inputs_mut(&mut self) -> &mut ElementCascadeInputs {
|
||||
&mut self.thread_local.current_element_info
|
||||
.as_mut().unwrap()
|
||||
.cascade_inputs
|
||||
}
|
||||
}
|
||||
|
||||
/// Why we're doing reflow.
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ReflowGoal {
|
||||
|
|
|
@ -8,11 +8,11 @@ use arrayvec::ArrayVec;
|
|||
use context::SharedStyleContext;
|
||||
use dom::TElement;
|
||||
use invalidation::element::restyle_hints::RestyleHint;
|
||||
use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock};
|
||||
use properties::ComputedValues;
|
||||
use properties::longhands::display::computed_value as display;
|
||||
use rule_tree::StrongRuleNode;
|
||||
use selector_parser::{EAGER_PSEUDO_COUNT, PseudoElement, RestyleDamage};
|
||||
use shared_lock::{Locked, StylesheetGuards};
|
||||
use shared_lock::StylesheetGuards;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use stylearc::Arc;
|
||||
|
||||
|
@ -105,7 +105,7 @@ impl RestyleData {
|
|||
/// not require duplicate allocations. We leverage the copy-on-write semantics of
|
||||
/// Arc::make_mut(), which is free (i.e. does not require atomic RMU operations)
|
||||
/// in servo_arc.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct EagerPseudoStyles(Option<Arc<EagerPseudoArray>>);
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -234,7 +234,7 @@ impl EagerPseudoStyles {
|
|||
|
||||
/// The styles associated with a node, including the styles for any
|
||||
/// pseudo-elements.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ElementStyles {
|
||||
/// The element's style.
|
||||
pub primary: Option<Arc<ComputedValues>>,
|
||||
|
@ -242,16 +242,6 @@ pub struct ElementStyles {
|
|||
pub pseudos: EagerPseudoStyles,
|
||||
}
|
||||
|
||||
impl Default for ElementStyles {
|
||||
/// Construct an empty `ElementStyles`.
|
||||
fn default() -> Self {
|
||||
ElementStyles {
|
||||
primary: None,
|
||||
pseudos: EagerPseudoStyles(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ElementStyles {
|
||||
/// Returns the primary style.
|
||||
pub fn get_primary(&self) -> Option<&Arc<ComputedValues>> {
|
||||
|
@ -412,29 +402,4 @@ impl ElementData {
|
|||
pub fn clear_restyle_state(&mut self) {
|
||||
self.restyle.clear();
|
||||
}
|
||||
|
||||
/// Returns SMIL overriden value if exists.
|
||||
pub fn get_smil_override(&self) -> Option<&Arc<Locked<PropertyDeclarationBlock>>> {
|
||||
if cfg!(feature = "servo") {
|
||||
// Servo has no knowledge of a SMIL rule, so just avoid looking for it.
|
||||
return None;
|
||||
}
|
||||
|
||||
match self.styles.get_primary() {
|
||||
Some(v) => v.rules().get_smil_animation_rule(),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns AnimationRules that has processed during animation-only restyles.
|
||||
pub fn get_animation_rules(&self) -> AnimationRules {
|
||||
if cfg!(feature = "servo") {
|
||||
return AnimationRules(None, None)
|
||||
}
|
||||
|
||||
match self.styles.get_primary() {
|
||||
Some(v) => v.rules().get_animation_rules(),
|
||||
None => AnimationRules(None, None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use data::ElementData;
|
|||
use element_state::ElementState;
|
||||
use font_metrics::FontMetricsProvider;
|
||||
use media_queries::Device;
|
||||
use properties::{ComputedValues, PropertyDeclarationBlock};
|
||||
use properties::{AnimationRules, ComputedValues, PropertyDeclarationBlock};
|
||||
#[cfg(feature = "gecko")] use properties::animated_properties::AnimationValue;
|
||||
#[cfg(feature = "gecko")] use properties::animated_properties::TransitionProperty;
|
||||
use rule_tree::CascadeLevel;
|
||||
|
@ -379,6 +379,18 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
|
|||
None
|
||||
}
|
||||
|
||||
/// Get the combined animation and transition rules.
|
||||
fn get_animation_rules(&self) -> AnimationRules {
|
||||
if !self.may_have_animations() {
|
||||
return AnimationRules(None, None)
|
||||
}
|
||||
|
||||
AnimationRules(
|
||||
self.get_animation_rule(),
|
||||
self.get_transition_rule(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Get this element's animation rule.
|
||||
fn get_animation_rule(&self)
|
||||
-> Option<Arc<Locked<PropertyDeclarationBlock>>> {
|
||||
|
|
|
@ -240,6 +240,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_arrow: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms7articleE"]
|
||||
pub static nsGkAtoms_article: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms2asE"]
|
||||
pub static nsGkAtoms_as: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms9ascendingE"]
|
||||
pub static nsGkAtoms_ascending: *mut nsIAtom;
|
||||
#[link_name = "_ZN9nsGkAtoms5asideE"]
|
||||
|
@ -5367,6 +5369,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_arrow: *mut nsIAtom;
|
||||
#[link_name = "?article@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_article: *mut nsIAtom;
|
||||
#[link_name = "?as@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_as: *mut nsIAtom;
|
||||
#[link_name = "?ascending@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
pub static nsGkAtoms_ascending: *mut nsIAtom;
|
||||
#[link_name = "?aside@nsGkAtoms@@2PEAVnsIAtom@@EA"]
|
||||
|
@ -10494,6 +10498,8 @@ cfg_if! {
|
|||
pub static nsGkAtoms_arrow: *mut nsIAtom;
|
||||
#[link_name = "\x01?article@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_article: *mut nsIAtom;
|
||||
#[link_name = "\x01?as@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_as: *mut nsIAtom;
|
||||
#[link_name = "\x01?ascending@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
pub static nsGkAtoms_ascending: *mut nsIAtom;
|
||||
#[link_name = "\x01?aside@nsGkAtoms@@2PAVnsIAtom@@A"]
|
||||
|
@ -15624,6 +15630,8 @@ macro_rules! atom {
|
|||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_arrow as *mut _) } };
|
||||
("article") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_article as *mut _) } };
|
||||
("as") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_as as *mut _) } };
|
||||
("ascending") =>
|
||||
{ unsafe { $crate::string_cache::atom_macro::atom_from_static($crate::string_cache::atom_macro::nsGkAtoms_ascending as *mut _) } };
|
||||
("aside") =>
|
||||
|
|
|
@ -2752,6 +2752,8 @@ extern "C" {
|
|||
RawServoStyleSetBorrowed,
|
||||
element:
|
||||
RawGeckoElementBorrowed,
|
||||
existing_style:
|
||||
ServoComputedValuesBorrowed,
|
||||
snapshots:
|
||||
*const ServoElementSnapshotTable,
|
||||
pseudo_type:
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -123,6 +123,7 @@ pub mod selector_map;
|
|||
pub mod selector_parser;
|
||||
pub mod shared_lock;
|
||||
pub mod sharing;
|
||||
pub mod style_resolver;
|
||||
pub mod stylist;
|
||||
#[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod servo;
|
||||
pub mod sequential;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -28,10 +28,10 @@ use values::computed::Context;
|
|||
///
|
||||
/// The first one is for Animation cascade level, and the second one is for
|
||||
/// Transition cascade level.
|
||||
pub struct AnimationRules<'a>(pub Option<&'a Arc<Locked<PropertyDeclarationBlock>>>,
|
||||
pub Option<&'a Arc<Locked<PropertyDeclarationBlock>>>);
|
||||
pub struct AnimationRules(pub Option<Arc<Locked<PropertyDeclarationBlock>>>,
|
||||
pub Option<Arc<Locked<PropertyDeclarationBlock>>>);
|
||||
|
||||
impl<'a> AnimationRules<'a> {
|
||||
impl AnimationRules {
|
||||
/// Returns whether these animation rules represents an actual rule or not.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_none() && self.1.is_none()
|
||||
|
|
|
@ -2576,11 +2576,11 @@ pub fn cascade(device: &Device,
|
|||
flags: CascadeFlags,
|
||||
quirks_mode: QuirksMode)
|
||||
-> ComputedValues {
|
||||
debug_assert_eq!(parent_style.is_some(), layout_parent_style.is_some());
|
||||
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())
|
||||
layout_parent_style.unwrap_or(parent_style))
|
||||
},
|
||||
None => {
|
||||
(device.default_computed_values(),
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
use applicable_declarations::ApplicableDeclarationList;
|
||||
#[cfg(feature = "servo")]
|
||||
use heapsize::HeapSizeOf;
|
||||
use properties::{AnimationRules, Importance, LonghandIdSet, PropertyDeclarationBlock};
|
||||
use properties::{Importance, LonghandIdSet, PropertyDeclarationBlock};
|
||||
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
|
||||
use smallvec::SmallVec;
|
||||
use std::io::{self, Write};
|
||||
|
@ -150,8 +150,8 @@ impl RuleTree {
|
|||
}
|
||||
|
||||
/// Get the root rule node.
|
||||
pub fn root(&self) -> StrongRuleNode {
|
||||
self.root.clone()
|
||||
pub fn root(&self) -> &StrongRuleNode {
|
||||
&self.root
|
||||
}
|
||||
|
||||
fn dump<W: Write>(&self, guards: &StylesheetGuards, writer: &mut W) {
|
||||
|
@ -171,11 +171,13 @@ impl RuleTree {
|
|||
/// !important rules are detected and inserted into the appropriate position
|
||||
/// in the rule tree. This allows selector matching to ignore importance,
|
||||
/// while still maintaining the appropriate cascade order in the rule tree.
|
||||
pub fn insert_ordered_rules_with_important<'a, I>(&self,
|
||||
iter: I,
|
||||
guards: &StylesheetGuards)
|
||||
-> StrongRuleNode
|
||||
where I: Iterator<Item=(StyleSource, CascadeLevel)>,
|
||||
pub fn insert_ordered_rules_with_important<'a, I>(
|
||||
&self,
|
||||
iter: I,
|
||||
guards: &StylesheetGuards
|
||||
) -> StrongRuleNode
|
||||
where
|
||||
I: Iterator<Item=(StyleSource, CascadeLevel)>,
|
||||
{
|
||||
use self::CascadeLevel::*;
|
||||
let mut current = self.root.clone();
|
||||
|
@ -257,11 +259,11 @@ impl RuleTree {
|
|||
|
||||
/// Given a list of applicable declarations, insert the rules and return the
|
||||
/// corresponding rule node.
|
||||
pub fn compute_rule_node(&self,
|
||||
applicable_declarations: &mut ApplicableDeclarationList,
|
||||
guards: &StylesheetGuards)
|
||||
-> StrongRuleNode
|
||||
{
|
||||
pub fn compute_rule_node(
|
||||
&self,
|
||||
applicable_declarations: &mut ApplicableDeclarationList,
|
||||
guards: &StylesheetGuards
|
||||
) -> StrongRuleNode {
|
||||
let rules = applicable_declarations.drain().map(|d| d.order_and_level());
|
||||
let rule_node = self.insert_ordered_rules_with_important(rules, guards);
|
||||
rule_node
|
||||
|
@ -1321,32 +1323,6 @@ impl StrongRuleNode {
|
|||
.find(|node| node.cascade_level() == CascadeLevel::SMILOverride)
|
||||
.map(|node| node.get_animation_style())
|
||||
}
|
||||
|
||||
/// Returns AnimationRules that has processed during animation-only restyles.
|
||||
pub fn get_animation_rules(&self) -> AnimationRules {
|
||||
if cfg!(feature = "servo") {
|
||||
return AnimationRules(None, None);
|
||||
}
|
||||
|
||||
let mut animation = None;
|
||||
let mut transition = None;
|
||||
|
||||
for node in self.self_and_ancestors()
|
||||
.take_while(|node| node.cascade_level() >= CascadeLevel::Animations) {
|
||||
match node.cascade_level() {
|
||||
CascadeLevel::Animations => {
|
||||
debug_assert!(animation.is_none());
|
||||
animation = Some(node.get_animation_style())
|
||||
},
|
||||
CascadeLevel::Transitions => {
|
||||
debug_assert!(transition.is_none());
|
||||
transition = Some(node.get_animation_style())
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
AnimationRules(animation, transition)
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over a rule node and its ancestors.
|
||||
|
|
|
@ -75,7 +75,7 @@ use dom::{TElement, SendElement};
|
|||
use matching::{ChildCascadeRequirement, MatchMethods};
|
||||
use properties::ComputedValues;
|
||||
use selector_parser::RestyleDamage;
|
||||
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode, StyleRelations};
|
||||
use selectors::matching::{ElementSelectorFlags, VisitedHandlingMode};
|
||||
use smallvec::SmallVec;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
|
@ -494,11 +494,8 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
pub fn insert_if_possible(&mut self,
|
||||
element: &E,
|
||||
style: &ComputedValues,
|
||||
relations: StyleRelations,
|
||||
mut validation_data: ValidationData,
|
||||
validation_data: ValidationData,
|
||||
dom_depth: usize) {
|
||||
use selectors::matching::AFFECTED_BY_PRESENTATIONAL_HINTS;
|
||||
|
||||
let parent = match element.traversal_parent() {
|
||||
Some(element) => element,
|
||||
None => {
|
||||
|
@ -525,13 +522,6 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Take advantage of the information we've learned during
|
||||
// selector-matching.
|
||||
if !relations.intersects(AFFECTED_BY_PRESENTATIONAL_HINTS) {
|
||||
debug_assert!(validation_data.pres_hints.as_ref().map_or(true, |v| v.is_empty()));
|
||||
validation_data.pres_hints = Some(SmallVec::new());
|
||||
}
|
||||
|
||||
debug!("Inserting into cache: {:?} with parent {:?}", element, parent);
|
||||
|
||||
if self.dom_depth != dom_depth {
|
||||
|
|
505
components/style/style_resolver.rs
Normal file
505
components/style/style_resolver.rs
Normal file
|
@ -0,0 +1,505 @@
|
|||
/* 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/. */
|
||||
|
||||
//! 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;
|
||||
use log::LogLevel::Trace;
|
||||
use matching::{CascadeVisitedMode, MatchMethods};
|
||||
use properties::{AnimationRules, CascadeFlags, ComputedValues};
|
||||
use properties::{IS_ROOT_ELEMENT, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP};
|
||||
use properties::{VISITED_DEPENDENT_ONLY, cascade};
|
||||
use rule_tree::StrongRuleNode;
|
||||
use selector_parser::{PseudoElement, SelectorImpl};
|
||||
use selectors::matching::{ElementSelectorFlags, MatchingContext, MatchingMode, VisitedHandlingMode};
|
||||
use stylearc::Arc;
|
||||
use stylist::RuleInclusion;
|
||||
|
||||
/// A struct that takes care of resolving the style of a given element.
|
||||
pub struct StyleResolverForElement<'a, 'ctx, 'le, E>
|
||||
where
|
||||
'ctx: 'a,
|
||||
'le: 'ctx,
|
||||
E: TElement + MatchMethods + 'le,
|
||||
{
|
||||
element: E,
|
||||
context: &'a mut StyleContext<'ctx, E>,
|
||||
rule_inclusion: RuleInclusion,
|
||||
_marker: ::std::marker::PhantomData<&'le E>,
|
||||
}
|
||||
|
||||
struct MatchingResults {
|
||||
rule_node: StrongRuleNode,
|
||||
relevant_link_found: bool,
|
||||
}
|
||||
|
||||
/// The primary style of an element or an element-backed pseudo-element.
|
||||
pub struct PrimaryStyle {
|
||||
/// The style per se.
|
||||
pub style: Arc<ComputedValues>,
|
||||
}
|
||||
|
||||
fn with_default_parent_styles<E, F, R>(element: E, f: F) -> R
|
||||
where
|
||||
E: TElement,
|
||||
F: FnOnce(Option<&ComputedValues>, Option<&ComputedValues>) -> R,
|
||||
{
|
||||
let parent_el = element.inheritance_parent();
|
||||
let parent_data = parent_el.as_ref().and_then(|e| e.borrow_data());
|
||||
let parent_style = parent_data.as_ref().map(|d| {
|
||||
// Sometimes Gecko eagerly styles things without processing
|
||||
// pending restyles first. In general we'd like to avoid this,
|
||||
// but there can be good reasons (for example, needing to
|
||||
// construct a frame for some small piece of newly-added
|
||||
// content in order to do something specific with that frame,
|
||||
// but not wanting to flush all of layout).
|
||||
debug_assert!(cfg!(feature = "gecko") ||
|
||||
parent_el.unwrap().has_current_styles(d));
|
||||
d.styles.primary()
|
||||
});
|
||||
|
||||
let mut layout_parent_el = parent_el.clone();
|
||||
let layout_parent_data;
|
||||
let mut layout_parent_style = parent_style;
|
||||
if parent_style.map_or(false, |s| s.is_display_contents()) {
|
||||
layout_parent_el = Some(layout_parent_el.unwrap().layout_parent());
|
||||
layout_parent_data = layout_parent_el.as_ref().unwrap().borrow_data().unwrap();
|
||||
layout_parent_style = Some(layout_parent_data.styles.primary());
|
||||
}
|
||||
|
||||
f(parent_style.map(|s| &**s), layout_parent_style.map(|s| &**s))
|
||||
}
|
||||
|
||||
impl<'a, 'ctx, 'le, E> StyleResolverForElement<'a, 'ctx, 'le, E>
|
||||
where
|
||||
'ctx: 'a,
|
||||
'le: 'ctx,
|
||||
E: TElement + MatchMethods + 'le,
|
||||
{
|
||||
/// Trivially construct a new StyleResolverForElement.
|
||||
pub fn new(
|
||||
element: E,
|
||||
context: &'a mut StyleContext<'ctx, E>,
|
||||
rule_inclusion: RuleInclusion,
|
||||
) -> Self {
|
||||
Self {
|
||||
element,
|
||||
context,
|
||||
rule_inclusion,
|
||||
_marker: ::std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve just the style of a given element.
|
||||
pub fn resolve_primary_style(
|
||||
&mut self,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
) -> PrimaryStyle {
|
||||
let primary_results =
|
||||
self.match_primary(VisitedHandlingMode::AllLinksUnvisited);
|
||||
|
||||
let relevant_link_found = primary_results.relevant_link_found;
|
||||
|
||||
let visited_rules = if relevant_link_found {
|
||||
let visited_matching_results =
|
||||
self.match_primary(VisitedHandlingMode::RelevantLinkVisited);
|
||||
Some(visited_matching_results.rule_node)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut visited_style = None;
|
||||
let should_compute_visited_style =
|
||||
relevant_link_found ||
|
||||
parent_style.and_then(|s| s.get_visited_style()).is_some();
|
||||
|
||||
if should_compute_visited_style {
|
||||
visited_style = Some(self.cascade_style(
|
||||
visited_rules.as_ref(),
|
||||
/* style_if_visited = */ None,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Visited,
|
||||
/* pseudo = */ None,
|
||||
));
|
||||
}
|
||||
|
||||
let style = self.cascade_style(
|
||||
Some(&primary_results.rule_node),
|
||||
visited_style,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Unvisited,
|
||||
/* pseudo = */ None,
|
||||
);
|
||||
|
||||
PrimaryStyle { style, }
|
||||
}
|
||||
|
||||
|
||||
/// Resolve the style of a given element, and all its eager pseudo-elements.
|
||||
pub fn resolve_style(
|
||||
&mut self,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
) -> ElementStyles {
|
||||
use properties::longhands::display::computed_value::T as display;
|
||||
|
||||
let primary_style =
|
||||
self.resolve_primary_style(parent_style, layout_parent_style);
|
||||
|
||||
let mut pseudo_styles = EagerPseudoStyles::default();
|
||||
if primary_style.style.get_box().clone_display() == display::none {
|
||||
return ElementStyles {
|
||||
// FIXME(emilio): Remove the Option<>.
|
||||
primary: Some(primary_style.style),
|
||||
pseudos: pseudo_styles,
|
||||
}
|
||||
}
|
||||
|
||||
if self.element.implemented_pseudo_element().is_none() {
|
||||
let layout_parent_style_for_pseudo =
|
||||
if primary_style.style.is_display_contents() {
|
||||
layout_parent_style
|
||||
} else {
|
||||
Some(&*primary_style.style)
|
||||
};
|
||||
SelectorImpl::each_eagerly_cascaded_pseudo_element(|pseudo| {
|
||||
let pseudo_style = self.resolve_pseudo_style(
|
||||
&pseudo,
|
||||
&primary_style,
|
||||
layout_parent_style_for_pseudo
|
||||
);
|
||||
if let Some(style) = pseudo_style {
|
||||
pseudo_styles.set(&pseudo, style);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ElementStyles {
|
||||
// FIXME(emilio): Remove the Option<>.
|
||||
primary: Some(primary_style.style),
|
||||
pseudos: pseudo_styles,
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve an element's styles with the default inheritance parent/layout
|
||||
/// parents.
|
||||
pub fn resolve_style_with_default_parents(&mut self) -> ElementStyles {
|
||||
with_default_parent_styles(self.element, |parent_style, layout_parent_style| {
|
||||
self.resolve_style(parent_style, layout_parent_style)
|
||||
})
|
||||
}
|
||||
|
||||
/// Cascade a set of rules, using the default parent for inheritance.
|
||||
pub fn cascade_style_and_visited_with_default_parents(
|
||||
&mut self,
|
||||
inputs: CascadeInputs,
|
||||
) -> Arc<ComputedValues> {
|
||||
with_default_parent_styles(self.element, |parent_style, layout_parent_style| {
|
||||
self.cascade_style_and_visited(
|
||||
inputs,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
/* pseudo = */ None
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn cascade_style_and_visited(
|
||||
&mut self,
|
||||
inputs: CascadeInputs,
|
||||
parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
pseudo: Option<&PseudoElement>,
|
||||
) -> Arc<ComputedValues> {
|
||||
let mut style_if_visited = None;
|
||||
if parent_style.map_or(false, |s| s.get_visited_style().is_some()) ||
|
||||
inputs.visited_rules.is_some() {
|
||||
style_if_visited = Some(self.cascade_style(
|
||||
inputs.visited_rules.as_ref(),
|
||||
/* style_if_visited = */ None,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Visited,
|
||||
pseudo,
|
||||
));
|
||||
}
|
||||
self.cascade_style(
|
||||
inputs.rules.as_ref(),
|
||||
style_if_visited,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
CascadeVisitedMode::Unvisited,
|
||||
pseudo,
|
||||
)
|
||||
}
|
||||
|
||||
/// Cascade the element and pseudo-element styles with the default parents.
|
||||
pub fn cascade_styles_with_default_parents(
|
||||
&mut self,
|
||||
inputs: ElementCascadeInputs,
|
||||
) -> ElementStyles {
|
||||
use properties::longhands::display::computed_value::T as display;
|
||||
with_default_parent_styles(self.element, move |parent_style, layout_parent_style| {
|
||||
let primary_style = PrimaryStyle {
|
||||
style: self.cascade_style_and_visited(
|
||||
inputs.primary,
|
||||
parent_style,
|
||||
layout_parent_style,
|
||||
/* pseudo = */ None,
|
||||
),
|
||||
};
|
||||
|
||||
let mut pseudo_styles = EagerPseudoStyles::default();
|
||||
let pseudo_array = inputs.pseudos.into_array();
|
||||
if pseudo_array.is_none() ||
|
||||
primary_style.style.get_box().clone_display() == display::none {
|
||||
return ElementStyles {
|
||||
primary: Some(primary_style.style),
|
||||
pseudos: pseudo_styles,
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let layout_parent_style_for_pseudo =
|
||||
if primary_style.style.is_display_contents() {
|
||||
layout_parent_style
|
||||
} else {
|
||||
Some(&*primary_style.style)
|
||||
};
|
||||
|
||||
for (i, mut inputs) in pseudo_array.unwrap().iter_mut().enumerate() {
|
||||
if let Some(inputs) = inputs.take() {
|
||||
let pseudo = PseudoElement::from_eager_index(i);
|
||||
pseudo_styles.set(
|
||||
&pseudo,
|
||||
self.cascade_style_and_visited(
|
||||
inputs,
|
||||
Some(&*primary_style.style),
|
||||
layout_parent_style_for_pseudo,
|
||||
Some(&pseudo),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ElementStyles {
|
||||
primary: Some(primary_style.style),
|
||||
pseudos: pseudo_styles,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_pseudo_style(
|
||||
&mut self,
|
||||
pseudo: &PseudoElement,
|
||||
originating_element_style: &PrimaryStyle,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
) -> Option<Arc<ComputedValues>> {
|
||||
let rules = self.match_pseudo(
|
||||
&originating_element_style.style,
|
||||
pseudo,
|
||||
VisitedHandlingMode::AllLinksUnvisited
|
||||
);
|
||||
let rules = match rules {
|
||||
Some(rules) => rules,
|
||||
None => return None,
|
||||
};
|
||||
|
||||
let mut visited_rules = None;
|
||||
if originating_element_style.style.get_visited_style().is_some() {
|
||||
visited_rules = self.match_pseudo(
|
||||
&originating_element_style.style,
|
||||
pseudo,
|
||||
VisitedHandlingMode::RelevantLinkVisited,
|
||||
);
|
||||
}
|
||||
|
||||
Some(self.cascade_style_and_visited(
|
||||
CascadeInputs {
|
||||
rules: Some(rules),
|
||||
visited_rules
|
||||
},
|
||||
Some(&originating_element_style.style),
|
||||
layout_parent_style,
|
||||
Some(pseudo),
|
||||
))
|
||||
}
|
||||
|
||||
fn match_primary(
|
||||
&mut self,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
) -> MatchingResults {
|
||||
debug!("Match primary for {:?}, visited: {:?}",
|
||||
self.element, visited_handling);
|
||||
let mut applicable_declarations = ApplicableDeclarationList::new();
|
||||
|
||||
let map = &mut self.context.thread_local.selector_flags;
|
||||
let bloom_filter = self.context.thread_local.bloom_filter.filter();
|
||||
let mut matching_context =
|
||||
MatchingContext::new_for_visited(
|
||||
MatchingMode::Normal,
|
||||
Some(bloom_filter),
|
||||
visited_handling,
|
||||
self.context.shared.quirks_mode
|
||||
);
|
||||
|
||||
let stylist = &self.context.shared.stylist;
|
||||
let implemented_pseudo = self.element.implemented_pseudo_element();
|
||||
{
|
||||
let resolving_element = self.element;
|
||||
let mut set_selector_flags = |element: &E, flags: ElementSelectorFlags| {
|
||||
resolving_element.apply_selector_flags(map, element, flags);
|
||||
};
|
||||
|
||||
// Compute the primary rule node.
|
||||
stylist.push_applicable_declarations(
|
||||
&self.element,
|
||||
implemented_pseudo.as_ref(),
|
||||
self.element.style_attribute(),
|
||||
self.element.get_smil_override(),
|
||||
self.element.get_animation_rules(),
|
||||
self.rule_inclusion,
|
||||
&mut applicable_declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags,
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME(emilio): This is a hack for animations, and should go away.
|
||||
self.element.unset_dirty_style_attribute();
|
||||
|
||||
let relevant_link_found = matching_context.relevant_link_found;
|
||||
let rule_node = stylist.rule_tree().compute_rule_node(
|
||||
&mut applicable_declarations,
|
||||
&self.context.shared.guards
|
||||
);
|
||||
|
||||
if log_enabled!(Trace) {
|
||||
trace!("Matched rules:");
|
||||
for rn in rule_node.self_and_ancestors() {
|
||||
let source = rn.style_source();
|
||||
if source.is_some() {
|
||||
trace!(" > {:?}", source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MatchingResults { rule_node, relevant_link_found }
|
||||
}
|
||||
|
||||
fn match_pseudo(
|
||||
&mut self,
|
||||
originating_element_style: &ComputedValues,
|
||||
pseudo_element: &PseudoElement,
|
||||
visited_handling: VisitedHandlingMode,
|
||||
) -> Option<StrongRuleNode> {
|
||||
debug!("Match pseudo {:?} for {:?}, visited: {:?}",
|
||||
self.element, pseudo_element, visited_handling);
|
||||
debug_assert!(pseudo_element.is_eager() || pseudo_element.is_lazy());
|
||||
debug_assert!(self.element.implemented_pseudo_element().is_none(),
|
||||
"Element pseudos can't have any other pseudo.");
|
||||
|
||||
let mut applicable_declarations = ApplicableDeclarationList::new();
|
||||
|
||||
let stylist = &self.context.shared.stylist;
|
||||
|
||||
if !self.element.may_generate_pseudo(pseudo_element, originating_element_style) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let bloom_filter = self.context.thread_local.bloom_filter.filter();
|
||||
|
||||
let mut matching_context =
|
||||
MatchingContext::new_for_visited(
|
||||
MatchingMode::ForStatelessPseudoElement,
|
||||
Some(bloom_filter),
|
||||
visited_handling,
|
||||
self.context.shared.quirks_mode
|
||||
);
|
||||
|
||||
let map = &mut self.context.thread_local.selector_flags;
|
||||
let resolving_element = self.element;
|
||||
let mut set_selector_flags = |element: &E, flags: ElementSelectorFlags| {
|
||||
resolving_element.apply_selector_flags(map, element, flags);
|
||||
};
|
||||
|
||||
// NB: We handle animation rules for ::before and ::after when
|
||||
// traversing them.
|
||||
stylist.push_applicable_declarations(
|
||||
&self.element,
|
||||
Some(pseudo_element),
|
||||
None,
|
||||
None,
|
||||
AnimationRules(None, None),
|
||||
self.rule_inclusion,
|
||||
&mut applicable_declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags
|
||||
);
|
||||
|
||||
if applicable_declarations.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let rule_node = stylist.rule_tree().compute_rule_node(
|
||||
&mut applicable_declarations,
|
||||
&self.context.shared.guards
|
||||
);
|
||||
|
||||
Some(rule_node)
|
||||
}
|
||||
|
||||
fn cascade_style(
|
||||
&mut self,
|
||||
rules: Option<&StrongRuleNode>,
|
||||
style_if_visited: Option<Arc<ComputedValues>>,
|
||||
mut parent_style: Option<&ComputedValues>,
|
||||
layout_parent_style: Option<&ComputedValues>,
|
||||
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() {
|
||||
cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP);
|
||||
}
|
||||
if cascade_visited.visited_dependent_only() {
|
||||
parent_style = parent_style.map(|s| {
|
||||
s.get_visited_style().map(|s| &**s).unwrap_or(s)
|
||||
});
|
||||
cascade_flags.insert(VISITED_DEPENDENT_ONLY);
|
||||
}
|
||||
if self.element.is_native_anonymous() || pseudo.is_some() {
|
||||
cascade_flags.insert(PROHIBIT_DISPLAY_CONTENTS);
|
||||
} else if self.element.is_root() {
|
||||
cascade_flags.insert(IS_ROOT_ELEMENT);
|
||||
}
|
||||
|
||||
let values =
|
||||
Arc::new(cascade(
|
||||
self.context.shared.stylist.device(),
|
||||
rules.unwrap_or(self.context.shared.stylist.rule_tree().root()),
|
||||
&self.context.shared.guards,
|
||||
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
|
||||
}
|
||||
}
|
|
@ -15,19 +15,18 @@ use font_metrics::FontMetricsProvider;
|
|||
use gecko_bindings::structs::{nsIAtom, StyleRuleInclusion};
|
||||
use invalidation::element::invalidation_map::InvalidationMap;
|
||||
use invalidation::media_queries::{EffectiveMediaQueryResults, ToMediaListKey};
|
||||
use matching::CascadeVisitedMode;
|
||||
use media_queries::Device;
|
||||
use properties::{self, CascadeFlags, ComputedValues};
|
||||
use properties::{AnimationRules, PropertyDeclarationBlock};
|
||||
#[cfg(feature = "servo")]
|
||||
use properties::INHERIT_ALL;
|
||||
use rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource};
|
||||
use rule_tree::{CascadeLevel, RuleTree, StyleSource};
|
||||
use selector_map::{SelectorMap, SelectorMapEntry};
|
||||
use selector_parser::{SelectorImpl, PseudoElement};
|
||||
use selectors::attr::NamespaceConstraint;
|
||||
use selectors::bloom::BloomFilter;
|
||||
use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode};
|
||||
use selectors::matching::{VisitedHandlingMode, AFFECTED_BY_PRESENTATIONAL_HINTS};
|
||||
use selectors::matching::VisitedHandlingMode;
|
||||
use selectors::parser::{AncestorHashes, Combinator, Component, Selector, SelectorAndHashes};
|
||||
use selectors::parser::{SelectorIter, SelectorMethods};
|
||||
use selectors::sink::Push;
|
||||
|
@ -607,13 +606,12 @@ impl Stylist {
|
|||
|
||||
let rule_node = match self.precomputed_pseudo_element_decls.get(pseudo) {
|
||||
Some(declarations) => {
|
||||
// FIXME(emilio): When we've taken rid of the cascade we can just
|
||||
// use into_iter.
|
||||
self.rule_tree.insert_ordered_rules_with_important(
|
||||
declarations.into_iter().map(|a| (a.source.clone(), a.level())),
|
||||
guards)
|
||||
guards
|
||||
)
|
||||
}
|
||||
None => self.rule_tree.root(),
|
||||
None => self.rule_tree.root().clone(),
|
||||
};
|
||||
|
||||
// NOTE(emilio): We skip calculating the proper layout parent style
|
||||
|
@ -720,24 +718,30 @@ impl Stylist {
|
|||
{
|
||||
// We may have only visited rules in cases when we are actually
|
||||
// resolving, not probing, pseudo-element style.
|
||||
if !inputs.has_rules() && !inputs.has_visited_rules() {
|
||||
if inputs.rules.is_none() && inputs.visited_rules.is_none() {
|
||||
return None
|
||||
}
|
||||
|
||||
// We need to compute visited values if we have visited rules or if our
|
||||
// parent has visited values.
|
||||
let visited_values = if inputs.has_visited_rules() || parent_style.get_visited_style().is_some() {
|
||||
let visited_values = if inputs.visited_rules.is_some() || parent_style.get_visited_style().is_some() {
|
||||
// Slightly annoying: we know that inputs has either rules or
|
||||
// visited rules, but we can't do inputs.rules() up front because
|
||||
// maybe it just has visited rules, so can't unwrap_or.
|
||||
let rule_node = match inputs.get_visited_rules() {
|
||||
let rule_node = match inputs.visited_rules.as_ref() {
|
||||
Some(rules) => rules,
|
||||
None => inputs.rules()
|
||||
None => inputs.rules.as_ref().unwrap(),
|
||||
};
|
||||
// We want to use the visited bits (if any) from our parent style as
|
||||
// our parent.
|
||||
let mode = CascadeVisitedMode::Visited;
|
||||
let inherited_style = mode.values(parent_style);
|
||||
let inherited_style =
|
||||
parent_style.get_visited_style().unwrap_or(&*parent_style);
|
||||
|
||||
// FIXME(emilio): The lack of layout_parent_style here could be
|
||||
// worrying, but we're probably dropping the display fixup for
|
||||
// pseudos other than before and after, so it's probably ok.
|
||||
//
|
||||
// (Though the flags don't indicate so!)
|
||||
let computed =
|
||||
properties::cascade(&self.device,
|
||||
rule_node,
|
||||
|
@ -757,13 +761,7 @@ impl Stylist {
|
|||
|
||||
// We may not have non-visited rules, if we only had visited ones. In
|
||||
// that case we want to use the root rulenode for our non-visited rules.
|
||||
let root;
|
||||
let rules = if let Some(rules) = inputs.get_rules() {
|
||||
rules
|
||||
} else {
|
||||
root = self.rule_tree.root();
|
||||
&root
|
||||
};
|
||||
let rules = inputs.rules.as_ref().unwrap_or(self.rule_tree.root());
|
||||
|
||||
// Read the comment on `precomputed_values_for_pseudo` to see why it's
|
||||
// difficult to assert that display: contents nodes never arrive here
|
||||
|
@ -839,27 +837,27 @@ impl Stylist {
|
|||
MatchingContext::new(MatchingMode::ForStatelessPseudoElement,
|
||||
None,
|
||||
self.quirks_mode);
|
||||
self.push_applicable_declarations(element,
|
||||
Some(&pseudo),
|
||||
None,
|
||||
None,
|
||||
AnimationRules(None, None),
|
||||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags);
|
||||
|
||||
self.push_applicable_declarations(
|
||||
element,
|
||||
Some(&pseudo),
|
||||
None,
|
||||
None,
|
||||
AnimationRules(None, None),
|
||||
rule_inclusion,
|
||||
&mut declarations,
|
||||
&mut matching_context,
|
||||
&mut set_selector_flags
|
||||
);
|
||||
|
||||
if !declarations.is_empty() {
|
||||
let rule_node = self.rule_tree.insert_ordered_rules_with_important(
|
||||
declarations.into_iter().map(|a| a.order_and_level()),
|
||||
guards);
|
||||
if rule_node != self.rule_tree.root() {
|
||||
inputs.set_rules(VisitedHandlingMode::AllLinksUnvisited,
|
||||
rule_node);
|
||||
}
|
||||
};
|
||||
let rule_node =
|
||||
self.rule_tree.compute_rule_node(&mut declarations, guards);
|
||||
debug_assert!(rule_node != *self.rule_tree.root());
|
||||
inputs.rules = Some(rule_node);
|
||||
}
|
||||
|
||||
if is_probe && !inputs.has_rules() {
|
||||
if is_probe && inputs.rules.is_none() {
|
||||
// When probing, don't compute visited styles if we have no
|
||||
// unvisited styles.
|
||||
return inputs;
|
||||
|
@ -886,9 +884,8 @@ impl Stylist {
|
|||
self.rule_tree.insert_ordered_rules_with_important(
|
||||
declarations.into_iter().map(|a| a.order_and_level()),
|
||||
guards);
|
||||
if rule_node != self.rule_tree.root() {
|
||||
inputs.set_rules(VisitedHandlingMode::RelevantLinkVisited,
|
||||
rule_node);
|
||||
if rule_node != *self.rule_tree.root() {
|
||||
inputs.visited_rules = Some(rule_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1148,7 +1145,6 @@ impl Stylist {
|
|||
self.quirks_mode,
|
||||
flags_setter,
|
||||
CascadeLevel::UANormal);
|
||||
debug!("UA normal: {:?}", context.relations);
|
||||
|
||||
if pseudo_element.is_none() && !only_default_rules {
|
||||
// Step 2: Presentational hints.
|
||||
|
@ -1163,12 +1159,7 @@ impl Stylist {
|
|||
assert_eq!(declaration.level(), CascadeLevel::PresHints);
|
||||
}
|
||||
}
|
||||
// Note the existence of presentational attributes so that the
|
||||
// style sharing cache can avoid re-querying them if they don't
|
||||
// exist.
|
||||
context.relations |= AFFECTED_BY_PRESENTATIONAL_HINTS;
|
||||
}
|
||||
debug!("preshints: {:?}", context.relations);
|
||||
}
|
||||
|
||||
// NB: the following condition, although it may look somewhat
|
||||
|
@ -1188,7 +1179,6 @@ impl Stylist {
|
|||
self.quirks_mode,
|
||||
flags_setter,
|
||||
CascadeLevel::UserNormal);
|
||||
debug!("user normal: {:?}", context.relations);
|
||||
} else {
|
||||
debug!("skipping user rules");
|
||||
}
|
||||
|
@ -1197,7 +1187,6 @@ impl Stylist {
|
|||
let cut_off_inheritance =
|
||||
element.get_declarations_from_xbl_bindings(pseudo_element,
|
||||
applicable_declarations);
|
||||
debug!("XBL: {:?}", context.relations);
|
||||
|
||||
if rule_hash_target.matches_user_and_author_rules() && !only_default_rules {
|
||||
// Gecko skips author normal rules if cutting off inheritance.
|
||||
|
@ -1211,7 +1200,6 @@ impl Stylist {
|
|||
self.quirks_mode,
|
||||
flags_setter,
|
||||
CascadeLevel::AuthorNormal);
|
||||
debug!("author normal: {:?}", context.relations);
|
||||
} else {
|
||||
debug!("skipping author normal rules due to cut off inheritance");
|
||||
}
|
||||
|
@ -1227,7 +1215,6 @@ impl Stylist {
|
|||
ApplicableDeclarationBlock::from_declarations(sa.clone(),
|
||||
CascadeLevel::StyleAttributeNormal));
|
||||
}
|
||||
debug!("style attr: {:?}", context.relations);
|
||||
|
||||
// Step 5: SMIL override.
|
||||
// Declarations from SVG SMIL animation elements.
|
||||
|
@ -1237,7 +1224,6 @@ impl Stylist {
|
|||
ApplicableDeclarationBlock::from_declarations(so.clone(),
|
||||
CascadeLevel::SMILOverride));
|
||||
}
|
||||
debug!("SMIL: {:?}", context.relations);
|
||||
|
||||
// Step 6: Animations.
|
||||
// The animations sheet (CSS animations, script-generated animations,
|
||||
|
@ -1248,7 +1234,6 @@ impl Stylist {
|
|||
ApplicableDeclarationBlock::from_declarations(anim.clone(),
|
||||
CascadeLevel::Animations));
|
||||
}
|
||||
debug!("animation: {:?}", context.relations);
|
||||
} else {
|
||||
debug!("skipping style attr and SMIL & animation rules");
|
||||
}
|
||||
|
@ -1267,12 +1252,9 @@ impl Stylist {
|
|||
ApplicableDeclarationBlock::from_declarations(anim.clone(),
|
||||
CascadeLevel::Transitions));
|
||||
}
|
||||
debug!("transition: {:?}", context.relations);
|
||||
} else {
|
||||
debug!("skipping transition rules");
|
||||
}
|
||||
|
||||
debug!("push_applicable_declarations: shareable: {:?}", context.relations);
|
||||
}
|
||||
|
||||
/// Given an id, returns whether there might be any rules for that id in any
|
||||
|
@ -1295,12 +1277,6 @@ impl Stylist {
|
|||
&self.animations
|
||||
}
|
||||
|
||||
/// Returns the rule root node.
|
||||
#[inline]
|
||||
pub fn rule_tree_root(&self) -> StrongRuleNode {
|
||||
self.rule_tree.root()
|
||||
}
|
||||
|
||||
/// Computes the match results of a given element against the set of
|
||||
/// revalidation selectors.
|
||||
pub fn match_revalidation_selectors<E, F>(&self,
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
use atomic_refcell::AtomicRefCell;
|
||||
use context::{ElementCascadeInputs, StyleContext, SharedStyleContext};
|
||||
use data::{ElementData, ElementStyles};
|
||||
use dom::{DirtyDescendants, NodeInfo, OpaqueNode, TElement, TNode};
|
||||
use dom::{NodeInfo, OpaqueNode, TElement, TNode};
|
||||
use invalidation::element::restyle_hints::{RECASCADE_SELF, RECASCADE_DESCENDANTS, RestyleHint};
|
||||
use matching::{ChildCascadeRequirement, MatchMethods};
|
||||
use sharing::{StyleSharingBehavior, StyleSharingTarget};
|
||||
#[cfg(feature = "servo")] use servo_config::opts;
|
||||
use sharing::StyleSharingTarget;
|
||||
use smallvec::SmallVec;
|
||||
use style_resolver::StyleResolverForElement;
|
||||
use stylist::RuleInclusion;
|
||||
|
||||
/// A per-traversal-level chunk of data. This is sent down by the traversal, and
|
||||
/// currently only holds the dom depth for the bloom filter.
|
||||
|
@ -41,8 +42,6 @@ bitflags! {
|
|||
/// Traverse and update all elements with CSS animations since
|
||||
/// @keyframes rules may have changed
|
||||
const FOR_CSS_RULE_CHANGES = 0x08,
|
||||
/// Only include user agent style sheets when selector matching.
|
||||
const FOR_DEFAULT_STYLES = 0x10,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,12 +65,6 @@ impl TraversalFlags {
|
|||
pub fn for_css_rule_changes(&self) -> bool {
|
||||
self.contains(FOR_CSS_RULE_CHANGES)
|
||||
}
|
||||
|
||||
/// Returns true if the traversal is to compute the default computed styles
|
||||
/// for an element.
|
||||
pub fn for_default_styles(&self) -> bool {
|
||||
self.contains(FOR_DEFAULT_STYLES)
|
||||
}
|
||||
}
|
||||
|
||||
/// This structure exists to enforce that callers invoke pre_traverse, and also
|
||||
|
@ -126,6 +119,8 @@ impl TraversalDriver {
|
|||
|
||||
#[cfg(feature = "servo")]
|
||||
fn is_servo_nonincremental_layout() -> bool {
|
||||
use servo_config::opts;
|
||||
|
||||
opts::get().nonincremental_layout
|
||||
}
|
||||
|
||||
|
@ -520,151 +515,87 @@ pub trait DomTraversal<E: TElement> : Sync {
|
|||
fn is_parallel(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Helper for the function below.
|
||||
fn resolve_style_internal<E, F>(
|
||||
context: &mut StyleContext<E>,
|
||||
element: E, ensure_data: &F
|
||||
) -> Option<E>
|
||||
where E: TElement,
|
||||
F: Fn(E),
|
||||
{
|
||||
ensure_data(element);
|
||||
let mut data = element.mutate_data().unwrap();
|
||||
let mut display_none_root = None;
|
||||
|
||||
// If the Element isn't styled, we need to compute its style.
|
||||
if !data.has_styles() {
|
||||
// Compute the parent style if necessary.
|
||||
let parent = element.traversal_parent();
|
||||
if let Some(p) = parent {
|
||||
display_none_root = resolve_style_internal(context, p, ensure_data);
|
||||
}
|
||||
|
||||
// Maintain the bloom filter. If it doesn't exist, we need to build it
|
||||
// from scratch. Otherwise we just need to push the parent.
|
||||
if context.thread_local.bloom_filter.is_empty() {
|
||||
context.thread_local.bloom_filter.rebuild(element);
|
||||
} else {
|
||||
context.thread_local.bloom_filter.push(parent.unwrap());
|
||||
context.thread_local.bloom_filter.assert_complete(element);
|
||||
}
|
||||
|
||||
// Compute our style.
|
||||
context.thread_local.begin_element(element, &data);
|
||||
element.match_and_cascade(context,
|
||||
&mut data,
|
||||
StyleSharingBehavior::Disallow);
|
||||
context.thread_local.end_element(element);
|
||||
|
||||
if !context.shared.traversal_flags.for_default_styles() {
|
||||
// Conservatively mark us as having dirty descendants, since there
|
||||
// might be other unstyled siblings we miss when walking straight up
|
||||
// the parent chain.
|
||||
//
|
||||
// No need to do this if we're computing default styles, since
|
||||
// resolve_default_style will want the tree to be left as it is.
|
||||
unsafe { element.note_descendants::<DirtyDescendants>() };
|
||||
}
|
||||
}
|
||||
|
||||
// If we're display:none and none of our ancestors are, we're the root of a
|
||||
// display:none subtree.
|
||||
if display_none_root.is_none() && data.styles.is_display_none() {
|
||||
display_none_root = Some(element);
|
||||
}
|
||||
|
||||
return display_none_root
|
||||
}
|
||||
|
||||
/// Manually resolve style by sequentially walking up the parent chain to the
|
||||
/// first styled Element, ignoring pending restyles. The resolved style is made
|
||||
/// available via a callback, and can be dropped by the time this function
|
||||
/// returns in the display:none subtree case.
|
||||
pub fn resolve_style<E, F, G, H>(context: &mut StyleContext<E>, element: E,
|
||||
ensure_data: &F, clear_data: &G, callback: H)
|
||||
where E: TElement,
|
||||
F: Fn(E),
|
||||
G: Fn(E),
|
||||
H: FnOnce(&ElementStyles)
|
||||
pub fn resolve_style<E>(
|
||||
context: &mut StyleContext<E>,
|
||||
element: E,
|
||||
rule_inclusion: RuleInclusion,
|
||||
) -> ElementStyles
|
||||
where
|
||||
E: TElement,
|
||||
{
|
||||
use style_resolver::StyleResolverForElement;
|
||||
|
||||
debug_assert!(rule_inclusion == RuleInclusion::DefaultOnly ||
|
||||
element.borrow_data().map_or(true, |d| !d.has_styles()),
|
||||
"Why are we here?");
|
||||
let mut ancestors_requiring_style_resolution = SmallVec::<[E; 16]>::new();
|
||||
|
||||
// Clear the bloom filter, just in case the caller is reusing TLS.
|
||||
context.thread_local.bloom_filter.clear();
|
||||
|
||||
// Resolve styles up the tree.
|
||||
let display_none_root = resolve_style_internal(context, element, ensure_data);
|
||||
|
||||
// Make them available for the scope of the callback. The callee may use the
|
||||
// argument, or perform any other processing that requires the styles to
|
||||
// exist on the Element.
|
||||
callback(&element.borrow_data().unwrap().styles);
|
||||
|
||||
// Clear any styles in display:none subtrees or subtrees not in the
|
||||
// document, to leave the tree in a valid state. For display:none subtrees,
|
||||
// we leave the styles on the display:none root, but for subtrees not in the
|
||||
// document, we clear styles all the way up to the root of the disconnected
|
||||
// subtree.
|
||||
let in_doc = element.as_node().is_in_doc();
|
||||
if !in_doc || display_none_root.is_some() {
|
||||
let mut curr = element;
|
||||
loop {
|
||||
unsafe {
|
||||
curr.unset_dirty_descendants();
|
||||
curr.unset_animation_only_dirty_descendants();
|
||||
}
|
||||
if in_doc && curr == display_none_root.unwrap() {
|
||||
break;
|
||||
}
|
||||
clear_data(curr);
|
||||
curr = match curr.traversal_parent() {
|
||||
Some(parent) => parent,
|
||||
None => break,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Manually resolve default styles for the given Element, which are the styles
|
||||
/// only taking into account user agent and user cascade levels. The resolved
|
||||
/// style is made available via a callback, and will be dropped by the time this
|
||||
/// function returns.
|
||||
pub fn resolve_default_style<E, F, G, H>(
|
||||
context: &mut StyleContext<E>,
|
||||
element: E,
|
||||
ensure_data: &F,
|
||||
set_data: &G,
|
||||
callback: H
|
||||
)
|
||||
where
|
||||
E: TElement,
|
||||
F: Fn(E),
|
||||
G: Fn(E, Option<ElementData>) -> Option<ElementData>,
|
||||
H: FnOnce(&ElementStyles),
|
||||
{
|
||||
// Save and clear out element data from the element and its ancestors.
|
||||
let mut old_data: SmallVec<[(E, Option<ElementData>); 8]> = SmallVec::new();
|
||||
{
|
||||
let mut e = element;
|
||||
loop {
|
||||
old_data.push((e, set_data(e, None)));
|
||||
match e.traversal_parent() {
|
||||
Some(parent) => e = parent,
|
||||
None => break,
|
||||
let mut style = None;
|
||||
let mut ancestor = element.traversal_parent();
|
||||
while let Some(current) = ancestor {
|
||||
if rule_inclusion == RuleInclusion::All {
|
||||
if let Some(data) = element.borrow_data() {
|
||||
if let Some(ancestor_style) = data.styles.get_primary() {
|
||||
style = Some(ancestor_style.clone());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ancestors_requiring_style_resolution.push(current);
|
||||
ancestor = current.traversal_parent();
|
||||
}
|
||||
|
||||
// Resolve styles up the tree.
|
||||
resolve_style_internal(context, element, ensure_data);
|
||||
|
||||
// Make them available for the scope of the callback. The callee may use the
|
||||
// argument, or perform any other processing that requires the styles to
|
||||
// exist on the Element.
|
||||
callback(&element.borrow_data().unwrap().styles);
|
||||
|
||||
// Swap the old element data back into the element and its ancestors.
|
||||
for entry in old_data {
|
||||
set_data(entry.0, entry.1);
|
||||
if let Some(ancestor) = ancestor {
|
||||
context.thread_local.bloom_filter.rebuild(ancestor);
|
||||
context.thread_local.bloom_filter.push(ancestor);
|
||||
}
|
||||
|
||||
let mut layout_parent_style = style.clone();
|
||||
while let Some(style) = layout_parent_style.take() {
|
||||
if !style.is_display_contents() {
|
||||
layout_parent_style = Some(style);
|
||||
break;
|
||||
}
|
||||
|
||||
ancestor = ancestor.unwrap().traversal_parent();
|
||||
layout_parent_style = ancestor.map(|a| {
|
||||
a.borrow_data().unwrap().styles.primary().clone()
|
||||
});
|
||||
}
|
||||
|
||||
for ancestor in ancestors_requiring_style_resolution.iter().rev() {
|
||||
context.thread_local.bloom_filter.assert_complete(*ancestor);
|
||||
|
||||
let primary_style =
|
||||
StyleResolverForElement::new(*ancestor, context, rule_inclusion)
|
||||
.resolve_primary_style(
|
||||
style.as_ref().map(|s| &**s),
|
||||
layout_parent_style.as_ref().map(|s| &**s)
|
||||
);
|
||||
|
||||
let is_display_contents = primary_style.style.is_display_contents();
|
||||
|
||||
style = Some(primary_style.style);
|
||||
if !is_display_contents {
|
||||
layout_parent_style = style.clone();
|
||||
}
|
||||
|
||||
context.thread_local.bloom_filter.push(*ancestor);
|
||||
}
|
||||
|
||||
context.thread_local.bloom_filter.assert_complete(element);
|
||||
StyleResolverForElement::new(element, context, rule_inclusion)
|
||||
.resolve_style(
|
||||
style.as_ref().map(|s| &**s),
|
||||
layout_parent_style.as_ref().map(|s| &**s)
|
||||
)
|
||||
}
|
||||
|
||||
/// Calculates the style for a single node.
|
||||
|
@ -827,7 +758,8 @@ where
|
|||
data.restyle.set_restyled();
|
||||
}
|
||||
|
||||
match kind {
|
||||
let mut important_rules_changed = false;
|
||||
let new_styles = match kind {
|
||||
MatchAndCascade => {
|
||||
debug_assert!(!context.shared.traversal_flags.for_animation_only(),
|
||||
"MatchAndCascade shouldn't be processed during \
|
||||
|
@ -852,35 +784,62 @@ where
|
|||
|
||||
context.thread_local.statistics.elements_matched += 1;
|
||||
|
||||
important_rules_changed = true;
|
||||
|
||||
// Perform the matching and cascading.
|
||||
element.match_and_cascade(
|
||||
context,
|
||||
data,
|
||||
StyleSharingBehavior::Allow
|
||||
)
|
||||
let new_styles =
|
||||
StyleResolverForElement::new(element, context, RuleInclusion::All)
|
||||
.resolve_style_with_default_parents();
|
||||
|
||||
// If we previously tried to match this element against the cache,
|
||||
// the revalidation match results will already be cached. Otherwise
|
||||
// we'll have None, and compute them later on-demand.
|
||||
//
|
||||
// If we do have the results, grab them here to satisfy the borrow
|
||||
// checker.
|
||||
let validation_data =
|
||||
context.thread_local
|
||||
.current_element_info
|
||||
.as_mut().unwrap()
|
||||
.validation_data
|
||||
.take();
|
||||
|
||||
let dom_depth = context.thread_local.bloom_filter.matching_depth();
|
||||
context.thread_local
|
||||
.style_sharing_candidate_cache
|
||||
.insert_if_possible(
|
||||
&element,
|
||||
new_styles.primary(),
|
||||
validation_data,
|
||||
dom_depth
|
||||
);
|
||||
|
||||
new_styles
|
||||
}
|
||||
CascadeWithReplacements(flags) => {
|
||||
// Skipping full matching, load cascade inputs from previous values.
|
||||
*context.cascade_inputs_mut() =
|
||||
let mut cascade_inputs =
|
||||
ElementCascadeInputs::new_from_element_data(data);
|
||||
let important_rules_changed = element.replace_rules(flags, context);
|
||||
element.cascade_primary_and_pseudos(
|
||||
context,
|
||||
data,
|
||||
important_rules_changed
|
||||
)
|
||||
important_rules_changed =
|
||||
element.replace_rules(flags, context, &mut cascade_inputs);
|
||||
StyleResolverForElement::new(element, context, RuleInclusion::All)
|
||||
.cascade_styles_with_default_parents(cascade_inputs)
|
||||
}
|
||||
CascadeOnly => {
|
||||
// Skipping full matching, load cascade inputs from previous values.
|
||||
*context.cascade_inputs_mut() =
|
||||
let cascade_inputs =
|
||||
ElementCascadeInputs::new_from_element_data(data);
|
||||
element.cascade_primary_and_pseudos(
|
||||
context,
|
||||
data,
|
||||
/* important_rules_changed = */ false
|
||||
)
|
||||
StyleResolverForElement::new(element, context, RuleInclusion::All)
|
||||
.cascade_styles_with_default_parents(cascade_inputs)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
element.finish_restyle(
|
||||
context,
|
||||
data,
|
||||
new_styles,
|
||||
important_rules_changed
|
||||
)
|
||||
}
|
||||
|
||||
fn preprocess_children<E, D>(
|
||||
|
|
|
@ -113,8 +113,8 @@ use style::stylist::RuleInclusion;
|
|||
use style::thread_state;
|
||||
use style::timer::Timer;
|
||||
use style::traversal::{ANIMATION_ONLY, DomTraversal, FOR_CSS_RULE_CHANGES, FOR_RECONSTRUCT};
|
||||
use style::traversal::{FOR_DEFAULT_STYLES, TraversalDriver, TraversalFlags, UNSTYLED_CHILDREN_ONLY};
|
||||
use style::traversal::{resolve_style, resolve_default_style};
|
||||
use style::traversal::{TraversalDriver, TraversalFlags, UNSTYLED_CHILDREN_ONLY};
|
||||
use style::traversal::resolve_style;
|
||||
use style::values::{CustomIdent, KeyframesName};
|
||||
use style::values::computed::Context;
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ToCss};
|
||||
|
@ -654,42 +654,70 @@ pub extern "C" fn Servo_AnimationValue_Uncompute(value: RawServoAnimationValueBo
|
|||
#[no_mangle]
|
||||
pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawServoStyleSetBorrowed,
|
||||
element: RawGeckoElementBorrowed,
|
||||
computed_values: ServoComputedValuesBorrowed,
|
||||
snapshots: *const ServoElementSnapshotTable,
|
||||
pseudo_type: CSSPseudoElementType)
|
||||
-> ServoComputedValuesStrong
|
||||
{
|
||||
use style::matching::MatchMethods;
|
||||
use style::style_resolver::StyleResolverForElement;
|
||||
|
||||
debug_assert!(!snapshots.is_null());
|
||||
let computed_values = ComputedValues::as_arc(&computed_values);
|
||||
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let shared_context = create_shared_context(&global_style_data,
|
||||
&guard,
|
||||
&doc_data,
|
||||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots });
|
||||
let element = GeckoElement(element);
|
||||
let element_data = element.borrow_data().unwrap();
|
||||
let styles = &element_data.styles;
|
||||
|
||||
let pseudo = PseudoElement::from_pseudo_type(pseudo_type);
|
||||
let pseudos = &styles.pseudos;
|
||||
let pseudo_style = match pseudo {
|
||||
Some(ref p) => {
|
||||
let style = pseudos.get(p);
|
||||
debug_assert!(style.is_some());
|
||||
style
|
||||
}
|
||||
None => None,
|
||||
let rules = match computed_values.rules {
|
||||
None => return computed_values.clone().into_strong(),
|
||||
Some(ref rules) => rules,
|
||||
};
|
||||
|
||||
let provider = get_metrics_provider_for_product();
|
||||
element.get_base_style(&shared_context,
|
||||
&provider,
|
||||
styles.primary(),
|
||||
pseudo_style)
|
||||
.into_strong()
|
||||
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
|
||||
let without_animations =
|
||||
doc_data.stylist.rule_tree().remove_animation_rules(rules);
|
||||
|
||||
if without_animations == *rules {
|
||||
return computed_values.clone().into_strong();
|
||||
}
|
||||
|
||||
let element = GeckoElement(element);
|
||||
|
||||
let element_data = match element.borrow_data() {
|
||||
Some(data) => data,
|
||||
None => return computed_values.clone().into_strong(),
|
||||
};
|
||||
let styles = &element_data.styles;
|
||||
|
||||
if let Some(pseudo) = PseudoElement::from_pseudo_type(pseudo_type) {
|
||||
// This style already doesn't have animations.
|
||||
return styles
|
||||
.pseudos
|
||||
.get(&pseudo)
|
||||
.expect("GetBaseComputedValuesForElement for an unexisting pseudo?")
|
||||
.clone().into_strong();
|
||||
}
|
||||
|
||||
let global_style_data = &*GLOBAL_STYLE_DATA;
|
||||
let guard = global_style_data.shared_lock.read();
|
||||
let shared = create_shared_context(&global_style_data,
|
||||
&guard,
|
||||
&doc_data,
|
||||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots });
|
||||
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
||||
let mut context = StyleContext {
|
||||
shared: &shared,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
|
||||
// This currently ignores visited styles, which seems acceptable, as
|
||||
// existing browsers don't appear to animate visited styles.
|
||||
let inputs =
|
||||
CascadeInputs {
|
||||
rules: Some(without_animations),
|
||||
visited_rules: None,
|
||||
};
|
||||
|
||||
StyleResolverForElement::new(element, &mut context, RuleInclusion::All)
|
||||
.cascade_style_and_visited_with_default_parents(inputs)
|
||||
.into_strong()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -2769,39 +2797,20 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
|
|||
}
|
||||
}
|
||||
|
||||
let traversal_flags = match rule_inclusion {
|
||||
RuleInclusion::All => TraversalFlags::empty(),
|
||||
RuleInclusion::DefaultOnly => FOR_DEFAULT_STYLES,
|
||||
};
|
||||
|
||||
// We don't have the style ready. Go ahead and compute it as necessary.
|
||||
let mut result = None;
|
||||
let shared = create_shared_context(&global_style_data,
|
||||
&guard,
|
||||
&data,
|
||||
traversal_flags,
|
||||
TraversalFlags::empty(),
|
||||
unsafe { &*snapshots });
|
||||
let mut tlc = ThreadLocalStyleContext::new(&shared);
|
||||
let mut context = StyleContext {
|
||||
shared: &shared,
|
||||
thread_local: &mut tlc,
|
||||
};
|
||||
let ensure = |el: GeckoElement| { unsafe { el.ensure_data(); } };
|
||||
|
||||
match rule_inclusion {
|
||||
RuleInclusion::All => {
|
||||
let clear = |el: GeckoElement| el.clear_data();
|
||||
resolve_style(&mut context, element, &ensure, &clear,
|
||||
|styles| result = Some(finish(styles)));
|
||||
}
|
||||
RuleInclusion::DefaultOnly => {
|
||||
let set_data = |el: GeckoElement, data| { unsafe { el.set_data(data) } };
|
||||
resolve_default_style(&mut context, element, &ensure, &set_data,
|
||||
|styles| result = Some(finish(styles)));
|
||||
}
|
||||
}
|
||||
|
||||
result.unwrap().into_strong()
|
||||
let styles = resolve_style(&mut context, element, rule_inclusion);
|
||||
finish(&styles).into_strong()
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko_debug")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue