Re: [cssom-view]: should caretRangeFromPoint() return NULL for a non-text related node?

On Thu, Oct 8, 2009 at 1:56 AM, Anne van Kesteren <annevk@opera.com> wrote:

> On Wed, 07 Oct 2009 18:45:11 +0200, Xiaomei Ji <xji@chromium.org> wrote:
>
>> Sam implemented caretRangeFromPoint() in
>> Webkit<https://bugs.webkit.org/show_bug.cgi?id=27046>
>>
>> But there is one question we are not sure about: whether NULL should be
>> returned if the hit test hits a non-text node.
>>
>> Following is extracted from the
>> spec<http://dev.w3.org/csswg/cssom-view/#the-documentview-interface>
>> : "(caretRangeFromPoint)..... *must* return an empty text range for the
>> position where a text insertion point indicator would have been
>> inserted.... or no insertion point indicator would have been inserted, the
>> method *must* return null."
>>
>> My understanding is that for a non-text related node (such as an image in
>> the  middle of text), since there is no insertion point indicator would
>> have been inserted into it (the image), a NULL range sould be returned if
>> the hit test hits it (the image).
>>
>> But I am not sure what is the objective of caretRangeFromPoint().
>> I have a specific use case which is to convert the mouse position to
>> character position inside a text node. Then returning NULL sounds
>> reasonable for such usage. Here <
>> https://bugs.webkit.org/show_bug.cgi?id=29249>is the related webkit bug.
>>
>> Would appreciate more background and clarification.
>>
>
> Hmm, I would have expected that in the image scenario you would typically
> get an insertion pointer as well in normal editing conventions. The idea was
> anyway for there to be one since this is a convenience method for editors.
>
> If someone can propose specification text that works better or maybe a set
> of constraints or something I can try to clarify.
>


Hi Anne,

Thanks for your explanation!

I should explain my use case for some background.
I am trying to find out the word under mouse.
So, first I use document.caretRangeFromPoint() to convert the mouse position
in viewport to     character position within a node in the document.
Then, find out the word based on the above result.

It is similar to the event.rangeOffset() and event.rangeParent() provided by
FireFox.

Then, for such use case, hit test on non-text node should not return a valid
range.
Given the example of an image within text, the returning ranges should be
different for mouse click on the image and mouse click right before the
first character in the text following the image. Otherwise, there is no way
to distinguish whether the mouse clicked on a word or not.

Maybe caretRangeFromPoint() is used for editing purpose, and not suitable
for the above use case?


Thanks,
Xiaomei





>
>
> --
> Anne van Kesteren
> http://annevankesteren.nl/
>

Received on Thursday, 8 October 2009 18:44:54 UTC