SimplifiedBackwardsTextIterator returns incorrect offset with first-letter rule
authorRyosuke Niwa <rniwa@webkit.org>
Thu, 18 Aug 2011 20:41:51 +0000 (20:41 +0000)
committerAdemar de Souza Reis Jr <ademar.reis@openbossa.org>
Tue, 23 Aug 2011 17:43:28 +0000 (14:43 -0300)
commitb0f1d639e8bd2da6bab80d6238a7d56a947420ff
tree6f7c12adaa28759b3252ba970b15fb6d1d8840b5
parentf011bd5f216ba62629ddd6e3f5cec97f44814f58
SimplifiedBackwardsTextIterator returns incorrect offset with first-letter rule
https://bugs.webkit.org/show_bug.cgi?id=66086

Reviewed by Darin Adler.

Source/WebCore:

The bug was caused by SimplifiedBackwardsTextIterator's not taking care of first-letter at all.
Fixing the bug by detecting RenderTextFragment in handleTextNode.

Also added m_shouldHandleFirstLetter to SimplifiedBackwardsTextIterator to keep track of whether or not
the next call to handleTextNode needs to process the first-letter part of the text fragment.

Test: editing/text-iterator/backward-textiterator-first-letter-crash.html

* editing/TextIterator.cpp:
(WebCore::firstRenderTextInFirstLetter): Extracted from handleTextNodeFirstLetter.
(WebCore::TextIterator::handleTextNodeFirstLetter): Calls firstRenderTextInFirstLetter.
(WebCore::SimplifiedBackwardsTextIterator::SimplifiedBackwardsTextIterator):
(WebCore::SimplifiedBackwardsTextIterator::handleTextNode):
(WebCore::SimplifiedBackwardsTextIterator::handleFirstLetter): Added.
* editing/TextIterator.h:

LayoutTests:

Added a test to ensure WebKit does not hit assertions in SimplifiedBackwardsTextIterator.
Also fixed a bug in first-letter-word-boundary.html and updated expected offsets for move backward by word
from 0 to 1 because there is unrendered space before "hello".

* editing/text-iterator/backward-textiterator-first-letter-crash-expected.txt: Added.
* editing/text-iterator/backward-textiterator-first-letter-crash.html: Added.
* editing/text-iterator/first-letter-word-boundary-expected.txt:
* editing/text-iterator/first-letter-word-boundary.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@93347 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/text-iterator/backward-textiterator-first-letter-crash-expected.txt [new file with mode: 0644]
LayoutTests/editing/text-iterator/backward-textiterator-first-letter-crash.html [new file with mode: 0644]
LayoutTests/editing/text-iterator/first-letter-word-boundary-expected.txt
LayoutTests/editing/text-iterator/first-letter-word-boundary.html
Source/WebCore/ChangeLog
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/TextIterator.h