Title: [96628] trunk/Source/WebCore
Revision
96628
Author
[email protected]
Date
2011-10-04 12:02:44 -0700 (Tue, 04 Oct 2011)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (96627 => 96628)


--- trunk/Source/WebCore/ChangeLog	2011-10-04 19:02:03 UTC (rev 96627)
+++ trunk/Source/WebCore/ChangeLog	2011-10-04 19:02:44 UTC (rev 96628)
@@ -1,3 +1,22 @@
+2011-10-04  Ryosuke Niwa  <[email protected]>
+
+        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.
+
 2011-10-04  Young Han Lee  <[email protected]>
 
         HTML canvas strokes with dash and dashOffset

Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (96627 => 96628)


--- trunk/Source/WebCore/editing/FrameSelection.cpp	2011-10-04 19:02:03 UTC (rev 96627)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp	2011-10-04 19:02:44 UTC (rev 96628)
@@ -274,7 +274,7 @@
     m_selection = s;
     setCaretRectNeedsUpdate();
     
-    if (!s.isNone())
+    if (!s.isNone() && !(options & DoNotSetFocus))
         setFocusedNodeIfNeeded();
     
     updateAppearance();
@@ -393,7 +393,7 @@
         clearRenderViewSelection(m_selection.start());
 
     if (clearDOMTreeSelection)
-        setSelection(VisibleSelection(), 0);
+        setSelection(VisibleSelection(), DoNotSetFocus);
 }
 
 static void updatePositionAfterAdoptingTextReplacement(Position& position, CharacterData* node, unsigned offset, unsigned oldLength, unsigned newLength)
@@ -433,7 +433,7 @@
         VisibleSelection newSelection;
         newSelection.setWithoutValidation(base, extent);
         m_frame->document()->updateLayout();
-        setSelection(newSelection, 0);
+        setSelection(newSelection, DoNotSetFocus);
     }
 }
 

Modified: trunk/Source/WebCore/editing/FrameSelection.h (96627 => 96628)


--- trunk/Source/WebCore/editing/FrameSelection.h	2011-10-04 19:02:03 UTC (rev 96627)
+++ trunk/Source/WebCore/editing/FrameSelection.h	2011-10-04 19:02:44 UTC (rev 96628)
@@ -115,6 +115,7 @@
         CloseTyping = 1 << 1,
         ClearTypingStyle = 1 << 2,
         SpellCorrectionTriggered = 1 << 3,
+        DoNotSetFocus = 1 << 4,
     };
     typedef unsigned SetSelectionOptions; // Union of values in SetSelectionOption and EUserTriggered
     static inline EUserTriggered selectionOptionsToUserTriggered(SetSelectionOptions options)

Added: trunk/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html (0 => 96628)


--- trunk/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html	                        (rev 0)
+++ trunk/Source/WebCore/manual-tests/mutate-unfocused-text-with-selection.html	2011-10-04 19:02:44 UTC (rev 96628)
@@ -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 = '';
+    alert('activeElement:' + document.activeElement.id); // necessary to reproduce the bug
+}, 50);
+
+</script>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to