Implement the :focus pseudo-class selector

Fixes #5460. This supports for simple focusable elements that are their own
DOM anchors, like text `input` fields.
This commit is contained in:
Matt Brubeck 2015-03-30 10:39:13 -07:00
parent ad6c511a5e
commit 791fa3757d
10 changed files with 106 additions and 9 deletions

View file

@ -454,7 +454,20 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
/// transaction, or none if no elements requested it.
fn commit_focus_transaction(self) {
//TODO: dispatch blur, focus, focusout, and focusin events
if let Some(ref elem) = self.focused.get().root() {
let node: JSRef<Node> = NodeCast::from_ref(elem.r());
node.set_focus_state(false);
}
self.focused.assign(self.possibly_focused.get());
if let Some(ref elem) = self.focused.get().root() {
let node: JSRef<Node> = NodeCast::from_ref(elem.r());
node.set_focus_state(true);
}
// TODO: Update the focus state for all elements in the focus chain.
// https://html.spec.whatwg.org/multipage/interaction.html#focus-chain
}
/// Handles any updates when the document's title has changed.