mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #7935 - bholley:eventstate_element, r=nox
Move event state from Node to Element Just getting my feet wet with Rust here. Please feel free to nit the hell out of it stylistically and idiomatically. :-) <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7935) <!-- Reviewable:end -->
This commit is contained in:
commit
ff2151b8bb
15 changed files with 295 additions and 307 deletions
|
@ -25,8 +25,7 @@ use dom::bindings::codegen::InheritTypes::{CharacterDataCast, CharacterDataTypeI
|
|||
use dom::bindings::codegen::InheritTypes::{DocumentCast, DocumentDerived, DocumentTypeCast};
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, ElementTypeId};
|
||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, EventTargetTypeId};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, HTMLFieldSetElementDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLLegendElementDerived, HTMLOptGroupElementDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId};
|
||||
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, NodeTypeId};
|
||||
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, TextCast, TextDerived};
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
|
@ -130,40 +129,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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -479,49 +466,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)
|
||||
}
|
||||
|
@ -1040,12 +984,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> {
|
||||
|
@ -1141,42 +1079,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1410,11 +1312,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)]
|
||||
|
@ -2527,53 +2425,6 @@ impl VirtualMethods for Node {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Node {
|
||||
pub fn check_ancestors_disabled_state_for_form_control(&self) {
|
||||
if self.get_disabled_state() { return; }
|
||||
for ancestor in self.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) {
|
||||
self.set_disabled_state(true);
|
||||
self.set_enabled_state(false);
|
||||
return;
|
||||
}
|
||||
match ancestor.children()
|
||||
.find(|child| child.r().is_htmllegendelement())
|
||||
{
|
||||
Some(ref legend) => {
|
||||
// XXXabinader: should we save previous ancestor to avoid this iteration?
|
||||
if self.ancestors().any(|ancestor| ancestor == *legend) { continue; }
|
||||
},
|
||||
None => ()
|
||||
}
|
||||
self.set_disabled_state(true);
|
||||
self.set_enabled_state(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
self.set_disabled_state(true);
|
||||
self.set_enabled_state(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_disabled_attribute(&self) {
|
||||
let elem = ElementCast::to_ref(self).unwrap();
|
||||
let has_disabled_attrib = elem.has_attribute(&atom!("disabled"));
|
||||
self.set_disabled_state(has_disabled_attrib);
|
||||
self.set_enabled_state(!has_disabled_attrib);
|
||||
}
|
||||
}
|
||||
|
||||
/// A summary of the changes that happened to a node.
|
||||
#[derive(Copy, Clone, PartialEq, HeapSizeOf)]
|
||||
pub enum NodeDamage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue