Diff
Modified: trunk/LayoutTests/ChangeLog (94965 => 94966)
--- trunk/LayoutTests/ChangeLog 2011-09-12 17:54:33 UTC (rev 94965)
+++ trunk/LayoutTests/ChangeLog 2011-09-12 17:55:49 UTC (rev 94966)
@@ -1,3 +1,15 @@
+2011-09-12 Arko Saha <[email protected]>
+
+ Selectstart is not fired when selection was created by arrow keys.
+ https://bugs.webkit.org/show_bug.cgi?id=60430
+
+ Reviewed by Ryosuke Niwa.
+
+ * fast/events/selectstart-by-arrow-keys-expected.txt: Added.
+ * fast/events/selectstart-by-arrow-keys-prevent-default-expected.txt: Added.
+ * fast/events/selectstart-by-arrow-keys-prevent-default.html: Added.
+ * fast/events/selectstart-by-arrow-keys.html: Added.
+
2011-09-12 Ben Wagner <[email protected]>
Chromium shadow-buffer-partial test change.
Added: trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-expected.txt (0 => 94966)
--- trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-expected.txt 2011-09-12 17:55:49 UTC (rev 94966)
@@ -0,0 +1,18 @@
+This test ensures selectstart is fired when selection is created by arrow keys.
+
+If running this test manually, click on div ("Hello World") element and try to select the text using arrow keys.
+Expected result : SelectStart event will fire when user starts extending selection.
+Hello World
+Initial state: PASS
+Check (Right arrow): PASS
+Check (Right arrow + Shift): PASS
+Check (Right arrow + Shift + Control): PASS
+Check (End + Shift): PASS
+Check (Home + Shift): PASS
+Check (End + Shift): PASS
+Check (Left arrow): PASS
+Check (LeftArrow + Shift + Control): PASS
+Check (Left arrow + Shift): PASS
+Check (Home + Shift): PASS
+Check (Home + Control): PASS
+Done.
Added: trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default-expected.txt (0 => 94966)
--- trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default-expected.txt 2011-09-12 17:55:49 UTC (rev 94966)
@@ -0,0 +1,9 @@
+This test ensures selectstart event fires when selection is created by arrow key and script can prevent the selection change.
+
+If running this test manually, click on the div ("Hello World") and try to select the text using arrow keys.
+Expected result: SelectStart event will fire when user starts extending the selection, but due to script preventDefault it prevents the selection change.
+Hello World
+Check Right arrow + Shift: PASS
+Check Right arrow + Shift + Control: PASS
+Check End + Shift: PASS
+
Added: trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default.html (0 => 94966)
--- trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default.html (rev 0)
+++ trunk/LayoutTests/fast/events/selectstart-by-arrow-keys-prevent-default.html 2011-09-12 17:55:49 UTC (rev 94966)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This test ensures selectstart event fires when selection is created by arrow key and script can prevent the selection change.</p>
+If running this test manually, click on the div ("Hello World") and try to select the text using arrow keys.<br>
+Expected result: SelectStart event will fire when user starts extending the selection, but due to script preventDefault it prevents the selection change.<br>
+<div contenteditable>Hello World</div>
+<script>
+
+
+var selectStartCount = 0;
+var div = document.getElementsByTagName('div')[0];
+div.addEventListener('selectstart', function (event) { event.preventDefault(); selectStartCount++; });
+div.focus();
+window.getSelection().setPosition(div.firstChild, 1);
+
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ eventSender.keyDown("rightArrow", ["shiftKey"]);
+ logResult("Check Right arrow + Shift", 1);
+
+ eventSender.keyDown("rightArrow", ["shiftKey"], ["ctrlKey"]);
+ logResult("Check Right arrow + Shift + Control", 2);
+
+ eventSender.keyDown("end", ["shiftKey"]);
+ logResult("Check End + Shift", 3);
+}
+
+function logResult(title, expectedCount) {
+ var range = window.getSelection().getRangeAt(0);
+ document.write(title + ': ');
+ if (selectStartCount != expectedCount)
+ document.write('FAIL - expected ' + expectedCount + ' events but got ' + selectStartCount + ' events');
+ else if (range.startOffset != 1 || range.endOffset != 1)
+ document.write('FAIL - selection changed');
+ else
+ document.write('PASS');
+ document.write('<br>');
+}
+
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/fast/events/selectstart-by-arrow-keys.html (0 => 94966)
--- trunk/LayoutTests/fast/events/selectstart-by-arrow-keys.html (rev 0)
+++ trunk/LayoutTests/fast/events/selectstart-by-arrow-keys.html 2011-09-12 17:55:49 UTC (rev 94966)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>This test ensures selectstart is fired when selection is created by arrow keys.</p>
+If running this test manually, click on div ("Hello World") element and try to select the text using arrow keys.<br>
+Expected result : SelectStart event will fire when user starts extending selection.<br>
+<div id="test" contenteditable>Hello World</div>
+<script>
+
+var selectStartCount = 0;
+var div = document.getElementById('test');
+div.addEventListener('selectstart', function (event) { selectStartCount++; });
+div.focus();
+
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ logResult('Initial state', 0);
+
+ eventSender.keyDown("rightArrow");
+ logResult('Check (Right arrow)', 0);
+
+ eventSender.keyDown("rightArrow", ["shiftKey"]);
+ logResult('Check (Right arrow + Shift)', 1);
+
+ eventSender.keyDown("rightArrow", ["shiftKey"], ["ctrlKey"]);
+ logResult('Check (Right arrow + Shift + Control)', 1);
+
+ eventSender.keyDown("end", ["shiftKey"]);
+ logResult('Check (End + Shift)', 1);
+
+ eventSender.keyDown("home", ["shiftKey"]);
+ logResult('Check (Home + Shift)', 1);
+
+ eventSender.keyDown("end", ["shiftKey"]);
+ logResult('Check (End + Shift)', 1);
+
+ eventSender.keyDown("leftArrow");
+ logResult('Check (Left arrow)', 1);
+
+ eventSender.keyDown("leftArrow", ["shiftKey"], ["ctrlKey"]);
+ logResult('Check (LeftArrow + Shift + Control)', 2);
+
+ eventSender.keyDown("leftArrow", ["shiftKey"]);
+ logResult('Check (Left arrow + Shift)', 2);
+
+ eventSender.keyDown("end", ["shiftKey"]);
+ logResult('Check (Home + Shift)', 2);
+
+ eventSender.keyDown("home", ["ctrlKey"]);
+ logResult('Check (Home + Control)', 2);
+}
+
+document.write("Done.")
+
+function logResult(title, expectedCount) {
+ document.write(title + ': ');
+ if (selectStartCount != expectedCount)
+ document.write('FAIL - expected ' + expectedCount + ' events but got ' + selectStartCount + ' events');
+ else
+ document.write('PASS');
+ document.write('<br>');
+}
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (94965 => 94966)
--- trunk/Source/WebCore/ChangeLog 2011-09-12 17:54:33 UTC (rev 94965)
+++ trunk/Source/WebCore/ChangeLog 2011-09-12 17:55:49 UTC (rev 94966)
@@ -1,3 +1,22 @@
+2011-09-12 Arko Saha <[email protected]>
+
+ Selectstart is not fired when selection was created by arrow keys.
+ https://bugs.webkit.org/show_bug.cgi?id=60430
+
+ Reviewed by Ryosuke Niwa.
+
+ Fire selectstart when a user starts extending the selection using arrow key.
+ Fixed by Arko Saha <[email protected]> and Kaustubh Atrawalkar <[email protected]>
+
+ Tests: fast/events/selectstart-by-arrow-keys-prevent-default.html
+ fast/events/selectstart-by-arrow-keys.html
+
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::modify):
+ (WebCore::FrameSelection::shouldChangeSelection):
+ (WebCore::FrameSelection::dispatchSelectStart):
+ * editing/FrameSelection.h:
+
2011-09-12 James Robinson <[email protected]>
[chromium] REGRESSION(94353): Compositor textures and resources leaked when tab closed that is not last tab in the process
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (94965 => 94966)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2011-09-12 17:54:33 UTC (rev 94965)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2011-09-12 17:55:49 UTC (rev 94966)
@@ -824,6 +824,9 @@
bool change = shouldChangeSelection(trialFrameSelection.selection());
if (!change)
return false;
+
+ if (trialFrameSelection.selection().isRange() && m_selection.isCaret() && !dispatchSelectStart())
+ return false;
}
willBeModified(alter, direction);
@@ -1884,6 +1887,15 @@
return m_frame->editor()->shouldChangeSelection(selection(), newSelection, newSelection.affinity(), false);
}
+bool FrameSelection::dispatchSelectStart()
+{
+ Node* selectStartTarget = m_selection.extent().containerNode();
+ if (!selectStartTarget)
+ return true;
+
+ return selectStartTarget->dispatchEvent(Event::create(eventNames().selectstartEvent, true, true));
+}
+
#ifndef NDEBUG
void FrameSelection::formatForDebugger(char* buffer, unsigned length) const
Modified: trunk/Source/WebCore/editing/FrameSelection.h (94965 => 94966)
--- trunk/Source/WebCore/editing/FrameSelection.h 2011-09-12 17:54:33 UTC (rev 94965)
+++ trunk/Source/WebCore/editing/FrameSelection.h 2011-09-12 17:55:49 UTC (rev 94966)
@@ -275,6 +275,8 @@
void setCaretVisibility(CaretVisibility);
+ bool dispatchSelectStart();
+
Frame* m_frame;
LayoutUnit m_xPosForVerticalArrowNavigation;