mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Refactor style to be completely backend-independent
This commit refactors the style crate to be completely independent of the actual implementation and pseudo-elements supported. This also adds a gecko backend which introduces parsing for the anonymous box pseudo-elements[1], although there's still no way of querying them. https://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSAnonBoxList.h
This commit is contained in:
parent
a164176876
commit
dd503dfacb
41 changed files with 767 additions and 310 deletions
|
@ -64,13 +64,13 @@ use std::sync::Arc;
|
|||
use string_cache::{Atom, Namespace};
|
||||
use style::computed_values::content::ContentItem;
|
||||
use style::computed_values::{content, display};
|
||||
use style::data::PrivateStyleData;
|
||||
use style::dom::{TDocument, TElement, TNode, UnsafeNode};
|
||||
use style::element_state::*;
|
||||
use style::properties::ComputedValues;
|
||||
use style::properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style::restyle_hints::ElementSnapshot;
|
||||
use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl};
|
||||
use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl};
|
||||
use style::servo::PrivateStyleData;
|
||||
use url::Url;
|
||||
use util::str::{is_whitespace, search_index};
|
||||
|
||||
|
@ -664,16 +664,20 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
|||
|
||||
#[inline]
|
||||
fn get_before_pseudo(&self) -> Option<Self> {
|
||||
self.borrow_layout_data().unwrap().style_data.before_style.as_ref().map(|style| {
|
||||
self.with_pseudo(PseudoElementType::Before(style.get_box().display))
|
||||
})
|
||||
self.borrow_layout_data().unwrap()
|
||||
.style_data.per_pseudo
|
||||
.get(&PseudoElement::Before).unwrap_or(&None).as_ref().map(|style| {
|
||||
self.with_pseudo(PseudoElementType::Before(style.get_box().display))
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_after_pseudo(&self) -> Option<Self> {
|
||||
self.borrow_layout_data().unwrap().style_data.after_style.as_ref().map(|style| {
|
||||
self.with_pseudo(PseudoElementType::After(style.get_box().display))
|
||||
})
|
||||
self.borrow_layout_data().unwrap()
|
||||
.style_data.per_pseudo
|
||||
.get(&PseudoElement::After).unwrap_or(&None).as_ref().map(|style| {
|
||||
self.with_pseudo(PseudoElementType::After(style.get_box().display))
|
||||
})
|
||||
}
|
||||
|
||||
/// Borrows the layout data immutably. Fails on a conflicting borrow.
|
||||
|
@ -696,8 +700,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
|||
fn style(&self) -> Ref<Arc<ComputedValues>> {
|
||||
Ref::map(self.borrow_layout_data().unwrap(), |data| {
|
||||
let style = match self.get_pseudo_element_type() {
|
||||
PseudoElementType::Before(_) => &data.style_data.before_style,
|
||||
PseudoElementType::After(_) => &data.style_data.after_style,
|
||||
PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before).unwrap(),
|
||||
PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After).unwrap(),
|
||||
PseudoElementType::Normal => &data.style_data.style,
|
||||
};
|
||||
style.as_ref().unwrap()
|
||||
|
@ -711,9 +715,19 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
|||
let mut data = self.mutate_layout_data().unwrap();
|
||||
let style =
|
||||
match self.get_pseudo_element_type() {
|
||||
PseudoElementType::Before(_) => &mut data.style_data.before_style,
|
||||
PseudoElementType::After (_) => &mut data.style_data.after_style,
|
||||
PseudoElementType::Normal => &mut data.style_data.style,
|
||||
PseudoElementType::Before(_) => {
|
||||
match data.style_data.per_pseudo.get_mut(&PseudoElement::Before) {
|
||||
None => return,
|
||||
Some(style) => style,
|
||||
}
|
||||
}
|
||||
PseudoElementType::After(_) => {
|
||||
match data.style_data.per_pseudo.get_mut(&PseudoElement::After) {
|
||||
None => return,
|
||||
Some(style) => style,
|
||||
}
|
||||
}
|
||||
PseudoElementType::Normal => &mut data.style_data.style,
|
||||
};
|
||||
|
||||
*style = None;
|
||||
|
@ -934,10 +948,11 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
|||
let data = &self.borrow_layout_data().unwrap().style_data;
|
||||
|
||||
let style = if self.pseudo.is_before() {
|
||||
&data.before_style
|
||||
data.per_pseudo.get(&PseudoElement::Before).unwrap()
|
||||
} else {
|
||||
&data.after_style
|
||||
data.per_pseudo.get(&PseudoElement::After).unwrap()
|
||||
};
|
||||
|
||||
return match style.as_ref().unwrap().get_box().content {
|
||||
content::T::Content(ref value) if !value.is_empty() => {
|
||||
TextContent::GeneratedContent((*value).clone())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue