Minor tweaks: rename composed_parent_node_ref, remove or update outdated comments...

This commit is contained in:
Fernando Jiménez Moreno 2019-03-07 13:10:04 +01:00
parent 0313e38074
commit bdd2f32c0f
6 changed files with 33 additions and 46 deletions

View file

@ -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,13 +1088,11 @@ 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))
} }

View file

@ -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>,

View file

@ -277,10 +277,6 @@ 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
// 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 mut id_map = id_map.borrow_mut();
let is_empty = match id_map.get_mut(&id) { let is_empty = match id_map.get_mut(&id) {
None => false, None => false,
@ -297,7 +293,6 @@ impl DocumentOrShadowRoot {
id_map.remove(&id); id_map.remove(&id);
} }
} }
}
/// Associate an element present in this document with the provided id. /// Associate an element present in this document with the provided id.
pub fn register_named_element( pub fn register_named_element(
@ -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());
// 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 mut id_map = id_map.borrow_mut();
let elements = id_map.entry(id.clone()).or_insert(Vec::new()); let elements = id_map.entry(id.clone()).or_insert(Vec::new());
elements.insert_pre_order(element, &root); elements.insert_pre_order(element, &root);
} }
}
} }

View file

@ -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) =

View file

@ -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>() {

View file

@ -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