Bug 145430

Summary: When the value of input isnot changed , selection range shouldnot be changed
Product: WebKit Reporter: Peng Xinchao <xinchao.peng>
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: beidson, buildbot, commit-queue, d_russell, jdiggs, rniwa, zalan
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
rniwa: review-, buildbot: commit-queue-
Archive of layout-test-results from ews104 for mac-mavericks-wk2
none
Patch
none
Patch beidson: review-

Description Peng Xinchao 2015-05-27 22:58:45 PDT
Test Case:
<html>
    <head>
        <title>Jasmine Spec Runner</title>	  
<script>

function testchangeime()
{
	
	var q = document.getElementById("username").value;
	document.getElementById("username").setSelectionRange(0,q.length);
	var p = q.trim();
	document.getElementById("username").value = p;
}
</script>		    
    </head>
    <body>
		 <input type="text" id="username"  oninput="testchangeime()">
		 </input>
    </body>
</html>

When user input "a"  "b"  "c" "d" continuously,the value of input is "abcd". 
But i think the value of input should be  "d".
Comment 1 zalan 2015-05-28 08:48:34 PDT
Apparently the "document.getElementById("username").value" removes the selection so the next input entry gets appended (instead of replacing the selected content).
Chrome behaves like Safari, while Firefox behaves differently (as described as expected behavior)
Comment 2 Peng Xinchao 2015-05-28 18:51:46 PDT
Created attachment 253887 [details]
Patch
Comment 3 WebKit Commit Bot 2015-05-28 18:53:26 PDT
Attachment 253887 [details] did not pass style-queue:


ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Peng Xinchao 2015-05-28 18:57:01 PDT
Created attachment 253888 [details]
Patch
Comment 5 Ryosuke Niwa 2015-05-28 21:59:26 PDT
Comment on attachment 253888 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=253888&action=review

r- because this patch is missing a test.
I'm also worried that this change is not backwards compatible and may worsen the certain aspects of user interaction.

> Source/WebCore/html/TextFieldInputType.cpp:129
> +    if (Frame* frame = input->document()->frame()) {
> +        start = frame->selection()->selection().start().offsetInContainerNode();
> +        end = frame->selection()->selection().end().offsetInContainerNode();
> +    }

This is wrong. containerNode could be a div in the shadow DOM.
We should be using element().selectionStart() and element().selectionEnd() instead.
Comment 6 Peng Xinchao 2015-05-31 18:29:23 PDT
Created attachment 253985 [details]
Patch
Comment 7 Build Bot 2015-05-31 19:08:13 PDT
Comment on attachment 253985 [details]
Patch

Attachment 253985 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/6746635820335104

New failing tests:
fast/frames/take-focus-from-iframe.html
platform/mac/editing/input/selection-change-closes-typing.html
fast/forms/input-setvalue-selection.html
Comment 8 Build Bot 2015-05-31 19:08:17 PDT
Created attachment 253986 [details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 9 Ryosuke Niwa 2015-05-31 19:10:30 PDT
Comment on attachment 253985 [details]
Patch

Again, this patch definitely needs a layout test, and we need to test backwards compatibility of this change.
Comment 10 Peng Xinchao 2015-06-01 22:48:25 PDT
Created attachment 254052 [details]
Patch
Comment 11 Peng Xinchao 2015-06-01 23:16:51 PDT
Created attachment 254056 [details]
Patch
Comment 12 Darin Adler 2015-06-02 11:43:25 PDT
Comment on attachment 254056 [details]
Patch

The old behavior was intentional, originally to match what other web browsers do. What’s the web compatibility impact of changing this?
Comment 13 Peng Xinchao 2015-06-02 18:26:31 PDT
It happened with IME of PreEdit .
Example :
<input type="text" id="username"  oninput="testchangeime()"> </input>
<script>
function testchangeime(){	
	var q = document.getElementById("username").value;
	var p = q.trim();
	document.getElementById("username").value = p;
}
</script>

When user input 'a' with IME ,the status of 'a' is PreEdit .
But if testchangeime() is called , the status of 'a' will become PreEdit to NoPreEdit.
Comment 14 Brady Eidson 2017-04-24 19:11:55 PDT
Comment on attachment 254056 [details]
Patch

This patch has been pending review since 2015 with no recent activity.
It seems unlikely that it would even still apply to trunk in its current form.

Clearing from the review queue.

Feel free to update and resubmit if the patch is still relevant.