When an empty <input> element is focused, window.getSelection().getRangeAt(0).startContainer returns an HTMLDivElement. I believe this is the HTMLInnerTextField element we put in the shadow tree. We should be returning the HTMLInputElement itself, not this shadow child.
Created attachment 17125 [details] testcase
What should we return if the INPUT is not empty? Firefox seems to behave differently - it returns last selection outside INPUT (such as (BODY, 0) - (BODY, 0)) or raises an exception because of not being able to execute getRange(), depending on some conditions that aren't clear to me.
(In reply to comment #2) > What should we return if the INPUT is not empty? > > Firefox seems to behave differently - it returns last selection outside INPUT > (such as (BODY, 0) - (BODY, 0)) or raises an exception because of not being > able to execute getRange(), depending on some conditions that aren't clear to > me. I guess we'll have to test other browsers as well. I only mentioned the empty case here because it was clearly wrong.
I found out that this problem affects any input/textarea element whether empty or not. I also encountered problems with the "anchorNode" and "focusNode" properties of the selection object. These properties as well as the "startContainer" and the "endContainer" are returning a DIV element as parentNode of the selected text node. I've attached a simple testcase to demonstrate this behaviour.
Created attachment 22445 [details] testcase for input/textarea elements with selection/range objects
Does it return the parent div, or the shadow node? If it's the shadow node, this will go away when Ojan's patch to remove shadow nodes on <input> elements is finished.
> Does it return the parent div, or the shadow node? If it's the shadow node, > this will go away when Ojan's patch to remove shadow nodes on <input> elements > is finished. No, the problem is (as you can see at attached test) that the result is a DIV element with the text node inside, but the INPUT/TEXTAREA element is gone. The result should be --snip-- <div> <input id="a" value="test input"/> </div> --snip-- but it returns --snip-- <div> test input </div> --snip-- Same issue is also true for the TEXTAREA element.
<rdar://problem/7103776>
*** Bug 28086 has been marked as a duplicate of this bug. ***
Created attachment 34353 [details] patch
http://trac.webkit.org/changeset/46982