mirror of
https://github.com/servo/servo.git
synced 2025-08-13 01:15:34 +01:00
Match and cascade visited styles
To support visited styles, we match and cascade a separate set of styles any time we notice that an element has a relevant link. The visited rules and values are held in `ComputedStyle` alongside the regular rules and values, which simplifies supporting various APIs like `cascade_primary_and_pseudos` which expect easy access to previously matched rules. To simplify passing the additional values around, an additional reference to the visited `ComputedValues` is placed inside the regular `ComputedValues`. MozReview-Commit-ID: 2ebbjcfkfWf
This commit is contained in:
parent
e3a256803d
commit
a7882cfeb9
9 changed files with 621 additions and 141 deletions
|
@ -100,6 +100,11 @@ pub struct ComputedValues {
|
|||
pub font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
/// The cached system font. See longhand/font.mako.rs
|
||||
pub cached_system_font: Option<longhands::system_font::ComputedSystemFont>,
|
||||
|
||||
/// 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.
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
}
|
||||
|
||||
impl ComputedValues {
|
||||
|
@ -107,6 +112,7 @@ impl ComputedValues {
|
|||
writing_mode: WritingMode,
|
||||
root_font_size: Au,
|
||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
|
@ -117,6 +123,7 @@ impl ComputedValues {
|
|||
root_font_size: root_font_size,
|
||||
cached_system_font: None,
|
||||
font_size_keyword: font_size_keyword,
|
||||
visited_style: visited_style,
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: ${style_struct.ident},
|
||||
% endfor
|
||||
|
@ -130,6 +137,7 @@ impl ComputedValues {
|
|||
root_font_size: longhands::font_size::get_initial_value(), // FIXME(bz): Also seems dubious?
|
||||
font_size_keyword: Some((Default::default(), 1.)),
|
||||
cached_system_font: None,
|
||||
visited_style: None,
|
||||
% for style_struct in data.style_structs:
|
||||
${style_struct.ident}: style_structs::${style_struct.name}::default(pres_context),
|
||||
% endfor
|
||||
|
@ -168,6 +176,23 @@ impl ComputedValues {
|
|||
}
|
||||
% endfor
|
||||
|
||||
/// Gets a reference to the visited computed values, if any.
|
||||
pub fn get_visited_style(&self) -> Option<<&Arc<ComputedValues>> {
|
||||
self.visited_style.as_ref()
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited computed values. Panic if the element
|
||||
/// does not have visited computed values.
|
||||
pub fn visited_style(&self) -> &Arc<ComputedValues> {
|
||||
self.get_visited_style().unwrap()
|
||||
}
|
||||
|
||||
/// Clone the visited computed values Arc. Used for inheriting parent styles
|
||||
/// in StyleBuilder::for_inheritance.
|
||||
pub fn clone_visited_style(&self) -> Option<Arc<ComputedValues>> {
|
||||
self.visited_style.clone()
|
||||
}
|
||||
|
||||
pub fn custom_properties(&self) -> Option<Arc<ComputedValuesMap>> {
|
||||
self.custom_properties.clone()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue