Skip to content

Commit

Permalink
Use bitflags! for NodeFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Jun 5, 2014
1 parent 7675b0c commit 7212c35
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/components/script/dom/node.rs
Expand Up @@ -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(),
}
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

5 comments on commit 7212c35

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at brendanzab@7212c35

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging bjz/servo/cleanups = 7212c35 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 3dedbd2

Please sign in to comment.