indexForVisiblePosition should use the root editable element as the scope
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 May 2016 19:51:14 +0000 (19:51 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 May 2016 19:51:14 +0000 (19:51 +0000)
commit53a3fb09ad6bd017aa8515f544de020ab6dd6b30
tree8b05872247e06739eac0edf22da08b8b77056b7b
parent726106d50d39b04ccdf54afd4422307b01eb7c6c
indexForVisiblePosition should use the root editable element as the scope
https://bugs.webkit.org/show_bug.cgi?id=157611

Reviewed by Darin Adler.

Source/WebCore:

Use the highest editing host instead of the document node as the scope in indexForVisiblePosition
when it's called inside an editable region. This refactoring is necessary to unblock the work to support
undo/redo in VoiceOver after r199030.

We have to workaround a bug in indexForVisiblePosition that it could return a slightly higher index than
the expected value because TextIterator emits an extra new line after a block element with a large margin
at the bottom. Unfortunately, fixing this requires a lot of code changes since the rest of the editing
code assumes this behavior and/or happens to cancel it out with some other quirks.

* editing/ApplyBlockElementCommand.cpp:
(WebCore::ApplyBlockElementCommand::doApply):
* editing/htmlediting.cpp:
(WebCore::indexForVisiblePosition):

LayoutTests:

Rebaselined tests with progressions.

* editing/execCommand/crash-indenting-list-item-expected.txt: Now preseves the selection at the beginning of
the editable region instead of moving it to the end.
* editing/execCommand/format-block-multiple-paragraphs-in-pre-expected.txt: Now preserves selection in more test
cases. This test is the one that required the workaround in ApplyBlockElementCommand::doApply. One of the test
cases would regress and clear the selection without it.
* editing/execCommand/indent-pre-list-expected.txt: Now preserves the selection instead of clearing it.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@200787 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/crash-indenting-list-item-expected.txt
LayoutTests/editing/execCommand/format-block-multiple-paragraphs-in-pre-expected.txt
LayoutTests/editing/execCommand/indent-pre-list-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/ApplyBlockElementCommand.cpp
Source/WebCore/editing/htmlediting.cpp