servo: Merge #11665 - Fixed issue #11651 (Do not fire a blur event when calling .focus() on… (from davideGiovannini:master); r=KiChjang
authorDavide Giovannini <giovannini.davide90@gmail.com>
Fri, 24 Jun 2016 23:34:37 -0500
changeset 339130 8207a383b070baea89d6e041f649e587f9fcd054
parent 339129 6366f60546872b0156cdba2d5d8324225122c55e
child 339131 737c883be6d8897f8bc0c36688f411f98b83dd64
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKiChjang
servo: Merge #11665 - Fixed issue #11651 (Do not fire a blur event when calling .focus() on… (from davideGiovannini:master); r=KiChjang <!-- Please describe your changes on the following line: --> Added check in `HTMLElement.Focus` to avoid requesting focus when the element already has it. Added check in `Document.commit_focus_transaction` to avoid sending `blur` and `focus` events when clicking on an already focused element. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #11651 <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ Source-Repo: https://github.com/servo/servo Source-Revision: 7d978e7b3d6b41b234f7c9b4051b746a1fbeddee
servo/components/script/dom/document.rs
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -594,16 +594,19 @@ impl Document {
         if elem.is_focusable_area() {
             self.possibly_focused.set(Some(elem))
         }
     }
 
     /// Reassign the focus context to the element that last requested focus during this
     /// transaction, or none if no elements requested it.
     pub fn commit_focus_transaction(&self, focus_type: FocusType) {
+        if self.focused == self.possibly_focused.get().r() {
+            return
+        }
         if let Some(ref elem) = self.focused.get() {
             let node = elem.upcast::<Node>();
             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());