mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Minor tweaks: rename composed_parent_node_ref, remove or update outdated comments...
This commit is contained in:
parent
0313e38074
commit
bdd2f32c0f
6 changed files with 33 additions and 46 deletions
|
@ -232,7 +232,7 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
|||
fn parent_node(&self) -> Option<Self> {
|
||||
unsafe {
|
||||
self.node
|
||||
.parent_node_ref()
|
||||
.composed_parent_node_ref()
|
||||
.map(|node| self.new_with_this_lifetime(&node))
|
||||
}
|
||||
}
|
||||
|
@ -794,7 +794,12 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
|||
}
|
||||
|
||||
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
|
||||
unsafe { self.element.upcast().parent_node_ref().and_then(as_element) }
|
||||
unsafe {
|
||||
self.element
|
||||
.upcast()
|
||||
.composed_parent_node_ref()
|
||||
.and_then(as_element)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_node_is_shadow_root(&self) -> bool {
|
||||
|
@ -1083,12 +1088,10 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
|
|||
}
|
||||
|
||||
fn children(&self) -> LayoutIterator<Self::ChildrenIterator> {
|
||||
if let Some(element) = self.node.as_element() {
|
||||
if let Some(shadow) = element.shadow_root() {
|
||||
return LayoutIterator(ThreadSafeLayoutNodeChildrenIterator::new(
|
||||
shadow.as_node().to_threadsafe(),
|
||||
));
|
||||
}
|
||||
if let Some(shadow) = self.node.as_element().and_then(|e| e.shadow_root()) {
|
||||
return LayoutIterator(ThreadSafeLayoutNodeChildrenIterator::new(
|
||||
shadow.as_node().to_threadsafe(),
|
||||
));
|
||||
}
|
||||
LayoutIterator(ThreadSafeLayoutNodeChildrenIterator::new(*self))
|
||||
}
|
||||
|
|
|
@ -376,7 +376,7 @@ pub struct Document {
|
|||
delayed_tasks: DomRefCell<Vec<Box<dyn TaskBox>>>,
|
||||
/// https://html.spec.whatwg.org/multipage/#completely-loaded
|
||||
completely_loaded: Cell<bool>,
|
||||
/// List of shadow roots bound to the document tree.
|
||||
/// Set of shadow roots connected to the document tree.
|
||||
shadow_roots: DomRefCell<HashSet<Dom<ShadowRoot>>>,
|
||||
/// Whether any of the shadow roots need the stylesheets flushed.
|
||||
shadow_roots_styles_changed: Cell<bool>,
|
||||
|
|
|
@ -277,25 +277,20 @@ impl DocumentOrShadowRoot {
|
|||
"Removing named element {:p}: {:p} id={}",
|
||||
self, to_unregister, id
|
||||
);
|
||||
// Limit the scope of the borrow because id_map might be borrowed again by
|
||||
// GetElementById through the following sequence of calls
|
||||
// reset_form_owner_for_listeners -> reset_form_owner -> GetElementById
|
||||
{
|
||||
let mut id_map = id_map.borrow_mut();
|
||||
let is_empty = match id_map.get_mut(&id) {
|
||||
None => false,
|
||||
Some(elements) => {
|
||||
let position = elements
|
||||
.iter()
|
||||
.position(|element| &**element == to_unregister)
|
||||
.expect("This element should be in registered.");
|
||||
elements.remove(position);
|
||||
elements.is_empty()
|
||||
},
|
||||
};
|
||||
if is_empty {
|
||||
id_map.remove(&id);
|
||||
}
|
||||
let mut id_map = id_map.borrow_mut();
|
||||
let is_empty = match id_map.get_mut(&id) {
|
||||
None => false,
|
||||
Some(elements) => {
|
||||
let position = elements
|
||||
.iter()
|
||||
.position(|element| &**element == to_unregister)
|
||||
.expect("This element should be in registered.");
|
||||
elements.remove(position);
|
||||
elements.is_empty()
|
||||
},
|
||||
};
|
||||
if is_empty {
|
||||
id_map.remove(&id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -310,14 +305,8 @@ impl DocumentOrShadowRoot {
|
|||
debug!("Adding named element {:p}: {:p} id={}", self, element, id);
|
||||
assert!(element.upcast::<Node>().is_connected());
|
||||
assert!(!id.is_empty());
|
||||
|
||||
// Limit the scope of the borrow because id_map might be borrowed again by
|
||||
// GetElementById through the following sequence of calls
|
||||
// reset_form_owner_for_listeners -> reset_form_owner -> GetElementById
|
||||
{
|
||||
let mut id_map = id_map.borrow_mut();
|
||||
let elements = id_map.entry(id.clone()).or_insert(Vec::new());
|
||||
elements.insert_pre_order(element, &root);
|
||||
}
|
||||
let mut id_map = id_map.borrow_mut();
|
||||
let elements = id_map.entry(id.clone()).or_insert(Vec::new());
|
||||
elements.insert_pre_order(element, &root);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -994,7 +994,7 @@ impl LayoutElementHelpers for LayoutDom<Element> {
|
|||
unsafe {
|
||||
let mut current_node = Some(self.upcast::<Node>());
|
||||
while let Some(node) = current_node {
|
||||
current_node = node.parent_node_ref();
|
||||
current_node = node.composed_parent_node_ref();
|
||||
match node.downcast::<Element>().map(|el| el.unsafe_get()) {
|
||||
Some(elem) => {
|
||||
if let Some(attr) =
|
||||
|
|
|
@ -1175,7 +1175,7 @@ pub unsafe fn from_untrusted_node_address(
|
|||
pub trait LayoutNodeHelpers {
|
||||
unsafe fn type_id_for_layout(&self) -> NodeTypeId;
|
||||
|
||||
unsafe fn parent_node_ref(&self) -> Option<LayoutDom<Node>>;
|
||||
unsafe fn composed_parent_node_ref(&self) -> Option<LayoutDom<Node>>;
|
||||
unsafe fn first_child_ref(&self) -> Option<LayoutDom<Node>>;
|
||||
unsafe fn last_child_ref(&self) -> Option<LayoutDom<Node>>;
|
||||
unsafe fn prev_sibling_ref(&self) -> Option<LayoutDom<Node>>;
|
||||
|
@ -1222,7 +1222,7 @@ impl LayoutNodeHelpers for LayoutDom<Node> {
|
|||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn parent_node_ref(&self) -> Option<LayoutDom<Node>> {
|
||||
unsafe fn composed_parent_node_ref(&self) -> Option<LayoutDom<Node>> {
|
||||
let parent = (*self.unsafe_get()).parent_node.get_inner_as_layout();
|
||||
if let Some(ref parent) = parent {
|
||||
if let Some(shadow_root) = parent.downcast::<ShadowRoot>() {
|
||||
|
|
|
@ -10,7 +10,6 @@ use crate::dom::bindings::codegen::Bindings::RangeBinding::RangeMethods;
|
|||
use crate::dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants};
|
||||
use crate::dom::bindings::codegen::Bindings::TextBinding::TextMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::codegen::InheritTypes::DocumentFragmentTypeId;
|
||||
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::inheritance::{CharacterDataTypeId, NodeTypeId};
|
||||
|
@ -764,11 +763,7 @@ impl RangeMethods for Range {
|
|||
|
||||
// Step 11
|
||||
let new_offset = new_offset +
|
||||
if node.type_id() ==
|
||||
NodeTypeId::DocumentFragment(DocumentFragmentTypeId::DocumentFragment) ||
|
||||
node.type_id() ==
|
||||
NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot)
|
||||
{
|
||||
if let NodeTypeId::DocumentFragment(_) = node.type_id() {
|
||||
node.len()
|
||||
} else {
|
||||
1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue