Bug 29249

Summary: document.caretRangeFromPoint() should differentiate whether hit test on text node or non text related node
Product: WebKit Reporter: Xiaomei Ji <xji>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: UNCONFIRMED ---    
Severity: Normal CC: cira, hyatt, jshin, mjs, sam, tonikitoo, xji
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Description Flags
behavior difference between Document.caretRangeFromPoint in webkit and event.rangeOffset in FireFox none

Description Xiaomei Ji 2009-09-14 11:19:39 PDT
Created attachment 39557 [details]

In caretRangeFromPoint(), there is the following code:

    Node* node = result.innerNode();
    if (!node)
        return 0;

Since we do not check whether the 'node' is a Text related node, there is a
possibility that a range is created even when the mouse is not pointed in the
text area.

Please open caretRangeFromPointInNonTextNode.html,
click mouse right before the first word "type", in the range created by
caretRangeFromPoint(), the node is the Text node, the start/end offset is 0. 

click mouse several characters ahead of word "type" (the empty space in the
left of "type"), although the 'node' is a HTMLBodyElement, but it has the
same visible position as the above, and the range created is the same as above.
Is this the correct behavior?

I think my assumption is that this function converts mouse position to the
character position within an element, so a null range should be returned if
click the empty spaces ahead of word "type".
Comment 1 Xiaomei Ji 2009-10-14 16:38:37 PDT
Created attachment 41194 [details]
behavior difference between Document.caretRangeFromPoint in webkit and event.rangeOffset in FireFox

1. open the attached page
2. mouse click right before the first word "the" in the list, the container node and offset in the range returned from caretRangeFromPoint() is the text node "the first", and offset 0.
3. mouse click some where in the empty space around the bullet before "the first".
caretRangeFromPoint() returns the same as the above.

By comparison, open the above page in Firefox and repeat the above steps, you will see the node and offset returned from event.rangeParent/rangeOffset in FireFox are different if click on the text node and the element node.

Does webkit have anyway to tell the difference?
Seems that none of document.caretRangeFromPoint(), event.target, and document.elementFromPoint() shows any difference in the above 2 clicks.

Should I apply for a new API for such differentiation?