Bug 29249 - document.caretRangeFromPoint() should differentiate whether hit test on text node or non text related node
Summary: document.caretRangeFromPoint() should differentiate whether hit test on text ...
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-14 11:19 PDT by Xiaomei Ji
Modified: 2013-05-10 07:28 PDT (History)
7 users (show)

See Also:


Attachments
caretRangeFromPointInNonTextNode.html (1.07 KB, text/html)
2009-09-14 11:19 PDT, Xiaomei Ji
no flags Details
behavior difference between Document.caretRangeFromPoint in webkit and event.rangeOffset in FireFox (726 bytes, text/html)
2009-10-14 16:38 PDT, Xiaomei Ji
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Xiaomei Ji 2009-09-14 11:19:39 PDT
Created attachment 39557 [details]
caretRangeFromPointInNonTextNode.html

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?