aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/node.rs
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2015-10-07 20:02:00 -0700
committerBobby Holley <bobbyholley@gmail.com>2015-10-16 17:56:31 -0700
commit75ec093334ff8f8f7ef41b90007588b924c40731 (patch)
treeba73c6dc51812c01f118e63c90ede1d8638f060d /components/script/dom/node.rs
parent628c2a04326b27ac2743771dca52612c8ce30ad2 (diff)
downloadservo-75ec093334ff8f8f7ef41b90007588b924c40731.tar.gz
servo-75ec093334ff8f8f7ef41b90007588b924c40731.zip
Move Event States to |Element|.
Conceptually they belong there, rather than on |Node|. Fixes #7934.
Diffstat (limited to 'components/script/dom/node.rs')
-rw-r--r--components/script/dom/node.rs136
1 files changed, 18 insertions, 118 deletions
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index daacdd09fa0..0629c816c5a 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -125,40 +125,28 @@ impl PartialEq for Node {
bitflags! {
#[doc = "Flags for node items."]
#[derive(JSTraceable, HeapSizeOf)]
- flags NodeFlags: u16 {
+ flags NodeFlags: u8 {
#[doc = "Specifies whether this node is in a document."]
const IS_IN_DOC = 0x01,
- #[doc = "Specifies whether this node is in hover state."]
- const IN_HOVER_STATE = 0x02,
- #[doc = "Specifies whether this node is in disabled state."]
- const IN_DISABLED_STATE = 0x04,
- #[doc = "Specifies whether this node is in enabled state."]
- const IN_ENABLED_STATE = 0x08,
#[doc = "Specifies whether this node _must_ be reflowed regardless of style differences."]
- const HAS_CHANGED = 0x10,
+ const HAS_CHANGED = 0x02,
#[doc = "Specifies whether this node needs style recalc on next reflow."]
- const IS_DIRTY = 0x20,
+ const IS_DIRTY = 0x04,
#[doc = "Specifies whether this node has siblings (inclusive of itself) which \
changed since the last reflow."]
- const HAS_DIRTY_SIBLINGS = 0x40,
+ const HAS_DIRTY_SIBLINGS = 0x08,
#[doc = "Specifies whether this node has descendants (inclusive of itself) which \
have changed since the last reflow."]
- const HAS_DIRTY_DESCENDANTS = 0x80,
+ const HAS_DIRTY_DESCENDANTS = 0x10,
// TODO: find a better place to keep this (#4105)
// https://critic.hoppipolla.co.uk/showcomment?chain=8873
// Perhaps using a Set in Document?
#[doc = "Specifies whether or not there is an authentic click in progress on \
this element."]
- const CLICK_IN_PROGRESS = 0x100,
- #[doc = "Specifies whether this node has the focus."]
- const IN_FOCUS_STATE = 0x200,
+ const CLICK_IN_PROGRESS = 0x20,
#[doc = "Specifies whether this node is focusable and whether it is supposed \
to be reachable with using sequential focus navigation."]
- const SEQUENTIALLY_FOCUSABLE = 0x400,
- #[doc = "Specifies whether this node is [being activated]\
- (https://html.spec.whatwg.org/multipage/#selector-active). \
- FIXME(#7333): set/unset this when appropriate"]
- const IN_ACTIVE_STATE = 0x800,
+ const SEQUENTIALLY_FOCUSABLE = 0x40,
}
}
@@ -474,49 +462,6 @@ impl Node {
self.flags.set(flags);
}
- pub fn get_hover_state(&self) -> bool {
- self.get_flag(IN_HOVER_STATE)
- }
-
- pub fn set_hover_state(&self, state: bool) {
- self.set_flag(IN_HOVER_STATE, state);
- self.dirty(NodeDamage::NodeStyleDamaged);
- }
-
- pub fn get_focus_state(&self) -> bool {
- self.get_flag(IN_FOCUS_STATE)
- }
-
- pub fn set_focus_state(&self, state: bool) {
- self.set_flag(IN_FOCUS_STATE, state);
- self.dirty(NodeDamage::NodeStyleDamaged);
- }
-
- pub fn get_active_state(&self) -> bool {
- self.get_flag(IN_ACTIVE_STATE)
- }
-
- pub fn set_active_state(&self, state: bool) {
- self.set_flag(IN_ACTIVE_STATE, state);
- self.dirty(NodeDamage::NodeStyleDamaged);
- }
-
- pub fn get_disabled_state(&self) -> bool {
- self.get_flag(IN_DISABLED_STATE)
- }
-
- pub fn set_disabled_state(&self, state: bool) {
- self.set_flag(IN_DISABLED_STATE, state)
- }
-
- pub fn get_enabled_state(&self) -> bool {
- self.get_flag(IN_ENABLED_STATE)
- }
-
- pub fn set_enabled_state(&self, state: bool) {
- self.set_flag(IN_ENABLED_STATE, state)
- }
-
pub fn get_has_changed(&self) -> bool {
self.get_flag(HAS_CHANGED)
}
@@ -975,12 +920,6 @@ pub trait LayoutNodeHelpers {
unsafe fn layout_data(&self) -> Ref<Option<LayoutData>>;
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData>;
-
- fn get_hover_state_for_layout(&self) -> bool;
- fn get_focus_state_for_layout(&self) -> bool;
- fn get_active_state_for_layout(&self) -> bool;
- fn get_disabled_state_for_layout(&self) -> bool;
- fn get_enabled_state_for_layout(&self) -> bool;
}
impl LayoutNodeHelpers for LayoutJS<Node> {
@@ -1076,42 +1015,6 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
(*self.unsafe_get()).layout_data.borrow_unchecked()
}
-
- #[inline]
- #[allow(unsafe_code)]
- fn get_hover_state_for_layout(&self) -> bool {
- unsafe {
- self.get_flag(IN_HOVER_STATE)
- }
- }
- #[inline]
- #[allow(unsafe_code)]
- fn get_focus_state_for_layout(&self) -> bool {
- unsafe {
- self.get_flag(IN_FOCUS_STATE)
- }
- }
- #[inline]
- #[allow(unsafe_code)]
- fn get_active_state_for_layout(&self) -> bool {
- unsafe {
- self.get_flag(IN_ACTIVE_STATE)
- }
- }
- #[inline]
- #[allow(unsafe_code)]
- fn get_disabled_state_for_layout(&self) -> bool {
- unsafe {
- self.get_flag(IN_DISABLED_STATE)
- }
- }
- #[inline]
- #[allow(unsafe_code)]
- fn get_enabled_state_for_layout(&self) -> bool {
- unsafe {
- self.get_flag(IN_ENABLED_STATE)
- }
- }
}
@@ -1345,11 +1248,7 @@ impl Node {
}
pub fn new_inherited(doc: &Document) -> Node {
- Node::new_inherited_with_flags(NodeFlags::new(), doc)
- }
-
- pub fn new_inherited_with_flags(flags: NodeFlags, doc: &Document) -> Node {
- Node::new_(flags, Some(doc))
+ Node::new_(NodeFlags::new(), Some(doc))
}
#[allow(unrooted_must_root)]
@@ -2463,15 +2362,16 @@ impl VirtualMethods for Node {
}
-impl Node {
+impl Element {
pub fn check_ancestors_disabled_state_for_form_control(&self) {
+ let node = NodeCast::from_ref(self);
if self.get_disabled_state() { return; }
- for ancestor in self.ancestors() {
+ for ancestor in node.ancestors() {
let ancestor = ancestor;
let ancestor = ancestor.r();
if !ancestor.is_htmlfieldsetelement() { continue; }
- if !ancestor.get_disabled_state() { continue; }
- if ancestor.is_parent_of(self) {
+ if !ElementCast::to_ref(ancestor).unwrap().get_disabled_state() { continue; }
+ if ancestor.is_parent_of(node) {
self.set_disabled_state(true);
self.set_enabled_state(false);
return;
@@ -2481,7 +2381,7 @@ impl Node {
{
Some(ref legend) => {
// XXXabinader: should we save previous ancestor to avoid this iteration?
- if self.ancestors().any(|ancestor| ancestor == *legend) { continue; }
+ if node.ancestors().any(|ancestor| ancestor == *legend) { continue; }
},
None => ()
}
@@ -2493,8 +2393,9 @@ impl Node {
pub fn check_parent_disabled_state_for_option(&self) {
if self.get_disabled_state() { return; }
- if let Some(ref parent) = self.GetParentNode() {
- if parent.r().is_htmloptgroupelement() && parent.r().get_disabled_state() {
+ let node = NodeCast::from_ref(self);
+ if let Some(ref parent) = node.GetParentNode() {
+ if parent.r().is_htmloptgroupelement() && ElementCast::to_ref(parent.r()).unwrap().get_disabled_state() {
self.set_disabled_state(true);
self.set_enabled_state(false);
}
@@ -2502,8 +2403,7 @@ impl Node {
}
pub fn check_disabled_attribute(&self) {
- let elem = ElementCast::to_ref(self).unwrap();
- let has_disabled_attrib = elem.has_attribute(&atom!("disabled"));
+ let has_disabled_attrib = self.has_attribute(&atom!("disabled"));
self.set_disabled_state(has_disabled_attrib);
self.set_enabled_state(!has_disabled_attrib);
}