зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #6715 - Implement more methods on LayoutJS (from Ms2ger:layoutelement); r=jdm
Source-Repo: https://github.com/servo/servo Source-Revision: f44d75e5b2e4229728d97b6a70de3babd3496eb1
This commit is contained in:
Родитель
5e560077e5
Коммит
7b2abc03ca
|
@ -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;
|
||||
|
@ -464,17 +464,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]
|
||||
|
@ -487,31 +483,23 @@ 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]
|
||||
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]
|
||||
|
|
|
@ -181,8 +181,6 @@ pub trait RawLayoutElementHelpers {
|
|||
|
||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V)
|
||||
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)
|
||||
-> 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,
|
||||
attribute: UnsignedIntegerAttribute)
|
||||
-> Option<u32> {
|
||||
|
@ -510,6 +485,8 @@ pub trait LayoutElementHelpers {
|
|||
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
|
||||
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<Element> {
|
||||
|
@ -548,6 +525,30 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
&(*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)]
|
||||
|
|
|
@ -1086,6 +1086,11 @@ pub trait LayoutNodeHelpers {
|
|||
unsafe fn layout_data_mut(&self) -> RefMut<Option<LayoutData>>;
|
||||
#[allow(unsafe_code)]
|
||||
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> {
|
||||
|
@ -1175,44 +1180,34 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
|||
unsafe fn layout_data_unchecked(&self) -> *const Option<LayoutData> {
|
||||
(*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]
|
||||
#[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)
|
||||
}
|
||||
#[inline]
|
||||
fn type_id_for_layout(&self) -> NodeTypeId {
|
||||
self.type_id
|
||||
fn get_enabled_state_for_layout(&self) -> bool {
|
||||
unsafe {
|
||||
self.get_flag(IN_ENABLED_STATE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче