Skip to content

Commit

Permalink
Implement stylo selector flag methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Sep 17, 2024
1 parent c0c0fa9 commit b53fb5d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/dom/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use atomic_refcell::{AtomicRef, AtomicRefCell};
use html5ever::{local_name, LocalName, QualName};
use image::DynamicImage;
use peniko::kurbo;
use selectors::matching::QuirksMode;
use selectors::matching::{ElementSelectorFlags, QuirksMode};
use slab::Slab;
use std::cell::RefCell;
use std::fmt::Write;
Expand Down Expand Up @@ -63,6 +63,7 @@ pub struct Node {
// This little bundle of joy is our style data from stylo and a lock guard that allows access to it
// TODO: See if guard can be hoisted to a higher level
pub stylo_element_data: AtomicRefCell<Option<ElementData>>,
pub selector_flags: AtomicRefCell<ElementSelectorFlags>,
pub guard: SharedRwLock,
pub element_state: ElementState,

Expand Down Expand Up @@ -97,6 +98,7 @@ impl Node {

raw_dom_data: data,
stylo_element_data: Default::default(),
selector_flags: AtomicRefCell::new(ElementSelectorFlags::empty()),
guard,
element_state: ElementState::empty(),

Expand Down
24 changes: 19 additions & 5 deletions packages/dom/src/stylo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,20 @@ impl<'a> selectors::Element for BlitzNode<'a> {
}
}

fn apply_selector_flags(&self, _flags: ElementSelectorFlags) {
// unimplemented!()
fn apply_selector_flags(&self, flags: ElementSelectorFlags) {
// Handle flags that apply to the element.
let self_flags = flags.for_self();
if !self_flags.is_empty() {
*self.selector_flags.borrow_mut() |= self_flags;
}

// Handle flags that apply to the parent.
let parent_flags = flags.for_parent();
if !parent_flags.is_empty() {
if let Some(parent) = self.parent_node() {
*parent.selector_flags.borrow_mut() |= self_flags;
}
}
}

fn is_link(&self) -> bool {
Expand Down Expand Up @@ -898,12 +910,14 @@ impl<'a> TElement for BlitzNode<'a> {
todo!()
}

fn has_selector_flags(&self, _flags: ElementSelectorFlags) -> bool {
todo!()
fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool {
self.selector_flags.borrow().contains(flags)
}

fn relative_selector_search_direction(&self) -> ElementSelectorFlags {
todo!()
self.selector_flags
.borrow()
.intersection(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING)
}

// fn update_animations(
Expand Down

0 comments on commit b53fb5d

Please sign in to comment.