Open Bug 932897 Opened 7 years ago Updated 2 years ago

Focus method should dispatch associated focus event synchronously

Categories

(Core :: DOM: Events, defect, P5)

28 Branch
x86_64
Linux
defect

Tracking

()

UNCONFIRMED

People

(Reporter: froidure_nicolas, Unassigned, NeedInfo)

Details

Attachments

(1 file)

Attached file tests.html
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36

Steps to reproduce:

Doing HTMLInputElement.focus()


Actual results:

The associated focus event is fired asynchronouly


Expected results:

The associated focus event should be dispatched synchronously according to the specification (http://www.w3.org/TR/DOM-Level-3-Events/#event-type-focus). The blur method seems to have the same surprising behavior.

Note that i didn't found any place in the spec recommending to fire focus event when calling the focus method. It appear that chrome is not firing this event.

Tried to look in the code and assuming the problem starts here: http://dxr.mozilla.org/mozilla-central/source/accessible/src/base/FocusManager.cpp#l223

To give more context: i encoutered this issue while trying to generate FocusEvents properly in a cross-browser manner : https://github.com/francejs/effroi/blob/master/src/ui/focus.js#L49 .

Hope it help feel free to ask me more informations if needed.
Boris, could you please take a look?
Flags: needinfo?(bzbarsky)
> Tried to look in the code and assuming the problem starts here:
> http://dxr.mozilla.org/mozilla-central/source/accessible/src/base/FocusManager.cpp#l223

That's an acessibility event, not a DOM event.

Focus DOM events are fired synchronously under the focus() call.  Try this simple testcase:

<input onfocus="window.logString += 'focused, '">
<script>
  window.logString = 'About to focus, ';
  document.querySelector("input").focus();
  window.logString += 'done focusing';
  setTimeout(function() { alert(window.logString); }, 100);
</script>

so whatever issue the attached testcase is showing is not due to async firing of focus events.  What issue _is_ it showing, exactly?
Flags: needinfo?(bzbarsky) → needinfo?(froidure_nicolas)
Oh, also:

> Note that i didn't found any place in the spec recommending to fire focus event when
> calling the focus method.

http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#dom-focus step 3 calls http://www.whatwg.org/specs/web-apps/current-work/multipage/editing.html#focusing-steps and step 5 there fires the event.  The DOM3 Events spec is ... very old and has little to do with reality.
Nicolas, is there any more information you can add?  Thanks!
Nothing more to say :). Just pointing out inconsistencies between browsers but not skilled enough in spec decoding and/or Mozilla codebase to help anymore.
Flags: needinfo?(froidure_nicolas)
No, my question is why exactly you think the focus event is fired asynchronously.  Or put another way, what is the actual problem behavior you see in the (huge, so it's hard to tell which part you care about) testcase?
Flags: needinfo?(froidure_nicolas)
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.