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