mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Auto merge of #14731 - heycam:flushing_and_pseudos, r=heycam
stylo: Coordinate stylist flushing with gecko, and clean up pseudo-element resolution
This commit is contained in:
commit
42ec8a8974
2 changed files with 82 additions and 67 deletions
|
@ -991,16 +991,18 @@ extern "C" {
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed,
|
pub fn Servo_StyleSet_AppendStyleSheet(set: RawServoStyleSetBorrowed,
|
||||||
sheet: RawServoStyleSheetBorrowed);
|
sheet: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowed,
|
pub fn Servo_StyleSet_PrependStyleSheet(set: RawServoStyleSetBorrowed,
|
||||||
sheet:
|
sheet: RawServoStyleSheetBorrowed,
|
||||||
RawServoStyleSheetBorrowed);
|
flush: bool);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_RemoveStyleSheet(set: RawServoStyleSetBorrowed,
|
pub fn Servo_StyleSet_RemoveStyleSheet(set: RawServoStyleSetBorrowed,
|
||||||
sheet: RawServoStyleSheetBorrowed);
|
sheet: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_InsertStyleSheetBefore(set:
|
pub fn Servo_StyleSet_InsertStyleSheetBefore(set:
|
||||||
|
@ -1008,7 +1010,11 @@ extern "C" {
|
||||||
sheet:
|
sheet:
|
||||||
RawServoStyleSheetBorrowed,
|
RawServoStyleSheetBorrowed,
|
||||||
reference:
|
reference:
|
||||||
RawServoStyleSheetBorrowed);
|
RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool);
|
||||||
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_StyleSet_FlushStyleSheets(set: RawServoStyleSetBorrowed);
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_StyleSet_NoteStyleSheetsChanged(set:
|
pub fn Servo_StyleSet_NoteStyleSheetsChanged(set:
|
||||||
|
@ -1177,17 +1183,6 @@ extern "C" {
|
||||||
RawServoStyleSetBorrowed)
|
RawServoStyleSetBorrowed)
|
||||||
-> ServoComputedValuesStrong;
|
-> ServoComputedValuesStrong;
|
||||||
}
|
}
|
||||||
extern "C" {
|
|
||||||
pub fn Servo_ComputedValues_GetForPseudoElement(parent_style:
|
|
||||||
ServoComputedValuesBorrowed,
|
|
||||||
match_element:
|
|
||||||
RawGeckoElementBorrowed,
|
|
||||||
pseudo_tag: *mut nsIAtom,
|
|
||||||
set:
|
|
||||||
RawServoStyleSetBorrowed,
|
|
||||||
is_probe: bool)
|
|
||||||
-> ServoComputedValuesStrong;
|
|
||||||
}
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_ComputedValues_Inherit(parent_style:
|
pub fn Servo_ComputedValues_Inherit(parent_style:
|
||||||
ServoComputedValuesBorrowedOrNull)
|
ServoComputedValuesBorrowedOrNull)
|
||||||
|
@ -1219,6 +1214,12 @@ extern "C" {
|
||||||
compute: LazyComputeBehavior)
|
compute: LazyComputeBehavior)
|
||||||
-> ServoComputedValuesStrong;
|
-> ServoComputedValuesStrong;
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
||||||
|
pseudo_tag: *mut nsIAtom, is_probe: bool,
|
||||||
|
set: RawServoStyleSetBorrowed)
|
||||||
|
-> ServoComputedValuesStrong;
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed,
|
pub fn Servo_TraverseSubtree(root: RawGeckoElementBorrowed,
|
||||||
set: RawServoStyleSetBorrowed,
|
set: RawServoStyleSetBorrowed,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use style::arc_ptr_eq;
|
||||||
use style::atomic_refcell::AtomicRefMut;
|
use style::atomic_refcell::AtomicRefMut;
|
||||||
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext, StyleContext};
|
||||||
use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInfo};
|
use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInfo};
|
||||||
use style::data::{ElementData, RestyleData};
|
use style::data::{ElementData, ElementStyles, RestyleData};
|
||||||
use style::dom::{ShowSubtreeData, TElement, TNode};
|
use style::dom::{ShowSubtreeData, TElement, TNode};
|
||||||
use style::error_reporting::StdoutErrorReporter;
|
use style::error_reporting::StdoutErrorReporter;
|
||||||
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
|
||||||
|
@ -90,10 +90,7 @@ pub extern "C" fn Servo_Shutdown() -> () {
|
||||||
unsafe { ComputedValues::shutdown(); }
|
unsafe { ComputedValues::shutdown(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_shared_context(mut per_doc_data: &mut AtomicRefMut<PerDocumentStyleDataImpl>) -> SharedStyleContext {
|
fn create_shared_context(per_doc_data: &PerDocumentStyleDataImpl) -> SharedStyleContext {
|
||||||
// The stylist consumes stylesheets lazily.
|
|
||||||
per_doc_data.flush_stylesheets();
|
|
||||||
|
|
||||||
let local_context_data =
|
let local_context_data =
|
||||||
ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
|
ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
|
||||||
|
|
||||||
|
@ -144,7 +141,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
|
||||||
debug!("Traversing subtree:");
|
debug!("Traversing subtree:");
|
||||||
debug!("{:?}", ShowSubtreeData(element.as_node()));
|
debug!("{:?}", ShowSubtreeData(element.as_node()));
|
||||||
|
|
||||||
let shared_style_context = create_shared_context(&mut per_doc_data);
|
let shared_style_context = create_shared_context(&per_doc_data);
|
||||||
let traversal = RecalcStyleOnly::new(shared_style_context);
|
let traversal = RecalcStyleOnly::new(shared_style_context);
|
||||||
let known_depth = None;
|
let known_depth = None;
|
||||||
|
|
||||||
|
@ -271,28 +268,37 @@ pub extern "C" fn Servo_StyleSheet_FromUTF8Bytes(data: *const nsACString,
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
pub extern "C" fn Servo_StyleSet_AppendStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
raw_sheet: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool) {
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||||
data.stylesheets.push(sheet.clone());
|
data.stylesheets.push(sheet.clone());
|
||||||
data.stylesheets_changed = true;
|
data.stylesheets_changed = true;
|
||||||
|
if flush {
|
||||||
|
data.flush_stylesheets();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
raw_sheet: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool) {
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||||
data.stylesheets.insert(0, sheet.clone());
|
data.stylesheets.insert(0, sheet.clone());
|
||||||
data.stylesheets_changed = true;
|
data.stylesheets_changed = true;
|
||||||
|
if flush {
|
||||||
|
data.flush_stylesheets();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleSetBorrowed,
|
pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleSetBorrowed,
|
||||||
raw_sheet: RawServoStyleSheetBorrowed,
|
raw_sheet: RawServoStyleSheetBorrowed,
|
||||||
raw_reference: RawServoStyleSheetBorrowed) {
|
raw_reference: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool) {
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||||
let reference = HasArcFFI::as_arc(&raw_reference);
|
let reference = HasArcFFI::as_arc(&raw_reference);
|
||||||
|
@ -300,15 +306,28 @@ pub extern "C" fn Servo_StyleSet_InsertStyleSheetBefore(raw_data: RawServoStyleS
|
||||||
let index = data.stylesheets.iter().position(|x| arc_ptr_eq(x, reference)).unwrap();
|
let index = data.stylesheets.iter().position(|x| arc_ptr_eq(x, reference)).unwrap();
|
||||||
data.stylesheets.insert(index, sheet.clone());
|
data.stylesheets.insert(index, sheet.clone());
|
||||||
data.stylesheets_changed = true;
|
data.stylesheets_changed = true;
|
||||||
|
if flush {
|
||||||
|
data.flush_stylesheets();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
pub extern "C" fn Servo_StyleSet_RemoveStyleSheet(raw_data: RawServoStyleSetBorrowed,
|
||||||
raw_sheet: RawServoStyleSheetBorrowed) {
|
raw_sheet: RawServoStyleSheetBorrowed,
|
||||||
|
flush: bool) {
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
let sheet = HasArcFFI::as_arc(&raw_sheet);
|
||||||
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
data.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
|
||||||
data.stylesheets_changed = true;
|
data.stylesheets_changed = true;
|
||||||
|
if flush {
|
||||||
|
data.flush_stylesheets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn Servo_StyleSet_FlushStyleSheets(raw_data: RawServoStyleSetBorrowed) {
|
||||||
|
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
|
data.flush_stylesheets();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -443,10 +462,7 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
||||||
pseudo_tag: *mut nsIAtom,
|
pseudo_tag: *mut nsIAtom,
|
||||||
raw_data: RawServoStyleSetBorrowed)
|
raw_data: RawServoStyleSetBorrowed)
|
||||||
-> ServoComputedValuesStrong {
|
-> ServoComputedValuesStrong {
|
||||||
// The stylist consumes stylesheets lazily.
|
let data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
|
||||||
data.flush_stylesheets();
|
|
||||||
|
|
||||||
let atom = Atom::from(pseudo_tag);
|
let atom = Atom::from(pseudo_tag);
|
||||||
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);
|
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);
|
||||||
|
|
||||||
|
@ -458,48 +474,46 @@ pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null:
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Servo_ComputedValues_GetForPseudoElement(parent_style: ServoComputedValuesBorrowed,
|
pub extern "C" fn Servo_ResolvePseudoStyle(element: RawGeckoElementBorrowed,
|
||||||
match_element: RawGeckoElementBorrowed,
|
pseudo_tag: *mut nsIAtom, is_probe: bool,
|
||||||
pseudo_tag: *mut nsIAtom,
|
raw_data: RawServoStyleSetBorrowed)
|
||||||
raw_data: RawServoStyleSetBorrowed,
|
-> ServoComputedValuesStrong
|
||||||
is_probe: bool)
|
{
|
||||||
-> ServoComputedValuesStrong {
|
let element = GeckoElement(element);
|
||||||
debug_assert!(!(match_element as *const _).is_null());
|
let data = unsafe { element.ensure_data() }.borrow_mut();
|
||||||
|
|
||||||
let parent_or_null = || {
|
// FIXME(bholley): Assert against this.
|
||||||
if is_probe {
|
if data.get_styles().is_none() {
|
||||||
|
error!("Calling Servo_ResolvePseudoStyle on unstyled element");
|
||||||
|
return if is_probe {
|
||||||
Strong::null()
|
Strong::null()
|
||||||
} else {
|
} else {
|
||||||
ComputedValues::as_arc(&parent_style).clone().into_strong()
|
Arc::new(ComputedValues::initial_values().clone()).into_strong()
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
let atom = Atom::from(pseudo_tag);
|
|
||||||
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);
|
|
||||||
|
|
||||||
// The stylist consumes stylesheets lazily.
|
|
||||||
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
|
||||||
data.flush_stylesheets();
|
|
||||||
|
|
||||||
let element = GeckoElement(match_element);
|
|
||||||
|
|
||||||
|
let doc_data = PerDocumentStyleData::from_ffi(raw_data);
|
||||||
|
match get_pseudo_style(element, pseudo_tag, data.styles(), doc_data) {
|
||||||
|
Some(values) => values.into_strong(),
|
||||||
|
None if !is_probe => data.styles().primary.values.clone().into_strong(),
|
||||||
|
None => Strong::null(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_pseudo_style(element: GeckoElement, pseudo_tag: *mut nsIAtom,
|
||||||
|
styles: &ElementStyles, doc_data: &PerDocumentStyleData)
|
||||||
|
-> Option<Arc<ComputedValues>>
|
||||||
|
{
|
||||||
|
let pseudo = PseudoElement::from_atom_unchecked(Atom::from(pseudo_tag), false);
|
||||||
match SelectorImpl::pseudo_element_cascade_type(&pseudo) {
|
match SelectorImpl::pseudo_element_cascade_type(&pseudo) {
|
||||||
PseudoElementCascadeType::Eager => {
|
PseudoElementCascadeType::Eager => styles.pseudos.get(&pseudo).map(|s| s.values.clone()),
|
||||||
let maybe_computed = element.get_pseudo_style(&pseudo);
|
PseudoElementCascadeType::Precomputed => unreachable!("No anonymous boxes"),
|
||||||
maybe_computed.map_or_else(parent_or_null, FFIArcHelpers::into_strong)
|
|
||||||
}
|
|
||||||
PseudoElementCascadeType::Lazy => {
|
PseudoElementCascadeType::Lazy => {
|
||||||
let parent = ComputedValues::as_arc(&parent_style);
|
let d = doc_data.borrow_mut();
|
||||||
data.stylist
|
let base = &styles.primary.values;
|
||||||
.lazily_compute_pseudo_element_style(&element, &pseudo, parent)
|
d.stylist.lazily_compute_pseudo_element_style(&element, &pseudo, base)
|
||||||
.map(|styles| styles.values)
|
.map(|s| s.values.clone())
|
||||||
.map_or_else(parent_or_null, FFIArcHelpers::into_strong)
|
},
|
||||||
}
|
|
||||||
PseudoElementCascadeType::Precomputed => {
|
|
||||||
unreachable!("Anonymous pseudo found in \
|
|
||||||
Servo_GetComputedValuesForPseudoElement");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,8 +879,8 @@ pub extern "C" fn Servo_ResolveStyle(element: RawGeckoElementBorrowed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
|
||||||
let shared_style_context = create_shared_context(&mut per_doc_data);
|
let shared_style_context = create_shared_context(&per_doc_data);
|
||||||
let traversal = RecalcStyleOnly::new(shared_style_context);
|
let traversal = RecalcStyleOnly::new(shared_style_context);
|
||||||
|
|
||||||
let mut traversal_data = PerLevelTraversalData {
|
let mut traversal_data = PerLevelTraversalData {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue