aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2013-12-17 12:41:10 -0800
committerbors-servo <release+servo@mozilla.com>2013-12-17 12:41:10 -0800
commit44a8b0987c0bc0b136cfb4c75bc35a4a0de34465 (patch)
tree9ac3ba7409ffde34d794863c6cc82b7039822d94 /src
parent0e14745762bb29a050bfc07c507d57a0f3acda1e (diff)
parentcfb73ed1239f14c7c895de9db44ef9a8814e72c0 (diff)
downloadservo-44a8b0987c0bc0b136cfb4c75bc35a4a0de34465.tar.gz
servo-44a8b0987c0bc0b136cfb4c75bc35a4a0de34465.zip
auto merge of #1427 : brunoabinader/servo/is-in-doc, r=jdm
Added a flags variable inside Node to represent boolean flags, with is_in_doc being the first of them. It is updated whenever a node is appended or removed from a parent. This patch is for: https://github.com/mozilla/servo/issues/1030
Diffstat (limited to 'src')
-rw-r--r--src/components/script/dom/node.rs27
-rw-r--r--src/components/script/macros.rs22
-rw-r--r--src/components/script/script.rc3
3 files changed, 50 insertions, 2 deletions
diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs
index 870e636e363..712bdd4b00d 100644
--- a/src/components/script/dom/node.rs
+++ b/src/components/script/dom/node.rs
@@ -91,6 +91,9 @@ pub struct Node<View> {
/// The live list of children return by .childNodes.
child_list: Option<@mut NodeList>,
+ /// A bitfield of flags for node items.
+ priv flags: NodeFlags,
+
/// Layout information. Only the layout task may touch this data.
///
/// FIXME(pcwalton): We need to send these back to the layout task to be destroyed when this
@@ -98,6 +101,23 @@ pub struct Node<View> {
layout_data: LayoutDataRef,
}
+/// Flags for node items.
+pub struct NodeFlags(u8);
+
+impl NodeFlags {
+ pub fn new(type_id: NodeTypeId) -> NodeFlags {
+ let mut flags = NodeFlags(0);
+ match type_id {
+ DocumentNodeTypeId(_) => { flags.set_is_in_doc(true); }
+ _ => {}
+ }
+ flags
+ }
+}
+
+/// Specifies whether this node is in a document.
+bitfield!(NodeFlags, is_in_doc, set_is_in_doc, 0x01)
+
#[unsafe_destructor]
impl<T> Drop for Node<T> {
fn drop(&mut self) {
@@ -546,9 +566,8 @@ impl<'self, View> AbstractNode<View> {
self.node().children()
}
- // Issue #1030: should not walk the tree
pub fn is_in_doc(&self) -> bool {
- self.ancestors().any(|node| node.is_document())
+ self.node().flags.is_in_doc()
}
}
@@ -649,6 +668,8 @@ impl Node<ScriptView> {
owner_doc: doc,
child_list: None,
+ flags: NodeFlags::new(type_id),
+
layout_data: LayoutDataRef::init(),
}
}
@@ -1002,6 +1023,7 @@ impl Node<ScriptView> {
// Step 8.
for node in nodes.iter() {
parent.add_child(*node, child);
+ node.mut_node().flags.set_is_in_doc(parent.is_in_doc());
}
// Step 9.
@@ -1080,6 +1102,7 @@ impl Node<ScriptView> {
// Step 6-7: mutation observers.
// Step 8.
parent.remove_child(node);
+ node.mut_node().flags.set_is_in_doc(false);
// Step 9.
if !suppress_observers {
diff --git a/src/components/script/macros.rs b/src/components/script/macros.rs
new file mode 100644
index 00000000000..f8eaa07cc05
--- /dev/null
+++ b/src/components/script/macros.rs
@@ -0,0 +1,22 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#[macro_escape];
+
+macro_rules! bitfield(
+ ($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
+ impl $bitfieldname {
+ #[inline]
+ pub fn $getter(self) -> bool {
+ (*self & $value) != 0
+ }
+
+ #[inline]
+ pub fn $setter(&mut self, value: bool) {
+ *self = $bitfieldname((**self & !$value) | (if value { $value } else { 0 }))
+ }
+ }
+ )
+)
+
diff --git a/src/components/script/script.rc b/src/components/script/script.rc
index 63e23211a01..7490024aeb8 100644
--- a/src/components/script/script.rc
+++ b/src/components/script/script.rc
@@ -23,6 +23,9 @@ extern mod style;
extern mod servo_msg (name = "msg");
extern mod extra;
+// Macros
+mod macros;
+
pub mod dom {
pub mod bindings {
pub mod element;