From 32ee62b4c8d66a1630c31f1b7a2e68dd81e7e332 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 23 Jul 2015 19:54:12 +0200 Subject: [PATCH 1/3] Remove unused RawLayoutNodeHelpers::type_id_for_layout. --- components/script/dom/node.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index ab48fcd1e35..81b2a8bbae4 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1185,7 +1185,6 @@ pub trait RawLayoutNodeHelpers { unsafe fn get_disabled_state_for_layout(&self) -> bool; #[allow(unsafe_code)] unsafe fn get_enabled_state_for_layout(&self) -> bool; - fn type_id_for_layout(&self) -> NodeTypeId; } impl RawLayoutNodeHelpers for Node { @@ -1209,10 +1208,6 @@ impl RawLayoutNodeHelpers for Node { unsafe fn get_enabled_state_for_layout(&self) -> bool { self.flags.get().contains(IN_ENABLED_STATE) } - #[inline] - fn type_id_for_layout(&self) -> NodeTypeId { - self.type_id - } } From 849eb7837a80acfd81fb3840f166ba754ea38b76 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 23 Jul 2015 20:13:06 +0200 Subject: [PATCH 2/3] Move the flag getters to LayoutNodeHelpers. --- components/layout/wrapper.rs | 18 +++++---------- components/script/dom/node.rs | 42 +++++++++++++++++------------------ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 762f7dba2a0..35bb53865f2 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -53,7 +53,7 @@ use script::dom::htmlimageelement::LayoutHTMLImageElementHelpers; use script::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers}; use script::dom::htmltextareaelement::LayoutHTMLTextAreaElementHelpers; use script::dom::node::{Node, NodeTypeId}; -use script::dom::node::{LayoutNodeHelpers, RawLayoutNodeHelpers, SharedLayoutData}; +use script::dom::node::{LayoutNodeHelpers, SharedLayoutData}; use script::dom::node::{HAS_CHANGED, IS_DIRTY, HAS_DIRTY_SIBLINGS, HAS_DIRTY_DESCENDANTS}; use script::dom::text::Text; use smallvec::VecLike; @@ -439,17 +439,13 @@ impl<'le> ::selectors::Element for LayoutElement<'le> { #[inline] fn get_hover_state(&self) -> bool { let node = NodeCast::from_layout_js(&self.element); - unsafe { - (*node.unsafe_get()).get_hover_state_for_layout() - } + node.get_hover_state_for_layout() } #[inline] fn get_focus_state(&self) -> bool { let node = NodeCast::from_layout_js(&self.element); - unsafe { - (*node.unsafe_get()).get_focus_state_for_layout() - } + node.get_focus_state_for_layout() } #[inline] @@ -462,17 +458,13 @@ impl<'le> ::selectors::Element for LayoutElement<'le> { #[inline] fn get_disabled_state(&self) -> bool { let node = NodeCast::from_layout_js(&self.element); - unsafe { - (*node.unsafe_get()).get_disabled_state_for_layout() - } + node.get_disabled_state_for_layout() } #[inline] fn get_enabled_state(&self) -> bool { let node = NodeCast::from_layout_js(&self.element); - unsafe { - (*node.unsafe_get()).get_enabled_state_for_layout() - } + node.get_enabled_state_for_layout() } #[inline] diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 81b2a8bbae4..822d7125623 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1085,6 +1085,11 @@ pub trait LayoutNodeHelpers { unsafe fn layout_data_mut(&self) -> RefMut>; #[allow(unsafe_code)] unsafe fn layout_data_unchecked(&self) -> *const Option; + + fn get_hover_state_for_layout(&self) -> bool; + fn get_focus_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 { @@ -1174,39 +1179,34 @@ impl LayoutNodeHelpers for LayoutJS { unsafe fn layout_data_unchecked(&self) -> *const Option { (*self.unsafe_get()).layout_data.borrow_unchecked() } -} -pub trait RawLayoutNodeHelpers { - #[allow(unsafe_code)] - unsafe fn get_hover_state_for_layout(&self) -> bool; - #[allow(unsafe_code)] - unsafe fn get_focus_state_for_layout(&self) -> bool; - #[allow(unsafe_code)] - unsafe fn get_disabled_state_for_layout(&self) -> bool; - #[allow(unsafe_code)] - unsafe fn get_enabled_state_for_layout(&self) -> bool; -} - -impl RawLayoutNodeHelpers for Node { #[inline] #[allow(unsafe_code)] - unsafe fn get_hover_state_for_layout(&self) -> bool { - self.flags.get().contains(IN_HOVER_STATE) + fn get_hover_state_for_layout(&self) -> bool { + unsafe { + self.get_flag(IN_HOVER_STATE) + } } #[inline] #[allow(unsafe_code)] - unsafe fn get_focus_state_for_layout(&self) -> bool { - self.flags.get().contains(IN_FOCUS_STATE) + fn get_focus_state_for_layout(&self) -> bool { + unsafe { + self.get_flag(IN_FOCUS_STATE) + } } #[inline] #[allow(unsafe_code)] - unsafe fn get_disabled_state_for_layout(&self) -> bool { - self.flags.get().contains(IN_DISABLED_STATE) + fn get_disabled_state_for_layout(&self) -> bool { + unsafe { + self.get_flag(IN_DISABLED_STATE) + } } #[inline] #[allow(unsafe_code)] - unsafe fn get_enabled_state_for_layout(&self) -> bool { - self.flags.get().contains(IN_ENABLED_STATE) + fn get_enabled_state_for_layout(&self) -> bool { + unsafe { + self.get_flag(IN_ENABLED_STATE) + } } } From 487eef88e314874a275ebc25e8e4658186f68dff Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 23 Jul 2015 20:30:59 +0200 Subject: [PATCH 3/3] Move the state getters to LayoutElementHelpers. --- components/layout/wrapper.rs | 8 ++--- components/script/dom/element.rs | 51 ++++++++++++++++---------------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 35bb53865f2..e856dcf3e51 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -469,16 +469,12 @@ impl<'le> ::selectors::Element for LayoutElement<'le> { #[inline] fn get_checked_state(&self) -> bool { - unsafe { - (*self.element.unsafe_get()).get_checked_state_for_layout() - } + self.element.get_checked_state_for_layout() } #[inline] fn get_indeterminate_state(&self) -> bool { - unsafe { - (*self.element.unsafe_get()).get_indeterminate_state_for_layout() - } + self.element.get_indeterminate_state_for_layout() } #[inline] diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a5fc6f955da..81db37aa09b 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -177,8 +177,6 @@ pub trait RawLayoutElementHelpers { unsafe fn synthesize_presentational_hints_for_legacy_attributes(&self, &mut V) where V: VecLike>>; - unsafe fn get_checked_state_for_layout(&self) -> bool; - unsafe fn get_indeterminate_state_for_layout(&self) -> bool; unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) -> Option; } @@ -457,29 +455,6 @@ impl RawLayoutElementHelpers for Element { } } - #[inline] - #[allow(unrooted_must_root)] - unsafe fn get_checked_state_for_layout(&self) -> bool { - // TODO option and menuitem can also have a checked state. - if !self.is_htmlinputelement() { - return false - } - let this: &HTMLInputElement = mem::transmute(self); - this.get_checked_state_for_layout() - } - - #[inline] - #[allow(unrooted_must_root)] - unsafe fn get_indeterminate_state_for_layout(&self) -> bool { - // TODO progress elements can also be matched with :indeterminate - if !self.is_htmlinputelement() { - return false - } - let this: &HTMLInputElement = mem::transmute(self); - this.get_indeterminate_state_for_layout() - } - - unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) -> Option { @@ -506,6 +481,8 @@ pub trait LayoutElementHelpers { fn style_attribute(&self) -> *const Option; fn local_name<'a>(&'a self) -> &'a Atom; fn namespace<'a>(&'a self) -> &'a Namespace; + fn get_checked_state_for_layout(&self) -> bool; + fn get_indeterminate_state_for_layout(&self) -> bool; } impl LayoutElementHelpers for LayoutJS { @@ -544,6 +521,30 @@ impl LayoutElementHelpers for LayoutJS { &(*self.unsafe_get()).namespace } } + + #[inline] + #[allow(unsafe_code)] + fn get_checked_state_for_layout(&self) -> bool { + // TODO option and menuitem can also have a checked state. + match HTMLInputElementCast::to_layout_js(self) { + Some(input) => unsafe { + (*input.unsafe_get()).get_checked_state_for_layout() + }, + None => false, + } + } + + #[inline] + #[allow(unsafe_code)] + fn get_indeterminate_state_for_layout(&self) -> bool { + // TODO progress elements can also be matched with :indeterminate + match HTMLInputElementCast::to_layout_js(self) { + Some(input) => unsafe { + (*input.unsafe_get()).get_indeterminate_state_for_layout() + }, + None => false, + } + } } #[derive(PartialEq)]