fixup! Fixed issue #11651 (Do not fire a blur event when calling .focus() on a focused element)

This commit is contained in:
Davide Giovannini 2016-06-10 11:36:08 +02:00
parent 35aa24eb4c
commit 01c3640e5f
2 changed files with 20 additions and 22 deletions

View file

@ -598,27 +598,28 @@ impl Document {
/// Reassign the focus context to the element that last requested focus during this /// Reassign the focus context to the element that last requested focus during this
/// transaction, or none if no elements requested it. /// transaction, or none if no elements requested it.
pub fn commit_focus_transaction(&self, focus_type: FocusType) { pub fn commit_focus_transaction(&self, focus_type: FocusType) {
if self.focused != self.possibly_focused.get().r() { if self.focused == self.possibly_focused.get().r() {
if let Some(ref elem) = self.focused.get() { return
let node = elem.upcast::<Node>(); }
elem.set_focus_state(false); if let Some(ref elem) = self.focused.get() {
// FIXME: pass appropriate relatedTarget let node = elem.upcast::<Node>();
self.fire_focus_event(FocusEventType::Blur, node, None); elem.set_focus_state(false);
} // FIXME: pass appropriate relatedTarget
self.fire_focus_event(FocusEventType::Blur, node, None);
}
self.focused.set(self.possibly_focused.get().r()); self.focused.set(self.possibly_focused.get().r());
if let Some(ref elem) = self.focused.get() { if let Some(ref elem) = self.focused.get() {
elem.set_focus_state(true); elem.set_focus_state(true);
let node = elem.upcast::<Node>(); let node = elem.upcast::<Node>();
// FIXME: pass appropriate relatedTarget // FIXME: pass appropriate relatedTarget
self.fire_focus_event(FocusEventType::Focus, node, None); self.fire_focus_event(FocusEventType::Focus, node, None);
// Update the focus state for all elements in the focus chain. // Update the focus state for all elements in the focus chain.
// https://html.spec.whatwg.org/multipage/#focus-chain // https://html.spec.whatwg.org/multipage/#focus-chain
if focus_type == FocusType::Element { if focus_type == FocusType::Element {
let event = ConstellationMsg::Focus(self.window.pipeline()); let event = ConstellationMsg::Focus(self.window.pipeline());
self.window.constellation_chan().send(event).unwrap(); self.window.constellation_chan().send(event).unwrap();
}
} }
} }
} }

View file

@ -251,9 +251,6 @@ impl HTMLElementMethods for HTMLElement {
fn Focus(&self) { fn Focus(&self) {
// TODO: Mark the element as locked for focus and run the focusing steps. // TODO: Mark the element as locked for focus and run the focusing steps.
// https://html.spec.whatwg.org/multipage/#focusing-steps // https://html.spec.whatwg.org/multipage/#focusing-steps
if self.upcast::<Element>().focus_state() {
return;
}
let document = document_from_node(self); let document = document_from_node(self);
document.begin_focus_transaction(); document.begin_focus_transaction();
document.request_focus(self.upcast()); document.request_focus(self.upcast());