computeSelectionStart and computeSelectionEnd shouldn't trigger synchronous layout
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Feb 2014 22:32:05 +0000 (22:32 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 15 Feb 2014 22:32:05 +0000 (22:32 +0000)
commita0843b46f936ad2d1b58c31d14c58f945920680f
tree4b5b5f0a7ce3740283da0a86711fee45fb0c6d46
parent015979d64e33f3a3d064b758581c63f13533af40
computeSelectionStart and computeSelectionEnd shouldn't trigger synchronous layout
https://bugs.webkit.org/show_bug.cgi?id=128806

Reviewed by Darin Adler.

Added indexForPosition to HTMLTextFormControlElement. Like r163825, this patch traverses the DOM tree
instead of the render tree to compute the index for a given position.

We traverse the DOM Tree backwards starting at the specified Position all the way back to the beginning
of the inner text element. The index is computed as the number of characters we encountered during
this backwards DOM traversal.

It's worth noting that passedPosition.computeNodeBeforePosition() returns and only returns 0 when the
position is before the first node of its parent or inside a text node. In such cases, we call
passedPosition.containerNode() to find the parent or the text node.

* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::indexForVisiblePosition): Use indexForPosition.
(WebCore::HTMLTextFormControlElement::computeSelectionStart): Ditto.
(WebCore::HTMLTextFormControlElement::computeSelectionEnd): Dotto.
(WebCore::finishText): Cleanup. Use newlineCharacter instead of hard-coding '\n'.
(WebCore::HTMLTextFormControlElement::indexForPosition): Added. See above for the description.
* html/HTMLTextFormControlElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164180 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h