[webkit-dev] Why does PositionIterator iterates until the end of the document when selecting?

Sergiy Byelozyorov byelozyorov at cs.uni-saarland.de
Thu Mar 29 07:27:22 PDT 2012


Hi,

When searching for the character to be selected (on mouse click), we run an
interator over the characters to determine the one under the cursor. I am
trying to understand why does PositionInterator that is used in this case
iterates over all characters starting from the element that was clicked and
until the end of the document(!). The following method is called to verify
whether PositionIterator has finished traversing the characters (see
comments inline):

bool PositionIterator::atEnd() const

{

    if (!m_anchorNode) // This is clear - if we don't have an an anchor -
then we are done.

        return true;

    if (m_nodeAfterPositionInAnchor) // This is also understandable - if
there is a next position then we are not at the end.

        return false;

    // This is what puzzles me. First check will be true until we will
reach the root of the Document.

    return !m_anchorNode->parentNode() && (m_anchorNode->hasChildNodes() ||
m_offsetInAnchor >= lastOffsetForEditing(m_anchorNode));

}

Is this the intended behaviour? Why wouldn't we just stay within the
element that was clicked on? This would save us a lot of CPU cycles because
we won't be checking text that in all other elements until the end of the
document, wouldn't it? This check has been around since at least 2004, so I
doub't that it's wrong, but I don't get the logic here. Please explain this
to me. Thanks.

Sergiy Byelozyorov
Computer Graphics Chair
Universitat des Saarlandes
Tel.: +49 (681) 302-3837
Web: http://graphics.cs.uni-saarland.de/sbyelozyorov/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20120329/9fa46769/attachment.html>


More information about the webkit-dev mailing list