Skip to content
Permalink
Browse files

Use bitflags! for NodeFlags

  • Loading branch information
brendanzab committed Jun 5, 2014
1 parent 7675b0c commit 7212c3573e7f2b13f907e17a5683d382b34ab932
Showing with 26 additions and 27 deletions.
  1. +26 −27 src/components/script/dom/node.rs
@@ -106,31 +106,22 @@ impl NodeDerived for EventTarget {
}
}

/// Flags for node items.
#[deriving(Encodable)]
pub struct NodeFlags(pub u8);
bitflags! {
#[doc = "Flags for node items."]
#[deriving(Encodable)]
flags NodeFlags: u8 {
#[doc = "Specifies whether this node is in a document."]
static IsInDoc = 0x01,
#[doc = "Specifies whether this node is hover state for this node"]
static InHoverState = 0x02
}
}

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)
/// Specifies whether this node is hover state for this node
bitfield!(NodeFlags, get_in_hover_state, set_is_in_hover_state, 0x02)

#[unsafe_destructor]
impl Drop for Node {
fn drop(&mut self) {
unsafe {
self.reap_layout_data()
DocumentNodeTypeId => IsInDoc,
_ => NodeFlags::empty(),
}
}
}
@@ -424,7 +415,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
}

fn is_in_doc(&self) -> bool {
self.deref().flags.is_in_doc()
self.deref().flags.contains(IsInDoc)
}

/// Returns the type ID of this node. Fails if this node is borrowed mutably.
@@ -483,11 +474,15 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
}

fn get_hover_state(&self) -> bool {
self.flags.get_in_hover_state()
self.flags.contains(InHoverState)
}

fn set_hover_state(&mut self, state: bool) {
self.flags.set_is_in_hover_state(state);
if state {
self.flags.insert(InHoverState);
} else {
self.flags.remove(InHoverState);
}
}

/// Iterates over this node and all its descendants, in preorder.
@@ -668,7 +663,7 @@ pub trait RawLayoutNodeHelpers {

impl RawLayoutNodeHelpers for Node {
unsafe fn get_hover_state_for_layout(&self) -> bool {
self.flags.get_in_hover_state()
self.flags.contains(InHoverState)
}
}

@@ -1071,7 +1066,11 @@ impl Node {
// Step 8.
for node in nodes.mut_iter() {
parent.add_child(node, child);
node.deref_mut().flags.set_is_in_doc(parent.is_in_doc());
if parent.is_in_doc() {
node.flags.insert(IsInDoc);
} else {
node.flags.remove(IsInDoc);
}
}

// Step 9.
@@ -1157,7 +1156,7 @@ impl Node {

// FIXME(2513): remove this `node_alias` when in fix mozilla#2513
let mut node_alias = node.clone();
node_alias.deref_mut().flags.set_is_in_doc(false);
node_alias.deref_mut().flags.remove(IsInDoc);

// Step 9.
match suppress_observers {

5 comments on commit 7212c35

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jun 5, 2014

saw approval from pcwalton
at brendanzab@7212c35

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jun 5, 2014

merging bjz/servo/cleanups = 7212c35 into auto

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jun 5, 2014

bjz/servo/cleanups = 7212c35 merged ok, testing candidate = 3dedbd2

@bors-servo

This comment has been minimized.

Copy link
Contributor

@bors-servo bors-servo replied Jun 6, 2014

fast-forwarding master to auto = 3dedbd2

Please sign in to comment.
You can’t perform that action at this time.