aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2015-04-07 17:27:58 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2015-04-10 10:16:06 -0700
commit4e63a5063eb234d8b14daea9c20aa201989e1179 (patch)
tree93ecd36412fff334238dffd02931aba46756f66e /components/script
parent35fb5166624faa13d8a7090ce3f2456726547e11 (diff)
downloadservo-4e63a5063eb234d8b14daea9c20aa201989e1179.tar.gz
servo-4e63a5063eb234d8b14daea9c20aa201989e1179.zip
Don't allow disabled fields to be focused
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/document.rs6
-rw-r--r--components/script/dom/element.rs47
2 files changed, 51 insertions, 2 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index ca4182164d8..57cee418838 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -36,7 +36,7 @@ use dom::documentfragment::DocumentFragment;
use dom::documenttype::DocumentType;
use dom::domimplementation::DOMImplementation;
use dom::element::{Element, ElementCreator, AttributeHandlers};
-use dom::element::{ElementTypeId, ActivationElementHelpers};
+use dom::element::{ElementTypeId, ActivationElementHelpers, FocusElementHelpers};
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers};
use dom::htmlanchorelement::HTMLAnchorElement;
@@ -448,7 +448,9 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
/// Request that the given element receive focus once the current transaction is complete.
fn request_focus(self, elem: JSRef<Element>) {
- self.possibly_focused.assign(Some(elem))
+ if elem.is_focusable_area() {
+ self.possibly_focused.assign(Some(elem))
+ }
}
/// Reassign the focus context to the element that last requested focus during this
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.