mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Auto merge of #6715 - Ms2ger:layoutelement, r=jdm
Implement more methods on LayoutJS. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6715) <!-- Reviewable:end -->
This commit is contained in:
commit
f44d75e5b2
3 changed files with 54 additions and 70 deletions
|
@ -53,7 +53,7 @@ use script::dom::htmlimageelement::LayoutHTMLImageElementHelpers;
|
||||||
use script::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
|
use script::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
|
||||||
use script::dom::htmltextareaelement::LayoutHTMLTextAreaElementHelpers;
|
use script::dom::htmltextareaelement::LayoutHTMLTextAreaElementHelpers;
|
||||||
use script::dom::node::{Node, NodeTypeId};
|
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::node::{HAS_CHANGED, IS_DIRTY, HAS_DIRTY_SIBLINGS, HAS_DIRTY_DESCENDANTS};
|
||||||
use script::dom::text::Text;
|
use script::dom::text::Text;
|
||||||
use smallvec::VecLike;
|
use smallvec::VecLike;
|
||||||
|
@ -464,17 +464,13 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_hover_state(&self) -> bool {
|
fn get_hover_state(&self) -> bool {
|
||||||
let node = NodeCast::from_layout_js(&self.element);
|
let node = NodeCast::from_layout_js(&self.element);
|
||||||
unsafe {
|
node.get_hover_state_for_layout()
|
||||||
(*node.unsafe_get()).get_hover_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_focus_state(&self) -> bool {
|
fn get_focus_state(&self) -> bool {
|
||||||
let node = NodeCast::from_layout_js(&self.element);
|
let node = NodeCast::from_layout_js(&self.element);
|
||||||
unsafe {
|
node.get_focus_state_for_layout()
|
||||||
(*node.unsafe_get()).get_focus_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -487,31 +483,23 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_disabled_state(&self) -> bool {
|
fn get_disabled_state(&self) -> bool {
|
||||||
let node = NodeCast::from_layout_js(&self.element);
|
let node = NodeCast::from_layout_js(&self.element);
|
||||||
unsafe {
|
node.get_disabled_state_for_layout()
|
||||||
(*node.unsafe_get()).get_disabled_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_enabled_state(&self) -> bool {
|
fn get_enabled_state(&self) -> bool {
|
||||||
let node = NodeCast::from_layout_js(&self.element);
|
let node = NodeCast::from_layout_js(&self.element);
|
||||||
unsafe {
|
node.get_enabled_state_for_layout()
|
||||||
(*node.unsafe_get()).get_enabled_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_checked_state(&self) -> bool {
|
fn get_checked_state(&self) -> bool {
|
||||||
unsafe {
|
self.element.get_checked_state_for_layout()
|
||||||
(*self.element.unsafe_get()).get_checked_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_indeterminate_state(&self) -> bool {
|
fn get_indeterminate_state(&self) -> bool {
|
||||||
unsafe {
|
self.element.get_indeterminate_state_for_layout()
|
||||||
(*self.element.unsafe_get()).get_indeterminate_state_for_layout()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -181,8 +181,6 @@ pub trait RawLayoutElementHelpers {
|
||||||
|
|
||||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
|
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
|
||||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
|
||||||
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)
|
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
|
||||||
-> Option<u32>;
|
-> Option<u32>;
|
||||||
}
|
}
|
||||||
|
@ -461,29 +459,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,
|
unsafe fn get_unsigned_integer_attribute_for_layout(&self,
|
||||||
attribute: UnsignedIntegerAttribute)
|
attribute: UnsignedIntegerAttribute)
|
||||||
-> Option<u32> {
|
-> Option<u32> {
|
||||||
|
@ -510,6 +485,8 @@ pub trait LayoutElementHelpers {
|
||||||
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
|
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
|
||||||
fn local_name<'a>(&'a self) -> &'a Atom;
|
fn local_name<'a>(&'a self) -> &'a Atom;
|
||||||
fn namespace<'a>(&'a self) -> &'a Namespace;
|
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<Element> {
|
impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
|
@ -548,6 +525,30 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
&(*self.unsafe_get()).namespace
|
&(*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)]
|
#[derive(PartialEq)]
|
||||||
|
|
|
@ -1086,6 +1086,11 @@ pub trait LayoutNodeHelpers {
|
||||||
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
|
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn layout_data_unchecked(&self) -> *const 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_disabled_state_for_layout(&self) -> bool;
|
||||||
|
fn get_enabled_state_for_layout(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutNodeHelpers for LayoutJS<Node> {
|
impl LayoutNodeHelpers for LayoutJS<Node> {
|
||||||
|
@ -1175,44 +1180,34 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
||||||
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
|
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
|
||||||
(*self.unsafe_get()).layout_data.borrow_unchecked()
|
(*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;
|
|
||||||
fn type_id_for_layout(&self) -> NodeTypeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RawLayoutNodeHelpers for Node {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_hover_state_for_layout(&self) -> bool {
|
fn get_hover_state_for_layout(&self) -> bool {
|
||||||
self.flags.get().contains(IN_HOVER_STATE)
|
unsafe {
|
||||||
|
self.get_flag(IN_HOVER_STATE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_focus_state_for_layout(&self) -> bool {
|
fn get_focus_state_for_layout(&self) -> bool {
|
||||||
self.flags.get().contains(IN_FOCUS_STATE)
|
unsafe {
|
||||||
|
self.get_flag(IN_FOCUS_STATE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_disabled_state_for_layout(&self) -> bool {
|
fn get_disabled_state_for_layout(&self) -> bool {
|
||||||
self.flags.get().contains(IN_DISABLED_STATE)
|
unsafe {
|
||||||
|
self.get_flag(IN_DISABLED_STATE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_enabled_state_for_layout(&self) -> bool {
|
fn get_enabled_state_for_layout(&self) -> bool {
|
||||||
self.flags.get().contains(IN_ENABLED_STATE)
|
unsafe {
|
||||||
}
|
self.get_flag(IN_ENABLED_STATE)
|
||||||
#[inline]
|
}
|
||||||
fn type_id_for_layout(&self) -> NodeTypeId {
|
|
||||||
self.type_id
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue