mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Teach Servo to compute text node style from layout.
MozReview-Commit-ID: IolVN5puF1i
This commit is contained in:
parent
97fd61f512
commit
a5cabda484
2 changed files with 35 additions and 4 deletions
|
@ -825,6 +825,14 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
||||||
self.node.type_id()
|
self.node.type_id()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn style_for_text_node(&self) -> Arc<ComputedValues> {
|
||||||
|
debug_assert!(self.is_text_node());
|
||||||
|
let parent = self.node.parent_node().unwrap();
|
||||||
|
let parent_data = parent.get_style_data().unwrap().borrow();
|
||||||
|
let parent_style = &parent_data.current_styles().primary;
|
||||||
|
ComputedValues::style_for_child_text_node(parent_style)
|
||||||
|
}
|
||||||
|
|
||||||
fn debug_id(self) -> usize {
|
fn debug_id(self) -> usize {
|
||||||
self.node.debug_id()
|
self.node.debug_id()
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,16 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
/// `type_id` does.
|
/// `type_id` does.
|
||||||
fn type_id_without_excluding_pseudo_elements(&self) -> LayoutNodeType;
|
fn type_id_without_excluding_pseudo_elements(&self) -> LayoutNodeType;
|
||||||
|
|
||||||
|
/// Returns the style for a text node. This is computed on the fly from the
|
||||||
|
/// parent style to avoid traversing text nodes in the style system.
|
||||||
|
///
|
||||||
|
/// Note that this does require accessing the parent, which this interface
|
||||||
|
/// technically forbids. But accessing the parent is only unsafe insofar as
|
||||||
|
/// it can be used to reach siblings and cousins. A simple immutable borrow
|
||||||
|
/// of the parent data is fine, since the bottom-up traversal will not process
|
||||||
|
/// the parent until all the children have been processed.
|
||||||
|
fn style_for_text_node(&self) -> Arc<ServoComputedValues>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_element_or_elements_pseudo(&self) -> bool {
|
fn is_element_or_elements_pseudo(&self) -> bool {
|
||||||
match self.type_id_without_excluding_pseudo_elements() {
|
match self.type_id_without_excluding_pseudo_elements() {
|
||||||
|
@ -187,7 +197,8 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_before_pseudo(&self) -> Option<Self> {
|
fn get_before_pseudo(&self) -> Option<Self> {
|
||||||
if self.get_style_data()
|
if self.is_element() &&
|
||||||
|
self.get_style_data()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.borrow()
|
.borrow()
|
||||||
.current_styles().pseudos
|
.current_styles().pseudos
|
||||||
|
@ -200,7 +211,8 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_after_pseudo(&self) -> Option<Self> {
|
fn get_after_pseudo(&self) -> Option<Self> {
|
||||||
if self.get_style_data()
|
if self.is_element() &&
|
||||||
|
self.get_style_data()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.borrow()
|
.borrow()
|
||||||
.current_styles().pseudos
|
.current_styles().pseudos
|
||||||
|
@ -248,8 +260,11 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
fn style(&self, context: &SharedStyleContext) -> Arc<ServoComputedValues> {
|
fn style(&self, context: &SharedStyleContext) -> Arc<ServoComputedValues> {
|
||||||
match self.get_pseudo_element_type() {
|
match self.get_pseudo_element_type() {
|
||||||
PseudoElementType::Normal => {
|
PseudoElementType::Normal => {
|
||||||
self.get_style_data().unwrap().borrow()
|
match self.type_id().unwrap() {
|
||||||
.current_styles().primary.clone()
|
LayoutNodeType::Text => self.style_for_text_node(),
|
||||||
|
LayoutNodeType::Element(_) => self.get_style_data().unwrap().borrow()
|
||||||
|
.current_styles().primary.clone(),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
other => {
|
other => {
|
||||||
// Precompute non-eagerly-cascaded pseudo-element styles if not
|
// Precompute non-eagerly-cascaded pseudo-element styles if not
|
||||||
|
@ -308,6 +323,10 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
/// element style is precomputed, not from general layout itself.
|
/// element style is precomputed, not from general layout itself.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn resolved_style(&self) -> Arc<ServoComputedValues> {
|
fn resolved_style(&self) -> Arc<ServoComputedValues> {
|
||||||
|
if self.is_text_node() {
|
||||||
|
return self.style_for_text_node();
|
||||||
|
}
|
||||||
|
|
||||||
let data = self.get_style_data().unwrap().borrow();
|
let data = self.get_style_data().unwrap().borrow();
|
||||||
match self.get_pseudo_element_type() {
|
match self.get_pseudo_element_type() {
|
||||||
PseudoElementType::Normal
|
PseudoElementType::Normal
|
||||||
|
@ -319,6 +338,10 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn selected_style(&self, _context: &SharedStyleContext) -> Arc<ServoComputedValues> {
|
fn selected_style(&self, _context: &SharedStyleContext) -> Arc<ServoComputedValues> {
|
||||||
|
if self.is_text_node() {
|
||||||
|
return self.style_for_text_node();
|
||||||
|
}
|
||||||
|
|
||||||
let data = self.get_style_data().unwrap().borrow();
|
let data = self.get_style_data().unwrap().borrow();
|
||||||
data.current_styles().pseudos
|
data.current_styles().pseudos
|
||||||
.get(&PseudoElement::Selection)
|
.get(&PseudoElement::Selection)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue