aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-04-10 12:25:42 -0500
committerbors-servo <metajack+bors@gmail.com>2015-04-10 12:25:42 -0500
commita8b0fb1e79ccc1a3da6ea4f58382b8482cdabd10 (patch)
tree93ecd36412fff334238dffd02931aba46756f66e /components/script/dom/element.rs
parent35fb5166624faa13d8a7090ce3f2456726547e11 (diff)
parent4e63a5063eb234d8b14daea9c20aa201989e1179 (diff)
downloadservo-a8b0fb1e79ccc1a3da6ea4f58382b8482cdabd10.tar.gz
servo-a8b0fb1e79ccc1a3da6ea4f58382b8482cdabd10.zip
Auto merge of #5592 - mbrubeck:focusable, r=jdm
This begins implementing parts of the [focusing steps](https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps) algorithm. r? @jdm or @Ms2ger
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 405ed80b95f..4625795b6c0 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -601,6 +601,53 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
}
}
+pub trait FocusElementHelpers {
+ /// https://html.spec.whatwg.org/multipage/interaction.html#focusable-area
+ fn is_focusable_area(self) -> bool;
+
+ /// https://html.spec.whatwg.org/multipage/scripting.html#concept-element-disabled
+ fn is_actually_disabled(self) -> bool;
+}
+
+impl<'a> FocusElementHelpers for JSRef<'a, Element> {
+ fn is_focusable_area(self) -> bool {
+ if self.is_actually_disabled() {
+ return false;
+ }
+ // TODO: Check whether the element is being rendered (i.e. not hidden).
+ // TODO: Check the tabindex focus flag.
+ // https://html.spec.whatwg.org/multipage/interaction.html#specially-focusable
+ let node: JSRef<Node> = NodeCast::from_ref(self);
+ match node.type_id() {
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
+ true
+ }
+ _ => false
+ }
+ }
+
+ fn is_actually_disabled(self) -> bool {
+ let node: JSRef<Node> = NodeCast::from_ref(self);
+ match node.type_id() {
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) |
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptionElement)) => {
+ node.get_disabled_state()
+ }
+ // TODO:
+ // an optgroup element that has a disabled attribute
+ // a menuitem element that has a disabled attribute
+ // a fieldset element that is a disabled fieldset
+ _ => false
+ }
+ }
+}
+
pub trait AttributeHandlers {
/// Returns the attribute with given namespace and case-sensitive local
/// name, if any.