REGRESSION(r94274): setting input.value erroneously triggers focus event
https://bugs.webkit.org/show_bug.cgi?id=69315

Reviewed by Kent Tamura.

Fixed the bug by adding a new flag to setSelection to avoid calling setFocusedNodeIfNeeded
when called by nodeWillBeRemoved and textWillBeReplaced.

Added a manual test. Unfortunately, the test always passes in DRT.

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::setSelection):
(WebCore::FrameSelection::respondToNodeModification):
(WebCore::FrameSelection::textWillBeReplaced):
* editing/FrameSelection.h:
* manual-tests/mutate-unfocused-text-with-selection.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96628 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html b/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html
new file mode 100644
index 0000000..c193d12
--- /dev/null
+++ b/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This tests modifying a text node with selection but without a focus.
+WebKit used to automatically set the focus to the root editable element of this node but it should not.
+You should see 'PASS' below:</p>
+<div id="target" onfocus="target.innerText='FAIL'" contenteditable>hello</div>
+<div id="focused" contenteditable>world</div>
+<script>
+
+var target = document.getElementById('target');
+var focused = document.getElementById('focused');
+focused.focus();
+getSelection().setBaseAndExtent(target.firstChild, 1, target.firstChild, 3);
+
+// The bug doesn't reproduce if this function was ran here or inside load event handler
+setTimeout(function() {
+    target.firstChild.data = 'PASS';
+    alert('activeElement:' + document.activeElement.id); // necessary to reproduce the bug
+}, 50);
+
+</script>
+</body>
+</html>