Skip to content

Commit

Permalink
Minor tweaks: rename composed_parent_node_ref, remove or update outda…
Browse files Browse the repository at this point in the history
…ted comments...
  • Loading branch information
ferjm committed Apr 26, 2019
1 parent 0313e38 commit bdd2f32
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 46 deletions.
19 changes: 11 additions & 8 deletions components/layout_thread/dom_wrapper.rs
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/document.rs
Expand Up @@ -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>,
Expand Down
45 changes: 17 additions & 28 deletions components/script/dom/documentorshadowroot.rs
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -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) =
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/node.rs
Expand Up @@ -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>>;
Expand Down Expand Up @@ -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>() {
Expand Down
7 changes: 1 addition & 6 deletions components/script/dom/range.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bdd2f32

Please sign in to comment.