mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
dom: IntersectionObserver initialization (#35314)
* Add internal slot definition Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Add initialization for new IntersectionObserver Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Move observer initialization Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Update WPT tests Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Make a copy of style IntersectionObserverRootMargin Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Move initialization to account for rooted expression Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Fix some fields typing Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Impl rest of IntersectionObserver interface Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Fix tidy issue Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Apply types logic and tidy fix from suggestions Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> * Add allow unrooted for add registration to element Signed-off-by: stevennovaryo <steven.novaryo@gmail.com> --------- Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
This commit is contained in:
parent
610a1c2303
commit
becd097585
11 changed files with 439 additions and 64 deletions
|
@ -64,6 +64,7 @@ use xml5ever::serialize::TraversalScope::{
|
|||
|
||||
use super::customelementregistry::is_valid_custom_element_name;
|
||||
use super::htmltablecolelement::{HTMLTableColElement, HTMLTableColElementLayoutHelpers};
|
||||
use super::intersectionobserver::{IntersectionObserver, IntersectionObserverRegistration};
|
||||
use crate::dom::activation::Activatable;
|
||||
use crate::dom::attr::{Attr, AttrHelpersForLayout};
|
||||
use crate::dom::bindings::cell::{ref_filter_map, DomRefCell, Ref, RefMut};
|
||||
|
@ -613,6 +614,50 @@ impl Element {
|
|||
Some(node) => node.is::<Document>(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Return all IntersectionObserverRegistration for this element.
|
||||
/// Lazily initialize the raredata if it does not exist.
|
||||
pub(crate) fn registered_intersection_observers_mut(
|
||||
&self,
|
||||
) -> RefMut<Vec<IntersectionObserverRegistration>> {
|
||||
RefMut::map(self.ensure_rare_data(), |rare_data| {
|
||||
&mut rare_data.registered_intersection_observers
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn registered_intersection_observers(
|
||||
&self,
|
||||
) -> Option<Ref<Vec<IntersectionObserverRegistration>>> {
|
||||
let rare_data: Ref<_> = self.rare_data.borrow();
|
||||
|
||||
if rare_data.is_none() {
|
||||
return None;
|
||||
}
|
||||
Some(Ref::map(rare_data, |rare_data| {
|
||||
&rare_data
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.registered_intersection_observers
|
||||
}))
|
||||
}
|
||||
|
||||
/// Add a new IntersectionObserverRegistration to the element.
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
pub(crate) fn add_intersection_observer_registration(
|
||||
&self,
|
||||
registration: IntersectionObserverRegistration,
|
||||
) {
|
||||
self.ensure_rare_data()
|
||||
.registered_intersection_observers
|
||||
.push(registration);
|
||||
}
|
||||
|
||||
/// Removes a certain IntersectionObserver.
|
||||
pub(crate) fn remove_intersection_observer(&self, observer: &IntersectionObserver) {
|
||||
self.ensure_rare_data()
|
||||
.registered_intersection_observers
|
||||
.retain(|reg_obs| *reg_obs.observer != *observer)
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://dom.spec.whatwg.org/#valid-shadow-host-name>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue