[Cherry-Pick] Selection in input event handler is different from opensource
authoreustas@chromium.org <eustas@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 May 2013 05:14:45 +0000 (05:14 +0000)
committerSangYong Park <sy302.park@samsung.com>
Tue, 17 Sep 2013 04:09:18 +0000 (13:09 +0900)
commit5192e0956737ba37791e300c8d2112e9ac3bc33f
tree7686bff456de15624f3b16be831a78df1594ec94
parentcd5379be7b6de61a55d19ee40ac1a5bcf0da5a1f
[Cherry-Pick] Selection in input event handler is different from opensource

[Title] Selection in input event handler is different from opensource
[Issue#] DCM-2420
[Solution] Cherry picked.
[Cherry-Picker] Sangyong Park <sy302.park>

selectionStart/selectionEnd return "obsolete" values when requested during "input" event
https://bugs.webkit.org/show_bug.cgi?id=110742

Reviewed by Ryosuke Niwa.

Source/WebCore:

This patch defers firing "webkitEditableContentChanged" until new
selection is applied to control. This makes selection during "input"
more consistent and reliable.

Background: "input" event is fired by "webkitEditableContentChanged"
dispatcher. But "input" is scoped event, so under some conditions its
dispatching may be deferred. When "input" dispatching is deferred,
dispatcher observes updated selectionStart and selectionEnd.
Otherwise values repersent state before applying editing command.

So, to make selectionStart/End to be more predictable and useful, we
need either always dispatch "input" before selection is updated, or
always dispatch "input" after selection is updated.

As it was mentioned, dispatching could be deferred by scoping. So
dispatching before updating selection couldn't be guaranteed.
Moreover, it will be hard to calculate updated selection in user
code. On the other side - old selection could be easily tracked.

So, it looks logically that we should guarantee dispatching "input"
after updating selection. There are no execution paths in
"webkitEditableContentChanged" dispatched that depends on current
selection. So it is safe to fire this event after selection is updated.

Test: editing/selection/caret-after-keypress.html

* editing/Editor.cpp:
Dispatch "input" event after new selection in applied.

LayoutTests:

Test that cursor is up-to-date during "input" event.

* editing/selection/caret-after-keypress-expected.txt: Added.
* editing/selection/caret-after-keypress.html: Added.
* platform/mac-wk2/TestExpectations: Exclude new test.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@151009 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Conflicts:

LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/TestExpectations
Source/WebCore/ChangeLog

Change-Id: Id5350596aa6633505c817b24b9e68a5cddd16ac1
LayoutTests/editing/selection/caret-after-keypress-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/caret-after-keypress.html [new file with mode: 0644]
Source/WebCore/editing/Editor.cpp