mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
The primary idea of this patch is to ditch the rigid enum of Previous/Current styles, and replace it with a series of indicators for the various types of work that needs to be performed (expanding snapshots, rematching, recascading, and damage processing). This loses us a little bit of sanity checking (since the up-to-date-ness of our style is no longer baked into the type system), but gives us a lot more flexibility that we'll need going forward (especially when we separate matching from cascading). We also eliminate get_styling_mode in favor of a method on the traversal. This patch does a few other things as ridealongs: * Temporarily eliminates the handling for transfering ownership of styles to the frame. We'll need this again at some point, but for now it's causing too much complexity for a half-implemented feature. * Ditches TRestyleDamage, which is no longer necessary post-crate-merge, and is a constant source of compilation failures from either needing to be imported or being unnecessarily imported (which varies between gecko and servo). * Expands Snapshots for the traversal root, which was missing before. * Fixes up the skip_root stuff to avoid visiting the skipped root. * Unifies parallel traversal and avoids spawning for a single work item. * Adds an explicit pre_traverse step do any pre-processing and determine whether we need to traverse at all. MozReview-Commit-ID: IKhLAkAigXE
169 lines
6.3 KiB
Rust
169 lines
6.3 KiB
Rust
/* 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/. */
|
|
|
|
use element_state::ElementState;
|
|
use gecko::snapshot_helpers;
|
|
use gecko::wrapper::{AttrSelectorHelpers, GeckoElement};
|
|
use gecko_bindings::bindings;
|
|
use gecko_bindings::structs::ServoElementSnapshot;
|
|
use gecko_bindings::structs::ServoElementSnapshotFlags as Flags;
|
|
use restyle_hints::ElementSnapshot;
|
|
use selector_parser::SelectorImpl;
|
|
use selectors::parser::AttrSelector;
|
|
use std::ptr;
|
|
use string_cache::Atom;
|
|
|
|
#[derive(Debug)]
|
|
pub struct GeckoElementSnapshot(bindings::ServoElementSnapshotOwned);
|
|
|
|
// FIXME(bholley): Add support for *OwnedConst type, and then we get Sync
|
|
// automatically.
|
|
unsafe impl Sync for GeckoElementSnapshot {}
|
|
|
|
impl Drop for GeckoElementSnapshot {
|
|
fn drop(&mut self) {
|
|
unsafe {
|
|
bindings::Gecko_DropElementSnapshot(ptr::read(&self.0 as *const _));
|
|
}
|
|
}
|
|
}
|
|
|
|
impl GeckoElementSnapshot {
|
|
pub fn new<'le>(el: GeckoElement<'le>) -> Self {
|
|
unsafe { GeckoElementSnapshot(bindings::Gecko_CreateElementSnapshot(el.0)) }
|
|
}
|
|
|
|
pub fn borrow_mut_raw(&mut self) -> bindings::ServoElementSnapshotBorrowedMut {
|
|
&mut *self.0
|
|
}
|
|
|
|
pub fn ptr(&self) -> *const ServoElementSnapshot {
|
|
&*self.0
|
|
}
|
|
|
|
#[inline]
|
|
fn is_html_element_in_html_document(&self) -> bool {
|
|
unsafe { (*self.0).mIsHTMLElementInHTMLDocument }
|
|
}
|
|
|
|
#[inline]
|
|
fn has_any(&self, flags: Flags) -> bool {
|
|
unsafe { ((*self.0).mContains as u8 & flags as u8) != 0 }
|
|
}
|
|
}
|
|
|
|
impl ::selectors::MatchAttr for GeckoElementSnapshot {
|
|
type Impl = SelectorImpl;
|
|
|
|
fn match_attr_has(&self, attr: &AttrSelector<SelectorImpl>) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotHasAttr(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()))
|
|
}
|
|
}
|
|
|
|
fn match_attr_equals(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrEquals(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr(),
|
|
/* ignoreCase = */ false)
|
|
}
|
|
}
|
|
|
|
fn match_attr_equals_ignore_ascii_case(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrEquals(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr(),
|
|
/* ignoreCase = */ true)
|
|
}
|
|
}
|
|
fn match_attr_includes(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrIncludes(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr())
|
|
}
|
|
}
|
|
fn match_attr_dash(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrDashEquals(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr())
|
|
}
|
|
}
|
|
fn match_attr_prefix(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrHasPrefix(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr())
|
|
}
|
|
}
|
|
fn match_attr_substring(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrHasSubstring(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr())
|
|
}
|
|
}
|
|
fn match_attr_suffix(&self, attr: &AttrSelector<SelectorImpl>, value: &Atom) -> bool {
|
|
unsafe {
|
|
bindings::Gecko_SnapshotAttrHasSuffix(self.ptr(),
|
|
attr.ns_or_null(),
|
|
attr.select_name(self.is_html_element_in_html_document()),
|
|
value.as_ptr())
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ElementSnapshot for GeckoElementSnapshot {
|
|
fn state(&self) -> Option<ElementState> {
|
|
if self.has_any(Flags::State) {
|
|
Some(ElementState::from_bits_truncate(unsafe { (*self.0).mState as u16 }))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
fn has_attrs(&self) -> bool {
|
|
self.has_any(Flags::Attributes)
|
|
}
|
|
|
|
fn id_attr(&self) -> Option<Atom> {
|
|
let ptr = unsafe {
|
|
bindings::Gecko_SnapshotAtomAttrValue(self.ptr(),
|
|
atom!("id").as_ptr())
|
|
};
|
|
|
|
if ptr.is_null() {
|
|
None
|
|
} else {
|
|
Some(Atom::from(ptr))
|
|
}
|
|
}
|
|
|
|
// TODO: share logic with Element::{has_class, each_class}?
|
|
fn has_class(&self, name: &Atom) -> bool {
|
|
snapshot_helpers::has_class(self.ptr(),
|
|
name,
|
|
bindings::Gecko_SnapshotClassOrClassList)
|
|
}
|
|
|
|
fn each_class<F>(&self, callback: F)
|
|
where F: FnMut(&Atom)
|
|
{
|
|
snapshot_helpers::each_class(self.ptr(),
|
|
callback,
|
|
bindings::Gecko_SnapshotClassOrClassList)
|
|
}
|
|
}
|