Summary: | window.getSelection().focusNode is null with onfocus handler registered | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Jessie Berlin <jberlin> | ||||
Component: | HTML Editing | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | NEW --- | ||||||
Severity: | Normal | CC: | ahmad.saleem792, ap, bfulgham, jparent, leviw, mrowe, rniwa, webkit | ||||
Priority: | P2 | ||||||
Version: | 528+ (Nightly build) | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
Attachments: |
|
This is due to the fact WebKit sets selection after setting the focus. Ojan, Alexey: Do you think we should change the WebKit's behavior so that we set the selection first and then focus? This will make our behavior consistent with IE. > This will make our behavior consistent with IE.
Have you tested Firefox?
I'm not aware of any reason why such a change would be bad per se. But I don't think that we allow unfocused (inactive? I'm confused about the difference) elements/frames to be selected, because having multiple selections in a window is bad UI.
FocusController / SelectionController is in the realm of the HTML Editing component. Latest test results across all browsers: *** Safari 15.6 on macOS *** > Clicking on 'Red' padding window.getSelection(): window.getSelection().focusNode: null > Clicking on 'Blue' padding window.getSelection(): window.getSelection().focusNode: [object Text] window.getSelection().focusNode.parentNode: [object HTMLDivElement] *** Chrome Canary 106 *** [MATCH WITH SAFARI] > Clicking on 'Red' padding window.getSelection(): window.getSelection().focusNode: null > Clicking on 'Blue' padding window.getSelection(): window.getSelection().focusNode: [object Text] window.getSelection().focusNode.parentNode: [object HTMLDivElement] *** Firefox Nightly 105 *** > Clicking on 'Red' padding window.getSelection(): window.getSelection().focusNode: [object Text] window.getSelection().focusNode.parentNode: [object HTMLDivElement] > Clicking on 'Blue' padding window.getSelection(): window.getSelection().focusNode: [object Text] window.getSelection().focusNode.parentNode: [object HTMLDivElement] ___________ I am not sure on web-spec but just wanted to share latest results across all browsers using attached test case. Thanks! |
Created attachment 32354 [details] Test case for window.getSelection with onfocus, onclick handlers When an onfocus handler is registered on a div containing another div with text, window.getSelection().focusNode reports null in said onfocus handler. If the handler is an onclick handler, it correctly reports the focusNode as a HTML div element.